DataScreenController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. using DocumentFormat.OpenXml.Drawing;
  2. using Hotline.Configurations;
  3. using Hotline.KnowledgeBase;
  4. using Hotline.Orders;
  5. using Hotline.Repository.SqlSugar.Orders;
  6. using Hotline.Settings;
  7. using Hotline.Settings.Hotspots;
  8. using Hotline.Share.Dtos;
  9. using Hotline.Share.Dtos.Bigscreen;
  10. using Hotline.Share.Dtos.Order;
  11. using Hotline.Share.Enums.KnowledgeBase;
  12. using Hotline.Share.Enums.Order;
  13. using JiebaNet.Segmenter.Common;
  14. using MapsterMapper;
  15. using Microsoft.AspNetCore.Authorization;
  16. using Microsoft.AspNetCore.Mvc;
  17. using Microsoft.Extensions.Options;
  18. using SqlSugar;
  19. using System;
  20. using XF.Domain.Repository;
  21. namespace Hotline.Api.Controllers.Bigscreen
  22. {
  23. public class DataScreenController : BaseController
  24. {
  25. private readonly IOrderRepository _orderRepository;
  26. private readonly IRepository<OrderDelay> _orderDelayRepository;
  27. private readonly IRepository<OrderVisit> _orderVisitRepository;
  28. private readonly IRepository<Knowledge> _knowledgeRepository;
  29. private readonly IRepository<KnowledgePv> _knowledgePvRepository;
  30. private readonly IMapper _mapper;
  31. private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
  32. private readonly IRepository<SystemArea> _systemAreaRepository;
  33. private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
  34. private readonly IRepository<OrderSecondaryHandling> _orderSecondaryHandlingRepository;
  35. public DataScreenController(IOrderRepository orderRepository, IRepository<OrderVisit> orderVisitRepository,
  36. IRepository<OrderDelay> orderDelayRepository, IRepository<Knowledge> knowledgeRepository, IRepository<KnowledgePv> knowledgePvRepository,
  37. IMapper mapper, IRepository<OrderVisitDetail> orderVisitDetailRepository, IRepository<SystemArea> systemAreaRepository,
  38. IOptionsSnapshot<AppConfiguration> appOptions,
  39. IRepository<OrderSecondaryHandling> orderSecondaryHandlingRepository)
  40. {
  41. _orderRepository = orderRepository;
  42. _orderVisitRepository = orderVisitRepository;
  43. _orderDelayRepository = orderDelayRepository;
  44. _knowledgeRepository = knowledgeRepository;
  45. _knowledgePvRepository = knowledgePvRepository;
  46. _mapper = mapper;
  47. _orderVisitDetailRepository = orderVisitDetailRepository;
  48. _systemAreaRepository = systemAreaRepository;
  49. _appOptions = appOptions;
  50. _orderSecondaryHandlingRepository = orderSecondaryHandlingRepository;
  51. }
  52. /// <summary>
  53. /// 工单统计
  54. /// </summary>
  55. /// <returns></returns>
  56. [AllowAnonymous]
  57. [HttpGet("order-statistics")]
  58. public async Task<OrderStatisticsDto> OrderStatistics(DateTime StartTime, DateTime EndTime)
  59. {
  60. EndTime = EndTime.AddDays(1).AddSeconds(-1);
  61. var dto = new OrderStatisticsDto();
  62. #region 办结工单
  63. dto.CompletionCount = await _orderRepository.Queryable(false, false, false)
  64. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status >= EOrderStatus.Filed).CountAsync();
  65. int CompletionSum = await _orderRepository.Queryable(false, false, false)
  66. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status >= EOrderStatus.Handling).CountAsync();
  67. if (CompletionSum == 0)
  68. {
  69. dto.CompletionRate = 0;
  70. }
  71. else
  72. {
  73. dto.CompletionRate = Math.Round((dto.CompletionCount / (double)CompletionSum) * 100, 2);
  74. }
  75. #endregion
  76. #region 待受理工单
  77. dto.HaveToAcceptCount = await _orderRepository.Queryable(false, false, false)
  78. .Where(x => x.CreationTime > StartTime && x.CreationTime <= EndTime && x.Status == EOrderStatus.WaitForAccept).CountAsync();
  79. int HaveToAcceptSum = await _orderRepository.Queryable(false, false, false)
  80. .Where(x => x.CreationTime >= StartTime && x.CreationTime <= EndTime).CountAsync();
  81. if (HaveToAcceptSum == 0)
  82. {
  83. dto.HaveToAcceptRate = 0;
  84. }
  85. else
  86. {
  87. dto.HaveToAcceptRate = Math.Round((dto.HaveToAcceptCount / (double)HaveToAcceptSum) * 100, 2);
  88. }
  89. #endregion
  90. #region 超期工单
  91. dto.OverTimeCount = await _orderRepository.Queryable(false, false, false)
  92. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.ExpiredStatus == EExpiredStatus.Expired).CountAsync();
  93. if (CompletionSum == 0)
  94. {
  95. dto.OverTimeRate = 0;
  96. }
  97. else
  98. {
  99. dto.OverTimeRate = Math.Round((dto.OverTimeCount / (double)CompletionSum) * 100, 2);
  100. }
  101. #endregion
  102. #region 延期工单
  103. dto.DelayCount = await _orderDelayRepository.Queryable()
  104. .Where(x => x.ApplyDelayTime >= StartTime && x.ApplyDelayTime <= EndTime && x.DelayState == EDelayState.Pass).CountAsync();
  105. if (CompletionSum == 0)
  106. {
  107. dto.DelayRate = 0;
  108. }
  109. else
  110. {
  111. dto.DelayRate = Math.Round((dto.DelayCount / (double)CompletionSum) * 100, 2);
  112. }
  113. #endregion
  114. #region 满意工单
  115. dto.SatisfiedCount = await _orderVisitRepository.Queryable().Where(x =>
  116. x.VisitTime >= StartTime && x.VisitTime <= EndTime && x.VisitState == EVisitState.Visited &&
  117. SqlFunc.JsonField(x.NowEvaluate, "Key") != "1" && SqlFunc.JsonField(x.NowEvaluate, "Key") != "2").CountAsync();
  118. int SatisfiedSum = await _orderVisitRepository.Queryable()
  119. .Where(x => x.VisitTime >= StartTime && x.VisitTime <= EndTime && x.VisitState == EVisitState.Visited).CountAsync();
  120. if (SatisfiedSum == 0)
  121. {
  122. dto.SatisfiedRate = 0;
  123. }
  124. else
  125. {
  126. dto.SatisfiedRate = Math.Round((dto.SatisfiedCount / (double)SatisfiedSum) * 100, 2);
  127. }
  128. #endregion
  129. #region 省工单量
  130. dto.ProvinceOrderCount = await _orderRepository.Queryable(false, false, false)
  131. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.IsProvince).CountAsync();
  132. dto.ProvinceOrderCompletionCount = await _orderRepository.Queryable(false, false, false)
  133. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.IsProvince && x.Status >= EOrderStatus.Filed).CountAsync();
  134. #endregion
  135. return dto;
  136. }
  137. /// <summary>
  138. /// 知识库统计
  139. /// </summary>
  140. /// <returns></returns>
  141. [AllowAnonymous]
  142. [HttpGet("knowledge-statistics")]
  143. public async Task<KnowledgeStatisticsDto> KnowledgeStatistics()
  144. {
  145. var dto = new KnowledgeStatisticsDto();
  146. dto.KnowledgeCount = await _knowledgeRepository.Queryable().Where(x => x.Status == EKnowledgeStatus.OnShelf).CountAsync(); //总数
  147. dto.TodayAddCount = await _knowledgeRepository.Queryable().Where(x =>
  148. x.Renewaln == false && x.Status == EKnowledgeStatus.OnShelf && x.OnShelfTime.Value.Date == DateTime.Now.Date).CountAsync(); //今日新增
  149. dto.ThisMonthModifyCount = await _knowledgeRepository.Queryable().Where(x => x.Renewaln == true && x.Status == EKnowledgeStatus.OnShelf &&
  150. x.OnShelfTime.Value.Year
  151. == DateTime.Now.Year &&
  152. x.OnShelfTime.Value.Month == DateTime.Now.Month)
  153. .CountAsync(); //本月修改
  154. dto.TodayReadCount = await _knowledgePvRepository.Queryable().Where(x => x.CreationTime.Date == DateTime.Now.Date).CountAsync();
  155. return dto;
  156. }
  157. /// <summary>
  158. /// 受理类型办件分析
  159. /// </summary>
  160. /// <param name="StartDate"></param>
  161. /// <param name="EndDate"></param>
  162. /// <returns></returns>
  163. [AllowAnonymous]
  164. [HttpGet("ordertype-statistics")]
  165. public async Task<List<OrderTypeHandleStatisticsDto>> OrderTypeHandleStatistics(DateTime StartTime, DateTime EndTime)
  166. {
  167. EndTime = EndTime.AddDays(1).AddSeconds(-1);
  168. var list = await _orderRepository.Queryable(false, false, false).Where(x =>
  169. x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status > EOrderStatus.Handling && !string.IsNullOrEmpty(x.AcceptType))
  170. .GroupBy(x => x.AcceptType)
  171. .Select(x => new OrderTypeHandleStatisticsDto
  172. {
  173. AcceptType = x.AcceptType,
  174. SumCount = SqlFunc.AggregateCount(x.Id),
  175. HandlingCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status >= EOrderStatus.Handling && x.Status < EOrderStatus.Filed, 1, 0)),
  176. FiledCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status >= EOrderStatus.Filed, 1, 0)),
  177. OverTimeCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.ExpiredStatus == EExpiredStatus.Expired, 1, 0))
  178. }).ToListAsync();
  179. return list;
  180. }
  181. /// <summary>
  182. /// 获取区域信息
  183. /// </summary>
  184. /// <returns></returns>
  185. [HttpGet("get_system_area")]
  186. [AllowAnonymous]
  187. public async Task<object> GetSystemAreaAsync()
  188. {
  189. var areaCode = _appOptions.Value.GetDefaultAppScopeConfiguration().AreaCode;
  190. return await _systemAreaRepository.Queryable()
  191. .Where(p => p.Id == areaCode || p.ParentId == areaCode)
  192. .Select(p => new
  193. {
  194. p.AreaName,
  195. p.Id
  196. })
  197. .OrderBy(p => p.Id)
  198. .ToListAsync();
  199. }
  200. /// <summary>
  201. /// 预警热点
  202. /// </summary>
  203. /// <param name="StartDate"></param>
  204. /// <param name="EndDate"></param>
  205. /// <param name="AreaCode"></param>
  206. /// <returns></returns>
  207. [AllowAnonymous]
  208. [HttpGet("earlywarning-statistics")]
  209. public async Task<List<EarlyWarningHotsPotsStatisticsDto>> EarlyWarningHotsPotsStatistics(DateTime StartTime, DateTime EndTime,
  210. string AreaCode)
  211. {
  212. EndTime = EndTime.AddDays(1).AddSeconds(-1);
  213. if (AreaCode.Length == 6 && AreaCode.IndexOf("00") == 4)
  214. {
  215. AreaCode = AreaCode.Remove(4);
  216. }
  217. var list = await _orderRepository.Queryable(false, false, false)
  218. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.AreaCode.StartsWith(AreaCode) && !x.HotspotId.StartsWith("18"))
  219. .GroupBy(x => new { x.HotspotId, x.HotspotName, x.HotspotSpliceName })
  220. .Select(x => new EarlyWarningHotsPotsStatisticsDto()
  221. {
  222. HotspotId = x.HotspotId,
  223. HotspotName = x.HotspotName,
  224. HotspotSpliceName = x.HotspotSpliceName,
  225. SumCount = SqlFunc.AggregateCount(x.Id)
  226. }).OrderByDescending(x => x.SumCount).Take(5).ToListAsync();
  227. return list;
  228. }
  229. /// <summary>
  230. /// 工单当日统计及环比
  231. /// </summary>
  232. /// <returns></returns>
  233. [AllowAnonymous]
  234. [HttpGet("ordercount-statistics")]
  235. public async Task<OrderCountStatisticsDto> OrderCountStatistics()
  236. {
  237. var today = DateTime.Now;
  238. var dto = new OrderCountStatisticsDto();
  239. #region 当日工单量
  240. dto.ToDayCount = await _orderRepository.Queryable(false, false, false)
  241. .Where(x => x.StartTime.Value.Date == DateTime.Now.Date && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  242. var beforToDayCount = await _orderRepository.Queryable(false, false, false)
  243. //.Where(x => x.StartTime.Value.Date == today.AddDays(-1).Date && x.Status > EOrderStatus.WaitForAccept)
  244. .Where(x => x.StartTime.Value.Date == DateTime.Now.AddDays(-1).Date && x.Status > EOrderStatus.WaitForAccept)
  245. .CountAsync();
  246. if (beforToDayCount == 0)
  247. {
  248. dto.ToDayQoQ = 0;
  249. }
  250. else
  251. {
  252. dto.ToDayQoQ = Math.Round(((dto.ToDayCount - beforToDayCount) / (double)beforToDayCount) * 100, 2);
  253. }
  254. #endregion
  255. #region 当月工单量
  256. dto.ToMonthCount = await _orderRepository.Queryable(false, false, false).Where(x =>
  257. x.StartTime.Value.ToString("yyyy-MM") == today.ToString("yyyy-MM") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  258. var beforToMonthCount = await _orderRepository.Queryable(false, false, false).Where(x =>
  259. x.StartTime.Value.ToString("yyyy-MM") == today.AddMonths(-1).ToString("yyyy-MM") && x.Status > EOrderStatus.WaitForAccept)
  260. .CountAsync();
  261. if (beforToMonthCount == 0)
  262. {
  263. dto.ToMonthQoQ = 0;
  264. }
  265. else
  266. {
  267. dto.ToMonthQoQ = Math.Round(((dto.ToMonthCount - beforToMonthCount) / (double)beforToMonthCount) * 100, 2);
  268. }
  269. #endregion
  270. #region 当年工单量
  271. dto.ToYearCount = await _orderRepository.Queryable(false, false, false)
  272. .Where(x => x.StartTime.Value.ToString("yyyy") == today.ToString("yyyy") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  273. var beforToYearCount = await _orderRepository.Queryable(false, false, false).Where(x =>
  274. x.StartTime.Value.ToString("yyyy") == today.AddYears(-1).ToString("yyyy") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  275. if (beforToYearCount == 0)
  276. {
  277. dto.ToYearQoQ = 0;
  278. }
  279. else
  280. {
  281. dto.ToYearQoQ = Math.Round(((dto.ToYearCount - beforToYearCount) / (double)beforToYearCount) * 100, 2);
  282. }
  283. #endregion
  284. return dto;
  285. }
  286. /// <summary>
  287. /// 区域受理排行
  288. /// </summary>
  289. /// <returns></returns>
  290. [AllowAnonymous]
  291. [HttpGet("orderarea-accept-statistics")]
  292. public async Task<List<OrderAreaAcceptStatisticsDto>> OrderAreaAcceptStatistics(DateTime StartTime, DateTime EndTime)
  293. {
  294. EndTime = EndTime.AddDays(1).AddSeconds(-1);
  295. var list = await _orderRepository.Queryable(false, false, false)
  296. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status > EOrderStatus.WaitForAccept)
  297. .LeftJoin<SystemArea>((it, o) => it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  298. .GroupBy((it, o) => new
  299. {
  300. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  301. o.AreaName,
  302. })
  303. .Select((it, o) => new OrderAreaAcceptStatisticsDto()
  304. {
  305. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  306. AreaName = o.AreaName,
  307. AcceptedCount = SqlFunc.AggregateCount(it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  308. CompletionCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status >= EOrderStatus.Filed, 1, 0))
  309. }).MergeTable()
  310. .Where(x => x.AreaCode != "519800" && x.AreaCode != "519900").OrderByDescending(it => it.AcceptedCount).ToListAsync();
  311. return list;
  312. }
  313. /// <summary>
  314. /// 区域明细数据
  315. /// </summary>
  316. /// <param name="StartTime"></param>
  317. /// <param name="EndTime"></param>
  318. /// <param name="AreaCode"></param>
  319. /// <returns></returns>
  320. [AllowAnonymous]
  321. [HttpGet("orderareaaccept-query")]
  322. public async Task<List<OrderAreaAcceptQueryDto>> OrderAreaAcceptQuery(DateTime StartTime, DateTime EndTime)
  323. {
  324. EndTime = EndTime.AddDays(1).AddSeconds(-1);
  325. var areaList = await _systemAreaRepository.Queryable()
  326. .Where(x => !x.Id.EndsWith("00"))
  327. .GroupBy(x => new
  328. {
  329. Id = x.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  330. })
  331. .Select(x => new
  332. {
  333. Id = x.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  334. })
  335. .MergeTable()
  336. .LeftJoin<SystemArea>((it, o) => it.Id == o.Id)
  337. .Select((it, o) => new
  338. {
  339. Id = it.Id,
  340. Name = o.AreaName
  341. })
  342. .ToListAsync();
  343. var list = new List<OrderAreaAcceptQueryDto>();
  344. foreach (var item in areaList)
  345. {
  346. #region 单个获取
  347. var dto = new OrderAreaAcceptQueryDto();
  348. dto.AreaCode = item.Id;
  349. dto.AreaName = item.Name;
  350. dto.HandlingCount = await _orderRepository.Queryable(false, false, false).Where(x =>
  351. x.AreaCode == item.Id && x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status > EOrderStatus.WaitForAccept &&
  352. x.Status < EOrderStatus.Filed).CountAsync();
  353. dto.FiledCount = await _orderRepository.Queryable(false, false, false).Where(x =>
  354. x.AreaCode == item.Id && x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status >= EOrderStatus.Filed).CountAsync();
  355. dto.OverTimeCount = await _orderRepository.Queryable(false, false, false).Where(x =>
  356. x.AreaCode == item.Id && x.StartTime >= StartTime && x.StartTime <= EndTime && x.ExpiredStatus == EExpiredStatus.Expired)
  357. .CountAsync();
  358. var hotsPot = await _orderRepository.Queryable(false, false, false)
  359. .Where(x => x.AreaCode == item.Id && x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status > EOrderStatus.WaitForAccept)
  360. .GroupBy(x => new { x.HotspotId, x.HotspotName })
  361. .Select(x => new
  362. {
  363. HotsPotName = x.HotspotName,
  364. HotCount = SqlFunc.AggregateCount(x.HotspotId)
  365. }).OrderByDescending(x => x.HotCount).FirstAsync();
  366. dto.HotspotName = hotsPot?.HotsPotName;
  367. #region 满意度
  368. var SatisfiedCount = await _orderRepository.Queryable(false, false, false)
  369. .LeftJoin<OrderVisit>((it, o) => it.Id == o.OrderId && o.VisitState == EVisitState.Visited)
  370. .Where((it, o) => it.AreaCode == item.Id && o.VisitTime >= StartTime && o.VisitTime <= EndTime
  371. && SqlFunc.JsonField(o.NowEvaluate, "Key") != "1" && SqlFunc.JsonField(o.NowEvaluate, "Key") != "2")
  372. .CountAsync();
  373. var VisitCount = await _orderRepository.Queryable(false, false, false)
  374. .LeftJoin<OrderVisit>((it, o) => it.Id == o.OrderId && o.VisitState == EVisitState.Visited)
  375. .Where((it, o) => it.AreaCode == item.Id && o.VisitTime >= StartTime && o.VisitTime <= EndTime)
  376. .CountAsync();
  377. if (SatisfiedCount != 0 && VisitCount != 0)
  378. {
  379. dto.SatisfiedRate = Math.Round((SatisfiedCount / (double)VisitCount) * 100, 2);
  380. }
  381. #endregion
  382. list.Add(dto);
  383. #endregion
  384. }
  385. return list;
  386. }
  387. /// <summary>
  388. /// 办理中工单概览
  389. /// </summary>
  390. /// <returns></returns>
  391. [AllowAnonymous]
  392. [HttpGet("order-handling-query")]
  393. public async Task<List<OrderDto>> OrderHandlingDetailQuery()
  394. {
  395. var list = await _orderRepository
  396. .Queryable(false, false, false)
  397. .Where(x => x.Status > EOrderStatus.WaitForAccept && x.StartTime.Value.Date == DateTime.Now.Date)
  398. //.Where(x => x.Status > EOrderStatus.WaitForAccept && x.StartTime.Value.Date == DateTime.Parse("2024-03-14").Date)
  399. .OrderByDescending(x => x.StartTime)
  400. .Take(50)
  401. .ToListAsync();
  402. return _mapper.Map<List<OrderDto>>(list);
  403. }
  404. /// <summary>
  405. /// 30天高频事项预警
  406. /// </summary>
  407. /// <returns></returns>
  408. [AllowAnonymous]
  409. [HttpGet("highmatter-warning")]
  410. public async Task<List<HighMatterWarningDto>> HighMatterWarning(DateTime StartTime, DateTime EndTime)
  411. {
  412. //var endDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
  413. //var startDate = endDate.AddDays(-30).Date;
  414. List<string> filterTitle = new List<string>();
  415. filterTitle.Add("无声");
  416. filterTitle.Add("骚扰");
  417. filterTitle.Add("错拨");
  418. filterTitle.Add("测试");
  419. var list = await _orderRepository.Queryable(false, false, false)
  420. .Where(x => x.CreationTime >= StartTime && x.CreationTime <= EndTime)
  421. .Where(x => filterTitle.Any(s => x.Title.Contains(s)) == false)
  422. .LeftJoin<SystemArea>((it, o) => it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  423. .GroupBy((it, o) => new
  424. {
  425. it.AcceptTypeCode,
  426. it.HotspotId,
  427. it.HotspotName,
  428. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  429. o.AreaName,
  430. })
  431. .Having((it, o) => SqlFunc.AggregateCount(it.HotspotName) >= 5)
  432. .Select((it, o) => new HighMatterWarningDto()
  433. {
  434. AreaName = o.AreaName,
  435. //Title = it.Title,
  436. HotspotName = it.HotspotName,
  437. SumCount = SqlFunc.AggregateCount(it.HotspotName),
  438. Id = SqlFunc.AggregateMin(it.Id)
  439. })
  440. .MergeTable()
  441. //.Where(x=>x.SumCount>=5)
  442. .LeftJoin<Order>((x, d) => x.Id == d.Id)
  443. .Select((x, d) => new HighMatterWarningDto()
  444. {
  445. AreaName = x.AreaName,
  446. HotspotName = x.HotspotName,
  447. Title = d.Title,
  448. SumCount = x.SumCount,
  449. Id = d.Id,
  450. }).Take(50).ToListAsync();
  451. return list;
  452. }
  453. /// <summary>
  454. /// 部门满意度排行榜
  455. /// </summary>
  456. /// <param name="StartTime"></param>
  457. /// <param name="EndTime"></param>
  458. /// <returns></returns>
  459. [AllowAnonymous]
  460. [HttpGet("ordervisit-orgsatisfaction-rank")]
  461. public async Task<List<OrderVisitOrgSatisfactionRankDto>> OrderVisitOrgSatisfactionRank(DateTime StartTime, DateTime EndTime)
  462. {
  463. var list = new List<OrderVisitOrgSatisfactionRankDto>();
  464. if (_appOptions.Value.IsLuZhou)
  465. {
  466. list = await _orderVisitDetailRepository.Queryable()
  467. .Includes(x => x.OrderVisit)
  468. .Where(x => x.OrderVisit.VisitTime >= StartTime && x.OrderVisit.VisitTime <= EndTime && x.VisitTarget == EVisitTarget.Org &&
  469. x.VisitOrgCode.Length >= 6 && x.OrderVisit.VisitState == EVisitState.Visited)
  470. .GroupBy(x => new
  471. {
  472. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
  473. })
  474. .Select(x => new OrderVisitOrgSatisfactionRankDto()
  475. {
  476. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  477. SatisfiedCount =
  478. SqlFunc.AggregateSum(SqlFunc.IIF(
  479. SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "1" && SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "2", 1,
  480. 0)),
  481. VisitCount = SqlFunc.AggregateCount(x.VisitOrgName)
  482. }).MergeTable()
  483. .LeftJoin<SystemOrganize>((x, so) => x.VisitOrgCode == so.Id)
  484. .Select((x, so) => new OrderVisitOrgSatisfactionRankDto()
  485. {
  486. VisitOrgCode = x.VisitOrgCode,
  487. VisitOrgName = so.Name,
  488. SatisfiedCount = x.SatisfiedCount,
  489. VisitCount = x.VisitCount
  490. })
  491. .OrderByDescending(x => x.SatisfiedCount).Take(10).ToListAsync();
  492. list = list.OrderByDescending(x => x.SatisfiedRate).ToList();
  493. }
  494. else
  495. {
  496. list = await _orderVisitDetailRepository.Queryable()
  497. .Includes(x => x.OrderVisit)
  498. .Where(x => x.OrderVisit.VisitTime >= StartTime && x.OrderVisit.VisitTime <= EndTime && x.VisitTarget == EVisitTarget.Org &&
  499. x.VisitOrgCode.Length >= 6 && x.OrderVisit.VisitState == EVisitState.Visited)
  500. .GroupBy(x => new
  501. {
  502. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  503. x.VisitOrgName
  504. })
  505. .Select(x => new OrderVisitOrgSatisfactionRankDto()
  506. {
  507. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  508. VisitOrgName = x.VisitOrgName,
  509. SatisfiedCount =
  510. SqlFunc.AggregateSum(SqlFunc.IIF(
  511. SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "1" && SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "2", 1,
  512. 0)),
  513. VisitCount = SqlFunc.AggregateCount(x.VisitOrgName)
  514. }).MergeTable().OrderByDescending(x => x.SatisfiedCount).Take(10).ToListAsync();
  515. list = list.OrderByDescending(x => x.SatisfiedRate).ToList();
  516. }
  517. return list;
  518. }
  519. /// <summary>
  520. /// 占比分析
  521. /// </summary>
  522. /// <param name="StartTime"></param>
  523. /// <param name="EndTime"></param>
  524. /// <param name="IsSource"></param>
  525. /// <returns></returns>
  526. [AllowAnonymous]
  527. [HttpGet("order-source-accepttype-statistics")]
  528. public async Task<List<OrderSourceAndAcceptTtoeStatisticsDto>> OrderSourceAndAcceptTtoeStatistics(DateTime StartTime, DateTime EndTime,
  529. bool IsSource)
  530. {
  531. EndTime = EndTime.AddDays(1).AddSeconds(-1);
  532. int SumCount = await _orderRepository.Queryable(false, false, false)
  533. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  534. if (IsSource)
  535. {
  536. var list = await _orderRepository.Queryable(false, false, false)
  537. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status > EOrderStatus.WaitForAccept)
  538. .GroupBy(x => new { x.SourceChannelCode, x.SourceChannel })
  539. .Select(x => new OrderSourceAndAcceptTtoeStatisticsDto()
  540. {
  541. Name = x.SourceChannel,
  542. SumCount = SumCount,
  543. HasCount = SqlFunc.AggregateCount(x.SourceChannel)
  544. }).ToListAsync();
  545. return list;
  546. }
  547. else
  548. {
  549. var list = await _orderRepository.Queryable(false, false, false)
  550. .Where(x => x.StartTime >= StartTime && x.StartTime <= EndTime && x.Status > EOrderStatus.WaitForAccept)
  551. .GroupBy(x => new { x.AcceptTypeCode, x.AcceptType })
  552. .Select(x => new OrderSourceAndAcceptTtoeStatisticsDto()
  553. {
  554. Name = x.AcceptType,
  555. SumCount = SumCount,
  556. HasCount = SqlFunc.AggregateCount(x.AcceptTypeCode),
  557. }).ToListAsync();
  558. return list;
  559. }
  560. }
  561. /// <summary>
  562. /// 二次办理统计
  563. /// </summary>
  564. /// <param name="StartTime"></param>
  565. /// <param name="EndTime"></param>
  566. /// <returns></returns>
  567. [AllowAnonymous]
  568. [HttpGet("order-secondary-statistics")]
  569. public async Task<SecondaryProcessingOrderStatisticsDto> OrderSecondaryStatistics(DateTime StartTime, DateTime EndTime)
  570. {
  571. DateTime? dateTime = DateTime.Now;
  572. EndTime = EndTime.AddDays(1).AddSeconds(-1);
  573. var data = new SecondaryProcessingOrderStatisticsDto
  574. {
  575. OrderCount = await _orderSecondaryHandlingRepository.Queryable()
  576. .Where(x => x.AuditTime >= StartTime && x.AuditTime <= EndTime && x.State != ESecondaryHandlingState.NotApply
  577. && x.State != ESecondaryHandlingState.Apply && x.State != ESecondaryHandlingState.Refuse).CountAsync(),
  578. OrderOverdueCount = await _orderSecondaryHandlingRepository.Queryable()
  579. .Includes(x => x.Order)
  580. //.Where(x => x.Order.Status < EOrderStatus.Filed)
  581. .Where(x => x.Order.ExpiredTime != null &&
  582. (((x.Order.Status == EOrderStatus.Filed || x.Order.Status == EOrderStatus.Published || x.Order.Status == EOrderStatus.Visited) &&
  583. x.Order.FiledTime >= x.Order.ExpiredTime) ||
  584. ((x.Order.Status != EOrderStatus.Filed && x.Order.Status != EOrderStatus.Published && x.Order.Status != EOrderStatus.Visited) &&
  585. dateTime >= x.Order.ExpiredTime.Value)))
  586. .Where(x => x.AuditTime >= StartTime && x.AuditTime <= EndTime
  587. && x.State != ESecondaryHandlingState.NotApply
  588. && x.State != ESecondaryHandlingState.Apply && x.State != ESecondaryHandlingState.Refuse)
  589. .CountAsync(),
  590. OrderSoonOverdueCount = await _orderSecondaryHandlingRepository.Queryable()
  591. .Includes(x => x.Order)
  592. .Where(x => x.Order.Status < EOrderStatus.Filed && dateTime > x.Order.NearlyExpiredTime && dateTime < x.Order.ExpiredTime)
  593. .Where(x => x.AuditTime >= StartTime && x.AuditTime <= EndTime
  594. && x.State != ESecondaryHandlingState.NotApply
  595. && x.State != ESecondaryHandlingState.Apply && x.State != ESecondaryHandlingState.Refuse)
  596. .CountAsync()
  597. };
  598. var da = await _orderSecondaryHandlingRepository.Queryable()
  599. .LeftJoin<OrderVisit>((os, ov) => os.OrderId == ov.OrderId)
  600. .LeftJoin<OrderVisitDetail>((os, ov, od) => ov.Id == od.VisitId)
  601. .Where((os, ov, od) => ov.VisitState == EVisitState.Visited && od.VisitTarget == EVisitTarget.Org && ov.VisitTime >= StartTime && ov.VisitTime <= EndTime
  602. && os.State != ESecondaryHandlingState.NotApply
  603. && os.State != ESecondaryHandlingState.Apply && os.State != ESecondaryHandlingState.Refuse)
  604. .Select((os, ov, od) => new SecondarySatisfactionDto()
  605. {
  606. Count = SqlFunc.AggregateCount(os.Id),
  607. NoSatisfiedCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(od.OrgProcessingResults, "Key") == "1"
  608. || SqlFunc.JsonField(od.OrgProcessingResults, "Key") == "2", 1, 0)),//不满意数
  609. }).FirstAsync();
  610. if (da != null)
  611. data.SatisfactionRate = da.SatisfiedRate;
  612. return data;
  613. }
  614. /// <summary>
  615. /// 二次办理中工单概览
  616. /// </summary>
  617. /// <returns></returns>
  618. [AllowAnonymous]
  619. [HttpGet("order-secondary-handling-query")]
  620. public async Task<List<OrderSecondaryHandlingDto>> OrderSecondaryHandlingDetailQuery()
  621. {
  622. var quer = await _orderSecondaryHandlingRepository.Queryable()
  623. .Includes(x => x.Order)
  624. .Where(x => x.CreationTime.Date == DateTime.Now.Date)
  625. .OrderByDescending(x => x.CreationTime)
  626. .Take(50)
  627. .ToListAsync();
  628. return _mapper.Map<List<OrderSecondaryHandlingDto>>(quer);
  629. }
  630. }
  631. }