IndustryClassificationApplication.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using Hotline.FlowEngine.Workflows;
  2. using Hotline.IndustryClassification;
  3. using Hotline.Orders;
  4. using Hotline.Settings;
  5. using Hotline.Share.Dtos.IndustryClassification;
  6. using Hotline.Share.Enums.FlowEngine;
  7. using Hotline.Share.Enums.Order;
  8. using Hotline.Share.Requests;
  9. using MapsterMapper;
  10. using SqlSugar;
  11. using XF.Domain.Authentications;
  12. using XF.Domain.Dependency;
  13. namespace Hotline.Application.IndustryClassification
  14. {
  15. public class IndustryClassificationApplication : IIndustryClassificationApplication, IScopeDependency
  16. {
  17. private readonly IMapper _mapper;
  18. private readonly ISystemOrganizeRepository _organizeRepository;
  19. private readonly IIndustryClassificationRepositpry _industrialManagementRepository;
  20. private readonly ISessionContext _sessionContext;
  21. private readonly IOrderRepository _orderRepository;
  22. public IndustryClassificationApplication(IMapper mapper,
  23. ISystemOrganizeRepository organizeRepository,
  24. IIndustryClassificationRepositpry industrialManagementRepository,
  25. ISessionContext sessionContext,
  26. IOrderRepository orderRepository)
  27. {
  28. _mapper = mapper;
  29. _organizeRepository = organizeRepository;
  30. _industrialManagementRepository = industrialManagementRepository;
  31. _sessionContext = sessionContext;
  32. _orderRepository = orderRepository;
  33. }
  34. /// <summary>
  35. /// 查询行业列表
  36. /// </summary>
  37. /// <param name="dto"></param>
  38. /// <returns></returns>
  39. public ISugarQueryable<IndustrialManagementDto> GetIndustrialManagementList(PagedKeywordRequest dto)
  40. {
  41. var query = _industrialManagementRepository.Queryable()
  42. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), p => p.IndustrialName.Contains(dto.Keyword))
  43. .Select(p => new IndustrialManagementDto
  44. {
  45. Id = p.Id,
  46. IndustrialName = p.IndustrialName,
  47. UpdateTime = SqlFunc.IIF(p.LastModificationTime != null, p.LastModificationTime, p.CreationTime),
  48. OrgCount = SqlFunc.Subqueryable<IndustryAssociations>().Where(s => s.IndustrialManagementId == p.Id).Count()
  49. })
  50. .MergeTable()
  51. .OrderByDescending(p => p.UpdateTime);
  52. return query;
  53. }
  54. /// <summary>
  55. /// 行业诉求工单
  56. /// </summary>
  57. /// <param name="dto"></param>
  58. /// <returns></returns>
  59. public ISugarQueryable<IndustrialManagementOrderDto> GetIndustrialManagementOrderList(IndustrialManagementRequestDto dto)
  60. {
  61. string industrialId = "";
  62. if (!_sessionContext.OrgIsCenter)
  63. {
  64. var industrial = _industrialManagementRepository.Queryable()
  65. .Includes(d => d.Orgs)
  66. .FirstAsync(d => d.Orgs.Any(p => p.Id == _sessionContext.RequiredOrgId)).GetAwaiter().GetResult();
  67. if (industrial is not null)
  68. industrialId = industrial.Id;
  69. else
  70. industrialId = "-1";
  71. }
  72. var queryorder = _industrialManagementRepository.Queryable()
  73. .InnerJoin<IndustryAssociations>((i, io) => i.Id == io.IndustrialManagementId)
  74. .InnerJoin<Order>((i, io, o) => io.OrganizeId == o.ActualHandleOrgCode)
  75. // .InnerJoin<Order>((i, io, s, o) => s.ExternalId == o.Id)
  76. .Where((i, io, o) => o.Status >= EOrderStatus.Filed)
  77. .WhereIF(!string.IsNullOrEmpty(industrialId), (i, io, o) => io.IndustrialManagementId == industrialId)
  78. .OrderBy((i, io, o) => i.Id)
  79. .GroupBy((i, io, o) => new
  80. {
  81. o.Id,
  82. o.Status,
  83. IndustrialId = i.Id,
  84. i.IndustrialName,
  85. o.Title,
  86. o.No,
  87. o.AcceptType,
  88. o.AcceptTypeCode,
  89. o.HotspotId,
  90. o.HotspotName,
  91. o.HotspotSpliceName,
  92. o.HotspotExternal,
  93. o.CreationTime,
  94. o.StartTime,
  95. o.OrgLevelOneCode,
  96. o.OrgLevelOneName,
  97. o.ActualHandleOrgName,
  98. o.ActualHandleOrgCode,
  99. o.CounterSignType,
  100. o.FiledTime,
  101. o.ExpiredTime,
  102. o.NearlyExpiredTime,
  103. o.NearlyExpiredTimeOne
  104. })
  105. .Select((i, io, o) => new IndustrialManagementOrderDto
  106. {
  107. Id = o.Id,
  108. Status = o.Status,
  109. IndustrialId = i.Id,
  110. IndustrialName = i.IndustrialName,
  111. Title = o.Title,
  112. No = o.No,
  113. AcceptType = o.AcceptType,
  114. AcceptTypeCode = o.AcceptTypeCode,
  115. HotspotId = o.HotspotId,
  116. HotspotName = o.HotspotName,
  117. HotspotSpliceName = o.HotspotSpliceName,
  118. HotspotExternal = o.HotspotExternal,
  119. CreationTime = o.CreationTime,
  120. StartTime = o.StartTime,
  121. OrgLevelOneCode = o.OrgLevelOneCode,
  122. OrgLevelOneName = o.OrgLevelOneName,
  123. ActualHandleOrgName = o.ActualHandleOrgName,
  124. ActualHandleOrgCode = o.ActualHandleOrgCode,
  125. CounterSignType = o.CounterSignType,
  126. FiledTime = o.FiledTime,
  127. ExpiredTime = o.ExpiredTime,
  128. NearlyExpiredTime = o.NearlyExpiredTime,
  129. NearlyExpiredTimeOne = o.NearlyExpiredTimeOne
  130. }).MergeTable()
  131. ;
  132. var queryhuiqian = _industrialManagementRepository.Queryable()
  133. .InnerJoin<IndustryAssociations>((i, io) => i.Id == io.IndustrialManagementId)
  134. .InnerJoin<WorkflowTrace>((i, io, s) => io.OrganizeId == s.HandlerOrgId)
  135. .InnerJoin<Order>((i, io, s, o) => s.ExternalId == o.Id)
  136. .Where((i, io, s, o) => o.Status >= EOrderStatus.Filed && s.CountersignPosition == ECountersignPosition.Direct)
  137. .WhereIF(!string.IsNullOrEmpty(industrialId), (i, io, s, o) => io.IndustrialManagementId == industrialId)
  138. .OrderBy((i, io, s, o) => i.Id)
  139. .GroupBy((i, io, s, o) => new
  140. {
  141. o.Id,
  142. o.Status,
  143. IndustrialId = i.Id,
  144. i.IndustrialName,
  145. o.Title,
  146. o.No,
  147. o.AcceptType,
  148. o.AcceptTypeCode,
  149. o.HotspotId,
  150. o.HotspotName,
  151. o.HotspotSpliceName,
  152. o.HotspotExternal,
  153. o.CreationTime,
  154. o.StartTime,
  155. o.OrgLevelOneCode,
  156. o.OrgLevelOneName,
  157. o.ActualHandleOrgName,
  158. o.ActualHandleOrgCode,
  159. o.CounterSignType,
  160. o.FiledTime,
  161. o.ExpiredTime,
  162. o.NearlyExpiredTime,
  163. o.NearlyExpiredTimeOne
  164. })
  165. .Select((i, io, s, o) => new IndustrialManagementOrderDto
  166. {
  167. Id = o.Id,
  168. Status = o.Status,
  169. IndustrialId = i.Id,
  170. IndustrialName = i.IndustrialName,
  171. Title = o.Title,
  172. No = o.No,
  173. AcceptType = o.AcceptType,
  174. AcceptTypeCode = o.AcceptTypeCode,
  175. HotspotId = o.HotspotId,
  176. HotspotName = o.HotspotName,
  177. HotspotSpliceName = o.HotspotSpliceName,
  178. HotspotExternal = o.HotspotExternal,
  179. CreationTime = o.CreationTime,
  180. StartTime = o.StartTime,
  181. OrgLevelOneCode = o.OrgLevelOneCode,
  182. OrgLevelOneName = o.OrgLevelOneName,
  183. ActualHandleOrgName = o.ActualHandleOrgName,
  184. ActualHandleOrgCode = o.ActualHandleOrgCode,
  185. CounterSignType = o.CounterSignType,
  186. FiledTime = o.FiledTime,
  187. ExpiredTime = o.ExpiredTime,
  188. NearlyExpiredTime = o.NearlyExpiredTime,
  189. NearlyExpiredTimeOne = o.NearlyExpiredTimeOne
  190. }).MergeTable()
  191. ;
  192. var query = _orderRepository.UnionAll(queryorder, queryhuiqian)
  193. .OrderBy(d => d.Id)
  194. .GroupBy(d => new
  195. {
  196. d.Id,
  197. d.Status,
  198. d.IndustrialId,
  199. d.IndustrialName,
  200. d.Title,
  201. d.No,
  202. d.AcceptType,
  203. d.AcceptTypeCode,
  204. d.HotspotId,
  205. d.HotspotName,
  206. d.HotspotSpliceName,
  207. d.HotspotExternal,
  208. d.CreationTime,
  209. d.StartTime,
  210. d.OrgLevelOneCode,
  211. d.OrgLevelOneName,
  212. d.ActualHandleOrgName,
  213. d.ActualHandleOrgCode,
  214. d.CounterSignType,
  215. d.FiledTime,
  216. d.ExpiredTime,
  217. d.NearlyExpiredTime,
  218. d.NearlyExpiredTimeOne
  219. })
  220. .Select(d => new IndustrialManagementOrderDto
  221. {
  222. Id = d.Id,
  223. Status = d.Status,
  224. IndustrialId = d.IndustrialId,
  225. IndustrialName = d.IndustrialName,
  226. Title = d.Title,
  227. No = d.No,
  228. AcceptType = d.AcceptType,
  229. AcceptTypeCode = d.AcceptTypeCode,
  230. HotspotId = d.HotspotId,
  231. HotspotName = d.HotspotName,
  232. HotspotSpliceName = d.HotspotSpliceName,
  233. HotspotExternal = d.HotspotExternal,
  234. CreationTime = d.CreationTime,
  235. StartTime = d.StartTime,
  236. OrgLevelOneCode = d.OrgLevelOneCode,
  237. OrgLevelOneName = d.OrgLevelOneName,
  238. ActualHandleOrgName = d.ActualHandleOrgName,
  239. ActualHandleOrgCode = d.ActualHandleOrgCode,
  240. CounterSignType = d.CounterSignType,
  241. FiledTime = d.FiledTime,
  242. ExpiredTime = d.ExpiredTime,
  243. NearlyExpiredTime = d.NearlyExpiredTime,
  244. NearlyExpiredTimeOne = d.NearlyExpiredTimeOne
  245. }).MergeTable()
  246. .WhereIF(!string.IsNullOrEmpty(dto.IndustrialName), d => d.IndustrialName.Contains(dto.IndustrialName))
  247. .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Title.Contains(dto.Title))
  248. .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.No.Contains(dto.No))
  249. .WhereIF(!string.IsNullOrEmpty(dto.AcceptTypeCode), d => d.AcceptTypeCode == dto.AcceptTypeCode)
  250. .WhereIF(dto.StartTime.HasValue, d => d.CreationTime >= dto.StartTime) //受理时间开始
  251. .WhereIF(dto.EndTime.HasValue, d => d.CreationTime <= dto.EndTime) //受理时间结束
  252. .WhereIF(!string.IsNullOrEmpty(dto.HotspotSpliceName), d => d.HotspotSpliceName.Contains(dto.HotspotSpliceName))
  253. .WhereIF(!string.IsNullOrEmpty(dto.OrgLevelOneName), d => d.OrgLevelOneName.Contains(dto.OrgLevelOneName))
  254. .WhereIF(!string.IsNullOrEmpty(dto.ActualHandleOrgName), d => d.ActualHandleOrgName.Contains(dto.ActualHandleOrgName))
  255. .OrderByIF(string.IsNullOrEmpty(dto.SortField), d => d.CreationTime, OrderByType.Desc) //默认排序时间为创建时间
  256. .OrderByIF(dto is { SortField: "creationTime", SortRule: 0 }, d => d.CreationTime, OrderByType.Asc) //工单创建时间
  257. .OrderByIF(dto is { SortField: "creationTime", SortRule: 1 }, d => d.CreationTime, OrderByType.Desc) //工单创建时间降序
  258. ;
  259. return query;
  260. //var query = _industrialManagementRepository.Queryable()
  261. // .InnerJoin<IndustryAssociations>((i, io) => i.Id == io.IndustrialManagementId)
  262. // .InnerJoin<WorkflowStep>((i, io, s) => io.OrganizeId == s.HandlerOrgId)
  263. // .InnerJoin<Order>((i, io, s, o) => s.ExternalId == o.Id)
  264. // .Where((i, io, s, o) => o.Status >= EOrderStatus.Filed)
  265. // .WhereIF(!string.IsNullOrEmpty(industrialId), (i, io, s, o) => io.IndustrialManagementId == industrialId)
  266. // .OrderBy((i, io, s, o) => i.Id)
  267. // .GroupBy((i, io, s, o) => new
  268. // {
  269. // o.Id,
  270. // o.Status,
  271. // IndustrialId = i.Id,
  272. // i.IndustrialName,
  273. // o.Title,
  274. // o.No,
  275. // o.AcceptType,
  276. // o.AcceptTypeCode,
  277. // o.HotspotId,
  278. // o.HotspotName,
  279. // o.HotspotSpliceName,
  280. // o.HotspotExternal,
  281. // o.CreationTime,
  282. // o.StartTime,
  283. // o.OrgLevelOneCode,
  284. // o.OrgLevelOneName,
  285. // o.ActualHandleOrgName,
  286. // o.ActualHandleOrgCode,
  287. // o.CounterSignType,
  288. // o.FiledTime,
  289. // o.ExpiredTime,
  290. // o.NearlyExpiredTime,
  291. // o.NearlyExpiredTimeOne
  292. // })
  293. // .Select((i, io, s, o) => new IndustrialManagementOrderDto
  294. // {
  295. // Id = o.Id,
  296. // Status = o.Status,
  297. // IndustrialId = i.Id,
  298. // IndustrialName = i.IndustrialName,
  299. // Title = o.Title,
  300. // No = o.No,
  301. // AcceptType = o.AcceptType,
  302. // AcceptTypeCode = o.AcceptTypeCode,
  303. // HotspotId = o.HotspotId,
  304. // HotspotName = o.HotspotName,
  305. // HotspotSpliceName = o.HotspotSpliceName,
  306. // HotspotExternal = o.HotspotExternal,
  307. // CreationTime = o.CreationTime,
  308. // StartTime = o.StartTime,
  309. // OrgLevelOneCode = o.OrgLevelOneCode,
  310. // OrgLevelOneName = o.OrgLevelOneName,
  311. // ActualHandleOrgName = o.ActualHandleOrgName,
  312. // ActualHandleOrgCode = o.ActualHandleOrgCode,
  313. // CounterSignType = o.CounterSignType,
  314. // FiledTime = o.FiledTime,
  315. // ExpiredTime = o.ExpiredTime,
  316. // NearlyExpiredTime = o.NearlyExpiredTime,
  317. // NearlyExpiredTimeOne = o.NearlyExpiredTimeOne
  318. // }).MergeTable()
  319. // .WhereIF(!string.IsNullOrEmpty(dto.IndustrialName), d => d.IndustrialName.Contains(dto.IndustrialName))
  320. // .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Title.Contains(dto.Title))
  321. // .WhereIF(!string.IsNullOrEmpty(dto.No), d => d.No.Contains(dto.No))
  322. // .WhereIF(!string.IsNullOrEmpty(dto.AcceptTypeCode), d => d.AcceptTypeCode == dto.AcceptTypeCode)
  323. // .WhereIF(dto.StartTime.HasValue, d => d.CreationTime >= dto.StartTime) //受理时间开始
  324. // .WhereIF(dto.EndTime.HasValue, d => d.CreationTime <= dto.EndTime) //受理时间结束
  325. // .WhereIF(!string.IsNullOrEmpty(dto.HotspotSpliceName), d => d.HotspotSpliceName.Contains(dto.HotspotSpliceName))
  326. // .WhereIF(!string.IsNullOrEmpty(dto.OrgLevelOneName), d => d.OrgLevelOneName.Contains(dto.OrgLevelOneName))
  327. // .WhereIF(!string.IsNullOrEmpty(dto.ActualHandleOrgName), d => d.ActualHandleOrgName.Contains(dto.ActualHandleOrgName))
  328. // .OrderByIF(string.IsNullOrEmpty(dto.SortField), d => d.CreationTime, OrderByType.Desc) //默认排序时间为创建时间
  329. // .OrderByIF(dto is { SortField: "creationTime", SortRule: 0 }, d => d.CreationTime, OrderByType.Asc) //工单创建时间
  330. // .OrderByIF(dto is { SortField: "creationTime", SortRule: 1 }, d => d.CreationTime, OrderByType.Desc) //工单创建时间降序
  331. // ;
  332. }
  333. }
  334. }