|
@@ -7,6 +7,8 @@ using Hotline.Share.Enums.Order;
|
|
|
using Hotline.Share.Enums.Snapshot;
|
|
|
using Hotline.Snapshot;
|
|
|
using Hotline.Snapshot.Interfaces;
|
|
|
+using Hotline.Tools;
|
|
|
+using Mapster;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using SqlSugar;
|
|
|
using System;
|
|
@@ -22,10 +24,125 @@ namespace Hotline.Application.Snapshot;
|
|
|
public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
|
|
|
{
|
|
|
public readonly IOrderSnapshotRepository _orderSnapshotRepository;
|
|
|
+ public readonly IRedPackRecordRepository _redPackRecordRepository;
|
|
|
+ public readonly IIndustryRepository _industryRepository;
|
|
|
+ public readonly IIndustryCaseRepository _industryCaseRepository;
|
|
|
+ public readonly IRedPackAuditRepository _redPackAuditRepository;
|
|
|
|
|
|
- public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository)
|
|
|
+ public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository)
|
|
|
{
|
|
|
_orderSnapshotRepository = orderSnapshotRepository;
|
|
|
+ _redPackRecordRepository = redPackRecordRepository;
|
|
|
+ _industryRepository = industryRepository;
|
|
|
+ _industryCaseRepository = industryCaseRepository;
|
|
|
+ _redPackAuditRepository = redPackAuditRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 市民红包审批统计
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="requestAborted"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public async Task<IList<RedPackStatisticsOutDto>> GetRedPackAuditStatisticsAsync(RedPackStatisticsInDto dto, CancellationToken requestAborted)
|
|
|
+ {
|
|
|
+ var industries = await _industryRepository.Queryable(includeDeleted: true)
|
|
|
+ .LeftJoin<IndustryCase>((industry, industryCase) => industry.Id == industryCase.IndustryId && industryCase.IsEnable == true)
|
|
|
+ .Select((industry, industryCase) => new RedPackStatisticsOutDto
|
|
|
+ {
|
|
|
+ Id = industry.Id,
|
|
|
+ Name = industry.Name,
|
|
|
+ CaseId = industryCase.Id,
|
|
|
+ CaseName = industryCase.Name,
|
|
|
+ ShouldAmount = industryCase.CitizenReadPackAmount == null ? industry.CitizenReadPackAmount : industryCase.CitizenReadPackAmount,
|
|
|
+ }).ToListAsync();
|
|
|
+
|
|
|
+ var redPackOutDto = await _redPackAuditRepository.Queryable(includeDeleted: true)
|
|
|
+ .LeftJoin<OrderSnapshot>((audit, snapshot) => audit.OrderId == snapshot.Id)
|
|
|
+ .LeftJoin<RedPackRecord>((audit, snapshot, record) => record.RedPackAuditId == audit.Id)
|
|
|
+ .LeftJoin<SupplementRecord>((audit, snapshot, record, supplement) => supplement.RedPackAuditId == audit.Id)
|
|
|
+ .Where((audit, snapshot) => audit.CreationTime >= dto.StartTime && audit.CreationTime <= dto.EndTime)
|
|
|
+ .GroupBy((audit, snapshot) => new { snapshot.IndustryCase, snapshot.IndustryId, snapshot.IndustryName })
|
|
|
+ .Select((audit, snapshot, record, supplement) => new RedPackStatisticsOutDto
|
|
|
+ {
|
|
|
+ Id = snapshot.IndustryId,
|
|
|
+ Name = snapshot.IndustryName,
|
|
|
+ CaseId = snapshot.IndustryCase,
|
|
|
+ ApprovalAmount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.Status == ERedPackAuditStatus.Agree, audit.ApprovedAmount, 0)), //审批同意总金额
|
|
|
+ ApprovalCount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.Status == ERedPackAuditStatus.Agree, 1, 0)), // 审批同意总个数
|
|
|
+ SentAmount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.IsSend == true, audit.AcutalAmount, 0)), // 发送成功金额
|
|
|
+ SentCount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.IsSend == true, 1, 0)), // 发送成功个数
|
|
|
+ SendFailAmount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Fail, record.Amount, 0)), //发送失败金额
|
|
|
+ SendFailCount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Fail, 1, 0)), // 发送失败个数
|
|
|
+ PendingAmount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Unsend, audit.ApprovedAmount, 0)), // 待发金额
|
|
|
+ PendingCount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Unsend, 1, 0)), // 待发个数
|
|
|
+ SupplementAmount = SqlFunc.AggregateSum(supplement.ReplenishAmount), // 补充红包金额
|
|
|
+ SupplementCount = SqlFunc.AggregateCount(supplement.Id), // 补充红包数
|
|
|
+ }).ToListAsync();
|
|
|
+
|
|
|
+ foreach (var industry in industries)
|
|
|
+ {
|
|
|
+ var item = redPackOutDto
|
|
|
+ .WhereIF(industry.CaseId != null, m => m.CaseId == industry.CaseId)
|
|
|
+ .WhereIF(industry.CaseId == null, m => m.Id == industry.Id)
|
|
|
+ .FirstOrDefault();
|
|
|
+
|
|
|
+ var config = new TypeAdapterConfig();
|
|
|
+ config.ForType<RedPackStatisticsOutDto, RedPackStatisticsOutDto>()
|
|
|
+ .Ignore(dest => dest.CaseId)
|
|
|
+ .Ignore(dest => dest.CaseName)
|
|
|
+ .Ignore(dest => dest.ShouldAmount);
|
|
|
+ item?.Adapt(industry, config);
|
|
|
+ if (industry.CaseId == null)
|
|
|
+ {
|
|
|
+ industry.IndustryName = $"{industry.Name}({industry.ShouldAmount?.ToString("f2")})";
|
|
|
+ industry.IndustryType = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ industry.IndustryType = 2;
|
|
|
+ if (industry.CaseName == industry.Name)
|
|
|
+ industry.IndustryName = $"{industry.Name}({industry.ShouldAmount?.ToString("f2")})";
|
|
|
+ else
|
|
|
+ {
|
|
|
+ industry.IndustryName = $"{industry.Name}-{industry.CaseName}({industry.ShouldAmount?.ToString("f2")})";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return industries;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ISugarQueryable<RedPackStatisticsDetailsOutDto> GetRedPackAuditStatisticsDetails(RedPackStatisticsDetailsInDto dto)
|
|
|
+ {
|
|
|
+ dto.ValidateObject();
|
|
|
+ dto.FieldName = dto.FieldName.ToLower();
|
|
|
+ var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
|
|
|
+ .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
|
|
|
+ .LeftJoin<RedPackAudit>((snapshot, order, audit) => snapshot.Id == audit.OrderId)
|
|
|
+ .LeftJoin<RedPackRecord>((snapshot, order, audit, record) => audit.Id == record.RedPackAuditId)
|
|
|
+ .LeftJoin<SupplementRecord>((snapshot, order, audit, record, supplement) => audit.Id == supplement.RedPackAuditId)
|
|
|
+ .Where((snapshot, order, audit) => audit.CreationTime >= dto.StartTime && audit.CreationTime <= dto.EndTime)
|
|
|
+ .WhereIF(dto.IndustryType == 1, (snapshot, order, audit) => snapshot.IndustryId == dto.IndustryId)
|
|
|
+ .WhereIF(dto.IndustryType == 2, (snapshot, order, audit) => snapshot.IndustryCase == dto.IndustryId);
|
|
|
+ query = dto.FieldName switch
|
|
|
+ {
|
|
|
+ "approvalamount" => query.Where((snapshot, order, audit) => audit.Status == ERedPackAuditStatus.Agree),
|
|
|
+ "approvalcount" => query.Where((snapshot, order, audit) => audit.Status == ERedPackAuditStatus.Agree),
|
|
|
+ "sentamount" => query.Where((snapshot, order, audit) => audit.IsSend == true),
|
|
|
+ "sentcount" => query.Where((snapshot, order, audit) => audit.IsSend == true),
|
|
|
+ "sendfailamount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Fail),
|
|
|
+ "sendfailcount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Fail),
|
|
|
+ "pendingamount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Unsend),
|
|
|
+ "pendingcount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Unsend),
|
|
|
+ "supplementamount" => query.Where((snapshot, order, audit, record, supplement) => supplement.Id != null),
|
|
|
+ "supplementcount" => query.Where((snapshot, order, audit, record, supplement) => supplement.Id != null),
|
|
|
+ _ => throw new UserFriendlyException($"不支持输入字段: {dto.FieldName}")
|
|
|
+ };
|
|
|
+ return query.Select((snapshot, order, audit, record, supplement) => new RedPackStatisticsDetailsOutDto
|
|
|
+ {
|
|
|
+ CreationTime = order.CreationTime
|
|
|
+ }, true);
|
|
|
}
|
|
|
|
|
|
public async Task<SnapshotStatisticsOutDto> GetSnapshotStatisticsAsync(SnapshotStatisticsInDto dto, CancellationToken token)
|
|
@@ -41,9 +158,9 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
|
|
|
.Where((snapshot) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime)
|
|
|
.Select((snapshot, order, redPackAudit, special, guiderAudit, record, second, orderSpecial) => new SnapshotStatisticsOutDto
|
|
|
{
|
|
|
- WZSLFWNJS = 0, // 未在受理范围内件数,
|
|
|
- SSPZ12345JS = SqlFunc.AggregateSum(SqlFunc.IIF(order.SourceChannelCode != "SSP", 1, 0)), // 随手拍转12345件数,
|
|
|
- SLFWNZJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.SourceChannelCode == "SSP", 1, 0)), // 受理范围内总件数,
|
|
|
+ WZSLFWNJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.HotspotName == "非受理范围", 1, 0)), // 未在受理范围内件数,
|
|
|
+ SSPZ12345JS = SqlFunc.AggregateSum(SqlFunc.IIF(order.SourceChannelCode == "SJP12345", 1, 0)), // 随手拍转12345件数,
|
|
|
+ SLFWNZJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.HotspotName != "非受理范围" && order.SourceChannelCode == "SJP12345", 1, 0)), // 受理范围内总件数,
|
|
|
SLFWNPGWGYSXSNHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) > snapshot.SendGuidSystemTime, 1, 0)), // 受理范围内派给网格员四小时内回复件数,
|
|
|
SLFWNPGWGYCGSXSHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) <= snapshot.SendGuidSystemTime, 1, 0)), // 受理范围内派给网格员超过四小时回复件数
|
|
|
SLFWNPGWGYWHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == false, 1, 0)), // 受理范围内派给网格员未回复件数
|
|
@@ -76,23 +193,25 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
|
|
|
SLFWNDBMHQJJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.CounterSignType != null, 1, 0)), // 受理范围内多部门会签件件数
|
|
|
SLFWNRXZXGDJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.FileOrgIsCenter == true, 1, 0)), // 受理范围内热线中心归档件数
|
|
|
RXZXFQHQJJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.CounterSignType != null && order.CounterSignType == ECounterSignType.Center, 1, 0)), // 热线中心发起会签件件数
|
|
|
- AQYH = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsDangerDepartment== true, 1, 0)), // 安全隐患
|
|
|
+ AQYH = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsDangerDepartment == true, 1, 0)), // 安全隐患
|
|
|
YWCAQYHZG = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsRectifyDepartment == true, 1, 0)), // 已完成安全隐患整改
|
|
|
- SQYQGDJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count(m => m.DelayState == Share.Enums.Order.EDelayState.Pass) > 0, 1, 0)), // 申请延期工单件数
|
|
|
- SQYQGDCS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count() > 0, order.OrderDelays.Count(m => m.DelayState == Share.Enums.Order.EDelayState.Pass), 0)), // 申请延期工单次数
|
|
|
+ SQYQGDJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count(m => m.DelayState == EDelayState.Pass) > 0, 1, 0)), // 申请延期工单件数
|
|
|
+ SQYQGDCS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count() > 0, order.OrderDelays.Count(m => m.DelayState == EDelayState.Pass), 0)), // 申请延期工单次数
|
|
|
CQJ = SqlFunc.AggregateSum(SqlFunc.IIF(order.Status >= EOrderStatus.Filed && order.ExpiredTime < order.FiledTime, 1, 0)), // 超期件
|
|
|
- ECBLJSTHBM = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && second.ApplyOrgName != "市民热线服务中心", 1, 0)), // 二次办理件数 - 退回部门
|
|
|
- ECBLJSHFBMYCB = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "2", 1, 0)), // 二次办理件数-回访不满意重办
|
|
|
- ECBLJSTTDYYJBM = 0, // 二次办理件数-特提到原一级部门
|
|
|
- ECBLJSHFMY = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && (SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "5" || SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "4" || SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "-1" || SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "0"), 1, 0)), // 二次办理件数-回访满意
|
|
|
+ ECBLJSTHBM = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && second.ApplyOrgId != "001", 1, 0)), // 二次办理件数 - 退回部门
|
|
|
+ ECBLJSHFBMYCB = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled, 1, 0)), // 二次办理件数-回访不满意重办
|
|
|
+ ECBLJSTTDYYJBM = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled, 1, 0)), // 二次办理件数-特提到原一级部门
|
|
|
+ ECBLJSHFMY = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && (SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "5" || SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "4" || SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "-1" || SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "0"), 1, 0)), // 二次办理件数-回访满意
|
|
|
// ECBLGDMYL = , // 二次办理工单满意率
|
|
|
- ECBLGDJSTMBMHFMYD = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && second.ApplyOrgName != "市民热线服务中心" && (SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "5" || SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "4" || SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "-1" || SqlFunc.JsonField(second.VisitDetail.OrgHandledAttitude, "Key") == "0"), 1, 0)), // 二次办理工单件数-退回部门回访满意
|
|
|
+ ECBLGDJSTMBMHFMYD = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && second.ApplyOrgId != "001" && (SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "5" || SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "4" || SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "-1" || SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "0"), 1, 0)), // 二次办理工单件数-退回部门回访满意
|
|
|
// ECBLGDMYLTHBM = , // 二次办理工单满意率-退回部门
|
|
|
// ECBLGDMYLHFBMYCB = 0, // 二次办理工单满意率-回访不满意重办
|
|
|
|
|
|
TTDYYJBMJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && orderSpecial.NextStepName == "一级部门", 1, 0)), // 特提到原一级部门件数
|
|
|
TTDPDZJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && orderSpecial.NextStepName == "派单组", 1, 0)), // 特提到派单组件数
|
|
|
- QTTTJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.IsDeleted == false && orderSpecial.SpecialType == ESpecialType.Special && (orderSpecial.NextStepName != "一级部门" || orderSpecial.NextStepName != "派单组"), 1, 0)), // 其他特提件数
|
|
|
+ QTTTJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && (orderSpecial.NextStepName != "一级部门" || orderSpecial.NextStepName != "派单组"), 1, 0)), // 其他特提件数
|
|
|
+
|
|
|
+
|
|
|
});
|
|
|
return await query.FirstAsync();
|
|
|
}
|