OrderApplication.cs 113 KB

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