BiOrderController.cs 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  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 IsCenter = _sessionContext.OrgIsCenter;
  494. var query = _orderRepository.Queryable(false, false, false)
  495. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  496. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  497. .WhereIF(IsCenter == false, x => x.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  498. .Select(x => new
  499. {
  500. AcceptType = x.AcceptType,
  501. OneHotspot = SqlFunc.Substring(x.HotspotSpliceName, 0, SqlFunc.CharIndex("-", x.HotspotSpliceName + "-")),
  502. Id = x.Id
  503. }).MergeTable()
  504. .GroupBy(x => new { x.OneHotspot })
  505. .Select(x => new AcceptTypeTop10Vo
  506. {
  507. Name = x.OneHotspot,
  508. ValidAccept = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  509. Consult = SqlFunc.AggregateSum(SqlFunc.IIF("咨询".Equals(x.AcceptType), 1, 0)),
  510. Report = SqlFunc.AggregateSum(SqlFunc.IIF("举报".Equals(x.AcceptType), 1, 0)),
  511. Complaint = SqlFunc.AggregateSum(SqlFunc.IIF("投诉".Equals(x.AcceptType), 1, 0)),
  512. SeekHelp = SqlFunc.AggregateSum(SqlFunc.IIF("求助".Equals(x.AcceptType), 1, 0)),
  513. Suggest = SqlFunc.AggregateSum(SqlFunc.IIF("建议".Equals(x.AcceptType), 1, 0)),
  514. Opinion = SqlFunc.AggregateSum(SqlFunc.IIF("意见".Equals(x.AcceptType), 1, 0)),
  515. Rests = SqlFunc.AggregateSum(SqlFunc.IIF("其他".Equals(x.AcceptType), 1, 0)),
  516. BenefitThePeople = SqlFunc.AggregateSum(SqlFunc.IIF("惠民帮助".Equals(x.AcceptType), 1, 0)),
  517. Praise = SqlFunc.AggregateSum(SqlFunc.IIF("表扬".Equals(x.AcceptType), 1, 0)),
  518. }).MergeTable();
  519. switch (dto.SortField)
  520. {
  521. case "validAccept":
  522. query = dto.SortRule == 0 ? query.OrderBy(x => x.ValidAccept) : query.OrderByDescending(x => x.ValidAccept);
  523. break;
  524. case "consult":
  525. query = dto.SortRule == 0 ? query.OrderBy(x => x.Consult) : query.OrderByDescending(x => x.Consult);
  526. break;
  527. case "report":
  528. query = dto.SortRule == 0 ? query.OrderBy(x => x.Report) : query.OrderByDescending(x => x.Report);
  529. break;
  530. case "complaint":
  531. query = dto.SortRule == 0 ? query.OrderBy(x => x.Complaint) : query.OrderByDescending(x => x.Complaint);
  532. break;
  533. case "seekHelp":
  534. query = dto.SortRule == 0 ? query.OrderBy(x => x.SeekHelp) : query.OrderByDescending(x => x.SeekHelp);
  535. break;
  536. case "suggest":
  537. query = dto.SortRule == 0 ? query.OrderBy(x => x.Suggest) : query.OrderByDescending(x => x.Suggest);
  538. break;
  539. case "opinion":
  540. query = dto.SortRule == 0 ? query.OrderBy(x => x.Opinion) : query.OrderByDescending(x => x.Opinion);
  541. break;
  542. case "rests":
  543. query = dto.SortRule == 0 ? query.OrderBy(x => x.Rests) : query.OrderByDescending(x => x.Rests);
  544. break;
  545. case "benefitThePeople":
  546. query = dto.SortRule == 0 ? query.OrderBy(x => x.BenefitThePeople) : query.OrderByDescending(x => x.BenefitThePeople);
  547. break;
  548. case "praise":
  549. query = dto.SortRule == 0 ? query.OrderBy(x => x.Praise) : query.OrderByDescending(x => x.Praise);
  550. break;
  551. default:
  552. query = query.OrderByDescending(x => x.ValidAccept);
  553. break;
  554. }
  555. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  556. return new PagedDto<AcceptTypeTop10Vo>(total, items);
  557. }
  558. /// <summary>
  559. /// 热点类型部门统计
  560. /// </summary>
  561. /// <param name="dto"></param>
  562. /// <returns></returns>
  563. [HttpGet("hotport-org-statistics")]
  564. public async Task<object> HotPortJoinOrgStatistics([FromQuery] HotPortJoinOrgStatisticsRequest dto)
  565. {
  566. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  567. var IsCenter = _sessionContext.OrgIsCenter;
  568. return await _orderRepository.HotPortJoinOrgStatistics(dto.StartTime, dto.EndTime, IsCenter, _sessionContext.OrgId);
  569. }
  570. /// <summary>
  571. /// 回访量统计
  572. /// </summary>
  573. /// <returns></returns>
  574. [HttpGet("visit-measure-statistics")]
  575. public async Task<VisitMeasureStatisticsDto> VisitMeasureStatistics(DateTime StartDate, DateTime EndDate, string? VisitName)
  576. {
  577. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  578. var list = await _orderVisitRepository.Queryable()
  579. .Includes(x => x.Employee)
  580. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited)
  581. .WhereIF(!string.IsNullOrEmpty(VisitName), x => x.Employee.Name.Contains(VisitName))
  582. .GroupBy(x => new { x.EmployeeId, x.Employee.Name })
  583. .Select(x => new VisitMeasureStatisticsModelDto()
  584. {
  585. VisitName = x.Employee.Name,
  586. CallVisitCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitType == EVisitType.CallVisit, 1, 0)),
  587. ArtificialVisitCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitType != EVisitType.CallVisit, 1, 0)),
  588. SumCount = SqlFunc.AggregateCount(x.EmployeeId)
  589. })
  590. .ToListAsync();
  591. var returnModel = new VisitMeasureStatisticsDto();
  592. returnModel.VisitMeasureStatisticsModelList = list;
  593. //查询AIVisit
  594. returnModel.AiVisitCount = await _aiOrderVisitDetailRepository.Queryable()
  595. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess != null).CountAsync();
  596. returnModel.AiVisitSatisfiedCount = await _aiOrderVisitDetailRepository.Queryable()
  597. .Includes(x => x.OrderVisit)
  598. .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();
  599. returnModel.AiVisitNoSatisfiedCount = await _aiOrderVisitDetailRepository.Queryable()
  600. .Includes(x => x.OrderVisit)
  601. .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();
  602. returnModel.AIVisitFailCount = await _aiOrderVisitDetailRepository.Queryable()
  603. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess == false).CountAsync();
  604. return returnModel;
  605. }
  606. /// <summary>
  607. /// 热点类型小类统计
  608. /// </summary>
  609. /// <param name="StartDate"></param>
  610. /// <param name="EndDate"></param>
  611. /// <param name="TypeId">0:全部 ,1:市民,2:企业</param>
  612. /// <returns></returns>
  613. [HttpGet("hotspot-statistics")]
  614. public async Task<object> HotspotStatistics(DateTime StartDate, DateTime EndDate, int TypeId, string? HotspotCode)
  615. {
  616. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  617. if (string.IsNullOrEmpty(HotspotCode))
  618. {
  619. var list = await _hotspotTypeRepository.Queryable()
  620. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  621. .Where((it, o) => o.CreationTime >= StartDate && o.CreationTime <= EndDate && o.Id != null)
  622. .WhereIF(TypeId == 1, (it, o) => o.IdentityType == EIdentityType.Citizen)
  623. .WhereIF(TypeId == 2, (it, o) => o.IdentityType == EIdentityType.Enterprise)
  624. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")) })
  625. .Select((it, o) => new
  626. {
  627. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")),
  628. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  629. })
  630. .MergeTable()
  631. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  632. .Select((x, q) => new
  633. {
  634. HotspotCode = x.HotspotCode,
  635. SumCount = x.SumCount,
  636. HotspotName = q.HotSpotName,
  637. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  638. })
  639. .ToListAsync();
  640. return list;
  641. }
  642. else
  643. {
  644. string count = (HotspotCode.Length + 2).ToString();
  645. string countx = HotspotCode.Length.ToString();
  646. var list = await _hotspotTypeRepository.Queryable()
  647. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  648. .Where((it, o) => o.CreationTime >= StartDate && o.CreationTime <= EndDate && it.ParentId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(countx)) == HotspotCode)
  649. .WhereIF(TypeId == 1, (it, o) => o.IdentityType == EIdentityType.Citizen)
  650. .WhereIF(TypeId == 2, (it, o) => o.IdentityType == EIdentityType.Enterprise)
  651. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)) })
  652. .Select((it, o) => new
  653. {
  654. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)),
  655. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  656. })
  657. .MergeTable()
  658. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  659. .Select((x, q) => new
  660. {
  661. HotspotCode = x.HotspotCode,
  662. SumCount = x.SumCount,
  663. HotspotName = q.HotSpotName,
  664. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  665. })
  666. .ToListAsync();
  667. return list;
  668. }
  669. }
  670. /// <summary>
  671. /// 部门满意度统计
  672. /// </summary>
  673. /// <param name="StartDate"></param>
  674. /// <param name="EndDate"></param>
  675. /// <param name="OrgName"></param>
  676. /// <param name="TypeId">1:办件结果 2:办件态度</param>
  677. /// <param name="LineNum"></param>
  678. /// <returns></returns>
  679. [HttpGet("visit-org-satisfaction-statistics")]
  680. public async Task<VisitAndOrgSatisfactionStatisticsResultDto> VisitAndOrgSatisfactionStatistics(DateTime StartDate, DateTime EndDate, string OrgName, int TypeId, string? LineNum)
  681. {
  682. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  683. bool IsCenter = _sessionContext.OrgIsCenter;
  684. var list = await _orderVisitDetailRepository.Queryable()
  685. .Where(x => x.OrderVisit.VisitTime >= StartDate && x.OrderVisit.VisitTime <= EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited && !string.IsNullOrEmpty(x.VisitOrgCode))
  686. .WhereIF(string.IsNullOrEmpty(OrgName)==false, x => x.VisitOrgName.Contains(OrgName))
  687. .WhereIF(string.IsNullOrEmpty(LineNum)==false, x => x.OrderVisit.Order.CallRecord.Gateway.Contains(LineNum))
  688. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  689. .GroupByIF(IsCenter,x => new
  690. {
  691. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  692. })
  693. .GroupByIF(IsCenter == false, x => new
  694. {
  695. VisitOrgCode = x.VisitOrgCode
  696. })
  697. .Select(x => new VisitAndOrgSatisfactionStatisticsDto()
  698. {
  699. OrgCode = SqlFunc.IIF(IsCenter,x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")), x.VisitOrgCode),
  700. TotalSumCount = SqlFunc.AggregateCount(x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  701. 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))),//非常满意数
  702. 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))), //满意数
  703. 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))),//视为满意
  704. 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))),//默认满意
  705. 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))),//不满意
  706. 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))),//未做评价
  707. 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))),//未接通
  708. })
  709. .MergeTable()
  710. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  711. .Select((it, o) => new VisitAndOrgSatisfactionStatisticsDto()
  712. {
  713. OrgName = o.Name,
  714. OrgCode = it.OrgCode,
  715. OrgType = o.OrgType,
  716. TotalSumCount = it.TotalSumCount,
  717. VerySatisfiedCount = it.VerySatisfiedCount,//非常满意数
  718. SatisfiedCount = it.SatisfiedCount, //满意数
  719. RegardedAsSatisfiedCount = it.RegardedAsSatisfiedCount,//视为满意
  720. DefaultSatisfiedCount = it.DefaultSatisfiedCount,//默认满意
  721. NoSatisfiedCount = it.NoSatisfiedCount,//不满意
  722. NoEvaluateCount = it.NoEvaluateCount,//未做评价
  723. NoPutThroughCount = it.NoPutThroughCount,//未接通
  724. })
  725. .ToListAsync();
  726. var countySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  727. {
  728. OrgName = "区县合计",
  729. TotalSumCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.TotalSumCount),
  730. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.VerySatisfiedCount),
  731. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.SatisfiedCount),
  732. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.RegardedAsSatisfiedCount),
  733. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.DefaultSatisfiedCount),
  734. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoSatisfiedCount),
  735. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoEvaluateCount),
  736. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoPutThroughCount),
  737. };
  738. var citySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  739. {
  740. OrgName = "市直合计",
  741. TotalSumCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.TotalSumCount),
  742. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.VerySatisfiedCount),
  743. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.SatisfiedCount),
  744. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.RegardedAsSatisfiedCount),
  745. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.DefaultSatisfiedCount),
  746. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoSatisfiedCount),
  747. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoEvaluateCount),
  748. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoPutThroughCount),
  749. };
  750. var sumModel = new VisitAndOrgSatisfactionStatisticsDto()
  751. {
  752. OrgName = "总计",
  753. TotalSumCount = list.Sum(x => x.TotalSumCount),
  754. VerySatisfiedCount = list.Sum(x => x.VerySatisfiedCount),
  755. SatisfiedCount = list.Sum(x => x.SatisfiedCount),
  756. RegardedAsSatisfiedCount = list.Sum(x => x.RegardedAsSatisfiedCount),
  757. DefaultSatisfiedCount = list.Sum(x => x.DefaultSatisfiedCount),
  758. NoSatisfiedCount = list.Sum(x => x.NoSatisfiedCount),
  759. NoEvaluateCount = list.Sum(x => x.NoEvaluateCount),
  760. NoPutThroughCount = list.Sum(x => x.NoPutThroughCount),
  761. };
  762. return new VisitAndOrgSatisfactionStatisticsResultDto { DataList = list, CountySumModel = countySumModel, CitySumModel = citySumModel, SumModel = sumModel };
  763. }
  764. /// <summary>
  765. /// 子部门满意度明细
  766. /// </summary>
  767. /// <param name="StartDate"></param>
  768. /// <param name="EndDate"></param>
  769. /// <param name="OrgCode"></param>
  770. /// <param name="TypeId"></param>
  771. /// <param name="LineNum"></param>
  772. /// <returns></returns>
  773. [HttpGet("visit-org-statisfaction-org-detail")]
  774. public async Task<VisitAndOrgSatisfactionStatisticsResultDto> VisitAndOrgStatisfactionOrgDetail(DateTime StartDate, DateTime EndDate, string OrgCode, int TypeId, string? LineNum)
  775. {
  776. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  777. bool IsCenter = _sessionContext.OrgIsCenter;
  778. var list = await _systemOrganizeRepository.Queryable().Where(x => x.Id.StartsWith(OrgCode))
  779. .LeftJoin<OrderVisitDetail>((x, it) => x.Id == it.VisitOrgCode)
  780. .Where((x, it) => it.OrderVisit.VisitTime >= StartDate && it.OrderVisit.VisitTime <= EndDate && it.VisitTarget == EVisitTarget.Org && it.OrderVisit.VisitState == EVisitState.Visited)
  781. .WhereIF(!string.IsNullOrEmpty(LineNum), (x, it) => it.OrderVisit.Order.CallRecord.Gateway.Contains(LineNum))
  782. .WhereIF(IsCenter == false, (x, it) => it.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  783. .GroupBy((x, it) => new
  784. {
  785. VisitOrgCode = it.VisitOrgCode
  786. })
  787. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  788. {
  789. OrgCode = it.VisitOrgCode,
  790. TotalSumCount = SqlFunc.AggregateCount(it.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("9"))),
  791. 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))),//非常满意数
  792. 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))), //满意数
  793. 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))),//视为满意
  794. 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))),//默认满意
  795. 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))),//不满意
  796. 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))),//未做评价
  797. 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)))//未接通
  798. })
  799. .MergeTable()
  800. .LeftJoin<SystemOrganize>((x, it) => x.OrgCode == it.Id)
  801. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  802. {
  803. OrgName = it.Name,
  804. OrgCode = x.OrgCode,
  805. OrgType = it.OrgType,
  806. TotalSumCount = x.TotalSumCount,
  807. VerySatisfiedCount = x.VerySatisfiedCount,//非常满意数
  808. SatisfiedCount = x.SatisfiedCount, //满意数
  809. RegardedAsSatisfiedCount = x.RegardedAsSatisfiedCount,//视为满意
  810. DefaultSatisfiedCount = x.DefaultSatisfiedCount,//默认满意
  811. NoSatisfiedCount = x.NoSatisfiedCount,//不满意
  812. NoEvaluateCount = x.NoEvaluateCount,//未做评价
  813. NoPutThroughCount = x.NoPutThroughCount,//未接通
  814. })
  815. .ToListAsync();
  816. var countySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  817. {
  818. OrgName = "区县合计",
  819. TotalSumCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.TotalSumCount),
  820. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.VerySatisfiedCount),
  821. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.SatisfiedCount),
  822. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.RegardedAsSatisfiedCount),
  823. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.DefaultSatisfiedCount),
  824. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoSatisfiedCount),
  825. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoEvaluateCount),
  826. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoPutThroughCount),
  827. };
  828. var citySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  829. {
  830. OrgName = "市直合计",
  831. TotalSumCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.TotalSumCount),
  832. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.VerySatisfiedCount),
  833. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.SatisfiedCount),
  834. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.RegardedAsSatisfiedCount),
  835. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.DefaultSatisfiedCount),
  836. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoSatisfiedCount),
  837. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoEvaluateCount),
  838. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoPutThroughCount),
  839. };
  840. var sumModel = new VisitAndOrgSatisfactionStatisticsDto()
  841. {
  842. OrgName = "总计",
  843. TotalSumCount = list.Sum(x => x.TotalSumCount),
  844. VerySatisfiedCount = list.Sum(x => x.VerySatisfiedCount),
  845. SatisfiedCount = list.Sum(x => x.SatisfiedCount),
  846. RegardedAsSatisfiedCount = list.Sum(x => x.RegardedAsSatisfiedCount),
  847. DefaultSatisfiedCount = list.Sum(x => x.DefaultSatisfiedCount),
  848. NoSatisfiedCount = list.Sum(x => x.NoSatisfiedCount),
  849. NoEvaluateCount = list.Sum(x => x.NoEvaluateCount),
  850. NoPutThroughCount = list.Sum(x => x.NoPutThroughCount),
  851. };
  852. return new VisitAndOrgSatisfactionStatisticsResultDto { DataList = list, CountySumModel = countySumModel, CitySumModel = citySumModel, SumModel = sumModel };
  853. }
  854. /// <summary>
  855. /// 部门满意度明细
  856. /// </summary>
  857. /// <param name="StartDate"></param>
  858. /// <param name="EndDate"></param>
  859. /// <param name="OrgCode"></param>
  860. /// <param name="TypeId"></param>
  861. /// <param name="LineNum"></param>
  862. /// <returns></returns>
  863. [HttpGet("visit-org-satisfaction-detail")]
  864. public async Task<PagedDto<OrderVisitDetailDto>> VisitAndOrgSatisfactionDetail([FromQuery] VisitAndOrgSatisfactionDetailDto dto)
  865. {
  866. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  867. var (total, items) = await _orderVisitDetailRepository.Queryable()
  868. .Includes(x => x.OrderVisit, o => o.Order, d => d.CallRecord)
  869. .Where(x => x.OrderVisit.VisitTime >= dto.StartDate && x.OrderVisit.VisitTime <= dto.EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited)
  870. .WhereIF(dto.OrgCode == "001", x => x.VisitOrgCode == dto.OrgCode)
  871. .WhereIF(dto.OrgCode != "001", x => x.VisitOrgCode.StartsWith(dto.OrgCode))
  872. .WhereIF(dto.TypeId == 1, x => SqlFunc.JsonField(x.OrgProcessingResults, "Key") == dto.DateValue)
  873. .WhereIF(dto.TypeId == 2, x => SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == dto.DateValue)
  874. .WhereIF(!string.IsNullOrEmpty(dto.LineNum), x => x.OrderVisit.Order.CallRecord.Gateway == dto.LineNum)
  875. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  876. return new PagedDto<OrderVisitDetailDto>(total, _mapper.Map<IReadOnlyList<OrderVisitDetailDto>>(items));
  877. }
  878. /// <summary>
  879. /// 中心报表统计
  880. /// </summary>
  881. /// <param name="StartDate"></param>
  882. /// <param name="EndDate"></param>
  883. /// <returns></returns>
  884. [HttpGet("center_report_forms_statistics")]
  885. public async Task<CenterReportStatisticsDto> CenterReportFormsStatistics(DateTime StartDate, DateTime EndDate)
  886. {
  887. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  888. CenterReportStatisticsDto centerReportStatisticsDto = new();
  889. //信件总量
  890. int sourceChannelCount = await _orderRepository.Queryable().Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate).CountAsync();
  891. #region 通话记录
  892. //通话记录
  893. var callData = await _trCallRecordRepository.Queryable()
  894. .Where(p => p.CreatedTime >= StartDate && p.CreatedTime <= EndDate)
  895. .Select(o => new CenterReportCallDto
  896. {
  897. EffectiveCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.OnState == EOnState.On, 1, 0)),//有效
  898. InvalidCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.OnState == EOnState.NoOn && o.BeginIvrTime.HasValue && o.BeginQueueTime.HasValue && o.BeginRingTime.HasValue, 1, 0)), //无效(排除队列挂断和IVR挂断)
  899. QueueByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In && o.QueueTims > 0 && o.RingTimes == 0, 1, 0)), //队列挂断
  900. 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挂断
  901. })
  902. .ToListAsync();
  903. if (callData != null && callData.Count > 0)
  904. centerReportStatisticsDto.CenterReportCall = callData[0];
  905. #endregion
  906. #region 工单
  907. //工单
  908. var orderData = await _orderRepository.Queryable()
  909. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  910. .Select(x => new CenterReportOrderDto
  911. {
  912. EffectiveCount = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  913. InvalidCount = 0,
  914. CompletedCount = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status >= 300, 1, 0)),
  915. InProgressCount = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status < 300, 1, 0))
  916. })
  917. .ToListAsync();
  918. if (orderData != null && orderData.Count > 0)
  919. centerReportStatisticsDto.CenterReportOrder = orderData[0];
  920. #endregion
  921. #region 信件来源
  922. //信件来源
  923. var sourceChannelData = await _orderRepository.Queryable()
  924. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  925. .Select(it => new
  926. {
  927. SourceChannelCode = SqlFunc.IIF(SqlFunc.IsNullOrEmpty(it.SourceChannelCode), "QT", it.SourceChannelCode)
  928. })
  929. .MergeTable()//将查询出来的结果合并成一个新表
  930. .GroupBy(it => new { it.SourceChannelCode })//对新表进行分组
  931. .Select(it => new CenterReportOrderSourceChannelDto
  932. {
  933. Code = it.SourceChannelCode,
  934. CountNum = SqlFunc.AggregateCount(it.SourceChannelCode)
  935. })
  936. .ToListAsync();
  937. List<CenterReportOrderSourceChannelDto> sourceChannel = new()
  938. {
  939. new CenterReportOrderSourceChannelDto
  940. {
  941. Name = "来源总量",
  942. Code = "All",
  943. CountNum = sourceChannelCount
  944. }
  945. };
  946. var sourceChannelDic = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.SourceChannel);
  947. foreach (var item in sourceChannelDic)
  948. {
  949. sourceChannel.Add(new CenterReportOrderSourceChannelDto
  950. {
  951. Name = item.DicDataName,
  952. Code = item.DicTypeCode,
  953. CountNum = sourceChannelData.Find(p => p.Code == item.DicDataValue)?.CountNum ?? 0
  954. });
  955. }
  956. centerReportStatisticsDto.CenterReportOrderSourceChannels = sourceChannel;
  957. #endregion
  958. #region 信件分类
  959. //信件来源
  960. var acceptTypeData = await _orderRepository.Queryable(false, false, false)
  961. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  962. .Select(it => new
  963. {
  964. AcceptTypeCode = SqlFunc.IIF(SqlFunc.IsNullOrEmpty(it.AcceptTypeCode), "40", it.AcceptTypeCode)
  965. })
  966. .MergeTable()//将查询出来的结果合并成一个新表
  967. .GroupBy(it => new { it.AcceptTypeCode })//对新表进行分组
  968. .Select(it => new CenterReportOrderSourceChannelDto
  969. {
  970. Code = it.AcceptTypeCode,
  971. CountNum = SqlFunc.AggregateCount(it.AcceptTypeCode)
  972. })
  973. .ToListAsync();
  974. List<CenterReportOrderSourceChannelDto> acceptType = new();
  975. var acceptTypeDic = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.AcceptType);
  976. foreach (var item in acceptTypeDic)
  977. {
  978. acceptType.Add(new CenterReportOrderSourceChannelDto
  979. {
  980. AllCountNum = sourceChannelCount,
  981. Name = item.DicDataName,
  982. Code = item.DicTypeCode,
  983. CountNum = acceptTypeData.Find(p => p.Code == item.DicDataValue)?.CountNum ?? 0
  984. });
  985. }
  986. centerReportStatisticsDto.CenterReportOrderAcceptTypes = acceptType;
  987. #endregion
  988. #region 信件回访量
  989. //信件回访量
  990. CenterReportVisitdDto centerReportVisitd = new()
  991. {
  992. Visitd = await _orderVisitRepository.Queryable()
  993. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited).CountAsync(),
  994. WaitVisitd = await _orderVisitRepository.Queryable()
  995. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState != EVisitState.None && x.VisitState != EVisitState.Visited).CountAsync()
  996. };
  997. //部门
  998. var listOrg = await _orderVisitDetailRepository.Queryable()
  999. .LeftJoin<OrderVisit>((it, o) => it.VisitId == o.Id)
  1000. .Where((it, o) => it.VisitTarget == EVisitTarget.Org && o.VisitTime >= StartDate && o.VisitTime <= EndDate && o.VisitState == EVisitState.Visited)
  1001. .Select((it, o) => new Satisfaction
  1002. {
  1003. Dissatisfied = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "2"), 1, 0)),
  1004. Satisfied = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "2"), 0, 1)),
  1005. })
  1006. .ToListAsync();
  1007. if (listOrg != null && listOrg.Count > 0)
  1008. {
  1009. var SatisfiedCount = listOrg[0].Satisfied + listOrg[0].Satisfied;
  1010. if (SatisfiedCount > 0 && listOrg[0].Satisfied > 0)
  1011. centerReportVisitd.OrgRate = Math.Round((listOrg[0].Satisfied / (double)SatisfiedCount) * 100, 2);
  1012. }
  1013. //if (centerReportVisitd.Visitd > 0 && listOrg != null && listOrg.Count > 0 && listOrg[0].Satisfied > 0)
  1014. //centerReportVisitd.OrgRate = Math.Round((listOrg[0].Satisfied / (double)centerReportVisitd.Visitd) * 100, 2);
  1015. //坐席
  1016. var listSet = await _orderVisitDetailRepository.Queryable()
  1017. .LeftJoin<OrderVisit>((it, o) => it.VisitId == o.Id)
  1018. .Where((it, o) => it.VisitTarget == EVisitTarget.Seat && o.VisitTime >= StartDate && o.VisitTime <= EndDate && o.VisitState == EVisitState.Visited)
  1019. .Select((it, o) => new Satisfaction
  1020. {
  1021. Dissatisfied = SqlFunc.AggregateSum(SqlFunc.IIF(it.SeatEvaluate == ESeatEvaluate.VeryNoSatisfied || it.SeatEvaluate == ESeatEvaluate.NoSatisfied, 1, 0)),
  1022. Satisfied = SqlFunc.AggregateSum(SqlFunc.IIF(it.SeatEvaluate != ESeatEvaluate.VeryNoSatisfied && it.SeatEvaluate != ESeatEvaluate.NoSatisfied, 1, 0)),
  1023. }).ToListAsync();
  1024. if (listSet != null && listSet.Count > 0)
  1025. {
  1026. var SatisfiedCount = listSet[0].Satisfied + listSet[0].Satisfied;
  1027. if (SatisfiedCount > 0 && listSet[0].Satisfied > 0)
  1028. centerReportVisitd.OrgRate = Math.Round((listSet[0].Satisfied / (double)SatisfiedCount) * 100, 2);
  1029. }
  1030. //if (centerReportVisitd.Visitd > 0 && listSet != null && listSet.Count > 0 && listSet[0].Satisfied > 0)
  1031. // centerReportVisitd.SeatsRate = Math.Round((listSet[0].Satisfied / (double)centerReportVisitd.Visitd) * 100, 2);
  1032. centerReportStatisticsDto.CenterReportVisitd = centerReportVisitd;
  1033. #endregion
  1034. #region 信件分布情况
  1035. //市直部门
  1036. var listOrgStatisticsCityAll = await _orderRepository.Queryable()
  1037. .LeftJoin<SystemOrganize>((it, o) => it.OrgLevelOneCode == o.Id)
  1038. .Where((it, o) => (o.OrgType == EOrgType.City || o.OrgType == EOrgType.Province) && it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1039. .GroupBy((it, o) => new
  1040. {
  1041. it.OrgLevelOneCode,
  1042. o.Name
  1043. })
  1044. .Select((it, o) => new OrgStatistics
  1045. {
  1046. CountNum = SqlFunc.AggregateCount(it.OrgLevelOneCode),
  1047. OrgName = it.OrgLevelOneCode == "001" ? "热线中心" : o.Name
  1048. }).ToListAsync();
  1049. centerReportStatisticsDto.OrgStatisticsCityAll = new OrgStatisticsAll
  1050. {
  1051. OrgStatistics = listOrgStatisticsCityAll
  1052. };
  1053. //区县部门
  1054. var listOrgStatisticsAreaAll = await _orderRepository.Queryable()
  1055. .LeftJoin<SystemOrganize>((it, o) => it.OrgLevelOneCode == o.Id)
  1056. .Where((it, o) => o.OrgType == EOrgType.County && it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1057. .GroupBy((it, o) => new
  1058. {
  1059. it.OrgLevelOneCode,
  1060. o.Name
  1061. })
  1062. .Select((it, o) => new OrgStatistics
  1063. {
  1064. CountNum = SqlFunc.AggregateCount(it.OrgLevelOneCode),
  1065. OrgName = it.OrgLevelOneCode == "001" ? "热线中心" : o.Name
  1066. }).ToListAsync();
  1067. centerReportStatisticsDto.OrgStatisticsAreaAll = new OrgStatisticsAll
  1068. {
  1069. OrgStatistics = listOrgStatisticsAreaAll
  1070. };
  1071. #endregion
  1072. return centerReportStatisticsDto;
  1073. }
  1074. /// <summary>
  1075. /// 部门受理类型统计周期
  1076. /// </summary>
  1077. /// <param name="StartDate"></param>
  1078. /// <param name="EndDate"></param>
  1079. /// <param name="TypeCode">0:全部,1:中心,2:部门</param>
  1080. /// <returns></returns>
  1081. [HttpGet("department_acceptance_type_statistics")]
  1082. public async Task<List<DepartmentAcceptanceTypeStatisticsDto>> DepartmentAcceptanceTypeStatistics(DateTime StartDate, DateTime EndDate, int TypeCode)
  1083. {
  1084. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1085. var IsCenter = _sessionContext.OrgIsCenter;
  1086. var orderData = await _orderRepository.Queryable()
  1087. // .LeftJoin<SystemOrganize>((it, o) => it.OrgLevelOneCode == o.Id)
  1088. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate && it.Status >= EOrderStatus.Filed)
  1089. .Select(it => new
  1090. {
  1091. OrgCode = IsCenter == true ? it.OrgLevelOneCode : it.ActualHandleOrgCode.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1092. it.AcceptTypeCode,
  1093. it.FileDurationWorkday,
  1094. it.AllDuration
  1095. })
  1096. .MergeTable()
  1097. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  1098. .WhereIF(TypeCode == 1, (it, o) => it.OrgCode == "001")
  1099. .WhereIF(TypeCode == 2, (it, o) => it.OrgCode != "001")
  1100. .WhereIF(IsCenter == false, (it, o) => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1101. .GroupBy((it, o) => new
  1102. {
  1103. it.OrgCode,
  1104. o.Name,
  1105. o.OrgType
  1106. })
  1107. .Select((it, o) => new DepartmentAcceptanceTypeStatisticsDto
  1108. {
  1109. OrgName = it.OrgCode == "001" ? "热线中心" : o.Name,
  1110. OrgCode = it.OrgCode,
  1111. OrgType = (int)o.OrgType == 2 ? "区县部门" : "市直部门",
  1112. ZxAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10", 1, 0)),
  1113. ZxAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10" && it.AllDuration != null, it.AllDuration, 0)),
  1114. ZxAcceptanceTypeCode = "10",
  1115. JyAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15", 1, 0)),
  1116. JyAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1117. JyAcceptanceTypeCode = "15",
  1118. QzAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20", 1, 0)),
  1119. QzAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1120. QzAcceptanceTypeCode = "20",
  1121. ByAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25", 1, 0)),
  1122. ByAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1123. ByAcceptanceTypeCode = "25",
  1124. JbAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30", 1, 0)),
  1125. JbAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1126. JbAcceptanceTypeCode = "30",
  1127. TsAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35", 1, 0)),
  1128. TsAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1129. TsAcceptanceTypeCode = "35",
  1130. QtAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40", 1, 0)),
  1131. QtAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1132. QtAcceptanceTypeCode = "40"
  1133. })
  1134. .ToListAsync();
  1135. return orderData;
  1136. }
  1137. /// <summary>
  1138. /// 部门受理类型统计周期--明细列表
  1139. /// </summary>
  1140. /// <param name="dto"></param>
  1141. /// <returns></returns>
  1142. [HttpGet("department_acceptance_type_order_list")]
  1143. public async Task<PagedDto<OrderDto>> DepartmentAcceptanceTypeOrderList([FromQuery] DepartmentKeyWordRequest dto)
  1144. {
  1145. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  1146. var (total, items) = await _orderRepository.Queryable()
  1147. .Where(p => p.CreationTime >= dto.StartDate && p.CreationTime <= dto.EndDate && p.Status >= EOrderStatus.Filed)
  1148. .WhereIF(!string.IsNullOrEmpty(dto.OrgLevelOneCode) && dto.OrgLevelOneCode == "001", p => p.OrgLevelOneCode == dto.OrgLevelOneCode)
  1149. .WhereIF(!string.IsNullOrEmpty(dto.OrgLevelOneCode) && dto.OrgLevelOneCode != "001", p => p.ActualHandleOrgCode.StartsWith(dto.OrgLevelOneCode))
  1150. .WhereIF(!string.IsNullOrEmpty(dto.AcceptTypeCode), p => p.AcceptTypeCode == dto.AcceptTypeCode)
  1151. .WhereIF(dto.TypeCode == 1, p => p.OrgLevelOneCode == "001")
  1152. .WhereIF(dto.TypeCode == 2, p => p.OrgLevelOneCode != "001")
  1153. .OrderByDescending(d => d.CreationTime)
  1154. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1155. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  1156. }
  1157. /// <summary>
  1158. /// 部门办件统计表-----未完成
  1159. /// </summary>
  1160. /// <param name="StartDate"></param>
  1161. /// <param name="EndDate"></param>
  1162. /// <param name="OrgCode"></param>
  1163. /// <param name="OrgName"></param>
  1164. /// <returns></returns>
  1165. [HttpGet("departmental_processing_statistics")]
  1166. [AllowAnonymous]
  1167. public async Task<object> DepartmentalProcessingStatistics(DateTime StartDate, DateTime EndDate, string? OrgCode, string? OrgName)
  1168. {
  1169. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1170. var handeOrgDownNum = 0;
  1171. if (!string.IsNullOrEmpty(OrgCode) && OrgCode != "001")
  1172. {
  1173. handeOrgDownNum = OrgCode.Length + 3;
  1174. }
  1175. //工单
  1176. var query = _orderRepository.Queryable()
  1177. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1178. .Select(it => new
  1179. {
  1180. it.Id,
  1181. OrgLevelOneCode = SqlFunc.IIF(it.ActualHandleOrgCode != "001", SqlFunc.Substring(it.ActualHandleOrgCode, 0, 6), it.ActualHandleOrgCode),
  1182. OrgLevelDownCode = SqlFunc.IIF(!string.IsNullOrEmpty(OrgCode) && OrgCode != "001" && it.ActualHandleOrgCode.Length >= handeOrgDownNum
  1183. , SqlFunc.Substring(it.ActualHandleOrgCode, 0, handeOrgDownNum), it.ActualHandleOrgCode),
  1184. it.ActualHandleOrgCode,
  1185. it.Status,//工单状态
  1186. it.ExpiredTime,//期满时间
  1187. it.ActualHandleTime,//办理时间
  1188. it.CounterSignType,//会签
  1189. }).MergeTable()
  1190. .WhereIF(!string.IsNullOrEmpty(OrgCode) && OrgCode == "001", it => it.OrgLevelOneCode == OrgCode)
  1191. .WhereIF(!string.IsNullOrEmpty(OrgCode) && OrgCode != "001", it => it.OrgLevelDownCode.Contains(OrgCode))
  1192. .MergeTable()
  1193. .Select(it => new DepartmentalProcessingStatisticsDto
  1194. {
  1195. Id = it.Id,
  1196. OrgCode = SqlFunc.IIF(!string.IsNullOrEmpty(OrgCode), it.OrgLevelDownCode, it.OrgLevelOneCode),
  1197. ActualHandleOrgCode = it.ActualHandleOrgCode,
  1198. Status = it.Status,//工单状态
  1199. ExpiredTime = it.ExpiredTime,//期满时间
  1200. ActualHandleTime = it.ActualHandleTime,//办理时间
  1201. CounterSignType = it.CounterSignType,//会签
  1202. }).MergeTable();
  1203. //发布
  1204. var queryPublish = _orderPublishRepository.Queryable()
  1205. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  1206. .GroupBy(it => new
  1207. {
  1208. it.OrderId,
  1209. it.PublishState
  1210. })
  1211. .Select(it => new DepartmentalProcessingStatisticsDto
  1212. {
  1213. Id = it.OrderId,
  1214. PublishState = it.PublishState
  1215. });
  1216. //会签
  1217. var queryCountersign = _workflowCountersignRepository.Queryable()
  1218. .LeftJoin<WorkflowCountersignMember>((x, o) => x.Id == o.WorkflowCountersignId)
  1219. .Where(x => x.CreationTime >= StartDate && x.CreationTime <= EndDate)
  1220. .GroupBy((x, o) => o.Key)
  1221. .Select((x, o) => new DepartmentalProcessingStatisticsDataDto
  1222. {
  1223. OrgCode = o.Key,
  1224. HQYBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled, 1, 0)),
  1225. HQZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(!o.IsHandled, 1, 0)),
  1226. DelayEnd = SqlFunc.AggregateSum(SqlFunc.IIF(!o.IsHandled, 1, 0)),
  1227. DelayWait = SqlFunc.AggregateSum(SqlFunc.IIF(!o.IsHandled, 1, 0)),
  1228. }).MergeTable();
  1229. var queryPush = query.LeftJoin(queryPublish, (it, o) => it.Id == o.Id).Where(it => it.OrgCode != null);
  1230. return await queryPush.GroupBy((it, o) => new
  1231. {
  1232. it.OrgCode
  1233. })
  1234. .Select((it, o) => new
  1235. {
  1236. //办件信息完整
  1237. OrgCode = it.OrgCode,
  1238. OrderCountNum = SqlFunc.AggregateCount(it.OrgCode),//总量
  1239. YBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300, 1, 0)),//已办
  1240. ZBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status < 300, 1, 0)),//在办
  1241. YBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300 && it.ActualHandleTime > it.ExpiredTime, 1, 0)),//已办超期
  1242. ZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status < 300 && it.ExpiredTime < SqlFunc.GetDate(), 1, 0)),//待办超期
  1243. HQYBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300 && it.CounterSignType != null && it.ActualHandleTime > it.ExpiredTime, 1, 0)),//会签已办超期
  1244. HQZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status < 300 && it.CounterSignType != null && it.ExpiredTime < SqlFunc.GetDate(), 1, 0)),//会签待办超期
  1245. //归档完整
  1246. Archived = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 300, 1, 0)),//已归档
  1247. ToBeArchived = 0,//待归档
  1248. //发布完整
  1249. WaitPublished = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status == 300, 1, 0)),//待发布 --已归档的就是待发布
  1250. PublishedOpen = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 400 && o.PublishState, 1, 0)),//已发布公开
  1251. PublishedNoOpen = SqlFunc.AggregateSum(SqlFunc.IIF((int)it.Status >= 400 && !o.PublishState, 1, 0)),//已发布不公开
  1252. }).ToListAsync();
  1253. }
  1254. /// <summary>
  1255. /// 高频来电统计
  1256. /// </summary>
  1257. /// <param name="dto"></param>
  1258. /// <returns></returns>
  1259. [HttpGet("high_frequency_call_statistics")]
  1260. public async Task<PagedDto<HighFrequencyCallStatisticsDto>> HighFrequencyCallStatistics([FromQuery] HighFrequencyCallStatisticsRequest dto)
  1261. {
  1262. if (!dto.StartDate.HasValue || !dto.EndDate.HasValue)
  1263. throw UserFriendlyException.SameMessage("请选择时间!");
  1264. dto.EndDate = dto.EndDate.Value.AddDays(1).AddSeconds(-1);
  1265. int CallCount = 2;
  1266. var HighFrequencyCallStatistics = _systemSettingCacheManager.GetSetting(SettingConstants.HighFrequencyCallStatistics)?.SettingValue[0];
  1267. if (HighFrequencyCallStatistics != null)
  1268. CallCount = int.Parse(HighFrequencyCallStatistics);
  1269. var (total, items) = await _trCallRecordRepository.Queryable()
  1270. .LeftJoin<Order>((p, o) => p.ExternalId == o.Id)
  1271. .Where((p, o) => p.OverTime >= dto.StartDate && p.OverTime <= dto.EndDate)
  1272. .Where((p, o) => p.CallOrderType == ECallOrderType.Order)
  1273. .Where((p, o) => p.ExternalId != null && o.Id != null)
  1274. .WhereIF(!string.IsNullOrEmpty(dto.PhoneNum), (p, o) => p.CPN == dto.PhoneNum)
  1275. .Select((p, o) => new
  1276. {
  1277. p.CPN,
  1278. p.ExternalId
  1279. })
  1280. .MergeTable()
  1281. .GroupBy(p => p.CPN)
  1282. .Select(p => new HighFrequencyCallStatisticsDto
  1283. {
  1284. Callnum = p.CPN,
  1285. OrderCountNum = SqlFunc.AggregateCount(p.CPN),//总量
  1286. })
  1287. .MergeTable()
  1288. .Where(p => p.OrderCountNum >= CallCount)
  1289. .OrderByDescending(p => p.OrderCountNum)
  1290. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  1291. return new PagedDto<HighFrequencyCallStatisticsDto>(total, _mapper.Map<IReadOnlyList<HighFrequencyCallStatisticsDto>>(items));
  1292. }
  1293. /// <summary>
  1294. /// 高频来电统计列表详情
  1295. /// </summary>
  1296. /// <param name="dto"></param>
  1297. /// <returns></returns>
  1298. [HttpGet("high_frequency_call_statistics_order_list")]
  1299. public async Task<PagedDto<OrderDto>> HighFrequencyCallStatisticsOrderList([FromQuery] HighFrequencyCallStatisticsListRequest dto)
  1300. {
  1301. if (!dto.StartDate.HasValue || !dto.EndDate.HasValue)
  1302. throw UserFriendlyException.SameMessage("请选择时间!");
  1303. if (string.IsNullOrEmpty(dto.FromPhone))
  1304. throw UserFriendlyException.SameMessage("号码不能为空!");
  1305. dto.EndDate = dto.EndDate.Value.AddDays(1).AddSeconds(-1);
  1306. var data = await _trCallRecordRepository.Queryable()
  1307. .LeftJoin<Order>((p, o) => p.ExternalId == o.Id)
  1308. .Where((p, o) => p.OverTime >= dto.StartDate && p.OverTime <= dto.EndDate)
  1309. .Where((p, o) => p.CallOrderType == ECallOrderType.Order)
  1310. .Where((p, o) => p.ExternalId != null && o.Id != null)
  1311. .Where((p, o) => p.CPN == dto.FromPhone)
  1312. .Select((p, o) =>
  1313. p.ExternalId
  1314. )
  1315. .ToListAsync();
  1316. var (total, items) = await _orderRepository.Queryable()
  1317. .Includes(x => x.OrderScreens)
  1318. .Where(p => data.Contains(p.Id))
  1319. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Title.Contains(dto.Keyword!)) //标题
  1320. .WhereIF(!string.IsNullOrEmpty(dto.ProvinceNo), d => d.ProvinceNo.Contains(dto.ProvinceNo)) //省本地编号
  1321. .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.No.Contains(dto.No)) //工单编码
  1322. .WhereIF(dto.AcceptTypes.Any(), d => dto.AcceptTypes.Contains(d.AcceptTypeCode)) //受理类型
  1323. .WhereIF(dto.Channels.Any(), d => dto.Channels.Contains(d.SourceChannelCode)) //来源渠道
  1324. .WhereIF(dto.HotspotIds.Any(), d => dto.HotspotIds.Contains(d.HotspotId)) //热点类型
  1325. .WhereIF(!string.IsNullOrEmpty(dto.TransferPhone), d => d.TransferPhone.Contains(dto.TransferPhone!)) //转接号码
  1326. .WhereIF(dto.OrgCodes.Any(), d => dto.OrgCodes.Contains(d.ActualHandleOrgCode)) //接办部门
  1327. .WhereIF(!string.IsNullOrEmpty(dto.NameOrNo), d => d.AcceptorName.Contains(dto.NameOrNo!) || d.AcceptorStaffNo.Contains(dto.NameOrNo!)) //受理人/坐席
  1328. .WhereIF(dto.CreationTimeStart.HasValue, d => d.CreationTime >= dto.CreationTimeStart) //受理时间开始
  1329. .WhereIF(dto.CreationTimeEnd.HasValue, d => d.CreationTime <= dto.CreationTimeEnd) //受理时间结束
  1330. .WhereIF(dto.EmergencyLevels.Any(), d => dto.EmergencyLevels.Contains(d.EmergencyLevel)) //紧急程度
  1331. // .WhereIF(!string.IsNullOrEmpty(dto.FromPhone), d => d.FromPhone.Contains(dto.FromPhone)) //来电号码
  1332. .WhereIF(!string.IsNullOrEmpty(dto.PhoneNo), d => d.Contact.Contains(dto.PhoneNo!)) //联系电话
  1333. .WhereIF(!string.IsNullOrEmpty(dto.PushTypeCode), d => d.PushTypeCode == dto.PushTypeCode) //推送分类
  1334. .WhereIF(dto.ExpiredTimeStart.HasValue, d => d.ExpiredTime >= dto.ExpiredTimeStart) //超期时间开始
  1335. .WhereIF(dto.ExpiredTimeEnd.HasValue, d => d.ExpiredTime <= dto.ExpiredTimeEnd) //超期时间结束
  1336. .WhereIF(dto.Statuses.Any(), d => dto.Statuses.Contains(d.Status)) //工单状态
  1337. .WhereIF(dto.Statuses.Any(d => d == EOrderStatus.SpecialToUnAccept), d => d.Status <= EOrderStatus.SpecialToUnAccept)
  1338. .WhereIF(!string.IsNullOrEmpty(dto.ActualHandlerName), d => d.ActualHandlerName.Contains(dto.ActualHandlerName)) //接办人
  1339. .WhereIF(dto.IsScreen == true, d => d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //有甄别
  1340. .WhereIF(dto.IsScreen == false, d => !d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //无甄别
  1341. .WhereIF(!string.IsNullOrEmpty(dto.CurrentStepCode), d => d.ActualHandleStepCode == dto.CurrentStepCode) //当前办理节点
  1342. .WhereIF(dto.ActualHandleTimeStart.HasValue, d => d.ActualHandleTime >= dto.ActualHandleTimeStart) //办结时间开始
  1343. .WhereIF(dto.ActualHandleTimeEnd.HasValue, d => d.ActualHandleTime <= dto.ActualHandleTimeEnd) //办结时间结束
  1344. .WhereIF(dto.IsOverTime == true, d => (d.ExpiredTime < DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime < d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //是 超期
  1345. .WhereIF(dto.IsOverTime == false, d => (d.ExpiredTime > DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime > d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //否 超期
  1346. .WhereIF(dto.IdentityType != null, d => d.IdentityType == dto.IdentityType) //来电主体
  1347. .WhereIF(!string.IsNullOrEmpty(dto.FromName), d => d.FromName.Contains(dto.FromName)) //来电人姓名
  1348. .WhereIF(dto.AreaCodes.Any(), d => dto.AreaCodes.Contains(d.AreaCode)) //区域
  1349. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == true, x => x.IsProvince == true)
  1350. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == false, x => x.IsProvince == false)
  1351. .OrderByDescending(d => d.CreationTime)
  1352. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1353. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  1354. }
  1355. /// <summary>
  1356. /// 高频事项预警
  1357. /// </summary>
  1358. /// <param name="dto"></param>
  1359. /// <returns></returns>
  1360. [HttpGet("highmatter-warning")]
  1361. public async Task<PagedDto<HighMatterWarningDto>> HighMatterWarning([FromQuery] HighMatterWarningRequest dto)
  1362. {
  1363. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  1364. var (total, items) = await _orderRepository.Queryable()
  1365. .Where(x => x.CreationTime >= dto.StartDate && x.CreationTime <= dto.EndDate)
  1366. .LeftJoin<SystemArea>((it, o) => it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  1367. .WhereIF(dto.AreaCodes.Any(), (it, o) => dto.AreaCodes.Contains(it.AreaCode)) //区域
  1368. .WhereIF(dto.HotspotIds.Any(), (it, o) => dto.HotspotIds.Contains(it.HotspotId)) //热点类型
  1369. .WhereIF(dto.AcceptTypeCodes.Any(), (it, o) => dto.AcceptTypeCodes.Contains(it.AcceptTypeCode)) //受理类型
  1370. .GroupBy((it, o) => new
  1371. {
  1372. it.AcceptTypeCode,
  1373. it.AcceptType,
  1374. it.HotspotId,
  1375. it.HotspotName,
  1376. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1377. o.AreaName,
  1378. })
  1379. .Having((it, o) => SqlFunc.AggregateCount(it.HotspotName) >= 5)
  1380. .Select((it, o) => new HighMatterWarningDto()
  1381. {
  1382. AcceptTypeCode = it.AcceptTypeCode,
  1383. AcceptType = it.AcceptType,
  1384. AreaName = o.AreaName,
  1385. HotspotName = it.HotspotName,
  1386. HotspotId = it.HotspotId,
  1387. SumCount = SqlFunc.AggregateCount(it.HotspotName),
  1388. Id = SqlFunc.AggregateMin(it.Id),
  1389. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  1390. })
  1391. .MergeTable()
  1392. .LeftJoin<Order>((x, d) => x.Id == d.Id)
  1393. .Select((x, d) => new HighMatterWarningDto()
  1394. {
  1395. AreaName = x.AreaName,
  1396. HotspotName = x.HotspotName,
  1397. HotspotId = x.HotspotId,
  1398. Title = d.Title,
  1399. SumCount = x.SumCount,
  1400. Id = d.Id,
  1401. AcceptTypeCode = x.AcceptTypeCode,
  1402. AcceptType = x.AcceptType,
  1403. AreaCode = x.AreaCode
  1404. })
  1405. .MergeTable()
  1406. .OrderByDescending(d => d.SumCount).ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  1407. return new PagedDto<HighMatterWarningDto>(total, _mapper.Map<IReadOnlyList<HighMatterWarningDto>>(items));
  1408. }
  1409. /// <summary>
  1410. /// 高频事项预警明细
  1411. /// </summary>
  1412. /// <param name="dto"></param>
  1413. /// <returns></returns>
  1414. [HttpGet("highmatter-warning-detail")]
  1415. public async Task<PagedDto<OrderDto>> HighMatterWarningDetail([FromQuery] HighMatterWarningDetailRequest dto)
  1416. {
  1417. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  1418. var (total, items) = await _orderRepository.Queryable()
  1419. .Includes(x => x.OrderScreens)
  1420. .Where(d => d.AcceptTypeCode == dto.AcceptTypeCode) //受理类型
  1421. .Where(d => d.HotspotId == dto.HotspotId) //热点类型
  1422. .Where(d => d.CreationTime >= dto.StartDate) //受理时间开始
  1423. .Where(d => d.CreationTime <= dto.EndDate) //受理时间结束
  1424. .Where(d => d.AreaCode == dto.AreaCode) //区域
  1425. .OrderByDescending(d => d.CreationTime)
  1426. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1427. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  1428. }
  1429. /// <summary>
  1430. /// 回退错件
  1431. /// </summary>
  1432. /// <param name="dto"></param>
  1433. /// <returns></returns>
  1434. [HttpGet("reTransact")]
  1435. public async Task<PagedDto<OrderReTransactVo>> OrderReTransact([FromQuery] QueryOrderReTransactRequest dto)
  1436. {
  1437. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  1438. throw UserFriendlyException.SameMessage("请选择时间!");
  1439. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1440. var (total, items) = await _orderSpecialDetailRepository.Queryable()
  1441. .Includes(x=>x.OrderSpecial)
  1442. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.OrgName.Contains(dto.OrgName!))
  1443. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  1444. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  1445. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime)
  1446. .GroupBy(x => new { Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"), x.OrgId, x.OrgName })
  1447. .Select(x => new OrderReTransactVo
  1448. {
  1449. Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"),
  1450. OrgId = x.OrgId,
  1451. OrgName = x.OrgName,
  1452. Num = SqlFunc.AggregateCount(1)
  1453. }).MergeTable()
  1454. .OrderByIF(dto.SortRule == 0, x => x.Num, OrderByType.Asc)
  1455. .OrderByIF(dto.SortRule == 1, x => x.Num, OrderByType.Desc)
  1456. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1457. return new PagedDto<OrderReTransactVo>(total, _mapper.Map<IReadOnlyList<OrderReTransactVo>>(items));
  1458. }
  1459. /// <summary>
  1460. /// 回退错件明细
  1461. /// </summary>
  1462. /// <param name="dto"></param>
  1463. /// <returns></returns>
  1464. [HttpGet("reTransact_detail")]
  1465. public async Task<PagedDto<OrderSpecialDetailDto>> OrderReTransactDetail([FromQuery] QueryOrderReTransactDetailRequest dto)
  1466. {
  1467. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  1468. throw UserFriendlyException.SameMessage("请选择时间!");
  1469. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1470. var (total, items) = await _orderSpecialDetailRepository.Queryable()
  1471. .Includes(x => x.OrderSpecial,s=>s.Order)
  1472. .WhereIF(!string.IsNullOrEmpty(dto.OrgName),x=>x.OrgName.Contains(dto.OrgName!))
  1473. .WhereIF(!string.IsNullOrEmpty(dto.ErrorName), x => x.ErrorName.Contains(dto.ErrorName!))
  1474. .WhereIF(!string.IsNullOrEmpty(dto.No), x => x.OrderSpecial!.Order!.No!.Contains(dto.No!))
  1475. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  1476. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  1477. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime)
  1478. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1479. return new PagedDto<OrderSpecialDetailDto>(total, _mapper.Map<IReadOnlyList<OrderSpecialDetailDto>>(items));
  1480. }
  1481. /// <summary>
  1482. /// 获取基本信息
  1483. /// </summary>
  1484. /// <param name="id"></param>
  1485. /// <returns></returns>
  1486. [HttpGet("reTransact_base")]
  1487. public async Task<object> ReTransactBaseData()
  1488. {
  1489. var rsp = new
  1490. {
  1491. ReTransactErrorType = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.ReTransactErrorType),
  1492. };
  1493. return rsp;
  1494. }
  1495. }
  1496. }