OrderApplication.cs 129 KB

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