BiOrderController.cs 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.FlowEngine.Workflows;
  4. using Hotline.Orders;
  5. using Hotline.Repository.SqlSugar.Extensions;
  6. using Hotline.Schedulings;
  7. using Hotline.Settings;
  8. using Hotline.Settings.Hotspots;
  9. using Hotline.Share.Dtos;
  10. using Hotline.Share.Dtos.Bi;
  11. using Hotline.Share.Dtos.Bigscreen;
  12. using Hotline.Share.Dtos.CallCenter;
  13. using Hotline.Share.Dtos.Order;
  14. using Hotline.Share.Enums.CallCenter;
  15. using Hotline.Share.Enums.FlowEngine;
  16. using Hotline.Share.Enums.Order;
  17. using Hotline.Share.Enums.Settings;
  18. using Hotline.Share.Requests;
  19. using MapsterMapper;
  20. using Microsoft.AspNetCore.Authorization;
  21. using Microsoft.AspNetCore.Mvc;
  22. using SqlSugar;
  23. using System.Collections.Generic;
  24. using XF.Domain.Authentications;
  25. using XF.Domain.Constants;
  26. using XF.Domain.Exceptions;
  27. using XF.Domain.Repository;
  28. using XF.Utility.EnumExtensions;
  29. namespace Hotline.Api.Controllers.Bi
  30. {
  31. public class BiOrderController : BaseController
  32. {
  33. private readonly IOrderRepository _orderRepository;
  34. private readonly IRepository<Hotspot> _hotspotTypeRepository;
  35. private readonly ISystemDicDataCacheManager _sysDicDataCacheManager;
  36. private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
  37. private readonly IRepository<OrderDelay> _orderDelayRepository;
  38. private readonly IMapper _mapper;
  39. private readonly IRepository<WorkflowCountersign> _workflowCountersignRepository;
  40. private readonly IRepository<OrderSpecial> _orderSpecialRepository;
  41. private readonly IRepository<OrderVisit> _orderVisitRepository;
  42. private readonly IRepository<TrCallRecord> _trCallRecordRepository;
  43. private readonly IRepository<OrderPublish> _orderPublishRepository;
  44. private readonly IRepository<SystemOrganize> _systemOrganizeRepository;
  45. private readonly IRepository<AiOrderVisitDetail> _aiOrderVisitDetailRepository;
  46. private readonly ISessionContext _sessionContext;
  47. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  48. private readonly IRepository<OrderSpecialDetail> _orderSpecialDetailRepository;
  49. private readonly IRepository<WorkflowTrace> _workflowTraceRepository;
  50. public BiOrderController(
  51. IOrderRepository orderRepository,
  52. IRepository<Hotspot> hotspotTypeRepository,
  53. ISystemDicDataCacheManager sysDicDataCacheManager,
  54. IRepository<OrderVisitDetail> orderVisitDetailRepository,
  55. IRepository<OrderDelay> orderDelayRepository,
  56. IRepository<WorkflowCountersign> workflowCountersignRepository,
  57. IRepository<OrderSpecial> orderSpecialRepository,
  58. IMapper mapper,
  59. IRepository<OrderVisit> orderVisitRepository,
  60. IRepository<TrCallRecord> trCallRecordRepository,
  61. IRepository<OrderPublish> orderPublishRepository,
  62. IRepository<SystemOrganize> systemOrganizeRepository,
  63. IRepository<AiOrderVisitDetail> aiOrderVisitDetailRepository,
  64. ISessionContext sessionContext,
  65. ISystemSettingCacheManager systemSettingCacheManager,
  66. IRepository<OrderSpecialDetail> orderSpecialDetailRepository,
  67. IRepository<WorkflowTrace> workflowTraceRepository
  68. )
  69. {
  70. _orderRepository = orderRepository;
  71. _hotspotTypeRepository = hotspotTypeRepository;
  72. _sysDicDataCacheManager = sysDicDataCacheManager;
  73. _orderVisitDetailRepository = orderVisitDetailRepository;
  74. _orderDelayRepository = orderDelayRepository;
  75. _workflowCountersignRepository = workflowCountersignRepository;
  76. _orderSpecialRepository = orderSpecialRepository;
  77. _mapper = mapper;
  78. _orderVisitRepository = orderVisitRepository;
  79. _trCallRecordRepository = trCallRecordRepository;
  80. _orderPublishRepository = orderPublishRepository;
  81. _systemOrganizeRepository = systemOrganizeRepository;
  82. _aiOrderVisitDetailRepository = aiOrderVisitDetailRepository;
  83. _sessionContext = sessionContext;
  84. _systemSettingCacheManager = systemSettingCacheManager;
  85. _orderSpecialDetailRepository = orderSpecialDetailRepository;
  86. _workflowTraceRepository = workflowTraceRepository;
  87. }
  88. //public async Task OrgDataListDetail([FromQuery] OrgDataListDetailRequest dto)
  89. //{
  90. // dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  91. // await _orderRepository.Queryable()
  92. // .Where(x => x.CreationTime >= dto.StartDate && x.CreationTime <= dto.EndDate)
  93. // .WhereIF(dto.QueryType == 1, x => x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) //业务已办超期
  94. // //.WhereIF(dto.QueryType== 2,) //会签已办超期
  95. // .WhereIF(dto.QueryType == 3, x => x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()) //业务待办超期
  96. // //.WhereIF(dto.QueryType ==4,) //会签待办超期
  97. // .ToPageListAsync(dto.PageIndex, dto.PageSize);
  98. //}
  99. /// <summary>
  100. /// 部门超期统计
  101. /// </summary>
  102. /// <param name="dto"></param>
  103. /// <returns></returns>
  104. [HttpGet("org_data_list")]
  105. public async Task<PagedDto<OrderBiOrgDataListVo>> OrgDataList([FromQuery] ReportPagedRequest dto)
  106. {
  107. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  108. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  109. var IsCenter = _sessionContext.OrgIsCenter;
  110. var queryOrder = _orderRepository.Queryable(false, false, false)
  111. .LeftJoin<SystemOrganize>((x, o) => x.ActualHandleOrgCode == o.Id)
  112. .WhereIF(dto.StartTime.HasValue, (x, o) => x.CreationTime >= dto.StartTime)
  113. .WhereIF(dto.EndTime.HasValue, (x, o) => x.CreationTime <= dto.EndTime)
  114. .WhereIF(IsCenter == false, (x, o) => x.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  115. .GroupBy((x, o) => new { x.ActualHandleOrgCode, o.Name })
  116. .Select((x, o) => new OrderBiOrgDataListVo
  117. {
  118. OrgName = o.Name,
  119. OrgId = x.ActualHandleOrgCode,
  120. HandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime, 1, 0)),
  121. NoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate(), 1, 0)),
  122. }).MergeTable();
  123. var queryCountersign = _workflowCountersignRepository.Queryable()
  124. .LeftJoin<WorkflowCountersignMember>((x, o) => x.Id == o.WorkflowCountersignId)
  125. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  126. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  127. .GroupBy((x, o) => o.Key)
  128. .Select((x, o) => new OrderBiOrgDataListVo
  129. {
  130. OrgId = o.Key,
  131. CounterHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled, 1, 0)),
  132. CounterNoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled == false, 1, 0)),
  133. }).MergeTable();
  134. var query = queryOrder.LeftJoin(queryCountersign, (or, co) => or.OrgId == co.OrgId)
  135. .Select((or, co) => new OrderBiOrgDataListVo
  136. {
  137. OrgName = or.OrgName,
  138. OrgId = or.OrgId,
  139. HandlerExtendedNum = or.HandlerExtendedNum,
  140. NoHandlerExtendedNum = or.NoHandlerExtendedNum,
  141. CounterHandlerExtendedNum = co.CounterHandlerExtendedNum,
  142. CounterNoHandlerExtendedNum = co.CounterNoHandlerExtendedNum
  143. }).MergeTable();
  144. query = query.WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.OrgName.Contains(dto.Keyword!));
  145. switch (dto.SortField)
  146. {
  147. case "handlerExtendedNum":
  148. query = dto.SortRule == 0 ? query.OrderBy(x => x.HandlerExtendedNum) : query.OrderByDescending(x => x.HandlerExtendedNum);
  149. break;
  150. case "counterHandlerExtendedNum":
  151. query = dto.SortRule == 0 ? query.OrderBy(x => x.CounterHandlerExtendedNum) : query.OrderByDescending(x => x.CounterHandlerExtendedNum);
  152. break;
  153. case "noHandlerExtendedNum":
  154. query = dto.SortRule == 0 ? query.OrderBy(x => x.NoHandlerExtendedNum) : query.OrderByDescending(x => x.NoHandlerExtendedNum);
  155. break;
  156. case "counterNoHandlerExtendedNum":
  157. query = dto.SortRule == 0 ? query.OrderBy(x => x.CounterNoHandlerExtendedNum) : query.OrderByDescending(x => x.CounterNoHandlerExtendedNum);
  158. break;
  159. }
  160. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  161. return new PagedDto<OrderBiOrgDataListVo>(total, items);
  162. }
  163. /// <summary>
  164. /// 话务员办件统计
  165. /// </summary>
  166. /// <param name="dto"></param>
  167. /// <returns></returns>
  168. [HttpGet("centre_data_list")]
  169. public async Task<PagedDto<OrderBiCentreDataListVo>> CentreDataList([FromQuery] ReportPagedRequest dto)
  170. {
  171. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  172. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  173. var query = _orderRepository.Queryable(false, false, false)
  174. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  175. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  176. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.AcceptorName.Contains(dto.Keyword!))
  177. .GroupBy(x => new { x.AcceptorId, x.AcceptorName })
  178. .Select(x => new OrderBiCentreDataListVo
  179. {
  180. UserName = x.AcceptorName,
  181. UserId = x.AcceptorId,
  182. //Subtotal = SqlFunc.AggregateCount(x.AcceptorId),
  183. CentreArchive = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status >= EOrderStatus.Filed && x.ProcessType == EProcessType.Zhiban, 1, 0)),
  184. CentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status >= EOrderStatus.Filed && x.ProcessType == EProcessType.Jiaoban, 1, 0)),
  185. //NoCentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status < 300 && x.ExpiredTime > x.FiledTime, 1, 0)),
  186. Invalid = SqlFunc.AggregateSum(SqlFunc.IIF(x.AcceptType == "无效", 1, 0)),
  187. Repeat = SqlFunc.AggregateSum(SqlFunc.IIF(x.DuplicateIds != null && SqlFunc.JsonArrayLength(x.DuplicateIds) > 0, 1, 0))
  188. }).MergeTable();
  189. switch (dto.SortField)
  190. {
  191. case "centreArchive":
  192. query = dto.SortRule == 0 ? query.OrderBy(x => x.CentreArchive) : query.OrderByDescending(x => x.CentreArchive);
  193. break;
  194. case "centreCareOf":
  195. query = dto.SortRule == 0 ? query.OrderBy(x => x.CentreCareOf) : query.OrderByDescending(x => x.CentreCareOf);
  196. break;
  197. case "noCentreCareOf":
  198. query = dto.SortRule == 0 ? query.OrderBy(x => x.NoCentreCareOf) : query.OrderByDescending(x => x.NoCentreCareOf);
  199. break;
  200. case "invalid":
  201. query = dto.SortRule == 0 ? query.OrderBy(x => x.Invalid) : query.OrderByDescending(x => x.Invalid);
  202. break;
  203. case "repeat":
  204. query = dto.SortRule == 0 ? query.OrderBy(x => x.Repeat) : query.OrderByDescending(x => x.Repeat);
  205. break;
  206. }
  207. var (total, items) = await query.Where(x => (x.CentreArchive + x.CentreCareOf + x.Invalid + x.Repeat) != 0).ToPagedListAsync(dto, HttpContext.RequestAborted);
  208. return new PagedDto<OrderBiCentreDataListVo>(total, items);
  209. }
  210. /// <summary>
  211. /// 热点数据小计统计
  212. /// </summary>
  213. /// <param name="dto"></param>
  214. /// <returns></returns>
  215. [HttpGet("hotspot_subtotal_data_list")]
  216. public async Task<PagedDto<HotspotDataLsitVo>> HotspotSubtotalDataLsit([FromQuery] HotspotSubtotalReportPagedRequest dto)
  217. {
  218. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  219. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  220. var query = _hotspotTypeRepository.Queryable(false, true)
  221. .LeftJoin<Order>((x, o) => o.HotspotSpliceName != null && (x.HotSpotFullName == o.HotspotSpliceName || o.HotspotSpliceName.Contains(x.HotSpotFullName)) && o.IsDeleted == false)
  222. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= dto.StartTime)
  223. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= dto.EndTime)
  224. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => x.HotSpotName.Contains(dto.Keyword!))
  225. .Where((x, o) => x.ParentId == dto.Id)
  226. .Where((x, o) => x.IsDeleted == false)
  227. .GroupBy((x, o) => new { x.Id, x.HotSpotName })
  228. .Select((x, o) => new HotspotDataLsitVo
  229. {
  230. Id = x.Id,
  231. Name = x.HotSpotName,
  232. Num = SqlFunc.AggregateSum(SqlFunc.IIF(o.Id != null, 1, 0)),
  233. }).MergeTable();
  234. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  235. return new PagedDto<HotspotDataLsitVo>(total, items);
  236. }
  237. /// <summary>
  238. /// 热点数据统计
  239. /// </summary>
  240. /// <param name="dto"></param>
  241. /// <returns></returns>
  242. [HttpGet("hotspot_data_list")]
  243. public async Task<object> HotspotDataLsit([FromQuery] HotspotReportPagedRequest dto)
  244. {
  245. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  246. if (dto.Type == 0 && (!dto.ChainStartTime.HasValue || !dto.ChainEndTime.HasValue)) throw UserFriendlyException.SameMessage("请选择环比时间!");
  247. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  248. var IsCenter = _sessionContext.OrgIsCenter;
  249. if (dto.Type == 0)
  250. {
  251. dto.ChainEndTime = dto.ChainEndTime.Value.AddDays(1).AddSeconds(-1);
  252. }
  253. var items = await _hotspotTypeRepository.Queryable(false, true)
  254. .LeftJoin<Order>((x, o) => o.HotspotSpliceName != null && (x.HotSpotName == o.HotspotSpliceName || o.HotspotSpliceName.Contains(x.HotSpotName)) && o.IsDeleted == false)
  255. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= dto.StartTime)
  256. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= dto.EndTime)
  257. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => x.HotSpotName.Contains(dto.Keyword!))
  258. .WhereIF(IsCenter == false, (x, o) => o.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  259. .Where((x, o) => x.ParentId == dto.Id)
  260. .Where((x, o) => x.IsDeleted == false)
  261. .GroupBy((x, o) => new { x.Id, x.HotSpotName })
  262. .Select((x, o) => new HotspotDataLsitVo
  263. {
  264. Id = x.Id,
  265. Name = x.HotSpotName,
  266. Num = SqlFunc.AggregateSum(SqlFunc.IIF(o.Id != null, 1, 0)),
  267. Sublevel = SqlFunc.AggregateSum(SqlFunc.IIF(x.HotSpotName != o.HotspotName, 1, 0)) > 0,
  268. }).MergeTable().ToListAsync();
  269. var chainStartTime = dto.StartTime;
  270. var chainEndTime = dto.EndTime;
  271. switch (dto.Type)
  272. {
  273. case 1://日
  274. chainStartTime = dto.StartTime.Value.AddDays(-1);
  275. chainEndTime = dto.EndTime.Value.AddDays(-1);
  276. break;
  277. case 2://月
  278. chainStartTime = dto.StartTime.Value.AddMonths(-1);
  279. chainEndTime = dto.EndTime.Value.AddMonths(-1);
  280. break;
  281. case 3://年
  282. chainStartTime = dto.StartTime.Value.AddYears(-1);
  283. chainEndTime = dto.EndTime.Value.AddYears(-1);
  284. break;
  285. case 0:
  286. chainStartTime = dto.ChainStartTime.Value;
  287. chainEndTime = dto.ChainEndTime.Value;
  288. break;
  289. }
  290. var chainItems = await _hotspotTypeRepository.Queryable(false, true)
  291. .LeftJoin<Order>((x, o) => o.HotspotSpliceName != null && (x.HotSpotName == o.HotspotSpliceName || o.HotspotSpliceName.Contains(x.HotSpotName)) && o.IsDeleted == false)
  292. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= chainStartTime)
  293. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= chainEndTime)
  294. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => x.HotSpotName.Contains(dto.Keyword!))
  295. .WhereIF(IsCenter == false, (x, o) => o.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  296. .Where((x, o) => x.ParentId == dto.Id)
  297. .Where((x, o) => x.IsDeleted == false)
  298. .GroupBy((x, o) => new { x.Id, x.HotSpotName })
  299. .Select((x, o) => new
  300. {
  301. Id = x.Id,
  302. ChainNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.Id != null, 1, 0)),
  303. }).MergeTable().ToListAsync();
  304. var res = (from t1 in items
  305. join t2 in chainItems on t1.Id equals t2.Id into t1_t2
  306. from item in t1_t2.DefaultIfEmpty()
  307. select new
  308. {
  309. Id = t1.Id,
  310. Name = t1.Name,
  311. Num = t1.Num,
  312. Sublevel = t1.Sublevel,
  313. Children = new List<HotspotDataLsitVo>(),
  314. ChainNum = t1_t2.Select(x => x.ChainNum).FirstOrDefault(),
  315. ChainRate = t1_t2.Select(x => x.ChainNum).FirstOrDefault() > 0 ?
  316. ((double.Parse(t1.Num.ToString()) - double.Parse(t1_t2.Select(x => x.ChainNum).FirstOrDefault().ToString())) / double.Parse(t1_t2.Select(x => x.ChainNum).FirstOrDefault().ToString()) * 100).ToString("F2") + "%" : "100.00%",
  317. }).ToList();
  318. var total = new
  319. {
  320. Id = "0",
  321. Name = "合计",
  322. Num = res.Sum(x => x.Num),
  323. Sublevel = false,
  324. Children = new List<HotspotDataLsitVo>(),
  325. ChainNum = res.Sum(x => x.ChainNum),
  326. ChainRate = res.Sum(x => x.ChainNum) > 0 ? ((double.Parse(res.Sum(x => x.Num).ToString()) - double.Parse(res.Sum(x => x.ChainNum).ToString())) / double.Parse(res.Sum(x => x.ChainNum).ToString()) * 100).ToString("F2") + "%" : "100.00%"
  327. };
  328. return new { List = res, Total = total };
  329. }
  330. /// <summary>
  331. /// 部门不满意统计
  332. /// 已加验证部门
  333. /// </summary>
  334. /// <param name="dto"></param>
  335. /// <returns></returns>
  336. [HttpGet("visit-nosatisfied")]
  337. public async Task<object> QueryVisitNoSatisfied([FromQuery] QueryVisitNoSatiisfiedRequest dto)
  338. {
  339. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  340. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  341. var IsCenter = _sessionContext.OrgIsCenter;
  342. var dissatisfiedReason = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.DissatisfiedReason);
  343. List<dynamic>? list = new List<dynamic>();
  344. //DataTable dt = new DataTable();
  345. foreach (var item in dissatisfiedReason)
  346. {
  347. var table = _orderVisitDetailRepository.Queryable()
  348. .Includes(x => x.OrderVisit)
  349. .Where(x => x.VisitTarget == Share.Enums.Order.EVisitTarget.Org)
  350. .Where(x => x.OrgNoSatisfiedReason != null)
  351. .Where(x => x.OrderVisit.VisitState == EVisitState.Visited)
  352. .Where(x => !string.IsNullOrEmpty(x.VisitOrgName))
  353. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.VisitOrgName.Contains(dto.OrgName))
  354. .WhereIF(dto.StartTime.HasValue, x => x.OrderVisit.VisitTime >= dto.StartTime.Value)
  355. .WhereIF(dto.EndTime.HasValue, x => x.OrderVisit.VisitTime <= dto.EndTime.Value)
  356. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  357. .GroupBy(x => new { x.VisitOrgName, x.VisitOrgCode })
  358. .Select(x => new BiVisitNoSatisfiedDto
  359. {
  360. Count = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(x.OrgNoSatisfiedReason, "Key", item.DicDataValue), 1, 0)),
  361. Key = item.DicDataValue,
  362. OrgName = x.VisitOrgName,
  363. OrgCode = x.VisitOrgCode
  364. })
  365. .OrderByDescending(x => x.Count)
  366. //.ToPivotTable(x => x.Key, x => x.OrgName, x => x.Sum(x => x.Count));
  367. .ToPivotList(x => x.Key, x => new { x.OrgCode, x.OrgName }, x => x.Sum(x => x.Count));
  368. list.AddRange(table);
  369. }
  370. return new { DicReason = dissatisfiedReason, Data = list };
  371. }
  372. /// <summary>
  373. /// 部门不满意统计明细
  374. /// </summary>
  375. /// <param name="dto"></param>
  376. /// <returns></returns>
  377. [HttpGet("visit-nosatisfied-detail")]
  378. public async Task<PagedDto<OrderVisitDetailDto>> BiQueryVisitNoSatisfiedDetail([FromQuery] BiQueryVisitNoSatisfiedDetailDto dto)
  379. {
  380. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  381. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  382. var IsCenter = _sessionContext.OrgIsCenter;
  383. var (total, items) = await _orderVisitDetailRepository.Queryable()
  384. .Includes(x => x.OrderVisit, d => d.Order)
  385. .Includes(x => x.OrderVisit, d => d.Employee)
  386. .Where(x => x.VisitOrgCode == dto.OrgCode)
  387. .Where(x => x.OrderVisit.VisitState == EVisitState.Visited)
  388. .Where(x => x.OrderVisit.VisitTime >= dto.StartTime.Value)
  389. .Where(x => x.OrderVisit.VisitTime <= dto.EndTime.Value)
  390. .Where(x => SqlFunc.JsonListObjectAny(x.OrgNoSatisfiedReason, "Key", dto.DissatisfiedKey))
  391. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  392. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.OrderVisit.Order.No.Contains(dto.Keyword) || x.OrderVisit.Order.Title.Contains(dto.Keyword))
  393. .OrderBy(x => x.OrderVisit.VisitTime)
  394. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  395. return new PagedDto<OrderVisitDetailDto>(total, _mapper.Map<IReadOnlyList<OrderVisitDetailDto>>(items));
  396. }
  397. /// <summary>
  398. /// 部门延期统计
  399. /// </summary>
  400. /// <param name="dto"></param>
  401. /// <returns></returns>
  402. [HttpGet("order-delay-data-list")]
  403. public async Task<IReadOnlyList<BiOrderDelayDataDto>> QueryOrderDelayDataList([FromQuery] QueryOrderDelayDataListRequest dto)
  404. {
  405. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  406. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  407. var IsCenter = _sessionContext.OrgIsCenter;
  408. var list = await _orderDelayRepository.Queryable()
  409. .LeftJoin<SystemOrganize>((x, o) => x.ApplyOrgCode == o.Id)
  410. .WhereIF(dto.StartTime.HasValue, (x, o) => x.CreationTime >= dto.StartTime)
  411. .WhereIF(dto.EndTime.HasValue, (x, o) => x.CreationTime <= dto.EndTime)
  412. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.ApplyOrgName.Contains(dto.OrgName))
  413. .WhereIF(IsCenter == false, x => x.ApplyOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  414. .GroupBy(x => new { x.ApplyOrgCode, x.ApplyOrgName })
  415. .Select(x => new BiOrderDelayDataDto
  416. {
  417. OrgName = x.ApplyOrgName,
  418. OrgCode = x.ApplyOrgCode,
  419. PassTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Pass, 1, 0)),
  420. NoPassTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.NoPass, 1, 0)),
  421. ExaminingTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Examining, 1, 0)),
  422. AllTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Pass, 1, 0)) + SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.NoPass, 1, 0)) + SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Examining, 1, 0))
  423. }).ToListAsync();
  424. return list;
  425. }
  426. /// <summary>
  427. /// 特提统计
  428. /// </summary>
  429. /// <param name="dto"></param>
  430. /// <returns></returns>
  431. [HttpGet("special_data_list")]
  432. public async Task<PagedDto<OrderBiSpecialListVo>> SpecialDataList([FromQuery] ReportPagedRequest dto)
  433. {
  434. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  435. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  436. var IsCenter = _sessionContext.OrgIsCenter;
  437. var query = _orderSpecialRepository.Queryable()
  438. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  439. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  440. .WhereIF(IsCenter == false, x => x.OrgId.StartsWith(_sessionContext.RequiredOrgId))
  441. .GroupBy(x => new { x.Cause })
  442. .Select(x => new OrderBiSpecialListVo
  443. {
  444. Cause = x.Cause,
  445. OrderNum = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  446. MaxSpecialTime = SqlFunc.AggregateMax(x.CreationTime),
  447. })
  448. .MergeTable();
  449. switch (dto.SortField)
  450. {
  451. case "cause":
  452. query = dto.SortRule == 0 ? query.OrderBy(x => x.Cause) : query.OrderByDescending(x => x.Cause);
  453. break;
  454. case "orderNum":
  455. query = dto.SortRule == 0 ? query.OrderBy(x => x.OrderNum) : query.OrderByDescending(x => x.OrderNum);
  456. break;
  457. case "maxSpecialTime":
  458. query = dto.SortRule == 0 ? query.OrderBy(x => x.MaxSpecialTime) : query.OrderByDescending(x => x.MaxSpecialTime);
  459. break;
  460. }
  461. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  462. return new PagedDto<OrderBiSpecialListVo>(total, items);
  463. }
  464. /// <summary>
  465. /// 获取工单特提信息列表
  466. /// </summary>
  467. /// <param name="dto"></param>
  468. /// <returns></returns>
  469. [HttpGet("special_data_list/list")]
  470. public async Task<PagedDto<OrderSpecialDto>> List([FromQuery] OrderSpecialListDto dto)
  471. {
  472. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  473. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  474. var IsCenter = _sessionContext.OrgIsCenter;
  475. var (total, items) = await _orderSpecialRepository.Queryable()
  476. .Includes(x => x.Order)
  477. .WhereIF(!string.IsNullOrEmpty(dto.Keyword),
  478. x => x.Order.No.Contains(dto.Keyword!) || x.Order.Title.Contains(dto.Keyword!))
  479. .WhereIF(!string.IsNullOrEmpty(dto.Cause),
  480. x => x.Cause != null && x.Cause.Equals(dto.Cause))
  481. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  482. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  483. .WhereIF(dto.State.HasValue, x => x.State == dto.State)
  484. .WhereIF(IsCenter == false, x => x.OrgId.StartsWith(_sessionContext.OrgId))
  485. .OrderByDescending(x => x.CreationTime)
  486. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  487. return new PagedDto<OrderSpecialDto>(total, _mapper.Map<IReadOnlyList<OrderSpecialDto>>(items));
  488. }
  489. /// <summary>
  490. /// 受理类型前十
  491. /// </summary>
  492. /// <param name="dto"></param>
  493. /// <returns></returns>
  494. [HttpGet("accept_type_top10_list")]
  495. public async Task<PagedDto<AcceptTypeTop10Vo>> AcceptTypeTop10List([FromQuery] ReportPagedRequest dto)
  496. {
  497. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  498. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  499. dto.PageIndex = 1;
  500. dto.PageSize = 10;
  501. var IsCenter = _sessionContext.OrgIsCenter;
  502. var query = _orderRepository.Queryable(false, false, false)
  503. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  504. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  505. .WhereIF(IsCenter == false, x => x.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  506. .Select(x => new
  507. {
  508. AcceptType = x.AcceptType,
  509. OneHotspot = SqlFunc.Substring(x.HotspotSpliceName, 0, SqlFunc.CharIndex("-", x.HotspotSpliceName + "-")),
  510. Id = x.Id
  511. }).MergeTable()
  512. .GroupBy(x => new { x.OneHotspot })
  513. .Select(x => new AcceptTypeTop10Vo
  514. {
  515. Name = x.OneHotspot,
  516. ValidAccept = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  517. Consult = SqlFunc.AggregateSum(SqlFunc.IIF("咨询".Equals(x.AcceptType), 1, 0)),
  518. Report = SqlFunc.AggregateSum(SqlFunc.IIF("举报".Equals(x.AcceptType), 1, 0)),
  519. Complaint = SqlFunc.AggregateSum(SqlFunc.IIF("投诉".Equals(x.AcceptType), 1, 0)),
  520. SeekHelp = SqlFunc.AggregateSum(SqlFunc.IIF("求助".Equals(x.AcceptType), 1, 0)),
  521. Suggest = SqlFunc.AggregateSum(SqlFunc.IIF("建议".Equals(x.AcceptType), 1, 0)),
  522. Opinion = SqlFunc.AggregateSum(SqlFunc.IIF("意见".Equals(x.AcceptType), 1, 0)),
  523. Rests = SqlFunc.AggregateSum(SqlFunc.IIF("其他".Equals(x.AcceptType), 1, 0)),
  524. BenefitThePeople = SqlFunc.AggregateSum(SqlFunc.IIF("惠民帮助".Equals(x.AcceptType), 1, 0)),
  525. Praise = SqlFunc.AggregateSum(SqlFunc.IIF("表扬".Equals(x.AcceptType), 1, 0)),
  526. }).MergeTable();
  527. switch (dto.SortField)
  528. {
  529. case "validAccept":
  530. query = dto.SortRule == 0 ? query.OrderBy(x => x.ValidAccept) : query.OrderByDescending(x => x.ValidAccept);
  531. break;
  532. case "consult":
  533. query = dto.SortRule == 0 ? query.OrderBy(x => x.Consult) : query.OrderByDescending(x => x.Consult);
  534. break;
  535. case "report":
  536. query = dto.SortRule == 0 ? query.OrderBy(x => x.Report) : query.OrderByDescending(x => x.Report);
  537. break;
  538. case "complaint":
  539. query = dto.SortRule == 0 ? query.OrderBy(x => x.Complaint) : query.OrderByDescending(x => x.Complaint);
  540. break;
  541. case "seekHelp":
  542. query = dto.SortRule == 0 ? query.OrderBy(x => x.SeekHelp) : query.OrderByDescending(x => x.SeekHelp);
  543. break;
  544. case "suggest":
  545. query = dto.SortRule == 0 ? query.OrderBy(x => x.Suggest) : query.OrderByDescending(x => x.Suggest);
  546. break;
  547. case "opinion":
  548. query = dto.SortRule == 0 ? query.OrderBy(x => x.Opinion) : query.OrderByDescending(x => x.Opinion);
  549. break;
  550. case "rests":
  551. query = dto.SortRule == 0 ? query.OrderBy(x => x.Rests) : query.OrderByDescending(x => x.Rests);
  552. break;
  553. case "benefitThePeople":
  554. query = dto.SortRule == 0 ? query.OrderBy(x => x.BenefitThePeople) : query.OrderByDescending(x => x.BenefitThePeople);
  555. break;
  556. case "praise":
  557. query = dto.SortRule == 0 ? query.OrderBy(x => x.Praise) : query.OrderByDescending(x => x.Praise);
  558. break;
  559. default:
  560. query = query.OrderByDescending(x => x.ValidAccept);
  561. break;
  562. }
  563. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  564. return new PagedDto<AcceptTypeTop10Vo>(total, items);
  565. }
  566. /// <summary>
  567. /// 热点类型部门统计
  568. /// </summary>
  569. /// <param name="dto"></param>
  570. /// <returns></returns>
  571. [HttpGet("hotport-org-statistics")]
  572. public async Task<object> HotPortJoinOrgStatistics([FromQuery] HotPortJoinOrgStatisticsRequest dto)
  573. {
  574. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  575. var IsCenter = _sessionContext.OrgIsCenter;
  576. return await _orderRepository.HotPortJoinOrgStatistics(dto.StartTime, dto.EndTime, IsCenter, _sessionContext.OrgId);
  577. }
  578. /// <summary>
  579. /// 回访量统计
  580. /// </summary>
  581. /// <returns></returns>
  582. [HttpGet("visit-measure-statistics")]
  583. public async Task<VisitMeasureStatisticsDto> VisitMeasureStatistics(DateTime StartDate, DateTime EndDate, string? VisitName)
  584. {
  585. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  586. var list = await _orderVisitRepository.Queryable()
  587. .Includes(x => x.Employee)
  588. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited)
  589. .WhereIF(!string.IsNullOrEmpty(VisitName), x => x.Employee.Name.Contains(VisitName))
  590. .GroupBy(x => new { x.EmployeeId, x.Employee.Name })
  591. .Select(x => new VisitMeasureStatisticsModelDto()
  592. {
  593. VisitName = x.Employee.Name,
  594. CallVisitCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitType == EVisitType.CallVisit, 1, 0)),
  595. ArtificialVisitCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitType != EVisitType.CallVisit, 1, 0)),
  596. SumCount = SqlFunc.AggregateCount(x.EmployeeId)
  597. })
  598. .ToListAsync();
  599. var returnModel = new VisitMeasureStatisticsDto();
  600. returnModel.VisitMeasureStatisticsModelList = list;
  601. //查询AIVisit
  602. returnModel.AiVisitCount = await _aiOrderVisitDetailRepository.Queryable()
  603. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess != null).CountAsync();
  604. returnModel.AiVisitSatisfiedCount = await _aiOrderVisitDetailRepository.Queryable()
  605. .Includes(x => x.OrderVisit)
  606. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess == true && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") != "1" && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") != "2").CountAsync();
  607. returnModel.AiVisitNoSatisfiedCount = await _aiOrderVisitDetailRepository.Queryable()
  608. .Includes(x => x.OrderVisit)
  609. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess == true && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") == "1" && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") == "2").CountAsync();
  610. returnModel.AIVisitFailCount = await _aiOrderVisitDetailRepository.Queryable()
  611. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess == false).CountAsync();
  612. return returnModel;
  613. }
  614. /// <summary>
  615. /// 热点类型小类统计
  616. /// </summary>
  617. /// <param name="StartDate"></param>
  618. /// <param name="EndDate"></param>
  619. /// <param name="TypeId">0:全部 ,1:市民,2:企业</param>
  620. /// <returns></returns>
  621. [HttpGet("hotspot-statistics")]
  622. public async Task<object> HotspotStatistics(DateTime StartDate, DateTime EndDate, int TypeId, string? HotspotCode)
  623. {
  624. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  625. var IsCenter = _sessionContext.OrgIsCenter;
  626. if (string.IsNullOrEmpty(HotspotCode))
  627. {
  628. var list = await _hotspotTypeRepository.Queryable()
  629. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  630. .Where((it, o) => o.CreationTime >= StartDate && o.CreationTime <= EndDate && o.Id != null)
  631. .WhereIF(TypeId == 1, (it, o) => o.IdentityType == EIdentityType.Citizen)
  632. .WhereIF(TypeId == 2, (it, o) => o.IdentityType == EIdentityType.Enterprise)
  633. .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  634. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")) })
  635. .Select((it, o) => new
  636. {
  637. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")),
  638. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  639. })
  640. .MergeTable()
  641. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  642. .Select((x, q) => new
  643. {
  644. HotspotCode = x.HotspotCode,
  645. SumCount = x.SumCount,
  646. HotspotName = q.HotSpotName,
  647. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  648. })
  649. .ToListAsync();
  650. return list;
  651. }
  652. else
  653. {
  654. string count = (HotspotCode.Length + 2).ToString();
  655. string countx = HotspotCode.Length.ToString();
  656. var list = await _hotspotTypeRepository.Queryable()
  657. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  658. .Where((it, o) => o.CreationTime >= StartDate && o.CreationTime <= EndDate && it.ParentId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(countx)) == HotspotCode)
  659. .WhereIF(TypeId == 1, (it, o) => o.IdentityType == EIdentityType.Citizen)
  660. .WhereIF(TypeId == 2, (it, o) => o.IdentityType == EIdentityType.Enterprise)
  661. .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  662. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)) })
  663. .Select((it, o) => new
  664. {
  665. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)),
  666. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  667. })
  668. .MergeTable()
  669. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  670. .Select((x, q) => new
  671. {
  672. HotspotCode = x.HotspotCode,
  673. SumCount = x.SumCount,
  674. HotspotName = q.HotSpotName,
  675. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  676. })
  677. .ToListAsync();
  678. return list;
  679. }
  680. }
  681. /// <summary>
  682. /// 部门满意度统计
  683. /// </summary>
  684. /// <param name="StartDate"></param>
  685. /// <param name="EndDate"></param>
  686. /// <param name="OrgName"></param>
  687. /// <param name="TypeId">1:办件结果 2:办件态度</param>
  688. /// <param name="LineNum"></param>
  689. /// <returns></returns>
  690. [HttpGet("visit-org-satisfaction-statistics")]
  691. public async Task<VisitAndOrgSatisfactionStatisticsResultDto> VisitAndOrgSatisfactionStatistics(DateTime StartDate, DateTime EndDate, string OrgName, int TypeId, string? LineNum)
  692. {
  693. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  694. bool IsCenter = _sessionContext.OrgIsCenter;
  695. var list = await _orderVisitDetailRepository.Queryable()
  696. .Where(x => x.OrderVisit.VisitTime >= StartDate && x.OrderVisit.VisitTime <= EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited && !string.IsNullOrEmpty(x.VisitOrgCode))
  697. .WhereIF(string.IsNullOrEmpty(OrgName) == false, x => x.VisitOrgName.Contains(OrgName))
  698. .WhereIF(string.IsNullOrEmpty(LineNum) == false, x => x.OrderVisit.Order.CallRecord.Gateway.Contains(LineNum))
  699. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  700. .GroupByIF(IsCenter, x => new
  701. {
  702. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  703. })
  704. .GroupByIF(IsCenter == false, x => new
  705. {
  706. VisitOrgCode = x.VisitOrgCode
  707. })
  708. .Select(x => new VisitAndOrgSatisfactionStatisticsDto()
  709. {
  710. OrgCode = SqlFunc.IIF(IsCenter, x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")), x.VisitOrgCode),
  711. TotalSumCount = SqlFunc.AggregateCount(x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  712. VerySatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "5", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "5", 1, 0))),//非常满意数
  713. SatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "4", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "4", 1, 0))), //满意数
  714. RegardedAsSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "-1", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "-1", 1, 0))),//视为满意
  715. DefaultSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "0", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "0", 1, 0))),//默认满意
  716. NoSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "2", 1, 0))),//不满意
  717. NoEvaluateCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "7", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "7", 1, 0))),//未做评价
  718. NoPutThroughCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "6", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "6", 1, 0))),//未接通
  719. })
  720. .MergeTable()
  721. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  722. .Select((it, o) => new VisitAndOrgSatisfactionStatisticsDto()
  723. {
  724. OrgName = o.Name,
  725. OrgCode = it.OrgCode,
  726. OrgType = o.OrgType,
  727. TotalSumCount = it.TotalSumCount,
  728. VerySatisfiedCount = it.VerySatisfiedCount,//非常满意数
  729. SatisfiedCount = it.SatisfiedCount, //满意数
  730. RegardedAsSatisfiedCount = it.RegardedAsSatisfiedCount,//视为满意
  731. DefaultSatisfiedCount = it.DefaultSatisfiedCount,//默认满意
  732. NoSatisfiedCount = it.NoSatisfiedCount,//不满意
  733. NoEvaluateCount = it.NoEvaluateCount,//未做评价
  734. NoPutThroughCount = it.NoPutThroughCount,//未接通
  735. })
  736. .ToListAsync();
  737. var countySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  738. {
  739. OrgName = "区县合计",
  740. TotalSumCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.TotalSumCount),
  741. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.VerySatisfiedCount),
  742. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.SatisfiedCount),
  743. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.RegardedAsSatisfiedCount),
  744. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.DefaultSatisfiedCount),
  745. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoSatisfiedCount),
  746. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoEvaluateCount),
  747. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoPutThroughCount),
  748. };
  749. var citySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  750. {
  751. OrgName = "市直合计",
  752. TotalSumCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.TotalSumCount),
  753. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.VerySatisfiedCount),
  754. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.SatisfiedCount),
  755. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.RegardedAsSatisfiedCount),
  756. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.DefaultSatisfiedCount),
  757. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoSatisfiedCount),
  758. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoEvaluateCount),
  759. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoPutThroughCount),
  760. };
  761. var sumModel = new VisitAndOrgSatisfactionStatisticsDto()
  762. {
  763. OrgName = "总计",
  764. TotalSumCount = list.Sum(x => x.TotalSumCount),
  765. VerySatisfiedCount = list.Sum(x => x.VerySatisfiedCount),
  766. SatisfiedCount = list.Sum(x => x.SatisfiedCount),
  767. RegardedAsSatisfiedCount = list.Sum(x => x.RegardedAsSatisfiedCount),
  768. DefaultSatisfiedCount = list.Sum(x => x.DefaultSatisfiedCount),
  769. NoSatisfiedCount = list.Sum(x => x.NoSatisfiedCount),
  770. NoEvaluateCount = list.Sum(x => x.NoEvaluateCount),
  771. NoPutThroughCount = list.Sum(x => x.NoPutThroughCount),
  772. };
  773. return new VisitAndOrgSatisfactionStatisticsResultDto { DataList = list, CountySumModel = countySumModel, CitySumModel = citySumModel, SumModel = sumModel };
  774. }
  775. /// <summary>
  776. /// 子部门满意度明细
  777. /// </summary>
  778. /// <param name="StartDate"></param>
  779. /// <param name="EndDate"></param>
  780. /// <param name="OrgCode"></param>
  781. /// <param name="TypeId"></param>
  782. /// <param name="LineNum"></param>
  783. /// <returns></returns>
  784. [HttpGet("visit-org-statisfaction-org-detail")]
  785. public async Task<VisitAndOrgSatisfactionStatisticsResultDto> VisitAndOrgStatisfactionOrgDetail(DateTime StartDate, DateTime EndDate, string OrgCode, int TypeId, string? LineNum)
  786. {
  787. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  788. bool IsCenter = _sessionContext.OrgIsCenter;
  789. var list = await _systemOrganizeRepository.Queryable().Where(x => x.Id.StartsWith(OrgCode))
  790. .LeftJoin<OrderVisitDetail>((x, it) => x.Id == it.VisitOrgCode)
  791. .Where((x, it) => it.OrderVisit.VisitTime >= StartDate && it.OrderVisit.VisitTime <= EndDate && it.VisitTarget == EVisitTarget.Org && it.OrderVisit.VisitState == EVisitState.Visited)
  792. .WhereIF(!string.IsNullOrEmpty(LineNum), (x, it) => it.OrderVisit.Order.CallRecord.Gateway.Contains(LineNum))
  793. .WhereIF(IsCenter == false, (x, it) => it.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  794. .GroupBy((x, it) => new
  795. {
  796. VisitOrgCode = it.VisitOrgCode
  797. })
  798. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  799. {
  800. OrgCode = it.VisitOrgCode,
  801. TotalSumCount = SqlFunc.AggregateCount(it.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("9"))),
  802. VerySatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "5", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "5", 1, 0))),//非常满意数
  803. SatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "4", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "4", 1, 0))), //满意数
  804. RegardedAsSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "-1", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "-1", 1, 0))),//视为满意
  805. DefaultSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "0", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "0", 1, 0))),//默认满意
  806. NoSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "2", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "2", 1, 0))),//不满意
  807. NoEvaluateCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "7", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "7", 1, 0))),//未做评价
  808. NoPutThroughCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "6", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "6", 1, 0)))//未接通
  809. })
  810. .MergeTable()
  811. .LeftJoin<SystemOrganize>((x, it) => x.OrgCode == it.Id)
  812. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  813. {
  814. OrgName = it.Name,
  815. OrgCode = x.OrgCode,
  816. OrgType = it.OrgType,
  817. TotalSumCount = x.TotalSumCount,
  818. VerySatisfiedCount = x.VerySatisfiedCount,//非常满意数
  819. SatisfiedCount = x.SatisfiedCount, //满意数
  820. RegardedAsSatisfiedCount = x.RegardedAsSatisfiedCount,//视为满意
  821. DefaultSatisfiedCount = x.DefaultSatisfiedCount,//默认满意
  822. NoSatisfiedCount = x.NoSatisfiedCount,//不满意
  823. NoEvaluateCount = x.NoEvaluateCount,//未做评价
  824. NoPutThroughCount = x.NoPutThroughCount,//未接通
  825. })
  826. .ToListAsync();
  827. var countySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  828. {
  829. OrgName = "区县合计",
  830. TotalSumCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.TotalSumCount),
  831. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.VerySatisfiedCount),
  832. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.SatisfiedCount),
  833. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.RegardedAsSatisfiedCount),
  834. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.DefaultSatisfiedCount),
  835. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoSatisfiedCount),
  836. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoEvaluateCount),
  837. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoPutThroughCount),
  838. };
  839. var citySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  840. {
  841. OrgName = "市直合计",
  842. TotalSumCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.TotalSumCount),
  843. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.VerySatisfiedCount),
  844. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.SatisfiedCount),
  845. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.RegardedAsSatisfiedCount),
  846. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.DefaultSatisfiedCount),
  847. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoSatisfiedCount),
  848. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoEvaluateCount),
  849. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoPutThroughCount),
  850. };
  851. var sumModel = new VisitAndOrgSatisfactionStatisticsDto()
  852. {
  853. OrgName = "总计",
  854. TotalSumCount = list.Sum(x => x.TotalSumCount),
  855. VerySatisfiedCount = list.Sum(x => x.VerySatisfiedCount),
  856. SatisfiedCount = list.Sum(x => x.SatisfiedCount),
  857. RegardedAsSatisfiedCount = list.Sum(x => x.RegardedAsSatisfiedCount),
  858. DefaultSatisfiedCount = list.Sum(x => x.DefaultSatisfiedCount),
  859. NoSatisfiedCount = list.Sum(x => x.NoSatisfiedCount),
  860. NoEvaluateCount = list.Sum(x => x.NoEvaluateCount),
  861. NoPutThroughCount = list.Sum(x => x.NoPutThroughCount),
  862. };
  863. return new VisitAndOrgSatisfactionStatisticsResultDto { DataList = list, CountySumModel = countySumModel, CitySumModel = citySumModel, SumModel = sumModel };
  864. }
  865. /// <summary>
  866. /// 部门满意度明细
  867. /// </summary>
  868. /// <param name="StartDate"></param>
  869. /// <param name="EndDate"></param>
  870. /// <param name="OrgCode"></param>
  871. /// <param name="TypeId"></param>
  872. /// <param name="LineNum"></param>
  873. /// <returns></returns>
  874. [HttpGet("visit-org-satisfaction-detail")]
  875. public async Task<PagedDto<OrderVisitDetailDto>> VisitAndOrgSatisfactionDetail([FromQuery] VisitAndOrgSatisfactionDetailDto dto)
  876. {
  877. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  878. var (total, items) = await _orderVisitDetailRepository.Queryable()
  879. .Includes(x => x.OrderVisit, o => o.Order, d => d.CallRecord)
  880. .Where(x => x.OrderVisit.VisitTime >= dto.StartDate && x.OrderVisit.VisitTime <= dto.EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited)
  881. .WhereIF(dto.OrgCode == "001", x => x.VisitOrgCode == dto.OrgCode)
  882. .WhereIF(dto.OrgCode != "001", x => x.VisitOrgCode.StartsWith(dto.OrgCode))
  883. .WhereIF(dto.TypeId == 1, x => SqlFunc.JsonField(x.OrgProcessingResults, "Key") == dto.DateValue)
  884. .WhereIF(dto.TypeId == 2, x => SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == dto.DateValue)
  885. .WhereIF(!string.IsNullOrEmpty(dto.LineNum), x => x.OrderVisit.Order.CallRecord.Gateway == dto.LineNum)
  886. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  887. return new PagedDto<OrderVisitDetailDto>(total, _mapper.Map<IReadOnlyList<OrderVisitDetailDto>>(items));
  888. }
  889. /// <summary>
  890. /// 中心报表统计
  891. /// </summary>
  892. /// <param name="StartDate"></param>
  893. /// <param name="EndDate"></param>
  894. /// <returns></returns>
  895. [HttpGet("center_report_forms_statistics")]
  896. public async Task<CenterReportStatisticsDto> CenterReportFormsStatistics(DateTime StartDate, DateTime EndDate)
  897. {
  898. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  899. CenterReportStatisticsDto centerReportStatisticsDto = new();
  900. //信件总量
  901. int sourceChannelCount = await _orderRepository.Queryable().Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate).CountAsync();
  902. #region 通话记录
  903. //通话记录
  904. var callData = await _trCallRecordRepository.Queryable()
  905. .Where(p => p.CreatedTime >= StartDate && p.CreatedTime <= EndDate)
  906. .Select(o => new CenterReportCallDto
  907. {
  908. EffectiveCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.OnState == EOnState.On, 1, 0)),//有效
  909. InvalidCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.OnState == EOnState.NoOn && o.BeginIvrTime.HasValue && o.BeginQueueTime.HasValue && o.BeginRingTime.HasValue, 1, 0)), //无效(排除队列挂断和IVR挂断)
  910. QueueByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In && o.QueueTims > 0 && o.RingTimes == 0, 1, 0)), //队列挂断
  911. IvrByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In && o.BeginIvrTime.HasValue && !o.BeginQueueTime.HasValue && !o.BeginRingTime.HasValue && o.OnState == EOnState.NoOn, 1, 0)), //IVR挂断
  912. })
  913. .ToListAsync();
  914. if (callData != null && callData.Count > 0)
  915. centerReportStatisticsDto.CenterReportCall = callData[0];
  916. #endregion
  917. #region 工单
  918. //工单
  919. var orderData = await _orderRepository.Queryable()
  920. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  921. .Select(x => new CenterReportOrderDto
  922. {
  923. EffectiveCount = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  924. InvalidCount = 0,
  925. CompletedCount = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status >= 300, 1, 0)),
  926. InProgressCount = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status < 300, 1, 0))
  927. })
  928. .ToListAsync();
  929. if (orderData != null && orderData.Count > 0)
  930. centerReportStatisticsDto.CenterReportOrder = orderData[0];
  931. #endregion
  932. #region 信件来源
  933. //信件来源
  934. var sourceChannelData = await _orderRepository.Queryable()
  935. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  936. .Select(it => new
  937. {
  938. SourceChannelCode = SqlFunc.IIF(SqlFunc.IsNullOrEmpty(it.SourceChannelCode), "QT", it.SourceChannelCode)
  939. })
  940. .MergeTable()//将查询出来的结果合并成一个新表
  941. .GroupBy(it => new { it.SourceChannelCode })//对新表进行分组
  942. .Select(it => new CenterReportOrderSourceChannelDto
  943. {
  944. Code = it.SourceChannelCode,
  945. CountNum = SqlFunc.AggregateCount(it.SourceChannelCode)
  946. })
  947. .ToListAsync();
  948. List<CenterReportOrderSourceChannelDto> sourceChannel = new()
  949. {
  950. new CenterReportOrderSourceChannelDto
  951. {
  952. Name = "来源总量",
  953. Code = "All",
  954. CountNum = sourceChannelCount
  955. }
  956. };
  957. var sourceChannelDic = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.SourceChannel);
  958. foreach (var item in sourceChannelDic)
  959. {
  960. sourceChannel.Add(new CenterReportOrderSourceChannelDto
  961. {
  962. Name = item.DicDataName,
  963. Code = item.DicTypeCode,
  964. CountNum = sourceChannelData.Find(p => p.Code == item.DicDataValue)?.CountNum ?? 0
  965. });
  966. }
  967. centerReportStatisticsDto.CenterReportOrderSourceChannels = sourceChannel;
  968. #endregion
  969. #region 信件分类
  970. //信件来源
  971. var acceptTypeData = await _orderRepository.Queryable(false, false, false)
  972. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  973. .Select(it => new
  974. {
  975. AcceptTypeCode = SqlFunc.IIF(SqlFunc.IsNullOrEmpty(it.AcceptTypeCode), "40", it.AcceptTypeCode)
  976. })
  977. .MergeTable()//将查询出来的结果合并成一个新表
  978. .GroupBy(it => new { it.AcceptTypeCode })//对新表进行分组
  979. .Select(it => new CenterReportOrderSourceChannelDto
  980. {
  981. Code = it.AcceptTypeCode,
  982. CountNum = SqlFunc.AggregateCount(it.AcceptTypeCode)
  983. })
  984. .ToListAsync();
  985. List<CenterReportOrderSourceChannelDto> acceptType = new();
  986. var acceptTypeDic = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.AcceptType);
  987. foreach (var item in acceptTypeDic)
  988. {
  989. acceptType.Add(new CenterReportOrderSourceChannelDto
  990. {
  991. AllCountNum = sourceChannelCount,
  992. Name = item.DicDataName,
  993. Code = item.DicTypeCode,
  994. CountNum = acceptTypeData.Find(p => p.Code == item.DicDataValue)?.CountNum ?? 0
  995. });
  996. }
  997. centerReportStatisticsDto.CenterReportOrderAcceptTypes = acceptType;
  998. #endregion
  999. #region 信件回访量
  1000. //信件回访量
  1001. CenterReportVisitdDto centerReportVisitd = new()
  1002. {
  1003. Visitd = await _orderVisitRepository.Queryable()
  1004. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited).CountAsync(),
  1005. WaitVisitd = await _orderVisitRepository.Queryable()
  1006. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState != EVisitState.None && x.VisitState != EVisitState.Visited).CountAsync()
  1007. };
  1008. //部门
  1009. var listOrg = await _orderVisitDetailRepository.Queryable()
  1010. .LeftJoin<OrderVisit>((it, o) => it.VisitId == o.Id)
  1011. .Where((it, o) => it.VisitTarget == EVisitTarget.Org && o.VisitTime >= StartDate && o.VisitTime <= EndDate && o.VisitState == EVisitState.Visited)
  1012. .Select((it, o) => new Satisfaction
  1013. {
  1014. Dissatisfied = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "2"), 1, 0)),
  1015. Satisfied = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "2"), 0, 1)),
  1016. })
  1017. .ToListAsync();
  1018. if (listOrg != null && listOrg.Count > 0)
  1019. {
  1020. var SatisfiedCount = listOrg[0].Satisfied + listOrg[0].Satisfied;
  1021. if (SatisfiedCount > 0 && listOrg[0].Satisfied > 0)
  1022. centerReportVisitd.OrgRate = Math.Round((listOrg[0].Satisfied / (double)SatisfiedCount) * 100, 2);
  1023. }
  1024. //if (centerReportVisitd.Visitd > 0 && listOrg != null && listOrg.Count > 0 && listOrg[0].Satisfied > 0)
  1025. //centerReportVisitd.OrgRate = Math.Round((listOrg[0].Satisfied / (double)centerReportVisitd.Visitd) * 100, 2);
  1026. //坐席
  1027. var listSet = await _orderVisitDetailRepository.Queryable()
  1028. .LeftJoin<OrderVisit>((it, o) => it.VisitId == o.Id)
  1029. .Where((it, o) => it.VisitTarget == EVisitTarget.Seat && o.VisitTime >= StartDate && o.VisitTime <= EndDate && o.VisitState == EVisitState.Visited)
  1030. .Select((it, o) => new Satisfaction
  1031. {
  1032. Dissatisfied = SqlFunc.AggregateSum(SqlFunc.IIF(it.SeatEvaluate == ESeatEvaluate.VeryNoSatisfied || it.SeatEvaluate == ESeatEvaluate.NoSatisfied, 1, 0)),
  1033. Satisfied = SqlFunc.AggregateSum(SqlFunc.IIF(it.SeatEvaluate != ESeatEvaluate.VeryNoSatisfied && it.SeatEvaluate != ESeatEvaluate.NoSatisfied, 1, 0)),
  1034. }).ToListAsync();
  1035. if (listSet != null && listSet.Count > 0)
  1036. {
  1037. var SatisfiedCount = listSet[0].Satisfied + listSet[0].Satisfied;
  1038. if (SatisfiedCount > 0 && listSet[0].Satisfied > 0)
  1039. centerReportVisitd.OrgRate = Math.Round((listSet[0].Satisfied / (double)SatisfiedCount) * 100, 2);
  1040. }
  1041. //if (centerReportVisitd.Visitd > 0 && listSet != null && listSet.Count > 0 && listSet[0].Satisfied > 0)
  1042. // centerReportVisitd.SeatsRate = Math.Round((listSet[0].Satisfied / (double)centerReportVisitd.Visitd) * 100, 2);
  1043. centerReportStatisticsDto.CenterReportVisitd = centerReportVisitd;
  1044. #endregion
  1045. #region 信件分布情况
  1046. //市直部门
  1047. var listOrgStatisticsCityAll = await _orderRepository.Queryable()
  1048. .LeftJoin<SystemOrganize>((it, o) => it.OrgLevelOneCode == o.Id)
  1049. .Where((it, o) => (o.OrgType == EOrgType.City || o.OrgType == EOrgType.Province) && it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1050. .GroupBy((it, o) => new
  1051. {
  1052. it.OrgLevelOneCode,
  1053. o.Name
  1054. })
  1055. .Select((it, o) => new OrgStatistics
  1056. {
  1057. CountNum = SqlFunc.AggregateCount(it.OrgLevelOneCode),
  1058. OrgName = it.OrgLevelOneCode == "001" ? "热线中心" : o.Name
  1059. }).ToListAsync();
  1060. centerReportStatisticsDto.OrgStatisticsCityAll = new OrgStatisticsAll
  1061. {
  1062. OrgStatistics = listOrgStatisticsCityAll
  1063. };
  1064. //区县部门
  1065. var listOrgStatisticsAreaAll = await _orderRepository.Queryable()
  1066. .LeftJoin<SystemOrganize>((it, o) => it.OrgLevelOneCode == o.Id)
  1067. .Where((it, o) => o.OrgType == EOrgType.County && it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1068. .GroupBy((it, o) => new
  1069. {
  1070. it.OrgLevelOneCode,
  1071. o.Name
  1072. })
  1073. .Select((it, o) => new OrgStatistics
  1074. {
  1075. CountNum = SqlFunc.AggregateCount(it.OrgLevelOneCode),
  1076. OrgName = it.OrgLevelOneCode == "001" ? "热线中心" : o.Name
  1077. }).ToListAsync();
  1078. centerReportStatisticsDto.OrgStatisticsAreaAll = new OrgStatisticsAll
  1079. {
  1080. OrgStatistics = listOrgStatisticsAreaAll
  1081. };
  1082. #endregion
  1083. return centerReportStatisticsDto;
  1084. }
  1085. /// <summary>
  1086. /// 部门受理类型统计周期
  1087. /// </summary>
  1088. /// <param name="StartDate"></param>
  1089. /// <param name="EndDate"></param>
  1090. /// <param name="TypeCode">0:全部,1:中心,2:部门</param>
  1091. /// <returns></returns>
  1092. [HttpGet("department_acceptance_type_statistics")]
  1093. public async Task<List<DepartmentAcceptanceTypeStatisticsDto>> DepartmentAcceptanceTypeStatistics(DateTime StartDate, DateTime EndDate, int TypeCode)
  1094. {
  1095. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1096. var IsCenter = _sessionContext.OrgIsCenter;
  1097. var orderData = await _orderRepository.Queryable()
  1098. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate && it.Status > EOrderStatus.WaitForAccept)
  1099. .Select(it => new
  1100. {
  1101. OrgCode = IsCenter == true ? it.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : it.ActualHandleOrgCode.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1102. it.AcceptTypeCode,
  1103. it.FileDurationWorkday,
  1104. it.AllDuration
  1105. })
  1106. .MergeTable()
  1107. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  1108. .WhereIF(TypeCode == 1, (it, o) => it.OrgCode == "001")
  1109. .WhereIF(TypeCode == 2, (it, o) => it.OrgCode != "001")
  1110. .WhereIF(IsCenter == false, (it, o) => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1111. .GroupBy((it, o) => new
  1112. {
  1113. it.OrgCode,
  1114. o.Name,
  1115. o.OrgType
  1116. })
  1117. .Select((it, o) => new DepartmentAcceptanceTypeStatisticsDto
  1118. {
  1119. OrgName = it.OrgCode == "001" ? "热线中心" : o.Name,
  1120. OrgCode = it.OrgCode,
  1121. OrgType = (int)o.OrgType == 2 ? "区县部门" : "市直部门",
  1122. ZxAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10", 1, 0)),
  1123. ZxAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10" && it.AllDuration != null, it.AllDuration, 0)),
  1124. ZxAcceptanceTypeCode = "10",
  1125. JyAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15", 1, 0)),
  1126. JyAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1127. JyAcceptanceTypeCode = "15",
  1128. QzAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20", 1, 0)),
  1129. QzAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1130. QzAcceptanceTypeCode = "20",
  1131. ByAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25", 1, 0)),
  1132. ByAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1133. ByAcceptanceTypeCode = "25",
  1134. JbAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30", 1, 0)),
  1135. JbAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1136. JbAcceptanceTypeCode = "30",
  1137. TsAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35", 1, 0)),
  1138. TsAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1139. TsAcceptanceTypeCode = "35",
  1140. QtAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40", 1, 0)),
  1141. QtAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1142. QtAcceptanceTypeCode = "40"
  1143. })
  1144. .ToListAsync();
  1145. return orderData;
  1146. }
  1147. /// <summary>
  1148. /// 部门受理类型统计周期---子级
  1149. /// </summary>
  1150. /// <param name="StartDate"></param>
  1151. /// <param name="EndDate"></param>
  1152. /// <param name="TypeCode">0:全部,1:中心,2:部门</param>
  1153. /// <param name="OrgCode"></param>
  1154. /// <returns></returns>
  1155. [HttpGet("department_acceptance_type_child_statistics")]
  1156. public async Task<object> DepartmentAcceptanceTypeChildStatistics(DateTime StartDate, DateTime EndDate, int TypeCode, string OrgCode)
  1157. {
  1158. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1159. // var IsCenter = _sessionContext.OrgIsCenter;
  1160. var orderData = await _orderRepository.Queryable()
  1161. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate && it.Status > EOrderStatus.WaitForAccept)// && it.Status >= EOrderStatus.Filed
  1162. .WhereIF(OrgCode == "001", it => it.ActualHandleOrgCode == OrgCode)
  1163. .WhereIF(OrgCode != "001", it => it.ActualHandleOrgCode.StartsWith(OrgCode))
  1164. .Select(it => new
  1165. {
  1166. // OrgCode = OrgCode == "001" ? OrgCode : it.ActualHandleOrgCode.Substring(0, OrgCode.Length + 3),
  1167. OrgCode = it.ActualHandleOrgCode == "001" ? it.ActualHandleOrgCode : it.ActualHandleOrgCode.Substring(0, OrgCode.Length + 3),
  1168. it.AcceptTypeCode,
  1169. it.FileDurationWorkday,
  1170. it.AllDuration
  1171. })
  1172. .MergeTable()
  1173. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  1174. .WhereIF(TypeCode == 1, (it, o) => it.OrgCode == "001")
  1175. .WhereIF(TypeCode == 2, (it, o) => it.OrgCode != "001")
  1176. //.WhereIF(IsCenter == false, (it, o) => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1177. .GroupBy((it, o) => new
  1178. {
  1179. it.OrgCode,
  1180. o.Name,
  1181. o.OrgType
  1182. })
  1183. .Select((it, o) => new DepartmentAcceptanceTypeStatisticsDto
  1184. {
  1185. OrgName = it.OrgCode == "001" ? "热线中心" : o.Name,
  1186. OrgCode = it.OrgCode,
  1187. OrgType = (int)o.OrgType == 2 ? "区县部门" : "市直部门",
  1188. ZxAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10", 1, 0)),
  1189. ZxAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10" && it.AllDuration != null, it.AllDuration, 0)),
  1190. ZxAcceptanceTypeCode = "10",
  1191. JyAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15", 1, 0)),
  1192. JyAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1193. JyAcceptanceTypeCode = "15",
  1194. QzAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20", 1, 0)),
  1195. QzAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1196. QzAcceptanceTypeCode = "20",
  1197. ByAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25", 1, 0)),
  1198. ByAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1199. ByAcceptanceTypeCode = "25",
  1200. JbAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30", 1, 0)),
  1201. JbAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1202. JbAcceptanceTypeCode = "30",
  1203. TsAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35", 1, 0)),
  1204. TsAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1205. TsAcceptanceTypeCode = "35",
  1206. QtAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40", 1, 0)),
  1207. QtAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1208. QtAcceptanceTypeCode = "40"
  1209. })
  1210. .ToListAsync();
  1211. var sumModel = new DepartmentAcceptanceTypeStatisticsDto
  1212. {
  1213. OrgName = "合计",
  1214. ZxAllCount = orderData.Sum(x => x.ZxAllCount),
  1215. ZxAllTimes = orderData.Sum(x => x.ZxAllTimes),
  1216. ZxAcceptanceTypeCode = "10",
  1217. JyAllCount = orderData.Sum(x => x.JyAllCount),
  1218. JyAllTimes = orderData.Sum(x => x.JyAllTimes),
  1219. JyAcceptanceTypeCode = "15",
  1220. QzAllCount = orderData.Sum(x => x.QzAllCount),
  1221. QzAllTimes = orderData.Sum(x => x.QzAllTimes),
  1222. QzAcceptanceTypeCode = "20",
  1223. ByAllCount = orderData.Sum(x => x.ByAllCount),
  1224. ByAllTimes = orderData.Sum(x => x.ByAllTimes),
  1225. ByAcceptanceTypeCode = "25",
  1226. JbAllCount = orderData.Sum(x => x.JbAllCount),
  1227. JbAllTimes = orderData.Sum(x => x.JbAllTimes),
  1228. JbAcceptanceTypeCode = "30",
  1229. TsAllCount = orderData.Sum(x => x.TsAllCount),
  1230. TsAllTimes = orderData.Sum(x => x.TsAllTimes),
  1231. TsAcceptanceTypeCode = "35",
  1232. QtAllCount = orderData.Sum(x => x.QtAllCount),
  1233. QtAllTimes = orderData.Sum(x => x.QtAllTimes),
  1234. QtAcceptanceTypeCode = "40"
  1235. };
  1236. return new { DataList = orderData, SumModel = sumModel };
  1237. }
  1238. /// <summary>
  1239. /// 部门受理类型统计周期--明细列表
  1240. /// </summary>
  1241. /// <param name="dto"></param>
  1242. /// <returns></returns>
  1243. [HttpGet("department_acceptance_type_order_list")]
  1244. public async Task<PagedDto<OrderDto>> DepartmentAcceptanceTypeOrderList([FromQuery] DepartmentKeyWordRequest dto)
  1245. {
  1246. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  1247. var (total, items) = await _orderRepository.Queryable()
  1248. .Where(p => p.CreationTime >= dto.StartDate && p.CreationTime <= dto.EndDate && p.Status > EOrderStatus.WaitForAccept)//&& p.Status >= EOrderStatus.Filed
  1249. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.OrgCode == "001", p => p.ActualHandleOrgCode == dto.OrgCode)
  1250. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.OrgCode != "001" && _sessionContext.RequiredOrgId != dto.OrgCode, p => p.ActualHandleOrgCode.StartsWith(dto.OrgCode))
  1251. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.OrgCode != "001" && _sessionContext.RequiredOrgId == dto.OrgCode, p => p.ActualHandleOrgCode == dto.OrgCode)
  1252. .WhereIF(!string.IsNullOrEmpty(dto.AcceptTypeCode), p => p.AcceptTypeCode == dto.AcceptTypeCode)
  1253. .WhereIF(dto.TypeCode == 1, p => p.ActualHandleOrgCode == "001")
  1254. .WhereIF(dto.TypeCode == 2, p => p.ActualHandleOrgCode != "001")
  1255. .OrderByDescending(d => d.CreationTime)
  1256. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1257. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  1258. }
  1259. /// <summary>
  1260. /// 部门办件统计表-----未完成
  1261. /// </summary>
  1262. /// <param name="StartDate"></param>
  1263. /// <param name="EndDate"></param>
  1264. /// <param name="OrgCode"></param>
  1265. /// <param name="OrgName"></param>
  1266. /// <returns></returns>
  1267. [HttpGet("departmental_processing_statistics")]
  1268. [AllowAnonymous]
  1269. public async Task<object> DepartmentalProcessingStatistics(DateTime StartDate, DateTime EndDate, string? OrgCode, string? OrgName)
  1270. {
  1271. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1272. var handeOrgDownNum = 0;
  1273. if (!string.IsNullOrEmpty(OrgCode) && OrgCode != "001")
  1274. {
  1275. handeOrgDownNum = OrgCode.Length + 3;
  1276. }
  1277. //工单
  1278. var query = _orderRepository.Queryable()
  1279. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1280. .Select(it => new
  1281. {
  1282. it.Id,
  1283. OrgLevelOneCode = SqlFunc.IIF(it.ActualHandleOrgCode != "001", SqlFunc.Substring(it.ActualHandleOrgCode, 0, 6), it.ActualHandleOrgCode),
  1284. OrgLevelDownCode = SqlFunc.IIF(!string.IsNullOrEmpty(OrgCode) && OrgCode != "001" && it.ActualHandleOrgCode.Length >= handeOrgDownNum
  1285. , SqlFunc.Substring(it.ActualHandleOrgCode, 0, handeOrgDownNum), it.ActualHandleOrgCode),
  1286. it.ActualHandleOrgCode,
  1287. it.Status,//工单状态
  1288. it.ExpiredTime,//期满时间
  1289. it.ActualHandleTime,//办理时间
  1290. it.CounterSignType,//会签
  1291. }).MergeTable()
  1292. .WhereIF(!string.IsNullOrEmpty(OrgCode) && OrgCode == "001", it => it.OrgLevelOneCode == OrgCode)
  1293. .WhereIF(!string.IsNullOrEmpty(OrgCode) && OrgCode != "001", it => it.OrgLevelDownCode.Contains(OrgCode))
  1294. .MergeTable()
  1295. .Select(it => new DepartmentalProcessingStatisticsDto
  1296. {
  1297. Id = it.Id,
  1298. OrgCode = SqlFunc.IIF(!string.IsNullOrEmpty(OrgCode), it.OrgLevelDownCode, it.OrgLevelOneCode),
  1299. ActualHandleOrgCode = it.ActualHandleOrgCode,
  1300. Status = it.Status,//工单状态
  1301. ExpiredTime = it.ExpiredTime,//期满时间
  1302. ActualHandleTime = it.ActualHandleTime,//办理时间
  1303. CounterSignType = it.CounterSignType,//会签
  1304. }).MergeTable();
  1305. //发布
  1306. var queryPublish = _orderPublishRepository.Queryable()
  1307. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  1308. .GroupBy(it => new
  1309. {
  1310. it.OrderId,
  1311. it.PublishState
  1312. })
  1313. .Select(it => new DepartmentalProcessingStatisticsDto
  1314. {
  1315. Id = it.OrderId,
  1316. PublishState = it.PublishState
  1317. });
  1318. //会签
  1319. var queryCountersign = _workflowCountersignRepository.Queryable()
  1320. .LeftJoin<WorkflowCountersignMember>((x, o) => x.Id == o.WorkflowCountersignId)
  1321. .Where(x => x.CreationTime >= StartDate && x.CreationTime <= EndDate)
  1322. .GroupBy((x, o) => o.Key)
  1323. .Select((x, o) => new DepartmentalProcessingStatisticsDataDto
  1324. {
  1325. OrgCode = o.Key,
  1326. HQYBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled, 1, 0)),
  1327. HQZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(!o.IsHandled, 1, 0)),
  1328. DelayEnd = SqlFunc.AggregateSum(SqlFunc.IIF(!o.IsHandled, 1, 0)),
  1329. DelayWait = SqlFunc.AggregateSum(SqlFunc.IIF(!o.IsHandled, 1, 0)),
  1330. }).MergeTable();
  1331. var queryPush = query.LeftJoin(queryPublish, (it, o) => it.Id == o.Id).Where(it => it.OrgCode != null);
  1332. return await queryPush.GroupBy((it, o) => new
  1333. {
  1334. it.OrgCode
  1335. })
  1336. .Select((it, o) => new
  1337. {
  1338. //办件信息完整
  1339. OrgCode = it.OrgCode,
  1340. OrderCountNum = SqlFunc.AggregateCount(it.OrgCode),//总量
  1341. YBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300, 1, 0)),//已办
  1342. ZBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status < 300, 1, 0)),//在办
  1343. YBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300 && it.ActualHandleTime > it.ExpiredTime, 1, 0)),//已办超期
  1344. ZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status < 300 && it.ExpiredTime < SqlFunc.GetDate(), 1, 0)),//待办超期
  1345. HQYBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300 && it.CounterSignType != null && it.ActualHandleTime > it.ExpiredTime, 1, 0)),//会签已办超期
  1346. HQZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status < 300 && it.CounterSignType != null && it.ExpiredTime < SqlFunc.GetDate(), 1, 0)),//会签待办超期
  1347. //归档完整
  1348. Archived = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300, 1, 0)),//已归档
  1349. ToBeArchived = 0,//待归档
  1350. //发布完整
  1351. WaitPublished = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status == 300, 1, 0)),//待发布 --已归档的就是待发布
  1352. PublishedOpen = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 400 && o.PublishState, 1, 0)),//已发布公开
  1353. PublishedNoOpen = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 400 && !o.PublishState, 1, 0)),//已发布不公开
  1354. }).ToListAsync();
  1355. }
  1356. /// <summary>
  1357. /// 高频来电统计
  1358. /// </summary>
  1359. /// <param name="dto"></param>
  1360. /// <returns></returns>
  1361. [HttpGet("high_frequency_call_statistics")]
  1362. public async Task<PagedDto<HighFrequencyCallStatisticsDto>> HighFrequencyCallStatistics([FromQuery] HighFrequencyCallStatisticsRequest dto)
  1363. {
  1364. if (!dto.StartDate.HasValue || !dto.EndDate.HasValue)
  1365. throw UserFriendlyException.SameMessage("请选择时间!");
  1366. dto.EndDate = dto.EndDate.Value.AddDays(1).AddSeconds(-1);
  1367. int CallCount = 2;
  1368. var HighFrequencyCallStatistics = _systemSettingCacheManager.GetSetting(SettingConstants.HighFrequencyCallStatistics)?.SettingValue[0];
  1369. if (HighFrequencyCallStatistics != null)
  1370. CallCount = int.Parse(HighFrequencyCallStatistics);
  1371. var (total, items) = await _trCallRecordRepository.Queryable()
  1372. .LeftJoin<Order>((p, o) => p.ExternalId == o.Id)
  1373. .Where((p, o) => p.OverTime >= dto.StartDate && p.OverTime <= dto.EndDate)
  1374. .Where((p, o) => p.CallOrderType == ECallOrderType.Order)
  1375. .Where((p, o) => p.ExternalId != null && o.Id != null)
  1376. .WhereIF(!string.IsNullOrEmpty(dto.PhoneNum), (p, o) => p.CPN == dto.PhoneNum)
  1377. .Select((p, o) => new
  1378. {
  1379. p.CPN,
  1380. p.ExternalId
  1381. })
  1382. .MergeTable()
  1383. .GroupBy(p => p.CPN)
  1384. .Select(p => new HighFrequencyCallStatisticsDto
  1385. {
  1386. Callnum = p.CPN,
  1387. OrderCountNum = SqlFunc.AggregateCount(p.CPN),//总量
  1388. })
  1389. .MergeTable()
  1390. .Where(p => p.OrderCountNum >= CallCount)
  1391. .OrderByDescending(p => p.OrderCountNum)
  1392. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  1393. return new PagedDto<HighFrequencyCallStatisticsDto>(total, _mapper.Map<IReadOnlyList<HighFrequencyCallStatisticsDto>>(items));
  1394. }
  1395. /// <summary>
  1396. /// 高频来电统计列表详情
  1397. /// </summary>
  1398. /// <param name="dto"></param>
  1399. /// <returns></returns>
  1400. [HttpGet("high_frequency_call_statistics_order_list")]
  1401. public async Task<PagedDto<OrderDto>> HighFrequencyCallStatisticsOrderList([FromQuery] HighFrequencyCallStatisticsListRequest dto)
  1402. {
  1403. if (!dto.StartDate.HasValue || !dto.EndDate.HasValue)
  1404. throw UserFriendlyException.SameMessage("请选择时间!");
  1405. if (string.IsNullOrEmpty(dto.FromPhone))
  1406. throw UserFriendlyException.SameMessage("号码不能为空!");
  1407. dto.EndDate = dto.EndDate.Value.AddDays(1).AddSeconds(-1);
  1408. var data = await _trCallRecordRepository.Queryable()
  1409. .LeftJoin<Order>((p, o) => p.ExternalId == o.Id)
  1410. .Where((p, o) => p.OverTime >= dto.StartDate && p.OverTime <= dto.EndDate)
  1411. .Where((p, o) => p.CallOrderType == ECallOrderType.Order)
  1412. .Where((p, o) => p.ExternalId != null && o.Id != null)
  1413. .Where((p, o) => p.CPN == dto.FromPhone)
  1414. .Select((p, o) =>
  1415. p.ExternalId
  1416. )
  1417. .ToListAsync();
  1418. var (total, items) = await _orderRepository.Queryable()
  1419. .Includes(x => x.OrderScreens)
  1420. .Where(p => data.Contains(p.Id))
  1421. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Title.Contains(dto.Keyword!)) //标题
  1422. .WhereIF(!string.IsNullOrEmpty(dto.ProvinceNo), d => d.ProvinceNo.Contains(dto.ProvinceNo)) //省本地编号
  1423. .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.No.Contains(dto.No)) //工单编码
  1424. .WhereIF(dto.AcceptTypes.Any(), d => dto.AcceptTypes.Contains(d.AcceptTypeCode)) //受理类型
  1425. .WhereIF(dto.Channels.Any(), d => dto.Channels.Contains(d.SourceChannelCode)) //来源渠道
  1426. .WhereIF(dto.HotspotIds.Any(), d => dto.HotspotIds.Contains(d.HotspotId)) //热点类型
  1427. .WhereIF(!string.IsNullOrEmpty(dto.TransferPhone), d => d.TransferPhone.Contains(dto.TransferPhone!)) //转接号码
  1428. .WhereIF(dto.OrgCodes.Any(), d => dto.OrgCodes.Contains(d.ActualHandleOrgCode)) //接办部门
  1429. .WhereIF(!string.IsNullOrEmpty(dto.NameOrNo), d => d.AcceptorName.Contains(dto.NameOrNo!) || d.AcceptorStaffNo.Contains(dto.NameOrNo!)) //受理人/坐席
  1430. .WhereIF(dto.CreationTimeStart.HasValue, d => d.CreationTime >= dto.CreationTimeStart) //受理时间开始
  1431. .WhereIF(dto.CreationTimeEnd.HasValue, d => d.CreationTime <= dto.CreationTimeEnd) //受理时间结束
  1432. .WhereIF(dto.EmergencyLevels.Any(), d => dto.EmergencyLevels.Contains(d.EmergencyLevel)) //紧急程度
  1433. // .WhereIF(!string.IsNullOrEmpty(dto.FromPhone), d => d.FromPhone.Contains(dto.FromPhone)) //来电号码
  1434. .WhereIF(!string.IsNullOrEmpty(dto.PhoneNo), d => d.Contact.Contains(dto.PhoneNo!)) //联系电话
  1435. .WhereIF(!string.IsNullOrEmpty(dto.PushTypeCode), d => d.PushTypeCode == dto.PushTypeCode) //推送分类
  1436. .WhereIF(dto.ExpiredTimeStart.HasValue, d => d.ExpiredTime >= dto.ExpiredTimeStart) //超期时间开始
  1437. .WhereIF(dto.ExpiredTimeEnd.HasValue, d => d.ExpiredTime <= dto.ExpiredTimeEnd) //超期时间结束
  1438. .WhereIF(dto.Statuses.Any(), d => dto.Statuses.Contains(d.Status)) //工单状态
  1439. .WhereIF(dto.Statuses.Any(d => d == EOrderStatus.SpecialToUnAccept), d => d.Status <= EOrderStatus.SpecialToUnAccept)
  1440. .WhereIF(!string.IsNullOrEmpty(dto.ActualHandlerName), d => d.ActualHandlerName.Contains(dto.ActualHandlerName)) //接办人
  1441. .WhereIF(dto.IsScreen == true, d => d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //有甄别
  1442. .WhereIF(dto.IsScreen == false, d => !d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //无甄别
  1443. .WhereIF(!string.IsNullOrEmpty(dto.CurrentStepCode), d => d.ActualHandleStepCode == dto.CurrentStepCode) //当前办理节点
  1444. .WhereIF(dto.ActualHandleTimeStart.HasValue, d => d.ActualHandleTime >= dto.ActualHandleTimeStart) //办结时间开始
  1445. .WhereIF(dto.ActualHandleTimeEnd.HasValue, d => d.ActualHandleTime <= dto.ActualHandleTimeEnd) //办结时间结束
  1446. .WhereIF(dto.IsOverTime == true, d => (d.ExpiredTime < DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime < d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //是 超期
  1447. .WhereIF(dto.IsOverTime == false, d => (d.ExpiredTime > DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime > d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //否 超期
  1448. .WhereIF(dto.IdentityType != null, d => d.IdentityType == dto.IdentityType) //来电主体
  1449. .WhereIF(!string.IsNullOrEmpty(dto.FromName), d => d.FromName.Contains(dto.FromName)) //来电人姓名
  1450. .WhereIF(dto.AreaCodes.Any(), d => dto.AreaCodes.Contains(d.AreaCode)) //区域
  1451. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == true, x => x.IsProvince == true)
  1452. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == false, x => x.IsProvince == false)
  1453. .OrderByDescending(d => d.CreationTime)
  1454. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1455. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  1456. }
  1457. /// <summary>
  1458. /// 高频事项预警
  1459. /// </summary>
  1460. /// <param name="dto"></param>
  1461. /// <returns></returns>
  1462. [HttpGet("highmatter-warning")]
  1463. public async Task<PagedDto<HighMatterWarningDto>> HighMatterWarning([FromQuery] HighMatterWarningRequest dto)
  1464. {
  1465. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  1466. var (total, items) = await _orderRepository.Queryable()
  1467. .Where(x => x.CreationTime >= dto.StartDate && x.CreationTime <= dto.EndDate)
  1468. .LeftJoin<SystemArea>((it, o) => it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  1469. .WhereIF(dto.AreaCodes.Any(), (it, o) => dto.AreaCodes.Contains(it.AreaCode)) //区域
  1470. .WhereIF(dto.HotspotIds.Any(), (it, o) => dto.HotspotIds.Contains(it.HotspotId)) //热点类型
  1471. .WhereIF(dto.AcceptTypeCodes.Any(), (it, o) => dto.AcceptTypeCodes.Contains(it.AcceptTypeCode)) //受理类型
  1472. .GroupBy((it, o) => new
  1473. {
  1474. it.AcceptTypeCode,
  1475. it.AcceptType,
  1476. it.HotspotId,
  1477. it.HotspotName,
  1478. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1479. o.AreaName,
  1480. })
  1481. .Having((it, o) => SqlFunc.AggregateCount(it.HotspotName) >= 5)
  1482. .Select((it, o) => new HighMatterWarningDto()
  1483. {
  1484. AcceptTypeCode = it.AcceptTypeCode,
  1485. AcceptType = it.AcceptType,
  1486. AreaName = o.AreaName,
  1487. HotspotName = it.HotspotName,
  1488. HotspotId = it.HotspotId,
  1489. SumCount = SqlFunc.AggregateCount(it.HotspotName),
  1490. Id = SqlFunc.AggregateMin(it.Id),
  1491. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  1492. })
  1493. .MergeTable()
  1494. .LeftJoin<Order>((x, d) => x.Id == d.Id)
  1495. .Select((x, d) => new HighMatterWarningDto()
  1496. {
  1497. AreaName = x.AreaName,
  1498. HotspotName = x.HotspotName,
  1499. HotspotId = x.HotspotId,
  1500. Title = d.Title,
  1501. SumCount = x.SumCount,
  1502. Id = d.Id,
  1503. AcceptTypeCode = x.AcceptTypeCode,
  1504. AcceptType = x.AcceptType,
  1505. AreaCode = x.AreaCode
  1506. })
  1507. .MergeTable()
  1508. .OrderByDescending(d => d.SumCount).ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  1509. return new PagedDto<HighMatterWarningDto>(total, _mapper.Map<IReadOnlyList<HighMatterWarningDto>>(items));
  1510. }
  1511. /// <summary>
  1512. /// 高频事项预警明细
  1513. /// </summary>
  1514. /// <param name="dto"></param>
  1515. /// <returns></returns>
  1516. [HttpGet("highmatter-warning-detail")]
  1517. public async Task<PagedDto<OrderDto>> HighMatterWarningDetail([FromQuery] HighMatterWarningDetailRequest dto)
  1518. {
  1519. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  1520. var (total, items) = await _orderRepository.Queryable()
  1521. .Includes(x => x.OrderScreens)
  1522. .Where(d => d.AcceptTypeCode == dto.AcceptTypeCode) //受理类型
  1523. .Where(d => d.HotspotId == dto.HotspotId) //热点类型
  1524. .Where(d => d.CreationTime >= dto.StartDate) //受理时间开始
  1525. .Where(d => d.CreationTime <= dto.EndDate) //受理时间结束
  1526. .Where(d => d.AreaCode == dto.AreaCode) //区域
  1527. .OrderByDescending(d => d.CreationTime)
  1528. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1529. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  1530. }
  1531. /// <summary>
  1532. /// 回退错件
  1533. /// </summary>
  1534. /// <param name="dto"></param>
  1535. /// <returns></returns>
  1536. [HttpGet("reTransact")]
  1537. public async Task<PagedDto<OrderReTransactVo>> OrderReTransact([FromQuery] QueryOrderReTransactRequest dto)
  1538. {
  1539. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  1540. throw UserFriendlyException.SameMessage("请选择时间!");
  1541. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1542. var (total, items) = await _orderSpecialDetailRepository.Queryable()
  1543. .Includes(x => x.OrderSpecial)
  1544. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.OrgName.Contains(dto.OrgName!))
  1545. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  1546. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  1547. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime)
  1548. .GroupBy(x => new { Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"), x.OrgId, x.OrgName })
  1549. .Select(x => new OrderReTransactVo
  1550. {
  1551. Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"),
  1552. OrgId = x.OrgId,
  1553. OrgName = x.OrgName,
  1554. Num = SqlFunc.AggregateCount(1)
  1555. }).MergeTable()
  1556. .OrderByIF(dto.SortRule == 0, x => x.Num, OrderByType.Asc)
  1557. .OrderByIF(dto.SortRule == 1, x => x.Num, OrderByType.Desc)
  1558. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1559. return new PagedDto<OrderReTransactVo>(total, _mapper.Map<IReadOnlyList<OrderReTransactVo>>(items));
  1560. }
  1561. /// <summary>
  1562. /// 回退错件明细
  1563. /// </summary>
  1564. /// <param name="dto"></param>
  1565. /// <returns></returns>
  1566. [HttpGet("reTransact_detail")]
  1567. public async Task<PagedDto<OrderSpecialDetailDto>> OrderReTransactDetail([FromQuery] QueryOrderReTransactDetailRequest dto)
  1568. {
  1569. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  1570. throw UserFriendlyException.SameMessage("请选择时间!");
  1571. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1572. var (total, items) = await _orderSpecialDetailRepository.Queryable()
  1573. .Includes(x => x.OrderSpecial, s => s.Order)
  1574. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.OrgName.Contains(dto.OrgName!))
  1575. .WhereIF(!string.IsNullOrEmpty(dto.ErrorName), x => x.ErrorName.Contains(dto.ErrorName!))
  1576. .WhereIF(!string.IsNullOrEmpty(dto.No), x => x.OrderSpecial!.Order!.No!.Contains(dto.No!))
  1577. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  1578. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  1579. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime)
  1580. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1581. return new PagedDto<OrderSpecialDetailDto>(total, _mapper.Map<IReadOnlyList<OrderSpecialDetailDto>>(items));
  1582. }
  1583. /// <summary>
  1584. /// 获取基本信息
  1585. /// </summary>
  1586. /// <param name="id"></param>
  1587. /// <returns></returns>
  1588. [HttpGet("reTransact_base")]
  1589. public async Task<object> ReTransactBaseData()
  1590. {
  1591. var rsp = new
  1592. {
  1593. ReTransactErrorType = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.ReTransactErrorType),
  1594. };
  1595. return rsp;
  1596. }
  1597. /// <summary>
  1598. /// 派单量统计
  1599. /// </summary>
  1600. /// <param name="dto"></param>
  1601. /// <returns></returns>
  1602. [HttpGet("send_order_report")]
  1603. public async Task<object> SendOrderReport([FromQuery] QuerySendOrderRequest dto)
  1604. {
  1605. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  1606. throw UserFriendlyException.SameMessage("请选择时间!");
  1607. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1608. var items = await _workflowTraceRepository.Queryable()
  1609. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  1610. .LeftJoin<WorkflowStepHandler>((x, w, wsh) => x.StepId == wsh.WorkflowStepId)
  1611. .InnerJoin<SchedulingUser>((x, w, wsh, su) => wsh.UserId == su.UserId)
  1612. .Where((x, w, wsh, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send)
  1613. .Where((x, w, wsh, su) =>x.CreationTime >= dto.StartTime.Value)
  1614. .Where((x, w, wsh, su) => x.CreationTime <= dto.EndTime.Value)
  1615. .WhereIF(!string.IsNullOrEmpty(dto.UserName),(x, w, wsh, su) => su.UserName == dto.UserName)
  1616. .GroupBy((x, w, wsh, su) => new { su.UserId, su.UserName})
  1617. .Having((x, w, wsh, su) => SqlFunc.AggregateCount(x.WorkflowId) == 1)
  1618. .Select((x, w, wsh, su) => new BiOrderSendVo
  1619. {
  1620. UserId = su.UserId,
  1621. UserName = su.UserName,
  1622. SendOrderNum = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  1623. NoSendOrderNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.HandlerId == null || x.HandlerId == "", 1, 0)),
  1624. ReSendOrderNum = 0,
  1625. }).ToListAsync();
  1626. var items2 = await _workflowTraceRepository.Queryable()
  1627. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  1628. .LeftJoin<WorkflowStepHandler>((x, w, wsh) => x.StepId == wsh.WorkflowStepId)
  1629. .InnerJoin<SchedulingUser>((x, w, wsh, su) => wsh.UserId == su.UserId)
  1630. .Where((x, w, wsh, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send)
  1631. .Where((x, w, wsh, su) => x.CreationTime >= dto.StartTime.Value)
  1632. .Where((x, w, wsh, su) => x.CreationTime <= dto.EndTime.Value)
  1633. .WhereIF(!string.IsNullOrEmpty(dto.UserName), (x, w, wsh, su) => su.UserName == dto.UserName)
  1634. .GroupBy((x, w, wsh, su) => new { su.UserId, su.UserName })
  1635. .Having((x, w, wsh, su) => SqlFunc.AggregateCount(x.WorkflowId) > 1)
  1636. .Select((x, w, wsh, su) => new BiOrderSendVo
  1637. {
  1638. UserId = su.UserId,
  1639. UserName = su.UserName,
  1640. SendOrderNum = 0,
  1641. NoSendOrderNum = 0,
  1642. ReSendOrderNum = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  1643. }).ToListAsync();
  1644. var res = (from t1 in items
  1645. join t2 in items2 on t1.UserId equals t2.UserId into t1_t2
  1646. from item in t1_t2.DefaultIfEmpty()
  1647. select new
  1648. {
  1649. UserId = t1.UserId,
  1650. UserName = t1.UserName,
  1651. SendOrderNum = t1.SendOrderNum,
  1652. NoSendOrderNum = t1.NoSendOrderNum,
  1653. ReSendOrderNum = t1_t2.Select(x => x.NoSendOrderNum).FirstOrDefault(),
  1654. ChainRate = t1_t2.Select(x => x.NoSendOrderNum).FirstOrDefault() > 0 ?
  1655. ((double.Parse(t1.SendOrderNum.ToString()) - double.Parse(t1_t2.Select(x => x.NoSendOrderNum).FirstOrDefault().ToString())) / double.Parse(t1.SendOrderNum.ToString()) * 100).ToString("F2") + "%" : "100.00%",
  1656. }).ToList();
  1657. return res;
  1658. }
  1659. }
  1660. }