OrderApplication.cs 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
  1. using DotNetCore.CAP;
  2. using Hotline.Application.Quality;
  3. using Hotline.Caching.Interfaces;
  4. using Hotline.File;
  5. using Hotline.FlowEngine.Workflows;
  6. using Hotline.Orders;
  7. using Hotline.Repository.SqlSugar.Extensions;
  8. using Hotline.Repository.SqlSugar.Ts;
  9. using Hotline.Settings.TimeLimits;
  10. using Hotline.Share.Dtos;
  11. using Hotline.Share.Dtos.DataSharing.PusherHotlineDto;
  12. using Hotline.Share.Dtos.File;
  13. using Hotline.Share.Dtos.FlowEngine;
  14. using Hotline.Share.Dtos.FlowEngine.Workflow;
  15. using Hotline.Share.Dtos.Order;
  16. using Hotline.Share.Dtos.Settings;
  17. using Hotline.Share.Enums.Order;
  18. using Hotline.Share.Enums.Quality;
  19. using Hotline.Share.Enums.Settings;
  20. using Hotline.Share.Requests;
  21. using Hotline.Tools;
  22. using MapsterMapper;
  23. using Microsoft.AspNetCore.Mvc.Formatters;
  24. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  25. using Novacode;
  26. using SqlSugar;
  27. using System.Data;
  28. using System.Dynamic;
  29. using Hotline.Settings;
  30. using XF.Domain.Authentications;
  31. using XF.Domain.Constants;
  32. using XF.Domain.Dependency;
  33. using XF.Domain.Exceptions;
  34. using XF.Domain.Repository;
  35. using Hotline.Repository.SqlSugar.System;
  36. using Microsoft.AspNetCore.Mvc;
  37. using Hotline.Share.Dtos.Bi;
  38. using System.Net;
  39. using PanGu;
  40. using Hotline.Users;
  41. using PanGu.Match;
  42. using Hotline.Settings.Hotspots;
  43. using Hotline.Share.Enums.FlowEngine;
  44. using Hotline.Authentications;
  45. using Hotline.Repository.SqlSugar;
  46. using MediatR;
  47. using Hotline.Share.Mq;
  48. using JiebaNet.Segmenter;
  49. using Microsoft.AspNetCore.Http;
  50. using WordInfo = PanGu.WordInfo;
  51. using Hotline.Schedulings;
  52. using NPOI.SS.Formula.Functions;
  53. using XF.Domain.Entities;
  54. namespace Hotline.Application.Orders;
  55. public class OrderApplication : IOrderApplication, IScopeDependency
  56. {
  57. private readonly IOrderDomainService _orderDomainService;
  58. private readonly IWorkflowDomainService _workflowDomainService;
  59. private readonly IOrderRepository _orderRepository;
  60. private readonly ITimeLimitDomainService _timeLimitDomainService;
  61. private readonly IMapper _mapper;
  62. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  63. private readonly IRepository<OrderWord> _orderWrodRepository;
  64. private readonly IRepositoryTextSearch<OrderTs> _repositoryts;
  65. private readonly IFileRepository _fileRepository;
  66. private readonly ISessionContext _sessionContext;
  67. private readonly IRepository<OrderVisit> _orderVisitRepository;
  68. private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
  69. private readonly IQualityApplication _qualityApplication;
  70. private readonly ICapPublisher _capPublisher;
  71. private readonly IRepository<SystemOrganize> _systemOrganizeRepository;
  72. private readonly IRepository<WorkflowCountersign> _workflowCountersignRepository;
  73. private readonly IRepository<OrderSpecialDetail> _orderSpecialDetailRepository;
  74. private readonly IRepository<SystemArea> _systemAreaRepository;
  75. private readonly IRepository<Hotspot> _hotspotRepository;
  76. private readonly IRepository<WorkflowStep> _workflowStepRepository;
  77. private readonly IRepository<WorkflowTrace> _workflowTraceRepository;
  78. private readonly IRepository<SystemDicData> _systemDicDataRepository;
  79. private readonly IRepository<OrderPublish> _orderPublishRepository;
  80. private readonly IRepository<OrderScreen> _orderScreenRepository;
  81. private readonly IRepository<OrderSendBackAudit> _orderSendBackAuditRepository;
  82. public OrderApplication(
  83. IOrderDomainService orderDomainService,
  84. IOrderRepository orderRepository,
  85. IWorkflowDomainService workflowDomainService,
  86. ITimeLimitDomainService timeLimitDomainService,
  87. ISystemSettingCacheManager systemSettingCacheManager,
  88. IMapper mapper,
  89. IRepository<OrderWord> orderWrodRepository,
  90. IRepositoryTextSearch<OrderTs> repositoryts,
  91. IFileRepository fileRepository,
  92. ISessionContext sessionContext,
  93. IRepository<OrderVisit> orderVisitRepository,
  94. IRepository<OrderVisitDetail> orderVisitDetailRepository,
  95. IQualityApplication qualityApplication,
  96. ICapPublisher capPublisher,
  97. IRepository<SystemOrganize> systemOrganizeRepository,
  98. IRepository<WorkflowCountersign> workflowCountersignRepository,
  99. IRepository<OrderSpecialDetail> orderSpecialDetailRepository,
  100. IRepository<SystemArea> systemAreaRepository,
  101. IRepository<Hotspot> hotspotRepository,
  102. IRepository<WorkflowStep> workflowStepRepository,
  103. IRepository<SystemDicData> systemDicDataRepository,
  104. IRepository<WorkflowTrace> workflowTraceRepository,
  105. IRepository<OrderPublish> orderPublishRepository,
  106. IRepository<OrderScreen> orderScreenRepository,
  107. IRepository<OrderSendBackAudit> orderSendBackAuditRepository)
  108. {
  109. _orderDomainService = orderDomainService;
  110. _workflowDomainService = workflowDomainService;
  111. _orderRepository = orderRepository;
  112. _timeLimitDomainService = timeLimitDomainService;
  113. _mapper = mapper;
  114. _systemSettingCacheManager = systemSettingCacheManager;
  115. _orderWrodRepository = orderWrodRepository;
  116. _repositoryts = repositoryts;
  117. _fileRepository = fileRepository;
  118. _sessionContext = sessionContext;
  119. _orderVisitRepository = orderVisitRepository;
  120. _orderVisitDetailRepository = orderVisitDetailRepository;
  121. _qualityApplication = qualityApplication;
  122. _capPublisher = capPublisher;
  123. _systemOrganizeRepository = systemOrganizeRepository;
  124. _workflowCountersignRepository = workflowCountersignRepository;
  125. _orderSpecialDetailRepository = orderSpecialDetailRepository;
  126. _systemAreaRepository = systemAreaRepository;
  127. _hotspotRepository = hotspotRepository;
  128. _workflowStepRepository = workflowStepRepository;
  129. _systemDicDataRepository = systemDicDataRepository;
  130. _workflowTraceRepository = workflowTraceRepository;
  131. _orderScreenRepository = orderScreenRepository;
  132. _orderPublishRepository = orderPublishRepository;
  133. _orderSendBackAuditRepository = orderSendBackAuditRepository;
  134. }
  135. /// <summary>
  136. /// 更新工单办理期满时间(延期调用,其他不调用)
  137. /// 1.更新工单 2.更新流程 3.推送省平台
  138. /// </summary>
  139. /// <returns></returns>
  140. public async Task DelayOrderExpiredTimeAsync(string orderId, int timeCount, ETimeType timeType, bool IsProDelay, CancellationToken cancellationToken)
  141. {
  142. var order = await _orderDomainService.GetOrderAsync(orderId, cancellationToken: cancellationToken);
  143. var expiredTimeConfig =
  144. _timeLimitDomainService.CalcEndTime(DateTime.Now, new TimeConfig(timeCount, timeType), order.AcceptTypeCode);
  145. order.TimeLimit = expiredTimeConfig.TimeText;
  146. order.TimeLimitCount = expiredTimeConfig.Count;
  147. order.TimeLimitUnit = expiredTimeConfig.TimeType;
  148. order.ExpiredTime = expiredTimeConfig.ExpiredTime;
  149. order.NearlyExpiredTime = expiredTimeConfig.NearlyExpiredTime;
  150. //TODO发送短信即将超期
  151. //_capPublisher.PublishDelay(expiredTimeConfig.NearlyExpiredTime - DateTime.Now, EventNames.HotlineOrderNearlyExpiredTimeSms, new PublishNearlyExpiredTimeSmsDto() { OrderId = order.Id });
  152. if (IsProDelay)
  153. {
  154. order.ExpiredTimeProvince = expiredTimeConfig.ExpiredTime;
  155. }
  156. //if (string.IsNullOrEmpty(order.WorkflowId))
  157. // throw new UserFriendlyException("该工单流程id异常");
  158. //var workflow = await _workflowDomainService.GetWorkflowAsync(order.WorkflowId, cancellationToken: cancellationToken);
  159. //await _workflowDomainService.UpdateExpiredTimeAsync(workflow, expiredTimeConfig.ExpiredTime,
  160. // expiredTimeConfig.TimeText, expiredTimeConfig.Count, expiredTimeConfig.TimeType, expiredTimeConfig.NearlyExpiredTime, cancellationToken);
  161. if (string.IsNullOrEmpty(order.WorkflowId))
  162. throw new UserFriendlyException("该工单流程id异常");
  163. await _workflowDomainService.UpdateUnhandleExpiredTimeAsync(order.WorkflowId, expiredTimeConfig.ExpiredTime, cancellationToken);
  164. await _orderRepository.UpdateAsync(order, cancellationToken);
  165. }
  166. /// <summary>
  167. /// 新增工单办理流程记录
  168. /// </summary>
  169. public async Task AddOrderTracesAsync(string orderId, ICollection<WorkflowTraceDto> traces, CancellationToken cancellationToken)
  170. {
  171. var order = await _orderRepository.GetAsync(orderId, cancellationToken);
  172. if (order is null)
  173. throw new UserFriendlyException("工单不存在");
  174. if (string.IsNullOrEmpty(order.WorkflowId))
  175. throw new UserFriendlyException("工单未开启流程");
  176. await _workflowDomainService.AddTracesAsync(order.WorkflowId, _mapper.Map<List<WorkflowTrace>>(traces),
  177. cancellationToken);
  178. }
  179. /// <summary>
  180. /// 撤销工单
  181. /// </summary>
  182. public async Task CancelOrderAsync(string orderId, string opinion, CancellationToken cancellationToken)
  183. {
  184. var order = await _orderRepository.GetAsync(orderId, cancellationToken);
  185. if (order is null)
  186. throw new UserFriendlyException("工单不存在");
  187. if (!string.IsNullOrEmpty(order.WorkflowId))
  188. {
  189. //结束流程
  190. await _workflowDomainService.TerminateAsync(new TerminateDto
  191. {
  192. WorkflowId = order.WorkflowId,
  193. Opinion = opinion
  194. }, cancellationToken);
  195. }
  196. //归档工单
  197. var now = DateTime.Now;
  198. var handleDuration = order.StartTime.HasValue
  199. ? _timeLimitDomainService.CalcWorkTime(order.StartTime.Value,
  200. now, order.ProcessType is EProcessType.Zhiban)
  201. : 0;
  202. var fileDuration = order.CenterToOrgTime.HasValue
  203. ? _timeLimitDomainService.CalcWorkTime(order.CenterToOrgTime.Value,
  204. now, order.ProcessType is EProcessType.Zhiban)
  205. : 0;
  206. var allDuration = order.StartTime.HasValue
  207. ? _timeLimitDomainService.CalcWorkTime(order.StartTime.Value, now,
  208. order.ProcessType is EProcessType.Zhiban)
  209. : 0;
  210. var creationTimeHandleDurationWorkday = order.ActualHandleTime.HasValue
  211. ? _timeLimitDomainService.CalcWorkTime(order.CreationTime, now,
  212. order.ProcessType is EProcessType.Zhiban)
  213. : 0;
  214. var centerToOrgHandleDurationWorkday = order.ActualHandleTime.HasValue && order.CenterToOrgTime.HasValue
  215. ? _timeLimitDomainService.CalcWorkTime(order.CenterToOrgTime.Value, now,
  216. order.ProcessType is EProcessType.Zhiban)
  217. : 0;
  218. order.File(now, handleDuration, fileDuration, allDuration, creationTimeHandleDurationWorkday, centerToOrgHandleDurationWorkday);
  219. await _orderRepository.UpdateAsync(order, cancellationToken);
  220. }
  221. /// <summary>
  222. /// 即将超期列表
  223. /// </summary>
  224. /// <param name="dto"></param>
  225. /// <param name="cancellationToken"></param>
  226. /// <returns></returns>
  227. public ISugarQueryable<Order> GetAboutToExpireAsync(AboutToExpireListDto dto)
  228. {
  229. //var setting = _systemSettingCacheManager.GetSetting(SettingConstants.OrderAboutToExpire);
  230. //var value = setting?.SettingValue[0];
  231. //value = string.IsNullOrEmpty(value) ? "0" : value;
  232. //DateTime stTime = DateTime.Now.AddDays(int.Parse(value));
  233. //stTime = _timeLimitDomainService.WorkDay(stTime);
  234. //DateTime stTime2 = _timeLimitDomainService.WorkDay(DateTime.Now);
  235. DateTime? dateTime = DateTime.Now;
  236. var IsCenter = _sessionContext.OrgIsCenter;
  237. return _orderRepository.Queryable(canView: !IsCenter).Includes(d => d.OrderDelays)
  238. .WhereIF(dto.IsProvince.HasValue, d => d.IsProvince == dto.IsProvince)
  239. .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.No.Contains(dto.No!))
  240. .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Title.Contains(dto.Title!))
  241. .WhereIF(dto.Delay.HasValue && dto.Delay == 1, d => d.OrderDelays.Any() == true)
  242. .WhereIF(dto.Delay.HasValue && dto.Delay == 2, d => d.OrderDelays.Any() == false)
  243. //&& stTime >= d.ExpiredTime.Value && stTime2 <= d.ExpiredTime.Value
  244. //.Where(d => d.ExpiredTime != null &&
  245. // d.Status != EOrderStatus.Filed && d.Status != EOrderStatus.Published && d.Status != EOrderStatus.Visited && stTime >= d.ExpiredTime.Value && stTime2 <= d.ExpiredTime.Value)
  246. .Where(d => d.Status < EOrderStatus.Filed && (dateTime > d.NearlyExpiredTimeOne || dateTime > d.NearlyExpiredTime) && dateTime < d.ExpiredTime)
  247. .OrderByDescending(d => d.CreationTime);
  248. }
  249. // /// <summary>
  250. // /// 即将超期节点列表
  251. // /// </summary>
  252. // /// <param name="dto"></param>
  253. // /// <param name="cancellationToken"></param>
  254. // /// <returns></returns>
  255. //public async Task<PagedDto<WorkflowOrderDto>> GetAboutToExpireNodeAsync(AboutToExpireListDto dto, CancellationToken cancellationToken)
  256. //{
  257. // var setting = _systemSettingCacheManager.GetSetting(SettingConstants.OrderAboutToExpire);
  258. // var value = setting?.SettingValue[0];
  259. // value = string.IsNullOrEmpty(value) ? "0" : value;
  260. // DateTime stTime = DateTime.Now.AddDays(int.Parse(value));
  261. // stTime = _timeLimitDomainService.WorkDay(DateTime.Now);
  262. // DateTime stTime2 = _timeLimitDomainService.WorkDay(DateTime.Now);
  263. // RefAsync<int> total = 0;
  264. // var items = await Db.Queryable<Workflow>()
  265. // .LeftJoin<Order>((x, o) => x.ExternalId == o.Id)
  266. // .Where(x => x.ModuleCode == "OrderHandle")
  267. // .WhereIF(dto.IsProvince.HasValue, (x, o) => o.IsProvince == dto.IsProvince)
  268. // .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => o.Title.Contains(dto.Keyword!) || o.No.Contains(dto.Keyword!))
  269. // .Where((x, o) => (int)x.Status < 20 && stTime >= x.ExpiredTime && stTime2 <= x.ExpiredTime)
  270. // .Select((x, o) => new WorkflowOrder { Order = o }, true)
  271. // .OrderByDescending(x => x.CreationTime)
  272. // .ToPageListAsync(dto.PageIndex, dto.PageSize, total, cancellationToken);
  273. // return new PagedDto<WorkflowOrderDto>(total, _mapper.Map<IReadOnlyList<WorkflowOrderDto>>(items));
  274. //}
  275. /// <summary>
  276. /// 已超期列表
  277. /// </summary>
  278. /// <param name="dto"></param>
  279. /// <param name="cancellationToken"></param>
  280. /// <returns></returns>
  281. public ISugarQueryable<Order> GetToExpireAsync(AboutToExpireListDto dto)
  282. {
  283. DateTime stTime = _timeLimitDomainService.WorkDay(DateTime.Now);
  284. var IsCenter = _sessionContext.OrgIsCenter;
  285. return _orderRepository.Queryable(canView: false).Includes(d => d.OrderDelays)
  286. .Where(d => SqlFunc.Subqueryable<WorkflowStep>()
  287. .Where(step => step.ExternalId == d.Id &&
  288. ((step.FlowAssignType == EFlowAssignType.User && !string.IsNullOrEmpty(step.HandlerId) && step.HandlerId == _sessionContext.RequiredUserId) ||
  289. (step.FlowAssignType == EFlowAssignType.Org && !string.IsNullOrEmpty(step.HandlerOrgId) && step.HandlerOrgId == _sessionContext.RequiredOrgId) ||
  290. (step.FlowAssignType == EFlowAssignType.Role && !string.IsNullOrEmpty(step.RoleId) && _sessionContext.Roles.Contains(step.RoleId))))
  291. .Any())
  292. .WhereIF(dto.IsProvince.HasValue, d => d.IsProvince == dto.IsProvince)
  293. //.WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Title.Contains(dto.Keyword!) || d.No.Contains(dto.Keyword!))
  294. .WhereIF(!string.IsNullOrEmpty(dto.No), x => x.No.Contains(dto.No))
  295. .WhereIF(!string.IsNullOrEmpty(dto.Title), x => x.Title.Contains(dto.Title!))
  296. .WhereIF(dto.Delay.HasValue && dto.Delay == 1, d => d.OrderDelays.Any() == true)
  297. .WhereIF(dto.Delay.HasValue && dto.Delay == 2, d => d.OrderDelays.Any() == false)
  298. .Where(d => d.ExpiredTime != null &&
  299. (((d.Status == EOrderStatus.Filed || d.Status == EOrderStatus.Published || d.Status == EOrderStatus.Visited) && d.FiledTime >= d.ExpiredTime) ||
  300. ((d.Status != EOrderStatus.Filed && d.Status != EOrderStatus.Published && d.Status != EOrderStatus.Visited) && stTime >= d.ExpiredTime.Value)))
  301. .OrderByDescending(x => x.CreationTime);
  302. }
  303. // /// <summary>
  304. // /// 已超期节点列表
  305. // /// </summary>
  306. // /// <param name="dto"></param>
  307. // /// <param name="cancellationToken"></param>
  308. // /// <returns></returns>
  309. // public async Task<PagedDto<WorkflowOrderDto>> GetToExpireNodeAsync(AboutToExpireListDto dto, CancellationToken cancellationToken)
  310. // {
  311. // DateTime stTime = _timeLimitDomainService.WorkDay(DateTime.Now);
  312. //RefAsync<int> total = 0;
  313. //var items= await Db.Queryable<Workflow>()
  314. // .LeftJoin<Order>((x,o)=>x.ExternalId == o.Id)
  315. // .Where(x => x.ModuleCode == "OrderHandle")
  316. // .WhereIF(dto.IsProvince.HasValue, (x, o) => o.IsProvince == dto.IsProvince)
  317. // .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => o.Title.Contains(dto.Keyword!) || o.No.Contains(dto.Keyword!))
  318. // .Where((x,o) => (((int)x.Status >= 20 && x.EndTime >= x.ExpiredTime) || ((int)x.Status < 20 && stTime >= x.ExpiredTime)))
  319. // .Select((x, o) => new WorkflowOrder { Order = o }, true)
  320. // .OrderByDescending(x => x.CreationTime)
  321. // .ToPageListAsync(dto.PageIndex, dto.PageSize, total, cancellationToken);
  322. // return new PagedDto<WorkflowOrderDto>(total, _mapper.Map<IReadOnlyList<WorkflowOrderDto>>(items));
  323. // }
  324. /// <summary>
  325. /// 工单关键字分词
  326. /// </summary>
  327. /// <param name="inputStr"></param>
  328. /// <returns></returns>
  329. public async Task OrderParticiple(string inputStr, string orderId, DateTime time, CancellationToken cancellationToken)
  330. {
  331. var seg = new Segment();
  332. ICollection<WordInfo> splitWords = seg.DoSegment(inputStr);
  333. var words = new List<string>();
  334. for (int i = 0;i < splitWords.Count;i++)
  335. {
  336. var word = splitWords.ElementAt(i);
  337. if (word is { WordType: WordType.SimplifiedChinese, Word.Length: > 1 })
  338. words.Add(splitWords.ElementAt(i).Word);
  339. }
  340. if (words.Any())
  341. {
  342. var vector = await _repositoryts.SearchAsync(orderId, cancellationToken);
  343. if (vector != null && vector.Any()) await _repositoryts.UpdateVectorAsync(orderId, words, cancellationToken);
  344. else await _repositoryts.AddVectorAsync(orderId, time, words, cancellationToken);
  345. }
  346. // 结巴分词
  347. //var segmenter = new JiebaSegmenter();
  348. //var segments1 = segmenter.Cut(inputStr, cutAll: true);
  349. //var b = segments1;
  350. //var words = await _orderWrodRepository.Queryable().Where(x => x.IsEnable == 1 && x.Classify.Contains("普通标签")).Select(x => x.Tag).ToListAsync(cancellationToken);
  351. //var res = new List<string>();
  352. //if (words.Any()) res = ParticipleTool.SegMMDouble(inputStr, ref words);
  353. //var participles = await _orderWrodRepository.Queryable().In(x => x.Tag, res).ToListAsync(cancellationToken);
  354. //if (participles.Any())
  355. //{
  356. // //关键词
  357. // var tags = participles.Select(x => x.Tag).ToList();
  358. // var tagsStr = string.Join(",", tags);
  359. // await _orderRepository.Updateable().SetColumns(x => x.TagNames == tagsStr).Where(x => x.Id == orderId).ExecuteCommandAsync(cancellationToken);
  360. // List<string> synonyms = participles.Select(x => x.Synonym).ToList();
  361. // if (synonyms.Any())
  362. // {
  363. // var synonymsStr = string.Join(",", synonyms);
  364. // synonyms = synonymsStr.Split(",").Distinct().ToList();
  365. // tags.AddRange(synonyms);
  366. // }
  367. // var vector = await _orderRepository.Queryable().Where(x => x.Id == orderId).ToListAsync(cancellationToken);
  368. // if (vector.Any()) await _repositoryts.UpdateVectorAsync(orderId, tags, cancellationToken);
  369. // else await _repositoryts.AddVectorAsync(orderId, DateTime.Now, tags, cancellationToken);
  370. //}
  371. }
  372. public async Task OrderSensitiveParticiple(string inputStr, string orderId, CancellationToken cancellationToken)
  373. {
  374. var words = await _orderWrodRepository.Queryable().Where(x => x.IsEnable == 1 && x.Classify.Contains("敏感标签")).Select(x => x.Tag).ToListAsync(cancellationToken);
  375. var res = new List<string>();
  376. if (words.Any()) res = ParticipleTool.SegMMDouble(inputStr, ref words);
  377. if (res.Any())
  378. {
  379. var intersect = words.Intersect(res).ToList();
  380. await _orderRepository.Updateable().SetColumns(o => new Order() { Sensitive = intersect }).Where(o => o.Id == orderId).ExecuteCommandAsync(cancellationToken);
  381. }
  382. }
  383. /// <summary>
  384. /// 接收外部平台工单
  385. /// </summary>
  386. public Task<AddOrderResponse> ReceiveOrderFromExternalAsync(AddOrderDto dto, ISessionContext current, CancellationToken cancellationToken)
  387. {
  388. switch (dto.Source)
  389. {
  390. case ESource.ProvinceStraight:
  391. return ReceiveOrderFromProvinceAsync(dto, dto.Files, current, cancellationToken);
  392. case ESource.Police110:
  393. case ESource.CityDataExchangeLz:
  394. case ESource.CityDataExchangeYB:
  395. case ESource.CityDataExchangeZG:
  396. case ESource.CityDataExchangeNJ:
  397. case ESource.WebPortal:
  398. case ESource.ConvergenceMedia:
  399. case ESource.IYIBIN:
  400. case ESource.ZHYB:
  401. case ESource.ZZPT:
  402. case ESource.WLLZ:
  403. return ReceiveOrderFromOtherPlatformAsync(dto, dto.Files, current, cancellationToken);
  404. case ESource.Hotline:
  405. case ESource.HotlineImport:
  406. default:
  407. throw new ArgumentOutOfRangeException();
  408. }
  409. }
  410. /// <summary>
  411. /// 接收外部平台修改工单附件
  412. /// </summary>
  413. public async Task UpdateOrderFilesAnonymousAsync(UpdateOrderFilesDto dto, CancellationToken cancellationToken)
  414. {
  415. if (string.IsNullOrEmpty(dto.Id) && string.IsNullOrEmpty(dto.OrderNo))
  416. throw new UserFriendlyException("工单外部编号不能为空");
  417. var order = await _orderRepository.Queryable()
  418. .FirstAsync(d => d.Id == dto.Id || d.No == dto.OrderNo, cancellationToken);
  419. if (order != null && dto.Files != null && dto.Files.Any())
  420. {
  421. order.FileJson = await _fileRepository.AddFileAsync(dto.Files, order.Id, "", cancellationToken);
  422. await _orderRepository.UpdateAsync(order, cancellationToken);
  423. }
  424. }
  425. /// <summary>
  426. /// 发布量统计(按账号)
  427. /// </summary>
  428. /// <param name="dto"></param>
  429. /// <returns></returns>
  430. /// <exception cref="UserFriendlyException"></exception>
  431. public async Task<(int, IList<PublishedOrderStatisticsDto>)> QueryPublishedOrderAsync(QueryOrderPublishStatisticsDto dto, bool isFull)
  432. {
  433. var query = _orderRepository.Queryable()
  434. .Includes(order =>order.OrderPublish)
  435. .LeftJoin<User>((order, user) => order.WaitForPublisherId == user.Id)
  436. .Where((order, user) => order.FiledTime >= dto.StartTime && order.FiledTime <= dto.EndTime && !string.IsNullOrEmpty(order.WaitForPublisherId))
  437. .WhereIF(dto.ProcessType != null, (order, user) => order.ProcessType == dto.ProcessType)
  438. .GroupBy((order, user) => new { order.WaitForPublisherId, user.Name })
  439. .Select((order, user) => new PublishedOrderStatisticsDto
  440. {
  441. Id = order.WaitForPublisherId,
  442. Name = user.Name,
  443. TotalCount = SqlFunc.AggregateCount(order.Id),
  444. WaitCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderPublish == null, 1, 0)),
  445. PublicCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderPublish.PublishState == true, 1, 0)),
  446. PrivateCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderPublish.PublishState == false, 1, 0))
  447. });
  448. var sql = query.ToSql();
  449. var total = 0;
  450. var items = new List<PublishedOrderStatisticsDto>();
  451. if (isFull)
  452. {
  453. items = await query.ToListAsync();
  454. }
  455. else
  456. {
  457. (total, items) = await query.ToPagedListAsync(dto.PageIndex, dto.PageSize);
  458. }
  459. return (total, items);
  460. }
  461. /// <summary>
  462. /// 发布量统计(部门)
  463. /// </summary>
  464. /// <param name="dto"></param>
  465. /// <returns></returns>
  466. /// <exception cref="UserFriendlyException"></exception>
  467. public async Task<(int, IList<PublishedOrderStatisticsDto>)> QueryPublishedOrderDepartmentAsync(QueryOrderPublishStatisticsAllDto dto, bool isFull)
  468. {
  469. var total = 0;
  470. var items = new List<PublishedOrderStatisticsDto>();
  471. var query = _orderRepository.Queryable()
  472. .Includes(order => order.OrderPublish)
  473. .Where(order => order.FiledTime >= dto.StartTime && order.FiledTime <= dto.EndTime && order.ActualHandleOrgName != null)
  474. .GroupBy(order => new { Name = order.ActualHandleOrgName, PublishTime = order.CreationTime.ToString("YYYY-MM-DD") })
  475. .Select(order => new PublishedOrderStatisticsDto
  476. {
  477. Name = order.ActualHandleOrgName,
  478. PublishTime = order.CreationTime.ToString("YYYY-MM-DD"),
  479. TotalCount = SqlFunc.AggregateCount(order.Id),
  480. // WaitCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderPublish == null, 1, 0)),
  481. PublicCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderPublish.PublishState == true, 1, 0)),
  482. PrivateCount = SqlFunc.AggregateSum(SqlFunc.IIF(order.OrderPublish.PublishState == false, 1, 0))
  483. });
  484. if (isFull)
  485. {
  486. items = await query.ToListAsync();
  487. }
  488. else
  489. {
  490. (total, items) = await query.ToPagedListAsync(dto.PageIndex, dto.PageSize);
  491. }
  492. items.ForEach(m => m.WaitCount = m.TotalCount - m.PublicCount - m.PrivateCount);
  493. return (total, items);
  494. }
  495. /// <summary>
  496. /// 回访来源统计
  497. /// </summary>
  498. /// <param name="dto"></param>
  499. /// <returns></returns>
  500. /// <exception cref="NotImplementedException"></exception>
  501. public async Task<IList<OrderVisitSourceChannelDto>> QueryOrderVisitSourceChannelAsync(QueryOrderVisitSourceChannelDto dto)
  502. {
  503. var result = await _orderVisitRepository.Queryable()
  504. .LeftJoin<Order>((visit, order) => order.Id == visit.OrderId)
  505. .Where((visit, order) => visit.VisitTime >= dto.StartTime && visit.VisitTime <= dto.EndTime)
  506. .GroupBy((visit, order) => new { order.SourceChannel })
  507. .Select((visit, order) => new OrderVisitSourceChannelDto
  508. {
  509. Count = SqlFunc.AggregateCount(visit.OrderId),
  510. SourceChannel = order.SourceChannel
  511. })
  512. .ToListAsync();
  513. return result;
  514. }
  515. /// <summary>
  516. /// 工单回访
  517. /// </summary>
  518. /// <param name="dto"></param>
  519. /// <param name="cancellationToken"></param>
  520. /// <returns></returns>
  521. public async Task OrderVisitWeb(OrderVisitWebDto dto, CancellationToken cancellationToken)
  522. {
  523. var visit = await _orderVisitRepository.Queryable()
  524. .Includes(x => x.Order)
  525. .Includes(x => x.OrderVisitDetails)
  526. .FirstAsync(x => x.Id == dto.Id);
  527. if (visit != null)
  528. {
  529. var first = dto.OrderVisitDetailDto.FirstOrDefault(x => x.VisitTarget == EVisitTarget.Org);
  530. if (first != null)
  531. {
  532. visit.NowEvaluate = first.OrgProcessingResults;
  533. visit.Order.Visited(first.OrgProcessingResults.Key, first.OrgProcessingResults.Value);
  534. }
  535. visit.VisitState = EVisitState.Visited;
  536. visit.VisitTime = dto.VisitTime;
  537. visit.VisitType = dto.VisitType;
  538. for (int i = 0;i < visit.OrderVisitDetails.Count;i++)
  539. {
  540. var detail = visit.OrderVisitDetails[i];
  541. var detaildto = dto.OrderVisitDetailDto.FirstOrDefault(x => x.Id == detail.Id);
  542. if (detaildto != null)
  543. {
  544. _mapper.Map(detaildto, visit.OrderVisitDetails[i]);
  545. }
  546. }
  547. await _orderVisitRepository.UpdateAsync(visit, cancellationToken);
  548. await _orderVisitDetailRepository.UpdateRangeAsync(visit.OrderVisitDetails, cancellationToken);
  549. await _orderRepository.UpdateAsync(visit.Order, cancellationToken);
  550. var orderDto = _mapper.Map<OrderDto>(visit.Order);
  551. if (first != null)
  552. {
  553. //推省上
  554. await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderVisited,
  555. new PublishVisitDto()
  556. {
  557. Order = orderDto,
  558. No = visit.No,
  559. VisitType = visit.VisitType,
  560. VisitName = visit.CreatorName,
  561. VisitTime = visit.VisitTime,
  562. VisitRemark = string.IsNullOrEmpty(first.VisitContent) ? first.OrgProcessingResults?.Value : first.VisitContent,
  563. AreaCode = visit.Order.AreaCode!,
  564. SubjectResultSatifyCode = first.OrgProcessingResults.Key,
  565. FirstSatisfactionCode = visit.Order.FirstVisitResultCode!,
  566. ClientGuid = ""
  567. }, cancellationToken: cancellationToken);
  568. }
  569. //写入质检
  570. await _qualityApplication.AddQualityAsync(EQualitySource.Visit, orderDto.Id, visit.Id,
  571. cancellationToken);
  572. }
  573. }
  574. public ISugarQueryable<Order> QueryOrders(QueryOrderDto dto)
  575. {
  576. var isCenter = _sessionContext.OrgIsCenter;
  577. var query = _orderRepository.Queryable();
  578. if (!isCenter)
  579. {
  580. //todo 可优化
  581. query.Where(d => SqlFunc.Subqueryable<WorkflowTrace>()
  582. .Where(step => step.ExternalId == d.Id &&
  583. !string.IsNullOrEmpty(step.HandlerOrgId) &&
  584. step.HandlerOrgId.StartsWith(_sessionContext.RequiredOrgId) &&
  585. step.TraceState != EWorkflowTraceState.StepRemoveByPrevious &&
  586. step.TraceState != EWorkflowTraceState.StepRemoveByRecall).Any());
  587. }
  588. return query
  589. .Includes(x => x.OrderScreens)
  590. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Title.StartsWith(dto.Keyword!)) //标题
  591. .WhereIF(!string.IsNullOrEmpty(dto.ProvinceNo), d => d.ProvinceNo == dto.ProvinceNo) //省本地编号
  592. .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.No == dto.No) //工单编码
  593. .WhereIF(!string.IsNullOrEmpty(dto.AcceptType), d => d.AcceptTypeCode == dto.AcceptType)//受理类型
  594. //.WhereIF(dto.AcceptTypes.Any(), d => dto.AcceptTypes.Contains(d.AcceptTypeCode)) //受理类型
  595. .WhereIF(!string.IsNullOrEmpty(dto.Channel), d => d.SourceChannelCode == dto.Channel)
  596. //.WhereIF(dto.Channels.Any(), d => dto.Channels.Contains(d.SourceChannelCode)) //来源渠道
  597. //.WhereIF(dto.HotspotIds.Any(), d => dto.HotspotIds.Contains(d.HotspotId)) //热点类型
  598. .WhereIF(!string.IsNullOrEmpty(dto.Hotspot), d => d.HotspotSpliceName != null && d.HotspotSpliceName.Contains(dto.Hotspot))
  599. .WhereIF(!string.IsNullOrEmpty(dto.TransferPhone), d => d.TransferPhone == dto.TransferPhone!) //转接号码
  600. //.WhereIF(dto.OrgCodes.Any(), d => d.Workflow.Assigns.Any(s => dto.OrgCodes.Contains(s.OrgCode)))
  601. //.WhereIF(dto.OrgCodes.Any(), d => dto.OrgCodes.Contains(d.ActualHandleOrgCode)) //接办部门
  602. .WhereIF(!string.IsNullOrEmpty(dto.OrgId), d => d.CurrentHandleOrgId == dto.OrgId)//接办部门
  603. .WhereIF(!string.IsNullOrEmpty(dto.NameOrNo), d => d.AcceptorName == dto.NameOrNo! || d.AcceptorStaffNo == dto.NameOrNo!) //受理人/坐席
  604. .WhereIF(dto.CreationTimeStart.HasValue, d => d.CreationTime >= dto.CreationTimeStart) //受理时间开始
  605. .WhereIF(dto.CreationTimeEnd.HasValue, d => d.CreationTime <= dto.CreationTimeEnd) //受理时间结束
  606. //.WhereIF(dto.EmergencyLevels.Any(), d => dto.EmergencyLevels.Contains(d.EmergencyLevel)) //紧急程度
  607. .WhereIF(!string.IsNullOrEmpty(dto.FromPhone), d => d.FromPhone == dto.FromPhone) //来电号码
  608. .WhereIF(!string.IsNullOrEmpty(dto.PhoneNo), d => d.Contact == dto.PhoneNo!) //联系电话
  609. .WhereIF(!string.IsNullOrEmpty(dto.PushTypeCode), d => d.PushTypeCode == dto.PushTypeCode) //推送分类
  610. .WhereIF(dto.ExpiredTimeStart.HasValue, d => d.ExpiredTime >= dto.ExpiredTimeStart) //超期时间开始
  611. .WhereIF(dto.ExpiredTimeEnd.HasValue, d => d.ExpiredTime <= dto.ExpiredTimeEnd) //超期时间结束
  612. //.WhereIF(dto.Statuses.Any(), d => dto.Statuses.Contains(d.Status)) //工单状态
  613. .WhereIF(dto.Status.HasValue, d => d.Status == dto.Status)//工单状态
  614. //.WhereIF(dto.Statuses.Any(d => d == EOrderStatus.SpecialToUnAccept), d => d.Status <= EOrderStatus.SpecialToUnAccept)
  615. .WhereIF(!string.IsNullOrEmpty(dto.ActualHandlerName), d => d.ActualHandlerName == dto.ActualHandlerName) //接办人
  616. .WhereIF(dto.IsScreen == true, d => d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //有甄别
  617. .WhereIF(dto.IsScreen == false, d => !d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //无甄别
  618. .WhereIF(!string.IsNullOrEmpty(dto.CurrentStepCode), d => d.ActualHandleStepCode == dto.CurrentStepCode) //当前办理节点
  619. .WhereIF(dto.ActualHandleTimeStart.HasValue, d => d.ActualHandleTime >= dto.ActualHandleTimeStart) //办结时间开始
  620. .WhereIF(dto.ActualHandleTimeEnd.HasValue, d => d.ActualHandleTime <= dto.ActualHandleTimeEnd) //办结时间结束
  621. .WhereIF(dto.IsOverTime == true, d => (d.ExpiredTime < DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime < d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //是 超期
  622. .WhereIF(dto.IsOverTime == false, d => (d.ExpiredTime > DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime > d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //否 超期
  623. .WhereIF(dto.IdentityType != null, d => d.IdentityType == dto.IdentityType) //来电主体
  624. .WhereIF(!string.IsNullOrEmpty(dto.FromName), d => d.FromName == dto.FromName) //来电人姓名
  625. //.WhereIF(dto.AreaCodes.Any(), d => dto.AreaCodes.Contains(d.AreaCode)) //区域
  626. .WhereIF(!string.IsNullOrEmpty(dto.AreaCode), d => d.AreaCode == dto.AreaCode)//区域
  627. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == true, d => d.Source == ESource.ProvinceStraight)
  628. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == false, d => d.Source != ESource.ProvinceStraight)
  629. .WhereIF(!string.IsNullOrEmpty(dto.SensitiveWord), d => SqlFunc.JsonArrayAny(d.Sensitive, dto.SensitiveWord))
  630. .WhereIF(dto.IsSensitiveWord.HasValue && dto.IsSensitiveWord == true, d => d.Sensitive != null && SqlFunc.JsonArrayLength(d.Sensitive) > 0)
  631. .WhereIF(dto.IsUrgent.HasValue, d => d.IsUrgent == dto.IsUrgent.Value)
  632. .WhereIF(!string.IsNullOrEmpty(dto.ProvinceChannel) && dto.ProvinceChannel == "1", d => d.Source == ESource.ProvinceStraight &&
  633. d.SourceChannelCode == "SZMHD" && d.IsProvince == false)//政民互动直派
  634. .WhereIF(!string.IsNullOrEmpty(dto.ProvinceChannel) && dto.ProvinceChannel == "2", d => d.Source == ESource.ProvinceStraight &&
  635. d.SourceChannelCode == "SZMHD" && d.IsProvince == true)//政民互动
  636. .WhereIF(!string.IsNullOrEmpty(dto.ProvinceChannel) && dto.ProvinceChannel == "3", d => d.Source == ESource.ProvinceStraight &&
  637. d.SourceChannelCode == "S12345" && d.IsProvince == true)//省12345
  638. .OrderByDescending(d => d.CreationTime);
  639. }
  640. /// <summary>
  641. /// 未签收统计
  642. /// </summary>
  643. /// <param name="dto"></param>
  644. /// <returns></returns>
  645. public ISugarQueryable<Order, WorkflowStep> QueryUnsignedOrders(QueryUnsignedOrdersRequest dto)
  646. {
  647. if (dto.EndTime.HasValue)
  648. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  649. var IsCenter = _sessionContext.OrgIsCenter;
  650. return _orderRepository.Queryable()
  651. .LeftJoin<WorkflowStep>((x, ws) => x.Id == ws.ExternalId)
  652. .WhereIF(dto.StartTime.HasValue, (x, ws) => ws.CreationTime >= dto.StartTime)
  653. .WhereIF(dto.EndTime.HasValue, (x, ws) => ws.CreationTime <= dto.EndTime)
  654. .WhereIF(dto.Level == 0 && IsCenter == false, (x, ws) => ws.AcceptorOrgId.StartsWith(_sessionContext.OrgId))
  655. .WhereIF(dto.Level == 1, (x, ws) => ws.AcceptorOrgId == _sessionContext.OrgId)
  656. .WhereIF(dto.Level == 2, (x, ws) => ws.AcceptorOrgId.StartsWith(_sessionContext.OrgId))
  657. .WhereIF(dto.Signed == 0, (x, ws) => ws.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.WaitForAccept)
  658. .WhereIF(dto.Signed == 1, (x, ws) => ws.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.WaitForHandle)
  659. .Where((x, ws) => ws.CountersignPosition == Share.Enums.FlowEngine.ECountersignPosition.None && x.Status > EOrderStatus.WaitForAccept)
  660. .OrderByDescending((x, ws) => ws.CreationTime);
  661. }
  662. /// <summary>
  663. /// 信件来源统计
  664. /// </summary>
  665. /// <param name="dto"></param>
  666. /// <returns></returns>
  667. public ISugarQueryable<Order> QueryOrderSource(QueryOrderSourceRequest dto)
  668. {
  669. if (dto.EndTime.HasValue)
  670. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  671. return _orderRepository.Queryable()
  672. .WhereIF(dto.StartTime.HasValue, d => d.CreationTime >= dto.StartTime)
  673. .WhereIF(dto.EndTime.HasValue, d => d.CreationTime <= dto.EndTime)
  674. .WhereIF(dto.TypeId != null && dto.TypeId == 1, x => x.IdentityType == EIdentityType.Citizen)
  675. .WhereIF(dto.TypeId != null && dto.TypeId == 2, x => x.IdentityType == EIdentityType.Enterprise)
  676. .Where(d => d.SourceChannel != null && d.SourceChannel != "");
  677. }
  678. /// <summary>
  679. /// 信件来源统计明细
  680. /// </summary>
  681. /// <param name="dto"></param>
  682. /// <returns></returns>
  683. public ISugarQueryable<Order> QueryOrderSourceDetail(QueryOrderSourceDetailRequest dto)
  684. {
  685. return _orderRepository.Queryable()
  686. .WhereIF(!string.IsNullOrEmpty(dto.SourceChannel), d => d.SourceChannel == dto.SourceChannel)
  687. .WhereIF(dto.Time.HasValue, d => d.CreationTime.ToString("yyyy-MM-dd") == dto.Time.Value.ToString("yyyy-MM-dd"))
  688. .WhereIF(dto.TypeId != null && dto.TypeId == 1, x => x.IdentityType == EIdentityType.Citizen)
  689. .WhereIF(dto.TypeId != null && dto.TypeId == 2, x => x.IdentityType == EIdentityType.Enterprise)
  690. .Where(d => d.SourceChannel != null && d.SourceChannel != "");
  691. }
  692. /// <summary>
  693. /// 部门超期统计
  694. /// </summary>
  695. /// <param name="dto"></param>
  696. /// <returns></returns>
  697. public ISugarQueryable<OrderBiOrgDataListVo> QueryOrgDataList(ReportPagedRequest dto)
  698. {
  699. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  700. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  701. var IsCenter = _sessionContext.OrgIsCenter;
  702. var queryOrder = _systemOrganizeRepository.Queryable()
  703. .LeftJoin<Order>((x, o) => x.Id == o.ActualHandleOrgCode)
  704. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= dto.StartTime)
  705. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= dto.EndTime)
  706. .WhereIF(dto.TypeId != null && dto.TypeId == 1, (x, o) => o.IdentityType == EIdentityType.Citizen)
  707. .WhereIF(dto.TypeId != null && dto.TypeId == 2, (x, o) => o.IdentityType == EIdentityType.Enterprise)
  708. .WhereIF(IsCenter == false, (x, o) => o.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  709. .GroupBy((x, o) => new { x.Id, x.Name })
  710. .Select((x, o) => new OrderBiOrgDataListVo
  711. {
  712. OrgName = x.Name,
  713. OrgId = x.Id,
  714. HandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.Status >= EOrderStatus.Filed && o.ExpiredTime < o.FiledTime, 1, 0)),
  715. NoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.Status < EOrderStatus.Filed && o.ExpiredTime < SqlFunc.GetDate(), 1, 0)),
  716. }).MergeTable();
  717. var queryCountersign = _workflowStepRepository.Queryable()
  718. .Where(x => x.CountersignPosition != ECountersignPosition.None)
  719. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  720. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  721. .GroupBy(x => x.HandlerOrgId)
  722. .Select(x => new OrderBiOrgDataListVo
  723. {
  724. OrgId = x.HandlerOrgId,
  725. CounterHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < x.HandleTime, 1, 0)),
  726. CounterNoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status != Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < SqlFunc.GetDate(), 1, 0)),
  727. }).MergeTable();
  728. var query =
  729. _systemOrganizeRepository.Queryable()
  730. .LeftJoin(queryOrder, (x, or) => x.Id == or.OrgId)
  731. .LeftJoin(queryCountersign, (x, or, co) => x.Id == co.OrgId)
  732. //.LeftJoin<SystemOrganize>((or, co, so) => or.OrgId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == so.Id)
  733. .LeftJoin<SystemOrganize>((x, or, co, so) => or.OrgId == so.Id && so.Level == 1)
  734. .GroupBy((x, or, co, so) => new { so.Id, so.Name })
  735. .Select((x, or, co, so) => new OrderBiOrgDataListVo
  736. {
  737. OrgName = so.Name,
  738. OrgId = so.Id,
  739. HandlerExtendedNum = SqlFunc.AggregateSum(or.HandlerExtendedNum),
  740. NoHandlerExtendedNum = SqlFunc.AggregateSum(or.NoHandlerExtendedNum),
  741. CounterHandlerExtendedNum = SqlFunc.AggregateSum(co.CounterHandlerExtendedNum),
  742. CounterNoHandlerExtendedNum = SqlFunc.AggregateSum(co.CounterNoHandlerExtendedNum)
  743. }).MergeTable();
  744. query = query.WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.OrgName.Contains(dto.Keyword!))
  745. .Where(x => x.OrgName != null).Where(x => x.HandlerExtendedNum > 0 || x.NoHandlerExtendedNum > 0 || x.CounterHandlerExtendedNum > 0 || x.CounterNoHandlerExtendedNum > 0);
  746. switch (dto.SortField)
  747. {
  748. case "handlerExtendedNum":
  749. query = dto.SortRule is 0 ? query.OrderBy(x => x.HandlerExtendedNum) : query.OrderByDescending(x => x.HandlerExtendedNum);
  750. break;
  751. case "counterHandlerExtendedNum":
  752. query = dto.SortRule is 0 ? query.OrderBy(x => x.CounterHandlerExtendedNum) : query.OrderByDescending(x => x.CounterHandlerExtendedNum);
  753. break;
  754. case "noHandlerExtendedNum":
  755. query = dto.SortRule is 0 ? query.OrderBy(x => x.NoHandlerExtendedNum) : query.OrderByDescending(x => x.NoHandlerExtendedNum);
  756. break;
  757. case "counterNoHandlerExtendedNum":
  758. query = dto.SortRule is 0 ? query.OrderBy(x => x.CounterNoHandlerExtendedNum) : query.OrderByDescending(x => x.CounterNoHandlerExtendedNum);
  759. break;
  760. }
  761. return query;
  762. }
  763. /// <summary>
  764. /// 部门超期统计明细
  765. /// </summary>
  766. /// <param name="dto"></param>
  767. /// <returns></returns>
  768. public ISugarQueryable<Order> QueryOrgDataListDetail(OrgDataListDetailRequest dto)
  769. {
  770. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  771. var quer = _orderRepository.Queryable()
  772. .InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id && so.Level == 1)
  773. .Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
  774. //.WhereIF(dto.Statuses.Any(), x => dto.Statuses.Contains(x.Status)) //工单状态
  775. .WhereIF(dto.QueryType == 1, (x, so) => x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) //业务已办超期
  776. .WhereIF(dto.QueryType == 3, (x, so) => x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()) //业务待办超期
  777. .WhereIF(dto.TypeId != null && dto.TypeId == 1, (x, so) => x.IdentityType == EIdentityType.Citizen)
  778. .WhereIF(dto.TypeId != null && dto.TypeId == 2, (x, so) => x.IdentityType == EIdentityType.Enterprise)
  779. .WhereIF(dto.QueryType == 5, (x, so) =>
  780. (x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) || (x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()))
  781. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode), (x, so) => x.ActualHandleOrgCode == dto.OrgCode)
  782. .Select(x => new Order { DaysOverdueOrgName = x.ActualHandleOrgName, Id = x.Id.SelectAll() });
  783. if (dto.QueryType is 2 or 4)
  784. {
  785. var queryCountersign = _workflowStepRepository.Queryable()
  786. .Includes(x => x.Workflow)
  787. .InnerJoin<SystemOrganize>((x, so) => x.HandlerOrgId == so.Id && so.Level == 1)
  788. .Where((x, so) => x.CountersignPosition != ECountersignPosition.None && x.Workflow.ModuleCode == "OrderHandle")
  789. .Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
  790. .WhereIF(dto.QueryType == 2, (x, so) => x.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < x.HandleTime) //会签已办超期
  791. .WhereIF(dto.QueryType == 4, (x, so) => x.Status != Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < SqlFunc.GetDate())//会签待办超期
  792. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode), (x, so) => x.HandlerOrgId == dto.OrgCode)
  793. .GroupBy(x => new { x.ExternalId, x.HandlerOrgName })
  794. .Select(x => new { Id = x.ExternalId, WorkflowId = x.ExternalId, HandlerOrgName = x.HandlerOrgName });
  795. quer = _orderRepository.Queryable().InnerJoin(queryCountersign, (o, w) => o.Id == w.Id)
  796. .Select((o, w) => new Order { DaysOverdueOrgName = w.HandlerOrgName, Id = o.Id.SelectAll() });
  797. //quer = _orderRepository.UnionAll(quer, queryCountersignOrder);
  798. }
  799. return quer;
  800. }
  801. /// <summary>
  802. /// 部门超期统计明细
  803. /// </summary>
  804. /// <param name="dto"></param>
  805. /// <returns></returns>
  806. public ISugarQueryable<Order> QueryOrgDataListDetail(OrgDataListAllDetailRequest dto)
  807. {
  808. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  809. bool IsCenter = _sessionContext.OrgIsCenter;
  810. var quer = _orderRepository.Queryable()
  811. .InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id && so.Level == 1)
  812. .Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
  813. .WhereIF(dto.Statuses.Any(), (x, so) => dto.Statuses.Contains(x.Status)) //工单状态
  814. .WhereIF(dto.ExpiredType is 2, (x, so) => x.OrderDelays.Any(x => x.DelayState == EDelayState.Pass))
  815. .Where((x, so) =>
  816. (x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) || (x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()))
  817. .WhereIF(IsCenter == false, (x, so) => x.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  818. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), (x, so) => x.AcceptorOrgName == dto.OrgName)
  819. .Select(x => new Order { DaysOverdueOrgName = x.ActualHandleOrgName, Id = x.Id.SelectAll() });
  820. var queryCountersign = _workflowStepRepository.Queryable()
  821. .Includes(x => x.Workflow)
  822. .InnerJoin<SystemOrganize>((x, so) => x.HandlerOrgId == so.Id && so.Level == 1)
  823. .LeftJoin<Order>((x, so, o) => x.ExternalId == o.Id)
  824. .Where((x, so) => x.CountersignPosition != ECountersignPosition.None && x.Workflow.ModuleCode == "OrderHandle")
  825. .Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
  826. .Where((x, so) => (x.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < x.HandleTime) || (x.Status != Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < SqlFunc.GetDate()))
  827. .WhereIF(IsCenter == false, (x, so) => x.HandlerOrgId == _sessionContext.RequiredOrgId)
  828. .WhereIF(dto.ExpiredType is 2, (x, so, o) => o.OrderDelays.Any(x => x.DelayState == EDelayState.Pass))
  829. .GroupBy(x => new { x.ExternalId, x.HandlerOrgName })
  830. .Select(x => new { Id = x.ExternalId, WorkflowId = x.ExternalId, HandlerOrgName = x.HandlerOrgName });
  831. var queryCountersignOrder = _orderRepository.Queryable().InnerJoin(queryCountersign, (o, w) => o.Id == w.Id)
  832. .Select((o, w) => new Order { DaysOverdueOrgName = w.HandlerOrgName, Id = o.Id.SelectAll() });
  833. quer = _orderRepository.UnionAll(quer, queryCountersignOrder).MergeTable().InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id);
  834. return quer;
  835. }
  836. /// <summary>
  837. /// 回退错件统计
  838. /// </summary>
  839. /// <param name="dto"></param>
  840. /// <returns></returns>
  841. public ISugarQueryable<OrderReTransactVo> OrderReTransact(QueryOrderReTransactRequest dto)
  842. {
  843. return _orderSpecialDetailRepository.Queryable()
  844. .Includes(x => x.OrderSpecial)
  845. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.OrgName.Contains(dto.OrgName!))
  846. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  847. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  848. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime)
  849. .GroupBy(x => new { Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"), x.OrgId, x.OrgName })
  850. .Select(x => new OrderReTransactVo
  851. {
  852. Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"),
  853. OrgId = x.OrgId,
  854. OrgName = x.OrgName,
  855. Num = SqlFunc.AggregateCount(1)
  856. }).MergeTable()
  857. .OrderByIF(dto.SortRule is 0, x => x.Num, OrderByType.Asc)
  858. .OrderByIF(dto.SortRule is 1, x => x.Num, OrderByType.Desc); ;
  859. }
  860. /// <summary>
  861. /// 回退错件明细统计
  862. /// </summary>
  863. /// <param name="dto"></param>
  864. /// <returns></returns>
  865. public ISugarQueryable<OrderSpecialDetail> QueryOrderSourceDetail(QueryOrderReTransactDetailRequest dto)
  866. {
  867. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  868. throw UserFriendlyException.SameMessage("请选择时间!");
  869. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  870. return _orderSpecialDetailRepository.Queryable()
  871. .Includes(x => x.OrderSpecial, s => s.Order)
  872. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.OrgName.Contains(dto.OrgName!))
  873. .WhereIF(!string.IsNullOrEmpty(dto.ErrorName), x => x.ErrorName.Contains(dto.ErrorName!))
  874. .WhereIF(!string.IsNullOrEmpty(dto.No), x => x.OrderSpecial!.Order!.No!.Contains(dto.No!))
  875. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  876. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  877. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime);
  878. }
  879. /// <summary>
  880. /// 部门满意度统计
  881. /// </summary>
  882. /// <returns></returns>
  883. public async Task<List<VisitAndOrgSatisfactionStatisticsDto>> VisitAndOrgSatisfactionStatistics(PagedKeywordSonRequest dto)
  884. {
  885. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  886. bool IsCenter = _sessionContext.OrgIsCenter;
  887. var list = _orderVisitDetailRepository.Queryable()
  888. .Where(x => x.OrderVisit.VisitTime >= dto.StartTime.Value && x.OrderVisit.VisitTime <= dto.EndTime.Value && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited && !string.IsNullOrEmpty(x.VisitOrgCode))
  889. .WhereIF(string.IsNullOrEmpty(dto.OrgName) == false, x => x.VisitOrgName.Contains(dto.OrgName))
  890. .WhereIF(string.IsNullOrEmpty(dto.LineNum) == false, x => x.OrderVisit.Order.CallRecord.Gateway.Contains(dto.LineNum))
  891. .WhereIF(dto.TypeCode != null && dto.TypeCode == 1, x => x.OrderVisit.Order.IdentityType == EIdentityType.Citizen)
  892. .WhereIF(dto.TypeCode != null && dto.TypeCode == 2, x => x.OrderVisit.Order.IdentityType == EIdentityType.Enterprise)
  893. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.OrgId));
  894. var data = new List<VisitAndOrgSatisfactionStatisticsDto>();
  895. if (IsCenter && list != null)
  896. {
  897. data = await list.GroupBy(x => new
  898. {
  899. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  900. })
  901. .Select(x => new VisitAndOrgSatisfactionStatisticsDto()
  902. {
  903. OrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  904. TotalSumCount = SqlFunc.AggregateCount(x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  905. VerySatisfiedCount = SqlFunc.IIF(dto.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))),//非常满意数
  906. SatisfiedCount = SqlFunc.IIF(dto.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))), //满意数
  907. RegardedAsSatisfiedCount = SqlFunc.IIF(dto.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))),//视为满意
  908. DefaultSatisfiedCount = SqlFunc.IIF(dto.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))),//默认满意
  909. NoSatisfiedCount = SqlFunc.IIF(dto.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))),//不满意
  910. NoEvaluateCount = SqlFunc.IIF(dto.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))),//未做评价
  911. NoPutThroughCount = SqlFunc.IIF(dto.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))),//未接通
  912. })
  913. .MergeTable()
  914. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  915. .Select((it, o) => new VisitAndOrgSatisfactionStatisticsDto()
  916. {
  917. OrgName = o.Name,
  918. OrgCode = it.OrgCode,
  919. OrgType = o.OrgType,
  920. TotalSumCount = it.TotalSumCount,
  921. VerySatisfiedCount = it.VerySatisfiedCount,//非常满意数
  922. SatisfiedCount = it.SatisfiedCount, //满意数
  923. RegardedAsSatisfiedCount = it.RegardedAsSatisfiedCount,//视为满意
  924. DefaultSatisfiedCount = it.DefaultSatisfiedCount,//默认满意
  925. NoSatisfiedCount = it.NoSatisfiedCount,//不满意
  926. NoEvaluateCount = it.NoEvaluateCount,//未做评价
  927. NoPutThroughCount = it.NoPutThroughCount,//未接通
  928. })
  929. .ToListAsync();
  930. }
  931. else
  932. {
  933. data = await list.GroupBy(x => new
  934. {
  935. x.VisitOrgCode
  936. })
  937. .Select(x => new VisitAndOrgSatisfactionStatisticsDto()
  938. {
  939. OrgCode = x.VisitOrgCode,
  940. TotalSumCount = SqlFunc.AggregateCount(x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  941. VerySatisfiedCount = SqlFunc.IIF(dto.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))),//非常满意数
  942. SatisfiedCount = SqlFunc.IIF(dto.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))), //满意数
  943. RegardedAsSatisfiedCount = SqlFunc.IIF(dto.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))),//视为满意
  944. DefaultSatisfiedCount = SqlFunc.IIF(dto.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))),//默认满意
  945. NoSatisfiedCount = SqlFunc.IIF(dto.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))),//不满意
  946. NoEvaluateCount = SqlFunc.IIF(dto.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))),//未做评价
  947. NoPutThroughCount = SqlFunc.IIF(dto.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))),//未接通
  948. })
  949. .MergeTable()
  950. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  951. .Select((it, o) => new VisitAndOrgSatisfactionStatisticsDto()
  952. {
  953. OrgName = o.Name,
  954. OrgCode = it.OrgCode,
  955. OrgType = o.OrgType,
  956. TotalSumCount = it.TotalSumCount,
  957. VerySatisfiedCount = it.VerySatisfiedCount,//非常满意数
  958. SatisfiedCount = it.SatisfiedCount, //满意数
  959. RegardedAsSatisfiedCount = it.RegardedAsSatisfiedCount,//视为满意
  960. DefaultSatisfiedCount = it.DefaultSatisfiedCount,//默认满意
  961. NoSatisfiedCount = it.NoSatisfiedCount,//不满意
  962. NoEvaluateCount = it.NoEvaluateCount,//未做评价
  963. NoPutThroughCount = it.NoPutThroughCount,//未接通
  964. })
  965. .ToListAsync();
  966. }
  967. return data;
  968. }
  969. /// <summary>
  970. /// 子部门满意度
  971. /// </summary>
  972. /// <returns></returns>
  973. public async Task<List<VisitAndOrgSatisfactionStatisticsDto>> VisitAndOrgStatisfactionOrgDetail(PagedKeywordSonRequest dto)
  974. {
  975. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  976. bool IsCenter = _sessionContext.OrgIsCenter;
  977. var list = await _systemOrganizeRepository.Queryable().Where(x => x.Id.StartsWith(dto.OrgCode))
  978. .LeftJoin<OrderVisitDetail>((x, it) => x.Id == it.VisitOrgCode)
  979. .Where((x, it) => it.OrderVisit.VisitTime >= dto.StartTime.Value && it.OrderVisit.VisitTime <= dto.EndTime.Value && it.VisitTarget == EVisitTarget.Org && it.OrderVisit.VisitState == EVisitState.Visited)
  980. .WhereIF(dto.OrgCode == "001", (x, it) => it.VisitOrgCode == dto.OrgCode)
  981. .WhereIF(dto.OrgCode != "001", (x, it) => it.VisitOrgCode.StartsWith(dto.OrgCode))
  982. .WhereIF(!string.IsNullOrEmpty(dto.LineNum), (x, it) => it.OrderVisit.Order.CallRecord.Gateway.Contains(dto.LineNum))
  983. .WhereIF(dto.TypeCode != null && dto.TypeCode == 1, (x, it) => it.OrderVisit.Order.IdentityType == EIdentityType.Citizen)
  984. .WhereIF(dto.TypeCode != null && dto.TypeCode == 2, (x, it) => it.OrderVisit.Order.IdentityType == EIdentityType.Enterprise)
  985. .WhereIF(IsCenter == false, (x, it) => it.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  986. .GroupBy((x, it) => new
  987. {
  988. VisitOrgCode = it.VisitOrgCode
  989. })
  990. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  991. {
  992. OrgCode = it.VisitOrgCode,
  993. TotalSumCount = SqlFunc.AggregateCount(it.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("9"))),
  994. VerySatisfiedCount = SqlFunc.IIF(dto.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))),//非常满意数
  995. SatisfiedCount = SqlFunc.IIF(dto.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))), //满意数
  996. RegardedAsSatisfiedCount = SqlFunc.IIF(dto.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))),//视为满意
  997. DefaultSatisfiedCount = SqlFunc.IIF(dto.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))),//默认满意
  998. NoSatisfiedCount = SqlFunc.IIF(dto.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))),//不满意
  999. NoEvaluateCount = SqlFunc.IIF(dto.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))),//未做评价
  1000. NoPutThroughCount = SqlFunc.IIF(dto.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)))//未接通
  1001. })
  1002. .MergeTable()
  1003. .LeftJoin<SystemOrganize>((x, it) => x.OrgCode == it.Id)
  1004. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  1005. {
  1006. OrgName = it.Name,
  1007. OrgCode = x.OrgCode,
  1008. OrgType = it.OrgType,
  1009. TotalSumCount = x.TotalSumCount,
  1010. VerySatisfiedCount = x.VerySatisfiedCount,//非常满意数
  1011. SatisfiedCount = x.SatisfiedCount, //满意数
  1012. RegardedAsSatisfiedCount = x.RegardedAsSatisfiedCount,//视为满意
  1013. DefaultSatisfiedCount = x.DefaultSatisfiedCount,//默认满意
  1014. NoSatisfiedCount = x.NoSatisfiedCount,//不满意
  1015. NoEvaluateCount = x.NoEvaluateCount,//未做评价
  1016. NoPutThroughCount = x.NoPutThroughCount,//未接通
  1017. })
  1018. .ToListAsync();
  1019. return list;
  1020. }
  1021. /// <summary>
  1022. /// 部门满意度明细统计
  1023. /// </summary>
  1024. /// <param name="dto"></param>
  1025. /// <returns></returns>
  1026. public ISugarQueryable<OrderVisitDetail> VisitAndOrgSatisfactionDetail(VisitAndOrgSatisfactionDetailDto dto)
  1027. {
  1028. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  1029. bool IsCenter = _sessionContext.OrgIsCenter;
  1030. return _orderVisitDetailRepository.Queryable()
  1031. .Includes(x => x.OrderVisit, o => o.Order, d => d.CallRecord)
  1032. .Where(x => x.OrderVisit.VisitTime >= dto.StartTime && x.OrderVisit.VisitTime <= dto.EndTime && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited)
  1033. .WhereIF(dto.OrgCode == "001", x => x.VisitOrgCode == dto.OrgCode)
  1034. .WhereIF(dto.TypeCode != null && dto.TypeCode == 1, x => x.OrderVisit.Order.IdentityType == EIdentityType.Citizen)
  1035. .WhereIF(dto.TypeCode != null && dto.TypeCode == 2, x => x.OrderVisit.Order.IdentityType == EIdentityType.Enterprise)
  1036. //.WhereIF(dto.OrgCode != "001", x => x.VisitOrgCode == dto.OrgCode).
  1037. .WhereIF(dto.IsOnlyMy == true, x => x.VisitOrgCode == dto.OrgCode)
  1038. .WhereIF(IsCenter == true && dto.IsOnlyMy == true, x => x.VisitOrgCode == dto.OrgCode)
  1039. .WhereIF(IsCenter == true && dto.IsOnlyMy == null, x => x.VisitOrgCode.StartsWith(dto.OrgCode))
  1040. .WhereIF(IsCenter == false, x => x.VisitOrgCode == dto.OrgCode)
  1041. .WhereIF(dto.TypeId is 1, x => SqlFunc.JsonField(x.OrgProcessingResults, "Key") == dto.DateValue)
  1042. .WhereIF(dto.TypeId is 2, x => SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == dto.DateValue)
  1043. .WhereIF(!string.IsNullOrEmpty(dto.LineNum), x => x.OrderVisit.Order.CallRecord.Gateway == dto.LineNum);
  1044. }
  1045. /// <summary>
  1046. /// 热点区域统计
  1047. /// </summary>
  1048. /// <param name="dto"></param>
  1049. /// <returns></returns>
  1050. public async Task<(List<SystemArea> area, object items)> HotspotAndAreaStatistics(HotspotAndAreaStatisticsReq dto)
  1051. {
  1052. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  1053. var areaList = _systemAreaRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == 6 && x.Id != "510000").OrderBy(x => x.Id).MergeTable();
  1054. var endIndex = (2 * dto.HotspotLevel).ToString();
  1055. var hotspotList = _hotspotRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == int.Parse(endIndex))
  1056. .Select(x => new
  1057. {
  1058. HotspotId = x.Id,
  1059. HotspotName = x.HotSpotFullName,
  1060. }).MergeTable();
  1061. var orderList = _orderRepository.Queryable().Where(x => x.CreationTime >= dto.StartTime && x.CreationTime < dto.EndTime)
  1062. .Select(x => new
  1063. {
  1064. HotspotId = x.HotspotId.Substring(0, int.Parse(endIndex)),
  1065. AreaCode = x.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1066. }).MergeTable();
  1067. var hotListAndOrder = hotspotList.LeftJoin(orderList, (it, o) => it.HotspotId == o.HotspotId)
  1068. .GroupBy((it, o) => new
  1069. {
  1070. it.HotspotId,
  1071. it.HotspotName,
  1072. AreaCode = o.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1073. })
  1074. .OrderBy((it, o) => it.HotspotId)
  1075. .Select((it, o) => new
  1076. {
  1077. HotspotId = it.HotspotId,
  1078. HotspotName = it.HotspotName,
  1079. AreaCode = o.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1080. Count = SqlFunc.AggregateCount(it.HotspotId)
  1081. }).MergeTable();
  1082. var returnList = await areaList.LeftJoin(hotListAndOrder, (pp, dd) => pp.Id == dd.AreaCode)
  1083. .GroupBy((pp, dd) => new
  1084. {
  1085. HotspotId = dd.HotspotId,
  1086. HotspotName = dd.HotspotName,
  1087. AreaCode = pp.Id,
  1088. AreaName = pp.AreaName,
  1089. })
  1090. .OrderBy((pp, dd) => dd.HotspotId)
  1091. .Select((pp, dd) => new
  1092. {
  1093. HotspotId = dd.HotspotId,
  1094. HotspotName = dd.HotspotName,
  1095. AreaCode = pp.Id,
  1096. AreaName = pp.AreaName,
  1097. Count = SqlFunc.AggregateSum(dd.Count)
  1098. }).ToPivotListAsync(q => q.AreaCode, q => new { q.HotspotName, q.HotspotId }, q => q.Sum(x => x.Count));
  1099. var areaTitleList = await _systemAreaRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == 6 && x.Id != "510000").OrderBy(x => x.Id).ToListAsync();
  1100. return (areaTitleList, returnList);
  1101. }
  1102. /// <summary>
  1103. /// 热点区域统计--导出
  1104. /// </summary>
  1105. /// <param name="dto"></param>
  1106. /// <returns></returns>
  1107. public async Task<DataTable> HotspotAndAreaStatisticsExport(HotspotAndAreaStatisticsReq dto)
  1108. {
  1109. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  1110. var areaList = _systemAreaRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == 6 && x.Id != "510000").OrderBy(x => x.Id).MergeTable();
  1111. var endIndex = (2 * dto.HotspotLevel).ToString();
  1112. var hotspotList = _hotspotRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == int.Parse(endIndex))
  1113. .Select(x => new
  1114. {
  1115. HotspotId = x.Id,
  1116. HotspotName = x.HotSpotFullName,
  1117. }).MergeTable();
  1118. var orderList = _orderRepository.Queryable().Where(x => x.CreationTime >= dto.StartTime && x.CreationTime < dto.EndTime)
  1119. .Select(x => new
  1120. {
  1121. HotspotId = x.HotspotId.Substring(0, int.Parse(endIndex)),
  1122. AreaCode = x.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1123. }).MergeTable();
  1124. var hotListAndOrder = hotspotList.LeftJoin(orderList, (it, o) => it.HotspotId == o.HotspotId)
  1125. .GroupBy((it, o) => new
  1126. {
  1127. it.HotspotId,
  1128. it.HotspotName,
  1129. AreaCode = o.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1130. })
  1131. .OrderBy((it, o) => it.HotspotId)
  1132. .Select((it, o) => new
  1133. {
  1134. HotspotId = it.HotspotId,
  1135. HotspotName = it.HotspotName,
  1136. AreaCode = o.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  1137. Count = SqlFunc.AggregateCount(it.HotspotId)
  1138. }).MergeTable();
  1139. var returnList = await areaList.LeftJoin(hotListAndOrder, (pp, dd) => pp.Id == dd.AreaCode)
  1140. .GroupBy((pp, dd) => new
  1141. {
  1142. HotspotId = dd.HotspotId,
  1143. HotspotName = dd.HotspotName,
  1144. AreaCode = pp.Id,
  1145. AreaName = pp.AreaName,
  1146. })
  1147. .OrderBy((pp, dd) => dd.HotspotId)
  1148. .Select((pp, dd) => new
  1149. {
  1150. HotspotId = dd.HotspotId,
  1151. HotspotName = dd.HotspotName,
  1152. AreaCode = pp.Id,
  1153. AreaName = pp.AreaName,
  1154. Count = SqlFunc.AggregateSum(dd.Count)
  1155. }).ToPivotTableAsync(q => q.AreaName, q => new { q.HotspotName }, q => q.Sum(x => x.Count));
  1156. //returnList.Rows.RemoveAt(returnList.Rows.Count-1);
  1157. return returnList;
  1158. }
  1159. public DataTable InitHotspotTable(DataTable dt, List<string> AddColumnName, int HotspotLevel)
  1160. {
  1161. //修改列名
  1162. if (dt.Columns.Contains("HotspotName"))
  1163. dt.Columns["HotspotName"].ColumnName = "一级热点";
  1164. //增加小计
  1165. DataColumn totalColumn = new DataColumn("小计", typeof(decimal));
  1166. dt.Columns.Add(totalColumn);
  1167. if (dt.Columns.Contains("Column1"))
  1168. dt.Columns.Remove("Column1");
  1169. //计算小计
  1170. for (int i = 0;i < dt.Rows.Count;i++)
  1171. {
  1172. int sumcount = 0;
  1173. for (int j = 1;j < dt.Columns.Count - 1;j++)
  1174. {
  1175. sumcount += Convert.ToInt32(dt.Rows[i][j].ToString());
  1176. }
  1177. dt.Rows[i][dt.Columns.Count - 1] = sumcount;
  1178. }
  1179. //增加合计
  1180. DataRow totalRow = dt.NewRow();
  1181. if (dt.Columns[0].ColumnName == "HotspotName") totalRow["HotspotName"] = "合计";
  1182. else totalRow["一级热点"] = "合计";
  1183. for (int i = 1;i < dt.Columns.Count;i++)
  1184. {
  1185. int sumcount = 0;
  1186. for (int j = 0;j < dt.Rows.Count;j++)
  1187. {
  1188. sumcount += Convert.ToInt32(dt.Rows[j][i].ToString());
  1189. }
  1190. totalRow[i] = sumcount;
  1191. }
  1192. dt.Rows.Add(totalRow);
  1193. //创建新表
  1194. DataTable dt2 = new DataTable();
  1195. //添加表头
  1196. foreach (var item in AddColumnName)
  1197. {
  1198. if (item.Equals("HotspotName") || item.Equals("热点分类"))
  1199. {
  1200. dt2.Columns.Add("一级热点");
  1201. if (HotspotLevel == 2)
  1202. {
  1203. dt2.Columns.Add("二级热点");
  1204. }
  1205. else if (HotspotLevel == 3)
  1206. {
  1207. dt2.Columns.Add("二级热点");
  1208. dt2.Columns.Add("三级热点");
  1209. }
  1210. else if (HotspotLevel == 4)
  1211. {
  1212. dt2.Columns.Add("二级热点");
  1213. dt2.Columns.Add("三级热点");
  1214. dt2.Columns.Add("四级热点");
  1215. }
  1216. }
  1217. else
  1218. {
  1219. //if (dt.Columns.Contains(item))
  1220. dt2.Columns.Add(item);
  1221. }
  1222. }
  1223. //处理数据
  1224. foreach (DataRow sourceRow in dt.Rows)
  1225. {
  1226. if (sourceRow["一级热点"].ToString() == "")
  1227. {
  1228. continue;
  1229. }
  1230. DataRow targetRow = dt2.NewRow();
  1231. foreach (var item in AddColumnName)
  1232. {
  1233. if (item.Equals("HotspotName") || item.Equals("热点分类"))
  1234. {
  1235. targetRow["一级热点"] = sourceRow["一级热点"].ToString()?.Split('-')[0];
  1236. if (HotspotLevel == 2)
  1237. {
  1238. targetRow["二级热点"] = sourceRow["一级热点"].ToString()?.Split('-')[1];
  1239. }
  1240. else if (HotspotLevel == 3)
  1241. {
  1242. try
  1243. {
  1244. targetRow["二级热点"] = sourceRow["一级热点"].ToString()?.Split('-')[1];
  1245. }
  1246. catch
  1247. {
  1248. targetRow["二级热点"] = "";
  1249. }
  1250. try
  1251. {
  1252. targetRow["三级热点"] = sourceRow["一级热点"].ToString()?.Split('-')[2];
  1253. }
  1254. catch
  1255. {
  1256. targetRow["三级热点"] = "";
  1257. }
  1258. }
  1259. else if (HotspotLevel == 4)
  1260. {
  1261. try
  1262. {
  1263. targetRow["二级热点"] = sourceRow["一级热点"].ToString()?.Split('-')[1];
  1264. }
  1265. catch
  1266. {
  1267. targetRow["二级热点"] = "";
  1268. }
  1269. try
  1270. {
  1271. targetRow["三级热点"] = sourceRow["一级热点"].ToString()?.Split('-')[2];
  1272. }
  1273. catch
  1274. {
  1275. targetRow["三级热点"] = "";
  1276. }
  1277. try
  1278. {
  1279. targetRow["四级热点"] = sourceRow["一级热点"].ToString()?.Split('-')[3];
  1280. }
  1281. catch
  1282. {
  1283. targetRow["四级热点"] = "";
  1284. }
  1285. }
  1286. }
  1287. else
  1288. {
  1289. try
  1290. {
  1291. targetRow[item] = sourceRow[item];
  1292. }
  1293. catch
  1294. {
  1295. targetRow[item] = 0;
  1296. }
  1297. }
  1298. }
  1299. dt2.Rows.Add(targetRow);
  1300. }
  1301. return dt2;
  1302. }
  1303. /// <summary>
  1304. /// 热点类型满意度统计
  1305. /// </summary>
  1306. /// <returns></returns>
  1307. public async Task<List<VisitAndHotspotSatisfactionStatisticsDto>> VisitAndHotspotSatisfactionStatistics(VisitAndHotspotPagedKeywordRequest dto)
  1308. {
  1309. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1310. bool IsCenter = _sessionContext.OrgIsCenter;
  1311. var list = _orderVisitDetailRepository.Queryable()
  1312. .Includes(x => x.OrderVisit, v => v.Order)
  1313. .InnerJoin<Hotspot>((x, h) => h.Id == x.OrderVisit.Order.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")) && h.ParentId == null)
  1314. .Where(x => x.OrderVisit.VisitTime >= dto.StartTime.Value && x.OrderVisit.VisitTime <= dto.EndTime.Value && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited && !string.IsNullOrEmpty(x.VisitOrgCode))
  1315. .WhereIF(string.IsNullOrEmpty(dto.HotspotName) == false, (x, h) => h.HotSpotName == dto.HotspotName)
  1316. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  1317. .WhereIF(dto.TypeId == 1, x => x.OrgProcessingResults != null)
  1318. .WhereIF(dto.TypeId == 2, x => x.OrgHandledAttitude != null);
  1319. var data = new List<VisitAndHotspotSatisfactionStatisticsDto>();
  1320. if (IsCenter && list != null)
  1321. {
  1322. data = await list.GroupBy((x, h) => new
  1323. {
  1324. HotspotName = h.HotSpotName,
  1325. HotspotId = h.Id
  1326. })
  1327. .Select((x, h) => new VisitAndHotspotSatisfactionStatisticsDto()
  1328. {
  1329. HotspotName = h.HotSpotName,
  1330. HotspotId = h.Id,
  1331. TotalSumCount = SqlFunc.AggregateCount(x.OrderVisit.Order.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2"))),
  1332. VerySatisfiedCount = SqlFunc.IIF(dto.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))),//非常满意数
  1333. SatisfiedCount = SqlFunc.IIF(dto.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))), //满意数
  1334. RegardedAsSatisfiedCount = SqlFunc.IIF(dto.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))),//视为满意
  1335. DefaultSatisfiedCount = SqlFunc.IIF(dto.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))),//默认满意
  1336. NoSatisfiedCount = SqlFunc.IIF(dto.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))),//不满意
  1337. NoEvaluateCount = SqlFunc.IIF(dto.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))),//未做评价
  1338. NoPutThroughCount = SqlFunc.IIF(dto.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))),//未接通
  1339. })
  1340. .ToListAsync();
  1341. }
  1342. else
  1343. {
  1344. data = await list.GroupBy((x, h) => new
  1345. {
  1346. HotspotName = h.HotSpotName,
  1347. HotspotId = h.Id
  1348. })
  1349. .Select((x, h) => new VisitAndHotspotSatisfactionStatisticsDto()
  1350. {
  1351. HotspotName = h.HotSpotName,
  1352. HotspotId = h.Id,
  1353. TotalSumCount = SqlFunc.AggregateCount(x.OrderVisit.Order.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2"))),
  1354. VerySatisfiedCount = SqlFunc.IIF(dto.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))),//非常满意数
  1355. SatisfiedCount = SqlFunc.IIF(dto.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))), //满意数
  1356. RegardedAsSatisfiedCount = SqlFunc.IIF(dto.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))),//视为满意
  1357. DefaultSatisfiedCount = SqlFunc.IIF(dto.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))),//默认满意
  1358. NoSatisfiedCount = SqlFunc.IIF(dto.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))),//不满意
  1359. NoEvaluateCount = SqlFunc.IIF(dto.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))),//未做评价
  1360. NoPutThroughCount = SqlFunc.IIF(dto.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))),//未接通
  1361. })
  1362. .ToListAsync();
  1363. }
  1364. return data;
  1365. }
  1366. /// <summary>
  1367. /// 热点满意度明细统计
  1368. /// </summary>
  1369. /// <param name="dto"></param>
  1370. /// <returns></returns>
  1371. public ISugarQueryable<OrderVisitDetail> VisitAndHotspotSatisfactionDetail(VisitAndHotspotPagedKeywordRequest dto)
  1372. {
  1373. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1374. bool IsCenter = _sessionContext.OrgIsCenter;
  1375. var key = string.Empty;
  1376. if (!string.IsNullOrEmpty(dto.TitleCode))
  1377. {
  1378. switch (dto.TitleCode)
  1379. {
  1380. case "verySatisfiedCount":
  1381. key = "5";
  1382. break;
  1383. case "satisfiedCount":
  1384. key = "4";
  1385. break;
  1386. case "regardedAsSatisfiedCount":
  1387. key = "-1";
  1388. break;
  1389. case "defaultSatisfiedCount":
  1390. key = "0";
  1391. break;
  1392. case "noSatisfiedCount":
  1393. key = "2";
  1394. break;
  1395. case "noEvaluateCount":
  1396. key = "7";
  1397. break;
  1398. case "noPutThroughCount":
  1399. key = "6";
  1400. break;
  1401. }
  1402. }
  1403. return _orderVisitDetailRepository.Queryable()
  1404. .Includes(x => x.OrderVisit, o => o.Order)
  1405. .Where(x => x.OrderVisit.VisitTime >= dto.StartTime && x.OrderVisit.VisitTime <= dto.EndTime && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited)
  1406. .WhereIF(!string.IsNullOrEmpty(dto.HotspotName), x => x.OrderVisit.Order.Hotspot.HotSpotFullName.StartsWith(dto.HotspotName))
  1407. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  1408. .WhereIF(dto.TypeId is 1, x => SqlFunc.JsonField(x.OrgProcessingResults, "Key") == key)
  1409. .WhereIF(dto.TypeId is 2, x => SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == key);
  1410. }
  1411. /// <summary>
  1412. /// 话务员办件统计
  1413. /// </summary>
  1414. /// <param name="dto"></param>
  1415. /// <returns></returns>
  1416. public ISugarQueryable<OrderBiCentreDataListVo> CentreDataList(ReportPagedRequest dto)
  1417. {
  1418. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  1419. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1420. var query = _orderRepository.Queryable(false, false, false)
  1421. .WhereIF(dto.StartTime.HasValue, it => it.CreationTime >= dto.StartTime)
  1422. .WhereIF(dto.EndTime.HasValue, it => it.CreationTime <= dto.EndTime)
  1423. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), it => it.SignerName.Contains(dto.Keyword!))
  1424. .GroupBy(it => new { it.SignerId, it.SignerName })
  1425. .Select(it => new OrderBiCentreDataListVo
  1426. {
  1427. UserName = it.SignerName,
  1428. UserId = it.SignerId,
  1429. //Subtotal = SqlFunc.AggregateCount(x.AcceptorId),
  1430. CentreArchive = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ProcessType == EProcessType.Zhiban && it.AcceptType != "无效", 1, 0)), //中心归档件
  1431. //CentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && (it.FileUserRole == EFileUserType.Org || it.FileUserRole == EFileUserType.Dispatch), 1, 0)), //转办信件
  1432. CentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptType != "无效" && (it.ProcessType == EProcessType.Jiaoban || (it.ActualHandleStepName == "派单组" && it.Status < EOrderStatus.Filed) || (it.ActualHandleStepName == "班长审批" && it.Status < EOrderStatus.Filed)), 1, 0)),
  1433. NoCentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptType != "无效" && (it.Status <= EOrderStatus.HandOverToUnAccept), 1, 0)), //坐席待办 //中心领导?市领导? 是否在统计条件中
  1434. //CentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ProcessType == EProcessType.Jiaoban, 1, 0)),
  1435. //NoCentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status < 300 && x.ExpiredTime > x.FiledTime, 1, 0)),
  1436. Invalid = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptType == "无效", 1, 0)),
  1437. Repeat = SqlFunc.AggregateSum(SqlFunc.IIF(it.DuplicateIds != null && SqlFunc.JsonArrayLength(it.DuplicateIds) > 0, 1, 0)),
  1438. Subtotal = SqlFunc.AggregateSum(SqlFunc.IIF((it.Status >= EOrderStatus.Filed && it.ProcessType == EProcessType.Zhiban && it.AcceptType != "无效") || (it.AcceptType != "无效" && (it.ProcessType == EProcessType.Jiaoban || (it.ActualHandleStepName == "派单组" && it.Status < EOrderStatus.Filed) || (it.ActualHandleStepName == "班长审批" && it.Status < EOrderStatus.Filed))) || (it.Status <= EOrderStatus.HandOverToUnAccept) || it.AcceptType == "无效" || (it.DuplicateIds != null && SqlFunc.JsonArrayLength(it.DuplicateIds) > 0), 1, 0))
  1439. }).MergeTable();
  1440. switch (dto.SortField)
  1441. {
  1442. case "centreArchive":
  1443. query = dto.SortRule is 0 ? query.OrderBy(x => x.CentreArchive) : query.OrderByDescending(x => x.CentreArchive);
  1444. break;
  1445. case "centreCareOf":
  1446. query = dto.SortRule is 0 ? query.OrderBy(x => x.CentreCareOf) : query.OrderByDescending(x => x.CentreCareOf);
  1447. break;
  1448. case "noCentreCareOf":
  1449. query = dto.SortRule is 0 ? query.OrderBy(x => x.NoCentreCareOf) : query.OrderByDescending(x => x.NoCentreCareOf);
  1450. break;
  1451. case "invalid":
  1452. query = dto.SortRule is 0 ? query.OrderBy(x => x.Invalid) : query.OrderByDescending(x => x.Invalid);
  1453. break;
  1454. case "repeat":
  1455. query = dto.SortRule is 0 ? query.OrderBy(x => x.Repeat) : query.OrderByDescending(x => x.Repeat);
  1456. break;
  1457. case "subtotal":
  1458. query = dto.SortRule is 0 ? query.OrderBy(x => x.Subtotal) : query.OrderByDescending(x => x.Subtotal);
  1459. break;
  1460. }
  1461. if (string.IsNullOrEmpty(dto.SortField))
  1462. {
  1463. query = query.OrderByDescending(x => x.Subtotal);
  1464. }
  1465. return query;
  1466. }
  1467. /// <summary>
  1468. /// 热点受理类型统计
  1469. /// </summary>
  1470. /// <param name="dto"></param>
  1471. /// <returns></returns>
  1472. public async Task<(List<SystemDicData> acceptTypes, object items)> HotspotAndAcceptTypeStatistics(HotspotAndAcceptTypeStatisticsReq dto)
  1473. {
  1474. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  1475. var dicList = _systemDicDataRepository.Queryable().Where(x => x.DicTypeCode == "AcceptType").OrderBy(x => x.Sort).MergeTable();
  1476. var endIndex = (2 * dto.HotspotLevel).ToString();
  1477. var hotspotList = _hotspotRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == int.Parse(endIndex))
  1478. .Select(x => new
  1479. {
  1480. HotspotId = x.Id,
  1481. HotspotName = x.HotSpotFullName,
  1482. }).MergeTable();
  1483. var orderList = _orderRepository.Queryable().Where(x => x.CreationTime >= dto.StartTime && x.CreationTime < dto.EndTime)
  1484. .Select(x => new
  1485. {
  1486. HotspotId = x.HotspotId.Substring(0, int.Parse(endIndex)),
  1487. AcceptTypeCode = x.AcceptTypeCode,
  1488. }).MergeTable();
  1489. var hotListAndOrder = hotspotList.LeftJoin(orderList, (it, o) => it.HotspotId == o.HotspotId)
  1490. .GroupBy((it, o) => new
  1491. {
  1492. it.HotspotId,
  1493. it.HotspotName,
  1494. AcceptTypeCode = o.AcceptTypeCode,
  1495. })
  1496. .OrderBy((it, o) => it.HotspotId)
  1497. .Select((it, o) => new
  1498. {
  1499. HotspotId = it.HotspotId,
  1500. HotspotName = it.HotspotName,
  1501. AcceptTypeCode = o.AcceptTypeCode,
  1502. Count = SqlFunc.AggregateCount(it.HotspotId)
  1503. }).MergeTable();
  1504. var returnList = await dicList.LeftJoin(hotListAndOrder, (pp, dd) => pp.DicDataValue == dd.AcceptTypeCode)
  1505. .GroupBy((pp, dd) => new
  1506. {
  1507. HotspotId = dd.HotspotId,
  1508. HotspotName = dd.HotspotName,
  1509. AcceptTypeCode = pp.DicDataValue,
  1510. AcceptType = pp.DicDataName,
  1511. })
  1512. .OrderBy((pp, dd) => dd.HotspotId)
  1513. .Select((pp, dd) => new
  1514. {
  1515. HotspotId = dd.HotspotId,
  1516. HotspotName = dd.HotspotName,
  1517. AcceptTypeCode = pp.DicDataValue,
  1518. AcceptType = pp.DicDataName,
  1519. Count = SqlFunc.AggregateSum(dd.Count)
  1520. }).ToPivotListAsync(q => q.AcceptTypeCode, q => new { q.HotspotName, q.HotspotId }, q => q.Sum(x => x.Count));
  1521. var titleList = await _systemDicDataRepository.Queryable().Where(x => x.DicTypeCode == "AcceptType").OrderBy(x => x.Sort).ToListAsync();
  1522. return (titleList, returnList);
  1523. }
  1524. /// <summary>
  1525. /// 热点受理类型统计--导出
  1526. /// </summary>
  1527. /// <param name="dto"></param>
  1528. /// <returns></returns>
  1529. public async Task<DataTable> HotspotAndAcceptTypeStatisticsExport(HotspotAndAcceptTypeStatisticsReq dto)
  1530. {
  1531. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  1532. var dicList = _systemDicDataRepository.Queryable().Where(x => x.DicTypeCode == "AcceptType").OrderBy(x => x.Sort).MergeTable();
  1533. var endIndex = (2 * dto.HotspotLevel).ToString();
  1534. var hotspotList = _hotspotRepository.Queryable().Where(x => SqlFunc.Length(x.Id) == int.Parse(endIndex))
  1535. .Select(x => new
  1536. {
  1537. HotspotId = x.Id,
  1538. HotspotName = x.HotSpotFullName,
  1539. }).MergeTable();
  1540. var orderList = _orderRepository.Queryable().Where(x => x.CreationTime >= dto.StartTime && x.CreationTime < dto.EndTime)
  1541. .Select(x => new
  1542. {
  1543. HotspotId = x.HotspotId.Substring(0, int.Parse(endIndex)),
  1544. AcceptTypeCode = x.AcceptTypeCode,
  1545. }).MergeTable();
  1546. var hotListAndOrder = hotspotList.LeftJoin(orderList, (it, o) => it.HotspotId == o.HotspotId)
  1547. .GroupBy((it, o) => new
  1548. {
  1549. it.HotspotId,
  1550. it.HotspotName,
  1551. AcceptTypeCode = o.AcceptTypeCode,
  1552. })
  1553. .OrderBy((it, o) => it.HotspotId)
  1554. .Select((it, o) => new
  1555. {
  1556. HotspotId = it.HotspotId,
  1557. HotspotName = it.HotspotName,
  1558. AcceptTypeCode = o.AcceptTypeCode,
  1559. Count = SqlFunc.AggregateCount(it.HotspotId)
  1560. }).MergeTable();
  1561. var returnList = await dicList.LeftJoin(hotListAndOrder, (pp, dd) => pp.DicDataValue == dd.AcceptTypeCode)
  1562. .GroupBy((pp, dd) => new
  1563. {
  1564. HotspotId = dd.HotspotId,
  1565. HotspotName = dd.HotspotName,
  1566. AcceptTypeCode = pp.DicDataValue,
  1567. AcceptType = pp.DicDataName,
  1568. })
  1569. .OrderBy((pp, dd) => dd.HotspotId)
  1570. .Select((pp, dd) => new
  1571. {
  1572. HotspotId = dd.HotspotId,
  1573. HotspotName = dd.HotspotName,
  1574. AcceptTypeCode = pp.DicDataValue,
  1575. AcceptType = pp.DicDataName,
  1576. Count = SqlFunc.AggregateSum(dd.Count)
  1577. }).ToPivotTableAsync(q => q.AcceptTypeCode, q => new { q.HotspotName }, q => q.Sum(x => x.Count));
  1578. //returnList.Rows.RemoveAt(returnList.Rows.Count-1);
  1579. return returnList;
  1580. }
  1581. /// <summary>
  1582. /// 热点受理类型统计明细
  1583. /// </summary>
  1584. /// <param name="dto"></param>
  1585. /// <returns></returns>
  1586. public ISugarQueryable<Order> HotspotAndAcceptTypeStatisticsDetail(HotspotAndAcceptTypeStatisticsDetailReq dto)
  1587. {
  1588. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  1589. var query = _orderRepository.Queryable()
  1590. .Where(x => x.HotspotId.StartsWith(dto.HotspotId) && x.CreationTime >= dto.StartTime && x.CreationTime < dto.EndTime)
  1591. .WhereIF(!string.IsNullOrEmpty(dto.AcceptTypeCode), x => x.AcceptTypeCode.StartsWith(dto.AcceptTypeCode))
  1592. .OrderByDescending(x => x.CreationTime);
  1593. return query;
  1594. }
  1595. /// <summary>
  1596. /// 甄别申请统计
  1597. /// </summary>
  1598. /// <returns></returns>
  1599. public ISugarQueryable<OrderScreenApplyVo> OrderScreenApply(OrderScreenApplyPagedRequest dto)
  1600. {
  1601. if (dto.EndTime.HasValue)
  1602. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1603. var query = _orderScreenRepository.Queryable()
  1604. .WhereIF(dto.StartTime.HasValue && dto.EndTime.HasValue, x => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
  1605. .WhereIF(!string.IsNullOrEmpty(dto.ApplyUserName),x=> x.CreatorName == dto.ApplyUserName)
  1606. .WhereIF(!string.IsNullOrEmpty(dto.ApplyOrgName), x => x.CreatorOrgName == dto.ApplyOrgName)
  1607. .GroupBy(x => new { ApplyTime = x.CreationTime.ToString("yyyy-MM-dd"), x.CreatorName, x.CreatorOrgName })
  1608. .Select(x => new OrderScreenApplyVo
  1609. {
  1610. ApplyTime = x.CreationTime.ToString("yyyy-MM-dd"),
  1611. ApplyUserName = x.CreatorName,
  1612. ApplyOrgName = x.CreatorOrgName,
  1613. ApplyNum = SqlFunc.AggregateCount(1)
  1614. });
  1615. return query;
  1616. }
  1617. /// <summary>
  1618. /// 甄别审批统计
  1619. /// </summary>
  1620. /// <returns></returns>
  1621. public ISugarQueryable<OrderScreenAuditVo> OrderScreenAudit(OrderScreenAuditPagedRequest dto)
  1622. {
  1623. if (dto.EndTime.HasValue)
  1624. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1625. var query = _workflowTraceRepository.Queryable()
  1626. .WhereIF(dto.StartTime.HasValue && dto.EndTime.HasValue, x => x.HandleTime >= dto.StartTime && x.HandleTime <= dto.EndTime)
  1627. .WhereIF(!string.IsNullOrEmpty(dto.AuditUserName), x => x.HandlerName == dto.AuditUserName)
  1628. .Where(x=> x.HandlerName != null && x.HandlerName != "" && x.Status == EWorkflowStepStatus.Handled)
  1629. .WhereIF(dto.AuditType is 1,x=>x.Name == "班长审批")
  1630. .WhereIF(dto.AuditType is 2, x => x.Name == "中心领导")
  1631. .GroupBy(x => new { x.HandlerName })
  1632. .Select(x => new OrderScreenAuditVo
  1633. {
  1634. AuditName = x.HandlerName,
  1635. AuditNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.TraceState == EWorkflowTraceState.Normal, 1, 0)),
  1636. AuditBackNum = SqlFunc.AggregateSum(SqlFunc.IIF( x.TraceState != EWorkflowTraceState.Normal, 1, 0)),
  1637. });
  1638. return query;
  1639. }
  1640. /// <summary>
  1641. /// 中心受理统计(日期)
  1642. /// </summary>
  1643. /// <param name="dto"></param>
  1644. /// <returns></returns>
  1645. public ISugarQueryable<OrderCenterAcceptVo> OrderCenterAccept(OrderCenterAcceptPagedRequest dto)
  1646. {
  1647. if (dto.EndTime.HasValue)
  1648. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1649. var sendBack = _orderSendBackAuditRepository.Queryable()
  1650. .Where(x => x.State == ESendBackAuditState.End)
  1651. .GroupBy(x => x.OrderId).Select(x => new { OrderId = x.OrderId } );
  1652. var query = _orderRepository.Queryable()
  1653. .LeftJoin(sendBack,(d,s)=> d.Id == s.OrderId)
  1654. .WhereIF(dto.StartTime.HasValue && dto.EndTime.HasValue, d => d.CreationTime >= dto.StartTime && d.CreationTime <= dto.EndTime)
  1655. .WhereIF(dto.TypeCode != null && dto.TypeCode == 1, d => d.IdentityType == EIdentityType.Citizen)
  1656. .WhereIF(dto.TypeCode != null && dto.TypeCode == 2, d => d.IdentityType == EIdentityType.Enterprise)
  1657. .GroupBy(d => d.CreationTime.ToString("yyyy-MM-dd"))
  1658. .Select((d,s) => new OrderCenterAcceptVo
  1659. {
  1660. Time = d.CreationTime.ToString("yyyy-MM-dd"),
  1661. AcceptNum = SqlFunc.AggregateCount(1),
  1662. ValidNum = SqlFunc.AggregateSum(SqlFunc.IIF( d.AcceptType != "无效" , 1, 0)),
  1663. RepetitionNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.DuplicateIds == null || SqlFunc.JsonArrayLength(d.DuplicateIds) > 0, 1, 0)),
  1664. InvalidNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.AcceptType == "无效", 1, 0)),
  1665. HandleNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status >= EOrderStatus.Filed, 1, 0)),
  1666. NoHandleNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status < EOrderStatus.Filed, 1, 0)),
  1667. BackNum = SqlFunc.AggregateSum(SqlFunc.IIF(!string.IsNullOrEmpty(s.OrderId), 1, 0)),
  1668. DutyDeskNum = SqlFunc.AggregateDistinctCount(d.AcceptorId)
  1669. });
  1670. return query;
  1671. }
  1672. /// <summary>
  1673. /// 中心受理统计(值班坐席)
  1674. /// </summary>
  1675. /// <returns></returns>
  1676. public ISugarQueryable<OrderCenterAcceptUserVo> OrderCenterAcceptUser(OrderCenterAcceptPagedRequest dto)
  1677. {
  1678. if (dto.EndTime.HasValue)
  1679. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  1680. var sendBack = _orderSendBackAuditRepository.Queryable()
  1681. .Where(x => x.State == ESendBackAuditState.End)
  1682. .GroupBy(x => x.OrderId).Select(x => new { OrderId = x.OrderId });
  1683. var query = _orderRepository.Queryable()
  1684. .LeftJoin(sendBack, (d, s) => d.Id == s.OrderId)
  1685. .WhereIF(dto.StartTime.HasValue && dto.EndTime.HasValue, d => d.CreationTime >= dto.StartTime && d.CreationTime <= dto.EndTime)
  1686. .WhereIF(dto.TypeCode != null && dto.TypeCode == 1, d => d.IdentityType == EIdentityType.Citizen)
  1687. .WhereIF(dto.TypeCode != null && dto.TypeCode == 2, d => d.IdentityType == EIdentityType.Enterprise)
  1688. .GroupBy(d => d.AcceptorName)
  1689. .Select((d, s) => new OrderCenterAcceptUserVo
  1690. {
  1691. AcceptUserName = d.AcceptorName,
  1692. AcceptNum = SqlFunc.AggregateCount(1),
  1693. ValidNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.AcceptType != "无效", 1, 0)),
  1694. RepetitionNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.DuplicateIds == null || SqlFunc.JsonArrayLength(d.DuplicateIds) > 0, 1, 0)),
  1695. InvalidNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.AcceptType == "无效", 1, 0)),
  1696. HandleNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status >= EOrderStatus.Filed, 1, 0)),
  1697. NoHandleNum = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status < EOrderStatus.Filed, 1, 0)),
  1698. BackNum = SqlFunc.AggregateSum(SqlFunc.IIF(!string.IsNullOrEmpty(s.OrderId), 1, 0))
  1699. });
  1700. return query;
  1701. }
  1702. #region private
  1703. /// <summary>
  1704. /// 接受外部工单(除省平台)
  1705. /// </summary>
  1706. /// <param name="dto"></param>
  1707. /// <param name="cancellationToken"></param>
  1708. /// <returns></returns>
  1709. private async Task<AddOrderResponse> ReceiveOrderFromOtherPlatformAsync(AddOrderDto dto, List<FileDto> files,
  1710. ISessionContext current, CancellationToken cancellationToken)
  1711. {
  1712. if (string.IsNullOrEmpty(dto.ExternalId))
  1713. throw new UserFriendlyException("工单外部编号不能为空");
  1714. var order = await _orderRepository.Queryable()
  1715. .FirstAsync(d => d.ExternalId == dto.ExternalId, cancellationToken);
  1716. if (order == null)
  1717. {
  1718. order = _mapper.Map<Order>(dto);
  1719. order.InitId();
  1720. if (files != null && files.Any())
  1721. order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
  1722. await _orderDomainService.AddAsync(order, cancellationToken: cancellationToken);
  1723. }
  1724. else
  1725. {
  1726. _mapper.Map(dto, order);
  1727. if (files != null && files.Any())
  1728. order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
  1729. else
  1730. order.FileJson = new List<Share.Dtos.File.FileJson>();
  1731. await _orderRepository.UpdateAsync(order, cancellationToken);
  1732. }
  1733. return _mapper.Map<AddOrderResponse>(order);
  1734. }
  1735. /// <summary>
  1736. /// 接受省平台工单
  1737. /// </summary>
  1738. private async Task<AddOrderResponse> ReceiveOrderFromProvinceAsync(AddOrderDto dto, List<FileDto> files,
  1739. ISessionContext current, CancellationToken cancellationToken)
  1740. {
  1741. if (string.IsNullOrEmpty(dto.ProvinceNo))
  1742. throw new UserFriendlyException("无效省工单编号");
  1743. var orderExtension = await _orderDomainService.GetOrderExtensionsAsync(dto.ProvinceNo, cancellationToken);
  1744. var order = await _orderRepository.GetAsync(d => d.ProvinceNo == dto.ProvinceNo, cancellationToken);
  1745. if (order is null)
  1746. {
  1747. order = _mapper.Map<Order>(dto);
  1748. order.InitId();
  1749. if (files != null && files.Any())
  1750. order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
  1751. await _orderDomainService.AddAsync(order, cancellationToken: cancellationToken);
  1752. if (orderExtension is not null)
  1753. {
  1754. orderExtension.Id = order.Id;
  1755. if (dto.OrderExtension != null)
  1756. _mapper.Map(dto.OrderExtension, orderExtension);
  1757. await _orderDomainService.UpdateExtensionAsync(orderExtension, cancellationToken);
  1758. }
  1759. }
  1760. else
  1761. {
  1762. _mapper.Map(dto, order);
  1763. if (files != null && files.Any())
  1764. order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
  1765. else
  1766. order.FileJson = new List<Share.Dtos.File.FileJson>();
  1767. order.ReTransactNum++;
  1768. await _orderRepository.UpdateAsync(order, cancellationToken);
  1769. if (orderExtension is not null)
  1770. {
  1771. orderExtension.Id = order.Id;
  1772. if (dto.OrderExtension != null)
  1773. _mapper.Map(dto.OrderExtension, orderExtension);
  1774. await _orderDomainService.UpdateExtensionAsync(orderExtension, cancellationToken);
  1775. }
  1776. //特提(撤回至发起)
  1777. if (!string.IsNullOrEmpty(order.WorkflowId))
  1778. {
  1779. current = SessionContextCreator.CreateSessionContext("province");
  1780. await _workflowDomainService.RecallToStartStepAsync(order.WorkflowId, "省工单重派", current, cancellationToken);
  1781. }
  1782. }
  1783. return _mapper.Map<AddOrderResponse>(order);
  1784. }
  1785. /// <summary>
  1786. /// 派单量统计
  1787. /// </summary>
  1788. /// <param name="dto"></param>
  1789. /// <returns></returns>
  1790. public async Task<List<SendOrderReportOutDto>> SendOrderReportAsync(QuerySendOrderRequest dto)
  1791. {
  1792. var items = await _workflowTraceRepository.Queryable()
  1793. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  1794. //.LeftJoin<WorkflowStepHandler>((x, w, wsh) => x.StepId == wsh.WorkflowStepId && wsh.IsActualHandler == true)
  1795. .InnerJoin<SchedulingUser>((x, w, su) => x.HandlerId == su.UserId)
  1796. .Where((x, w, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send && x.Status == EWorkflowStepStatus.Handled)
  1797. .Where((x, w, su) => x.CreationTime >= dto.StartTime.Value)
  1798. .Where((x, w, su) => x.CreationTime <= dto.EndTime.Value)
  1799. .WhereIF(!string.IsNullOrEmpty(dto.UserName), (x, w, su) => su.UserName == dto.UserName)
  1800. .GroupBy((x, w, su) => new { su.UserId, su.UserName })
  1801. //.Having((x, w, wsh, su) => SqlFunc.AggregateCount(x.WorkflowId) == 1)
  1802. .Select((x, w, su) => new BiOrderSendVo
  1803. {
  1804. UserId = su.UserId,
  1805. UserName = su.UserName,
  1806. SendOrderNum = SqlFunc.AggregateDistinctCount(w.ExternalId),
  1807. NoSendOrderNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.HandlerId == null || x.HandlerId == "", 1, 0)),
  1808. }).ToListAsync();
  1809. var items2 = await _workflowTraceRepository.Queryable()
  1810. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  1811. //.LeftJoin<WorkflowStepHandler>((x, w, wfsh) => x.StepId == wfsh.WorkflowStepId && wfsh.IsActualHandler == true)
  1812. .InnerJoin<SchedulingUser>((x, w, su) => x.HandlerId == su.UserId)
  1813. .Where((x, w, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send && x.Status == EWorkflowStepStatus.Handled)
  1814. .Where((x, w, su) => x.CreationTime >= dto.StartTime.Value)
  1815. .Where((x, w, su) => x.CreationTime <= dto.EndTime.Value)
  1816. .GroupBy((x, w, su) => x.WorkflowId)
  1817. .Having((x, w, su) => SqlFunc.AggregateCount(x.WorkflowId) > 1)
  1818. .Select((x, w, su) => new { Id = x.WorkflowId, CreationTime = SqlFunc.AggregateMin(x.CreationTime) })
  1819. .MergeTable()
  1820. .LeftJoin<WorkflowTrace>((a, wt) => a.Id == wt.WorkflowId)
  1821. .LeftJoin<Workflow>((a, wt, wf) => wt.WorkflowId == wf.Id)
  1822. //.LeftJoin<WorkflowStepHandler>((a, wt, wf, wsh) => wt.StepId == wsh.WorkflowStepId && wsh.CreationTime == a.CreationTime)
  1823. .InnerJoin<SchedulingUser>((a, wt, wf, su) => wt.HandlerId == su.UserId)
  1824. .WhereIF(!string.IsNullOrEmpty(dto.UserName), ((a, wt, wf, su) => su.UserName == dto.UserName))
  1825. .GroupBy((a, wt, wf, su) => new { su.UserId, su.UserName })
  1826. .Select((a, wt, wf, su) => new BiOrderSendVo
  1827. {
  1828. UserId = su.UserId,
  1829. UserName = su.UserName,
  1830. SendOrderNum = 0,
  1831. NoSendOrderNum = 0,
  1832. ReSendOrderNum = SqlFunc.AggregateDistinctCount(wf.ExternalId),
  1833. }).ToListAsync();
  1834. var res = (from t1 in items
  1835. join t2 in items2 on t1.UserId equals t2.UserId into t1_t2
  1836. from item in t1_t2.DefaultIfEmpty()
  1837. select new SendOrderReportOutDto
  1838. {
  1839. UserId = t1.UserId,
  1840. UserName = t1.UserName,
  1841. SendOrderNum = t1.SendOrderNum,
  1842. NoSendOrderNum = t1.NoSendOrderNum,
  1843. ReSendOrderNum = t1_t2.Select(x => x.ReSendOrderNum).FirstOrDefault(),
  1844. ChainRate = t1_t2.Select(x => x.ReSendOrderNum).FirstOrDefault() > 0 ?
  1845. ((double.Parse(t1.SendOrderNum.ToString()) - double.Parse(t1_t2.Select(x => x.ReSendOrderNum).FirstOrDefault().ToString())) / double.Parse(t1.SendOrderNum.ToString()) * 100).ToString("F2") + "%" : "100.00%",
  1846. }).ToList();
  1847. return res;
  1848. }
  1849. /// <summary>
  1850. /// 扭转信件统计
  1851. /// </summary>
  1852. /// <param name="dto"></param>
  1853. /// <returns></returns>
  1854. public ISugarQueryable<OrderVisitJudeStatisticsRep> OrderVisitJudeStatistics(OrderVisitJudeStatisticsReq dto)
  1855. {
  1856. if (!dto.EndTime.HasValue)
  1857. {
  1858. dto.EndTime = dto.StartTime?.AddDays(1).AddSeconds(-1);
  1859. }
  1860. return _orderVisitRepository.Queryable()
  1861. .WhereIF(dto.StartTime.HasValue, x => x.VisitTime >= dto.StartTime)
  1862. .WhereIF(dto.EndTime.HasValue, x => x.VisitTime <= dto.EndTime)
  1863. .GroupBy(x => new { EmployeeId = x.EmployeeId, Name = x.Employee.Name })
  1864. .Select(x => new OrderVisitJudeStatisticsRep()
  1865. {
  1866. EmpId = x.EmployeeId,
  1867. EmpName = x.Employee.Name,
  1868. OrgJudeCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.OrgJudge.HasValue, 1, 0)), //部门扭转总件
  1869. OrgJudeApprovalingCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.OrgJudge.HasValue && x.JudgeState == EJudgeState.Judging, 1, 0)),
  1870. OrgJudeSuccessCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.OrgJudge.HasValue && x.JudgeState == EJudgeState.Agreed, 1, 0)),
  1871. OrgJudeFailCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.OrgJudge.HasValue && x.JudgeState == EJudgeState.UnAgreed, 1, 0)),
  1872. SeatJudeCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.SeatJudge.HasValue, 1, 0)),
  1873. SeatJudeApprovalingCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.SeatJudge.HasValue && x.JudgeState == EJudgeState.Judging, 1, 0)),
  1874. SeatJudeSuccessCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.SeatJudge.HasValue && x.JudgeState == EJudgeState.Agreed, 1, 0)),
  1875. SeatJudeFailCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.SeatJudge.HasValue && x.JudgeState == EJudgeState.UnAgreed, 1, 0))
  1876. });
  1877. }
  1878. #endregion
  1879. }