BiSnapshotApplication.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using FluentValidation.Results;
  2. using Hotline.FlowEngine.Workflows;
  3. using Hotline.Orders;
  4. using Hotline.Settings.Hotspots;
  5. using Hotline.Share.Attributes;
  6. using Hotline.Share.Dtos.Snapshot;
  7. using Hotline.Share.Enums.FlowEngine;
  8. using Hotline.Share.Enums.Order;
  9. using Hotline.Share.Enums.Snapshot;
  10. using Hotline.Share.Tools;
  11. using Hotline.Snapshot;
  12. using Hotline.Snapshot.Interfaces;
  13. using Hotline.Tools;
  14. using Mapster;
  15. using NPOI.SS.Formula.Functions;
  16. using SqlSugar;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using XF.Domain.Authentications;
  23. using XF.Domain.Dependency;
  24. using XF.Domain.Exceptions;
  25. using XF.Domain.Repository;
  26. using static NPOI.SS.Format.CellNumberFormatter;
  27. namespace Hotline.Application.Snapshot;
  28. public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
  29. {
  30. private readonly IOrderSnapshotRepository _orderSnapshotRepository;
  31. private readonly IRedPackRecordRepository _redPackRecordRepository;
  32. private readonly IIndustryRepository _industryRepository;
  33. private readonly IIndustryCaseRepository _industryCaseRepository;
  34. private readonly IRedPackAuditRepository _redPackAuditRepository;
  35. private readonly IRepository<Hotspot> _hotspotTypeRepository;
  36. private readonly ISessionContext _sessionContext;
  37. public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository, IRepository<Hotspot> hotspotTypeRepository, ISessionContext sessionContext)
  38. {
  39. _orderSnapshotRepository = orderSnapshotRepository;
  40. _redPackRecordRepository = redPackRecordRepository;
  41. _industryRepository = industryRepository;
  42. _industryCaseRepository = industryCaseRepository;
  43. _redPackAuditRepository = redPackAuditRepository;
  44. _hotspotTypeRepository = hotspotTypeRepository;
  45. _sessionContext = sessionContext;
  46. }
  47. public ISugarQueryable<HotspotStatisticsOutDto> GetHotspotStatistics(HotspotStatisticsInDto dto)
  48. {
  49. var IsCenter = _sessionContext.OrgIsCenter;
  50. string count = "2";
  51. string countx = string.Empty;
  52. if (dto.HotspotCode.NotNullOrEmpty())
  53. {
  54. count = (dto.HotspotCode.Length + 2).ToString();
  55. dto.HotspotCode.Length.ToString();
  56. }
  57. return _hotspotTypeRepository.Queryable()
  58. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  59. .LeftJoin<OrderSnapshot>((it, o, s) => o.Id == s.Id)
  60. .Where((it, o, s) => o.CreationTime >= dto.StartTime && o.CreationTime <= dto.EndTime && s.Id != null)
  61. .WhereIF(dto.HotspotCode.IsNullOrEmpty(), (it, o) => o.Id != null)
  62. .WhereIF(dto.HotspotCode.NotNullOrEmpty(), (it, o) => it.ParentId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(countx)) == dto.HotspotCode)
  63. .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  64. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)) })
  65. .Select((it, o) => new
  66. {
  67. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)),
  68. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  69. })
  70. .MergeTable()
  71. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  72. .Select((x, q) => new HotspotStatisticsOutDto
  73. {
  74. HotspotCode = x.HotspotCode,
  75. SumCount = x.SumCount,
  76. HotspotName = q.HotSpotName,
  77. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  78. });
  79. }
  80. /// <summary>
  81. /// 市民红包审批统计
  82. /// </summary>
  83. /// <param name="dto"></param>
  84. /// <param name="requestAborted"></param>
  85. /// <returns></returns>
  86. /// <exception cref="NotImplementedException"></exception>
  87. [ExportExcel("市民红包审核统计")]
  88. public IList<RedPackStatisticsOutDto> GetRedPackAuditStatistics(RedPackStatisticsInDto dto)
  89. {
  90. var industries = _industryRepository.Queryable(includeDeleted: true)
  91. .LeftJoin<IndustryCase>((industry, industryCase) => industry.Id == industryCase.IndustryId && industryCase.IsEnable == true)
  92. .Select((industry, industryCase) => new RedPackStatisticsOutDto
  93. {
  94. Id = industry.Id,
  95. Name = industry.Name,
  96. CaseId = industryCase.Id,
  97. CaseName = industryCase.Name,
  98. ShouldAmount = industryCase.CitizenReadPackAmount == null ? industry.CitizenReadPackAmount : industryCase.CitizenReadPackAmount,
  99. }).ToList();
  100. var redPackOutDto = _redPackAuditRepository.Queryable(includeDeleted: true)
  101. .LeftJoin<OrderSnapshot>((audit, snapshot) => audit.OrderId == snapshot.Id)
  102. .LeftJoin<RedPackRecord>((audit, snapshot, record) => record.RedPackAuditId == audit.Id)
  103. .LeftJoin<SupplementRecord>((audit, snapshot, record, supplement) => supplement.RedPackAuditId == audit.Id)
  104. .Where((audit, snapshot) => audit.CreationTime >= dto.StartTime && audit.CreationTime <= dto.EndTime)
  105. .GroupBy((audit, snapshot) => new { snapshot.IndustryCase, snapshot.IndustryId, snapshot.IndustryName })
  106. .Select((audit, snapshot, record, supplement) => new RedPackStatisticsOutDto
  107. {
  108. Id = snapshot.IndustryId,
  109. Name = snapshot.IndustryName,
  110. CaseId = snapshot.IndustryCase,
  111. ApprovalAmount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.Status == ERedPackAuditStatus.Agree, audit.ApprovedAmount, 0)), //审批同意总金额
  112. ApprovalCount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.Status == ERedPackAuditStatus.Agree, 1, 0)), // 审批同意总个数
  113. SentAmount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.IsSend == true, audit.AcutalAmount, 0)), // 发送成功金额
  114. SentCount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.IsSend == true, 1, 0)), // 发送成功个数
  115. SendFailAmount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Fail, record.Amount, 0)), //发送失败金额
  116. SendFailCount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Fail, 1, 0)), // 发送失败个数
  117. PendingAmount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Unsend, audit.ApprovedAmount, 0)), // 待发金额
  118. PendingCount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Unsend, 1, 0)), // 待发个数
  119. SupplementAmount = SqlFunc.AggregateSum(supplement.ReplenishAmount), // 补充红包金额
  120. SupplementCount = SqlFunc.AggregateCount(supplement.Id), // 补充红包数
  121. }).ToList();
  122. foreach (var industry in industries)
  123. {
  124. var item = redPackOutDto
  125. .WhereIF(industry.CaseId != null, m => m.CaseId == industry.CaseId)
  126. .WhereIF(industry.CaseId == null, m => m.Id == industry.Id)
  127. .FirstOrDefault();
  128. var config = new TypeAdapterConfig();
  129. config.ForType<RedPackStatisticsOutDto, RedPackStatisticsOutDto>()
  130. .Ignore(dest => dest.CaseId)
  131. .Ignore(dest => dest.CaseName)
  132. .Ignore(dest => dest.ShouldAmount);
  133. item?.Adapt(industry, config);
  134. if (industry.CaseId == null)
  135. {
  136. industry.IndustryName = $"{industry.Name}({industry.ShouldAmount?.ToString("f2")})";
  137. industry.IndustryType = 1;
  138. industry.IndustryId = industry.Id;
  139. }
  140. else
  141. {
  142. industry.IndustryType = 2;
  143. industry.IndustryId = industry.CaseId;
  144. if (industry.CaseName == industry.Name)
  145. industry.IndustryName = $"{industry.Name}({industry.ShouldAmount?.ToString("f2")})";
  146. else
  147. {
  148. industry.IndustryName = $"{industry.Name}-{industry.CaseName}({industry.ShouldAmount?.ToString("f2")})";
  149. }
  150. }
  151. }
  152. return industries;
  153. }
  154. public ISugarQueryable<RedPackStatisticsDetailsOutDto> GetRedPackAuditStatisticsDetails(RedPackStatisticsDetailsInDto dto)
  155. {
  156. dto.ValidateObject();
  157. dto.FieldName = dto.FieldName.ToLower();
  158. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  159. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  160. .LeftJoin<RedPackAudit>((snapshot, order, audit) => snapshot.Id == audit.OrderId)
  161. .LeftJoin<RedPackRecord>((snapshot, order, audit, record) => audit.Id == record.RedPackAuditId)
  162. .LeftJoin<SupplementRecord>((snapshot, order, audit, record, supplement) => audit.Id == supplement.RedPackAuditId)
  163. .Where((snapshot, order, audit) => audit.CreationTime >= dto.StartTime && audit.CreationTime <= dto.EndTime)
  164. .WhereIF(dto.IndustryType == 1, (snapshot, order, audit) => snapshot.IndustryId == dto.IndustryId)
  165. .WhereIF(dto.IndustryType == 2, (snapshot, order, audit) => snapshot.IndustryCase == dto.IndustryId);
  166. query = dto.FieldName switch
  167. {
  168. "approvalamount" => query.Where((snapshot, order, audit) => audit.Status == ERedPackAuditStatus.Agree),
  169. "approvalcount" => query.Where((snapshot, order, audit) => audit.Status == ERedPackAuditStatus.Agree),
  170. "sentamount" => query.Where((snapshot, order, audit) => audit.IsSend == true),
  171. "sentcount" => query.Where((snapshot, order, audit) => audit.IsSend == true),
  172. "sendfailamount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Fail),
  173. "sendfailcount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Fail),
  174. "pendingamount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Unsend),
  175. "pendingcount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Unsend),
  176. "supplementamount" => query.Where((snapshot, order, audit, record, supplement) => supplement.Id != null),
  177. "supplementcount" => query.Where((snapshot, order, audit, record, supplement) => supplement.Id != null),
  178. _ => throw new UserFriendlyException($"不支持输入字段: {dto.FieldName}")
  179. };
  180. return query.Select((snapshot, order, audit, record, supplement) => new RedPackStatisticsDetailsOutDto
  181. {
  182. CreationTime = order.CreationTime
  183. }, true);
  184. }
  185. public async Task<SnapshotStatisticsOutDto> GetSnapshotStatisticsAsync(SnapshotStatisticsInDto dto, CancellationToken token)
  186. {
  187. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  188. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  189. .LeftJoin<RedPackAudit>((snapshot, order, redPackAudit) => snapshot.Id == redPackAudit.OrderId)
  190. .LeftJoin<SpecialRedPackAudit>((snapshot, order, redPackAudit, special) => snapshot.Id == special.OrderId)
  191. .LeftJoin<RedPackGuiderAudit>((snapshot, order, redPackAudit, special, guiderAudit) => snapshot.Id == guiderAudit.OrderId)
  192. .LeftJoin<RedPackRecord>((snapshot, order, redPackAudit, special, guiderAudit, record) => redPackAudit.Id == record.RedPackAuditId)
  193. .LeftJoin<OrderSecondaryHandling>((snapshot, order, redPackAudit, special, guiderAudit, record, second) => snapshot.Id == second.OrderId)
  194. .LeftJoin<OrderSpecial>((snapshot, order, redPackAudit, special, guiderAudit, record, second, orderSpecial) => snapshot.Id == orderSpecial.OrderId)
  195. .Where((snapshot) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime)
  196. .Select((snapshot, order, redPackAudit, special, guiderAudit, record, second, orderSpecial) => new SnapshotStatisticsOutDto
  197. {
  198. WZSLFWNJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.HotspotName == "非受理范围", 1, 0)), // 未在受理范围内件数,
  199. SSPZ12345JS = SqlFunc.AggregateSum(SqlFunc.IIF(order.SourceChannelCode == "SJP12345", 1, 0)), // 随手拍转12345件数,
  200. SLFWNZJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.HotspotName != "非受理范围" && order.SourceChannelCode == "SJP12345", 1, 0)), // 受理范围内总件数,
  201. SLFWNPGWGYSXSNHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) > snapshot.SendGuidSystemTime, 1, 0)), // 受理范围内派给网格员四小时内回复件数,
  202. SLFWNPGWGYCGSXSHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) <= snapshot.SendGuidSystemTime, 1, 0)), // 受理范围内派给网格员超过四小时回复件数
  203. SLFWNPGWGYWHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == false, 1, 0)), // 受理范围内派给网格员未回复件数
  204. SLFWNA12345ZPGGBMJS = 0, //受理范围内按12345直派给各部门件数,
  205. SLFWNA12345ZPGGQXJS = 0, //受理范围内按12345直派给各区县件数
  206. ZXYB = SqlFunc.AggregateSum(SqlFunc.IIF(order.FileOrgIsCenter == true, 1, 0)), // 中心已办
  207. BMYB = SqlFunc.AggregateSum(SqlFunc.IIF(order.FileOrgIsCenter == false, 1, 0)), // 部门已办
  208. SLFWMYD = 0, //受理范围满意度
  209. MYL = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "2"), 0, 1)), // 满意量
  210. BMYL = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "2"), 1, 0)), // 不满意量
  211. SPBTYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.Status == ERedPackAuditStatus.Refuse, 1, 0)), // 审批不同意红包个数
  212. SPTYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.Status == ERedPackAuditStatus.Agree, 1, 0)), // 审批同意红包个数
  213. TSHBSP = 0, //特殊红包审批统计
  214. SPTYGS = SqlFunc.AggregateSum(SqlFunc.IIF(special.Status == ERedPackAuditStatus.Agree, 1, 0)), //审批同意个数
  215. YFJE = SqlFunc.AggregateSum(SqlFunc.IIF(special.IsSend == true, special.AcutalAmount, 0)), // 已发金额
  216. JSHFFWGJLGS = 0, //局审核发放网格员奖励个数
  217. SPTYWGYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree, 1, 0)), //审批同意(网格员)红包个数
  218. SPBTYWGYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelOneStatus == ERedPackAuditStatus.Refuse || guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Refuse, 1, 0)), //审批不同意(网格员)红包个数
  219. SMJLZE = SqlFunc.AggregateSum(redPackAudit.AcutalAmount), // 市民奖励总额
  220. SMYFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.IsSend == true, redPackAudit.AcutalAmount, 0)), // 市民已发放奖励总额
  221. SMDFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.IsSend == false, redPackAudit.ApprovedAmount, 0)), // 市民待发奖励总额
  222. YFG = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.IsSend == true, 1, 0)), //已发(个)
  223. WFLXG = 0, // 无法联系(个)
  224. WJHBG = SqlFunc.AggregateSum(SqlFunc.IIF(record.FailCase == ERedPackPickupFailCase.Excuse, 1, 0)), // 婉拒红包(个)
  225. WGYYFJLJE = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree, guiderAudit.AcutalAmount, 0)), //网格员应发奖励金额
  226. WGYYFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.IsSend == true, guiderAudit.AcutalAmount, 0)), // 网格员已发放奖励总额
  227. WGYDFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree && guiderAudit.IsSend == false, guiderAudit.ApprovedAmount, 0)), // 网格员待发放奖励总额
  228. WGYKKZEYF = 0, // 网格员扣款总额(已发)
  229. WGYKKZEDF = 0, // 网格员扣款总额(待发)
  230. SLFWNDBMHQJJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.CounterSignType != null, 1, 0)), // 受理范围内多部门会签件件数
  231. SLFWNRXZXGDJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.FileOrgIsCenter == true, 1, 0)), // 受理范围内热线中心归档件数
  232. RXZXFQHQJJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.CounterSignType != null && order.CounterSignType == ECounterSignType.Center, 1, 0)), // 热线中心发起会签件件数
  233. AQYH = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsDangerDepartment == true, 1, 0)), // 安全隐患
  234. YWCAQYHZG = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsRectifyDepartment == true, 1, 0)), // 已完成安全隐患整改
  235. SQYQGDJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count(m => m.DelayState == EDelayState.Pass) > 0, 1, 0)), // 申请延期工单件数
  236. SQYQGDCS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count() > 0, order.OrderDelays.Count(m => m.DelayState == EDelayState.Pass), 0)), // 申请延期工单次数
  237. CQJ = SqlFunc.AggregateSum(SqlFunc.IIF(order.Status >= EOrderStatus.Filed && order.ExpiredTime < order.FiledTime, 1, 0)), // 超期件
  238. ECBLJSTHBM = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && second.ApplyOrgId != "001", 1, 0)), // 二次办理件数 - 退回部门
  239. ECBLJSHFBMYCB = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled, 1, 0)), // 二次办理件数-回访不满意重办
  240. ECBLJSTTDYYJBM = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled, 1, 0)), // 二次办理件数-特提到原一级部门
  241. 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)), // 二次办理件数-回访满意
  242. // ECBLGDMYL = , // 二次办理工单满意率
  243. 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)), // 二次办理工单件数-退回部门回访满意
  244. // ECBLGDMYLTHBM = , // 二次办理工单满意率-退回部门
  245. // ECBLGDMYLHFBMYCB = 0, // 二次办理工单满意率-回访不满意重办
  246. TTDYYJBMJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && orderSpecial.NextStepName == "一级部门", 1, 0)), // 特提到原一级部门件数
  247. TTDPDZJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && orderSpecial.NextStepName == "派单组", 1, 0)), // 特提到派单组件数
  248. QTTTJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && (orderSpecial.NextStepName != "一级部门" || orderSpecial.NextStepName != "派单组"), 1, 0)), // 其他特提件数
  249. });
  250. return await query.FirstAsync();
  251. }
  252. public ISugarQueryable<SnapshotStatisticsDetailOutDto> GetSnapshotStatisticsDetail(SnapshotStatisticsDetailInDto dto)
  253. {
  254. dto.FieldName = dto.FieldName.ToUpper();
  255. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  256. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  257. .LeftJoin<RedPackAudit>((snapshot, order, redPackAudit) => snapshot.Id == redPackAudit.OrderId)
  258. .LeftJoin<SpecialRedPackAudit>((snapshot, order, redPackAudit, special) => snapshot.Id == special.OrderId)
  259. .LeftJoin<RedPackGuiderAudit>((snapshot, order, redPackAudit, special, guiderAudit) => snapshot.Id == guiderAudit.OrderId)
  260. .Where((snapshot, order) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime);
  261. query = dto.FieldName switch
  262. {
  263. "WZSLFWNJS" => query.Where((snapshot, order) => order.SourceChannelCode != "SSP"),
  264. "SSPZ12345JS" => query.Where((snapshot, order) => order.SourceChannelCode != "SSP"),
  265. "SLFWNPGWGYSXSNHFJS" => query.Where((snapshot, order) => snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime!.Value.AddHours(-4) <= snapshot.SendGuidSystemTime),
  266. "SLFWNPGWGYCGSXSHFJS" => query.Where((snapshot, order) => snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime!.Value.AddHours(-4) <= snapshot.SendGuidSystemTime),
  267. "SLFWNPGWGYWHFJS" => query.Where((snapshot, order) => snapshot.IsGuidSystemCallBack == false),
  268. "ZXYB" => query.Where((snapshop, order) => order.FileOrgIsCenter == true),
  269. "BMYB" => query.Where((snapshop, order) => order.FileOrgIsCenter == false),
  270. "MYL" => query.Where((snapshot, order) => SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "-1") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "3") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "4") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "5")),
  271. "BMYL" => query.Where((snapshot, order) => SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "2")),
  272. "SPBTYHBGS" => query.Where((snapshot, order, redPackAudit) => redPackAudit.Status == ERedPackAuditStatus.Refuse),
  273. "SPTYHBGS" => query.Where((snapshot, order, redPackAudit) => redPackAudit.Status == ERedPackAuditStatus.Agree),
  274. "SPTYGS" => query.Where((snapshot, order, redPackAudit, special) => special.Status == ERedPackAuditStatus.Agree),
  275. "YFJE" => query.Where((snapshot, order, redPackAudit, special) => special.IsSend == true),
  276. "SPTYWGYHBGS" => query.Where((snapshot, order, redPackAudit, special, guiderAudit) => guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree),
  277. "SPBTYWGYHBGS" => query.Where((snapshot, order, redPackAudit, special, guiderAudit) => guiderAudit.LevelOneStatus == ERedPackAuditStatus.Refuse || guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Refuse),
  278. _ => throw new UserFriendlyException("入参错误:" + dto.FieldName + " 未实现")
  279. };
  280. return query.Select((snapshot, order, redPackAudit, special, guiderAudit) => new SnapshotStatisticsDetailOutDto
  281. {
  282. CreationTime = order.CreationTime
  283. }, true);
  284. }
  285. }