You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
12 KiB
235 lines
12 KiB
|
3 months ago
|
using ATS.NonCustodial.Application.Base;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.AppDictionaries;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement.Input;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement.Output;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppEarlyWarnings;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppEarlyWarnings.Output;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.IM.Notifies;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.ViolationStatistics;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.ViolationStatistics.Input;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.ViolationStatistics.Output;
|
||
|
|
using ATS.NonCustodial.Domain.Entities.Business;
|
||
|
|
using ATS.NonCustodial.Domain.Entities.Business.CaseManagements;
|
||
|
|
using ATS.NonCustodial.Domain.Entities.Business.EarlyWarning;
|
||
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos;
|
||
|
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore;
|
||
|
|
using ATS.NonCustodial.DynamicApi;
|
||
|
|
using ATS.NonCustodial.DynamicApi.Attributes;
|
||
|
|
using ATS.NonCustodial.Shared.Common.Dtos;
|
||
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions.Collection;
|
||
|
|
using AutoMapper.QueryableExtensions;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using NPOI.SS.Formula.Functions;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||
|
|
|
||
|
|
namespace ATS.NonCustodial.Application.Impl.Business
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 违规统计服务管理
|
||
|
|
/// </summary>
|
||
|
|
/// Author:mxg
|
||
|
|
/// CreatedTimed:2022-06-06 05:35 PM
|
||
|
|
[DynamicApi(Area = "admin")]
|
||
|
|
public class AppViolationStatisticsService : AdminCommonService, IAppViolationStatisticsService, IDynamicApi
|
||
|
|
{
|
||
|
|
#region Identity
|
||
|
|
|
||
|
|
private readonly IEfRepository<AppViolationStatistics, long> _appViolationStatisticsRepository;
|
||
|
|
private readonly IAppDictionaryService _appDictionaryService;
|
||
|
|
private readonly IEfRepository<AppEarlyWarning, long> _appEarlyWarningRepository;
|
||
|
|
private readonly IUserService _userService;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
///
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="appViolationStatisticsRepository"></param>
|
||
|
|
/// <param name="appDictionaryService"></param>
|
||
|
|
/// <param name="appEarlyWarningRepository"></param>
|
||
|
|
/// <param name="userService"></param>
|
||
|
|
public AppViolationStatisticsService(IEfRepository<AppViolationStatistics, long> appViolationStatisticsRepository,
|
||
|
|
IAppDictionaryService appDictionaryService,
|
||
|
|
IEfRepository<AppEarlyWarning, long> appEarlyWarningRepository,
|
||
|
|
IUserService userService,
|
||
|
|
IEfRepository<AppSupervisedPersonRealTimeLocation, long> asprl,
|
||
|
|
IEfRepository<AppCaseManagement, long> appCaseManagementRepository,
|
||
|
|
IEfRepository<AppCaseSupervisedPerson, long> appCaseSupervisedPersonRepository,
|
||
|
|
IEfRepository<AppCaseSupervisor, long> appCaseSupervisorRepository
|
||
|
|
):base(appCaseManagementRepository,
|
||
|
|
appCaseSupervisorRepository,
|
||
|
|
appCaseSupervisedPersonRepository,
|
||
|
|
userService,
|
||
|
|
appDictionaryService,
|
||
|
|
asprl)
|
||
|
|
{
|
||
|
|
_appViolationStatisticsRepository = appViolationStatisticsRepository;
|
||
|
|
_appDictionaryService = appDictionaryService;
|
||
|
|
_appEarlyWarningRepository = appEarlyWarningRepository;
|
||
|
|
_userService = userService;
|
||
|
|
}
|
||
|
|
|
||
|
|
#endregion Identity
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 根据被监管人员违规明细Id分页查询
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[HttpPost]
|
||
|
|
public async Task<IResultOutput> GetPageAsync(AppViolationStatisticsGetPageInput input)
|
||
|
|
{
|
||
|
|
var data = await _appEarlyWarningRepository.AsQueryable(false, true)
|
||
|
|
.Where(w => w.CaseId == input.Id && w.SupervisedPersonId == input.SupervisedPersonId)
|
||
|
|
.OrderByDescending(r => r.CreatedTime)
|
||
|
|
.ProjectTo<AppEarlyWarningListDto>(Mapper.ConfigurationProvider)
|
||
|
|
.PagedAsync(input)
|
||
|
|
.ConfigureAwait(false);
|
||
|
|
|
||
|
|
return ResultOutput.Ok(data);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 违规记录统计
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
[HttpPost]
|
||
|
|
public async Task<IResultOutput> ViolationStatisticsPageAsync(ViolationStatisticsPageInput input)
|
||
|
|
{
|
||
|
|
//根据当前登录人查看其手里的案件被监管人
|
||
|
|
var spList = await base.GetCurrentUserCaseListAsync();
|
||
|
|
//获取案件信息
|
||
|
|
var casebaselist = await spList.Where(q => q.AppCaseManagement != null).Select(q => q.AppCaseManagement).ToListAsync();
|
||
|
|
//获取案件id
|
||
|
|
var casebase = await spList
|
||
|
|
.Where(q => q.AppCaseManagement != null)
|
||
|
|
.WhereIf(input.CaseProgress != null, a => a.AppCaseManagement.CaseProgress == input.CaseProgress).Select(q => q.AppCaseManagement.Id).ToListAsync();
|
||
|
|
var spIds = await spList.Where(q => q.AppCaseSupervisedPerson != null&& casebase.Contains(q.AppCaseSupervisedPerson.CaseId)).Select(w => w.AppCaseSupervisedPerson!.SupervisedPersonId).ToListAsync();
|
||
|
|
//查询记录
|
||
|
|
var query = await _appEarlyWarningRepository
|
||
|
|
.AsQueryable(false, true).Where(q=> spIds.Contains(q.SupervisedPersonId))
|
||
|
|
.WhereIf(input.CaseId != default, a => a.CaseId == input.CaseId)
|
||
|
|
.WhereIf(input.SupervisedPersonId != default, w => w.SupervisedPersonId == input.SupervisedPersonId)
|
||
|
|
.WhereIf(input.TimeSearch?.BeginTime != null && input.TimeSearch?.EndTime != null, q => q.CreatedTime >= input.TimeSearch.BeginTime && q.CreatedTime <= $"{input.TimeSearch.EndTime.Value.ToString("yyyy-MM-dd")} 23:59:59".ToDateTime())
|
||
|
|
.ToListAsync();
|
||
|
|
|
||
|
|
//分组
|
||
|
|
var dataGroup = query
|
||
|
|
.GroupBy(w => new { w.CaseId, w.SupervisedPersonId, w.CaseName, w.SupervisedPersonName });
|
||
|
|
|
||
|
|
var pageData = dataGroup.Skip((input.PageIndex - 1) * input.PageSize)
|
||
|
|
.Take(input.PageSize);
|
||
|
|
//处理身份证字段
|
||
|
|
var userList = await _userService.GetAllByConditionAsync(new BatchIdsInput()
|
||
|
|
{
|
||
|
|
Ids = pageData.Select(w => w.Key.SupervisedPersonId).ToList()
|
||
|
|
});
|
||
|
|
|
||
|
|
var dataList = pageData.Select(data => new ViolationStatisticsListDto()
|
||
|
|
{
|
||
|
|
CaseId = data.Key.CaseId,
|
||
|
|
SupervisedPersonId = data.Key.SupervisedPersonId,
|
||
|
|
CaseName = casebaselist.Where(q=>q.Id==data.Key.CaseId).First()?.Name,
|
||
|
|
//data.Key.CaseName,
|
||
|
|
SupervisedPersonName = data.Key.SupervisedPersonName,
|
||
|
|
CaseProgress = casebaselist.Where(q => q.Id == data.Key.CaseId).First()?.CaseProgress,
|
||
|
|
Violations = data.Count(),
|
||
|
|
IdCard = userList.FirstOrDefault(w => w.Id == data.Key.SupervisedPersonId)?.IdCard
|
||
|
|
}).ToList();
|
||
|
|
|
||
|
|
var pageResult = new PagedList<ViolationStatisticsListDto>()
|
||
|
|
{
|
||
|
|
TotalCount = dataGroup.Count(),
|
||
|
|
Data = dataList
|
||
|
|
};
|
||
|
|
|
||
|
|
return ResultOutput.Ok(pageResult);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 违规人数分页查询
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
[HttpPost]
|
||
|
|
public async Task<IResultOutput> AppEarlyWarningPageAsync(ViolationStatisticsPageInput input)
|
||
|
|
{
|
||
|
|
//根据当前登录人查看其手里的案件被监管人
|
||
|
|
var spList = await _appCaseManagementRepository.AsQueryable(false, true).Where(q => q.IsDeleted == false).ToListAsync();
|
||
|
|
//获取案件id
|
||
|
|
var casebase = spList.Select(q => q.Id);
|
||
|
|
//查询记录
|
||
|
|
var query = await _appEarlyWarningRepository
|
||
|
|
.AsQueryable(false, true).Where(q => casebase.Contains(q.CaseId)&& !string.IsNullOrEmpty(q.Title))
|
||
|
|
.WhereIf(input.CaseId != default, a => a.CaseId == input.CaseId)
|
||
|
|
.WhereIf(input.Wglx != null, a => a.EarlyWarningTypeId == input.Wglx)
|
||
|
|
.WhereIf(input.SupervisedPersonId != default, w => w.SupervisedPersonId == input.SupervisedPersonId)
|
||
|
|
.WhereIf(input.TimeSearch?.BeginTime != null && input.TimeSearch?.EndTime != null, q => q.CreatedTime >= input.TimeSearch.BeginTime && q.CreatedTime <= $"{input.TimeSearch.EndTime.Value.ToString("yyyy-MM-dd")} 23:59:59".ToDateTime())
|
||
|
|
.OrderByDescending(q=>q.CreatedTime)
|
||
|
|
.ToListAsync();
|
||
|
|
|
||
|
|
//分组
|
||
|
|
var dataGroup = query.Distinct((a, b) => a.SupervisedPersonId == b.SupervisedPersonId && a.Title == b.Title);
|
||
|
|
|
||
|
|
var pageData = dataGroup.Skip((input.PageIndex - 1) * input.PageSize)
|
||
|
|
.Take(input.PageSize);
|
||
|
|
//处理身份证字段
|
||
|
|
var userList = await _userService.GetAllByConditionAsync(new BatchIdsInput()
|
||
|
|
{
|
||
|
|
Ids = pageData.Select(w => w.SupervisedPersonId).ToList()
|
||
|
|
});
|
||
|
|
|
||
|
|
var dataList = pageData.Select(data => new ViolationStatisticsListDto()
|
||
|
|
{
|
||
|
|
SupervisedPersonId = data.SupervisedPersonId,
|
||
|
|
CaseName = spList.FirstOrDefault(q => q.Id == data.CaseId)?.Name,
|
||
|
|
CaseProgress = spList.FirstOrDefault(q => q.Id == data.CaseId)?.CaseProgress,
|
||
|
|
//data.Key.CaseName,
|
||
|
|
SupervisedPersonName = data.SupervisedPersonName,
|
||
|
|
IdCard = userList.FirstOrDefault(w => w.Id == data.SupervisedPersonId)?.IdCard,
|
||
|
|
Wgtime= data?.CreatedTime,
|
||
|
|
Wglx = data?.Title,
|
||
|
|
|
||
|
|
}).ToList();
|
||
|
|
|
||
|
|
var pageResult = new PagedList<ViolationStatisticsListDto>()
|
||
|
|
{
|
||
|
|
TotalCount = dataGroup.Count(),
|
||
|
|
Data = dataList
|
||
|
|
};
|
||
|
|
|
||
|
|
return ResultOutput.Ok(pageResult);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 违规人数统计
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
[HttpPost]
|
||
|
|
public async Task<IResultOutput> ViolationStatisticsAsync(ViolationStatisticsPageInput input)
|
||
|
|
{
|
||
|
|
var caseIds = await _appCaseManagementRepository.AsQueryable(false, true).Where(q => q.IsDeleted == false).Select(q => q.Id).ToListAsync();
|
||
|
|
//查询记录
|
||
|
|
var list = await _appEarlyWarningRepository
|
||
|
|
.AsQueryable(false, true)
|
||
|
|
.WhereIf(input.TimeSearch.BeginTime != null && input.TimeSearch.EndTime != null, q => q.CreatedTime >= input.TimeSearch.BeginTime && q.CreatedTime <= $"{input.TimeSearch.EndTime.Value.ToString("yyyy-MM-dd")} 23:59:59".ToDateTime())
|
||
|
|
.WhereIf(input.Wglx!=null, q=>q.EarlyWarningTypeId == input.Wglx)
|
||
|
|
.Where(q => caseIds.Contains(q.CaseId)).ToListAsync();
|
||
|
|
|
||
|
|
var geruplist = list.Where(q=>!string.IsNullOrEmpty(q.Title)).GroupBy(q => q.Title).Select(q => new { name = q.Key, value = q.Distinct((a, b) => a.SupervisedPersonId == b.SupervisedPersonId).Count() });
|
||
|
|
var count = geruplist.Sum(q=>q.value);
|
||
|
|
return ResultOutput.Ok(new { count=count, data = geruplist,list= list.Distinct((a, b) => a.SupervisedPersonId == b.SupervisedPersonId&&a.Title == b.Title).ToList() });
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 添加违规记录
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<IResultOutput> AddAsync(AppViolationStatisticsAddInput input) => await base.AddAsync(input, _appViolationStatisticsRepository);
|
||
|
|
}
|
||
|
|
}
|