BiOrderController.cs 93 KB

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