BiOrderController.cs 157 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.FlowEngine.WorkflowModules;
  4. using Hotline.FlowEngine.Workflows;
  5. using Hotline.Orders;
  6. using Hotline.Repository.SqlSugar.Extensions;
  7. using Hotline.Schedulings;
  8. using Hotline.Settings;
  9. using Hotline.Settings.Hotspots;
  10. using Hotline.Share.Dtos;
  11. using Hotline.Share.Dtos.Bi;
  12. using Hotline.Share.Dtos.Bigscreen;
  13. using Hotline.Share.Dtos.CallCenter;
  14. using Hotline.Share.Dtos.FlowEngine.Workflow;
  15. using Hotline.Share.Dtos.Order;
  16. using Hotline.Share.Enums.CallCenter;
  17. using Hotline.Share.Enums.FlowEngine;
  18. using Hotline.Share.Enums.Order;
  19. using Hotline.Share.Requests;
  20. using MapsterMapper;
  21. using Microsoft.AspNetCore.Mvc;
  22. using SqlSugar;
  23. using XF.Domain.Authentications;
  24. using XF.Domain.Constants;
  25. using XF.Domain.Exceptions;
  26. using XF.Domain.Repository;
  27. namespace Hotline.Api.Controllers.Bi
  28. {
  29. public class BiOrderController : BaseController
  30. {
  31. private readonly IOrderRepository _orderRepository;
  32. private readonly IRepository<Hotspot> _hotspotTypeRepository;
  33. private readonly ISystemDicDataCacheManager _sysDicDataCacheManager;
  34. private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
  35. private readonly IRepository<OrderDelay> _orderDelayRepository;
  36. private readonly IMapper _mapper;
  37. private readonly IRepository<WorkflowCountersign> _workflowCountersignRepository;
  38. private readonly IRepository<WorkflowStepHandler> _workflowStepHandleRepository;
  39. private readonly IRepository<OrderSpecial> _orderSpecialRepository;
  40. private readonly IRepository<OrderVisit> _orderVisitRepository;
  41. private readonly IRepository<TrCallRecord> _trCallRecordRepository;
  42. private readonly IRepository<OrderPublish> _orderPublishRepository;
  43. private readonly IRepository<SystemOrganize> _systemOrganizeRepository;
  44. private readonly IRepository<AiOrderVisitDetail> _aiOrderVisitDetailRepository;
  45. private readonly ISessionContext _sessionContext;
  46. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  47. private readonly IRepository<OrderSpecialDetail> _orderSpecialDetailRepository;
  48. private readonly IRepository<WorkflowTrace> _workflowTraceRepository;
  49. private readonly IRepository<OrderScreen> _orderScreenRepository;
  50. public BiOrderController(
  51. IOrderRepository orderRepository,
  52. IRepository<Hotspot> hotspotTypeRepository,
  53. ISystemDicDataCacheManager sysDicDataCacheManager,
  54. IRepository<OrderVisitDetail> orderVisitDetailRepository,
  55. IRepository<OrderDelay> orderDelayRepository,
  56. IRepository<WorkflowCountersign> workflowCountersignRepository,
  57. IRepository<OrderSpecial> orderSpecialRepository,
  58. IMapper mapper,
  59. IRepository<OrderVisit> orderVisitRepository,
  60. IRepository<TrCallRecord> trCallRecordRepository,
  61. IRepository<OrderPublish> orderPublishRepository,
  62. IRepository<SystemOrganize> systemOrganizeRepository,
  63. IRepository<AiOrderVisitDetail> aiOrderVisitDetailRepository,
  64. ISessionContext sessionContext,
  65. ISystemSettingCacheManager systemSettingCacheManager,
  66. IRepository<OrderSpecialDetail> orderSpecialDetailRepository,
  67. IRepository<WorkflowTrace> workflowTraceRepository,
  68. IRepository<OrderScreen> orderScreenRepository,
  69. IRepository<WorkflowStepHandler> workflowStepHandleRepository
  70. )
  71. {
  72. _orderRepository = orderRepository;
  73. _hotspotTypeRepository = hotspotTypeRepository;
  74. _sysDicDataCacheManager = sysDicDataCacheManager;
  75. _orderVisitDetailRepository = orderVisitDetailRepository;
  76. _orderDelayRepository = orderDelayRepository;
  77. _workflowCountersignRepository = workflowCountersignRepository;
  78. _orderSpecialRepository = orderSpecialRepository;
  79. _mapper = mapper;
  80. _orderVisitRepository = orderVisitRepository;
  81. _trCallRecordRepository = trCallRecordRepository;
  82. _orderPublishRepository = orderPublishRepository;
  83. _systemOrganizeRepository = systemOrganizeRepository;
  84. _aiOrderVisitDetailRepository = aiOrderVisitDetailRepository;
  85. _sessionContext = sessionContext;
  86. _systemSettingCacheManager = systemSettingCacheManager;
  87. _orderSpecialDetailRepository = orderSpecialDetailRepository;
  88. _workflowTraceRepository = workflowTraceRepository;
  89. _orderScreenRepository = orderScreenRepository;
  90. _workflowStepHandleRepository = workflowStepHandleRepository;
  91. }
  92. /// <summary>
  93. /// 部门超期统计明细
  94. /// </summary>
  95. /// <param name="dto"></param>
  96. /// <returns></returns>
  97. [HttpGet("org_data_list_detail")]
  98. public async Task<PagedDto<OrderDto>> OrgDataListDetail([FromQuery] OrgDataListDetailRequest dto)
  99. {
  100. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  101. var (total, items) = await _orderRepository.Queryable()
  102. .Where(x => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
  103. .WhereIF(dto.QueryType == 1, x => x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) //业务已办超期
  104. //.WhereIF(dto.QueryType== 2,) //会签已办超期
  105. .WhereIF(dto.QueryType == 3, x => x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()) //业务待办超期
  106. .WhereIF(string.IsNullOrEmpty(dto.OrgCode), x => x.ActualHandleOrgCode == dto.OrgCode)
  107. //.WhereIF(dto.QueryType ==4,) //会签待办超期
  108. //.MergeTable();
  109. .ToPagedListAsync(dto.PageIndex, dto.PageSize);
  110. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  111. }
  112. /// <summary>
  113. /// 部门超期统计
  114. /// </summary>
  115. /// <param name="dto"></param>
  116. /// <returns></returns>
  117. [HttpGet("org_data_list")]
  118. public async Task<PagedDto<OrderBiOrgDataListVo>> OrgDataList([FromQuery] ReportPagedRequest dto)
  119. {
  120. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  121. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  122. var IsCenter = _sessionContext.OrgIsCenter;
  123. var queryOrder = _systemOrganizeRepository.Queryable()
  124. .LeftJoin<Order>((x, o) => x.Id == o.ActualHandleOrgCode)
  125. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= dto.StartTime)
  126. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= dto.EndTime)
  127. .WhereIF(IsCenter == false, (x, o) => o.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  128. .GroupBy((x, o) => new { x.Id, x.Name })
  129. .Select((x, o) => new OrderBiOrgDataListVo
  130. {
  131. OrgName = x.Name,
  132. OrgId = x.Id,
  133. HandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.Status >= EOrderStatus.Filed && o.ExpiredTime < o.FiledTime, 1, 0)),
  134. NoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.Status < EOrderStatus.Filed && o.ExpiredTime < SqlFunc.GetDate(), 1, 0)),
  135. }).MergeTable();
  136. //var queryOrder = _orderRepository.Queryable(false, false, false)
  137. // .LeftJoin<SystemOrganize>((x, o) => x.ActualHandleOrgCode == o.Id)
  138. // .WhereIF(dto.StartTime.HasValue, (x, o) => x.CreationTime >= dto.StartTime)
  139. // .WhereIF(dto.EndTime.HasValue, (x, o) => x.CreationTime <= dto.EndTime)
  140. // .WhereIF(IsCenter == false, (x, o) => x.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  141. // .GroupBy((x, o) => new { x.ActualHandleOrgCode, o.Name })
  142. // .Select((x, o) => new OrderBiOrgDataListVo
  143. // {
  144. // OrgName = o.Name,
  145. // OrgId = x.ActualHandleOrgCode,
  146. // HandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime, 1, 0)),
  147. // NoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate(), 1, 0)),
  148. // }).MergeTable();
  149. var queryCountersign = _workflowCountersignRepository.Queryable()
  150. .LeftJoin<WorkflowCountersignMember>((x, o) => x.Id == o.WorkflowCountersignId)
  151. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  152. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  153. .GroupBy((x, o) => o.Key)
  154. .Select((x, o) => new OrderBiOrgDataListVo
  155. {
  156. OrgId = o.Key,
  157. CounterHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled, 1, 0)),
  158. CounterNoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled == false, 1, 0)),
  159. }).MergeTable();
  160. var query = queryOrder.LeftJoin(queryCountersign, (or, co) => or.OrgId == co.OrgId)
  161. .Select((or, co) => new OrderBiOrgDataListVo
  162. {
  163. OrgName = or.OrgName,
  164. OrgId = or.OrgId,
  165. HandlerExtendedNum = or.HandlerExtendedNum,
  166. NoHandlerExtendedNum = or.NoHandlerExtendedNum,
  167. CounterHandlerExtendedNum = co.CounterHandlerExtendedNum,
  168. CounterNoHandlerExtendedNum = co.CounterNoHandlerExtendedNum
  169. }).MergeTable();
  170. query = query.WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.OrgName.Contains(dto.Keyword!));
  171. switch (dto.SortField)
  172. {
  173. case "handlerExtendedNum":
  174. query = dto.SortRule == 0 ? query.OrderBy(x => x.HandlerExtendedNum) : query.OrderByDescending(x => x.HandlerExtendedNum);
  175. break;
  176. case "counterHandlerExtendedNum":
  177. query = dto.SortRule == 0 ? query.OrderBy(x => x.CounterHandlerExtendedNum) : query.OrderByDescending(x => x.CounterHandlerExtendedNum);
  178. break;
  179. case "noHandlerExtendedNum":
  180. query = dto.SortRule == 0 ? query.OrderBy(x => x.NoHandlerExtendedNum) : query.OrderByDescending(x => x.NoHandlerExtendedNum);
  181. break;
  182. case "counterNoHandlerExtendedNum":
  183. query = dto.SortRule == 0 ? query.OrderBy(x => x.CounterNoHandlerExtendedNum) : query.OrderByDescending(x => x.CounterNoHandlerExtendedNum);
  184. break;
  185. }
  186. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  187. return new PagedDto<OrderBiOrgDataListVo>(total, items);
  188. }
  189. /// <summary>
  190. /// 话务员办件统计
  191. /// </summary>
  192. /// <param name="dto"></param>
  193. /// <returns></returns>
  194. [HttpGet("centre_data_list")]
  195. public async Task<PagedDto<OrderBiCentreDataListVo>> CentreDataList([FromQuery] ReportPagedRequest dto)
  196. {
  197. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  198. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  199. var query = _orderRepository.Queryable(false, false, false)
  200. .WhereIF(dto.StartTime.HasValue, it => it.CreationTime >= dto.StartTime)
  201. .WhereIF(dto.EndTime.HasValue, it => it.CreationTime <= dto.EndTime)
  202. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), it => it.SignerName.Contains(dto.Keyword!))
  203. .GroupBy(it => new { it.SignerId, it.SignerName })
  204. .Select(it => new OrderBiCentreDataListVo
  205. {
  206. UserName = it.SignerName,
  207. UserId = it.SignerId,
  208. //Subtotal = SqlFunc.AggregateCount(x.AcceptorId),
  209. CentreArchive = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ProcessType == EProcessType.Zhiban, 1, 0)),
  210. //CentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ProcessType == EProcessType.Jiaoban, 1, 0)),
  211. CentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF((it.Status >= EOrderStatus.Filed && it.ProcessType == EProcessType.Jiaoban),1,0)),
  212. //NoCentreCareOf = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status < 300 && x.ExpiredTime > x.FiledTime, 1, 0)),
  213. Invalid = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptType == "无效", 1, 0)),
  214. Repeat = SqlFunc.AggregateSum(SqlFunc.IIF(it.DuplicateIds != null && SqlFunc.JsonArrayLength(it.DuplicateIds) > 0, 1, 0)),
  215. Subtotal = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed || it.AcceptType == "无效" || (it.DuplicateIds != null && SqlFunc.JsonArrayLength(it.DuplicateIds) > 0), 1, 0))
  216. }).MergeTable();
  217. switch (dto.SortField)
  218. {
  219. case "centreArchive":
  220. query = dto.SortRule == 0 ? query.OrderBy(x => x.CentreArchive) : query.OrderByDescending(x => x.CentreArchive);
  221. break;
  222. case "centreCareOf":
  223. query = dto.SortRule == 0 ? query.OrderBy(x => x.CentreCareOf) : query.OrderByDescending(x => x.CentreCareOf);
  224. break;
  225. case "noCentreCareOf":
  226. query = dto.SortRule == 0 ? query.OrderBy(x => x.NoCentreCareOf) : query.OrderByDescending(x => x.NoCentreCareOf);
  227. break;
  228. case "invalid":
  229. query = dto.SortRule == 0 ? query.OrderBy(x => x.Invalid) : query.OrderByDescending(x => x.Invalid);
  230. break;
  231. case "repeat":
  232. query = dto.SortRule == 0 ? query.OrderBy(x => x.Repeat) : query.OrderByDescending(x => x.Repeat);
  233. break;
  234. case "subtotal":
  235. query = dto.SortRule == 0 ? query.OrderBy(x => x.Subtotal) : query.OrderByDescending(x => x.Subtotal);
  236. break;
  237. }
  238. if (string.IsNullOrEmpty(dto.SortField))
  239. {
  240. query = query.OrderByDescending(x => x.Subtotal);
  241. }
  242. var (total, items) = await query.Where(x => (x.CentreArchive + x.CentreCareOf + x.Invalid + x.Repeat) != 0).ToPagedListAsync(dto, HttpContext.RequestAborted);
  243. return new PagedDto<OrderBiCentreDataListVo>(total, items);
  244. }
  245. /// <summary>
  246. /// 热点数据小计统计
  247. /// </summary>
  248. /// <param name="dto"></param>
  249. /// <returns></returns>
  250. [HttpGet("hotspot_subtotal_data_list")]
  251. public async Task<PagedDto<HotspotDataLsitVo>> HotspotSubtotalDataLsit([FromQuery] HotspotSubtotalReportPagedRequest dto)
  252. {
  253. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  254. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  255. var query = _hotspotTypeRepository.Queryable(false, true)
  256. .LeftJoin<Order>((x, o) => o.HotspotSpliceName != null && (x.HotSpotFullName == o.HotspotSpliceName || o.HotspotSpliceName.Contains(x.HotSpotFullName)) && o.IsDeleted == false)
  257. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= dto.StartTime)
  258. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= dto.EndTime)
  259. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => x.HotSpotName.Contains(dto.Keyword!))
  260. .Where((x, o) => x.ParentId == dto.Id)
  261. .Where((x, o) => x.IsDeleted == false)
  262. .GroupBy((x, o) => new { x.Id, x.HotSpotName })
  263. .Select((x, o) => new HotspotDataLsitVo
  264. {
  265. Id = x.Id,
  266. Name = x.HotSpotName,
  267. Num = SqlFunc.AggregateSum(SqlFunc.IIF(o.Id != null, 1, 0)),
  268. }).MergeTable();
  269. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  270. return new PagedDto<HotspotDataLsitVo>(total, items);
  271. }
  272. /// <summary>
  273. /// 热点数据统计
  274. /// </summary>
  275. /// <param name="dto"></param>
  276. /// <returns></returns>
  277. [HttpGet("hotspot_data_list")]
  278. public async Task<object> HotspotDataLsit([FromQuery] HotspotReportPagedRequest dto)
  279. {
  280. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  281. if (dto.Type == 0 && (!dto.ChainStartTime.HasValue || !dto.ChainEndTime.HasValue)) throw UserFriendlyException.SameMessage("请选择环比时间!");
  282. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  283. var IsCenter = _sessionContext.OrgIsCenter;
  284. if (dto.Type == 0)
  285. {
  286. dto.ChainEndTime = dto.ChainEndTime.Value.AddDays(1).AddSeconds(-1);
  287. }
  288. var items = await _hotspotTypeRepository.Queryable(false, true)
  289. .LeftJoin<Order>((x, o) => o.HotspotSpliceName != null && (x.HotSpotName == o.HotspotSpliceName || o.HotspotSpliceName.Contains(x.HotSpotName)) && o.IsDeleted == false)
  290. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= dto.StartTime)
  291. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= dto.EndTime)
  292. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => x.HotSpotName.Contains(dto.Keyword!))
  293. .WhereIF(IsCenter == false, (x, o) => o.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  294. .Where((x, o) => x.ParentId == dto.Id)
  295. .Where((x, o) => x.IsDeleted == false)
  296. .GroupBy((x, o) => new { x.Id, x.HotSpotName })
  297. .Select((x, o) => new HotspotDataLsitVo
  298. {
  299. Id = x.Id,
  300. Name = x.HotSpotName,
  301. Num = SqlFunc.AggregateSum(SqlFunc.IIF(o.Id != null, 1, 0)),
  302. Sublevel = SqlFunc.AggregateSum(SqlFunc.IIF(x.HotSpotName != o.HotspotName, 1, 0)) > 0,
  303. }).MergeTable().ToListAsync();
  304. var chainStartTime = dto.StartTime;
  305. var chainEndTime = dto.EndTime;
  306. switch (dto.Type)
  307. {
  308. case 1://日
  309. chainStartTime = dto.StartTime.Value.AddDays(-1);
  310. chainEndTime = dto.EndTime.Value.AddDays(-1);
  311. break;
  312. case 2://月
  313. chainStartTime = dto.StartTime.Value.AddMonths(-1);
  314. chainEndTime = dto.EndTime.Value.AddMonths(-1);
  315. break;
  316. case 3://年
  317. chainStartTime = dto.StartTime.Value.AddYears(-1);
  318. chainEndTime = dto.EndTime.Value.AddYears(-1);
  319. break;
  320. case 0:
  321. chainStartTime = dto.ChainStartTime.Value;
  322. chainEndTime = dto.ChainEndTime.Value;
  323. break;
  324. }
  325. var chainItems = await _hotspotTypeRepository.Queryable(false, true)
  326. .LeftJoin<Order>((x, o) => o.HotspotSpliceName != null && (x.HotSpotName == o.HotspotSpliceName || o.HotspotSpliceName.Contains(x.HotSpotName)) && o.IsDeleted == false)
  327. .WhereIF(dto.StartTime.HasValue, (x, o) => o.CreationTime >= chainStartTime)
  328. .WhereIF(dto.EndTime.HasValue, (x, o) => o.CreationTime <= chainEndTime)
  329. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), (x, o) => x.HotSpotName.Contains(dto.Keyword!))
  330. .WhereIF(IsCenter == false, (x, o) => o.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
  331. .Where((x, o) => x.ParentId == dto.Id)
  332. .Where((x, o) => x.IsDeleted == false)
  333. .GroupBy((x, o) => new { x.Id, x.HotSpotName })
  334. .Select((x, o) => new
  335. {
  336. Id = x.Id,
  337. ChainNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.Id != null, 1, 0)),
  338. }).MergeTable().ToListAsync();
  339. var res = (from t1 in items
  340. join t2 in chainItems on t1.Id equals t2.Id into t1_t2
  341. from item in t1_t2.DefaultIfEmpty()
  342. select new
  343. {
  344. Id = t1.Id,
  345. Name = t1.Name,
  346. Num = t1.Num,
  347. Sublevel = t1.Sublevel,
  348. Children = new List<HotspotDataLsitVo>(),
  349. ChainNum = t1_t2.Select(x => x.ChainNum).FirstOrDefault(),
  350. ChainRate = t1_t2.Select(x => x.ChainNum).FirstOrDefault() > 0 ?
  351. ((double.Parse(t1.Num.ToString()) - double.Parse(t1_t2.Select(x => x.ChainNum).FirstOrDefault().ToString())) / double.Parse(t1_t2.Select(x => x.ChainNum).FirstOrDefault().ToString()) * 100).ToString("F2") + "%" : "100.00%",
  352. }).ToList();
  353. var total = new
  354. {
  355. Id = "0",
  356. Name = "合计",
  357. Num = res.Sum(x => x.Num),
  358. Sublevel = false,
  359. Children = new List<HotspotDataLsitVo>(),
  360. ChainNum = res.Sum(x => x.ChainNum),
  361. ChainRate = res.Sum(x => x.ChainNum) > 0 ? ((double.Parse(res.Sum(x => x.Num).ToString()) - double.Parse(res.Sum(x => x.ChainNum).ToString())) / double.Parse(res.Sum(x => x.ChainNum).ToString()) * 100).ToString("F2") + "%" : "100.00%"
  362. };
  363. return new { List = res, Total = total };
  364. }
  365. /// <summary>
  366. /// 部门不满意统计
  367. /// 已加验证部门
  368. /// </summary>
  369. /// <param name="dto"></param>
  370. /// <returns></returns>
  371. [HttpGet("visit-nosatisfied")]
  372. public async Task<object> QueryVisitNoSatisfied([FromQuery] QueryVisitNoSatiisfiedRequest dto)
  373. {
  374. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  375. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  376. var IsCenter = _sessionContext.OrgIsCenter;
  377. var dissatisfiedReason = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.DissatisfiedReason);
  378. List<dynamic>? list = new List<dynamic>();
  379. //DataTable dt = new DataTable();
  380. foreach (var item in dissatisfiedReason)
  381. {
  382. var table = _orderVisitDetailRepository.Queryable()
  383. .Includes(x => x.OrderVisit)
  384. .Where(x => x.VisitTarget == Share.Enums.Order.EVisitTarget.Org)
  385. .Where(x => x.OrgNoSatisfiedReason != null)
  386. .Where(x => x.OrderVisit.VisitState == EVisitState.Visited)
  387. .Where(x => !string.IsNullOrEmpty(x.VisitOrgName))
  388. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.VisitOrgName.Contains(dto.OrgName))
  389. .WhereIF(dto.StartTime.HasValue, x => x.OrderVisit.VisitTime >= dto.StartTime.Value)
  390. .WhereIF(dto.EndTime.HasValue, x => x.OrderVisit.VisitTime <= dto.EndTime.Value)
  391. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  392. .GroupBy(x => new { x.VisitOrgName, x.VisitOrgCode })
  393. .Select(x => new BiVisitNoSatisfiedDto
  394. {
  395. Count = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(x.OrgNoSatisfiedReason, "Key", item.DicDataValue), 1, 0)),
  396. Key = item.DicDataValue,
  397. OrgName = x.VisitOrgName,
  398. OrgCode = x.VisitOrgCode
  399. })
  400. .OrderByDescending(x => x.Count)
  401. //.ToPivotTable(x => x.Key, x => x.OrgName, x => x.Sum(x => x.Count));
  402. .ToPivotList(x => x.Key, x => new { x.OrgCode, x.OrgName }, x => x.Sum(x => x.Count));
  403. list.AddRange(table);
  404. }
  405. return new { DicReason = dissatisfiedReason, Data = list };
  406. }
  407. /// <summary>
  408. /// 部门不满意统计明细
  409. /// </summary>
  410. /// <param name="dto"></param>
  411. /// <returns></returns>
  412. [HttpGet("visit-nosatisfied-detail")]
  413. public async Task<PagedDto<OrderVisitDetailDto>> BiQueryVisitNoSatisfiedDetail([FromQuery] BiQueryVisitNoSatisfiedDetailDto dto)
  414. {
  415. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  416. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  417. var IsCenter = _sessionContext.OrgIsCenter;
  418. var (total, items) = await _orderVisitDetailRepository.Queryable()
  419. .Includes(x => x.OrderVisit, d => d.Order)
  420. .Includes(x => x.OrderVisit, d => d.Employee)
  421. .Where(x => x.VisitOrgCode == dto.OrgCode)
  422. .Where(x => x.OrderVisit.VisitState == EVisitState.Visited)
  423. .Where(x => x.OrderVisit.VisitTime >= dto.StartTime.Value)
  424. .Where(x => x.OrderVisit.VisitTime <= dto.EndTime.Value)
  425. .Where(x => SqlFunc.JsonListObjectAny(x.OrgNoSatisfiedReason, "Key", dto.DissatisfiedKey))
  426. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  427. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.OrderVisit.Order.No.Contains(dto.Keyword) || x.OrderVisit.Order.Title.Contains(dto.Keyword))
  428. .OrderBy(x => x.OrderVisit.VisitTime)
  429. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  430. return new PagedDto<OrderVisitDetailDto>(total, _mapper.Map<IReadOnlyList<OrderVisitDetailDto>>(items));
  431. }
  432. /// <summary>
  433. /// 部门延期统计
  434. /// </summary>
  435. /// <param name="dto"></param>
  436. /// <returns></returns>
  437. [HttpGet("order-delay-data-list")]
  438. public async Task<IReadOnlyList<BiOrderDelayDataDto>> QueryOrderDelayDataList([FromQuery] QueryOrderDelayDataListRequest dto)
  439. {
  440. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  441. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  442. var IsCenter = _sessionContext.OrgIsCenter;
  443. var list = await _orderDelayRepository.Queryable()
  444. .LeftJoin<SystemOrganize>((x, o) => x.ApplyOrgCode == o.Id)
  445. .WhereIF(dto.StartTime.HasValue, (x, o) => x.CreationTime >= dto.StartTime)
  446. .WhereIF(dto.EndTime.HasValue, (x, o) => x.CreationTime <= dto.EndTime)
  447. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.ApplyOrgName.Contains(dto.OrgName))
  448. .WhereIF(IsCenter == false, x => x.ApplyOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  449. .GroupBy(x => new { x.ApplyOrgCode, x.ApplyOrgName })
  450. .Select(x => new BiOrderDelayDataDto
  451. {
  452. OrgName = x.ApplyOrgName,
  453. OrgCode = x.ApplyOrgCode,
  454. PassTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Pass, 1, 0)),
  455. NoPassTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.NoPass, 1, 0)),
  456. ExaminingTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Examining, 1, 0)),
  457. AllTotal = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Pass, 1, 0)) + SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.NoPass, 1, 0)) + SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState == EDelayState.Examining, 1, 0))
  458. }).ToListAsync();
  459. return list;
  460. }
  461. /// <summary>
  462. /// 特提统计
  463. /// </summary>
  464. /// <param name="dto"></param>
  465. /// <returns></returns>
  466. [HttpGet("special_data_list")]
  467. public async Task<PagedDto<OrderBiSpecialListVo>> SpecialDataList([FromQuery] ReportPagedRequest dto)
  468. {
  469. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  470. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  471. var IsCenter = _sessionContext.OrgIsCenter;
  472. var query = _orderSpecialRepository.Queryable()
  473. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  474. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  475. .WhereIF(IsCenter == false, x => x.OrgId.StartsWith(_sessionContext.RequiredOrgId))
  476. .GroupBy(x => new { x.Cause })
  477. .Select(x => new OrderBiSpecialListVo
  478. {
  479. Cause = x.Cause,
  480. OrderNum = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  481. MaxSpecialTime = SqlFunc.AggregateMax(x.CreationTime),
  482. })
  483. .MergeTable();
  484. switch (dto.SortField)
  485. {
  486. case "cause":
  487. query = dto.SortRule == 0 ? query.OrderBy(x => x.Cause) : query.OrderByDescending(x => x.Cause);
  488. break;
  489. case "orderNum":
  490. query = dto.SortRule == 0 ? query.OrderBy(x => x.OrderNum) : query.OrderByDescending(x => x.OrderNum);
  491. break;
  492. case "maxSpecialTime":
  493. query = dto.SortRule == 0 ? query.OrderBy(x => x.MaxSpecialTime) : query.OrderByDescending(x => x.MaxSpecialTime);
  494. break;
  495. }
  496. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  497. return new PagedDto<OrderBiSpecialListVo>(total, items);
  498. }
  499. /// <summary>
  500. /// 获取工单特提信息列表
  501. /// </summary>
  502. /// <param name="dto"></param>
  503. /// <returns></returns>
  504. [HttpGet("special_data_list/list")]
  505. public async Task<PagedDto<OrderSpecialDto>> List([FromQuery] OrderSpecialListDto dto)
  506. {
  507. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  508. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  509. var IsCenter = _sessionContext.OrgIsCenter;
  510. var (total, items) = await _orderSpecialRepository.Queryable()
  511. .Includes(x => x.Order)
  512. .WhereIF(!string.IsNullOrEmpty(dto.Keyword),
  513. x => x.Order.No.Contains(dto.Keyword!) || x.Order.Title.Contains(dto.Keyword!))
  514. .WhereIF(!string.IsNullOrEmpty(dto.Cause),
  515. x => x.Cause != null && x.Cause.Equals(dto.Cause))
  516. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  517. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  518. .WhereIF(dto.State.HasValue, x => x.State == dto.State)
  519. .WhereIF(IsCenter == false, x => x.OrgId.StartsWith(_sessionContext.OrgId))
  520. .OrderByDescending(x => x.CreationTime)
  521. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  522. return new PagedDto<OrderSpecialDto>(total, _mapper.Map<IReadOnlyList<OrderSpecialDto>>(items));
  523. }
  524. /// <summary>
  525. /// 受理类型前十
  526. /// </summary>
  527. /// <param name="dto"></param>
  528. /// <returns></returns>
  529. [HttpGet("accept_type_top10_list")]
  530. public async Task<PagedDto<AcceptTypeTop10Vo>> AcceptTypeTop10List([FromQuery] ReportPagedRequest dto)
  531. {
  532. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
  533. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  534. dto.PageIndex = 1;
  535. dto.PageSize = 10;
  536. var IsCenter = _sessionContext.OrgIsCenter;
  537. var query = _orderRepository.Queryable(false, false, false)
  538. .WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
  539. .WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
  540. .WhereIF(IsCenter == false, x => x.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  541. .Select(x => new
  542. {
  543. AcceptType = x.AcceptType,
  544. OneHotspot = SqlFunc.Substring(x.HotspotSpliceName, 0, SqlFunc.CharIndex("-", x.HotspotSpliceName + "-")),
  545. Id = x.Id
  546. }).MergeTable()
  547. .GroupBy(x => new { x.OneHotspot })
  548. .Select(x => new AcceptTypeTop10Vo
  549. {
  550. Name = x.OneHotspot,
  551. ValidAccept = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  552. Consult = SqlFunc.AggregateSum(SqlFunc.IIF("咨询".Equals(x.AcceptType), 1, 0)),
  553. Report = SqlFunc.AggregateSum(SqlFunc.IIF("举报".Equals(x.AcceptType), 1, 0)),
  554. Complaint = SqlFunc.AggregateSum(SqlFunc.IIF("投诉".Equals(x.AcceptType), 1, 0)),
  555. SeekHelp = SqlFunc.AggregateSum(SqlFunc.IIF("求助".Equals(x.AcceptType), 1, 0)),
  556. Suggest = SqlFunc.AggregateSum(SqlFunc.IIF("建议".Equals(x.AcceptType), 1, 0)),
  557. Opinion = SqlFunc.AggregateSum(SqlFunc.IIF("意见".Equals(x.AcceptType), 1, 0)),
  558. Rests = SqlFunc.AggregateSum(SqlFunc.IIF("其他".Equals(x.AcceptType), 1, 0)),
  559. BenefitThePeople = SqlFunc.AggregateSum(SqlFunc.IIF("惠民帮助".Equals(x.AcceptType), 1, 0)),
  560. Praise = SqlFunc.AggregateSum(SqlFunc.IIF("表扬".Equals(x.AcceptType), 1, 0)),
  561. }).MergeTable();
  562. switch (dto.SortField)
  563. {
  564. case "validAccept":
  565. query = dto.SortRule == 0 ? query.OrderBy(x => x.ValidAccept) : query.OrderByDescending(x => x.ValidAccept);
  566. break;
  567. case "consult":
  568. query = dto.SortRule == 0 ? query.OrderBy(x => x.Consult) : query.OrderByDescending(x => x.Consult);
  569. break;
  570. case "report":
  571. query = dto.SortRule == 0 ? query.OrderBy(x => x.Report) : query.OrderByDescending(x => x.Report);
  572. break;
  573. case "complaint":
  574. query = dto.SortRule == 0 ? query.OrderBy(x => x.Complaint) : query.OrderByDescending(x => x.Complaint);
  575. break;
  576. case "seekHelp":
  577. query = dto.SortRule == 0 ? query.OrderBy(x => x.SeekHelp) : query.OrderByDescending(x => x.SeekHelp);
  578. break;
  579. case "suggest":
  580. query = dto.SortRule == 0 ? query.OrderBy(x => x.Suggest) : query.OrderByDescending(x => x.Suggest);
  581. break;
  582. case "opinion":
  583. query = dto.SortRule == 0 ? query.OrderBy(x => x.Opinion) : query.OrderByDescending(x => x.Opinion);
  584. break;
  585. case "rests":
  586. query = dto.SortRule == 0 ? query.OrderBy(x => x.Rests) : query.OrderByDescending(x => x.Rests);
  587. break;
  588. case "benefitThePeople":
  589. query = dto.SortRule == 0 ? query.OrderBy(x => x.BenefitThePeople) : query.OrderByDescending(x => x.BenefitThePeople);
  590. break;
  591. case "praise":
  592. query = dto.SortRule == 0 ? query.OrderBy(x => x.Praise) : query.OrderByDescending(x => x.Praise);
  593. break;
  594. default:
  595. query = query.OrderByDescending(x => x.ValidAccept);
  596. break;
  597. }
  598. var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
  599. return new PagedDto<AcceptTypeTop10Vo>(total, items);
  600. }
  601. /// <summary>
  602. /// 热点类型部门统计
  603. /// </summary>
  604. /// <param name="dto"></param>
  605. /// <returns></returns>
  606. [HttpGet("hotport-org-statistics")]
  607. public async Task<object> HotPortJoinOrgStatistics([FromQuery] HotPortJoinOrgStatisticsRequest dto)
  608. {
  609. dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
  610. var IsCenter = _sessionContext.OrgIsCenter;
  611. return await _orderRepository.HotPortJoinOrgStatistics(dto.StartTime, dto.EndTime, IsCenter, _sessionContext.OrgId);
  612. }
  613. /// <summary>
  614. /// 回访量统计
  615. /// </summary>
  616. /// <returns></returns>
  617. [HttpGet("visit-measure-statistics")]
  618. public async Task<VisitMeasureStatisticsDto> VisitMeasureStatistics(DateTime StartDate, DateTime EndDate, string? VisitName)
  619. {
  620. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  621. var list = await _orderVisitRepository.Queryable()
  622. .Includes(x => x.Employee)
  623. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited)
  624. .WhereIF(!string.IsNullOrEmpty(VisitName), x => x.Employee.Name.Contains(VisitName))
  625. .GroupBy(x => new { x.EmployeeId, x.Employee.Name })
  626. .Select(x => new VisitMeasureStatisticsModelDto()
  627. {
  628. VisitName = x.Employee.Name,
  629. CallVisitCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitType == EVisitType.CallVisit, 1, 0)),
  630. ArtificialVisitCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitType != EVisitType.CallVisit, 1, 0)),
  631. SumCount = SqlFunc.AggregateCount(x.EmployeeId)
  632. })
  633. .ToListAsync();
  634. var returnModel = new VisitMeasureStatisticsDto();
  635. returnModel.VisitMeasureStatisticsModelList = list;
  636. //查询AIVisit
  637. returnModel.AiVisitCount = await _aiOrderVisitDetailRepository.Queryable()
  638. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess != null).CountAsync();
  639. returnModel.AiVisitSatisfiedCount = await _aiOrderVisitDetailRepository.Queryable()
  640. .Includes(x => x.OrderVisit)
  641. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess == true && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") != "1" && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") != "2").CountAsync();
  642. returnModel.AiVisitNoSatisfiedCount = await _aiOrderVisitDetailRepository.Queryable()
  643. .Includes(x => x.OrderVisit)
  644. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess == true && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") == "1" && SqlFunc.JsonField(x.OrderVisit.NowEvaluate, "Key") == "2").CountAsync();
  645. returnModel.AIVisitFailCount = await _aiOrderVisitDetailRepository.Queryable()
  646. .Where(x => x.AiVisitTime >= StartDate && x.AiVisitTime <= EndDate && x.IsSuccess == false).CountAsync();
  647. return returnModel;
  648. }
  649. /// <summary>
  650. /// 热点类型小类统计
  651. /// </summary>
  652. /// <param name="StartDate"></param>
  653. /// <param name="EndDate"></param>
  654. /// <param name="TypeId">0:全部 ,1:市民,2:企业</param>
  655. /// <returns></returns>
  656. [HttpGet("hotspot-statistics")]
  657. public async Task<object> HotspotStatistics(DateTime StartDate, DateTime EndDate, int TypeId, string? HotspotCode)
  658. {
  659. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  660. var IsCenter = _sessionContext.OrgIsCenter;
  661. if (string.IsNullOrEmpty(HotspotCode))
  662. {
  663. var list = await _hotspotTypeRepository.Queryable()
  664. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  665. .Where((it, o) => o.CreationTime >= StartDate && o.CreationTime <= EndDate && o.Id != null)
  666. .WhereIF(TypeId == 1, (it, o) => o.IdentityType == EIdentityType.Citizen)
  667. .WhereIF(TypeId == 2, (it, o) => o.IdentityType == EIdentityType.Enterprise)
  668. .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  669. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")) })
  670. .Select((it, o) => new
  671. {
  672. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")),
  673. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  674. })
  675. .MergeTable()
  676. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  677. .Select((x, q) => new
  678. {
  679. HotspotCode = x.HotspotCode,
  680. SumCount = x.SumCount,
  681. HotspotName = q.HotSpotName,
  682. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  683. })
  684. .ToListAsync();
  685. return list;
  686. }
  687. else
  688. {
  689. string count = (HotspotCode.Length + 2).ToString();
  690. string countx = HotspotCode.Length.ToString();
  691. var list = await _hotspotTypeRepository.Queryable()
  692. .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
  693. .Where((it, o) => o.CreationTime >= StartDate && o.CreationTime <= EndDate && it.ParentId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(countx)) == HotspotCode)
  694. .WhereIF(TypeId == 1, (it, o) => o.IdentityType == EIdentityType.Citizen)
  695. .WhereIF(TypeId == 2, (it, o) => o.IdentityType == EIdentityType.Enterprise)
  696. .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
  697. .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)) })
  698. .Select((it, o) => new
  699. {
  700. HotspotCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)),
  701. SumCount = SqlFunc.AggregateCount(it.HotSpotName)
  702. })
  703. .MergeTable()
  704. .LeftJoin<Hotspot>((x, q) => x.HotspotCode == q.Id)
  705. .Select((x, q) => new
  706. {
  707. HotspotCode = x.HotspotCode,
  708. SumCount = x.SumCount,
  709. HotspotName = q.HotSpotName,
  710. HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.HotspotCode).Any()
  711. })
  712. .ToListAsync();
  713. return list;
  714. }
  715. }
  716. /// <summary>
  717. /// 部门满意度统计
  718. /// </summary>
  719. /// <param name="StartDate"></param>
  720. /// <param name="EndDate"></param>
  721. /// <param name="OrgName"></param>
  722. /// <param name="TypeId">1:办件结果 2:办件态度</param>
  723. /// <param name="LineNum"></param>
  724. /// <returns></returns>
  725. [HttpGet("visit-org-satisfaction-statistics")]
  726. public async Task<VisitAndOrgSatisfactionStatisticsResultDto> VisitAndOrgSatisfactionStatistics(DateTime StartDate, DateTime EndDate, string OrgName, int TypeId, string? LineNum)
  727. {
  728. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  729. bool IsCenter = _sessionContext.OrgIsCenter;
  730. var list = _orderVisitDetailRepository.Queryable()
  731. .Where(x => x.OrderVisit.VisitTime >= StartDate && x.OrderVisit.VisitTime <= EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited && !string.IsNullOrEmpty(x.VisitOrgCode))
  732. .WhereIF(string.IsNullOrEmpty(OrgName) == false, x => x.VisitOrgName.Contains(OrgName))
  733. .WhereIF(string.IsNullOrEmpty(LineNum) == false, x => x.OrderVisit.Order.CallRecord.Gateway.Contains(LineNum))
  734. .WhereIF(IsCenter == false, x => x.VisitOrgCode.StartsWith(_sessionContext.OrgId));
  735. var data = new List<VisitAndOrgSatisfactionStatisticsDto>();
  736. if (IsCenter && list != null)
  737. {
  738. data = await list.GroupBy(x => new
  739. {
  740. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  741. })
  742. .Select(x => new VisitAndOrgSatisfactionStatisticsDto()
  743. {
  744. OrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  745. TotalSumCount = SqlFunc.AggregateCount(x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  746. VerySatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "5", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "5", 1, 0))),//非常满意数
  747. SatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "4", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "4", 1, 0))), //满意数
  748. RegardedAsSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "-1", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "-1", 1, 0))),//视为满意
  749. DefaultSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "0", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "0", 1, 0))),//默认满意
  750. NoSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "2", 1, 0))),//不满意
  751. NoEvaluateCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "7", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "7", 1, 0))),//未做评价
  752. NoPutThroughCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "6", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "6", 1, 0))),//未接通
  753. })
  754. .MergeTable()
  755. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  756. .Select((it, o) => new VisitAndOrgSatisfactionStatisticsDto()
  757. {
  758. OrgName = o.Name,
  759. OrgCode = it.OrgCode,
  760. OrgType = o.OrgType,
  761. TotalSumCount = it.TotalSumCount,
  762. VerySatisfiedCount = it.VerySatisfiedCount,//非常满意数
  763. SatisfiedCount = it.SatisfiedCount, //满意数
  764. RegardedAsSatisfiedCount = it.RegardedAsSatisfiedCount,//视为满意
  765. DefaultSatisfiedCount = it.DefaultSatisfiedCount,//默认满意
  766. NoSatisfiedCount = it.NoSatisfiedCount,//不满意
  767. NoEvaluateCount = it.NoEvaluateCount,//未做评价
  768. NoPutThroughCount = it.NoPutThroughCount,//未接通
  769. })
  770. .ToListAsync();
  771. }
  772. else
  773. {
  774. data = await list.GroupBy(x => new
  775. {
  776. x.VisitOrgCode
  777. })
  778. .Select(x => new VisitAndOrgSatisfactionStatisticsDto()
  779. {
  780. OrgCode = x.VisitOrgCode,
  781. TotalSumCount = SqlFunc.AggregateCount(x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  782. VerySatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "5", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "5", 1, 0))),//非常满意数
  783. SatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "4", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "4", 1, 0))), //满意数
  784. RegardedAsSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "-1", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "-1", 1, 0))),//视为满意
  785. DefaultSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "0", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "0", 1, 0))),//默认满意
  786. NoSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "2", 1, 0))),//不满意
  787. NoEvaluateCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "7", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "7", 1, 0))),//未做评价
  788. NoPutThroughCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "6", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "6", 1, 0))),//未接通
  789. })
  790. .MergeTable()
  791. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  792. .Select((it, o) => new VisitAndOrgSatisfactionStatisticsDto()
  793. {
  794. OrgName = o.Name,
  795. OrgCode = it.OrgCode,
  796. OrgType = o.OrgType,
  797. TotalSumCount = it.TotalSumCount,
  798. VerySatisfiedCount = it.VerySatisfiedCount,//非常满意数
  799. SatisfiedCount = it.SatisfiedCount, //满意数
  800. RegardedAsSatisfiedCount = it.RegardedAsSatisfiedCount,//视为满意
  801. DefaultSatisfiedCount = it.DefaultSatisfiedCount,//默认满意
  802. NoSatisfiedCount = it.NoSatisfiedCount,//不满意
  803. NoEvaluateCount = it.NoEvaluateCount,//未做评价
  804. NoPutThroughCount = it.NoPutThroughCount,//未接通
  805. })
  806. .ToListAsync();
  807. }
  808. var countySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  809. {
  810. OrgName = "区县合计",
  811. TotalSumCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.TotalSumCount),
  812. VerySatisfiedCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.VerySatisfiedCount),
  813. SatisfiedCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.SatisfiedCount),
  814. RegardedAsSatisfiedCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.RegardedAsSatisfiedCount),
  815. DefaultSatisfiedCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.DefaultSatisfiedCount),
  816. NoSatisfiedCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoSatisfiedCount),
  817. NoEvaluateCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoEvaluateCount),
  818. NoPutThroughCount = data.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoPutThroughCount),
  819. };
  820. var citySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  821. {
  822. OrgName = "市直合计",
  823. TotalSumCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.TotalSumCount),
  824. VerySatisfiedCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.VerySatisfiedCount),
  825. SatisfiedCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.SatisfiedCount),
  826. RegardedAsSatisfiedCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.RegardedAsSatisfiedCount),
  827. DefaultSatisfiedCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.DefaultSatisfiedCount),
  828. NoSatisfiedCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoSatisfiedCount),
  829. NoEvaluateCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoEvaluateCount),
  830. NoPutThroughCount = data.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoPutThroughCount),
  831. };
  832. var sumModel = new VisitAndOrgSatisfactionStatisticsDto()
  833. {
  834. OrgName = "总计",
  835. TotalSumCount = data.Sum(x => x.TotalSumCount),
  836. VerySatisfiedCount = data.Sum(x => x.VerySatisfiedCount),
  837. SatisfiedCount = data.Sum(x => x.SatisfiedCount),
  838. RegardedAsSatisfiedCount = data.Sum(x => x.RegardedAsSatisfiedCount),
  839. DefaultSatisfiedCount = data.Sum(x => x.DefaultSatisfiedCount),
  840. NoSatisfiedCount = data.Sum(x => x.NoSatisfiedCount),
  841. NoEvaluateCount = data.Sum(x => x.NoEvaluateCount),
  842. NoPutThroughCount = data.Sum(x => x.NoPutThroughCount),
  843. };
  844. return new VisitAndOrgSatisfactionStatisticsResultDto { DataList = data, CountySumModel = countySumModel, CitySumModel = citySumModel, SumModel = sumModel };
  845. }
  846. /// <summary>
  847. /// 子部门满意度明细
  848. /// </summary>
  849. /// <param name="StartDate"></param>
  850. /// <param name="EndDate"></param>
  851. /// <param name="OrgCode"></param>
  852. /// <param name="TypeId"></param>
  853. /// <param name="LineNum"></param>
  854. /// <returns></returns>
  855. [HttpGet("visit-org-statisfaction-org-detail")]
  856. public async Task<VisitAndOrgSatisfactionStatisticsResultDto> VisitAndOrgStatisfactionOrgDetail(DateTime StartDate, DateTime EndDate, string OrgCode, int TypeId, string? LineNum)
  857. {
  858. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  859. bool IsCenter = _sessionContext.OrgIsCenter;
  860. var list = await _systemOrganizeRepository.Queryable().Where(x => x.Id.StartsWith(OrgCode))
  861. .LeftJoin<OrderVisitDetail>((x, it) => x.Id == it.VisitOrgCode)
  862. .Where((x, it) => it.OrderVisit.VisitTime >= StartDate && it.OrderVisit.VisitTime <= EndDate && it.VisitTarget == EVisitTarget.Org && it.OrderVisit.VisitState == EVisitState.Visited)
  863. .WhereIF(OrgCode == "001", (x, it) => it.VisitOrgCode == OrgCode)
  864. .WhereIF(OrgCode != "001", (x, it) => it.VisitOrgCode.StartsWith(OrgCode))
  865. .WhereIF(!string.IsNullOrEmpty(LineNum), (x, it) => it.OrderVisit.Order.CallRecord.Gateway.Contains(LineNum))
  866. .WhereIF(IsCenter == false, (x, it) => it.VisitOrgCode.StartsWith(_sessionContext.OrgId))
  867. .GroupBy((x, it) => new
  868. {
  869. VisitOrgCode = it.VisitOrgCode
  870. })
  871. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  872. {
  873. OrgCode = it.VisitOrgCode,
  874. TotalSumCount = SqlFunc.AggregateCount(it.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("9"))),
  875. VerySatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "5", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "5", 1, 0))),//非常满意数
  876. SatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "4", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "4", 1, 0))), //满意数
  877. RegardedAsSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "-1", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "-1", 1, 0))),//视为满意
  878. DefaultSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "0", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "0", 1, 0))),//默认满意
  879. NoSatisfiedCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "2", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "2", 1, 0))),//不满意
  880. NoEvaluateCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "7", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "7", 1, 0))),//未做评价
  881. NoPutThroughCount = SqlFunc.IIF(TypeId == 1, SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgProcessingResults, "Key") == "6", 1, 0)), SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(it.OrgHandledAttitude, "Key") == "6", 1, 0)))//未接通
  882. })
  883. .MergeTable()
  884. .LeftJoin<SystemOrganize>((x, it) => x.OrgCode == it.Id)
  885. .Select((x, it) => new VisitAndOrgSatisfactionStatisticsDto()
  886. {
  887. OrgName = it.Name,
  888. OrgCode = x.OrgCode,
  889. OrgType = it.OrgType,
  890. TotalSumCount = x.TotalSumCount,
  891. VerySatisfiedCount = x.VerySatisfiedCount,//非常满意数
  892. SatisfiedCount = x.SatisfiedCount, //满意数
  893. RegardedAsSatisfiedCount = x.RegardedAsSatisfiedCount,//视为满意
  894. DefaultSatisfiedCount = x.DefaultSatisfiedCount,//默认满意
  895. NoSatisfiedCount = x.NoSatisfiedCount,//不满意
  896. NoEvaluateCount = x.NoEvaluateCount,//未做评价
  897. NoPutThroughCount = x.NoPutThroughCount,//未接通
  898. })
  899. .ToListAsync();
  900. var countySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  901. {
  902. OrgName = "区县合计",
  903. TotalSumCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.TotalSumCount),
  904. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.VerySatisfiedCount),
  905. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.SatisfiedCount),
  906. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.RegardedAsSatisfiedCount),
  907. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.DefaultSatisfiedCount),
  908. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoSatisfiedCount),
  909. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoEvaluateCount),
  910. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.County).Sum(x => x.NoPutThroughCount),
  911. };
  912. var citySumModel = new VisitAndOrgSatisfactionStatisticsDto()
  913. {
  914. OrgName = "市直合计",
  915. TotalSumCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.TotalSumCount),
  916. VerySatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.VerySatisfiedCount),
  917. SatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.SatisfiedCount),
  918. RegardedAsSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.RegardedAsSatisfiedCount),
  919. DefaultSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.DefaultSatisfiedCount),
  920. NoSatisfiedCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoSatisfiedCount),
  921. NoEvaluateCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoEvaluateCount),
  922. NoPutThroughCount = list.Where(x => x.OrgType == EOrgType.City).Sum(x => x.NoPutThroughCount),
  923. };
  924. var sumModel = new VisitAndOrgSatisfactionStatisticsDto()
  925. {
  926. OrgName = "总计",
  927. TotalSumCount = list.Sum(x => x.TotalSumCount),
  928. VerySatisfiedCount = list.Sum(x => x.VerySatisfiedCount),
  929. SatisfiedCount = list.Sum(x => x.SatisfiedCount),
  930. RegardedAsSatisfiedCount = list.Sum(x => x.RegardedAsSatisfiedCount),
  931. DefaultSatisfiedCount = list.Sum(x => x.DefaultSatisfiedCount),
  932. NoSatisfiedCount = list.Sum(x => x.NoSatisfiedCount),
  933. NoEvaluateCount = list.Sum(x => x.NoEvaluateCount),
  934. NoPutThroughCount = list.Sum(x => x.NoPutThroughCount),
  935. };
  936. return new VisitAndOrgSatisfactionStatisticsResultDto { DataList = list, CountySumModel = countySumModel, CitySumModel = citySumModel, SumModel = sumModel };
  937. }
  938. /// <summary>
  939. /// 部门满意度明细
  940. /// </summary>
  941. /// <param name="StartDate"></param>
  942. /// <param name="EndDate"></param>
  943. /// <param name="OrgCode"></param>
  944. /// <param name="TypeId"></param>
  945. /// <param name="LineNum"></param>
  946. /// <returns></returns>
  947. [HttpGet("visit-org-satisfaction-detail")]
  948. public async Task<PagedDto<OrderVisitDetailDto>> VisitAndOrgSatisfactionDetail([FromQuery] VisitAndOrgSatisfactionDetailDto dto)
  949. {
  950. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  951. var (total, items) = await _orderVisitDetailRepository.Queryable()
  952. .Includes(x => x.OrderVisit, o => o.Order, d => d.CallRecord)
  953. .Where(x => x.OrderVisit.VisitTime >= dto.StartDate && x.OrderVisit.VisitTime <= dto.EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited)
  954. .WhereIF(dto.OrgCode == "001", x => x.VisitOrgCode == dto.OrgCode)
  955. .WhereIF(dto.OrgCode != "001", x => x.VisitOrgCode.StartsWith(dto.OrgCode))
  956. .WhereIF(dto.TypeId == 1, x => SqlFunc.JsonField(x.OrgProcessingResults, "Key") == dto.DateValue)
  957. .WhereIF(dto.TypeId == 2, x => SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == dto.DateValue)
  958. .WhereIF(!string.IsNullOrEmpty(dto.LineNum), x => x.OrderVisit.Order.CallRecord.Gateway == dto.LineNum)
  959. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  960. return new PagedDto<OrderVisitDetailDto>(total, _mapper.Map<IReadOnlyList<OrderVisitDetailDto>>(items));
  961. }
  962. /// <summary>
  963. /// 中心报表统计
  964. /// </summary>
  965. /// <param name="StartDate"></param>
  966. /// <param name="EndDate"></param>
  967. /// <returns></returns>
  968. [HttpGet("center_report_forms_statistics")]
  969. public async Task<CenterReportStatisticsDto> CenterReportFormsStatistics(DateTime StartDate, DateTime EndDate)
  970. {
  971. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  972. CenterReportStatisticsDto centerReportStatisticsDto = new();
  973. //信件总量
  974. int sourceChannelCount = await _orderRepository.Queryable().Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate).CountAsync();
  975. #region 通话记录
  976. //通话记录
  977. var callData = await _trCallRecordRepository.Queryable()
  978. .Where(p => p.CreatedTime >= StartDate && p.CreatedTime <= EndDate)
  979. .Select(o => new CenterReportCallDto
  980. {
  981. EffectiveCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.OnState == EOnState.On, 1, 0)),//有效
  982. InvalidCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.OnState == EOnState.NoOn && o.BeginIvrTime.HasValue && o.BeginQueueTime.HasValue && o.BeginRingTime.HasValue, 1, 0)), //无效(排除队列挂断和IVR挂断)
  983. QueueByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In && o.QueueTims > 0 && o.RingTimes == 0, 1, 0)), //队列挂断
  984. IvrByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In && o.BeginIvrTime.HasValue && !o.BeginQueueTime.HasValue && !o.BeginRingTime.HasValue && o.OnState == EOnState.NoOn, 1, 0)), //IVR挂断
  985. })
  986. .ToListAsync();
  987. if (callData != null && callData.Count > 0)
  988. centerReportStatisticsDto.CenterReportCall = callData[0];
  989. #endregion
  990. #region 工单
  991. //工单
  992. var orderData = await _orderRepository.Queryable()
  993. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  994. .Select(x => new CenterReportOrderDto
  995. {
  996. EffectiveCount = SqlFunc.AggregateSum(SqlFunc.IIF(true, 1, 0)),
  997. InvalidCount = 0,
  998. CompletedCount = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status >= 300, 1, 0)),
  999. InProgressCount = SqlFunc.AggregateSum(SqlFunc.IIF((int)x.Status < 300, 1, 0))
  1000. })
  1001. .ToListAsync();
  1002. if (orderData != null && orderData.Count > 0)
  1003. centerReportStatisticsDto.CenterReportOrder = orderData[0];
  1004. #endregion
  1005. #region 信件来源
  1006. //信件来源
  1007. var sourceChannelData = await _orderRepository.Queryable()
  1008. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  1009. .Select(it => new
  1010. {
  1011. SourceChannelCode = SqlFunc.IIF(SqlFunc.IsNullOrEmpty(it.SourceChannelCode), "QT", it.SourceChannelCode)
  1012. })
  1013. .MergeTable()//将查询出来的结果合并成一个新表
  1014. .GroupBy(it => new { it.SourceChannelCode })//对新表进行分组
  1015. .Select(it => new CenterReportOrderSourceChannelDto
  1016. {
  1017. Code = it.SourceChannelCode,
  1018. CountNum = SqlFunc.AggregateCount(it.SourceChannelCode)
  1019. })
  1020. .ToListAsync();
  1021. List<CenterReportOrderSourceChannelDto> sourceChannel = new()
  1022. {
  1023. new CenterReportOrderSourceChannelDto
  1024. {
  1025. Name = "来源总量",
  1026. Code = "All",
  1027. CountNum = sourceChannelCount
  1028. }
  1029. };
  1030. var sourceChannelDic = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.SourceChannel);
  1031. foreach (var item in sourceChannelDic)
  1032. {
  1033. sourceChannel.Add(new CenterReportOrderSourceChannelDto
  1034. {
  1035. Name = item.DicDataName,
  1036. Code = item.DicTypeCode,
  1037. CountNum = sourceChannelData.Find(p => p.Code == item.DicDataValue)?.CountNum ?? 0
  1038. });
  1039. }
  1040. centerReportStatisticsDto.CenterReportOrderSourceChannels = sourceChannel;
  1041. #endregion
  1042. #region 信件分类
  1043. //信件来源
  1044. var acceptTypeData = await _orderRepository.Queryable(false, false, false)
  1045. .Where(p => p.CreationTime >= StartDate && p.CreationTime <= EndDate)
  1046. .Select(it => new
  1047. {
  1048. AcceptTypeCode = SqlFunc.IIF(SqlFunc.IsNullOrEmpty(it.AcceptTypeCode), "40", it.AcceptTypeCode)
  1049. })
  1050. .MergeTable()//将查询出来的结果合并成一个新表
  1051. .GroupBy(it => new { it.AcceptTypeCode })//对新表进行分组
  1052. .Select(it => new CenterReportOrderSourceChannelDto
  1053. {
  1054. Code = it.AcceptTypeCode,
  1055. CountNum = SqlFunc.AggregateCount(it.AcceptTypeCode)
  1056. })
  1057. .ToListAsync();
  1058. List<CenterReportOrderSourceChannelDto> acceptType = new();
  1059. var acceptTypeDic = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.AcceptType);
  1060. foreach (var item in acceptTypeDic)
  1061. {
  1062. acceptType.Add(new CenterReportOrderSourceChannelDto
  1063. {
  1064. AllCountNum = sourceChannelCount,
  1065. Name = item.DicDataName,
  1066. Code = item.DicTypeCode,
  1067. CountNum = acceptTypeData.Find(p => p.Code == item.DicDataValue)?.CountNum ?? 0
  1068. });
  1069. }
  1070. centerReportStatisticsDto.CenterReportOrderAcceptTypes = acceptType;
  1071. #endregion
  1072. #region 信件回访量
  1073. //信件回访量
  1074. CenterReportVisitdDto centerReportVisitd = new()
  1075. {
  1076. Visitd = await _orderVisitRepository.Queryable()
  1077. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited).CountAsync(),
  1078. WaitVisitd = await _orderVisitRepository.Queryable()
  1079. .Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState != EVisitState.None && x.VisitState != EVisitState.Visited).CountAsync()
  1080. };
  1081. //部门
  1082. var listOrg = await _orderVisitDetailRepository.Queryable()
  1083. .LeftJoin<OrderVisit>((it, o) => it.VisitId == o.Id)
  1084. .Where((it, o) => it.VisitTarget == EVisitTarget.Org && o.VisitTime >= StartDate && o.VisitTime <= EndDate && o.VisitState == EVisitState.Visited)
  1085. .Select((it, o) => new Satisfaction
  1086. {
  1087. Dissatisfied = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "2"), 1, 0)),
  1088. Satisfied = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "1") || SqlFunc.JsonListObjectAny(it.OrgProcessingResults, "key", "2"), 0, 1)),
  1089. })
  1090. .ToListAsync();
  1091. if (listOrg != null && listOrg.Count > 0)
  1092. {
  1093. var SatisfiedCount = listOrg[0].Satisfied + listOrg[0].Satisfied;
  1094. if (SatisfiedCount > 0 && listOrg[0].Satisfied > 0)
  1095. centerReportVisitd.OrgRate = Math.Round((listOrg[0].Satisfied / (double)SatisfiedCount) * 100, 2);
  1096. }
  1097. //if (centerReportVisitd.Visitd > 0 && listOrg != null && listOrg.Count > 0 && listOrg[0].Satisfied > 0)
  1098. //centerReportVisitd.OrgRate = Math.Round((listOrg[0].Satisfied / (double)centerReportVisitd.Visitd) * 100, 2);
  1099. //坐席
  1100. var listSet = await _orderVisitDetailRepository.Queryable()
  1101. .LeftJoin<OrderVisit>((it, o) => it.VisitId == o.Id)
  1102. .Where((it, o) => it.VisitTarget == EVisitTarget.Seat && o.VisitTime >= StartDate && o.VisitTime <= EndDate && o.VisitState == EVisitState.Visited)
  1103. .Select((it, o) => new Satisfaction
  1104. {
  1105. Dissatisfied = SqlFunc.AggregateSum(SqlFunc.IIF(it.SeatEvaluate == ESeatEvaluate.VeryNoSatisfied || it.SeatEvaluate == ESeatEvaluate.NoSatisfied, 1, 0)),
  1106. Satisfied = SqlFunc.AggregateSum(SqlFunc.IIF(it.SeatEvaluate != ESeatEvaluate.VeryNoSatisfied && it.SeatEvaluate != ESeatEvaluate.NoSatisfied, 1, 0)),
  1107. }).ToListAsync();
  1108. if (listSet != null && listSet.Count > 0)
  1109. {
  1110. var SatisfiedCount = listSet[0].Satisfied + listSet[0].Satisfied;
  1111. if (SatisfiedCount > 0 && listSet[0].Satisfied > 0)
  1112. centerReportVisitd.OrgRate = Math.Round((listSet[0].Satisfied / (double)SatisfiedCount) * 100, 2);
  1113. }
  1114. //if (centerReportVisitd.Visitd > 0 && listSet != null && listSet.Count > 0 && listSet[0].Satisfied > 0)
  1115. // centerReportVisitd.SeatsRate = Math.Round((listSet[0].Satisfied / (double)centerReportVisitd.Visitd) * 100, 2);
  1116. centerReportStatisticsDto.CenterReportVisitd = centerReportVisitd;
  1117. #endregion
  1118. #region 信件分布情况
  1119. //市直部门
  1120. var listOrgStatisticsCityAll = await _orderRepository.Queryable()
  1121. .LeftJoin<SystemOrganize>((it, o) => it.OrgLevelOneCode == o.Id)
  1122. .Where((it, o) => (o.OrgType == EOrgType.City || o.OrgType == EOrgType.Province) && it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1123. .GroupBy((it, o) => new
  1124. {
  1125. it.OrgLevelOneCode,
  1126. o.Name
  1127. })
  1128. .Select((it, o) => new OrgStatistics
  1129. {
  1130. CountNum = SqlFunc.AggregateCount(it.OrgLevelOneCode),
  1131. OrgName = it.OrgLevelOneCode == "001" ? "热线中心" : o.Name
  1132. }).ToListAsync();
  1133. centerReportStatisticsDto.OrgStatisticsCityAll = new OrgStatisticsAll
  1134. {
  1135. OrgStatistics = listOrgStatisticsCityAll
  1136. };
  1137. //区县部门
  1138. var listOrgStatisticsAreaAll = await _orderRepository.Queryable()
  1139. .LeftJoin<SystemOrganize>((it, o) => it.OrgLevelOneCode == o.Id)
  1140. .Where((it, o) => o.OrgType == EOrgType.County && it.CreationTime >= StartDate && it.CreationTime <= EndDate)
  1141. .GroupBy((it, o) => new
  1142. {
  1143. it.OrgLevelOneCode,
  1144. o.Name
  1145. })
  1146. .Select((it, o) => new OrgStatistics
  1147. {
  1148. CountNum = SqlFunc.AggregateCount(it.OrgLevelOneCode),
  1149. OrgName = it.OrgLevelOneCode == "001" ? "热线中心" : o.Name
  1150. }).ToListAsync();
  1151. centerReportStatisticsDto.OrgStatisticsAreaAll = new OrgStatisticsAll
  1152. {
  1153. OrgStatistics = listOrgStatisticsAreaAll
  1154. };
  1155. #endregion
  1156. return centerReportStatisticsDto;
  1157. }
  1158. /// <summary>
  1159. /// 部门受理类型统计周期
  1160. /// </summary>
  1161. /// <param name="StartDate"></param>
  1162. /// <param name="EndDate"></param>
  1163. /// <param name="TypeCode">0:全部,1:中心,2:部门</param>
  1164. /// <returns></returns>
  1165. [HttpGet("department_acceptance_type_statistics")]
  1166. public async Task<List<DepartmentAcceptanceTypeStatisticsDto>> DepartmentAcceptanceTypeStatistics(DateTime StartDate, DateTime EndDate, int TypeCode)
  1167. {
  1168. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1169. var IsCenter = _sessionContext.OrgIsCenter;
  1170. var orderData = await _orderRepository.Queryable()
  1171. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate && it.Status > EOrderStatus.WaitForAccept)
  1172. .Select(it => new
  1173. {
  1174. OrgCode = IsCenter == true ? it.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : it.ActualHandleOrgCode.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1175. it.AcceptTypeCode,
  1176. it.FileDurationWorkday,
  1177. it.AllDuration
  1178. })
  1179. .MergeTable()
  1180. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  1181. .WhereIF(TypeCode == 1, (it, o) => it.OrgCode == "001")
  1182. .WhereIF(TypeCode == 2, (it, o) => it.OrgCode != "001")
  1183. .WhereIF(IsCenter == false, (it, o) => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1184. .GroupBy((it, o) => new
  1185. {
  1186. it.OrgCode,
  1187. o.Name,
  1188. o.OrgType
  1189. })
  1190. .Select((it, o) => new DepartmentAcceptanceTypeStatisticsDto
  1191. {
  1192. OrgName = it.OrgCode == "001" ? "热线中心" : o.Name,
  1193. OrgCode = it.OrgCode,
  1194. OrgType = (int)o.OrgType == 2 ? "区县部门" : "市直部门",
  1195. ZxAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10", 1, 0)),
  1196. ZxAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10" && it.AllDuration != null, it.AllDuration, 0)),
  1197. ZxAcceptanceTypeCode = "10",
  1198. JyAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15", 1, 0)),
  1199. JyAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1200. JyAcceptanceTypeCode = "15",
  1201. QzAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20", 1, 0)),
  1202. QzAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1203. QzAcceptanceTypeCode = "20",
  1204. ByAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25", 1, 0)),
  1205. ByAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1206. ByAcceptanceTypeCode = "25",
  1207. JbAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30", 1, 0)),
  1208. JbAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1209. JbAcceptanceTypeCode = "30",
  1210. TsAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35", 1, 0)),
  1211. TsAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1212. TsAcceptanceTypeCode = "35",
  1213. QtAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40", 1, 0)),
  1214. QtAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1215. QtAcceptanceTypeCode = "40",
  1216. YjAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "1", 1, 0)),
  1217. YjAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "1" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1218. YjAcceptanceTypeCode = "1"
  1219. })
  1220. .ToListAsync();
  1221. return orderData;
  1222. }
  1223. /// <summary>
  1224. /// 部门受理类型统计周期---子级
  1225. /// </summary>
  1226. /// <param name="StartDate"></param>
  1227. /// <param name="EndDate"></param>
  1228. /// <param name="TypeCode">0:全部,1:中心,2:部门</param>
  1229. /// <param name="OrgCode"></param>
  1230. /// <returns></returns>
  1231. [HttpGet("department_acceptance_type_child_statistics")]
  1232. public async Task<object> DepartmentAcceptanceTypeChildStatistics(DateTime StartDate, DateTime EndDate, int TypeCode, string OrgCode)
  1233. {
  1234. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1235. // var IsCenter = _sessionContext.OrgIsCenter;
  1236. var orderData = await _orderRepository.Queryable()
  1237. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate && it.Status > EOrderStatus.WaitForAccept)// && it.Status >= EOrderStatus.Filed
  1238. .WhereIF(OrgCode == "001", it => it.ActualHandleOrgCode == OrgCode)
  1239. .WhereIF(OrgCode != "001", it => it.ActualHandleOrgCode.StartsWith(OrgCode))
  1240. .Select(it => new
  1241. {
  1242. // OrgCode = OrgCode == "001" ? OrgCode : it.ActualHandleOrgCode.Substring(0, OrgCode.Length + 3),
  1243. OrgCode = it.ActualHandleOrgCode == "001" ? it.ActualHandleOrgCode : it.ActualHandleOrgCode.Substring(0, OrgCode.Length + 3),
  1244. it.AcceptTypeCode,
  1245. it.FileDurationWorkday,
  1246. it.AllDuration
  1247. })
  1248. .MergeTable()
  1249. .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
  1250. .WhereIF(TypeCode == 1, (it, o) => it.OrgCode == "001")
  1251. .WhereIF(TypeCode == 2, (it, o) => it.OrgCode != "001")
  1252. //.WhereIF(IsCenter == false, (it, o) => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1253. .GroupBy((it, o) => new
  1254. {
  1255. it.OrgCode,
  1256. o.Name,
  1257. o.OrgType
  1258. })
  1259. .Select((it, o) => new DepartmentAcceptanceTypeStatisticsDto
  1260. {
  1261. OrgName = it.OrgCode == "001" ? "热线中心" : o.Name,
  1262. OrgCode = it.OrgCode,
  1263. OrgType = (int)o.OrgType == 2 ? "区县部门" : "市直部门",
  1264. ZxAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10", 1, 0)),
  1265. ZxAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "10" && it.AllDuration != null, it.AllDuration, 0)),
  1266. ZxAcceptanceTypeCode = "10",
  1267. JyAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15", 1, 0)),
  1268. JyAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "15" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1269. JyAcceptanceTypeCode = "15",
  1270. QzAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20", 1, 0)),
  1271. QzAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "20" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1272. QzAcceptanceTypeCode = "20",
  1273. ByAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25", 1, 0)),
  1274. ByAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "25" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1275. ByAcceptanceTypeCode = "25",
  1276. JbAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30", 1, 0)),
  1277. JbAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "30" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1278. JbAcceptanceTypeCode = "30",
  1279. TsAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35", 1, 0)),
  1280. TsAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "35" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1281. TsAcceptanceTypeCode = "35",
  1282. QtAllCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40", 1, 0)),
  1283. QtAllTimes = SqlFunc.AggregateSum(SqlFunc.IIF(it.AcceptTypeCode == "40" && it.FileDurationWorkday != null, it.FileDurationWorkday, 0)),
  1284. QtAcceptanceTypeCode = "40"
  1285. })
  1286. .ToListAsync();
  1287. var sumModel = new DepartmentAcceptanceTypeStatisticsDto
  1288. {
  1289. OrgName = "合计",
  1290. ZxAllCount = orderData.Sum(x => x.ZxAllCount),
  1291. ZxAllTimes = orderData.Sum(x => x.ZxAllTimes),
  1292. ZxAcceptanceTypeCode = "10",
  1293. JyAllCount = orderData.Sum(x => x.JyAllCount),
  1294. JyAllTimes = orderData.Sum(x => x.JyAllTimes),
  1295. JyAcceptanceTypeCode = "15",
  1296. QzAllCount = orderData.Sum(x => x.QzAllCount),
  1297. QzAllTimes = orderData.Sum(x => x.QzAllTimes),
  1298. QzAcceptanceTypeCode = "20",
  1299. ByAllCount = orderData.Sum(x => x.ByAllCount),
  1300. ByAllTimes = orderData.Sum(x => x.ByAllTimes),
  1301. ByAcceptanceTypeCode = "25",
  1302. JbAllCount = orderData.Sum(x => x.JbAllCount),
  1303. JbAllTimes = orderData.Sum(x => x.JbAllTimes),
  1304. JbAcceptanceTypeCode = "30",
  1305. TsAllCount = orderData.Sum(x => x.TsAllCount),
  1306. TsAllTimes = orderData.Sum(x => x.TsAllTimes),
  1307. TsAcceptanceTypeCode = "35",
  1308. QtAllCount = orderData.Sum(x => x.QtAllCount),
  1309. QtAllTimes = orderData.Sum(x => x.QtAllTimes),
  1310. QtAcceptanceTypeCode = "40"
  1311. };
  1312. return new { DataList = orderData, SumModel = sumModel };
  1313. }
  1314. /// <summary>
  1315. /// 部门受理类型统计周期--明细列表
  1316. /// </summary>
  1317. /// <param name="dto"></param>
  1318. /// <returns></returns>
  1319. [HttpGet("department_acceptance_type_order_list")]
  1320. public async Task<PagedDto<OrderDto>> DepartmentAcceptanceTypeOrderList([FromQuery] DepartmentKeyWordRequest dto)
  1321. {
  1322. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  1323. var (total, items) = await _orderRepository.Queryable()
  1324. .Where(p => p.CreationTime >= dto.StartDate && p.CreationTime <= dto.EndDate && p.Status > EOrderStatus.WaitForAccept)//&& p.Status >= EOrderStatus.Filed
  1325. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.OrgCode == "001", p => p.ActualHandleOrgCode == dto.OrgCode)
  1326. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.OrgCode != "001" && _sessionContext.RequiredOrgId != dto.OrgCode, p => p.ActualHandleOrgCode.StartsWith(dto.OrgCode))
  1327. .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.OrgCode != "001" && _sessionContext.RequiredOrgId == dto.OrgCode, p => p.ActualHandleOrgCode == dto.OrgCode)
  1328. .WhereIF(!string.IsNullOrEmpty(dto.AcceptTypeCode), p => p.AcceptTypeCode == dto.AcceptTypeCode)
  1329. .WhereIF(dto.TypeCode == 1, p => p.ActualHandleOrgCode == "001")
  1330. .WhereIF(dto.TypeCode == 2, p => p.ActualHandleOrgCode != "001")
  1331. .OrderByDescending(d => d.CreationTime)
  1332. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  1333. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  1334. }
  1335. /// <summary>
  1336. /// 部门办件统计表
  1337. /// </summary>
  1338. /// <param name="StartDate"></param>
  1339. /// <param name="EndDate"></param>
  1340. /// <param name="OrgName"></param>
  1341. /// <returns></returns>
  1342. [HttpGet("departmental_processing_statistics")]
  1343. public async Task<object> DepartmentalProcessingStatistics(DateTime StartDate, DateTime EndDate, string? OrgName)
  1344. {
  1345. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1346. var IsCenter = _sessionContext.OrgIsCenter;
  1347. //工单
  1348. #region 工单
  1349. var queryOrder = _orderRepository.Queryable()
  1350. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate && it.Status > EOrderStatus.WaitForAccept)
  1351. .Select(it => new
  1352. {
  1353. it.Id,
  1354. OrgCode = IsCenter == true ? it.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : it.ActualHandleOrgCode.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1355. it.ActualHandleOrgCode,
  1356. it.Status,//工单状态
  1357. it.ExpiredTime,//期满时间
  1358. it.ActualHandleTime,//办理时间
  1359. it.CounterSignType,//会签
  1360. })
  1361. .MergeTable()
  1362. .WhereIF(IsCenter == false, it => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1363. .GroupBy(it => new
  1364. {
  1365. it.OrgCode
  1366. })
  1367. .Select(it => new DepartmentalProcessingStatisticsDataDto
  1368. {
  1369. OrgCode = it.OrgCode,
  1370. OrderCountNum = SqlFunc.AggregateCount(it.OrgCode),//总量
  1371. YBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed, 1, 0)),//已办
  1372. ZBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status < EOrderStatus.Filed, 1, 0)),//在办
  1373. Archived = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed, 1, 0)),//已归档
  1374. ToBeArchived = 0,
  1375. WaitPublished = 0,
  1376. PublishedOpen = 0,
  1377. PublishedNoOpen = 0,
  1378. YBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ActualHandleTime > it.ExpiredTime, 1, 0)),//已办超期
  1379. ZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status < EOrderStatus.Filed && it.ExpiredTime < SqlFunc.GetDate(), 1, 0)),//待办超期
  1380. CompleteOnTime= SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ActualHandleTime <= it.ExpiredTime, 1, 0)),//按时办结
  1381. HQYBOverdue = 0,
  1382. HQZBOverdue = 0,
  1383. DelayEnd = 0,
  1384. DelayWait = 0,
  1385. OrderDelayCount = 0,
  1386. ScreenCount = 0,
  1387. ScreenApproval = 0,
  1388. ScreenPass = 0,
  1389. ScreenNotPass = 0,
  1390. SatisfactionCount = 0,
  1391. NotSatisfactionCount = 0
  1392. })
  1393. .MergeTable();
  1394. #endregion
  1395. #region 发布
  1396. //发布
  1397. var queryPublish = _orderPublishRepository.Queryable()
  1398. .LeftJoin<Order>((x, o) => x.OrderId == o.Id)
  1399. .Where((x, o) => x.CreationTime >= StartDate && x.CreationTime <= EndDate)
  1400. .Select((x, o) => new
  1401. {
  1402. o.Id,
  1403. OrgCode = IsCenter == true ? o.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : o.ActualHandleOrgCode.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1404. PublishState = x.PublishState,
  1405. Status = o.Status
  1406. })
  1407. .MergeTable()
  1408. .WhereIF(IsCenter == false, it => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1409. .GroupBy(it => new { it.OrgCode })
  1410. .Select(it => new DepartmentalProcessingStatisticsDataDto
  1411. {
  1412. OrgCode = it.OrgCode,
  1413. OrderCountNum = 0,//总量
  1414. YBOrderCountNum = 0,//已办
  1415. ZBOrderCountNum = 0,//在办
  1416. Archived = 0,
  1417. ToBeArchived = 0,
  1418. WaitPublished = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status == EOrderStatus.Filed, 1, 0)),//待发布 --已归档的就是待发布
  1419. PublishedOpen = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Published && it.PublishState, 1, 0)),//已发布公开
  1420. PublishedNoOpen = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Published && !it.PublishState, 1, 0)),//已发布不公开
  1421. YBOverdue = 0,
  1422. ZBOverdue = 0,
  1423. CompleteOnTime = 0,
  1424. HQYBOverdue = 0,
  1425. HQZBOverdue = 0,
  1426. DelayEnd = 0,
  1427. DelayWait = 0,
  1428. OrderDelayCount = 0,
  1429. ScreenCount = 0,
  1430. ScreenApproval = 0,
  1431. ScreenPass = 0,
  1432. ScreenNotPass = 0,
  1433. SatisfactionCount = 0,
  1434. NotSatisfactionCount = 0,
  1435. })
  1436. .MergeTable();
  1437. #endregion
  1438. #region 会签(已办超期、待办超期)
  1439. //会签(已办超期、待办超期)
  1440. var queryCountersign = _workflowStepHandleRepository.Queryable()
  1441. .LeftJoin<WorkflowTrace>((x, o) => x.WorkflowStepId == o.StepId)
  1442. .Where((x, o) => o.ModuleCode == WorkflowModuleConsts.OrderHandle && o.CountersignPosition == ECountersignPosition.Multi && o.CountersignPosition == ECountersignPosition.Single && o.CreationTime >= StartDate && o.CreationTime <= EndDate)
  1443. .Select((x, o) => new
  1444. {
  1445. OrgCode = IsCenter == true ? x.OrgId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : x.OrgId.Substring(0, _sessionContext.RequiredOrgId.Length + 3),// d.OrgId,
  1446. HandleTime = o.HandleTime,
  1447. StepExpiredTime = o.StepExpiredTime,
  1448. Status = o.Status
  1449. })
  1450. .MergeTable()
  1451. .WhereIF(IsCenter == false, it => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1452. .GroupBy(d => new { d.OrgCode })
  1453. .Select(d => new DepartmentalProcessingStatisticsDataDto
  1454. {
  1455. OrgCode = d.OrgCode,
  1456. OrderCountNum = 0,//总量
  1457. YBOrderCountNum = 0,//已办
  1458. ZBOrderCountNum = 0,//在办
  1459. Archived = 0,
  1460. ToBeArchived = 0,
  1461. WaitPublished = 0,
  1462. PublishedOpen = 0,
  1463. PublishedNoOpen = 0,
  1464. YBOverdue = 0,
  1465. ZBOverdue = 0,
  1466. CompleteOnTime = 0,
  1467. HQYBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status == EWorkflowStepStatus.Handled && d.HandleTime > d.StepExpiredTime, 1, 0)),
  1468. HQZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status != EWorkflowStepStatus.Handled && DateTime.Now >= d.StepExpiredTime, 1, 0)),
  1469. DelayEnd = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status == EWorkflowStepStatus.Handled, 1, 0)),
  1470. DelayWait = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status != EWorkflowStepStatus.Handled, 1, 0)),
  1471. OrderDelayCount = 0,
  1472. ScreenCount = 0,
  1473. ScreenApproval = 0,
  1474. ScreenPass = 0,
  1475. ScreenNotPass = 0,
  1476. SatisfactionCount = 0,
  1477. NotSatisfactionCount = 0,
  1478. })
  1479. .MergeTable();
  1480. #endregion
  1481. #region 延期
  1482. //延期
  1483. var orderDelay = _orderDelayRepository.Queryable()
  1484. .Where(x => x.CreationTime >= StartDate&& x.CreationTime <= EndDate)
  1485. .Select(x => new
  1486. {
  1487. OrgCode = IsCenter == true ? x.ApplyOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : x.ApplyOrgCode.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1488. x.DelayState
  1489. })
  1490. .MergeTable()
  1491. .WhereIF(IsCenter == false, it => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1492. .GroupBy(x => new { x.OrgCode })
  1493. .Select(x => new DepartmentalProcessingStatisticsDataDto
  1494. {
  1495. OrgCode = x.OrgCode,
  1496. OrderCountNum = 0,//总量
  1497. YBOrderCountNum = 0,//已办
  1498. ZBOrderCountNum = 0,//在办
  1499. Archived = 0,
  1500. ToBeArchived = 0,
  1501. WaitPublished = 0,
  1502. PublishedOpen = 0,
  1503. PublishedNoOpen = 0,
  1504. YBOverdue = 0,
  1505. ZBOverdue = 0,
  1506. CompleteOnTime = 0,
  1507. HQYBOverdue = 0,
  1508. HQZBOverdue = 0,
  1509. DelayEnd = 0,
  1510. DelayWait = 0,
  1511. OrderDelayCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState != EDelayState.Withdraw, 1, 0)),
  1512. ScreenCount = 0,
  1513. ScreenApproval = 0,
  1514. ScreenPass = 0,
  1515. ScreenNotPass = 0,
  1516. SatisfactionCount = 0,
  1517. NotSatisfactionCount = 0,
  1518. })
  1519. .MergeTable();
  1520. #endregion
  1521. #region 甄别
  1522. //甄别
  1523. var orderScreen = _orderScreenRepository.Queryable()
  1524. .Where(x => x.CreationTime >= StartDate&& x.CreationTime <= EndDate)
  1525. .WhereIF(!string.IsNullOrEmpty(OrgName), x => x.CreatorOrgId.Contains(OrgName))
  1526. .Select(x => new
  1527. {
  1528. x.Id,
  1529. OrgCode = IsCenter == true ? x.CreatorOrgId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : x.CreatorOrgId.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1530. Status = x.Status
  1531. })
  1532. .MergeTable()
  1533. .WhereIF(IsCenter == false, it => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1534. .GroupBy(x => new { x.OrgCode })
  1535. .Select(x => new DepartmentalProcessingStatisticsDataDto
  1536. {
  1537. OrgCode = x.OrgCode,
  1538. OrderCountNum = 0,//总量
  1539. YBOrderCountNum = 0,//已办
  1540. ZBOrderCountNum = 0,//在办
  1541. Archived = 0,
  1542. ToBeArchived = 0,
  1543. WaitPublished = 0,
  1544. PublishedOpen = 0,
  1545. PublishedNoOpen = 0,
  1546. YBOverdue = 0,
  1547. ZBOverdue = 0,
  1548. CompleteOnTime = 0,
  1549. HQYBOverdue = 0,
  1550. HQZBOverdue = 0,
  1551. DelayEnd = 0,
  1552. DelayWait = 0,
  1553. OrderDelayCount = 0,
  1554. ScreenCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.Id != null, 1, 0)),
  1555. ScreenApproval = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status == EScreenStatus.Approval || x.Status == EScreenStatus.Apply, 1, 0)),
  1556. ScreenPass = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status == EScreenStatus.End, 1, 0)),
  1557. ScreenNotPass = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status == EScreenStatus.Refuse, 1, 0)),
  1558. SatisfactionCount = 0,
  1559. NotSatisfactionCount = 0,
  1560. })
  1561. .MergeTable();
  1562. #endregion
  1563. #region 满意度
  1564. //满意度
  1565. var orderVisit = _orderVisitDetailRepository.Queryable()
  1566. .Where(x => x.OrderVisit.VisitTime >= StartDate && x.OrderVisit.VisitTime <= EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited && !string.IsNullOrEmpty(x.VisitOrgCode))
  1567. .Select(x => new
  1568. {
  1569. OrgCode = IsCenter == true ? x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) : x.VisitOrgCode.Substring(0, _sessionContext.RequiredOrgId.Length + 3),
  1570. x.OrgProcessingResults
  1571. })
  1572. .MergeTable()
  1573. .WhereIF(IsCenter == false, it => it.OrgCode.StartsWith(_sessionContext.RequiredOrgId))
  1574. .GroupBy(x => new { x.OrgCode })
  1575. .Select(x => new DepartmentalProcessingStatisticsDataDto
  1576. {
  1577. OrgCode = x.OrgCode,
  1578. OrderCountNum = 0,//总量
  1579. YBOrderCountNum = 0,//已办
  1580. ZBOrderCountNum = 0,//在办
  1581. Archived = 0,
  1582. ToBeArchived = 0,
  1583. WaitPublished = 0,
  1584. PublishedOpen = 0,
  1585. PublishedNoOpen = 0,
  1586. YBOverdue = 0,
  1587. ZBOverdue = 0,
  1588. CompleteOnTime = 0,
  1589. HQYBOverdue = 0,
  1590. HQZBOverdue = 0,
  1591. DelayEnd = 0,
  1592. DelayWait = 0,
  1593. OrderDelayCount = 0,
  1594. ScreenCount = 0,
  1595. ScreenApproval = 0,
  1596. ScreenPass = 0,
  1597. ScreenNotPass = 0,
  1598. SatisfactionCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "2", 1, 0)),
  1599. NotSatisfactionCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2", 1, 0))
  1600. })
  1601. .MergeTable();
  1602. #endregion
  1603. //联合查询
  1604. var items = await _orderRepository.OrderUnionAll(queryOrder, queryPublish, queryCountersign, orderDelay, orderScreen, orderVisit)
  1605. .LeftJoin<SystemOrganize>((p, o) => p.OrgCode == o.Id)
  1606. .Select((p, o) => new DepartmentalProcessingStatisticsDataDto
  1607. {
  1608. OrgCode = p.OrgCode,
  1609. OrgName = o.Name,
  1610. OrgType = o.OrgType,
  1611. OrderCountNum = p.OrderCountNum,
  1612. YBOrderCountNum = p.YBOrderCountNum,
  1613. ZBOrderCountNum = p.ZBOrderCountNum,
  1614. Archived = p.Archived,
  1615. ToBeArchived = p.ToBeArchived,
  1616. WaitPublished = p.WaitPublished,
  1617. PublishedOpen = p.PublishedOpen,
  1618. PublishedNoOpen = p.PublishedNoOpen,
  1619. YBOverdue = p.YBOverdue,
  1620. ZBOverdue = p.ZBOverdue,
  1621. CompleteOnTime = p.CompleteOnTime,
  1622. HQYBOverdue = p.HQYBOverdue,
  1623. HQZBOverdue = p.HQZBOverdue,
  1624. DelayEnd = p.DelayEnd,
  1625. DelayWait = p.DelayWait,
  1626. OrderDelayCount = p.OrderDelayCount,
  1627. ScreenCount = p.ScreenCount,
  1628. ScreenApproval = p.ScreenApproval,
  1629. ScreenPass = p.ScreenPass,
  1630. ScreenNotPass = p.ScreenNotPass,
  1631. SatisfactionCount = p.SatisfactionCount,
  1632. NotSatisfactionCount = p.NotSatisfactionCount
  1633. })
  1634. .MergeTable()
  1635. .WhereIF(string.IsNullOrEmpty(OrgName) == false, x => x.OrgName.Contains(OrgName))
  1636. .ToListAsync();
  1637. var total = new DepartmentalProcessingStatisticsDataDto
  1638. {
  1639. OrgCode = "",
  1640. OrgName = "合计",
  1641. OrgType = EOrgType.City,
  1642. OrderCountNum = items.Sum(p => p.OrderCountNum),
  1643. YBOrderCountNum = items.Sum(p => p.YBOrderCountNum),
  1644. ZBOrderCountNum = items.Sum(p => p.ZBOrderCountNum),
  1645. Archived = items.Sum(p => p.Archived),
  1646. ToBeArchived = items.Sum(p => p.ToBeArchived),
  1647. WaitPublished = items.Sum(p => p.WaitPublished),
  1648. PublishedOpen = items.Sum(p => p.PublishedOpen),
  1649. PublishedNoOpen = items.Sum(p => p.PublishedNoOpen),
  1650. YBOverdue = items.Sum(p => p.YBOverdue),
  1651. ZBOverdue = items.Sum(p => p.ZBOverdue),
  1652. CompleteOnTime=items.Sum(p=>p.CompleteOnTime),
  1653. HQYBOverdue = items.Sum(p => p.HQYBOverdue),
  1654. HQZBOverdue = items.Sum(p => p.HQZBOverdue),
  1655. DelayEnd = items.Sum(p => p.DelayEnd),
  1656. DelayWait = items.Sum(p => p.DelayWait),
  1657. OrderDelayCount = items.Sum(p => p.OrderDelayCount),
  1658. ScreenCount = items.Sum(p => p.ScreenCount),
  1659. ScreenApproval = items.Sum(p => p.ScreenApproval),
  1660. ScreenPass = items.Sum(p => p.ScreenPass),
  1661. ScreenNotPass = items.Sum(p => p.ScreenNotPass),
  1662. SatisfactionCount = items.Sum(p => p.SatisfactionCount),
  1663. NotSatisfactionCount = items.Sum(p => p.NotSatisfactionCount)
  1664. };
  1665. return new { List = items, Total = total };
  1666. }
  1667. /// <summary>
  1668. /// 部门办件统计表--子级
  1669. /// </summary>
  1670. /// <param name="StartDate"></param>
  1671. /// <param name="EndDate"></param>
  1672. /// <param name="OrgCode"></param>
  1673. /// <param name="OrgName"></param>
  1674. /// <returns></returns>
  1675. [HttpGet("departmental_processing_child_statistics")]
  1676. public async Task<object> DepartmentalProcessingChildStatistics(DateTime StartDate, DateTime EndDate, string OrgCode, string? OrgName)
  1677. {
  1678. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  1679. #region 工单
  1680. //工单
  1681. var queryOrder = _orderRepository.Queryable()
  1682. .Where(it => it.CreationTime >= StartDate && it.CreationTime <= EndDate && it.Status > EOrderStatus.WaitForAccept)
  1683. .WhereIF(OrgCode == "001", it => it.ActualHandleOrgCode == OrgCode)
  1684. .WhereIF(OrgCode != "001", it => it.ActualHandleOrgCode.StartsWith(OrgCode))
  1685. .Select(it => new
  1686. {
  1687. it.Id,
  1688. OrgCode = it.ActualHandleOrgCode.Substring(0, OrgCode.Length + 3),
  1689. it.ActualHandleOrgCode,
  1690. it.Status,//工单状态
  1691. it.ExpiredTime,//期满时间
  1692. it.ActualHandleTime,//办理时间
  1693. it.CounterSignType,//会签
  1694. })
  1695. .MergeTable()
  1696. .GroupBy(it => new
  1697. {
  1698. it.OrgCode
  1699. })
  1700. .Select(it => new DepartmentalProcessingStatisticsDataDto
  1701. {
  1702. OrgCode = it.OrgCode,
  1703. OrderCountNum = SqlFunc.AggregateCount(it.OrgCode),//总量
  1704. YBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed, 1, 0)),//已办
  1705. ZBOrderCountNum = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status < EOrderStatus.Filed, 1, 0)),//在办
  1706. Archived = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed, 1, 0)),//已归档
  1707. ToBeArchived = 0,
  1708. WaitPublished = 0,
  1709. PublishedOpen = 0,
  1710. PublishedNoOpen = 0,
  1711. YBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ActualHandleTime > it.ExpiredTime, 1, 0)),//已办超期
  1712. ZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status < EOrderStatus.Filed && it.ExpiredTime < SqlFunc.GetDate(), 1, 0)),//待办超期
  1713. CompleteOnTime = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed && it.ActualHandleTime <= it.ExpiredTime, 1, 0)),//按时办结
  1714. HQYBOverdue = 0,
  1715. HQZBOverdue = 0,
  1716. DelayEnd = 0,
  1717. DelayWait = 0,
  1718. OrderDelayCount = 0,
  1719. ScreenCount = 0,
  1720. ScreenApproval = 0,
  1721. ScreenPass = 0,
  1722. ScreenNotPass = 0,
  1723. SatisfactionCount = 0,
  1724. NotSatisfactionCount = 0
  1725. })
  1726. .MergeTable();
  1727. #endregion
  1728. #region 发布
  1729. //发布
  1730. var queryPublish = _orderPublishRepository.Queryable()
  1731. .LeftJoin<Order>((x, o) => x.OrderId == o.Id)
  1732. .Where((x, o) => x.CreationTime >= StartDate && x.CreationTime <= EndDate)
  1733. .WhereIF(OrgCode == "001", (x, o) => o.ActualHandleOrgCode == OrgCode)
  1734. .WhereIF(OrgCode != "001", (x, o) => o.ActualHandleOrgCode.StartsWith(OrgCode))
  1735. .Select((x, o) => new
  1736. {
  1737. o.Id,
  1738. OrgCode = o.ActualHandleOrgCode.Substring(0, OrgCode.Length + 3),
  1739. PublishState = x.PublishState,
  1740. Status = o.Status
  1741. })
  1742. .MergeTable()
  1743. .GroupBy(it => new { it.OrgCode })
  1744. .Select(it => new DepartmentalProcessingStatisticsDataDto
  1745. {
  1746. OrgCode = it.OrgCode,
  1747. OrderCountNum = 0,//总量
  1748. YBOrderCountNum = 0,//已办
  1749. ZBOrderCountNum = 0,//在办
  1750. Archived = 0,
  1751. ToBeArchived = 0,
  1752. WaitPublished = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status == EOrderStatus.Filed, 1, 0)),//待发布 --已归档的就是待发布
  1753. PublishedOpen = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Published && it.PublishState, 1, 0)),//已发布公开
  1754. PublishedNoOpen = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Published && !it.PublishState, 1, 0)),//已发布不公开
  1755. YBOverdue = 0,
  1756. ZBOverdue = 0,
  1757. CompleteOnTime =0,
  1758. HQYBOverdue = 0,
  1759. HQZBOverdue = 0,
  1760. DelayEnd = 0,
  1761. DelayWait = 0,
  1762. OrderDelayCount = 0,
  1763. ScreenCount = 0,
  1764. ScreenApproval = 0,
  1765. ScreenPass = 0,
  1766. ScreenNotPass = 0,
  1767. SatisfactionCount = 0,
  1768. NotSatisfactionCount = 0,
  1769. })
  1770. .MergeTable();
  1771. #endregion
  1772. #region 会签(已办超期、待办超期)
  1773. //会签(已办超期、待办超期)
  1774. var queryCountersign = _workflowStepHandleRepository.Queryable()
  1775. .LeftJoin<WorkflowTrace>((x, o) => x.WorkflowStepId == o.StepId)
  1776. .Where((x, o) => o.ModuleCode == WorkflowModuleConsts.OrderHandle && o.CountersignPosition == ECountersignPosition.Multi && o.CountersignPosition == ECountersignPosition.Single && o.CreationTime >= StartDate && o.CreationTime <= EndDate)
  1777. .WhereIF(OrgCode == "001", (x, o) => x.OrgId == OrgCode)
  1778. .WhereIF(OrgCode != "001", (x, o) => x.OrgId.StartsWith(OrgCode))
  1779. .Select((x, o) => new
  1780. {
  1781. OrgCode = x.OrgId.Substring(0, OrgCode.Length + 3),
  1782. HandleTime = o.HandleTime,
  1783. StepExpiredTime = o.StepExpiredTime,
  1784. Status = o.Status
  1785. })
  1786. .MergeTable()
  1787. .GroupBy(d => new { d.OrgCode })
  1788. .Select(d => new DepartmentalProcessingStatisticsDataDto
  1789. {
  1790. OrgCode = d.OrgCode,
  1791. OrderCountNum = 0,//总量
  1792. YBOrderCountNum = 0,//已办
  1793. ZBOrderCountNum = 0,//在办
  1794. Archived = 0,
  1795. ToBeArchived = 0,
  1796. WaitPublished = 0,
  1797. PublishedOpen = 0,
  1798. PublishedNoOpen = 0,
  1799. YBOverdue = 0,
  1800. ZBOverdue = 0,
  1801. CompleteOnTime = 0,
  1802. HQYBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status == EWorkflowStepStatus.Handled && d.HandleTime > d.StepExpiredTime, 1, 0)),
  1803. HQZBOverdue = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status != EWorkflowStepStatus.Handled && DateTime.Now >= d.StepExpiredTime, 1, 0)),
  1804. DelayEnd = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status == EWorkflowStepStatus.Handled, 1, 0)),
  1805. DelayWait = SqlFunc.AggregateSum(SqlFunc.IIF(d.Status != EWorkflowStepStatus.Handled, 1, 0)),
  1806. OrderDelayCount = 0,
  1807. ScreenCount = 0,
  1808. ScreenApproval = 0,
  1809. ScreenPass = 0,
  1810. ScreenNotPass = 0,
  1811. SatisfactionCount = 0,
  1812. NotSatisfactionCount = 0,
  1813. })
  1814. .MergeTable();
  1815. #endregion
  1816. #region 延期
  1817. //延期
  1818. var orderDelay = _orderDelayRepository.Queryable()
  1819. .Where(x => x.CreationTime >= StartDate&& x.CreationTime <= EndDate)
  1820. .WhereIF(OrgCode == "001", x => x.ApplyOrgCode == OrgCode)
  1821. .WhereIF(OrgCode != "001", x => x.ApplyOrgCode.StartsWith(OrgCode))
  1822. .Select(x => new
  1823. {
  1824. OrgCode = x.ApplyOrgCode.Substring(0, OrgCode.Length + 3),
  1825. x.DelayState
  1826. })
  1827. .MergeTable()
  1828. .GroupBy(x => new { x.OrgCode })
  1829. .Select(x => new DepartmentalProcessingStatisticsDataDto
  1830. {
  1831. OrgCode = x.OrgCode,
  1832. OrderCountNum = 0,//总量
  1833. YBOrderCountNum = 0,//已办
  1834. ZBOrderCountNum = 0,//在办
  1835. Archived = 0,
  1836. ToBeArchived = 0,
  1837. WaitPublished = 0,
  1838. PublishedOpen = 0,
  1839. PublishedNoOpen = 0,
  1840. YBOverdue = 0,
  1841. ZBOverdue = 0,
  1842. CompleteOnTime = 0,
  1843. HQYBOverdue = 0,
  1844. HQZBOverdue = 0,
  1845. DelayEnd = 0,
  1846. DelayWait = 0,
  1847. OrderDelayCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.DelayState != EDelayState.Withdraw, 1, 0)),
  1848. ScreenCount = 0,
  1849. ScreenApproval = 0,
  1850. ScreenPass = 0,
  1851. ScreenNotPass = 0,
  1852. SatisfactionCount = 0,
  1853. NotSatisfactionCount = 0,
  1854. })
  1855. .MergeTable();
  1856. #endregion
  1857. #region 甄别
  1858. //甄别
  1859. var orderScreen = _orderScreenRepository.Queryable()
  1860. .Where(x => x.CreationTime >= StartDate&& x.CreationTime <= EndDate)
  1861. .WhereIF(!string.IsNullOrEmpty(OrgName), x => x.CreatorOrgId.Contains(OrgName))
  1862. .WhereIF(OrgCode == "001", x => x.CreatorOrgId == OrgCode)
  1863. .WhereIF(OrgCode != "001", x => x.CreatorOrgId.StartsWith(OrgCode))
  1864. .Select(x => new
  1865. {
  1866. x.Id,
  1867. OrgCode = x.CreatorOrgId.Substring(0, OrgCode.Length + 3),
  1868. Status = x.Status
  1869. })
  1870. .MergeTable()
  1871. .GroupBy(x => new { x.OrgCode })
  1872. .Select(x => new DepartmentalProcessingStatisticsDataDto
  1873. {
  1874. OrgCode = x.OrgCode,
  1875. OrderCountNum = 0,//总量
  1876. YBOrderCountNum = 0,//已办
  1877. ZBOrderCountNum = 0,//在办
  1878. Archived = 0,
  1879. ToBeArchived = 0,
  1880. WaitPublished = 0,
  1881. PublishedOpen = 0,
  1882. PublishedNoOpen = 0,
  1883. YBOverdue = 0,
  1884. ZBOverdue = 0,
  1885. CompleteOnTime = 0,
  1886. HQYBOverdue = 0,
  1887. HQZBOverdue = 0,
  1888. DelayEnd = 0,
  1889. DelayWait = 0,
  1890. OrderDelayCount = 0,
  1891. ScreenCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.Id != null, 1, 0)),
  1892. ScreenApproval = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status == EScreenStatus.Approval || x.Status == EScreenStatus.Apply, 1, 0)),
  1893. ScreenPass = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status == EScreenStatus.End, 1, 0)),
  1894. ScreenNotPass = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status == EScreenStatus.Refuse, 1, 0)),
  1895. SatisfactionCount = 0,
  1896. NotSatisfactionCount = 0,
  1897. })
  1898. .MergeTable();
  1899. #endregion
  1900. #region 满意度
  1901. //满意度
  1902. var orderVisit = _orderVisitDetailRepository.Queryable()
  1903. .Where(x => x.OrderVisit.VisitTime >= StartDate && x.OrderVisit.VisitTime <= EndDate && x.VisitTarget == EVisitTarget.Org && x.OrderVisit.VisitState == EVisitState.Visited && !string.IsNullOrEmpty(x.VisitOrgCode))
  1904. .WhereIF(OrgCode == "001", x => x.VisitOrgCode == OrgCode)
  1905. .WhereIF(OrgCode != "001", x => x.VisitOrgCode.StartsWith(OrgCode))
  1906. .Select(x => new
  1907. {
  1908. OrgCode = x.VisitOrgCode.Substring(0, OrgCode.Length + 3),
  1909. x.OrgProcessingResults
  1910. })
  1911. .MergeTable()
  1912. .GroupBy(x => new { x.OrgCode })
  1913. .Select(x => new DepartmentalProcessingStatisticsDataDto
  1914. {
  1915. OrgCode = x.OrgCode,
  1916. OrderCountNum = 0,//总量
  1917. YBOrderCountNum = 0,//已办
  1918. ZBOrderCountNum = 0,//在办
  1919. Archived = 0,
  1920. ToBeArchived = 0,
  1921. WaitPublished = 0,
  1922. PublishedOpen = 0,
  1923. PublishedNoOpen = 0,
  1924. YBOverdue = 0,
  1925. ZBOverdue = 0,
  1926. CompleteOnTime = 0,
  1927. HQYBOverdue = 0,
  1928. HQZBOverdue = 0,
  1929. DelayEnd = 0,
  1930. DelayWait = 0,
  1931. OrderDelayCount = 0,
  1932. ScreenCount = 0,
  1933. ScreenApproval = 0,
  1934. ScreenPass = 0,
  1935. ScreenNotPass = 0,
  1936. SatisfactionCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "2", 1, 0)),
  1937. NotSatisfactionCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2", 1, 0))
  1938. })
  1939. .MergeTable();
  1940. #endregion
  1941. //联合查询
  1942. var items = await _orderRepository.OrderUnionAll(queryOrder, queryPublish, queryCountersign, orderDelay, orderScreen, orderVisit)
  1943. .LeftJoin<SystemOrganize>((p, o) => p.OrgCode == o.Id)
  1944. .Select((p, o) => new DepartmentalProcessingStatisticsDataDto
  1945. {
  1946. OrgCode = p.OrgCode,
  1947. OrgName = o.Name,
  1948. OrgType = o.OrgType,
  1949. OrderCountNum = p.OrderCountNum,
  1950. YBOrderCountNum = p.YBOrderCountNum,
  1951. ZBOrderCountNum = p.ZBOrderCountNum,
  1952. Archived = p.Archived,
  1953. ToBeArchived = p.ToBeArchived,
  1954. WaitPublished = p.WaitPublished,
  1955. PublishedOpen = p.PublishedOpen,
  1956. PublishedNoOpen = p.PublishedNoOpen,
  1957. YBOverdue = p.YBOverdue,
  1958. ZBOverdue = p.ZBOverdue,
  1959. CompleteOnTime = p.CompleteOnTime,
  1960. HQYBOverdue = p.HQYBOverdue,
  1961. HQZBOverdue = p.HQZBOverdue,
  1962. DelayEnd = p.DelayEnd,
  1963. DelayWait = p.DelayWait,
  1964. OrderDelayCount = p.OrderDelayCount,
  1965. ScreenCount = p.ScreenCount,
  1966. ScreenApproval = p.ScreenApproval,
  1967. ScreenPass = p.ScreenPass,
  1968. ScreenNotPass = p.ScreenNotPass,
  1969. SatisfactionCount = p.SatisfactionCount,
  1970. NotSatisfactionCount = p.NotSatisfactionCount
  1971. })
  1972. .MergeTable()
  1973. .WhereIF(string.IsNullOrEmpty(OrgName) == false, x => x.OrgName.Contains(OrgName))
  1974. .ToListAsync();
  1975. //计算合计
  1976. var total = new DepartmentalProcessingStatisticsDataDto
  1977. {
  1978. OrgCode = "",
  1979. OrgName = "合计",
  1980. OrgType = EOrgType.City,
  1981. OrderCountNum = items.Sum(p => p.OrderCountNum),
  1982. YBOrderCountNum = items.Sum(p => p.YBOrderCountNum),
  1983. ZBOrderCountNum = items.Sum(p => p.ZBOrderCountNum),
  1984. Archived = items.Sum(p => p.Archived),
  1985. ToBeArchived = items.Sum(p => p.ToBeArchived),
  1986. WaitPublished = items.Sum(p => p.WaitPublished),
  1987. PublishedOpen = items.Sum(p => p.PublishedOpen),
  1988. PublishedNoOpen = items.Sum(p => p.PublishedNoOpen),
  1989. YBOverdue = items.Sum(p => p.YBOverdue),
  1990. ZBOverdue = items.Sum(p => p.ZBOverdue),
  1991. CompleteOnTime =items.Sum(p=>p.CompleteOnTime),
  1992. HQYBOverdue = items.Sum(p => p.HQYBOverdue),
  1993. HQZBOverdue = items.Sum(p => p.HQZBOverdue),
  1994. DelayEnd = items.Sum(p => p.DelayEnd),
  1995. DelayWait = items.Sum(p => p.DelayWait),
  1996. OrderDelayCount = items.Sum(p => p.OrderDelayCount),
  1997. ScreenCount = items.Sum(p => p.ScreenCount),
  1998. ScreenApproval = items.Sum(p => p.ScreenApproval),
  1999. ScreenPass = items.Sum(p => p.ScreenPass),
  2000. ScreenNotPass = items.Sum(p => p.ScreenNotPass),
  2001. SatisfactionCount = items.Sum(p => p.SatisfactionCount),
  2002. NotSatisfactionCount = items.Sum(p => p.NotSatisfactionCount)
  2003. };
  2004. return new { List = items, Total = total };
  2005. }
  2006. /// <summary>
  2007. /// 部门办件统计表--明细
  2008. /// </summary>
  2009. /// <param name="dto"></param>
  2010. /// <returns></returns>
  2011. [HttpGet("departmental_processing_statistics_list")]
  2012. public async Task<PagedDto<OrderDto>> GetDepartmentalProcessingStatisticsList([FromQuery] DepartmentalProcessingStatisticsRequest dto)
  2013. {
  2014. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  2015. RefAsync<int> total = 0;
  2016. string stye = "";
  2017. switch (dto.StatisticsType)
  2018. {
  2019. case EStatisticsType.YBOrderCountNum:
  2020. case EStatisticsType.ZBOrderCountNum:
  2021. case EStatisticsType.ToBeArchived:
  2022. case EStatisticsType.Archived:
  2023. case EStatisticsType.YBOverdue:
  2024. case EStatisticsType.ZBOverdue:
  2025. //工单
  2026. stye = "1";
  2027. break;
  2028. case EStatisticsType.WaitPublished:
  2029. case EStatisticsType.PublishedOpen:
  2030. case EStatisticsType.PublishedNoOpen:
  2031. //发布
  2032. stye = "2";
  2033. break;
  2034. case EStatisticsType.OrderDelayCount:
  2035. //延期
  2036. stye = "3";
  2037. break;
  2038. case EStatisticsType.ScreenCount:
  2039. case EStatisticsType.ScreenApproval:
  2040. case EStatisticsType.ScreenPass:
  2041. case EStatisticsType.ScreenNotPass:
  2042. //甄别
  2043. stye = "4";
  2044. break;
  2045. case EStatisticsType.HQYBOverdue:
  2046. case EStatisticsType.HQZBOverdue:
  2047. case EStatisticsType.DelayEnd:
  2048. case EStatisticsType.DelayWait:
  2049. //会签
  2050. stye = "5";
  2051. break;
  2052. case EStatisticsType.SubtotalOverdue:
  2053. //超期总数
  2054. stye = "6";
  2055. break;
  2056. default:
  2057. break;
  2058. }
  2059. #region 工单
  2060. if (stye == "1")
  2061. {
  2062. //工单
  2063. var (totalOrder, items) = await _orderRepository.Queryable()
  2064. .Where(it => it.CreationTime >= dto.StartDate && it.CreationTime <= dto.EndDate && it.Status > EOrderStatus.WaitForAccept)
  2065. .WhereIF(dto.OrgCode == "001", it => it.ActualHandleOrgCode == dto.OrgCode)
  2066. .WhereIF(dto.OrgCode != "001", it => it.ActualHandleOrgCode.StartsWith(dto.OrgCode))
  2067. .WhereIF(dto.StatisticsType == EStatisticsType.YBOrderCountNum, it => it.Status >= EOrderStatus.Filed)//已办
  2068. .WhereIF(dto.StatisticsType == EStatisticsType.ZBOrderCountNum, it => it.Status < EOrderStatus.Filed)//在办
  2069. .WhereIF(dto.StatisticsType == EStatisticsType.Archived, it => it.Status >= EOrderStatus.Filed)//已归档
  2070. .WhereIF(dto.StatisticsType == EStatisticsType.ToBeArchived, it => it.Status < EOrderStatus.WaitForAccept)//待归档--没得待归档数据
  2071. .WhereIF(dto.StatisticsType == EStatisticsType.YBOverdue, it => it.Status >= EOrderStatus.Filed && it.ActualHandleTime > it.ExpiredTime)//已办超期
  2072. .WhereIF(dto.StatisticsType == EStatisticsType.ZBOverdue, it => it.Status < EOrderStatus.Filed && it.ExpiredTime < SqlFunc.GetDate())//待办超期
  2073. .OrderByDescending(it => it.CreationTime)
  2074. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  2075. return new PagedDto<OrderDto>(totalOrder, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  2076. }
  2077. #endregion
  2078. #region 发布
  2079. if (stye == "2")
  2080. {
  2081. //发布
  2082. var queryPublish = await _orderPublishRepository.Queryable()
  2083. .LeftJoin<Order>((x, o) => x.OrderId == o.Id)
  2084. .Where((x, o) => x.CreationTime >= dto.StartDate && x.CreationTime <= dto.EndDate)
  2085. .WhereIF(dto.OrgCode == "001", (x, o) => o.ActualHandleOrgCode == dto.OrgCode)
  2086. .WhereIF(dto.OrgCode != "001", (x, o) => o.ActualHandleOrgCode.StartsWith(dto.OrgCode))
  2087. .WhereIF(dto.StatisticsType == EStatisticsType.WaitPublished, (x, o) => o.Status == EOrderStatus.Filed)//待发布 --已归档的就是待发布
  2088. .WhereIF(dto.StatisticsType == EStatisticsType.PublishedOpen, (x, o) => o.Status >= EOrderStatus.Published && x.PublishState)//已发布公开
  2089. .WhereIF(dto.StatisticsType == EStatisticsType.PublishedNoOpen, (x, o) => o.Status == EOrderStatus.Published && !x.PublishState)//已发布不公开
  2090. .OrderByDescending((x, o) => o.CreationTime)
  2091. .Select((x, o) => new { o })
  2092. .ToPageListAsync(dto.PageIndex, dto.PageSize, total, HttpContext.RequestAborted);
  2093. var dtos = queryPublish.Select(d =>
  2094. {
  2095. var dto = _mapper.Map<OrderDto>(d.o);
  2096. return dto;
  2097. }).ToList();
  2098. return new PagedDto<OrderDto>(total, dtos);
  2099. }
  2100. #endregion
  2101. #region 延期
  2102. if (stye == "3")
  2103. {
  2104. //延期
  2105. var orderDelay = await _orderDelayRepository.Queryable()
  2106. .LeftJoin<Order>((x, o) => x.OrderId == o.Id)
  2107. .Where((x, o) => x.CreationTime >= dto.StartDate && x.CreationTime <= dto.EndDate)
  2108. .WhereIF(dto.OrgCode == "001", (x, o) => x.ApplyOrgCode == dto.OrgCode)
  2109. .WhereIF(dto.OrgCode != "001", (x, o) => x.ApplyOrgCode.StartsWith(dto.OrgCode))
  2110. .WhereIF(dto.StatisticsType == EStatisticsType.OrderDelayCount, (x, o) => x.DelayState != EDelayState.Withdraw)//延期次数
  2111. .OrderByDescending((x, o) => o.CreationTime)
  2112. .Select((x, o) => new { o })
  2113. .ToPageListAsync(dto.PageIndex, dto.PageSize, total, HttpContext.RequestAborted);
  2114. var dtos = orderDelay.Select(d =>
  2115. {
  2116. var dto = _mapper.Map<OrderDto>(d.o);
  2117. return dto;
  2118. }).ToList();
  2119. return new PagedDto<OrderDto>(total, dtos);
  2120. }
  2121. #endregion
  2122. #region 甄别
  2123. if (stye == "4")
  2124. {
  2125. //甄别
  2126. var orderScreen = await _orderScreenRepository.Queryable()
  2127. .LeftJoin<Order>((x, o) => x.OrderId == o.Id)
  2128. .Where((x, o) => x.CreationTime >= dto.StartDate && x.CreationTime <= dto.EndDate)
  2129. .WhereIF(dto.OrgCode == "001", (x, o) => x.CreatorOrgId == dto.OrgCode)
  2130. .WhereIF(dto.OrgCode != "001", (x, o) => x.CreatorOrgId.StartsWith(dto.OrgCode))
  2131. .WhereIF(dto.StatisticsType == EStatisticsType.ScreenCount, (x, o) => x.Id != null)//申请总量
  2132. .WhereIF(dto.StatisticsType == EStatisticsType.ScreenApproval, (x, o) => x.Status == EScreenStatus.Approval || x.Status == EScreenStatus.Apply)//待甄别
  2133. .WhereIF(dto.StatisticsType == EStatisticsType.ScreenPass, (x, o) => x.Status == EScreenStatus.End)//甄别通过
  2134. .WhereIF(dto.StatisticsType == EStatisticsType.ScreenNotPass, (x, o) => x.Status == EScreenStatus.Refuse)//甄别不通过
  2135. .OrderByDescending((x, o) => o.CreationTime)
  2136. .Select((x, o) => new { o })
  2137. .ToPageListAsync(dto.PageIndex, dto.PageSize, total, HttpContext.RequestAborted);
  2138. var dtos = orderScreen.Select(d =>
  2139. {
  2140. var dto = _mapper.Map<OrderDto>(d.o);
  2141. return dto;
  2142. }).ToList();
  2143. return new PagedDto<OrderDto>(total, dtos);
  2144. }
  2145. #endregion
  2146. #region 会签(已办超期、待办超期)
  2147. if (stye == "5")
  2148. {
  2149. //会签(已办超期、待办超期)
  2150. var queryCountersign = await _workflowStepHandleRepository.Queryable()
  2151. .LeftJoin<WorkflowTrace>((x, o) => x.WorkflowStepId == o.StepId)
  2152. .LeftJoin<Order>((x, o, p) => o.WorkflowId == p.WorkflowId)
  2153. .Where((x, o, p) => o.ModuleCode == WorkflowModuleConsts.OrderHandle && o.CountersignPosition == ECountersignPosition.Multi && o.CountersignPosition == ECountersignPosition.Single && o.CreationTime >= dto.StartDate && o.CreationTime <= dto.EndDate)
  2154. .WhereIF(dto.OrgCode == "001", (x, o, p) => x.OrgId == dto.OrgCode)
  2155. .WhereIF(dto.OrgCode != "001", (x, o, p) => x.OrgId.StartsWith(dto.OrgCode))
  2156. .WhereIF(dto.StatisticsType == EStatisticsType.HQYBOverdue, (x, o, p) => o.Status == EWorkflowStepStatus.Handled && o.HandleTime > o.StepExpiredTime)//会签已办超期
  2157. .WhereIF(dto.StatisticsType == EStatisticsType.HQZBOverdue, (x, o, p) => o.Status != EWorkflowStepStatus.Handled && DateTime.Now >= o.StepExpiredTime)//会签待办超期
  2158. .WhereIF(dto.StatisticsType == EStatisticsType.DelayEnd, (x, o, p) => o.Status == EWorkflowStepStatus.Handled)//会签已办
  2159. .WhereIF(dto.StatisticsType == EStatisticsType.DelayWait, (x, o, p) => o.Status != EWorkflowStepStatus.Handled)//会签待办
  2160. .OrderByDescending((x, o, p) => p.CreationTime)
  2161. .Select((x, o, p) => new { p })
  2162. .ToPageListAsync(dto.PageIndex, dto.PageSize, total, HttpContext.RequestAborted);
  2163. var dtos = queryCountersign.Select(d =>
  2164. {
  2165. var dto = _mapper.Map<OrderDto>(d.p);
  2166. return dto;
  2167. }).ToList();
  2168. return new PagedDto<OrderDto>(total, dtos);
  2169. }
  2170. #endregion
  2171. #region 超期件数
  2172. //超期件数
  2173. if (stye == "6")
  2174. {
  2175. var queryOrder = _orderRepository.Queryable()
  2176. .Where(it => it.CreationTime >= dto.StartDate && it.CreationTime <= dto.EndDate && it.Status > EOrderStatus.WaitForAccept)
  2177. .WhereIF(dto.OrgCode == "001", it => it.ActualHandleOrgCode == dto.OrgCode)
  2178. .WhereIF(dto.OrgCode != "001", it => it.ActualHandleOrgCode.StartsWith(dto.OrgCode))
  2179. .WhereIF(dto.StatisticsType == EStatisticsType.SubtotalOverdue, it => (it.Status >= EOrderStatus.Filed && it.ActualHandleTime > it.ExpiredTime)
  2180. || (it.Status < EOrderStatus.Filed && it.ExpiredTime < SqlFunc.GetDate()))//已办超期/待办超期
  2181. .Select(it => new SelectOrderId { Id = it.Id })
  2182. .MergeTable();
  2183. //会签(已办超期、待办超期)
  2184. var queryCountersign = _workflowStepHandleRepository.Queryable()
  2185. .LeftJoin<WorkflowTrace>((x, o) => x.WorkflowStepId == o.StepId)
  2186. .LeftJoin<Order>((x, o, p) => o.WorkflowId == p.WorkflowId)
  2187. .Where((x, o, p) => o.ModuleCode == WorkflowModuleConsts.OrderHandle && o.CountersignPosition == ECountersignPosition.Multi
  2188. && o.CountersignPosition == ECountersignPosition.Single && o.CreationTime >= dto.StartDate && o.CreationTime <= dto.EndDate)
  2189. .WhereIF(dto.OrgCode == "001", (x, o, p) => x.OrgId == dto.OrgCode)
  2190. .WhereIF(dto.OrgCode != "001", (x, o, p) => x.OrgId.StartsWith(dto.OrgCode))
  2191. .WhereIF(dto.StatisticsType == EStatisticsType.HQYBOverdue, (x, o, p) => (o.Status == EWorkflowStepStatus.Handled && o.HandleTime > o.StepExpiredTime)
  2192. || (o.Status != EWorkflowStepStatus.Handled && DateTime.Now >= o.StepExpiredTime))//会签已办超期/会签待办超期
  2193. .Select((x, o, p) => new SelectOrderId { Id = p.Id })
  2194. .MergeTable();
  2195. var queryData = await _orderRepository.OrderListUnionAll(queryOrder, queryCountersign)
  2196. .LeftJoin<Order>((x, o) => x.Id == o.Id)
  2197. .Select((x, o) => new { o })
  2198. .ToPageListAsync(dto.PageIndex, dto.PageSize, total, HttpContext.RequestAborted);
  2199. var dtos = queryData.Select(d =>
  2200. {
  2201. var dto = _mapper.Map<OrderDto>(d.o);
  2202. return dto;
  2203. }).ToList();
  2204. return new PagedDto<OrderDto>(total, dtos);
  2205. }
  2206. #endregion
  2207. return new PagedDto<OrderDto>(total, new List<OrderDto>());
  2208. }
  2209. /// <summary>
  2210. /// 高频来电统计
  2211. /// </summary>
  2212. /// <param name="dto"></param>
  2213. /// <returns></returns>
  2214. [HttpGet("high_frequency_call_statistics")]
  2215. public async Task<PagedDto<HighFrequencyCallStatisticsDto>> HighFrequencyCallStatistics([FromQuery] HighFrequencyCallStatisticsRequest dto)
  2216. {
  2217. if (!dto.StartDate.HasValue || !dto.EndDate.HasValue)
  2218. throw UserFriendlyException.SameMessage("请选择时间!");
  2219. dto.EndDate = dto.EndDate.Value.AddDays(1).AddSeconds(-1);
  2220. int CallCount = 2;
  2221. var HighFrequencyCallStatistics = _systemSettingCacheManager.GetSetting(SettingConstants.HighFrequencyCallStatistics)?.SettingValue[0];
  2222. if (HighFrequencyCallStatistics != null)
  2223. CallCount = int.Parse(HighFrequencyCallStatistics);
  2224. var (total, items) = await _trCallRecordRepository.Queryable()
  2225. .LeftJoin<Order>((p, o) => p.ExternalId == o.Id)
  2226. .Where((p, o) => p.OverTime >= dto.StartDate && p.OverTime <= dto.EndDate)
  2227. .Where((p, o) => p.CallOrderType == ECallOrderType.Order)
  2228. .Where((p, o) => p.ExternalId != null && o.Id != null)
  2229. .Where((p, o) => p.CallDirection == ECallDirection.In)
  2230. .WhereIF(!string.IsNullOrEmpty(dto.PhoneNum), (p, o) => p.CPN == dto.PhoneNum)
  2231. .Select((p, o) => new
  2232. {
  2233. p.CPN,
  2234. p.ExternalId
  2235. })
  2236. .MergeTable()
  2237. .GroupBy(p => p.CPN)
  2238. .Select(p => new HighFrequencyCallStatisticsDto
  2239. {
  2240. Callnum = p.CPN,
  2241. OrderCountNum = SqlFunc.AggregateCount(p.CPN),//总量
  2242. })
  2243. .MergeTable()
  2244. .Where(p => p.OrderCountNum >= CallCount)
  2245. .OrderByDescending(p => p.OrderCountNum)
  2246. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  2247. return new PagedDto<HighFrequencyCallStatisticsDto>(total, _mapper.Map<IReadOnlyList<HighFrequencyCallStatisticsDto>>(items));
  2248. }
  2249. /// <summary>
  2250. /// 高频来电统计列表详情
  2251. /// </summary>
  2252. /// <param name="dto"></param>
  2253. /// <returns></returns>
  2254. [HttpGet("high_frequency_call_statistics_order_list")]
  2255. public async Task<PagedDto<OrderDto>> HighFrequencyCallStatisticsOrderList([FromQuery] HighFrequencyCallStatisticsListRequest dto)
  2256. {
  2257. if (!dto.StartDate.HasValue || !dto.EndDate.HasValue)
  2258. throw UserFriendlyException.SameMessage("请选择时间!");
  2259. if (string.IsNullOrEmpty(dto.FromPhone))
  2260. throw UserFriendlyException.SameMessage("号码不能为空!");
  2261. dto.EndDate = dto.EndDate.Value.AddDays(1).AddSeconds(-1);
  2262. var data = await _trCallRecordRepository.Queryable()
  2263. .LeftJoin<Order>((p, o) => p.ExternalId == o.Id)
  2264. .Where((p, o) => p.OverTime >= dto.StartDate && p.OverTime <= dto.EndDate)
  2265. .Where((p, o) => p.CallOrderType == ECallOrderType.Order)
  2266. .Where((p, o) => p.ExternalId != null && o.Id != null)
  2267. .Where((p, o) => p.CPN == dto.FromPhone)
  2268. .Where((p, o) => p.CallDirection == ECallDirection.In)
  2269. .Select((p, o) =>
  2270. p.ExternalId
  2271. )
  2272. .ToListAsync();
  2273. var (total, items) = await _orderRepository.Queryable()
  2274. .Includes(x => x.OrderScreens)
  2275. .Where(p => data.Contains(p.Id))
  2276. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Title.Contains(dto.Keyword!)) //标题
  2277. .WhereIF(!string.IsNullOrEmpty(dto.ProvinceNo), d => d.ProvinceNo.Contains(dto.ProvinceNo)) //省本地编号
  2278. .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.No.Contains(dto.No)) //工单编码
  2279. .WhereIF(dto.AcceptTypes.Any(), d => dto.AcceptTypes.Contains(d.AcceptTypeCode)) //受理类型
  2280. .WhereIF(dto.Channels.Any(), d => dto.Channels.Contains(d.SourceChannelCode)) //来源渠道
  2281. .WhereIF(dto.HotspotIds.Any(), d => dto.HotspotIds.Contains(d.HotspotId)) //热点类型
  2282. .WhereIF(!string.IsNullOrEmpty(dto.TransferPhone), d => d.TransferPhone.Contains(dto.TransferPhone!)) //转接号码
  2283. .WhereIF(dto.OrgCodes.Any(), d => dto.OrgCodes.Contains(d.ActualHandleOrgCode)) //接办部门
  2284. .WhereIF(!string.IsNullOrEmpty(dto.NameOrNo), d => d.AcceptorName.Contains(dto.NameOrNo!) || d.AcceptorStaffNo.Contains(dto.NameOrNo!)) //受理人/坐席
  2285. .WhereIF(dto.CreationTimeStart.HasValue, d => d.CreationTime >= dto.CreationTimeStart) //受理时间开始
  2286. .WhereIF(dto.CreationTimeEnd.HasValue, d => d.CreationTime <= dto.CreationTimeEnd) //受理时间结束
  2287. .WhereIF(dto.EmergencyLevels.Any(), d => dto.EmergencyLevels.Contains(d.EmergencyLevel)) //紧急程度
  2288. // .WhereIF(!string.IsNullOrEmpty(dto.FromPhone), d => d.FromPhone.Contains(dto.FromPhone)) //来电号码
  2289. .WhereIF(!string.IsNullOrEmpty(dto.PhoneNo), d => d.Contact.Contains(dto.PhoneNo!)) //联系电话
  2290. .WhereIF(!string.IsNullOrEmpty(dto.PushTypeCode), d => d.PushTypeCode == dto.PushTypeCode) //推送分类
  2291. .WhereIF(dto.ExpiredTimeStart.HasValue, d => d.ExpiredTime >= dto.ExpiredTimeStart) //超期时间开始
  2292. .WhereIF(dto.ExpiredTimeEnd.HasValue, d => d.ExpiredTime <= dto.ExpiredTimeEnd) //超期时间结束
  2293. .WhereIF(dto.Statuses.Any(), d => dto.Statuses.Contains(d.Status)) //工单状态
  2294. .WhereIF(dto.Statuses.Any(d => d == EOrderStatus.SpecialToUnAccept), d => d.Status <= EOrderStatus.SpecialToUnAccept)
  2295. .WhereIF(!string.IsNullOrEmpty(dto.ActualHandlerName), d => d.ActualHandlerName.Contains(dto.ActualHandlerName)) //接办人
  2296. .WhereIF(dto.IsScreen == true, d => d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //有甄别
  2297. .WhereIF(dto.IsScreen == false, d => !d.OrderScreens.Any(x => x.Status != EScreenStatus.Refuse)) //无甄别
  2298. .WhereIF(!string.IsNullOrEmpty(dto.CurrentStepCode), d => d.ActualHandleStepCode == dto.CurrentStepCode) //当前办理节点
  2299. .WhereIF(dto.ActualHandleTimeStart.HasValue, d => d.ActualHandleTime >= dto.ActualHandleTimeStart) //办结时间开始
  2300. .WhereIF(dto.ActualHandleTimeEnd.HasValue, d => d.ActualHandleTime <= dto.ActualHandleTimeEnd) //办结时间结束
  2301. .WhereIF(dto.IsOverTime == true, d => (d.ExpiredTime < DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime < d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //是 超期
  2302. .WhereIF(dto.IsOverTime == false, d => (d.ExpiredTime > DateTime.Now && d.Status < EOrderStatus.Filed) || (d.ExpiredTime > d.ActualHandleTime && d.Status >= EOrderStatus.Filed)) //否 超期
  2303. .WhereIF(dto.IdentityType != null, d => d.IdentityType == dto.IdentityType) //来电主体
  2304. .WhereIF(!string.IsNullOrEmpty(dto.FromName), d => d.FromName.Contains(dto.FromName)) //来电人姓名
  2305. .WhereIF(dto.AreaCodes.Any(), d => dto.AreaCodes.Contains(d.AreaCode)) //区域
  2306. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == true, x => x.IsProvince == true)
  2307. .WhereIF(dto.IsProvinceOrder.HasValue && dto.IsProvinceOrder == false, x => x.IsProvince == false)
  2308. .OrderByDescending(d => d.CreationTime)
  2309. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  2310. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  2311. }
  2312. /// <summary>
  2313. /// 高频事项预警
  2314. /// </summary>
  2315. /// <param name="dto"></param>
  2316. /// <returns></returns>
  2317. [HttpGet("highmatter-warning")]
  2318. public async Task<PagedDto<HighMatterWarningDto>> HighMatterWarning([FromQuery] HighMatterWarningRequest dto)
  2319. {
  2320. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  2321. List<string> filterTitle = new List<string>();
  2322. filterTitle.Add("无声");
  2323. filterTitle.Add("骚扰");
  2324. filterTitle.Add("错拨");
  2325. filterTitle.Add("测试");
  2326. var (total, items) = await _orderRepository.Queryable()
  2327. .Where(x => x.CreationTime >= dto.StartDate && x.CreationTime <= dto.EndDate)
  2328. .Where(x => filterTitle.Any(s => x.Title.Contains(s)) == false)
  2329. .LeftJoin<SystemArea>((it, o) => it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  2330. .WhereIF(dto.AreaCodes.Any(), (it, o) => dto.AreaCodes.Contains(it.AreaCode)) //区域
  2331. .WhereIF(dto.HotspotIds.Any(), (it, o) => dto.HotspotIds.Contains(it.HotspotId)) //热点类型
  2332. .WhereIF(dto.AcceptTypeCodes.Any(), (it, o) => dto.AcceptTypeCodes.Contains(it.AcceptTypeCode)) //受理类型
  2333. .GroupBy((it, o) => new
  2334. {
  2335. it.AcceptTypeCode,
  2336. it.AcceptType,
  2337. it.HotspotId,
  2338. it.HotspotName,
  2339. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  2340. o.AreaName,
  2341. })
  2342. .Having((it, o) => SqlFunc.AggregateCount(it.HotspotName) >= 5)
  2343. .Select((it, o) => new HighMatterWarningDto()
  2344. {
  2345. AcceptTypeCode = it.AcceptTypeCode,
  2346. AcceptType = it.AcceptType,
  2347. AreaName = o.AreaName,
  2348. HotspotName = it.HotspotName,
  2349. HotspotId = it.HotspotId,
  2350. SumCount = SqlFunc.AggregateCount(it.HotspotName),
  2351. Id = SqlFunc.AggregateMin(it.Id),
  2352. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  2353. })
  2354. .MergeTable()
  2355. .LeftJoin<Order>((x, d) => x.Id == d.Id)
  2356. .Select((x, d) => new HighMatterWarningDto()
  2357. {
  2358. AreaName = x.AreaName,
  2359. HotspotName = x.HotspotName,
  2360. HotspotId = x.HotspotId,
  2361. Title = d.Title,
  2362. SumCount = x.SumCount,
  2363. Id = d.Id,
  2364. AcceptTypeCode = x.AcceptTypeCode,
  2365. AcceptType = x.AcceptType,
  2366. AreaCode = x.AreaCode
  2367. })
  2368. .MergeTable()
  2369. .OrderByDescending(d => d.SumCount).ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  2370. return new PagedDto<HighMatterWarningDto>(total, _mapper.Map<IReadOnlyList<HighMatterWarningDto>>(items));
  2371. }
  2372. /// <summary>
  2373. /// 高频事项预警明细
  2374. /// </summary>
  2375. /// <param name="dto"></param>
  2376. /// <returns></returns>
  2377. [HttpGet("highmatter-warning-detail")]
  2378. public async Task<PagedDto<OrderDto>> HighMatterWarningDetail([FromQuery] HighMatterWarningDetailRequest dto)
  2379. {
  2380. dto.EndDate = dto.EndDate.AddDays(1).AddSeconds(-1);
  2381. List<string> filterTitle = new List<string>();
  2382. filterTitle.Add("无声");
  2383. filterTitle.Add("骚扰");
  2384. filterTitle.Add("错拨");
  2385. filterTitle.Add("测试");
  2386. var (total, items) = await _orderRepository.Queryable()
  2387. .Includes(x => x.OrderScreens)
  2388. .Where(d => d.AcceptTypeCode == dto.AcceptTypeCode) //受理类型
  2389. .Where(d => d.HotspotId == dto.HotspotId) //热点类型
  2390. .Where(d => d.CreationTime >= dto.StartDate) //受理时间开始
  2391. .Where(d => d.CreationTime <= dto.EndDate) //受理时间结束
  2392. .Where(d => d.AreaCode == dto.AreaCode) //区域
  2393. .Where(x => filterTitle.Any(s => x.Title.Contains(s)) == false)
  2394. .OrderByDescending(d => d.CreationTime)
  2395. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  2396. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  2397. }
  2398. /// <summary>
  2399. /// 回退错件
  2400. /// </summary>
  2401. /// <param name="dto"></param>
  2402. /// <returns></returns>
  2403. [HttpGet("reTransact")]
  2404. public async Task<PagedDto<OrderReTransactVo>> OrderReTransact([FromQuery] QueryOrderReTransactRequest dto)
  2405. {
  2406. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  2407. throw UserFriendlyException.SameMessage("请选择时间!");
  2408. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  2409. var (total, items) = await _orderSpecialDetailRepository.Queryable()
  2410. .Includes(x => x.OrderSpecial)
  2411. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.OrgName.Contains(dto.OrgName!))
  2412. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  2413. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  2414. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime)
  2415. .GroupBy(x => new { Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"), x.OrgId, x.OrgName })
  2416. .Select(x => new OrderReTransactVo
  2417. {
  2418. Time = x.OrderSpecial.CreationTime.ToString("yyyy-MM-dd"),
  2419. OrgId = x.OrgId,
  2420. OrgName = x.OrgName,
  2421. Num = SqlFunc.AggregateCount(1)
  2422. }).MergeTable()
  2423. .OrderByIF(dto.SortRule == 0, x => x.Num, OrderByType.Asc)
  2424. .OrderByIF(dto.SortRule == 1, x => x.Num, OrderByType.Desc)
  2425. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  2426. return new PagedDto<OrderReTransactVo>(total, _mapper.Map<IReadOnlyList<OrderReTransactVo>>(items));
  2427. }
  2428. /// <summary>
  2429. /// 回退错件明细
  2430. /// </summary>
  2431. /// <param name="dto"></param>
  2432. /// <returns></returns>
  2433. [HttpGet("reTransact_detail")]
  2434. public async Task<PagedDto<OrderSpecialDetailDto>> OrderReTransactDetail([FromQuery] QueryOrderReTransactDetailRequest dto)
  2435. {
  2436. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  2437. throw UserFriendlyException.SameMessage("请选择时间!");
  2438. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  2439. var (total, items) = await _orderSpecialDetailRepository.Queryable()
  2440. .Includes(x => x.OrderSpecial, s => s.Order)
  2441. .WhereIF(!string.IsNullOrEmpty(dto.OrgName), x => x.OrgName.Contains(dto.OrgName!))
  2442. .WhereIF(!string.IsNullOrEmpty(dto.ErrorName), x => x.ErrorName.Contains(dto.ErrorName!))
  2443. .WhereIF(!string.IsNullOrEmpty(dto.No), x => x.OrderSpecial!.Order!.No!.Contains(dto.No!))
  2444. .Where(x => x.OrderSpecial.ESpecialType == ESpecialType.ReTransact)
  2445. .Where(x => x.OrderSpecial.CreationTime >= dto.StartTime)
  2446. .Where(x => x.OrderSpecial.CreationTime <= dto.EndTime)
  2447. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  2448. return new PagedDto<OrderSpecialDetailDto>(total, _mapper.Map<IReadOnlyList<OrderSpecialDetailDto>>(items));
  2449. }
  2450. /// <summary>
  2451. /// 获取基本信息
  2452. /// </summary>
  2453. /// <param name="id"></param>
  2454. /// <returns></returns>
  2455. [HttpGet("reTransact_base")]
  2456. public async Task<object> ReTransactBaseData()
  2457. {
  2458. var rsp = new
  2459. {
  2460. ReTransactErrorType = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.ReTransactErrorType),
  2461. };
  2462. return rsp;
  2463. }
  2464. /// <summary>
  2465. /// 派单量统计
  2466. /// </summary>
  2467. /// <param name="dto"></param>
  2468. /// <returns></returns>
  2469. [HttpGet("send_order_report")]
  2470. public async Task<object> SendOrderReport([FromQuery] QuerySendOrderRequest dto)
  2471. {
  2472. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  2473. throw UserFriendlyException.SameMessage("请选择时间!");
  2474. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  2475. var items = await _workflowTraceRepository.Queryable()
  2476. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  2477. .LeftJoin<WorkflowStepHandler>((x, w, wsh) => x.StepId == wsh.WorkflowStepId)
  2478. .InnerJoin<SchedulingUser>((x, w, wsh, su) => wsh.UserId == su.UserId)
  2479. .Where((x, w, wsh, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send)
  2480. .Where((x, w, wsh, su) => x.CreationTime >= dto.StartTime.Value)
  2481. .Where((x, w, wsh, su) => x.CreationTime <= dto.EndTime.Value)
  2482. .WhereIF(!string.IsNullOrEmpty(dto.UserName), (x, w, wsh, su) => su.UserName == dto.UserName)
  2483. .GroupBy((x, w, wsh, su) => new { su.UserId, su.UserName })
  2484. //.Having((x, w, wsh, su) => SqlFunc.AggregateCount(x.WorkflowId) == 1)
  2485. .Select((x, w, wsh, su) => new BiOrderSendVo
  2486. {
  2487. UserId = su.UserId,
  2488. UserName = su.UserName,
  2489. SendOrderNum = SqlFunc.AggregateDistinctCount(w.ExternalId),
  2490. NoSendOrderNum = SqlFunc.AggregateSum(SqlFunc.IIF(x.HandlerId == null || x.HandlerId == "", 1, 0)),
  2491. ReSendOrderNum = 0,
  2492. }).ToListAsync();
  2493. var items2 = await _workflowTraceRepository.Queryable()
  2494. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  2495. .LeftJoin<WorkflowStepHandler>((x, w, wfsh) => x.StepId == wfsh.WorkflowStepId)
  2496. .InnerJoin<SchedulingUser>((x, w, wfsh, su) => wfsh.UserId == su.UserId)
  2497. .Where((x, w, wfsh, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send)
  2498. .Where((x, w, wfsh, su) => x.CreationTime >= dto.StartTime.Value)
  2499. .Where((x, w, wfsh, su) => x.CreationTime <= dto.EndTime.Value)
  2500. .GroupBy((x, w, wfsh, su) => x.WorkflowId)
  2501. .Having((x, w, wfsh, su) => SqlFunc.AggregateCount(x.WorkflowId) > 1)
  2502. .Select((x, w, wfsh, su) => new { Id = x.WorkflowId })
  2503. .MergeTable()
  2504. .LeftJoin<WorkflowTrace>((a, wt) => a.Id == wt.WorkflowId)
  2505. .LeftJoin<Workflow>((a, wt, wf) => wt.WorkflowId == wf.Id)
  2506. .LeftJoin<WorkflowStepHandler>((a, wt, wf, wsh) => wt.StepId == wsh.WorkflowStepId)
  2507. .InnerJoin<SchedulingUser>((a, wt, wf, wsh, su) => wsh.UserId == su.UserId)
  2508. .WhereIF(!string.IsNullOrEmpty(dto.UserName), ((a, wt, wf, wsh, su) => su.UserName == dto.UserName))
  2509. .GroupBy((a, wt, wf, wsh, su) => new { su.UserId, su.UserName })
  2510. .Select((a, wt, wf, wsh, su) => new BiOrderSendVo
  2511. {
  2512. UserId = su.UserId,
  2513. UserName = su.UserName,
  2514. SendOrderNum = 0,
  2515. NoSendOrderNum = 0,
  2516. ReSendOrderNum = SqlFunc.AggregateDistinctCount(wf.ExternalId),
  2517. }).ToListAsync();
  2518. var res = (from t1 in items
  2519. join t2 in items2 on t1.UserId equals t2.UserId into t1_t2
  2520. from item in t1_t2.DefaultIfEmpty()
  2521. select new
  2522. {
  2523. UserId = t1.UserId,
  2524. UserName = t1.UserName,
  2525. SendOrderNum = t1.SendOrderNum,
  2526. NoSendOrderNum = t1.NoSendOrderNum,
  2527. ReSendOrderNum = t1_t2.Select(x => x.ReSendOrderNum).FirstOrDefault(),
  2528. ChainRate = t1_t2.Select(x => x.ReSendOrderNum).FirstOrDefault() > 0 ?
  2529. ((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%",
  2530. }).ToList();
  2531. return res;
  2532. }
  2533. /// <summary>
  2534. /// 派单量统计明细
  2535. /// </summary>
  2536. /// <param name="dto"></param>
  2537. /// <returns></returns>
  2538. [HttpGet("send_order_detail_report")]
  2539. public async Task<PagedDto<OrderDto>> QuerySendOrderDetail([FromQuery] QuerySendOrderDetailRequest dto)
  2540. {
  2541. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  2542. throw UserFriendlyException.SameMessage("请选择时间!");
  2543. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  2544. var (total, items) = await _workflowTraceRepository.Queryable()
  2545. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  2546. .LeftJoin<WorkflowStepHandler>((x, w, wsh) => x.StepId == wsh.WorkflowStepId)
  2547. .InnerJoin<SchedulingUser>((x, w, wsh, su) => wsh.UserId == su.UserId)
  2548. .Where((x, w, wsh, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send)
  2549. .Where((x, w, wsh, su) => x.CreationTime >= dto.StartTime.Value)
  2550. .Where((x, w, wsh, su) => x.CreationTime <= dto.EndTime.Value)
  2551. .Where((x, w, wsh, su) => su.UserId == dto.UserId)
  2552. .WhereIF(dto.TitleCode.ToUpper() == "NOSENDORDERNUM", (x, w, wsh, su) => x.HandlerId == null || x.HandlerId == "")
  2553. .GroupBy((x, w, wsh, su) => w.ExternalId)
  2554. .Select((x, w, wsh, su) => new { Id = w.ExternalId })
  2555. .MergeTable()
  2556. .LeftJoin<Order>((a, b) => a.Id == b.Id)
  2557. .Select((a, b) => b)
  2558. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  2559. if (dto.TitleCode.ToUpper() == "RESENDORDERNUM")
  2560. {
  2561. (total, items) = await _workflowTraceRepository.Queryable()
  2562. .LeftJoin<Workflow>((x, w) => x.WorkflowId == w.Id)
  2563. .LeftJoin<WorkflowStepHandler>((x, w, wfsh) => x.StepId == wfsh.WorkflowStepId)
  2564. .InnerJoin<SchedulingUser>((x, w, wfsh, su) => wfsh.UserId == su.UserId)
  2565. .Where((x, w, wfsh, su) => w.ModuleCode == "OrderHandle" && x.BusinessType == EBusinessType.Send)
  2566. .Where((x, w, wfsh, su) => x.CreationTime >= dto.StartTime.Value)
  2567. .Where((x, w, wfsh, su) => x.CreationTime <= dto.EndTime.Value)
  2568. .GroupBy((x, w, wfsh, su) => x.WorkflowId)
  2569. .Having((x, w, wfsh, su) => SqlFunc.AggregateCount(x.WorkflowId) > 1)
  2570. .Select((x, w, wfsh, su) => new { Id = x.WorkflowId })
  2571. .MergeTable()
  2572. .LeftJoin<WorkflowTrace>((a, wt) => a.Id == wt.WorkflowId)
  2573. .LeftJoin<Workflow>((a, wt, wf) => wt.WorkflowId == wf.Id)
  2574. .LeftJoin<WorkflowStepHandler>((a, wt, wf, wsh) => wt.StepId == wsh.WorkflowStepId)
  2575. .InnerJoin<SchedulingUser>((a, wt, wf, wsh, su) => wsh.UserId == su.UserId)
  2576. .Where((a, wt, wf, wsh, su) => su.UserId == dto.UserId)
  2577. .GroupBy((a, wt, wf, wsh, su) => wf.ExternalId)
  2578. .Select((a, wt, wf, wsh, su) => new { Id = wf.ExternalId })
  2579. .MergeTable()
  2580. .LeftJoin<Order>((a, b) => a.Id == b.Id)
  2581. .Select((a, b) => b)
  2582. .ToPagedListAsync(dto, HttpContext.RequestAborted);
  2583. }
  2584. return new PagedDto<OrderDto>(total, _mapper.Map<IReadOnlyList<OrderDto>>(items));
  2585. }
  2586. }
  2587. }