BiSnapshotApplication.cs 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. using FluentValidation.Results;
  2. using Hotline.Configurations;
  3. using Hotline.FlowEngine.Workflows;
  4. using Hotline.Orders;
  5. using Hotline.Repository.SqlSugar.Orders;
  6. using Hotline.Settings;
  7. using Hotline.Settings.Hotspots;
  8. using Hotline.Share.Attributes;
  9. using Hotline.Share.Dtos;
  10. using Hotline.Share.Dtos.Order;
  11. using Hotline.Share.Dtos.Snapshot;
  12. using Hotline.Share.Enums.FlowEngine;
  13. using Hotline.Share.Enums.Order;
  14. using Hotline.Share.Enums.Snapshot;
  15. using Hotline.Share.Requests;
  16. using Hotline.Share.Tools;
  17. using Hotline.Snapshot;
  18. using Hotline.Snapshot.Interfaces;
  19. using Hotline.Tools;
  20. using Mapster;
  21. using MediatR;
  22. using Microsoft.AspNetCore.Http;
  23. using Microsoft.AspNetCore.Mvc;
  24. using Microsoft.Extensions.Options;
  25. using NPOI.SS.Formula.Functions;
  26. using Org.BouncyCastle.Asn1.Pkcs;
  27. using SqlSugar;
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Linq;
  31. using System.Text;
  32. using System.Threading.Tasks;
  33. using XF.Domain.Authentications;
  34. using XF.Domain.Dependency;
  35. using XF.Domain.Exceptions;
  36. using XF.Domain.Repository;
  37. using static NPOI.HSSF.Util.HSSFColor;
  38. using static NPOI.SS.Format.CellNumberFormatter;
  39. namespace Hotline.Application.Snapshot;
  40. public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
  41. {
  42. private readonly IOrderSnapshotRepository _orderSnapshotRepository;
  43. private readonly IRedPackRecordRepository _redPackRecordRepository;
  44. private readonly IIndustryRepository _industryRepository;
  45. private readonly IIndustryCaseRepository _industryCaseRepository;
  46. private readonly IRedPackAuditRepository _redPackAuditRepository;
  47. private readonly IRepository<Hotspot> _hotspotTypeRepository;
  48. private readonly ISessionContext _sessionContext;
  49. private readonly IOrderRepository _orderRepository;
  50. private readonly ICommunityInfoRepository _communityInfoRepository;
  51. private readonly IRepository<SystemArea> _systemAreaRepository;
  52. private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
  53. public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository, IRepository<Hotspot> hotspotTypeRepository, ISessionContext sessionContext, IOrderRepository orderRepository, ICommunityInfoRepository communityInfoRepository, IRepository<SystemArea> systemAreaRepository, IOptionsSnapshot<AppConfiguration> appOptions)
  54. {
  55. _orderSnapshotRepository = orderSnapshotRepository;
  56. _redPackRecordRepository = redPackRecordRepository;
  57. _industryRepository = industryRepository;
  58. _industryCaseRepository = industryCaseRepository;
  59. _redPackAuditRepository = redPackAuditRepository;
  60. _hotspotTypeRepository = hotspotTypeRepository;
  61. _sessionContext = sessionContext;
  62. _orderRepository = orderRepository;
  63. _communityInfoRepository = communityInfoRepository;
  64. _systemAreaRepository = systemAreaRepository;
  65. _appOptions = appOptions;
  66. }
  67. public ISugarQueryable<HotspotStatisticsOutDto> GetHotspotStatistics(HotspotStatisticsInDto dto)
  68. {
  69. var IsCenter = _sessionContext.OrgIsCenter;
  70. string count = "2";
  71. string countx = string.Empty;
  72. if (dto.HotspotCode.NotNullOrEmpty())
  73. {
  74. count = (dto.HotspotCode.Length + 2).ToString();
  75. countx = dto.HotspotCode.Length.ToString();
  76. }
  77. return _hotspotTypeRepository.Queryable()
  78. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  79. .LeftJoin<OrderSnapshot>((it, o, s) => o.Id == s.Id)
  80. .Where((it, o, s) => o.CreationTime >= dto.StartTime && o.CreationTime <= dto.EndTime && s.Id != null)
  81. .WhereIF(dto.HotspotCode.IsNullOrEmpty(), (it, o) => o.Id != null)
  82. .WhereIF(dto.HotspotCode.NotNullOrEmpty(), (it, o) => it.ParentId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(countx)) == dto.HotspotCode)
  83. .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  84. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)) })
  85. .Select((it, o) => new
  86. {
  87. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)),
  88. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  89. })
  90. .MergeTable()
  91. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  92. .Select((x, q) => new HotspotStatisticsOutDto
  93. {
  94. HotspotCode = x.HotspotCode,
  95. SumCount = x.SumCount,
  96. HotspotName = q.HotSpotName,
  97. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  98. });
  99. }
  100. /// <summary>
  101. /// 热点类型小类统计明细
  102. /// </summary>
  103. /// <param name="dto"></param>
  104. /// <returns></returns>
  105. public ISugarQueryable<HotspotStatisticsDetailsOutDto> HotspotStatisticsDetail([FromQuery] HotspotStatisticsDetailsInDto dto)
  106. {
  107. var IsCenter = _sessionContext.OrgIsCenter;
  108. IsCenter = true;
  109. var query = _orderRepository.Queryable()
  110. .Includes(d => d.OrderVisits)
  111. .Where(d => d.CreationTime >= dto.StartTime && d.CreationTime <= dto.EndTime)
  112. .WhereIF(dto.HotspotCode.NotNullOrEmpty(), d => d.HotspotId.StartsWith(dto.HotspotCode))
  113. .WhereIF(IsCenter == false, d => d.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  114. .Select(d => new HotspotStatisticsDetailsOutDto
  115. {
  116. OrderScreenStatus = SqlFunc.Subqueryable<OrderScreen>().Where(q => q.OrderId == d.Id).OrderByDesc(q => q.CreationTime).Select(q => q.Status), //x.OrderScreens.FirstOrDefault().Status,
  117. }, true);
  118. return query;
  119. }
  120. /// <summary>
  121. /// 市民红包审批统计
  122. /// </summary>
  123. /// <param name="dto"></param>
  124. /// <param name="requestAborted"></param>
  125. /// <returns></returns>
  126. /// <exception cref="NotImplementedException"></exception>
  127. [ExportExcel("市民红包审核统计")]
  128. public IList<RedPackStatisticsOutDto> GetRedPackAuditStatistics(RedPackStatisticsInDto dto)
  129. {
  130. var industries = _industryRepository.Queryable(includeDeleted: true)
  131. .LeftJoin<IndustryCase>((industry, industryCase) => industry.Id == industryCase.IndustryId && industryCase.IsEnable == true)
  132. .Select((industry, industryCase) => new RedPackStatisticsOutDto
  133. {
  134. Id = industry.Id,
  135. Name = industry.Name,
  136. CaseId = industryCase.Id,
  137. CaseName = industryCase.Name,
  138. ShouldAmount = industryCase.CitizenReadPackAmount == null ? industry.CitizenReadPackAmount : industryCase.CitizenReadPackAmount,
  139. }).ToList();
  140. var redPackOutDto = _redPackAuditRepository.Queryable(includeDeleted: true)
  141. .LeftJoin<OrderSnapshot>((audit, snapshot) => audit.OrderId == snapshot.Id)
  142. .LeftJoin<RedPackRecord>((audit, snapshot, record) => record.RedPackAuditId == audit.Id)
  143. .LeftJoin<SupplementRecord>((audit, snapshot, record, supplement) => supplement.RedPackAuditId == audit.Id)
  144. .Where((audit, snapshot) => audit.CreationTime >= dto.StartTime && audit.CreationTime <= dto.EndTime)
  145. .GroupBy((audit, snapshot) => new { snapshot.IndustryCase, snapshot.IndustryId, snapshot.IndustryName })
  146. .Select((audit, snapshot, record, supplement) => new RedPackStatisticsOutDto
  147. {
  148. Id = snapshot.IndustryId,
  149. Name = snapshot.IndustryName,
  150. CaseId = snapshot.IndustryCase,
  151. ApprovalAmount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.Status == ERedPackAuditStatus.Agree, audit.ApprovedAmount, 0)), //审批同意总金额
  152. ApprovalCount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.Status == ERedPackAuditStatus.Agree, 1, 0)), // 审批同意总个数
  153. SentAmount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.IsSend == true, audit.AcutalAmount, 0)), // 发送成功金额
  154. SentCount = SqlFunc.AggregateSum(SqlFunc.IIF(audit.IsSend == true, 1, 0)), // 发送成功个数
  155. SendFailAmount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Fail, record.Amount, 0)), //发送失败金额
  156. SendFailCount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Fail, 1, 0)), // 发送失败个数
  157. PendingAmount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Unsend, audit.ApprovedAmount, 0)), // 待发金额
  158. PendingCount = SqlFunc.AggregateSum(SqlFunc.IIF(record.DistributionState == EReadPackSendStatus.Unsend, 1, 0)), // 待发个数
  159. SupplementAmount = SqlFunc.AggregateSum(supplement.ReplenishAmount), // 补充红包金额
  160. SupplementCount = SqlFunc.AggregateCount(supplement.Id), // 补充红包数
  161. }).ToList();
  162. foreach (var industry in industries)
  163. {
  164. var item = redPackOutDto
  165. .WhereIF(industry.CaseId != null, m => m.CaseId == industry.CaseId)
  166. .WhereIF(industry.CaseId == null, m => m.Id == industry.Id)
  167. .FirstOrDefault();
  168. var config = new TypeAdapterConfig();
  169. config.ForType<RedPackStatisticsOutDto, RedPackStatisticsOutDto>()
  170. .Ignore(dest => dest.CaseId)
  171. .Ignore(dest => dest.CaseName)
  172. .Ignore(dest => dest.ShouldAmount);
  173. item?.Adapt(industry, config);
  174. if (industry.CaseId == null)
  175. {
  176. industry.IndustryName = $"{industry.Name}({industry.ShouldAmount?.ToString("f2")})";
  177. industry.IndustryType = 1;
  178. industry.IndustryId = industry.Id;
  179. }
  180. else
  181. {
  182. industry.IndustryType = 2;
  183. industry.IndustryId = industry.CaseId;
  184. if (industry.CaseName == industry.Name)
  185. industry.IndustryName = $"{industry.Name}({industry.ShouldAmount?.ToString("f2")})";
  186. else
  187. {
  188. industry.IndustryName = $"{industry.Name}-{industry.CaseName}({industry.ShouldAmount?.ToString("f2")})";
  189. }
  190. }
  191. }
  192. return industries;
  193. }
  194. public ISugarQueryable<RedPackStatisticsDetailsOutDto> GetRedPackAuditStatisticsDetails(RedPackStatisticsDetailsInDto dto)
  195. {
  196. dto.ValidateObject();
  197. dto.FieldName = dto.FieldName.ToLower();
  198. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  199. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  200. .LeftJoin<RedPackAudit>((snapshot, order, audit) => snapshot.Id == audit.OrderId)
  201. .LeftJoin<RedPackRecord>((snapshot, order, audit, record) => audit.Id == record.RedPackAuditId)
  202. .LeftJoin<SupplementRecord>((snapshot, order, audit, record, supplement) => audit.Id == supplement.RedPackAuditId)
  203. .Where((snapshot, order, audit) => audit.CreationTime >= dto.StartTime && audit.CreationTime <= dto.EndTime)
  204. .WhereIF(dto.IndustryType == 1, (snapshot, order, audit) => snapshot.IndustryId == dto.IndustryId)
  205. .WhereIF(dto.IndustryType == 2, (snapshot, order, audit) => snapshot.IndustryCase == dto.IndustryId);
  206. query = dto.FieldName switch
  207. {
  208. "approvalamount" => query.Where((snapshot, order, audit) => audit.Status == ERedPackAuditStatus.Agree),
  209. "approvalcount" => query.Where((snapshot, order, audit) => audit.Status == ERedPackAuditStatus.Agree),
  210. "sentamount" => query.Where((snapshot, order, audit) => audit.IsSend == true),
  211. "sentcount" => query.Where((snapshot, order, audit) => audit.IsSend == true),
  212. "sendfailamount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Fail),
  213. "sendfailcount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Fail),
  214. "pendingamount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Unsend),
  215. "pendingcount" => query.Where((snapshot, order, audit, record) => record.DistributionState == EReadPackSendStatus.Unsend),
  216. "supplementamount" => query.Where((snapshot, order, audit, record, supplement) => supplement.Id != null),
  217. "supplementcount" => query.Where((snapshot, order, audit, record, supplement) => supplement.Id != null),
  218. _ => throw new UserFriendlyException($"不支持输入字段: {dto.FieldName}")
  219. };
  220. return query.Select((snapshot, order, audit, record, supplement) => new RedPackStatisticsDetailsOutDto
  221. {
  222. CreationTime = order.CreationTime
  223. }, true);
  224. }
  225. public async Task<SnapshotStatisticsOutDto> GetSnapshotStatisticsAsync(SnapshotStatisticsInDto dto, CancellationToken token)
  226. {
  227. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  228. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  229. .LeftJoin<RedPackAudit>((snapshot, order, redPackAudit) => snapshot.Id == redPackAudit.OrderId)
  230. .LeftJoin<SpecialRedPackAudit>((snapshot, order, redPackAudit, special) => snapshot.Id == special.OrderId)
  231. .LeftJoin<RedPackGuiderAudit>((snapshot, order, redPackAudit, special, guiderAudit) => snapshot.Id == guiderAudit.OrderId)
  232. .LeftJoin<RedPackRecord>((snapshot, order, redPackAudit, special, guiderAudit, record) => redPackAudit.Id == record.RedPackAuditId)
  233. .LeftJoin<OrderSecondaryHandling>((snapshot, order, redPackAudit, special, guiderAudit, record, second) => snapshot.Id == second.OrderId)
  234. .LeftJoin<OrderSpecial>((snapshot, order, redPackAudit, special, guiderAudit, record, second, orderSpecial) => snapshot.Id == orderSpecial.OrderId)
  235. .Where((snapshot) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime)
  236. .Select((snapshot, order, redPackAudit, special, guiderAudit, record, second, orderSpecial) => new SnapshotStatisticsOutDto
  237. {
  238. WZSLFWNJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.HotspotName == "非受理范围", 1, 0)), // 未在受理范围内件数,
  239. SSPZ12345JS = SqlFunc.AggregateSum(SqlFunc.IIF(order.SourceChannelCode == "SJP12345", 1, 0)), // 随手拍转12345件数,
  240. SLFWNZJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.HotspotName != "非受理范围" && order.SourceChannelCode == "SJP12345", 1, 0)), // 受理范围内总件数,
  241. SLFWNPGWGYSXSNHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) > snapshot.SendGuidSystemTime, 1, 0)), // 受理范围内派给网格员四小时内回复件数,
  242. SLFWNPGWGYCGSXSHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) <= snapshot.SendGuidSystemTime, 1, 0)), // 受理范围内派给网格员超过四小时回复件数
  243. SLFWNPGWGYWHFJS = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsGuidSystemCallBack == false, 1, 0)), // 受理范围内派给网格员未回复件数
  244. SLFWNA12345ZPGGBMJS = 0, //受理范围内按12345直派给各部门件数,
  245. SLFWNA12345ZPGGQXJS = 0, //受理范围内按12345直派给各区县件数
  246. ZXYB = SqlFunc.AggregateSum(SqlFunc.IIF(order.FileOrgIsCenter == true, 1, 0)), // 中心已办
  247. BMYB = SqlFunc.AggregateSum(SqlFunc.IIF(order.FileOrgIsCenter == false, 1, 0)), // 部门已办
  248. SLFWMYD = 0, //受理范围满意度
  249. MYL = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "2"), 0, 1)), // 满意量
  250. BMYL = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "2"), 1, 0)), // 不满意量
  251. SPBTYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.Status == ERedPackAuditStatus.Refuse, 1, 0)), // 审批不同意红包个数
  252. SPTYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.Status == ERedPackAuditStatus.Agree, 1, 0)), // 审批同意红包个数
  253. TSHBSP = 0, //特殊红包审批统计
  254. SPTYGS = SqlFunc.AggregateSum(SqlFunc.IIF(special.Status == ERedPackAuditStatus.Agree, 1, 0)), //审批同意个数
  255. YFJE = SqlFunc.AggregateSum(SqlFunc.IIF(special.IsSend == true, special.AcutalAmount, 0)), // 已发金额
  256. JSHFFWGJLGS = 0, //局审核发放网格员奖励个数
  257. SPTYWGYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree, 1, 0)), //审批同意(网格员)红包个数
  258. SPBTYWGYHBGS = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelOneStatus == ERedPackAuditStatus.Refuse || guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Refuse, 1, 0)), //审批不同意(网格员)红包个数
  259. SMJLZE = SqlFunc.AggregateSum(redPackAudit.AcutalAmount), // 市民奖励总额
  260. SMYFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.IsSend == true, redPackAudit.AcutalAmount, 0)), // 市民已发放奖励总额
  261. SMDFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.IsSend == false, redPackAudit.ApprovedAmount, 0)), // 市民待发奖励总额
  262. YFG = SqlFunc.AggregateSum(SqlFunc.IIF(redPackAudit.IsSend == true, 1, 0)), //已发(个)
  263. WFLXG = 0, // 无法联系(个)
  264. WJHBG = SqlFunc.AggregateSum(SqlFunc.IIF(record.FailCase == ERedPackPickupFailCase.Excuse, 1, 0)), // 婉拒红包(个)
  265. WGYYFJLJE = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree, guiderAudit.AcutalAmount, 0)), //网格员应发奖励金额
  266. WGYYFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.IsSend == true, guiderAudit.AcutalAmount, 0)), // 网格员已发放奖励总额
  267. WGYDFFJLZE = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree && guiderAudit.IsSend == false, guiderAudit.ApprovedAmount, 0)), // 网格员待发放奖励总额
  268. WGYKKZEYF = 0, // 网格员扣款总额(已发)
  269. WGYKKZEDF = 0, // 网格员扣款总额(待发)
  270. SLFWNDBMHQJJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.CounterSignType != null, 1, 0)), // 受理范围内多部门会签件件数
  271. SLFWNRXZXGDJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.FileOrgIsCenter == true, 1, 0)), // 受理范围内热线中心归档件数
  272. RXZXFQHQJJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.CounterSignType != null && order.CounterSignType == ECounterSignType.Center, 1, 0)), // 热线中心发起会签件件数
  273. AQYH = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsDangerDepartment == true, 1, 0)), // 安全隐患
  274. YWCAQYHZG = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsRectifyDepartment == true, 1, 0)), // 已完成安全隐患整改
  275. SQYQGDJS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count(m => m.DelayState == EDelayState.Pass) > 0, 1, 0)), // 申请延期工单件数
  276. SQYQGDCS = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderDelays.Count() > 0, order.OrderDelays.Count(m => m.DelayState == EDelayState.Pass), 0)), // 申请延期工单次数
  277. CQJ = SqlFunc.AggregateSum(SqlFunc.IIF(order.Status >= EOrderStatus.Filed && order.ExpiredTime < order.FiledTime, 1, 0)), // 超期件
  278. ECBLJSTHBM = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && second.ApplyOrgId != "001", 1, 0)), // 二次办理件数 - 退回部门
  279. ECBLJSHFBMYCB = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled, 1, 0)), // 二次办理件数-回访不满意重办
  280. ECBLJSTTDYYJBM = SqlFunc.AggregateSum(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled, 1, 0)), // 二次办理件数-特提到原一级部门
  281. 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)), // 二次办理件数-回访满意
  282. // ECBLGDMYL = , // 二次办理工单满意率
  283. 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)), // 二次办理工单件数-退回部门回访满意
  284. // ECBLGDMYLTHBM = , // 二次办理工单满意率-退回部门
  285. // ECBLGDMYLHFBMYCB = 0, // 二次办理工单满意率-回访不满意重办
  286. TTDYYJBMJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && orderSpecial.NextStepName == "一级部门", 1, 0)), // 特提到原一级部门件数
  287. TTDPDZJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && orderSpecial.NextStepName == "派单组", 1, 0)), // 特提到派单组件数
  288. QTTTJS = SqlFunc.AggregateSum(SqlFunc.IIF(orderSpecial.State == 1 && orderSpecial.SpecialType == ESpecialType.Special && (orderSpecial.NextStepName != "一级部门" || orderSpecial.NextStepName != "派单组"), 1, 0)), // 其他特提件数
  289. });
  290. return await query.FirstAsync();
  291. }
  292. public ISugarQueryable<SnapshotStatisticsDetailOutDto> GetSnapshotStatisticsDetail(SnapshotStatisticsDetailInDto dto)
  293. {
  294. dto.FieldName = dto.FieldName.ToUpper();
  295. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  296. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  297. .LeftJoin<RedPackAudit>((snapshot, order, redPackAudit) => snapshot.Id == redPackAudit.OrderId)
  298. .LeftJoin<SpecialRedPackAudit>((snapshot, order, redPackAudit, special) => snapshot.Id == special.OrderId)
  299. .LeftJoin<RedPackGuiderAudit>((snapshot, order, redPackAudit, special, guiderAudit) => snapshot.Id == guiderAudit.OrderId)
  300. .Where((snapshot, order) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime);
  301. query = dto.FieldName switch
  302. {
  303. "WZSLFWNJS" => query.Where((snapshot, order) => order.SourceChannelCode != "SSP"),
  304. "SSPZ12345JS" => query.Where((snapshot, order) => order.SourceChannelCode != "SSP"),
  305. "SLFWNPGWGYSXSNHFJS" => query.Where((snapshot, order) => snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime!.Value.AddHours(-4) <= snapshot.SendGuidSystemTime),
  306. "SLFWNPGWGYCGSXSHFJS" => query.Where((snapshot, order) => snapshot.IsGuidSystemCallBack == true && snapshot.GuidSystemCallBackTime!.Value.AddHours(-4) <= snapshot.SendGuidSystemTime),
  307. "SLFWNPGWGYWHFJS" => query.Where((snapshot, order) => snapshot.IsGuidSystemCallBack == false),
  308. "ZXYB" => query.Where((snapshop, order) => order.FileOrgIsCenter == true),
  309. "BMYB" => query.Where((snapshop, order) => order.FileOrgIsCenter == false),
  310. "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")),
  311. "BMYL" => query.Where((snapshot, order) => SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(order.OrgProcessingResults, "key", "2")),
  312. "SPBTYHBGS" => query.Where((snapshot, order, redPackAudit) => redPackAudit.Status == ERedPackAuditStatus.Refuse),
  313. "SPTYHBGS" => query.Where((snapshot, order, redPackAudit) => redPackAudit.Status == ERedPackAuditStatus.Agree),
  314. "SPTYGS" => query.Where((snapshot, order, redPackAudit, special) => special.Status == ERedPackAuditStatus.Agree),
  315. "YFJE" => query.Where((snapshot, order, redPackAudit, special) => special.IsSend == true),
  316. "SPTYWGYHBGS" => query.Where((snapshot, order, redPackAudit, special, guiderAudit) => guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree),
  317. "SPBTYWGYHBGS" => query.Where((snapshot, order, redPackAudit, special, guiderAudit) => guiderAudit.LevelOneStatus == ERedPackAuditStatus.Refuse || guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Refuse),
  318. _ => throw new UserFriendlyException("入参错误:" + dto.FieldName + " 未实现")
  319. };
  320. return query.Select((snapshot, order, redPackAudit, special, guiderAudit) => new SnapshotStatisticsDetailOutDto
  321. {
  322. CreationTime = order.CreationTime
  323. }, true);
  324. }
  325. /// <summary>
  326. /// 办件统计-随手拍
  327. /// </summary>
  328. /// <param name="dto"></param>
  329. /// <returns></returns>
  330. /// <exception cref="NotImplementedException"></exception>
  331. public ISugarQueryable<SnapshotProcessingStatisticsOutDto> GetSnapshotProcessingStatistics(SnapshotProcessingStatisticsInDto dto)
  332. {
  333. bool IsCenter = _sessionContext.OrgIsCenter;
  334. var orgLevel = _sessionContext.OrgLevel;
  335. string orgLevelStr = (_sessionContext.RequiredOrgId.Length + 3).ToString();
  336. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  337. .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
  338. .LeftJoin<OrderSendBackAudit>((snapshot, order, back) => snapshot.Id == back.OrderId && back.State == ESendBackAuditState.End)
  339. .LeftJoin<OrderVisit>((snapshot, order, back, visit) => snapshot.Id == visit.OrderId && visit.VisitState == EVisitState.Visited)
  340. .LeftJoin<OrderSecondaryHandling>((snapshot, order, back, visit, second) => snapshot.Id == second.OrderId && second.State == ESecondaryHandlingState.End)
  341. .Where(snapshot => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime)
  342. .WhereIF(dto.IndustryId.NotNullOrEmpty(), snapshot => snapshot.IndustryId == dto.IndustryId)
  343. .GroupBy((snapshot, order) => new
  344. {
  345. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  346. })
  347. .Select((snapshot, order, back, visit, second) => new SnapshotProcessingStatisticsOutDto()
  348. {
  349. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  350. YbOrderCountNum = SqlFunc.AggregateCount(SqlFunc.IIF(order.Status >= EOrderStatus.Filed, 1, 0)),
  351. ZbOrderCountNum = SqlFunc.AggregateCount(SqlFunc.IIF(order.Status < EOrderStatus.Filed, 1, 0)),
  352. ReceiveIn20Minutes = SqlFunc.AggregateCount(SqlFunc.IIF(order.ActualHandleStepCreateTime != null && order.ActualHandleStepCreateTime.Value.AddMinutes(-20) <= order.CreationTime, 1, 0)),
  353. ReceiveOut20Minutes = SqlFunc.AggregateCount(SqlFunc.IIF(order.ActualHandleStepCreateTime == null || order.ActualHandleStepCreateTime.Value.AddMinutes(-20) > order.CreationTime, 1, 0)),
  354. BackNum = SqlFunc.AggregateCount(SqlFunc.IIF(back.OrderId != null && back.OrderId != "", 1, 0)),
  355. TotalHandleDuration = SqlFunc.AggregateSum(order.HandleDuration),
  356. End3Day = SqlFunc.AggregateSum(SqlFunc.IIF(order.FiledTime != null && order.FiledTime.Value.AddDays(-3) < order.CreationTime, 1, 0)),
  357. End3To5Day = SqlFunc.AggregateSum(SqlFunc.IIF(order.FiledTime != null && order.FiledTime.Value.AddDays(-3) > order.CreationTime && order.FiledTime.Value.AddDays(-5) < order.CreationTime, 1, 0)),
  358. End5To7Day = SqlFunc.AggregateSum(SqlFunc.IIF(order.FiledTime != null && order.FiledTime.Value.AddDays(-5) > order.CreationTime && order.FiledTime.Value.AddDays(-7) < order.CreationTime, 1, 0)),
  359. End7Day = SqlFunc.AggregateSum(SqlFunc.IIF(order.FiledTime != null && order.FiledTime.Value.AddDays(-7) < order.CreationTime, 1, 0)),
  360. OnTimeCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.FiledTime <= order.ExpiredTime, 1, 0)),
  361. SatisfiedCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "1") || SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "2"), 1, 0)),
  362. NoSatisfiedCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "1") || SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "2"), 0, 1)),
  363. SecondNum = SqlFunc.AggregateCount(second.Id)
  364. })
  365. .MergeTable()
  366. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  367. .Select((it, o) => new SnapshotProcessingStatisticsOutDto()
  368. {
  369. OrgName = o.Name,
  370. OrgCode = it.OrgCode,
  371. YbOrderCountNum = it.YbOrderCountNum,
  372. ZbOrderCountNum = it.ZbOrderCountNum,
  373. ReceiveIn20Minutes = it.ReceiveIn20Minutes,
  374. ReceiveOut20Minutes = it.ReceiveOut20Minutes,
  375. BackNum = it.BackNum,
  376. TotalHandleDuration = it.TotalHandleDuration,
  377. End3Day = it.End3Day,
  378. End3To5Day = it.End3To5Day,
  379. End5To7Day = it.End5To7Day,
  380. End7Day = it.End7Day,
  381. OnTimeCount = it.OnTimeCount,
  382. SatisfiedCount = it.SatisfiedCount,
  383. NoSatisfiedCount = it.NoSatisfiedCount,
  384. SecondNum = it.SecondNum
  385. });
  386. return query;
  387. }
  388. public ISugarQueryable<SnapshotProcessingStatisticsDetailsOutDto> GetSnapshotProcessingStatisticsDetails(SnapshotProcessingStatisticsDetailsInDto dto)
  389. {
  390. dto.FieldName = dto.FieldName.ToLower();
  391. var IsCenter = _sessionContext.OrgIsCenter;
  392. IsCenter = true;
  393. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  394. .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
  395. .LeftJoin<OrderSendBackAudit>((snapshot, order, back) => snapshot.Id == back.OrderId && back.State == ESendBackAuditState.End)
  396. .LeftJoin<OrderVisit>((snapshot, order, back, visit) => snapshot.Id == visit.OrderId && visit.VisitState == EVisitState.Visited)
  397. .LeftJoin<OrderSecondaryHandling>((snapshot, order, back, visit, second) => snapshot.Id == second.OrderId && second.State == ESecondaryHandlingState.End)
  398. .Where((snapshot, order, back) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime && order.ActualHandleOrgCode.StartsWith(dto.OrgId))
  399. .WhereIF(IsCenter == false, (snapshot, order, back) => order.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  400. .WhereIF(dto.IndustryId.NotNullOrEmpty(), (snapshot, order, back) => snapshot.IndustryId == dto.IndustryId);
  401. query = dto.FieldName switch
  402. {
  403. "ybordercountnum" => query.Where((snapshot, order, back) => order.Status >= EOrderStatus.Filed),
  404. "zbordercountnum" => query.Where((snapshot, order, back) => order.Status < EOrderStatus.Filed),
  405. "receivein20minutes" => query.Where((snapshot, order, back) => order.ActualHandleStepCreateTime != null && order.ActualHandleStepCreateTime.Value.AddMinutes(-20) <= order.CreationTime),
  406. "receiveout20minutes" => query.Where((snapshot, order, back) => order.ActualHandleStepCreateTime == null || order.ActualHandleStepCreateTime.Value.AddMinutes(-20) > order.CreationTime),
  407. "backnum" => query.Where((snapshot, order, back) => back.OrderId != null && back.OrderId != ""),
  408. "end3day" => query.Where((snapshot, order, back) => order.FiledTime != null && order.FiledTime.Value.AddDays(-3) < order.CreationTime),
  409. "end3to5day" => query.Where((snapshot, order, back) => order.FiledTime != null && order.FiledTime.Value.AddDays(-3) > order.CreationTime && order.FiledTime.Value.AddDays(-5) < order.CreationTime),
  410. "end5to7day" => query.Where((snapshot, order, back) => order.FiledTime != null && order.FiledTime.Value.AddDays(-5) > order.CreationTime && order.FiledTime.Value.AddDays(-7) < order.CreationTime),
  411. "end7day" => query.Where((snapshot, order, back) => order.FiledTime != null && order.FiledTime.Value.AddDays(-7) < order.CreationTime),
  412. "satisfiedcount" => query.Where((snapshot, order, back, visit) => SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "1") || SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "2")),
  413. "nosatisfiedcount" => query.Where((snapshot, order, back, visit) => SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "1") || SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "2")),
  414. "secondnum" => query.Where((snapshot, order, back, visit, second) => second.Id != null || second.Id != ""),
  415. _ => throw new UserFriendlyException($"入参: {dto.FieldName} 异常")
  416. };
  417. return query.Select((snapshot, order, back, visit, second) => new SnapshotProcessingStatisticsDetailsOutDto
  418. {
  419. OrderScreenStatus = SqlFunc.Subqueryable<OrderScreen>().Where(q => q.OrderId == order.Id).OrderByDesc(q => q.CreationTime).Select(q => q.Status),
  420. }, true);
  421. }
  422. public ISugarQueryable<GuiderWorkStatisticsOutDto> GetGuiderWorkStatisticsAsync(GuiderWorkStatisticsInDto dto)
  423. {
  424. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  425. .Where(snapshot => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && snapshot.MemberName != null)
  426. .GroupBy(snapshot => new { snapshot.MemberName, snapshot.MemberMobile })
  427. .Select(snapshot => new GuiderWorkStatisticsOutDto
  428. {
  429. MemberMobile = snapshot.MemberMobile,
  430. MemberName = snapshot.MemberName,
  431. ReplyIn4HourCount = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.ReplyResultType == EGuiderSystemReplyType.Field && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) <= snapshot.SendGuidSystemTime, 1, 0)),
  432. ReplyOut4HourCount = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.ReplyResultType == EGuiderSystemReplyType.Field && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) > snapshot.SendGuidSystemTime, 1, 0)),
  433. UnReplyCount = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.ReplyResultType != EGuiderSystemReplyType.Field, 1, 0)),
  434. });
  435. return query;
  436. }
  437. public ISugarQueryable<GuiderWorkStatisticsDetailsOutDto> GetGuiderWorkStatisticsDetails(GuiderWorkStatisticsDetailsInDto dto)
  438. {
  439. dto.FieldName = dto.FieldName.ToLower();
  440. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  441. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  442. .Where(snapshot => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && snapshot.MemberMobile == dto.MemberMobile);
  443. query = dto.FieldName switch
  444. {
  445. "replyin4hourcount" => query.Where(snapshot => snapshot.ReplyResultType == EGuiderSystemReplyType.Field && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) <= snapshot.SendGuidSystemTime),
  446. "replyout4hourcount" => query.Where(snapshot => snapshot.ReplyResultType == EGuiderSystemReplyType.Field && snapshot.GuidSystemCallBackTime.Value.AddHours(-4) > snapshot.SendGuidSystemTime),
  447. "unreplycount" => query.Where(snapshot => snapshot.ReplyResultType != EGuiderSystemReplyType.Field),
  448. _ => throw new UserFriendlyException($"入参: {dto.FieldName} 异常")
  449. };
  450. return query.Select((snapshot, order) => new GuiderWorkStatisticsDetailsOutDto
  451. {
  452. }, true);
  453. }
  454. public ISugarQueryable<HotspotDataStatisticsOutDto> GetHotspotDataStatisticsAsync(HotspotDataStatisticsInDto dto)
  455. {
  456. var isCenter = _sessionContext.OrgIsCenter;
  457. var query = _hotspotTypeRepository.Queryable(includeDeleted: true)
  458. .LeftJoin<Order>((hotspot, order) => order.HotspotSpliceName != null && (hotspot.HotSpotName == order.HotspotSpliceName || order.HotspotSpliceName.Contains(hotspot.HotSpotName)) && order.IsDeleted == false && order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime)
  459. .WhereIF(isCenter == false, (hotspot, order) => order.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  460. .Where(hotspot => hotspot.ParentId == null)
  461. .GroupBy((hotspot, order) => new { hotspot.Id, hotspot.HotSpotName })
  462. .Select((hotspot, order) => new HotspotDataStatisticsOutDto
  463. {
  464. Name = hotspot.HotSpotName,
  465. OrderCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.Id != null, 1, 0)),
  466. });
  467. return query;
  468. }
  469. public ISugarQueryable<GuiderWorkLogsOutDto> GetGuiderWorkLogs(GuiderWorkLogsInDto dto)
  470. {
  471. var query = _orderSnapshotRepository.Queryable()
  472. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  473. .Where((snapshot, order) => snapshot.IsGuidSystemCallBack == true)
  474. .WhereIF(dto.MemberMobile.NotNullOrEmpty(), snapshot => snapshot.MemberMobile.Contains(dto.MemberMobile))
  475. .WhereIF(dto.BeginCreationTime != null && dto.EndCreationTime != null, snapshot => snapshot.CreationTime >= dto.BeginCreationTime && snapshot.CreationTime <= dto.EndCreationTime)
  476. .WhereIF(dto.MemberName.NotNullOrEmpty(), snapshot => snapshot.MemberName.Contains(dto.MemberName))
  477. .WhereIF(dto.No.NotNullOrEmpty(), (snapshot, order) => order.No.Contains(dto.No))
  478. .WhereIF(dto.Title.NotNullOrEmpty(), (snapshot, order) => order.Title.Contains(dto.Title))
  479. .WhereIF(dto.NetworkENumber.NotNullOrEmpty(), (snapshot, order) => snapshot.NetworkENumber.Contains(dto.NetworkENumber))
  480. .WhereIF(dto.Status != null, (snapshot, order) => order.Status == dto.Status)
  481. .OrderByDescending(snapshot => snapshot.CreationTime)
  482. .Select(snapshot => new GuiderWorkLogsOutDto(), true);
  483. return query;
  484. }
  485. public ISugarQueryable<DuplicateItemsOutDto> GetDuplicateItems(DuplicateItemsInDto dto)
  486. {
  487. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  488. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  489. .WhereIF(dto.No.NotNullOrEmpty(), (snapshot, order) => order.No.Contains(dto.No))
  490. .WhereIF(dto.Title.NotNullOrEmpty(), (snapshot, order) => order.Title.Contains(dto.Title))
  491. .WhereIF(dto.FromName.NotNullOrEmpty(), (snapshot, order) => order.FromName.Contains(dto.FromName))
  492. .WhereIF(dto.FromPhone.NotNullOrEmpty(), (snapshot, order) => order.FromPhone.Contains(dto.FromPhone))
  493. .WhereIF(dto.BeginCreationTime != null && dto.EndCreationTime != null, (snapshot, order) => order.CreationTime >= dto.BeginCreationTime && order.CreationTime <= dto.EndCreationTime)
  494. .WhereIF(dto.BeginExpiredTime != null && dto.EndExpiredTime != null, (snapshot, order) => order.ExpiredTime >= dto.BeginExpiredTime && order.ExpiredTime <= dto.EndExpiredTime)
  495. .WhereIF(dto.ActualHandleOrgName.NotNullOrEmpty(), (snapshot, order) => order.ActualHandleOrgName == dto.ActualHandleOrgName)
  496. .WhereIF(dto.AcceptType.NotNullOrEmpty(), (snapshot, order) => order.AcceptType == dto.AcceptType)
  497. .WhereIF(dto.HotspotName.NotNullOrEmpty(), (snapshot, order) => order.HotspotName == dto.HotspotName)
  498. .WhereIF(dto.AcceptorName.NotNullOrEmpty(), (snapshot, order) => order.AcceptorName == dto.AcceptorName)
  499. .WhereIF(dto.IndustryId.NotNullOrEmpty(), (snapshot, order) => snapshot.IndustryId == dto.IndustryId)
  500. .Select((snapshot, order) => new DuplicateItemsOutDto(), true);
  501. return query;
  502. }
  503. public ISugarQueryable<CommunityStatisticsOutDto> GetCommunityStatistics(CommunityStatisticsInDto dto)
  504. {
  505. var query = _communityInfoRepository.Queryable(includeDeleted: true)
  506. .LeftJoin<OrderSnapshot>((it, s) => s.CommunityFullName.Contains(it.FullName) && s.CreationTime >= dto.StartTime && s.CreationTime <= dto.EndTime)
  507. .WhereIF(dto.CommunityCode.IsNullOrEmpty(), (it, s) => it.ParentCode == null)
  508. .WhereIF(dto.CommunityCode.NotNullOrEmpty(), (it, s) => it.ParentCode == dto.CommunityCode)
  509. .WhereIF(dto.IndustryId.NotNullOrEmpty(), (it, s) => s.IndustryId == dto.IndustryId)
  510. .GroupBy((it, s) => new { it.Name, it.Id })
  511. .Select((it, s) => new CommunityStatisticsOutDto
  512. {
  513. CommunityCode = it.Id,
  514. CommunityName = it.Name,
  515. CommunityFullName = it.FullName,
  516. SumCount = SqlFunc.Subqueryable<OrderSnapshot>().Where(snapshot => snapshot.CommunityFullName!.Contains(it.FullName)).Count(),
  517. HasChild = SqlFunc.Subqueryable<CommunityInfo>().Where(c => c.ParentCode == it.Id).Any()
  518. });
  519. #if DEBUG
  520. var sql = query.ToSqlString();
  521. #endif
  522. return query;
  523. }
  524. public ISugarQueryable<CommunityStatisticsDetailsOutDto> GetCommunityStatisticsDetails(CommunityStatisticsDetailsInDto dto)
  525. {
  526. var communityFullName = _communityInfoRepository.Queryable().Where(c => c.Id == dto.CommunityCode).Select(c => c.FullName).First();
  527. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  528. .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
  529. .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && snapshot.CommunityFullName!.Contains(communityFullName))
  530. .WhereIF(dto.IndustryId.NotNullOrEmpty(), (snapshot, order) => snapshot.IndustryId == dto.IndustryId)
  531. .Select((snapshot, order) => new CommunityStatisticsDetailsOutDto(), true);
  532. #if DEBUG
  533. var sql = query.ToSqlString();
  534. #endif
  535. return query;
  536. }
  537. [ExportExcel("随手拍区域统计", "County")]
  538. public ISugarQueryable<CountyRedPackStatisticsOutDto> GetCountyRedPackStatistics(CountyRedPackStatisticsInDto dto)
  539. {
  540. var parentId = _appOptions.Value.AreaCode;
  541. var query = _systemAreaRepository.Queryable(includeDeleted: true)
  542. .LeftJoin<Order>((area, order) => order.County == area.AreaName && order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime && order.County != null)
  543. .LeftJoin<OrderSnapshot>((area, order, snapshot) => snapshot.Id == order.Id && (dto.IndustryId.IsNullOrEmpty() || snapshot.IndustryId == dto.IndustryId))
  544. .LeftJoin<RedPackAudit>((area, order, snapshot, audit) => snapshot.Id == audit.OrderId)
  545. .LeftJoin<RedPackRecord>((area, order, snapshot, audit, record) => audit.Id == record.RedPackAuditId)
  546. .LeftJoin<SupplementRecord>((area, order, snapshot, audit, record, supplement) => supplement.RedPackAuditId == audit.Id)
  547. .LeftJoin<RedPackGuiderAudit>((area, order, snapshot, audit, record, supplement, guiderAudit) => guiderAudit.OrderId == snapshot.Id)
  548. .LeftJoin<RedPackRecord>((area, order, snapshot, audit, record, supplement, guiderAudit, guiderRecord) => guiderAudit.Id == guiderRecord.RedPackAuditId)
  549. .LeftJoin<Industry>((area, order, snapshot, audit, record, supplement, guiderAudit, guiderRecord, industry) => snapshot.IndustryId == industry.Id)
  550. .Where((area, order, snapshot, audit, record, supplement, guiderAudit, guiderRecord) => area.ParentId == parentId || area.AreaName == "外地")
  551. .GroupBy((area, order, snapshot, audit, record, supplement, guiderAudit, guiderRecord) => new { area.AreaName, order.County })
  552. .Select((area, order, snapshot, audit, record, supplement, guiderAudit, guiderRecord, industry) => new CountyRedPackStatisticsOutDto
  553. {
  554. County = area.AreaName,
  555. JuBaoZongShu = SqlFunc.AggregateSum(SqlFunc.IIF(industry.IndustryType == EIndustryType.Clue, 1, 0)),
  556. YiBanJieShu = SqlFunc.AggregateSum(SqlFunc.IIF(order.Status >= EOrderStatus.Filed && industry.IndustryType == EIndustryType.Clue, 1, 0)),
  557. ShiMinShenHeTongGuoShu = SqlFunc.AggregateSum(SqlFunc.IIF(record.PeopleType == EReadPackUserType.Citizen && audit.Status == ERedPackAuditStatus.Agree, 1, 0)),
  558. ShiMinZongJinE = SqlFunc.AggregateSum(SqlFunc.IIF(record.PeopleType == EReadPackUserType.Citizen && audit.Status == ERedPackAuditStatus.Agree, audit.ApprovedAmount, 0)),
  559. ShiMinYiLing = SqlFunc.AggregateSum(SqlFunc.IIF(record.PeopleType == EReadPackUserType.Citizen && record.PickupStatus == ERedPackPickupStatus.Received, record.Amount, 0)),
  560. ShiMinDaiLing = SqlFunc.AggregateSum(SqlFunc.IIF(record.PeopleType == EReadPackUserType.Citizen && record.PickupStatus == ERedPackPickupStatus.Unreceived, record.Amount, 0)),
  561. ShiMinDaiBuLing = SqlFunc.AggregateSum(SqlFunc.IIF(record.PeopleType == EReadPackUserType.Citizen && supplement.Id != null, supplement.ReplenishAmount, 0)),
  562. WangGeYuanZongJianShu = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsDeal == true, 1, 0)),
  563. WangGeYuanShenHeTongGuoShu = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree, 1, 0)),
  564. WangGeYuanZongJinE = SqlFunc.AggregateSum(SqlFunc.IIF(guiderAudit.LevelTwoStatus == ERedPackAuditStatus.Agree, guiderAudit.ApprovedAmount, 0)),
  565. WangGeYuanYiLing = SqlFunc.AggregateSum(SqlFunc.IIF(guiderRecord.PickupStatus == ERedPackPickupStatus.Received, guiderRecord.Amount, 0)),
  566. WangGeYuanDaiLing = SqlFunc.AggregateSum(SqlFunc.IIF(guiderRecord.PickupStatus == ERedPackPickupStatus.Unreceived, guiderRecord.Amount, 0)),
  567. });
  568. #if DEBUG
  569. var sql = query.ToSqlString();
  570. #endif
  571. return query;
  572. }
  573. /// <summary>
  574. /// 部门考核统计-随手拍
  575. /// </summary>
  576. /// <param name="dto"></param>
  577. /// <returns></returns>
  578. /// <exception cref="NotImplementedException"></exception>
  579. public ISugarQueryable<SnapshotDepartmentStatisticsOutDto> GetSnapshotDepartmentStatistics(SnapshotDepartmentStatisticsInDto dto)
  580. {
  581. bool IsCenter = _sessionContext.OrgIsCenter;
  582. var orgLevel = _sessionContext.OrgLevel;
  583. string orgLevelStr = (_sessionContext.RequiredOrgId.Length + 3).ToString();
  584. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  585. .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
  586. .LeftJoin<OrderSendBackAudit>((snapshot, order, back) => snapshot.Id == back.OrderId && back.State == ESendBackAuditState.End)
  587. .LeftJoin<OrderVisit>((snapshot, order, back, visit) => snapshot.Id == visit.OrderId && visit.VisitState == EVisitState.Visited)
  588. .LeftJoin<OrderSecondaryHandling>((snapshot, order, back, visit, second) => snapshot.Id == second.OrderId && second.State == ESecondaryHandlingState.End)
  589. .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && order.ActualHandleOrgCode != null)
  590. .GroupBy((snapshot, order) => new
  591. {
  592. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  593. })
  594. .Select((snapshot, order, back, visit, second) => new SnapshotDepartmentStatisticsOutDto()
  595. {
  596. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  597. OrderCountNum = SqlFunc.AggregateCount(snapshot.Id),
  598. ReceiveIn4Hour = SqlFunc.AggregateCount(SqlFunc.IIF(order.ActualHandleStepCreateTime != null && order.ActualHandleStepCreateTime.Value.AddHours(-4) <= order.CreationTime, 1, 0)),
  599. TimeOutField = SqlFunc.AggregateCount(SqlFunc.IIF(order.Status >= EOrderStatus.Filed && order.FiledTime > order.ExpiredTime, 1, 0)),
  600. TimeOutNoField = SqlFunc.AggregateCount(SqlFunc.IIF(order.Status < EOrderStatus.Filed && DateTime.Now > order.ExpiredTime, 1, 0)),
  601. OnTimeCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.FiledTime <= order.ExpiredTime, 1, 0)),
  602. SatisfiedCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "1") || SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "2"), 1, 0)),
  603. NoSatisfiedCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "1") || SqlFunc.JsonListObjectAny(visit.NowEvaluate, "key", "2"), 0, 1)),
  604. SecondNum = SqlFunc.AggregateCount(second.Id),
  605. FirstFiledOrderCount = SqlFunc.AggregateCount(SqlFunc.IIF(order.Status >= EOrderStatus.Filed && second.Id == null, 1, 0)),
  606. SecondSatisfied = SqlFunc.AggregateCount(SqlFunc.IIF(second.State == ESecondaryHandlingState.Handled && (SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "1" || SqlFunc.JsonField(order.OrgProcessingResults, "Key") == "2"), 1, 0)),
  607. })
  608. .MergeTable()
  609. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  610. .Select((it, o) => new SnapshotDepartmentStatisticsOutDto()
  611. {
  612. OrgName = o.Name,
  613. OrgCode = it.OrgCode,
  614. ReceiveIn4Hour = it.ReceiveIn4Hour,
  615. TimeOutField = it.TimeOutField,
  616. TimeOutNoField = it.TimeOutNoField,
  617. OnTimeCount = it.OnTimeCount,
  618. SatisfiedCount = it.SatisfiedCount,
  619. NoSatisfiedCount = it.NoSatisfiedCount,
  620. SecondNum = it.SecondNum,
  621. FirstFiledOrderCount = it.FirstFiledOrderCount,
  622. SecondSatisfied = it.SecondSatisfied
  623. });
  624. return query;
  625. }
  626. public ISugarQueryable<SnapshotDepartmentAveTimeStatisticsOutDto> GetSnapshotDepartmentAveTimeStatistics(SnapshotDepartmentAveTimeStatisticsInDto dto)
  627. {
  628. bool IsCenter = _sessionContext.OrgIsCenter;
  629. var orgLevel = _sessionContext.OrgLevel;
  630. string orgLevelStr = (_sessionContext.RequiredOrgId.Length + 3).ToString();
  631. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  632. .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
  633. .LeftJoin<OrderSendBackAudit>((snapshot, order, back) => snapshot.Id == back.OrderId && back.State == ESendBackAuditState.End)
  634. .LeftJoin<OrderVisit>((snapshot, order, back, visit) => snapshot.Id == visit.OrderId && visit.VisitState == EVisitState.Visited)
  635. .LeftJoin<OrderSecondaryHandling>((snapshot, order, back, visit, second) => snapshot.Id == second.OrderId && second.State == ESecondaryHandlingState.End)
  636. .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && order.ActualHandleOrgCode != null)
  637. .GroupBy((snapshot, order) => new
  638. {
  639. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  640. })
  641. .Select((snapshot, order, back, visit, second) => new SnapshotDepartmentAveTimeStatisticsOutDto()
  642. {
  643. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  644. OrderCountNum = SqlFunc.AggregateCount(snapshot.Id),
  645. TotalSeconds = SqlFunc.AggregateSum(order.AllDuration),
  646. })
  647. .MergeTable()
  648. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  649. .Select((it, o) => new SnapshotDepartmentAveTimeStatisticsOutDto()
  650. {
  651. OrgName = o.Name,
  652. OrgCode = it.OrgCode,
  653. TotalSeconds = it.TotalSeconds,
  654. OrderCountNum = it.OrderCountNum
  655. });
  656. return query;
  657. }
  658. public ISugarQueryable<SnapshotDepartmentAveTimeStatisticsDetailsOutDto> GetSnapshotDepartmentAveTimeStatisticsDtails(SnapshotDepartmentAveTimeStatisticsDetailsInDto dto)
  659. {
  660. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  661. .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
  662. .Where((snapshot, order) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime && order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == dto.OrgCode)
  663. .Select((snapshot, order) => new SnapshotDepartmentAveTimeStatisticsDetailsOutDto(), true);
  664. return query;
  665. }
  666. [ExportExcel("检查合规统计", "OrgName")]
  667. public ISugarQueryable<CompliantStatisticsOutDto> GetCompliantStatistics(CompliantStatisticsInDto dto)
  668. {
  669. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  670. .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
  671. .LeftJoin<OrderSendBackAudit>((snapshot, order, back) => snapshot.Id == back.OrderId && back.State == ESendBackAuditState.End)
  672. .LeftJoin<OrderVisit>((snapshot, order, back, visit) => snapshot.Id == visit.OrderId && visit.VisitState == EVisitState.Visited)
  673. .LeftJoin<OrderSecondaryHandling>((snapshot, order, back, visit, second) => snapshot.Id == second.OrderId && second.State == ESecondaryHandlingState.End)
  674. .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && order.ActualHandleOrgCode != null)
  675. .GroupBy((snapshot, order) => new
  676. {
  677. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  678. })
  679. .Select((snapshot, order, back, visit, second) => new CompliantStatisticsOutDto()
  680. {
  681. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  682. OrderCountNum = SqlFunc.AggregateCount(snapshot.Id),
  683. First = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.CompliantType == ECompliantType.First, 1, 0)),
  684. Second = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.CompliantType == ECompliantType.Second, 1, 0)),
  685. Third = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.CompliantType == ECompliantType.Third, 1, 0)),
  686. Not = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.CompliantType == ECompliantType.Not, 1, 0)),
  687. })
  688. .MergeTable()
  689. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  690. .Select((it, o) => new CompliantStatisticsOutDto()
  691. {
  692. OrgName = o.Name,
  693. OrgCode = it.OrgCode,
  694. OrderCountNum = it.OrderCountNum,
  695. First = it.First,
  696. Second = it.Second,
  697. Third = it.Third,
  698. Not = it.Not
  699. });
  700. return query;
  701. }
  702. public ISugarQueryable<CompliantStatisticsDetailsOutDto> GetCompliantStatisticsDetails(CompliantStatisticsDetailsInDto dto)
  703. {
  704. dto.FieldName = dto.FieldName.ToLower();
  705. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  706. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  707. .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == dto.OrgCode);
  708. query = dto.FieldName switch
  709. {
  710. "ordercountnum" => query,
  711. "first" => query.Where(snapshot => snapshot.CompliantType == ECompliantType.First),
  712. "second" => query.Where(snapshot => snapshot.CompliantType == ECompliantType.Second),
  713. "third" => query.Where(snapshot => snapshot.CompliantType == ECompliantType.Third),
  714. "not" => query.Where(snapshot => snapshot.CompliantType == ECompliantType.Not),
  715. _ => throw new UserFriendlyException($"入参: {dto.FieldName} 异常")
  716. };
  717. return query.Select((snapshot, order) => new CompliantStatisticsDetailsOutDto
  718. {
  719. }, true);
  720. }
  721. public List<Dictionary<string, object>> GetReTransactStatistics(ReTransactStatisticsInDto dto)
  722. {
  723. var rawData = _orderSnapshotRepository.Queryable(includeDeleted: true)
  724. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  725. .Where((snapshot, order) => snapshot.SpecialReasonId != null)
  726. .GroupBy((snapshot, order) => new
  727. {
  728. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  729. SpecialReasonId = snapshot.SpecialReasonId,
  730. snapshot.SpecialReasonName
  731. })
  732. .Select((snapshot, order) => new
  733. {
  734. OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  735. OrderCountNum = SqlFunc.AggregateCount(snapshot.Id),
  736. SpecialReasonId = snapshot.SpecialReasonId,
  737. SpecialReasonName = snapshot.SpecialReasonName
  738. }, true)
  739. .MergeTable()
  740. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  741. .Select((it, o) => new
  742. {
  743. OrgName = o.Name,
  744. OrgCode = it.OrgCode,
  745. OrderCountNum = it.OrderCountNum,
  746. SpecialReasonId = it.SpecialReasonId,
  747. SpecialReasonName = it.SpecialReasonName
  748. }).ToList();
  749. var pivotResult = new List<Dictionary<string, object>>();
  750. var orgGroups = rawData.GroupBy(x => new { x.OrgCode, x.OrgName });
  751. var specialReasons = rawData
  752. .Select(x => x.SpecialReasonId)
  753. .Distinct()
  754. .ToList();
  755. foreach (var orgGroup in orgGroups)
  756. {
  757. var row = new Dictionary<string, object>
  758. {
  759. ["OrgName"] = orgGroup.Key.OrgName,
  760. ["OrgCode"] = orgGroup.Key.OrgCode
  761. };
  762. foreach (var reason in specialReasons)
  763. {
  764. row[reason] = 0;
  765. }
  766. foreach (var item in orgGroup)
  767. {
  768. if (item.SpecialReasonId != null)
  769. {
  770. row[item.SpecialReasonId] = item.OrderCountNum;
  771. }
  772. }
  773. pivotResult.Add(row);
  774. }
  775. pivotResult.AddSumLine("OrgName");
  776. return pivotResult;
  777. }
  778. public ISugarQueryable<ReTransactStatisticsDetailsOutDto> GetReTransactStatisticsDetail(ReTransactStatisticsDetailsInDto dto)
  779. {
  780. var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
  781. .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
  782. .LeftJoin<OrderSpecial>((snapshot, order, special) => special.OrderId == order.Id)
  783. .LeftJoin<SystemOrganize>((snapshot, order, special, org) => org.Id == special.OrgId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")))
  784. .Where((snapshot, order, special) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime && order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == dto.OrgCode && special.Id != null && snapshot.SpecialReasonId != null && special.SpecialType == ESpecialType.ReTransact)
  785. .WhereIF(dto.FieldName.NotNullOrEmpty(), (snapshot, order) => dto.FieldName == snapshot.SpecialReasonId)
  786. .OrderByDescending((snapshot, order) => order.CreationTime)
  787. .Select((snapshot, order, special, org) => new ReTransactStatisticsDetailsOutDto
  788. {
  789. ReTransactOrgName = special.OrgName, // 被重办部门
  790. ReTransactOneOrgName = org.Name, // 被重办一级部门
  791. ReTransactTime = special.CreationTime, // 重办时间
  792. ReTransactHandlerName = special.CreatorName, // 重办操作人
  793. ReTransactContent = special.Opinion // 重办理由
  794. }, true);
  795. #if DEBUG
  796. var sql = query.ToSqlString();
  797. #endif
  798. return query;
  799. }
  800. }