OrderApplication.cs 118 KB

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