DataScreenController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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)
  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. /// <param name="StartDate"></param>
  155. /// <param name="EndDate"></param>
  156. /// <param name="AreaCode"></param>
  157. /// <returns></returns>
  158. [AllowAnonymous]
  159. [HttpGet("earlywarning-statistics")]
  160. public async Task<List<EarlyWarningHotsPotsStatisticsDto>> EarlyWarningHotsPotsStatistics(DateTime StartDate, DateTime EndDate,string AreaCode)
  161. {
  162. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  163. if (AreaCode.Length==6 && AreaCode.IndexOf("0") == 5)
  164. {
  165. AreaCode = AreaCode.Remove(4);
  166. }
  167. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  168. var list = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.AreaCode.StartsWith(AreaCode))
  169. .GroupBy(x => new { x.HotspotId, x.HotspotName })
  170. .Select(x => new EarlyWarningHotsPotsStatisticsDto()
  171. {
  172. HotspotId = x.HotspotId,
  173. HotspotName = x.HotspotName,
  174. SumCount = SqlFunc.AggregateCount(x.Id)
  175. }).OrderByDescending(x=>x.SumCount).Take(5).ToListAsync();
  176. return list;
  177. }
  178. /// <summary>
  179. /// 工单当日统计及环比
  180. /// </summary>
  181. /// <returns></returns>
  182. [AllowAnonymous]
  183. [HttpGet("ordercount-statistics")]
  184. public async Task<OrderCountStatisticsDto> OrderCountStatistics()
  185. {
  186. var today = DateTime.Now;
  187. var dto = new OrderCountStatisticsDto();
  188. #region 当日工单量
  189. dto.ToDayCount =await _orderRepository.Queryable(false,false,false).Where(x => x.StartTime.Value.Date == today.Date && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  190. var beforToDayCount = await _orderRepository.Queryable(false, false, false)
  191. //.Where(x => x.StartTime.Value.Date == today.AddDays(-1).Date && x.Status > EOrderStatus.WaitForAccept)
  192. .Where(x=>x.StartTime.Value.Date == SqlFunc.AggregateMax(x.StartTime).Value.Date && x.Status > EOrderStatus.WaitForAccept)
  193. .CountAsync();
  194. if (beforToDayCount == 0)
  195. {
  196. dto.ToDayQoQ = 0;
  197. }
  198. else
  199. {
  200. dto.ToDayQoQ = Math.Round(((dto.ToDayCount - beforToDayCount) / (double)beforToDayCount) * 100, 2);
  201. }
  202. #endregion
  203. #region 当月工单量
  204. 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();
  205. 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();
  206. if (beforToMonthCount==0)
  207. {
  208. dto.ToMonthQoQ = 0;
  209. }
  210. else
  211. {
  212. dto.ToMonthQoQ = Math.Round(((dto.ToMonthCount - beforToMonthCount) / (double)beforToMonthCount) * 100, 2);
  213. }
  214. #endregion
  215. #region 当年工单量
  216. dto.ToYearCount = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime.Value.ToString("yyyy") == today.ToString("yyyy") && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  217. 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();
  218. if (beforToYearCount==0)
  219. {
  220. dto.ToYearQoQ = 0;
  221. }
  222. else
  223. {
  224. dto.ToYearQoQ = Math.Round(((dto.ToYearCount - beforToYearCount) / (double)beforToYearCount) * 100, 2);
  225. }
  226. #endregion
  227. return dto;
  228. }
  229. /// <summary>
  230. /// 区域受理排行
  231. /// </summary>
  232. /// <returns></returns>
  233. [AllowAnonymous]
  234. [HttpGet("orderarea-accept-statistics")]
  235. public async Task<List<OrderAreaAcceptStatisticsDto>> OrderAreaAcceptStatistics(DateTime StartDate,DateTime EndDate)
  236. {
  237. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  238. var list = await _orderRepository.Queryable(false, false, false).Where(x => x.StartTime>= StartDate && x.StartTime<= EndDate && x.Status > EOrderStatus.WaitForAccept)
  239. .LeftJoin<SystemArea>((it,o)=> it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  240. .GroupBy((it,o) => new {
  241. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  242. o.AreaName,
  243. })
  244. .Select((it,o) => new OrderAreaAcceptStatisticsDto()
  245. {
  246. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  247. AreaName = o.AreaName,
  248. AcceptedCount = SqlFunc.AggregateCount(it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
  249. CompletionCount = SqlFunc.AggregateSum(SqlFunc.IIF(it.Status>= EOrderStatus.Filed,1,0))
  250. }).MergeTable().OrderByDescending(it=> it.AcceptedCount).ToListAsync();
  251. return list;
  252. }
  253. /// <summary>
  254. /// 区域明细数据
  255. /// </summary>
  256. /// <param name="StartDate"></param>
  257. /// <param name="EndDate"></param>
  258. /// <param name="AreaCode"></param>
  259. /// <returns></returns>
  260. [AllowAnonymous]
  261. [HttpGet("orderareaaccept-query")]
  262. public async Task<List<OrderAreaAcceptQueryDto>> OrderAreaAcceptQuery(DateTime StartDate,DateTime EndDate)
  263. {
  264. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  265. var areaList =await _systemAreaRepository.Queryable()
  266. .Where(x => !x.Id.EndsWith("00"))
  267. .GroupBy(x => new {
  268. Id = x.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  269. })
  270. .Select(x => new {
  271. Id = x.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  272. })
  273. .MergeTable()
  274. .LeftJoin<SystemArea>((it,o)=> it.Id == o.Id)
  275. .Select((it, o) => new {
  276. Id = it.Id,
  277. Name=o.AreaName
  278. })
  279. .ToListAsync();
  280. var list = new List<OrderAreaAcceptQueryDto>();
  281. foreach (var item in areaList)
  282. {
  283. #region 单个获取
  284. var dto = new OrderAreaAcceptQueryDto();
  285. dto.AreaCode = item.Id;
  286. dto.AreaName = item.Name;
  287. 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();
  288. 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();
  289. 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();
  290. 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 })
  291. .Select(x => new
  292. {
  293. HotsPotName = x.HotspotName,
  294. HotCount = SqlFunc.AggregateCount(x.HotspotId)
  295. }).OrderByDescending(x => x.HotCount).FirstAsync();
  296. dto.HotspotName = hotsPot?.HotsPotName;
  297. #region 满意度
  298. var SatisfiedCount = await _orderRepository.Queryable(false, false, false)
  299. .LeftJoin<OrderVisit>((it, o) => it.Id == o.OrderId && o.VisitState == EVisitState.Visited)
  300. .Where((it, o) => it.AreaCode == item.Id && o.VisitTime >= StartDate && o.VisitTime <= EndDate
  301. && SqlFunc.JsonField(o.NowEvaluate, "Key") != "1" && SqlFunc.JsonField(o.NowEvaluate, "Key") != "2")
  302. .CountAsync();
  303. var VisitCount = await _orderRepository.Queryable(false, false, false)
  304. .LeftJoin<OrderVisit>((it, o) => it.Id == o.OrderId && o.VisitState == EVisitState.Visited)
  305. .Where((it, o) => it.AreaCode == item.Id && o.VisitTime >= StartDate && o.VisitTime <= EndDate)
  306. .CountAsync();
  307. if (SatisfiedCount!=0 && VisitCount!=0)
  308. {
  309. dto.SatisfiedRate = Math.Round((SatisfiedCount / (double)VisitCount) * 100, 2);
  310. }
  311. #endregion
  312. list.Add(dto);
  313. #endregion
  314. }
  315. return list;
  316. }
  317. /// <summary>
  318. /// 办理中工单概览
  319. /// </summary>
  320. /// <returns></returns>
  321. [AllowAnonymous]
  322. [HttpGet("order-handling-query")]
  323. public async Task<List<OrderDto>> OrderHandlingDetailQuery()
  324. {
  325. var list = await _orderRepository
  326. .Queryable(false, false, false)
  327. //.Where(x => x.Status > EOrderStatus.WaitForAccept && x.StartTime.Value.Date == DateTime.Now.Date )
  328. .Where(x=>x.Status> EOrderStatus.WaitForAccept && x.StartTime.Value.Date == SqlFunc.AggregateMax(x.StartTime).Value.Date)
  329. .OrderByDescending(x=>x.StartTime)
  330. .Take(50)
  331. .ToListAsync();
  332. return _mapper.Map<List<OrderDto>>(list);
  333. }
  334. /// <summary>
  335. /// 30天高频事项预警
  336. /// </summary>
  337. /// <returns></returns>
  338. [AllowAnonymous]
  339. [HttpGet("highmatter-warning")]
  340. public async Task<List<HighMatterWarningDto>> HighMatterWarning(DateTime StartDate,DateTime EndDate)
  341. {
  342. //var endDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
  343. //var startDate = endDate.AddDays(-30).Date;
  344. var list = await _orderRepository.Queryable(false, false, false)
  345. .Where(x => x.CreationTime >= StartDate && x.CreationTime <= EndDate)
  346. .LeftJoin<SystemArea>((it, o) => it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
  347. .GroupBy((it, o) => new
  348. {
  349. it.AcceptTypeCode,
  350. it.HotspotId,
  351. it.HotspotName,
  352. AreaCode = it.AreaCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  353. o.AreaName,
  354. })
  355. .Having((it,o) => SqlFunc.AggregateCount(it.HotspotName)>=5)
  356. .Select((it, o) => new HighMatterWarningDto()
  357. {
  358. AreaName = o.AreaName,
  359. //Title = it.Title,
  360. HotspotName = it.HotspotName,
  361. SumCount = SqlFunc.AggregateCount(it.HotspotName),
  362. Id = SqlFunc.AggregateMin(it.Id)
  363. })
  364. .MergeTable()
  365. //.Where(x=>x.SumCount>=5)
  366. .LeftJoin<Order>((x,d)=>x.Id==d.Id)
  367. .Select((x,d)=>new HighMatterWarningDto() {
  368. AreaName = x.AreaName,
  369. HotspotName = x.HotspotName,
  370. Title = d.Title,
  371. SumCount = x.SumCount,
  372. Id = d.Id,
  373. }).Take(50).ToListAsync();
  374. return list;
  375. }
  376. /// <summary>
  377. /// 部门满意度排行榜
  378. /// </summary>
  379. /// <param name="StartDate"></param>
  380. /// <param name="EndDate"></param>
  381. /// <returns></returns>
  382. [AllowAnonymous]
  383. [HttpGet("ordervisit-orgsatisfaction-rank")]
  384. public async Task<List<OrderVisitOrgSatisfactionRankDto>> OrderVisitOrgSatisfactionRank(DateTime StartDate,DateTime EndDate)
  385. {
  386. var list = await _orderVisitDetailRepository.Queryable()
  387. .Includes(x => x.OrderVisit)
  388. .Where(x => x.OrderVisit.VisitTime >= StartDate && x.OrderVisit.VisitTime <= EndDate && x.VisitTarget == EVisitTarget.Org && x.VisitOrgCode.Length >= 6 && x.OrderVisit.VisitState == EVisitState.Visited)
  389. .GroupBy(x => new
  390. {
  391. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  392. x.VisitOrgName
  393. })
  394. .Select(x => new OrderVisitOrgSatisfactionRankDto()
  395. {
  396. VisitOrgCode = x.VisitOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
  397. VisitOrgName = x.VisitOrgName,
  398. SatisfiedCount = SqlFunc.AggregateSum(SqlFunc.IIF(SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "1" && SqlFunc.JsonField(x.OrgProcessingResults, "Key") != "2", 1, 0)),
  399. VisitCount = SqlFunc.AggregateCount(x.VisitOrgName)
  400. }).MergeTable().OrderByDescending(x=>x.SatisfiedCount).Take(10).ToListAsync();
  401. return list;
  402. }
  403. /// <summary>
  404. /// 占比分析
  405. /// </summary>
  406. /// <param name="StartDate"></param>
  407. /// <param name="EndDate"></param>
  408. /// <param name="IsSource"></param>
  409. /// <returns></returns>
  410. [AllowAnonymous]
  411. [HttpGet("order-source-accepttype-statistics")]
  412. public async Task<List<OrderSourceAndAcceptTtoeStatisticsDto>> OrderSourceAndAcceptTtoeStatistics(DateTime StartDate,DateTime EndDate,bool IsSource)
  413. {
  414. EndDate = EndDate.AddDays(1).AddSeconds(-1);
  415. int SumCount = await _orderRepository.Queryable(false, false, false)
  416. .Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept).CountAsync();
  417. if (IsSource)
  418. {
  419. var list = await _orderRepository.Queryable(false, false, false)
  420. .Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept)
  421. .GroupBy(x => new { x.SourceChannelCode, x.SourceChannel })
  422. .Select(x => new OrderSourceAndAcceptTtoeStatisticsDto()
  423. {
  424. Name = x.SourceChannel,
  425. SumCount = SumCount,
  426. HasCount = SqlFunc.AggregateCount(x.SourceChannel)
  427. }).ToListAsync();
  428. return list;
  429. }
  430. else
  431. {
  432. var list = await _orderRepository.Queryable(false, false, false)
  433. .Where(x => x.StartTime >= StartDate && x.StartTime <= EndDate && x.Status > EOrderStatus.WaitForAccept)
  434. .GroupBy( x => new { x.AcceptTypeCode, x.AcceptType })
  435. .Select(x => new OrderSourceAndAcceptTtoeStatisticsDto()
  436. {
  437. Name = x.AcceptType,
  438. SumCount = SumCount,
  439. HasCount = SqlFunc.AggregateCount(x.AcceptTypeCode),
  440. }).ToListAsync();
  441. return list;
  442. }
  443. }
  444. }
  445. }