Skip to content

Commit 1876085

Browse files
committed
Adding the new stats.
1 parent 02a0aa4 commit 1876085

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Controllers/CompliancesController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public CompliancesController(IBackendConfigurationCompliancesService backendConf
4444
_backendConfigurationCompliancesService = backendConfigurationCompliancesService;
4545
}
4646

47+
[HttpGet]
48+
[Route("stats")]
49+
[AllowAnonymous]
50+
public Task<OperationDataResult<CompliancesStatsModel>> Stats()
51+
{
52+
return _backendConfigurationCompliancesService.Stats();
53+
}
54+
4755
[HttpPost]
4856
[Route("index")]
4957
public Task<OperationDataResult<Paged<CompliancesModel>>> Index([FromBody] CompliancesRequestModel request)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace BackendConfiguration.Pn.Controllers;
2+
3+
public class CompliancesStatsModel
4+
{
5+
public int OneWeekInTheFutureCount { get; set; }
6+
public int TotalCount { get; set; }
7+
public int OneWeekCount { get; set; }
8+
public int TwoWeeksCount { get; set; }
9+
public int OneMonthCount { get; set; }
10+
public int TwoMonthsCount { get; set; }
11+
public int ThreeMonthsCount { get; set; }
12+
public int SixMonthsCount { get; set; }
13+
public int MoreThanSixMonthsCount { get; set; }
14+
}

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationCompliancesService/BackendConfigurationCompliancesService.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
*/
2424

2525

26+
using BackendConfiguration.Pn.Controllers;
27+
2628
namespace BackendConfiguration.Pn.Services.BackendConfigurationCompliancesService;
2729

2830
using BackendConfigurationLocalizationService;
@@ -385,6 +387,37 @@ public async Task<OperationResult> Delete(int id)
385387
return new OperationResult(true, _localizationService.GetString("TaskDeletedSuccessful"));
386388
}
387389

390+
public async Task<OperationDataResult<CompliancesStatsModel>> Stats()
391+
{
392+
var complianceList = _backendConfigurationPnDbContext.Compliances
393+
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed);
394+
var oneWeekInTheFutureCount = await complianceList.CountAsync(x => x.Deadline >= DateTime.UtcNow && x.Deadline <= DateTime.UtcNow.AddDays(7));
395+
var oneWeekCount = await complianceList.CountAsync(x => x.Deadline <= DateTime.UtcNow && x.Deadline >= DateTime.UtcNow.AddDays(-7));
396+
var twoWeeksCount = await complianceList.CountAsync(x => x.Deadline <= DateTime.UtcNow.AddDays(-7) && x.Deadline >= DateTime.UtcNow.AddDays(-14));
397+
var oneMonthCount = await complianceList.CountAsync(x => x.Deadline <= DateTime.UtcNow.AddDays(-14) && x.Deadline >= DateTime.UtcNow.AddDays(-30));
398+
var twoMonthsCount = await complianceList.CountAsync(x => x.Deadline <= DateTime.UtcNow.AddDays(-30) && x.Deadline >= DateTime.UtcNow.AddDays(-60));
399+
var threeMonthsCount = await complianceList.CountAsync(x => x.Deadline <= DateTime.UtcNow.AddDays(-60) && x.Deadline >= DateTime.UtcNow.AddDays(-90));
400+
var sixMonthsCount = await complianceList.CountAsync(x => x.Deadline <= DateTime.UtcNow.AddDays(-90) && x.Deadline >= DateTime.UtcNow.AddDays(-180));
401+
var moreThanSixMonthsCount = await complianceList.CountAsync(x => x.Deadline < DateTime.UtcNow.AddDays(-180));
402+
403+
var totalCount = complianceList.Count();
404+
405+
var statsModel = new CompliancesStatsModel
406+
{
407+
OneWeekInTheFutureCount = oneWeekInTheFutureCount,
408+
TotalCount = totalCount,
409+
OneWeekCount = oneWeekCount,
410+
TwoWeeksCount = twoWeeksCount,
411+
OneMonthCount = oneMonthCount,
412+
TwoMonthsCount = twoMonthsCount,
413+
ThreeMonthsCount = threeMonthsCount,
414+
SixMonthsCount = sixMonthsCount,
415+
MoreThanSixMonthsCount = moreThanSixMonthsCount
416+
};
417+
418+
return new OperationDataResult<CompliancesStatsModel>(true, statsModel);
419+
}
420+
388421
private async Task<PlanningCaseSite> SetFieldValue(PlanningCaseSite planningCaseSite, int caseId, Language language)
389422
{
390423
var planning = _itemsPlanningPnDbContext.Plannings

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationCompliancesService/IBackendConfigurationCompliancesService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
2323
*/
2424

25+
using BackendConfiguration.Pn.Controllers;
2526
using Microting.eForm.Infrastructure.Models;
2627
using Microting.eFormApi.BasePn.Infrastructure.Models.Application.Case.CaseEdit;
2728

@@ -39,4 +40,5 @@ public interface IBackendConfigurationCompliancesService
3940
Task<OperationDataResult<ReplyElement>> Read(int id);
4041
Task<OperationResult> Update(ReplyRequest model);
4142
Task<OperationResult> Delete(int id);
43+
Task<OperationDataResult<CompliancesStatsModel>> Stats();
4244
}

0 commit comments

Comments
 (0)