OrderSnapshotApplicationTest.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using Hotline.Api.Controllers;
  2. using Hotline.Application.Snapshot;
  3. using Hotline.Caching.Interfaces;
  4. using Hotline.Identity.Accounts;
  5. using Hotline.Identity.Roles;
  6. using Hotline.Orders;
  7. using Hotline.Repository.SqlSugar.Extensions;
  8. using Hotline.Repository.SqlSugar.Snapshot;
  9. using Hotline.Settings;
  10. using Hotline.Share.Dtos;
  11. using Hotline.Share.Dtos.Snapshot;
  12. using Hotline.Share.Enums.Snapshot;
  13. using Hotline.Share.Requests;
  14. using Hotline.Share.Tools;
  15. using Hotline.Snapshot;
  16. using Hotline.Snapshot.IRepository;
  17. using Hotline.Tests.Mock;
  18. using Hotline.ThirdAccountDomainServices;
  19. using Hotline.ThirdAccountDomainServices.Interfaces;
  20. using Hotline.Users;
  21. using Microsoft.AspNetCore.Http;
  22. using Microsoft.Extensions.DependencyInjection;
  23. using NPOI.SS.Formula.Functions;
  24. using Shouldly;
  25. using System;
  26. using System.Collections.Generic;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Threading.Tasks;
  30. using XF.Domain.Cache;
  31. using XF.Domain.Repository;
  32. namespace Hotline.Tests.Application;
  33. public class OrderSnapshotApplicationTest : TestBase
  34. {
  35. private readonly OrderServiceMock _orderServiceMock;
  36. private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
  37. private readonly IOrderSnapshotRepository _orderSnapshotRepository;
  38. private readonly IOrderSnapshotApplication _orderSnapshotApplication;
  39. private readonly ISnapshotApplication _snapshotApplication;
  40. private readonly IIndustryLogRepository _industryLogRepository;
  41. private readonly ICommunityInfoRepository _communityInfoRepository;
  42. private readonly IRedPackAuditRepository _redPackAuditRepository;
  43. private readonly IRedPackRecordRepository _redPackRecordRepository;
  44. private readonly ISnapshotLabelLogRepository _snapshotLabelLogRepository;
  45. private readonly IRedPackApplication _redPackApplication;
  46. private readonly IOrderRepository _orderRepository;
  47. private readonly IIndustryCaseRepository _industryCaseRepository;
  48. private readonly ISnapshotPointsRecordRepository _pointsRecordRepository;
  49. private readonly IIndustryRepository _industryRepository;
  50. public OrderSnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, OrderServiceMock orderServiceMock, ISystemDicDataCacheManager systemDicDataCacheManager, IOrderSnapshotRepository orderSnapshotRepository, IOrderSnapshotApplication orderSnapshotApplication, ISnapshotApplication snapshotApplication, IIndustryLogRepository industryLogRepository, ICommunityInfoRepository communityInfoRepository, IRedPackAuditRepository redPackAuditRepository, IRedPackRecordRepository redPackRecordRepository, ISnapshotLabelLogRepository snapshotLabelLogRepository, ITypedCache<SystemSetting> cacheSettingData, IRedPackApplication redPackApplication, IOrderRepository orderRepository, ThirdAccounSupplierFactory thirdAccountDomainFactory, IIndustryCaseRepository industryCaseRepository, ISnapshotPointsRecordRepository pointsRecordRepository, IIndustryRepository industryRepository) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory)
  51. {
  52. _orderServiceMock = orderServiceMock;
  53. _systemDicDataCacheManager = systemDicDataCacheManager;
  54. _orderSnapshotRepository = orderSnapshotRepository;
  55. _orderSnapshotApplication = orderSnapshotApplication;
  56. _snapshotApplication = snapshotApplication;
  57. _industryLogRepository = industryLogRepository;
  58. _communityInfoRepository = communityInfoRepository;
  59. _redPackAuditRepository = redPackAuditRepository;
  60. _redPackRecordRepository = redPackRecordRepository;
  61. _snapshotLabelLogRepository = snapshotLabelLogRepository;
  62. _redPackApplication = redPackApplication;
  63. _orderRepository = orderRepository;
  64. _industryCaseRepository = industryCaseRepository;
  65. _pointsRecordRepository = pointsRecordRepository;
  66. _industryRepository = industryRepository;
  67. }
  68. /// <summary>
  69. /// 随手拍网格员超时:
  70. /// </summary>
  71. /// <returns></returns>
  72. [Fact]
  73. public async Task SnapshotWorkflow_Guider_Timeout_Test()
  74. {
  75. SetSettingCache(SettingConstants.OvertimeBack, "0.00027778");
  76. var order = _orderServiceMock.CreateSnapshotOrder(SetWeiXin)
  77. .办理到网格员(SetZuoXi)
  78. .StepHandle(async order =>
  79. {
  80. Thread.Sleep(5 * 1000);
  81. var orderEntity = await _orderRepository.GetAsync(order.Id);
  82. orderEntity.ActualHandleStepName.ShouldBe("工单标记");
  83. }
  84. ).GetCreateResult();
  85. }
  86. /// <summary>
  87. /// 随手拍办理流程:
  88. /// 坐席
  89. /// 网格员
  90. /// 派单员
  91. /// 一级部门
  92. /// 归档
  93. /// 发布工单
  94. /// 政法委部门审核网格红包
  95. /// 应急局部门审核网格员红包
  96. /// 部门审核市民红包
  97. /// </summary>
  98. /// <returns></returns>
  99. [Fact]
  100. public async Task SnapshotWorkflow_Guider_Test()
  101. {
  102. SetSettingCache(SettingConstants.OvertimeBack, "4");
  103. var snapshotLabels = _systemDicDataCacheManager.SnapshotOrderLabel;
  104. var inputLable = snapshotLabels.Where(m => m.DicDataValue == "bss").ToList();
  105. var industryCase = await _industryCaseRepository.Queryable().Where(m => m.IsEnable == true).FirstAsync();
  106. var order = _orderServiceMock.CreateSnapshotOrder(SetWeiXin)
  107. .办理到网格员(SetZuoXi)
  108. .StepHandle(async (order, mock) =>
  109. {
  110. var industry = await _industryRepository.Queryable()
  111. .LeftJoin<OrderSnapshot>((industry, snapshot) => industry.Id == snapshot.IndustryId)
  112. .Where((industry, snapshot) => snapshot.Id == order.Id)
  113. .Select((industry, snapshot) => new Industry(), true)
  114. .FirstAsync();
  115. var pointsRecord = await _pointsRecordRepository.Queryable().Where(m => m.OrderId == order.Id && m.Source == EPointsSource.Report).FirstAsync();
  116. pointsRecord.ShouldNotBeNull();
  117. pointsRecord.Points.ShouldBe(industry.ReportPoints!.Value);
  118. await _snapshotApplication.PostOrderGuiderSystemAsync(order.Id, CancellationToken.None);
  119. var orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
  120. orderSnapshot.IndustryName = "修改行业名称";
  121. await _orderSnapshotRepository.UpdateAsync(orderSnapshot);
  122. var industryLog = await _industryLogRepository.Queryable()
  123. .Where(m => m.OrderId == order.Id)
  124. .FirstAsync();
  125. industryLog.ShouldNotBeNull();
  126. industryLog.IndustryName.ShouldBe("修改行业名称");
  127. await _orderSnapshotRepository.Updateable()
  128. .SetColumns(m => m.IndustryName, industryLog.OldIndustryName)
  129. .Where(m => m.Id == order.Id)
  130. .ExecuteCommandAsync();
  131. await _orderRepository.Updateable()
  132. .SetColumns(m => m.OrderTagCode, "DHZY")
  133. .Where(m => m.Id == order.Id)
  134. .ExecuteCommandAsync();
  135. orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
  136. var replyDto = mock.GetGuiderSystemInDto(orderSnapshot.NetworkENumber);
  137. await _snapshotApplication.SaveGuiderSystemReplyAsync(replyDto, CancellationToken.None);
  138. orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
  139. orderSnapshot.CommunityName.ShouldNotBeNull();
  140. var orderReply = await _orderSnapshotRepository.GetByNetworkENumberAsync(replyDto.AppealNumber);
  141. orderReply.IsDanger.ShouldBe(replyDto.IsHiddenDanger == "1" ? true : false);
  142. orderReply.MemberMobile.ShouldBe(replyDto.MemberMobile);
  143. orderReply.MemberName.ShouldBe(replyDto.MemberName);
  144. orderReply.NetworkRemark.ShouldBe(replyDto.ReplyContent);
  145. orderReply.ReplyDate.Value.ToString("yyyy-MM-dd hh:mm:ss").ShouldBe(replyDto.ReplyDate);
  146. var community = await _communityInfoRepository.GetAsync(replyDto.OrgId);
  147. community.ShouldNotBeNull();
  148. community.Name.ShouldBe(replyDto.OrgName);
  149. community.FullName.ShouldBe(replyDto.OrgFullName);
  150. var orderEntity = await _orderRepository.GetAsync(order.Id);
  151. orderEntity.ActualHandleStepName.ShouldBe("工单标记");
  152. })
  153. .办理到派单员(Set班长)
  154. .办理到一级部门(SetPaiDanYuan)
  155. .办理到归档(Set一级部门, data =>
  156. {
  157. data.IsDangerDepartment = true;
  158. data.IndustryCase = industryCase.Id;
  159. data.IsRectifyDepartment = true;
  160. })
  161. .StepHandle(async order => {
  162. var snapshot = await _orderSnapshotRepository.GetAsync(order.Id);
  163. snapshot.IndustryCase.ShouldBe(industryCase.Id);
  164. })
  165. .发布工单(SetZuoXi, inputLable.Select(m => new Kv(m.DicDataName, m.DicDataName)).ToList())
  166. .StepHandle(async order =>
  167. {
  168. var log = _snapshotLabelLogRepository.Queryable().Where(m => m.OrderId == order.Id).First();
  169. log.ShouldNotBeNull();
  170. await _orderSnapshotApplication.UpdateIsEmphasisAsync(new UpdateIsEmphasisInDto { Ids = [order.Id] });
  171. var snapshot = _orderSnapshotRepository.Get(order.Id);
  172. snapshot.LabelName.ShouldBe(string.Join(',', inputLable.Select(m => m.DicDataName)), "label异常");
  173. snapshot.IsEmphasis.ShouldBe(true);
  174. })
  175. .部门审核网格员红包(Set政法委)
  176. .部门审核网格员红包(Set应急管理局)
  177. .StepHandle(async order =>
  178. {
  179. var redPackRecord = _redPackRecordRepository.Queryable()
  180. .Where(m => m.OrderId == order.Id && m.PeopleType == EReadPackUserType.Guider)
  181. .First();
  182. redPackRecord.Amount.ShouldNotBe(0);
  183. })
  184. .部门审核市民红包(Set应急管理局)
  185. .StepHandle(async order =>
  186. {
  187. var redPackAudit = _redPackAuditRepository.Queryable().Where(m => m.OrderId == order.Id).First();
  188. redPackAudit.Status.ShouldBe(ERedPackAuditStatus.Agree);
  189. var redPackRecord = _redPackRecordRepository.Queryable().Where(m => m.OrderId == order.Id).First();
  190. redPackRecord.ShouldNotBeNull();
  191. })
  192. .部门审核特殊红包(Set应急管理局)
  193. .StepHandle(async order =>
  194. {
  195. var baseData = await _redPackApplication.GetRedPackRecordBaseDataAsync(order.Id);
  196. baseData.AuditType.ShouldNotBeNull();
  197. baseData.AuditTypeCode.ShouldNotBeNull();
  198. baseData.Amount.ShouldNotBeNull();
  199. })
  200. .GetCreateResult();
  201. order.Id.ShouldNotBeNull();
  202. }
  203. /// <summary>
  204. /// 随手拍办理流程
  205. /// 工单标注 : 验证数据是否保存正确
  206. /// 获取已标注集合: 验证是否有已标注的数据
  207. /// </summary>
  208. /// <returns></returns>
  209. [Fact]
  210. public async Task SnapshotWrokflow_Test()
  211. {
  212. var snapshotLabels = _systemDicDataCacheManager.SnapshotOrderLabel;
  213. var inputLable = snapshotLabels.Where(m => m.DicDataValue == "bss").ToList();
  214. var order = _orderServiceMock.CreateSnapshotOrder(SetWeiXin)
  215. .办理到工单标注(SetZuoXi)
  216. .办理到派单员(SetZuoXi, false)
  217. .办理到归档(SetZuoXi)
  218. .发布工单(SetZuoXi, inputLable.Select(m => new Kv { Key = m.DicDataValue, Value = m.DicDataName }).ToList())
  219. .GetCreateResult();
  220. order.Id.ShouldNotBeNull();
  221. var snapshot = await _orderSnapshotRepository.GetAsync(order.Id);
  222. // 验证工单标注是否生效
  223. snapshot.ShouldNotBeNull();
  224. snapshot.IsTruthDepartment.ShouldBe(false);
  225. snapshot.LabelName.ShouldBe(string.Join('|', inputLable.Select(m => m.DicDataName)));
  226. snapshot.Labels.ShouldNotBeNull();
  227. snapshot.Labels.Count.ShouldBe(inputLable.Count);
  228. snapshot.IsSafetyDepartment.ShouldBe(false);
  229. var labelLog = await _orderSnapshotApplication.GetLabelOrderSnapshotLogItems(new LabelOrderSnapshotLogItemsInDto()).ToPagedListAsync(new PagedRequest());
  230. labelLog.Items.Any(m => m.Title.IsNullOrEmpty()).ShouldBe(false);
  231. labelLog.Items.Any(m => m.SourceChannel.IsNullOrEmpty()).ShouldBe(false);
  232. var sigedItems = await _orderSnapshotApplication.GetLabeledOrderSnapshotItems(new LabeledOrderSnapshotItemsInDto()).ToListAsync();
  233. sigedItems.Any(m => m.OrderId == order.Id).ShouldBe(true);
  234. }
  235. [Fact]
  236. public async Task GetOrderSnapshotElectrogasItems_Test()
  237. {
  238. var inDto = new OrderSnapshotItemsInDto();
  239. var items = (await _orderSnapshotApplication.GetOrderSnapshotElectrogasItems(inDto).ToPagedListAsync(inDto));
  240. items.Total.ShouldNotBe(0);
  241. }
  242. }