DataScreenController.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. using Hotline.KnowledgeBase;
  2. using Hotline.Orders;
  3. using Hotline.Repository.SqlSugar.Orders;
  4. using Hotline.Settings;
  5. using Hotline.Settings.Hotspots;
  6. using Hotline.Share.Dtos.Bigscreen;
  7. using Hotline.Share.Dtos.Order;
  8. using Hotline.Share.Enums.KnowledgeBase;
  9. using Hotline.Share.Enums.Order;
  10. using MapsterMapper;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Mvc;
  13. using SqlSugar;
  14. using XF.Domain.Repository;
  15. namespace Hotline.Api.Controllers.Bigscreen
  16. {
  17. public class DataScreenController: BaseController
  18. {
  19. private readonly IOrderRepository _orderRepository;
  20. private readonly IRepository<OrderDelay> _orderDelayRepository;
  21. private readonly IRepository<OrderVisit> _orderVisitRepository;
  22. private readonly IRepository<Knowledge> _knowledgeRepository;
  23. private readonly IRepository<KnowledgePv> _knowledgePvRepository;
  24. private readonly IMapper _mapper;
  25. private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
  26. private readonly IRepository<SystemArea> _systemAreaRepository;
  27. public DataScreenController(IOrderRepository orderRepository, IRepository<OrderVisit> orderVisitRepository, IRepository<OrderDelay> orderDelayRepository, IRepository<Knowledge> knowledgeRepository, IRepository<KnowledgePv> knowledgePvRepository,IMapper mapper,IRepository<OrderVisitDetail> orderVisitDetailRepository, IRepository<SystemArea> systemAreaRepository)
  28. {
  29. _orderRepository = orderRepository;
  30. _orderVisitRepository = orderVisitRepository;
  31. _orderDelayRepository = orderDelayRepository;
  32. _knowledgeRepository = knowledgeRepository;
  33. _knowledgePvRepository = knowledgePvRepository;
  34. _mapper = mapper;
  35. _orderVisitDetailRepository = orderVisitDetailRepository;
  36. _systemAreaRepository = systemAreaRepository;
  37. }
  38. /// <summary>
  39. /// 工单统计
  40. /// </summary>
  41. /// <returns></returns>
  42. [AllowAnonymous]
  43. [HttpGet("order-statistics")]
  44. public async Task<OrderStatisticsDto> OrderStatistics(DateTime StartDate,DateTime EndDate)
  45. {
  46. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  47. var dto = new OrderStatisticsDto();
  48. #region 办结工单
  49. dto.CompletionCount =await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status>= EOrderStatus.Filed).CountAsync();
  50. int CompletionSum = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status >= EOrderStatus.Handling).CountAsync();
  51. if (CompletionSum==0)
  52. {
  53. dto.CompletionRate = 0;
  54. }
  55. else
  56. {
  57. dto.CompletionRate = Math.Round((dto.CompletionCount / (double)CompletionSum) * 100, 2);
  58. }
  59. #endregion
  60. #region 待受理工单
  61. dto.HaveToAcceptCount =await _orderRepository.Queryable(false, false, false).Where(x => x.CreationTime > StartDate && x.CreationTime <= EndDate && x.Status == EOrderStatus.WaitForAccept).CountAsync();
  62. int HaveToAcceptSum = await _orderRepository.Queryable(false, false, false).Where(x => x.CreationTime >= StartDate && x.CreationTime <= EndDate).CountAsync();
  63. if (HaveToAcceptSum == 0)
  64. {
  65. dto.HaveToAcceptRate = 0;
  66. }
  67. else
  68. {
  69. dto.HaveToAcceptRate = Math.Round((dto.HaveToAcceptCount / (double)HaveToAcceptSum) * 100, 2);
  70. }
  71. #endregion
  72. #region 超期工单
  73. dto.OverTimeCount = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.ExpiredStatus == EExpiredStatus.Expired).CountAsync();
  74. if (CompletionSum==0)
  75. {
  76. dto.OverTimeRate = 0;
  77. }
  78. else
  79. {
  80. dto.OverTimeRate = Math.Round((dto.OverTimeCount / (double)CompletionSum) * 100, 2);
  81. }
  82. #endregion
  83. #region 延期工单
  84. dto.DelayCount = await _orderDelayRepository.Queryable().Where(x => x.ApplyDelayTime >= StartDate && x.ApplyDelayTime <= EndDate && x.DelayState == EDelayState.Pass).CountAsync();
  85. if (CompletionSum==0)
  86. {
  87. dto.DelayRate = 0;
  88. }
  89. else
  90. {
  91. dto.DelayRate = Math.Round((dto.DelayCount / (double)CompletionSum) * 100, 2);
  92. }
  93. #endregion
  94. #region 满意工单
  95. dto.SatisfiedCount =await _orderVisitRepository.Queryable().Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited && SqlFunc.JsonField(x.NowEvaluate, "Key") != "1" && SqlFunc.JsonField(x.NowEvaluate,"Key")!="2" ).CountAsync();
  96. int SatisfiedSum = await _orderVisitRepository.Queryable().Where(x => x.VisitTime >= StartDate && x.VisitTime <= EndDate && x.VisitState == EVisitState.Visited).CountAsync();
  97. if (SatisfiedSum==0)
  98. {
  99. dto.SatisfiedRate = 0;
  100. }
  101. else
  102. {
  103. dto.SatisfiedRate = Math.Round((dto.SatisfiedCount / (double)SatisfiedSum) * 100, 2);
  104. }
  105. #endregion
  106. #region 省工单量
  107. dto.ProvinceOrderCount =await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.IsProvince).CountAsync();
  108. dto.ProvinceOrderCompletionCount = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.IsProvince && x.Status >= EOrderStatus.Filed).CountAsync();
  109. #endregion
  110. return dto;
  111. }
  112. /// <summary>
  113. /// 知识库统计
  114. /// </summary>
  115. /// <returns></returns>
  116. [AllowAnonymous]
  117. [HttpGet("knowledge-statistics")]
  118. public async Task<KnowledgeStatisticsDto> KnowledgeStatistics()
  119. {
  120. var dto = new KnowledgeStatisticsDto();
  121. dto.KnowledgeCount = await _knowledgeRepository.Queryable().Where(x => x.Status == EKnowledgeStatus.OnShelf).CountAsync();//总数
  122. dto.TodayAddCount = await _knowledgeRepository.Queryable().Where(x => x.Renewaln==false && x.Status == EKnowledgeStatus.OnShelf && x.OnShelfTime.Value.Date== DateTime.Now.Date).CountAsync();//今日新增
  123. dto.ThisMonthModifyCount = await _knowledgeRepository.Queryable().Where(x => x.Renewaln == true && x.Status == EKnowledgeStatus.OnShelf && x.OnShelfTime.Value.Year
  124. == DateTime.Now.Year && x.OnShelfTime.Value.Month == DateTime.Now.Month).CountAsync();//本月修改
  125. dto.TodayReadCount = await _knowledgePvRepository.Queryable().Where(x => x.CreationTime.Date == DateTime.Now.Date).CountAsync();
  126. return dto;
  127. }
  128. /// <summary>
  129. /// 受理类型办件分析
  130. /// </summary>
  131. /// <param name="StartDate"></param>
  132. /// <param name="EndDate"></param>
  133. /// <returns></returns>
  134. [AllowAnonymous]
  135. [HttpGet("ordertype-statistics")]
  136. public async Task<List<OrderTypeHandleStatisticsDto>> OrderTypeHandleStatistics(DateTime StartDate,DateTime EndDate)
  137. {
  138. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  139. var list =await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.Handling && !string.IsNullOrEmpty(x.AcceptType))
  140. .GroupBy(x=>x.AcceptType)
  141. .Select(x => new OrderTypeHandleStatisticsDto
  142. {
  143. AcceptType = x.AcceptType,
  144. SumCount = SqlFunc.AggregateCount(x.Id),
  145. HandlingCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status>= EOrderStatus.Handling && x.Status < EOrderStatus.Filed,1,0)),
  146. FiledCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.Status>= EOrderStatus.Filed,1,0)),
  147. OverTimeCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.ExpiredStatus == EExpiredStatus.Expired,1,0))
  148. }).ToListAsync();
  149. return list;
  150. }
  151. /// <summary>
  152. /// 获取区域信息
  153. /// </summary>
  154. /// <returns></returns>
  155. [HttpGet("get_system_area")]
  156. [AllowAnonymous]
  157. public async Task<object> GetSystemAreaAsync()
  158. {
  159. return await _systemAreaRepository.Queryable()
  160. .Where(p => p.Id == "511500" || p.ParentId == "511500")
  161. .Select(p => new
  162. {
  163. p.AreaName,
  164. p.Id
  165. })
  166. .OrderBy(p => p.Id)
  167. .ToListAsync();
  168. }
  169. /// <summary>
  170. /// 预警热点
  171. /// </summary>
  172. /// <param name="StartDate"></param>
  173. /// <param name="EndDate"></param>
  174. /// <param name="AreaCode"></param>
  175. /// <returns></returns>
  176. [AllowAnonymous]
  177. [HttpGet("earlywarning-statistics")]
  178. public async Task<List<EarlyWarningHotsPotsStatisticsDto>> EarlyWarningHotsPotsStatistics(DateTime StartDate, DateTime EndDate,string AreaCode)
  179. {
  180. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  181. if (AreaCode.Length==6 && AreaCode.IndexOf("00") == 4)
  182. {
  183. AreaCode = AreaCode.Remove(4);
  184. }
  185. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  186. var list = await _orderRepository.Queryable(false, false, false)
  187. .Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.AreaCode.StartsWith(AreaCode) && !x.HotspotId.StartsWith("18"))
  188. .GroupBy(x => new { x.HotspotId, x.HotspotName,x.HotspotSpliceName })
  189. .Select(x => new EarlyWarningHotsPotsStatisticsDto()
  190. {
  191. HotspotId = x.HotspotId,
  192. HotspotName = x.HotspotName,
  193. HotspotSpliceName = x.HotspotSpliceName,
  194. SumCount = SqlFunc.AggregateCount(x.Id)
  195. }).OrderByDescending(x=>x.SumCount).Take(5).ToListAsync();
  196. return list;
  197. }
  198. /// <summary>
  199. /// 工单当日统计及环比
  200. /// </summary>
  201. /// <returns></returns>
  202. [AllowAnonymous]
  203. [HttpGet("ordercount-statistics")]
  204. public async Task<OrderCountStatisticsDto> OrderCountStatistics()
  205. {
  206. var today = DateTime.Now;
  207. var dto = new OrderCountStatisticsDto();
  208. #region 当日工单量
  209. dto.ToDayCount = await _orderRepository.Queryable(false,false,false).Where(x => x.StartTime.Value.Date == DateTime.Now.Date && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  210. var beforToDayCount = await _orderRepository.Queryable(false, false, false)
  211. //.Where(x => x.StartTime.Value.Date == today.AddDays(-1).Date && x.Status > EOrderStatus.WaitForAccept)
  212. .Where(x=>x.StartTime.Value.Date == DateTime.Now.AddDays(-1).Date && x.Status > EOrderStatus.WaitForAccept)
  213. .CountAsync();
  214. if (beforToDayCount == 0)
  215. {
  216. dto.ToDayQoQ = 0;
  217. }
  218. else
  219. {
  220. dto.ToDayQoQ = Math.Round(((dto.ToDayCount - beforToDayCount) / (double)beforToDayCount) * 100, 2);
  221. }
  222. #endregion
  223. #region 当月工单量
  224. dto.ToMonthCount = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime.Value.ToString("yyyy-MM") == today.ToString("yyyy-MM") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  225. var beforToMonthCount = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime.Value.ToString("yyyy-MM") == today.AddMonths(-1).ToString("yyyy-MM") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  226. if (beforToMonthCount==0)
  227. {
  228. dto.ToMonthQoQ = 0;
  229. }
  230. else
  231. {
  232. dto.ToMonthQoQ = Math.Round(((dto.ToMonthCount - beforToMonthCount) / (double)beforToMonthCount) * 100, 2);
  233. }
  234. #endregion
  235. #region 当年工单量
  236. dto.ToYearCount = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime.Value.ToString("yyyy") == today.ToString("yyyy") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  237. var beforToYearCount = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime.Value.ToString("yyyy") == today.AddYears(-1).ToString("yyyy") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  238. if (beforToYearCount==0)
  239. {
  240. dto.ToYearQoQ = 0;
  241. }
  242. else
  243. {
  244. dto.ToYearQoQ = Math.Round(((dto.ToYearCount - beforToYearCount) / (double)beforToYearCount) * 100, 2);
  245. }
  246. #endregion
  247. return dto;
  248. }
  249. /// <summary>
  250. /// 区域受理排行
  251. /// </summary>
  252. /// <returns></returns>
  253. [AllowAnonymous]
  254. [HttpGet("orderarea-accept-statistics")]
  255. public async Task<List<OrderAreaAcceptStatisticsDto>> OrderAreaAcceptStatistics(DateTime StartDate,DateTime EndDate)
  256. {
  257. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  258. var list = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime>= StartDate && x.StartTime<= EndDate && x.Status > EOrderStatus.WaitForAccept)
  259. .LeftJoin<SystemArea>((it,o)=> it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  260. .GroupBy((it,o) => new {
  261. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  262. o.AreaName,
  263. })
  264. .Select((it,o) => new OrderAreaAcceptStatisticsDto()
  265. {
  266. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  267. AreaName = o.AreaName,
  268. AcceptedCount = SqlFunc.AggregateCount(it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  269. CompletionCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status>= EOrderStatus.Filed,1,0))
  270. }).MergeTable()
  271. .Where(x=> x.AreaCode!= "519800" && x.AreaCode!= "519900").OrderByDescending(it=> it.AcceptedCount).ToListAsync();
  272. return list;
  273. }
  274. /// <summary>
  275. /// 区域明细数据
  276. /// </summary>
  277. /// <param name="StartDate"></param>
  278. /// <param name="EndDate"></param>
  279. /// <param name="AreaCode"></param>
  280. /// <returns></returns>
  281. [AllowAnonymous]
  282. [HttpGet("orderareaaccept-query")]
  283. public async Task<List<OrderAreaAcceptQueryDto>> OrderAreaAcceptQuery(DateTime StartDate,DateTime EndDate)
  284. {
  285. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  286. var areaList =await _systemAreaRepository.Queryable()
  287. .Where(x => !x.Id.EndsWith("00"))
  288. .GroupBy(x => new {
  289. Id = x.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  290. })
  291. .Select(x => new {
  292. Id = x.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  293. })
  294. .MergeTable()
  295. .LeftJoin<SystemArea>((it,o)=> it.Id == o.Id)
  296. .Select((it, o) => new {
  297. Id = it.Id,
  298. Name=o.AreaName
  299. })
  300. .ToListAsync();
  301. var list = new List<OrderAreaAcceptQueryDto>();
  302. foreach (var item in areaList)
  303. {
  304. #region 单个获取
  305. var dto = new OrderAreaAcceptQueryDto();
  306. dto.AreaCode = item.Id;
  307. dto.AreaName = item.Name;
  308. dto.HandlingCount = await _orderRepository.Queryable(false, false, false).Where(x => x.AreaCode == item.Id && x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept && x.Status < EOrderStatus.Filed).CountAsync();
  309. dto.FiledCount = await _orderRepository.Queryable(false, false, false).Where(x => x.AreaCode == item.Id && x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status >= EOrderStatus.Filed).CountAsync();
  310. dto.OverTimeCount = await _orderRepository.Queryable(false, false, false).Where(x => x.AreaCode == item.Id && x.StartTime >= StartDate && x.StartTime <= EndDate && x.ExpiredStatus == EExpiredStatus.Expired).CountAsync();
  311. var hotsPot = await _orderRepository.Queryable(false, false, false).Where(x => x.AreaCode == item.Id && x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept).GroupBy(x => new { x.HotspotId, x.HotspotName })
  312. .Select(x => new
  313. {
  314. HotsPotName = x.HotspotName,
  315. HotCount = SqlFunc.AggregateCount(x.HotspotId)
  316. }).OrderByDescending(x => x.HotCount).FirstAsync();
  317. dto.HotspotName = hotsPot?.HotsPotName;
  318. #region 满意度
  319. var SatisfiedCount = await _orderRepository.Queryable(false, false, false)
  320. .LeftJoin<OrderVisit>((it, o) => it.Id == o.OrderId && o.VisitState == EVisitState.Visited)
  321. .Where((it, o) => it.AreaCode == item.Id && o.VisitTime >= StartDate && o.VisitTime <= EndDate
  322. && SqlFunc.JsonField(o.NowEvaluate, "Key") != "1" && SqlFunc.JsonField(o.NowEvaluate, "Key") != "2")
  323. .CountAsync();
  324. var VisitCount = await _orderRepository.Queryable(false, false, false)
  325. .LeftJoin<OrderVisit>((it, o) => it.Id == o.OrderId && o.VisitState == EVisitState.Visited)
  326. .Where((it, o) => it.AreaCode == item.Id && o.VisitTime >= StartDate && o.VisitTime <= EndDate)
  327. .CountAsync();
  328. if (SatisfiedCount!=0 && VisitCount!=0)
  329. {
  330. dto.SatisfiedRate = Math.Round((SatisfiedCount / (double)VisitCount) * 100, 2);
  331. }
  332. #endregion
  333. list.Add(dto);
  334. #endregion
  335. }
  336. return list;
  337. }
  338. /// <summary>
  339. /// 办理中工单概览
  340. /// </summary>
  341. /// <returns></returns>
  342. [AllowAnonymous]
  343. [HttpGet("order-handling-query")]
  344. public async Task<List<OrderDto>> OrderHandlingDetailQuery()
  345. {
  346. var list = await _orderRepository
  347. .Queryable(false, false, false)
  348. .Where(x => x.Status > EOrderStatus.WaitForAccept && x.StartTime.Value.Date == DateTime.Now.Date )
  349. //.Where(x => x.Status > EOrderStatus.WaitForAccept && x.StartTime.Value.Date == DateTime.Parse("2024-03-14").Date)
  350. .OrderByDescending(x=>x.StartTime)
  351. .Take(50)
  352. .ToListAsync();
  353. return _mapper.Map<List<OrderDto>>(list);
  354. }
  355. /// <summary>
  356. /// 30天高频事项预警
  357. /// </summary>
  358. /// <returns></returns>
  359. [AllowAnonymous]
  360. [HttpGet("highmatter-warning")]
  361. public async Task<List<HighMatterWarningDto>> HighMatterWarning(DateTime StartDate,DateTime EndDate)
  362. {
  363. //var endDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
  364. //var startDate = endDate.AddDays(-30).Date;
  365. List<string> filterTitle = new List<string>();
  366. filterTitle.Add("无声");
  367. filterTitle.Add("骚扰");
  368. filterTitle.Add("错拨");
  369. filterTitle.Add("测试");
  370. var list = await _orderRepository.Queryable(false, false, false)
  371. .Where(x => x.CreationTime >= StartDate && x.CreationTime <= EndDate)
  372. .Where(x=> filterTitle.Any(s=> x.Title.Contains(s)) == false)
  373. .LeftJoin<SystemArea>((it, o) => it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  374. .GroupBy((it, o) => new
  375. {
  376. it.AcceptTypeCode,
  377. it.HotspotId,
  378. it.HotspotName,
  379. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  380. o.AreaName,
  381. })
  382. .Having((it,o) => SqlFunc.AggregateCount(it.HotspotName)>=5)
  383. .Select((it, o) => new HighMatterWarningDto()
  384. {
  385. AreaName = o.AreaName,
  386. //Title = it.Title,
  387. HotspotName = it.HotspotName,
  388. SumCount = SqlFunc.AggregateCount(it.HotspotName),
  389. Id = SqlFunc.AggregateMin(it.Id)
  390. })
  391. .MergeTable()
  392. //.Where(x=>x.SumCount>=5)
  393. .LeftJoin<Order>((x,d)=>x.Id==d.Id)
  394. .Select((x,d)=>new HighMatterWarningDto() {
  395. AreaName = x.AreaName,
  396. HotspotName = x.HotspotName,
  397. Title = d.Title,
  398. SumCount = x.SumCount,
  399. Id = d.Id,
  400. }).Take(50).ToListAsync();
  401. return list;
  402. }
  403. /// <summary>
  404. /// 部门满意度排行榜
  405. /// </summary>
  406. /// <param name="StartDate"></param>
  407. /// <param name="EndDate"></param>
  408. /// <returns></returns>
  409. [AllowAnonymous]
  410. [HttpGet("ordervisit-orgsatisfaction-rank")]
  411. public async Task<List<OrderVisitOrgSatisfactionRankDto>> OrderVisitOrgSatisfactionRank(DateTime StartDate,DateTime EndDate)
  412. {
  413. var list = await _orderVisitDetailRepository.Queryable()
  414. .Includes(x => x.OrderVisit)
  415. .Where(x => x.OrderVisit.VisitTime >= StartDate && x.OrderVisit.VisitTime <= EndDate && x.VisitTarget == EVisitTarget.Org && x.VisitOrgCode.Length >= 6 && x.OrderVisit.VisitState == EVisitState.Visited)
  416. .GroupBy(x => new
  417. {
  418. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  419. x.VisitOrgName
  420. })
  421. .Select(x => new OrderVisitOrgSatisfactionRankDto()
  422. {
  423. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  424. VisitOrgName = x.VisitOrgName,
  425. SatisfiedCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "1" && SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "2", 1, 0)),
  426. VisitCount = SqlFunc.AggregateCount(x.VisitOrgName)
  427. }).MergeTable().OrderByDescending(x=>x.SatisfiedCount).Take(10).ToListAsync();
  428. return list;
  429. }
  430. /// <summary>
  431. /// 占比分析
  432. /// </summary>
  433. /// <param name="StartDate"></param>
  434. /// <param name="EndDate"></param>
  435. /// <param name="IsSource"></param>
  436. /// <returns></returns>
  437. [AllowAnonymous]
  438. [HttpGet("order-source-accepttype-statistics")]
  439. public async Task<List<OrderSourceAndAcceptTtoeStatisticsDto>> OrderSourceAndAcceptTtoeStatistics(DateTime StartDate,DateTime EndDate,bool IsSource)
  440. {
  441. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  442. int SumCount = await _orderRepository.Queryable(false, false, false)
  443. .Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  444. if (IsSource)
  445. {
  446. var list = await _orderRepository.Queryable(false, false, false)
  447. .Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept)
  448. .GroupBy(x => new { x.SourceChannelCode, x.SourceChannel })
  449. .Select(x => new OrderSourceAndAcceptTtoeStatisticsDto()
  450. {
  451. Name = x.SourceChannel,
  452. SumCount = SumCount,
  453. HasCount = SqlFunc.AggregateCount(x.SourceChannel)
  454. }).ToListAsync();
  455. return list;
  456. }
  457. else
  458. {
  459. var list = await _orderRepository.Queryable(false, false, false)
  460. .Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept)
  461. .GroupBy( x => new { x.AcceptTypeCode, x.AcceptType })
  462. .Select(x => new OrderSourceAndAcceptTtoeStatisticsDto()
  463. {
  464. Name = x.AcceptType,
  465. SumCount = SumCount,
  466. HasCount = SqlFunc.AggregateCount(x.AcceptTypeCode),
  467. }).ToListAsync();
  468. return list;
  469. }
  470. }
  471. }
  472. }