ProvinceService.cs 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104
  1. using DataSharing.RawData;
  2. using DataSharing.SendTask;
  3. using DataSharing.Share.Consts;
  4. using DataSharing.Share.Dtos;
  5. using DataSharing.Share.Dtos.HotlineWeb;
  6. using DataSharing.Share.Dtos.Province;
  7. using DataSharing.Share.Dtos.Province.Extend;
  8. using DataSharing.Share.Dtos.Province.HuiJu;
  9. using DataSharing.Share.Dtos.Province.XieTong.Knowledge;
  10. using DataSharing.Share.Dtos.Province.XieTong.Receive;
  11. using DataSharing.Share.Dtos.Province.XieTong.Send;
  12. using DataSharing.Share.Enums;
  13. using DataSharing.Validators.HuiJu;
  14. using DataSharing.Validators.XieTong;
  15. using DotNetCore.CAP;
  16. using Hotline.Share.Dtos.CallCenter;
  17. using Hotline.Share.Dtos.File;
  18. using Hotline.Share.Dtos.Knowledge;
  19. using Hotline.Share.Dtos.Order;
  20. using Hotline.Share.Dtos.TrCallCenter;
  21. using Hotline.Share.Enums.CallCenter;
  22. using Hotline.Share.Enums.FlowEngine;
  23. using Hotline.Share.Enums.Order;
  24. using MapsterMapper;
  25. using Microsoft.Extensions.Logging;
  26. using System.Text.Json;
  27. using XF.Domain.Cache;
  28. using XF.Domain.Dependency;
  29. using XF.Domain.Exceptions;
  30. using XF.Domain.Repository;
  31. namespace DataSharing.Province
  32. {
  33. /// <summary>
  34. /// 省推送数据
  35. /// </summary>
  36. public class ProvinceService : IProvinceService, IScopeDependency
  37. {
  38. #region 注入
  39. private readonly IMapper _mapper;
  40. private readonly ILogger<ProvinceService> _logger;
  41. private readonly IRepository<DsOrder> _dsOrderRepository;
  42. private readonly IRepository<DsOrderWorkFlow> _dataOrderWorkFlowRepository;
  43. private readonly IRepository<DsKnowledgeRawData> _knowledgeRawDataRepository;
  44. private readonly IChannelConfigurationManager _channelConfigurationManager;
  45. private readonly IRepository<DsSendCaseInfo> _sendCaseInfoRepository;
  46. private readonly ITypedCache<MissedCallModelDto> _missedCallModelCache;
  47. private readonly string MissedCallKey = "missedCallKey_";
  48. private readonly IRepository<DsOrderVisit> _dsOrderVisitRepository;
  49. private readonly IRepository<DsGetCaseBackApply> _getCaseBackApplyRepository;
  50. private readonly ICapPublisher _capPublisher;
  51. private readonly IRepository<DsTelCall> _dsTelCallRepository;
  52. private readonly ITypedCache<ConfigurationInformationDto> _configurationInformationCache;
  53. private readonly IRepository<DsOrderVisitSend> _dsOrderVisitSendRepository;
  54. private readonly ISharingConfigurationManager _sharingConfigurationManager;
  55. private readonly IInitPushDataService _initPushDataService;
  56. private readonly IRepository<DsGetCaseMaterialInfo> _getCaseMaterialInfoRepository;
  57. /// <summary>
  58. ///
  59. /// </summary>
  60. /// <param name="mapper"></param>
  61. /// <param name="logger"></param>
  62. /// <param name="dsOrderRepository"></param>
  63. /// <param name="dataOrderWorkFlowRepository"></param>
  64. /// <param name="knowledgeRawDataRepository"></param>
  65. /// <param name="channelConfigurationManager"></param>
  66. /// <param name="sendCaseInfoRepository"></param>
  67. /// <param name="missedCallModelCache"></param>
  68. /// <param name="dsOrderVisitRepository"></param>
  69. /// <param name="getCaseBackApplyRepository"></param>
  70. /// <param name="capPublisher"></param>
  71. /// <param name="dsTelCallRepository"></param>
  72. /// <param name="configurationInformationCache"></param>
  73. /// <param name="dsOrderVisitSendRepository"></param>
  74. /// <param name="sharingConfigurationManager"></param>
  75. /// <param name="initPushDataService"></param>
  76. /// <param name="getCaseMaterialInfoRepository"></param>
  77. public ProvinceService(IMapper mapper,
  78. ILogger<ProvinceService> logger,
  79. IRepository<DsOrder> dsOrderRepository,
  80. IRepository<DsOrderWorkFlow> dataOrderWorkFlowRepository,
  81. IRepository<DsKnowledgeRawData> knowledgeRawDataRepository,
  82. IChannelConfigurationManager channelConfigurationManager,
  83. IRepository<DsSendCaseInfo> sendCaseInfoRepository,
  84. ITypedCache<MissedCallModelDto> missedCallModelCache,
  85. IRepository<DsOrderVisit> dsOrderVisitRepository,
  86. IRepository<DsGetCaseBackApply> getCaseBackApplyRepository,
  87. ICapPublisher capPublisher,
  88. IRepository<DsTelCall> dsTelCallRepository,
  89. ITypedCache<ConfigurationInformationDto> configurationInformationCache,
  90. IRepository<DsOrderVisitSend> dsOrderVisitSendRepository,
  91. ISharingConfigurationManager sharingConfigurationManager,
  92. IInitPushDataService initPushDataService,
  93. IRepository<DsGetCaseMaterialInfo> getCaseMaterialInfoRepository)
  94. {
  95. _mapper = mapper;
  96. _logger = logger;
  97. _dsOrderRepository = dsOrderRepository;
  98. _dataOrderWorkFlowRepository = dataOrderWorkFlowRepository;
  99. _knowledgeRawDataRepository = knowledgeRawDataRepository;
  100. _channelConfigurationManager = channelConfigurationManager;
  101. _sendCaseInfoRepository = sendCaseInfoRepository;
  102. _missedCallModelCache = missedCallModelCache;
  103. _dsOrderVisitRepository = dsOrderVisitRepository;
  104. _getCaseBackApplyRepository = getCaseBackApplyRepository;
  105. _capPublisher = capPublisher;
  106. _dsTelCallRepository = dsTelCallRepository;
  107. _configurationInformationCache = configurationInformationCache;
  108. _dsOrderVisitSendRepository = dsOrderVisitSendRepository;
  109. _sharingConfigurationManager = sharingConfigurationManager;
  110. _initPushDataService = initPushDataService;
  111. _getCaseMaterialInfoRepository = getCaseMaterialInfoRepository;
  112. }
  113. #endregion
  114. #region 协同-第一批次---已处理
  115. /// <summary>
  116. /// 退回申请
  117. /// </summary>
  118. /// <param name="dtos"></param>
  119. /// <param name="cancellationToken"></param>
  120. /// <returns></returns>
  121. /// <exception cref="UserFriendlyException"></exception>
  122. public async Task GetCaseBackApplyAsync(PublishOrderSendBackDto dtos, CancellationToken cancellationToken)
  123. {
  124. //验证数据
  125. foreach (var dto in dtos.SendDatas)
  126. {
  127. var validator = new GetCaseBackApplyValidator();
  128. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  129. if (!validResult.IsValid)
  130. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  131. }
  132. foreach (var dto in dtos.SendDatas)
  133. {
  134. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.Source == ESource.ProvinceStraight || dto.Order.AreaCode.Contains("519"))
  135. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  136. //处理省上的退回申请
  137. if (dto.Order.Source == ESource.ProvinceStraight)
  138. {
  139. var data = _mapper.Map<GetCaseBackApplyInfo>(dto);
  140. data.CliengGuid = dto.SendBack.Id;
  141. data.BackType = "1";
  142. var tempData = _mapper.Map<DsGetCaseBackApply>(data);
  143. tempData.OrderSendBackId = dto.SendBack.Id;
  144. var backId = await _getCaseBackApplyRepository.AddAsync(tempData, cancellationToken);
  145. if (!string.IsNullOrEmpty(backId))
  146. {
  147. #region 处理请求参数
  148. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  149. var request = new ProvinceRequest<GetCaseBackApplyInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  150. request.SetData(data);
  151. var jsonData = request.ToString();
  152. #endregion
  153. //将待推送数据写入待推送表
  154. await _initPushDataService.InitDsSendTaskProvinceOther("GetCaseBackApply", "get_case_back_apply", data.CaseSerial,
  155. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong, generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  156. //处理附件
  157. await FileDataAsync(dto.SendBack.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Process, dto.Order.AreaCode, cancellationToken: cancellationToken);
  158. }
  159. }
  160. }
  161. }
  162. /// <summary>
  163. /// 服务工单督办过程
  164. /// </summary>
  165. /// <param name="dto"></param>
  166. /// <param name="cancellationToken"></param>
  167. /// <returns></returns>
  168. /// <exception cref="UserFriendlyException"></exception>
  169. public async Task SendSuperviseProcessInfoAsync(PublishSuperviseDto dto, CancellationToken cancellationToken)
  170. {
  171. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.Source == ESource.ProvinceStraight || dto.Order.AreaCode.Contains("519"))
  172. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  173. var validator = new SendSuperviseProcessInfoValidator();
  174. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  175. if (!validResult.IsValid)
  176. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  177. var data = _mapper.Map<SendSuperviseProcessInfo>(dto);
  178. data.ReplyOpinion = "已签收";
  179. #region 处理请求参数
  180. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  181. var request = new ProvinceRequest<SendSuperviseProcessInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  182. request.SetData(data);
  183. var jsonData = request.ToString();
  184. #endregion
  185. //将待推送数据写入待推送表
  186. await _initPushDataService.InitDsSendTaskProvinceOther("SendSuperviseProcessInfo", "send_supervise_process_info", dto.Order.ReceiveProvinceNo,
  187. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  188. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  189. }
  190. /// <summary>
  191. /// 服务工单督办结果
  192. /// </summary>
  193. /// <param name="dto"></param>
  194. /// <param name="cancellationToken"></param>
  195. /// <returns></returns>
  196. /// <exception cref="UserFriendlyException"></exception>
  197. public async Task SendSuperviseResultInfoAsync(PublishSuperviseDto dto, CancellationToken cancellationToken)
  198. {
  199. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.Source == ESource.ProvinceStraight || dto.Order.AreaCode.Contains("519"))
  200. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  201. var validator = new SendSuperviseResultInfoValidator();
  202. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  203. if (!validResult.IsValid)
  204. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  205. var data = _mapper.Map<SendSuperviseResultInfo>(dto);
  206. data.CliengGuid = dto.Supervise.Id;
  207. #region 处理请求参数
  208. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  209. var request = new ProvinceRequest<SendSuperviseResultInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  210. request.SetData(data);
  211. var jsonData = request.ToString();
  212. #endregion
  213. //将待推送数据写入待推送表
  214. await _initPushDataService.InitDsSendTaskProvinceOther("SendSuperviseResultInfo", "send_supervise_result_info", dto.Order.ReceiveProvinceNo,
  215. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  216. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  217. //处理附件
  218. await FileDataAsync(dto.Supervise.FileJson, dto.Order.ReceiveProvinceNo, data.CliengGuid, EMaterialType.Supervise, dto.Order.AreaCode, cancellationToken);
  219. }
  220. /// <summary>
  221. /// 工单发起甄别
  222. /// </summary>
  223. /// <param name="dto"></param>
  224. /// <param name="cancellationToken"></param>
  225. /// <returns></returns>
  226. /// <exception cref="UserFriendlyException"></exception>
  227. public async Task ScreenCaseInfoSendAsync(PublishScreenDto dto, CancellationToken cancellationToken)
  228. {
  229. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.Source == ESource.ProvinceStraight || dto.Order.AreaCode.Contains("519"))
  230. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  231. var validator = new ScreenCaseInfoSendInfoValidator();
  232. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  233. if (!validResult.IsValid)
  234. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  235. var data = _mapper.Map<ScreenCaseInfoSendInfo>(dto);
  236. data.CliengGuid = dto.Screen.Id;
  237. data.ApplyType = dto.Screen.TypeDicName switch
  238. {
  239. "违反法律法规" => "10",
  240. "按正常流程处理" => "20",
  241. _ => "30",
  242. };
  243. #region 处理请求参数
  244. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  245. var request = new ProvinceRequest<ScreenCaseInfoSendInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  246. request.SetData(data);
  247. var jsonData = request.ToString();
  248. #endregion
  249. //将待推送数据写入待推送表
  250. await _initPushDataService.InitDsSendTaskProvinceOther("ScreenCaseInfoSend", "screen_case_info_send", data.CaseSerial,
  251. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  252. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  253. //处理附件
  254. await FileDataAsync(dto.Screen.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Process, dto.Order.AreaCode, cancellationToken: cancellationToken);
  255. }
  256. /// <summary>
  257. /// 服务工单申请延时
  258. /// </summary>
  259. /// <param name="dto"></param>
  260. /// <param name="cancellationToken"></param>
  261. /// <returns></returns>
  262. /// <exception cref="UserFriendlyException"></exception>
  263. public async Task DelayCaseInfoSendAsync(PublishOrderDelayDto dto, CancellationToken cancellationToken)
  264. {
  265. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.Source == ESource.ProvinceStraight || dto.Order.AreaCode.Contains("519"))
  266. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  267. var validator = new DelayCaseInfoSendInfoValidator();
  268. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  269. if (!validResult.IsValid)
  270. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  271. var data = _mapper.Map<DelayCaseInfoSendInfo>(dto);
  272. data.CliengGuid = dto.Id;
  273. data.ApplyType = "1";
  274. #region 处理请求参数
  275. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  276. var request = new ProvinceRequest<DelayCaseInfoSendInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  277. request.SetData(data);
  278. var jsonData = request.ToString();
  279. #endregion
  280. //将待推送数据写入待推送表
  281. await _initPushDataService.InitDsSendTaskProvinceOther("DelayCaseInfoSend", "delay_case_info_send", data.CaseSerial,
  282. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  283. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  284. //处理附件
  285. await FileDataAsync(dto.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Process, data.AreaCode, cancellationToken);
  286. }
  287. #endregion
  288. #region 汇聚-第二批次
  289. /// <summary>
  290. /// 热线工单流程开启
  291. /// </summary>
  292. /// <param name="pushdto"></param>
  293. /// <param name="cancellationToken"></param>
  294. /// <returns></returns>
  295. /// <exception cref="UserFriendlyException"></exception>
  296. public async Task OrderFlowStartedAsync(PublishCallRecrodDto pushdto, CancellationToken cancellationToken)
  297. {
  298. if (string.IsNullOrEmpty(pushdto.Order.AreaCode) || pushdto.Order.AreaCode.Contains("519"))
  299. pushdto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  300. var dto = pushdto.Order;
  301. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  302. //如果不是省上派下来的工单,需要汇聚到省上
  303. if (dto is not null && !dto.IsProvince)
  304. {
  305. //先上传拓展信息
  306. if (dto.OrderExtension != null)
  307. await SubmitCaseExtendsAsync(dto, cancellationToken);
  308. var data = InitDataAsync(dto);
  309. var validator = new SubmitCaseInfoValidator();
  310. var validResult = await validator.ValidateAsync(data, cancellationToken);
  311. if (!validResult.IsValid)
  312. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  313. #region 处理请求参数
  314. var request = new ProvinceListRequest<SubmitCaseInfo>(configProvince.ClientId, configProvince.ClientSecret);
  315. request.SetData(new List<SubmitCaseInfo>() { data });
  316. var jsonData = request.ToString();
  317. #endregion
  318. //将待推送数据写入待推送表
  319. await _initPushDataService.InitDsSendTaskSubmitCaseInfo(data.CaseSerial, jsonData, data, pushdto.Order.StartTime, cancellationToken);
  320. //处理附件
  321. await FileDataAsync(dto.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Acceptance, data.AreaCode, cancellationToken);
  322. }
  323. //推送当前办理信息
  324. await SubmitCaseProcessFlowAsync(new OrderFlowDto { Order = pushdto.Order, WorkflowTrace = pushdto.WorkflowTrace, ExpiredTimeChanged = false }, cancellationToken);
  325. //再次推送通话记录
  326. if (pushdto.TrCallRecordDto is not null)
  327. {
  328. //如果推送工单的时候判断通话记录是否是未接,并且是否已经上传,如果没有咋补再次推送通话记录
  329. var tellCall = await _dsTelCallRepository.AnyAsync(p => p.CallId == pushdto.TrCallRecordDto.OtherAccept, cancellationToken);
  330. if (pushdto.TrCallRecordDto.OnState == EOnState.NoOn && !tellCall)
  331. return;
  332. var dataCall = _mapper.Map<SubmitCaseRecordInfo>(pushdto.TrCallRecordDto);
  333. dataCall.AreaCode = dto.AreaCode.Length > 6 ? dto.AreaCode.Substring(0, 6) : dto.AreaCode;
  334. dataCall.CaseSerial = dto.ProvinceNo;
  335. if (string.IsNullOrEmpty(dataCall.AccordUrl))
  336. dataCall.AccordUrl = "";
  337. //处理通话记录时间
  338. SetCallTime(dataCall);
  339. var validator = new SubmitCaseRecordInfoValidator();
  340. var validResult = await validator.ValidateAsync(dataCall, cancellationToken);
  341. if (!validResult.IsValid)
  342. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  343. #region 处理请求参数
  344. var requestCall = new ProvinceListRequest<SubmitCaseRecordInfo>(configProvince.ClientId, configProvince.ClientSecret);
  345. requestCall.SetData(new List<SubmitCaseRecordInfo>() { dataCall });
  346. var jsonDataCall = requestCall.ToString();
  347. jsonDataCall = jsonDataCall.Replace("0001-01-01 00:00:00", "");
  348. //将待推送数据写入待推送表
  349. var taskId = await _initPushDataService.InitDsSendTaskSubmitCaseRecord(dataCall.CaseSerial, pushdto.TrCallRecordDto.OtherAccept, jsonDataCall, dataCall, pushdto.TrCallRecordDto.OverTime, cancellationToken);
  350. //本地保存通话记录数据
  351. await InitTelCallData(pushdto.TrCallRecordDto, dto.ProvinceNo, taskId, cancellationToken);
  352. #endregion
  353. }
  354. }
  355. /// <summary>
  356. /// 热线工单期满时间变更--推送服务工单受理
  357. /// </summary>
  358. /// <param name="dto"></param>
  359. /// <param name="cancellationToken"></param>
  360. /// <returns></returns>
  361. /// <exception cref="UserFriendlyException"></exception>
  362. public async Task HotlineOrderFlowRecalledAsync(OrderDto dto, CancellationToken cancellationToken)
  363. {
  364. if (string.IsNullOrEmpty(dto.AreaCode) || dto.AreaCode.Contains("519"))
  365. dto.AreaCode = _sharingConfigurationManager.GetCityCode();
  366. //如果不是省上派下来的工单,需要汇聚到省上
  367. if (!dto.IsProvince)
  368. {
  369. var data = InitDataAsync(dto);
  370. var validator = new SubmitCaseInfoValidator();
  371. var validResult = await validator.ValidateAsync(data, cancellationToken);
  372. if (!validResult.IsValid)
  373. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  374. #region 处理请求参数
  375. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  376. var request = new ProvinceListRequest<SubmitCaseInfo>(configProvince.ClientId, configProvince.ClientSecret);
  377. request.SetData(new List<SubmitCaseInfo>() { data });
  378. var jsonData = request.ToString();
  379. #endregion
  380. //将待推送数据写入待推送表
  381. await _initPushDataService.InitDsSendTaskSubmitCaseInfo(data.CaseSerial, jsonData, data, dto.StartTime, cancellationToken);
  382. }
  383. }
  384. /// <summary>
  385. /// 热线工单办理---服务工单处理/服务工单交办处理过程
  386. /// </summary>
  387. /// <param name="dto"></param>
  388. /// <param name="cancellationToken"></param>
  389. /// <returns></returns>
  390. /// <exception cref="UserFriendlyException"></exception>
  391. public async Task SubmitCaseProcessAsync(OrderFlowDto dto, CancellationToken cancellationToken)
  392. {
  393. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.AreaCode.Contains("519"))
  394. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  395. if (string.IsNullOrEmpty(dto.WorkflowTrace.HandlerOrgAreaCode))
  396. {
  397. dto.WorkflowTrace.HandlerOrgAreaCode = dto.Order.AreaCode;
  398. if (dto.WorkflowTrace.HandlerOrgAreaCode.Length > 6)
  399. dto.WorkflowTrace.HandlerOrgAreaCode = dto.WorkflowTrace.HandlerOrgAreaCode.Substring(0, 6);
  400. }
  401. await SubmitCaseProcessFlowAsync(dto, cancellationToken);
  402. //期满时间变更或者办理节点为话务部,重新推送数据
  403. if ((dto.ExpiredTimeChanged || dto.Order.ActualHandleStepName == "话务部") && !dto.Order.IsProvince)
  404. {
  405. var submitCaseInfo = InitDataAsync(dto.Order);
  406. var validator = new SubmitCaseInfoValidator();
  407. var validResult = await validator.ValidateAsync(submitCaseInfo, cancellationToken);
  408. if (!validResult.IsValid)
  409. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  410. #region 处理请求参数
  411. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  412. var requestSubmitCaseInfo = new ProvinceListRequest<SubmitCaseInfo>(configProvince.ClientId, configProvince.ClientSecret);
  413. requestSubmitCaseInfo.SetData(new List<SubmitCaseInfo>() { submitCaseInfo });
  414. var jsonDataSubmitCaseInfo = requestSubmitCaseInfo.ToString();
  415. var urlSubmitCaseInfo = configProvince.HuiJu + "submit_case_info";
  416. #endregion
  417. //将待推送数据写入待推送表
  418. await _initPushDataService.InitDsSendTaskSubmitCaseInfo(submitCaseInfo.CaseSerial, jsonDataSubmitCaseInfo, submitCaseInfo, dto.Order.StartTime, cancellationToken);
  419. //如果话务部派出去,再次上传附件
  420. if (dto.Order.ActualHandleStepName == "话务部")
  421. {
  422. //处理附件
  423. await FileDataAsync(dto.Order.FileJson, submitCaseInfo.CaseSerial, submitCaseInfo.CliengGuid, EMaterialType.Acceptance, submitCaseInfo.AreaCode, cancellationToken);
  424. }
  425. }
  426. }
  427. /// <summary>
  428. /// 服务工单回访评价/服务工单交办评价
  429. /// </summary>
  430. /// <param name="dto"></param>
  431. /// <param name="cancellationToken"></param>
  432. /// <returns></returns>
  433. /// <exception cref="UserFriendlyException"></exception>
  434. public async Task SubmitVisitInfoDataAsync(PublishVisitDto dto, CancellationToken cancellationToken)
  435. {
  436. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.AreaCode.Contains("519"))
  437. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  438. dto.AreaCode = dto.Order.AreaCode.Length > 6 ? dto.Order.AreaCode.Substring(0, 6) : dto.Order.AreaCode;
  439. //存在更新,不存在新增
  440. var visitData = await _dsOrderVisitSendRepository.GetAsync(p => p.OrderId == dto.Order.Id, cancellationToken);
  441. if (visitData != null)
  442. {
  443. visitData.VisitType = dto.VisitType.ToString();
  444. visitData.VisitName = dto.VisitName;
  445. visitData.VisitTime = dto.VisitTime;
  446. visitData.VisitRemark = dto.VisitRemark;
  447. visitData.SubjectResultSatifyCode = dto.SubjectResultSatifyCode;
  448. await _dsOrderVisitSendRepository.UpdateAsync(visitData, cancellationToken);
  449. }
  450. else
  451. {
  452. ///写入推送数据表,用于统计满意度
  453. visitData = new()
  454. {
  455. OrderId = dto.Order.Id,
  456. OrderNo = dto.No,
  457. ProvinceNo = dto.Order.ProvinceNo,
  458. VisitType = dto.VisitType.ToString(),
  459. VisitName = dto.VisitName,
  460. VisitTime = dto.VisitTime,
  461. VisitRemark = dto.VisitRemark,
  462. SubjectResultSatifyCode = dto.SubjectResultSatifyCode,
  463. IsProvince = dto.Order.IsProvince,
  464. Source = dto.Order.Source.ToString()
  465. };
  466. await _dsOrderVisitSendRepository.AddAsync(visitData, cancellationToken);
  467. }
  468. var visitType = dto.VisitType switch
  469. {
  470. EVisitType.ArtificialVisit => "DH",
  471. EVisitType.SmsVisit => "DX",
  472. EVisitType.WebVisit => "WZ",
  473. EVisitType.WeChatVisit => "WX",
  474. EVisitType.AppVisit => "AP",
  475. _ => "DH",
  476. };
  477. //将未接通未做评价的默认为满意
  478. switch (dto.SubjectResultSatifyCode)
  479. {
  480. case "5":
  481. case "4":
  482. case "2":
  483. break;
  484. case "-1":
  485. case "0":
  486. dto.SubjectResultSatifyCode = "4";
  487. break;
  488. case "6":
  489. case "7":
  490. dto.SubjectResultSatifyCode = "3";
  491. break;
  492. default:
  493. dto.SubjectResultSatifyCode = "3";
  494. break;
  495. }
  496. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  497. //如果省上下来的工单走服务工单交办评价接口,不是省上派下来的工单,走服务工单评价接口
  498. if (dto.Order.IsProvince && dto.Order.Source == ESource.ProvinceStraight)
  499. {
  500. var data = _mapper.Map<GetVisitInfoReceiveInfo>(dto);
  501. data.VisitType = visitType;
  502. data.CliengGuid = Guid.NewGuid().ToString();
  503. var validator = new GetVisitInfoReceiveInfoValidator();
  504. var validResult = await validator.ValidateAsync(data, cancellationToken);
  505. if (!validResult.IsValid)
  506. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  507. #region 处理请求参数
  508. var request = new ProvinceRequest<GetVisitInfoReceiveInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  509. request.SetData(data);
  510. var jsonData = request.ToString();
  511. #endregion
  512. //将待推送数据写入待推送表
  513. await _initPushDataService.InitDsSendTaskProvinceOther("GetVisitInfoReceive", "get_visit_info_receive", data.CaseSerial,
  514. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  515. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  516. //处理附件
  517. await FileDataAsync(null, data.CaseSerial, data.CliengGuid, EMaterialType.Visit, data.AreaCode, cancellationToken);
  518. }
  519. else
  520. {
  521. var data = _mapper.Map<SubmitVisitInfo>(dto);
  522. data.VisitType = visitType;
  523. data.CliengGuid = Guid.NewGuid().ToString();
  524. var validator = new SubmitVisitInfoValidator();
  525. var validResult = await validator.ValidateAsync(data, cancellationToken);
  526. if (!validResult.IsValid)
  527. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  528. #region 处理请求参数
  529. var request = new ProvinceListRequest<SubmitVisitInfo>(configProvince.ClientId, configProvince.ClientSecret);
  530. request.SetData(new List<SubmitVisitInfo>() { data });
  531. var jsonData = request.ToString();
  532. #endregion
  533. //将待推送数据写入待推送表
  534. await _initPushDataService.InitDsSendTaskProvinceOther("SubmitVisitInfo", "submit_visit_info", data.CaseSerial,
  535. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.HuiJu,
  536. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  537. //处理附件
  538. await FileDataAsync(null, data.CaseSerial, data.CliengGuid, EMaterialType.Visit, data.AreaCode, cancellationToken);
  539. }
  540. }
  541. /// <summary>
  542. /// 热线工单归档---服务工单结果/服务工单交办处理结果
  543. /// </summary>
  544. /// <param name="dto"></param>
  545. /// <param name="cancellationToken"></param>
  546. /// <returns></returns>
  547. /// <exception cref="UserFriendlyException"></exception>
  548. public async Task OrderFiledAsync(OrderFlowDto dto, CancellationToken cancellationToken)
  549. {
  550. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.AreaCode.Contains("519"))
  551. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  552. if (string.IsNullOrEmpty(dto.Order.ActualHandleOrgAreaCode))
  553. {
  554. dto.Order.ActualHandleOrgAreaCode = dto.Order.AreaCode;
  555. if (dto.Order.ActualHandleOrgAreaCode.Length > 6)
  556. dto.Order.ActualHandleOrgAreaCode = dto.Order.ActualHandleOrgAreaCode.Substring(0, 6);
  557. }
  558. //先看看需要处理工单数据不
  559. SubmitCaseInfo data = new();
  560. if (dto != null && dto.Order != null && !dto.Order.IsProvince)
  561. {
  562. data = InitDataAsync(dto.Order);
  563. var validator = new SubmitCaseInfoValidator();
  564. var validResult = await validator.ValidateAsync(data, cancellationToken);
  565. if (!validResult.IsValid)
  566. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  567. }
  568. //推送办理记录
  569. dto.ExpiredTimeChanged = false;
  570. //推送办理过程
  571. await SubmitCaseProcessFlowAsync(dto, cancellationToken);
  572. //判断是否是热线中心
  573. if (!string.IsNullOrEmpty(dto.Order.ActualHandleOrgCode) && dto.Order.ActualHandleOrgCode == "001")
  574. dto.Order.ActualHandleOrgName = "热线中心";
  575. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  576. //IsProvince 如果是false 则推送服务工单受理
  577. if (dto != null && dto.Order != null && !dto.Order.IsProvince)
  578. {
  579. #region 处理请求参数--推送工单数据
  580. var request = new ProvinceListRequest<SubmitCaseInfo>(configProvince.ClientId, configProvince.ClientSecret);
  581. request.SetData(new List<SubmitCaseInfo>() { data });
  582. var jsonData = request.ToString();
  583. #endregion
  584. //将待推送数据写入待推送表
  585. await _initPushDataService.InitDsSendTaskSubmitCaseInfo(data.CaseSerial, jsonData, data, dto.Order.StartTime, cancellationToken);
  586. //推送服务工单结果信息
  587. await SubmitCaseResultAsync(dto, cancellationToken);
  588. }
  589. //再次推送通话记录
  590. if (dto.TrCallRecordDto is not null)
  591. {
  592. //如果推送工单的时候判断通话记录是否是未接,并且是否已经上传,如果没有咋补再次推送通话记录
  593. var tellCall = await _dsTelCallRepository.AnyAsync(p => p.CallId == dto.TrCallRecordDto.OtherAccept, cancellationToken);
  594. if (dto.TrCallRecordDto.OnState == EOnState.NoOn && !tellCall)
  595. return;
  596. var dataCall = _mapper.Map<SubmitCaseRecordInfo>(dto.TrCallRecordDto);
  597. dataCall.AreaCode = dto.Order.AreaCode.Length > 6 ? dto.Order.AreaCode.Substring(0, 6) : dto.Order.AreaCode;
  598. dataCall.CaseSerial = dto.Order.ProvinceNo;
  599. if (string.IsNullOrEmpty(dataCall.AccordUrl))
  600. dataCall.AccordUrl = "";
  601. //处理通话记录时间
  602. SetCallTime(dataCall);
  603. var validator = new SubmitCaseRecordInfoValidator();
  604. var validResult = await validator.ValidateAsync(dataCall, cancellationToken);
  605. if (!validResult.IsValid)
  606. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  607. #region 处理请求参数
  608. var requestCall = new ProvinceListRequest<SubmitCaseRecordInfo>(configProvince.ClientId, configProvince.ClientSecret);
  609. requestCall.SetData(new List<SubmitCaseRecordInfo>() { dataCall });
  610. var jsonDataCall = requestCall.ToString();
  611. jsonDataCall = jsonDataCall.Replace("0001-01-01 00:00:00", "");
  612. //将待推送数据写入待推送表
  613. var taskId = await _initPushDataService.InitDsSendTaskSubmitCaseRecord(dataCall.CaseSerial, dto.TrCallRecordDto.OtherAccept, jsonDataCall, dataCall, dto.TrCallRecordDto.OverTime, cancellationToken);
  614. //本地保存通话记录数据
  615. await InitTelCallData(dto.TrCallRecordDto, dto.Order.ProvinceNo, taskId, cancellationToken);
  616. #endregion
  617. }
  618. }
  619. /// <summary>
  620. /// 挂电话推送----电话记录--丰窝最新
  621. /// </summary>
  622. /// <param name="dto"></param>
  623. /// <param name="cancellationToken"></param>
  624. /// <returns></returns>
  625. /// <exception cref="UserFriendlyException"></exception>
  626. public async Task SubmitCaseRecordFwAsync(CallNativeDto dto, CancellationToken cancellationToken)
  627. {
  628. //验证是否需要推送未接数据
  629. if (dto != null && dto.AnsweredTime == null)
  630. {
  631. if (await IsPublishMissedCall(dto.EndTime, cancellationToken) == false)
  632. return;
  633. }
  634. var data = _mapper.Map<SubmitCaseRecordInfo>(dto);
  635. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  636. if (string.IsNullOrEmpty(data.CaseSerial))
  637. data.CaseSerial = "";
  638. if (string.IsNullOrEmpty(data.AccordUrl))
  639. data.AccordUrl = "";
  640. //处理通话记录时间
  641. SetCallTime(data);
  642. var validator = new SubmitCaseRecordInfoValidator();
  643. var validResult = await validator.ValidateAsync(data, cancellationToken);
  644. if (!validResult.IsValid)
  645. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  646. #region 处理请求参数
  647. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  648. var request = new ProvinceListRequest<SubmitCaseRecordInfo>(configProvince.ClientId, configProvince.ClientSecret);
  649. request.SetData(new List<SubmitCaseRecordInfo>() { data });
  650. var jsonData = request.ToString();
  651. jsonData = jsonData.Replace("0001-01-01 00:00:00", "");
  652. #endregion
  653. //将待推送数据写入待推送表
  654. var taskId = await _initPushDataService.InitDsSendTaskSubmitCaseRecord(data.CaseSerial, dto.Id, jsonData, data, dto.EndTime, cancellationToken);
  655. //本地保存通话记录数据
  656. await InitTelFwCallData(dto, data.CaseSerial, taskId, cancellationToken);
  657. }
  658. /// <summary>
  659. /// 挂电话推送----电话记录
  660. /// </summary>
  661. /// <param name="dto"></param>
  662. /// <param name="cancellationToken"></param>
  663. /// <returns></returns>
  664. /// <exception cref="UserFriendlyException"></exception>
  665. public async Task SubmitCaseRecordAsync(PublishCallRecrodDto dto, CancellationToken cancellationToken)
  666. {
  667. //验证是否需要推送未接数据
  668. if (dto != null && dto.TrCallRecordDto != null && dto.TrCallRecordDto.OnState == EOnState.NoOn && dto.Order == null)
  669. {
  670. if (await IsPublishMissedCall(dto.TrCallRecordDto.OverTime, cancellationToken) == false)
  671. return;
  672. }
  673. var data = _mapper.Map<SubmitCaseRecordInfo>(dto.TrCallRecordDto);
  674. if (dto.Order != null)
  675. {
  676. if (string.IsNullOrEmpty(dto.Order.AreaCode))
  677. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  678. else
  679. data.AreaCode = dto.Order.AreaCode;
  680. if (!string.IsNullOrEmpty(dto.Order.ProvinceNo))
  681. data.CaseSerial = dto.Order.ProvinceNo;
  682. }
  683. else
  684. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  685. if (data.AreaCode.Contains("519"))
  686. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  687. if (data.AreaCode.Length > 6)
  688. data.AreaCode = data.AreaCode.Substring(0, 6);
  689. if (string.IsNullOrEmpty(data.CaseSerial))
  690. data.CaseSerial = "";
  691. if (string.IsNullOrEmpty(data.AccordUrl))
  692. data.AccordUrl = "";
  693. //处理通话记录时间
  694. SetCallTime(data);
  695. var validator = new SubmitCaseRecordInfoValidator();
  696. var validResult = await validator.ValidateAsync(data, cancellationToken);
  697. if (!validResult.IsValid)
  698. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  699. #region 处理请求参数
  700. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  701. var request = new ProvinceListRequest<SubmitCaseRecordInfo>(configProvince.ClientId, configProvince.ClientSecret);
  702. request.SetData(new List<SubmitCaseRecordInfo>() { data });
  703. var jsonData = request.ToString();
  704. jsonData = jsonData.Replace("0001-01-01 00:00:00", "");
  705. #endregion
  706. var startTime = dto.TrCallRecordDto.OverTime;
  707. //将待推送数据写入待推送表
  708. var taskId = await _initPushDataService.InitDsSendTaskSubmitCaseRecord(data.CaseSerial, dto.TrCallRecordDto.OtherAccept, jsonData, data, startTime, cancellationToken);
  709. //本地保存通话记录数据
  710. await InitTelCallData(dto.TrCallRecordDto, data.CaseSerial, taskId, cancellationToken);
  711. }
  712. /// <summary>
  713. /// 关联工单了推送----电话记录
  714. /// </summary>
  715. /// <param name="dto"></param>
  716. /// <param name="cancellationToken"></param>
  717. /// <returns></returns>
  718. /// <exception cref="UserFriendlyException"></exception>
  719. public async Task SubmitCaseRecordOrderAsync(PublishCallRecrodDto dto, CancellationToken cancellationToken)
  720. {
  721. //如果推送工单的时候判断通话记录是否是未接,并且是否已经上传,如果没有咋补再次推送通话记录
  722. var tellCall = await _dsTelCallRepository.AnyAsync(p => p.CallId == dto.TrCallRecordDto.OtherAccept, cancellationToken);
  723. if (dto.TrCallRecordDto.OnState == EOnState.NoOn && !tellCall)
  724. return;
  725. var data = _mapper.Map<SubmitCaseRecordInfo>(dto.TrCallRecordDto);
  726. if (dto.Order != null)
  727. {
  728. if (string.IsNullOrEmpty(dto.Order.AreaCode))
  729. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  730. else
  731. data.AreaCode = dto.Order.AreaCode;
  732. if (!string.IsNullOrEmpty(dto.Order.ProvinceNo))
  733. data.CaseSerial = dto.Order.ProvinceNo;
  734. }
  735. else
  736. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  737. if (data.AreaCode.Contains("519"))
  738. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  739. if (data.AreaCode.Length > 6)
  740. data.AreaCode = data.AreaCode.Substring(0, 6);
  741. if (string.IsNullOrEmpty(data.CaseSerial))
  742. data.CaseSerial = "";
  743. if (string.IsNullOrEmpty(data.AccordUrl))
  744. data.AccordUrl = "";
  745. //处理通话记录时间
  746. SetCallTime(data);
  747. var validator = new SubmitCaseRecordInfoValidator();
  748. var validResult = await validator.ValidateAsync(data, cancellationToken);
  749. if (!validResult.IsValid)
  750. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  751. #region 处理请求参数
  752. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  753. var request = new ProvinceListRequest<SubmitCaseRecordInfo>(configProvince.ClientId, configProvince.ClientSecret);
  754. request.SetData(new List<SubmitCaseRecordInfo>() { data });
  755. var jsonData = request.ToString();
  756. jsonData = jsonData.Replace("0001-01-01 00:00:00", "");
  757. #endregion
  758. var startTime = dto.TrCallRecordDto.OverTime;
  759. //将待推送数据写入待推送表
  760. var taskId = await _initPushDataService.InitDsSendTaskSubmitCaseRecord(data.CaseSerial, dto.TrCallRecordDto.OtherAccept, jsonData, data, startTime, cancellationToken);
  761. //本地保存通话记录数据
  762. await InitTelCallData(dto.TrCallRecordDto, data.CaseSerial, taskId, cancellationToken);
  763. }
  764. /// <summary>
  765. /// 统计数据
  766. /// </summary>
  767. /// <param name="dto"></param>
  768. /// <returns></returns>
  769. public async Task SubmitCaseTotalAsync(SubmitCaseTotalInfo dto, CancellationToken cancellationToken)
  770. {
  771. #region 处理请求参数
  772. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  773. var request = new ProvinceListRequest<SubmitCaseTotalInfo>(configProvince.ClientId, configProvince.ClientSecret);
  774. request.SetData(new List<SubmitCaseTotalInfo>() { dto });
  775. var jsonData = request.ToString();
  776. #endregion
  777. //将待推送数据写入待推送表
  778. await _initPushDataService.InitDsSendTaskProvinceOther("SubmitCaseTotal", "submit_case_total", "",
  779. jsonData, JsonSerializer.Serialize(dto, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.HuiJu,
  780. cancellationToken: cancellationToken);
  781. }
  782. #endregion
  783. #region 协同-第三批次
  784. /// <summary>
  785. /// 上报补充诉求
  786. /// </summary>
  787. /// <param name="dto"></param>
  788. /// <param name="cancellationToken"></param>
  789. /// <returns></returns>
  790. public async Task SupplyCaseInfoSendAsync(SupplyCaseInfoSendInfo dto, CancellationToken cancellationToken)
  791. {
  792. dto.AreaCode = _sharingConfigurationManager.GetCityCode();
  793. dto.CliengGuid = Guid.NewGuid().ToString();
  794. #region 处理请求参数
  795. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  796. var request = new ProvinceRequest<SupplyCaseInfoSendInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  797. request.SetData(dto);
  798. var jsonData = request.ToString();
  799. #endregion
  800. //将待推送数据写入待推送表
  801. await _initPushDataService.InitDsSendTaskProvinceOther("SupplyCaseInfoSend", "supply_case_info_send", dto.CaseSerial, jsonData,
  802. JsonSerializer.Serialize(dto, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  803. cancellationToken: cancellationToken);
  804. //处理附件
  805. await FileDataAsync(null, dto.CaseSerial, dto.CliengGuid, EMaterialType.Process, dto.AreaCode, cancellationToken);
  806. }
  807. /// <summary>
  808. /// 撤单
  809. /// </summary>
  810. /// <param name="dto"></param>
  811. /// <param name="cancellationToken"></param>
  812. /// <returns></returns>
  813. /// <exception cref="UserFriendlyException"></exception>
  814. public async Task RevokeOrderAsync(PublishSpecialDto dto, CancellationToken cancellationToken)
  815. {
  816. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.AreaCode.Contains("519"))
  817. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  818. var validator = new RevokeCaseInfoModelValidator();
  819. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  820. if (!validResult.IsValid)
  821. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  822. RevokeCaseInfoModel dsRevoke = new()
  823. {
  824. CaseSerial = dto.Order.ProvinceNo,
  825. AreaCode = dto.Order.AreaCode,
  826. RevokeTime = dto.Special.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"),
  827. RevokeName = dto.Special.CreatorName,
  828. RevokeReasion = dto.Special.Reason,
  829. CliengGuid = dto.Special.Id
  830. };
  831. if (string.IsNullOrEmpty(dto.Special.Cause))
  832. dsRevoke.RevokeType = "other";
  833. else if (dto.Special.Cause.Contains("内容错误"))
  834. dsRevoke.RevokeType = "2";
  835. else if (dto.Special.Cause == "撤销工单")
  836. dsRevoke.RevokeType = "1";
  837. else
  838. dsRevoke.RevokeType = "other";
  839. #region 处理请求参数
  840. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  841. var request = new ProvinceRequest<RevokeCaseInfoModel>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  842. request.SetData(dsRevoke);
  843. var jsonData = request.ToString();
  844. #endregion
  845. //将待推送数据写入待推送表
  846. await _initPushDataService.InitDsSendTaskProvinceOther("SendRevokeCaseInfo", "revoke_case_info", dsRevoke.CaseSerial,
  847. jsonData, JsonSerializer.Serialize(dsRevoke, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  848. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  849. await FileDataAsync(dto.Special.FileJson, dsRevoke.CaseSerial, dsRevoke.CliengGuid, EMaterialType.Process, dto.Order.AreaCode, cancellationToken);
  850. }
  851. /// <summary>
  852. /// 服务工单催单
  853. /// </summary>
  854. /// <param name="dto"></param>
  855. /// <param name="cancellationToken"></param>
  856. /// <returns></returns>
  857. /// <exception cref="UserFriendlyException"></exception>
  858. public async Task SendRemindCaseInfoAsync(PublishUrgeDto dto, CancellationToken cancellationToken)
  859. {
  860. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.AreaCode.Contains("519"))
  861. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  862. var validator = new RemindCaseInfoValidator();
  863. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  864. if (!validResult.IsValid)
  865. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  866. var data = _mapper.Map<RemindCaseInfoModel>(dto);
  867. data.CliengGuid = dto.Urge.Id;
  868. #region 处理请求参数
  869. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  870. var request = new ProvinceRequest<RemindCaseInfoModel>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  871. request.SetData(data);
  872. var jsonData = request.ToString();
  873. #endregion
  874. //将待推送数据写入待推送表
  875. await _initPushDataService.InitDsSendTaskProvinceOther("SendRemindCaseInfo", "remind_case_info", data.CaseSerial,
  876. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  877. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  878. //处理附件
  879. await FileDataAsync(dto.Urge.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Process, dto.Order.AreaCode, cancellationToken);
  880. }
  881. /// <summary>
  882. /// 接收发布数据----推送服务工单交办结果
  883. /// </summary>
  884. /// <param name="dto"></param>
  885. /// <param name="cancellationToken"></param>
  886. /// <returns></returns>
  887. /// <exception cref="UserFriendlyException"></exception>
  888. public async Task PublishOrderAsync(PublishPublishOrderDto dto, CancellationToken cancellationToken)
  889. {
  890. if (string.IsNullOrEmpty(dto.Order.AreaCode) || dto.Order.Source == ESource.ProvinceStraight || dto.Order.AreaCode.Contains("519"))
  891. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  892. //推省上的交办结果
  893. if (dto.Order.IsProvince && dto.Order.Source == ESource.ProvinceStraight)
  894. {
  895. if (dto.Order.RealCommunicationMode == null)
  896. dto.Order.RealCommunicationMode = ERealCommunicationMode.Phone;
  897. if (dto.Order.HandleDurationWorkday <= 0)
  898. dto.Order.HandleDurationWorkday = 1;
  899. var validator = new CaseResultReceiveValidator();
  900. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  901. if (!validResult.IsValid)
  902. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  903. #region 服务工单交办处理结果
  904. //判断是否是热线中心
  905. if (!string.IsNullOrEmpty(dto.Order.ActualHandleOrgCode) && dto.Order.ActualHandleOrgCode == "001")
  906. dto.Order.ActualHandleOrgName = "热线中心";
  907. ///如果是省上派下来的,直接将区域设置为系统市州
  908. if (dto.Order.Source == ESource.ProvinceStraight)
  909. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  910. var data = _mapper.Map<GetCaseResultReceiveInfo>(dto.Order);
  911. data.FinishNote = dto.ArrangeOpinion;
  912. data.FdBack = dto.ArrangeOpinion;
  913. data.ConcactType = "40";
  914. data.FinishType = "1";
  915. data.HandleTimeLong = (decimal)dto.Order.AllDuration;
  916. data.EndAreaName = string.IsNullOrEmpty(dto.Order.ActualHandleOrgAreaName) == false ? dto.Order.ActualHandleOrgAreaName : _sharingConfigurationManager.GetCityName();
  917. data.ConcactType = dto.Order.RealCommunicationMode switch
  918. {
  919. ERealCommunicationMode.Phone => "10",
  920. ERealCommunicationMode.Locale => "20",
  921. _ => "40",
  922. };
  923. data.CliengGuid = dto.Id;
  924. //中国政府网的数据处理
  925. if (dto.Order.ReceiveProvinceNo.Contains("ZGZFW"))
  926. {
  927. data.Notes = dto.Remark;
  928. data.MsgOpenByArea = dto.ProPublishState == true ? "1" : "0";
  929. data.AreaNotPublicReason = dto.NoPubReason;
  930. data.FeedBackAnswerContent = dto.AnswerContent;
  931. data.FeedBackTel = dto.FeedBackPhone;
  932. data.EventType = "";
  933. data.Eventname = "";
  934. data.ContactFlag = dto.IsContact == true ? "1" : "0";
  935. data.AssessFlag = dto.IsVisited == true ? "1" : "0";
  936. data.AssessContent = dto.EvaluateContent;
  937. if (dto.NetizenEvaluate != null)
  938. {
  939. data.AssessOpinion = dto.NetizenEvaluate.Value;
  940. }
  941. }
  942. #region 处理请求参数
  943. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  944. var request = new ProvinceRequest<GetCaseResultReceiveInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  945. request.SetData(data);
  946. var jsonData = request.ToString();
  947. #endregion
  948. await _initPushDataService.InitDsSendTaskProvinceOther("GetCaseResultReceive", "get_case_result_receive", data.CaseSerial,
  949. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  950. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  951. //处理附件
  952. await FileDataAsync(dto.FileJsons, data.CaseSerial, data.CliengGuid, EMaterialType.Result, dto.Order.AreaCode, cancellationToken);
  953. #endregion
  954. }
  955. }
  956. /// <summary>
  957. /// 政民互动公开
  958. /// </summary>
  959. /// <param name="dto"></param>
  960. /// <param name="cancellationToken"></param>
  961. /// <returns></returns>
  962. /// <exception cref="UserFriendlyException"></exception>
  963. public async Task PublicOrderProvinceZmhd(PublicOrderProvinceZmhdDto dto, CancellationToken cancellationToken)
  964. {
  965. //政民互动提交公开数据验证
  966. var validator = new ZmhdCaseInfoPublicInfoValidator();
  967. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  968. if (!validResult.IsValid)
  969. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  970. //政民互动提交公开
  971. var data = _mapper.Map<ZmhdCaseInfoPublicInfo>(dto);
  972. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  973. #region 处理请求参数
  974. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  975. var request = new ProvinceRequest<ZmhdCaseInfoPublicInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  976. request.SetData(data);
  977. var jsonData = request.ToString();
  978. #endregion
  979. //将待推送数据写入待推送表
  980. await _initPushDataService.InitDsSendTaskProvinceOther("ZmhdCaseInfoPublic", "zmhd_case_info_public", data.CaseSerial,
  981. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  982. generationTime: dto.PublishDate, cancellationToken: cancellationToken);
  983. }
  984. /// <summary>
  985. /// 接收发布的时候生成的待回访部门数据
  986. /// </summary>
  987. /// <param name="dto"></param>
  988. /// <param name="cancellationToken"></param>
  989. /// <returns></returns>
  990. public async Task PublishVisitAllAsync(PublishVisitAllDto dto, CancellationToken cancellationToken)
  991. {
  992. if (dto != null)
  993. {
  994. List<DsOrderVisit> orderVisits = new List<DsOrderVisit>();
  995. //1、待回访和已回访要将接收的数据写入库
  996. //2、其他状态的时候需要将工单的回访状态改成不能回访
  997. //处理待回访和已回访的数据
  998. if (dto.VisitState == EVisitState.WaitForVisit || dto.VisitState == EVisitState.Visited)
  999. {
  1000. if (dto.OrderVisitDetails != null && dto.OrderVisitDetails.Count > 0)
  1001. {
  1002. //组装回访数据
  1003. foreach (var item in dto.OrderVisitDetails)
  1004. {
  1005. DsOrderVisit dsOrderVisit = new()
  1006. {
  1007. OrderId = dto.Order.Id,
  1008. VisitDetailId = item.Id,
  1009. VisitId = item.VisitId,
  1010. VoiceEvaluate = item.VoiceEvaluate.ToString(),
  1011. SeatEvaluate = item.SeatEvaluate.ToString(),
  1012. OrgProcessingResults = _mapper.Map<Kv>(item.OrgProcessingResults),
  1013. OrgNoSatisfiedReason = _mapper.Map<List<Kv>>(item.OrgNoSatisfiedReason),
  1014. OrgHandledAttitude = _mapper.Map<Kv>(item.OrgHandledAttitude),
  1015. VisitContent = item.VisitContent,
  1016. VisitOrgName = item.VisitOrgName,
  1017. VisitOrgCode = item.VisitOrgCode,
  1018. VisitTarget = item.VisitTarget.ToString(),
  1019. VisitType = dto.VisitType.ToString(),
  1020. VisitTime = dto.VisitTime,
  1021. IsEffective = true
  1022. };
  1023. orderVisits.Add(dsOrderVisit);
  1024. }
  1025. //// 方式一: 保留数据
  1026. //var tempList = await _dsOrderVisitRepository.Queryable().Where(p => p.OrderId == dto.Order.Id && p.IsEffective == true).ToListAsync();
  1027. //foreach (var item in tempList)
  1028. //{
  1029. // item.IsEffective = false;
  1030. // await _dsOrderVisitRepository.UpdateAsync(item, cancellationToken);
  1031. //}
  1032. //方式二:直接删除原始数据
  1033. await _dsOrderVisitRepository.RemoveAsync(p => p.OrderId == dto.Order.Id);
  1034. //写入新数据
  1035. await _dsOrderVisitRepository.AddRangeAsync(orderVisits, cancellationToken);
  1036. }
  1037. }
  1038. //处理是否可以评价,如果是
  1039. var orderData = await _dsOrderRepository.GetAsync(p => p.OrderId == dto.Order.Id);
  1040. if (orderData is not null)
  1041. {
  1042. var tempState = orderData.VisitTypeState;
  1043. switch (dto.VisitState)
  1044. {
  1045. case EVisitState.WaitForVisit:
  1046. orderData.VisitTypeState = DataSharing.Share.Enums.EVisitTypeState.Visit;
  1047. break;
  1048. case EVisitState.Visited:
  1049. orderData.VisitTypeState = DataSharing.Share.Enums.EVisitTypeState.Reviewed;
  1050. break;
  1051. case EVisitState.Visiting:
  1052. case EVisitState.NoSatisfiedWaitForVisit:
  1053. case EVisitState.None:
  1054. orderData.VisitTypeState = DataSharing.Share.Enums.EVisitTypeState.UnVisit;
  1055. break;
  1056. default:
  1057. break;
  1058. }
  1059. if (tempState != orderData.VisitTypeState)
  1060. await _dsOrderRepository.UpdateAsync(orderData, cancellationToken);
  1061. }
  1062. }
  1063. }
  1064. /// <summary>
  1065. /// 往省上派单
  1066. /// </summary>
  1067. /// <param name="dto"></param>
  1068. /// <param name="cancellationToken"></param>
  1069. /// <returns></returns>
  1070. public async Task SendCaseInfoDataAsync(OrderDto dto, CancellationToken cancellationToken)
  1071. {
  1072. //在处理工单信息
  1073. var sendCaseInfo = _mapper.Map<SendCaseInfo>(dto);
  1074. if (dto.OrderExtension != null)
  1075. sendCaseInfo.IsExtends = "1";
  1076. else
  1077. sendCaseInfo.IsExtends = "0";
  1078. #region 处理数据
  1079. //处理性别
  1080. switch (dto.FromGender)
  1081. {
  1082. case EGender.Female:
  1083. sendCaseInfo.AppLicantSex = "0";
  1084. break;
  1085. case EGender.Male:
  1086. sendCaseInfo.AppLicantSex = "1";
  1087. break;
  1088. case EGender.Unknown:
  1089. sendCaseInfo.AppLicantSex = "2";
  1090. break;
  1091. default:
  1092. sendCaseInfo.AppLicantSex = "2";
  1093. break;
  1094. }
  1095. //处理证件类型
  1096. sendCaseInfo.CertifiCateType = dto.LicenceTypeCode switch
  1097. {
  1098. "10" => "10",
  1099. "40" => "20",
  1100. "55" => "30",
  1101. "57" => "40",
  1102. _ => "50",
  1103. };
  1104. //处理紧急程度
  1105. sendCaseInfo.CaseIsUrgent = dto.EmergencyLevel switch
  1106. {
  1107. EEmergencyLevel.QuiteEmergency => "10",
  1108. EEmergencyLevel.Emergency => "20",
  1109. _ => "30",
  1110. };
  1111. //处理诉求类型
  1112. switch (sendCaseInfo.CaseType)
  1113. {
  1114. case "10":
  1115. case "15":
  1116. case "20":
  1117. case "25":
  1118. case "30":
  1119. case "35":
  1120. break;
  1121. default:
  1122. sendCaseInfo.CaseType = "40";
  1123. break;
  1124. }
  1125. #endregion
  1126. switch (dto.SourceChannelCode.ToUpper())
  1127. {
  1128. case "RGDH":
  1129. case "WX":
  1130. case "WB":
  1131. case "AP":
  1132. case "WZ":
  1133. case "YJ":
  1134. case "SCZWFWW":
  1135. case "XCX":
  1136. break;
  1137. default:
  1138. sendCaseInfo.CaseSource = "QT";
  1139. break;
  1140. }
  1141. sendCaseInfo.CaseSource = sendCaseInfo.CaseSource;
  1142. var sendCaseInfoData = _mapper.Map<DsSendCaseInfo>(sendCaseInfo);
  1143. sendCaseInfoData.OrderID = dto.Id;
  1144. sendCaseInfoData.No = dto.No;
  1145. sendCaseInfoData.State = "0";
  1146. await _sendCaseInfoRepository.AddAsync(sendCaseInfoData, cancellationToken);
  1147. #region 处理请求参数
  1148. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1149. var request = new ProvinceRequest<SendCaseInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  1150. request.SetData(sendCaseInfo);
  1151. var jsonData = request.ToString();
  1152. #endregion
  1153. //将待推送数据写入待推送表
  1154. await _initPushDataService.InitDsSendTaskProvinceOther("SendCaseInfo", "send_case_info", sendCaseInfo.CaseSerial,
  1155. jsonData, JsonSerializer.Serialize(sendCaseInfo, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  1156. generationTime: dto.StartTime, cancellationToken: cancellationToken);
  1157. //处理附件
  1158. await FileDataAsync(dto.FileJson, sendCaseInfo.CaseSerial, sendCaseInfoData.CliengGuid, EMaterialType.Acceptance, sendCaseInfoData.AreaCode, cancellationToken);
  1159. }
  1160. #endregion
  1161. #region 汇聚-第四批次--已处理
  1162. #region 知识库
  1163. /// <summary>
  1164. /// 知识库上报
  1165. /// </summary>
  1166. /// <param name="dto"></param>
  1167. /// <param name="cancellationToken"></param>
  1168. /// <returns></returns>
  1169. /// <exception cref="UserFriendlyException"></exception>
  1170. public async Task GetKnowledgeInfoSendAsync(KnowledgeSendDto dto, CancellationToken cancellationToken)
  1171. {
  1172. var validator = new KnowledgeInfoValidator();
  1173. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  1174. if (!validResult.IsValid)
  1175. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  1176. var data = _mapper.Map<KnowledgeInfoSendInfo>(dto);
  1177. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  1178. data.CliengGuid = Guid.NewGuid().ToString();
  1179. if (data.DisableDate == null)//如果没得有失效时间,默认在生效日期上面加10年
  1180. data.DisableDate = data.BeginDate.Value.AddYears(10);
  1181. data.CategoryCode = "01";
  1182. data.CategoryName = "公共服务";
  1183. #region 处理请求参数
  1184. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1185. var request = new ProvinceRequest<KnowledgeInfoSendInfo>(configProvince.ClientId, configProvince.ClientSecret);
  1186. request.SetData(data);
  1187. var jsonData = request.ToString();
  1188. #endregion
  1189. //将待推送数据写入待推送表
  1190. await _initPushDataService.InitDsSendTaskProvinceOther("GetKnowledgeInfoSend", "get_knowledge_info_send", data.UID,
  1191. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.HuiJu,
  1192. generationTime: dto.CreatDate, cancellationToken: cancellationToken);
  1193. #region 处理知识库原始数据
  1194. //查询原有数据,如果有修改原始数据,没有直接新增
  1195. var dataRaw = await _knowledgeRawDataRepository.GetAsync(p => p.UID == data.UID);
  1196. var raw = _mapper.Map<DsKnowledgeRawData>(data);
  1197. if (dataRaw != null)
  1198. {
  1199. raw.Id = dataRaw.Id;
  1200. await _knowledgeRawDataRepository.UpdateAsync(raw, cancellationToken: cancellationToken);
  1201. }
  1202. else
  1203. await _knowledgeRawDataRepository.AddAsync(raw, cancellationToken: cancellationToken);
  1204. #endregion
  1205. //知识附件处理
  1206. await FileDataAsync(dto.FileJson, dto.UID, data.CliengGuid, EMaterialType.Knowledge, data.AreaCode, cancellationToken);
  1207. }
  1208. /// <summary>
  1209. /// 知识库变更
  1210. /// </summary>
  1211. /// <param name="dto"></param>
  1212. /// <param name="cancellationToken"></param>
  1213. /// <returns></returns>
  1214. /// <exception cref="UserFriendlyException"></exception>
  1215. public async Task GetKnowledgeInfoUpdateAsync(KnowledgeSendDto dto, CancellationToken cancellationToken)
  1216. {
  1217. var validator = new KnowledgeInfoValidator();
  1218. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  1219. if (!validResult.IsValid)
  1220. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  1221. var data = _mapper.Map<GetKnowledgeInfoUpdateInfo>(dto);
  1222. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  1223. data.CliengGuid = Guid.NewGuid().ToString();
  1224. if (data.DisableDate == null)//如果没得有失效时间,默认在生效日期上面加10年
  1225. data.DisableDate = data.BeginDate.Value.AddYears(10);
  1226. data.CategoryCode = "01";
  1227. data.CategoryName = "公共服务";
  1228. #region 处理请求参数
  1229. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1230. var request = new ProvinceRequest<GetKnowledgeInfoUpdateInfo>(configProvince.ClientId, configProvince.ClientSecret);
  1231. request.SetData(data);
  1232. var jsonData = request.ToString();
  1233. #endregion
  1234. //将待推送数据写入待推送表
  1235. await _initPushDataService.InitDsSendTaskProvinceOther("GetKnowledgeInfoUpdate", "get_knowledge_info_update", data.UID,
  1236. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.HuiJu,
  1237. generationTime: dto.CreatDate, cancellationToken: cancellationToken);
  1238. #region 处理知识库原始数据
  1239. //查询原有数据,如果有修改原始数据,没有直接新增
  1240. var dataRaw = await _knowledgeRawDataRepository.GetAsync(p => p.UID == data.UID);
  1241. var raw = _mapper.Map<DsKnowledgeRawData>(data);
  1242. if (dataRaw != null)
  1243. {
  1244. raw.Id = dataRaw.Id;
  1245. await _knowledgeRawDataRepository.UpdateAsync(raw, cancellationToken: cancellationToken);
  1246. }
  1247. else
  1248. await _knowledgeRawDataRepository.AddAsync(raw, cancellationToken: cancellationToken);
  1249. #endregion
  1250. //知识附件处理
  1251. await FileDataAsync(dto.FileJson, dto.UID, data.CliengGuid, EMaterialType.Knowledge, data.AreaCode, cancellationToken);
  1252. }
  1253. /// <summary>
  1254. /// 知识库下架
  1255. /// </summary>
  1256. /// <param name="dto"></param>
  1257. /// <param name="cancellationToken"></param>
  1258. /// <returns></returns>
  1259. /// <exception cref="UserFriendlyException"></exception>
  1260. public async Task GetKnowledgeInfoAbandonAsync(KnowledgeSendDto dto, CancellationToken cancellationToken)
  1261. {
  1262. var validator = new KnowledgeInfoAbandonValidator();
  1263. var validResult = await validator.ValidateAsync(dto, cancellationToken);
  1264. if (!validResult.IsValid)
  1265. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  1266. var data = _mapper.Map<GetKnowledgeInfoAbandonInfo>(dto);
  1267. data.AreaCode = _sharingConfigurationManager.GetCityCode();
  1268. data.CategoryCode = "01";
  1269. data.CategoryName = "公共服务";
  1270. #region 处理请求参数
  1271. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1272. var request = new ProvinceRequest<GetKnowledgeInfoAbandonInfo>(configProvince.ClientId, configProvince.ClientSecret);
  1273. request.SetData(data);
  1274. var jsonData = request.ToString();
  1275. #endregion
  1276. //将待推送数据写入待推送表
  1277. await _initPushDataService.InitDsSendTaskProvinceOther("GetKnowledgeInfoAbandon", "get_knowledge_info_abandon", data.UID,
  1278. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.HuiJu,
  1279. generationTime: dto.CreatDate, cancellationToken: cancellationToken);
  1280. //知识下架删除原有原始数据
  1281. await _knowledgeRawDataRepository.RemoveAsync(p => p.UID == data.UID, cancellationToken: cancellationToken);
  1282. }
  1283. #endregion
  1284. /// <summary>
  1285. /// 实时服务上报
  1286. /// </summary>
  1287. /// <param name="dto"></param>
  1288. /// <param name="cancellationToken"></param>
  1289. /// <returns></returns>
  1290. public async Task SendRealTimeStatusAsync(SendRealTimeStatusInfo dto, CancellationToken cancellationToken)
  1291. {
  1292. dto.AreaCode = _sharingConfigurationManager.GetCityCode();
  1293. #region 处理请求参数
  1294. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1295. var request = new ProvinceRequest<SendRealTimeStatusInfo>(configProvince.ClientId, configProvince.ClientSecret);
  1296. request.SetData(dto);
  1297. var jsonData = request.ToString();
  1298. #endregion
  1299. await _initPushDataService.InitDsSendTaskProvinceOther("SendRealTimeStatus", "sendrealtimestatus", "",
  1300. jsonData, JsonSerializer.Serialize(dto, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.HuiJu,
  1301. cancellationToken: cancellationToken);
  1302. }
  1303. #endregion
  1304. #region 私有方法
  1305. #region 省数据处理
  1306. /// <summary>
  1307. /// 热线工单办理---服务工单处理/服务工单交办处理过程
  1308. /// </summary>
  1309. /// <param name="dto"></param>
  1310. /// <param name="cancellationToken"></param>
  1311. /// <returns></returns>
  1312. /// <exception cref="UserFriendlyException"></exception>
  1313. private async Task SubmitCaseProcessFlowAsync(OrderFlowDto dto, CancellationToken cancellationToken)
  1314. {
  1315. //判断是否是热线中心
  1316. if (!string.IsNullOrEmpty(dto.Order.ActualHandleOrgCode) && dto.Order.ActualHandleOrgCode == "001")
  1317. dto.Order.ActualHandleOrgName = "热线中心";
  1318. #region 写本地办理数据-用于查询办理流程
  1319. //写本地办理数据-用于查询办理流程
  1320. var orderWorkFlow = _mapper.Map<DsOrderWorkFlow>(dto.WorkflowTrace);
  1321. orderWorkFlow.OrderId = dto.Order.Id;
  1322. await _dataOrderWorkFlowRepository.AddAsync(orderWorkFlow, cancellationToken);
  1323. #endregion
  1324. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1325. ///如果是省上派下来的,直接将区域设置为系统市州
  1326. if (dto.Order.Source == ESource.ProvinceStraight)
  1327. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  1328. //省上下来的工单走协同的接口
  1329. if (dto.Order.Source == ESource.ProvinceStraight && dto.Order.IsProvince)
  1330. {
  1331. var data = _mapper.Map<GetCaseProcessReceiveInfo>(dto);
  1332. data.TacheName = "70:" + data.DeptName;
  1333. data.EndAreaName = string.IsNullOrEmpty(dto.WorkflowTrace.HandlerOrgAreaName) == false ? dto.WorkflowTrace.HandlerOrgAreaName : _sharingConfigurationManager.GetCityName();
  1334. var validator = new GetCaseProcessReceiveInfoValidator();
  1335. var validResult = await validator.ValidateAsync(data, cancellationToken);
  1336. if (!validResult.IsValid)
  1337. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  1338. #region 处理请求参数
  1339. var request = new ProvinceRequest<GetCaseProcessReceiveInfo>(configProvince.ClientIdXieTong, configProvince.ClientSecretXieTong);
  1340. request.SetData(data);
  1341. var jsonData = request.ToString();
  1342. #endregion
  1343. //将待推送数据写入待推送表
  1344. await _initPushDataService.InitDsSendTaskProvinceOther("GetCaseProcessReceive", "get_case_process_receive", data.CaseSerial,
  1345. jsonData, JsonSerializer.Serialize(data, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.XieTong,
  1346. generationTime: dto.Order.StartTime, cancellationToken: cancellationToken);
  1347. //处理附件
  1348. await FileDataAsync(dto.WorkflowTrace.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Process, dto.Order.AreaCode, cancellationToken);
  1349. }
  1350. else //如果不是省上派下来的工单
  1351. {
  1352. //本地工单走市州接口
  1353. var data = _mapper.Map<SubmitCaseProcessInfo>(dto);
  1354. data.TacheName = "70:" + data.DeptName;
  1355. data.EndAreaName = string.IsNullOrEmpty(dto.WorkflowTrace.HandlerOrgAreaName) == false ? dto.WorkflowTrace.HandlerOrgAreaName : _sharingConfigurationManager.GetCityName();
  1356. var validator = new SubmitCaseProcessInfoValidator();
  1357. var validResult = await validator.ValidateAsync(data, cancellationToken);
  1358. if (!validResult.IsValid)
  1359. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  1360. #region 处理请求参数
  1361. var requestSubmitCaseProcessInfo = new ProvinceListRequest<SubmitCaseProcessInfo>(configProvince.ClientId, configProvince.ClientSecret);
  1362. requestSubmitCaseProcessInfo.SetData(new List<SubmitCaseProcessInfo>() { data });
  1363. var jsonDataSubmitCaseProcessInfo = requestSubmitCaseProcessInfo.ToString();
  1364. #endregion
  1365. //将待推送数据写入待推送表
  1366. await _initPushDataService.InitDsSendTaskSubmitCaseProcess(data.CaseSerial, jsonDataSubmitCaseProcessInfo, data, dto.Order.StartTime, cancellationToken);
  1367. //处理附件
  1368. await FileDataAsync(dto.WorkflowTrace.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Process, dto.Order.AreaCode, cancellationToken);
  1369. }
  1370. ////这里判断是否需要往其他平台推送数据
  1371. //await OrderDispatchAsync(dto, cancellationToken);
  1372. }
  1373. /// <summary>
  1374. /// 服务工单结果
  1375. /// </summary>
  1376. /// <param name="dto"></param>
  1377. /// <returns></returns>
  1378. private async Task SubmitCaseResultAsync(OrderFlowDto dto, CancellationToken cancellationToken)
  1379. {
  1380. ///如果是省上派下来的,直接将区域设置为系统市州
  1381. if (dto.Order.Source == ESource.ProvinceStraight)
  1382. dto.Order.AreaCode = _sharingConfigurationManager.GetCityCode();
  1383. var data = _mapper.Map<SubmitCaseResultInfo>(dto);
  1384. data.ConcactType = "40";
  1385. data.FinishType = "1";
  1386. data.HandleTimeLong = (int)dto.Order.AllDuration;
  1387. data.CliengGuid = dto.WorkflowTrace.Id;
  1388. data.EndAreaName = string.IsNullOrEmpty(dto.Order.ActualHandleOrgAreaName) == false ? dto.Order.ActualHandleOrgAreaName : _sharingConfigurationManager.GetCityName();
  1389. //宜宾工单不超期,如果在推送省上数据时,实际办理时间大于过期时间,则将办理时间改成过期时间减2个小时
  1390. if (_sharingConfigurationManager.IsCity(ConfigurationConsts.YiBin))
  1391. {
  1392. if (dto.Order.ExpiredTime < dto.Order.ActualHandleTime)
  1393. {
  1394. var finishTime = dto.Order.ExpiredTime.Value.AddHours(-2);
  1395. data.FinishTime = finishTime;
  1396. data.FdBackTime = finishTime;
  1397. }
  1398. }
  1399. var validator = new SubmitCaseResultInfoValidator();
  1400. var validResult = await validator.ValidateAsync(data, cancellationToken);
  1401. if (!validResult.IsValid)
  1402. throw new UserFriendlyException(string.Join(',', validResult.Errors.Select(d => d.ErrorMessage)));
  1403. #region 处理请求参数
  1404. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1405. var request = new ProvinceListRequest<SubmitCaseResultInfo>(configProvince.ClientId, configProvince.ClientSecret);
  1406. request.SetData(new List<SubmitCaseResultInfo>() { data });
  1407. var jsonData = request.ToString();
  1408. #endregion
  1409. //将待推送数据写入待推送表
  1410. await _initPushDataService.InitDsSendTaskSubmitCaseResult(data.CaseSerial, jsonData, data, dto.Order.StartTime, cancellationToken);
  1411. //处理附件
  1412. if (dto.WorkflowTrace != null && dto.WorkflowTrace.FileJson != null && dto.WorkflowTrace.FileJson.Count > 0)
  1413. await FileDataAsync(dto.WorkflowTrace.FileJson, data.CaseSerial, data.CliengGuid, EMaterialType.Result, dto.Order.AreaCode, cancellationToken);
  1414. }
  1415. /// <summary>
  1416. /// 工单创建数据处理
  1417. /// </summary>
  1418. /// <param name="dto"></param>
  1419. /// <returns></returns>
  1420. private SubmitCaseInfo InitDataAsync(OrderDto dto)
  1421. {
  1422. var submitCaseInfo = _mapper.Map<SubmitCaseInfo>(dto);
  1423. //处理性别
  1424. submitCaseInfo.AppLicantSex = dto.FromGender switch
  1425. {
  1426. EGender.Female => "0",
  1427. EGender.Male => "1",
  1428. EGender.Unknown => "2",
  1429. _ => "2",
  1430. };
  1431. //处理证件类型
  1432. submitCaseInfo.CertifiCateType = dto.LicenceTypeCode switch
  1433. {
  1434. "10" => "10",
  1435. "40" => "20",
  1436. "55" => "30",
  1437. "57" => "40",
  1438. _ => "50",
  1439. };
  1440. //处理紧急程度
  1441. submitCaseInfo.CaseIsUrgent = dto.EmergencyLevel switch
  1442. {
  1443. EEmergencyLevel.QuiteEmergency => "10",
  1444. EEmergencyLevel.Emergency => "20",
  1445. _ => "30",
  1446. };
  1447. //处理推送分类,如果存在多个只取第一个
  1448. if (dto.OrderPushTypes != null && dto.OrderPushTypes.Count > 0)
  1449. {
  1450. var push = dto.OrderPushTypes[0];
  1451. if (push != null)
  1452. submitCaseInfo.PushType = push.PushTypeCode;
  1453. }
  1454. //处理诉求类型
  1455. switch (submitCaseInfo.CaseType)
  1456. {
  1457. case "10":
  1458. case "15":
  1459. case "20":
  1460. case "25":
  1461. case "30":
  1462. case "35":
  1463. break;
  1464. default:
  1465. submitCaseInfo.CaseType = "40";
  1466. break;
  1467. }
  1468. submitCaseInfo.CaseValid = "1";
  1469. submitCaseInfo.CaseIsPublic = string.IsNullOrEmpty(submitCaseInfo.CaseIsPublic) == true ? "0" : submitCaseInfo.CaseIsPublic;
  1470. submitCaseInfo.ThemeSerial = "20";
  1471. if (dto.SourceChannelCode == "SZMHD" && dto.IsProvince == false && dto.Source == ESource.ProvinceStraight)
  1472. submitCaseInfo.TrowGuid = "【政民互动直派】";
  1473. switch (dto.SourceChannelCode.ToUpper())
  1474. {
  1475. case "RGDH":
  1476. case "WX":
  1477. case "WB":
  1478. case "AP":
  1479. case "WZ":
  1480. case "YJ":
  1481. case "SCZWFWW":
  1482. case "XCX":
  1483. break;
  1484. default:
  1485. submitCaseInfo.CaseSource = "QT";
  1486. break;
  1487. }
  1488. return submitCaseInfo;
  1489. }
  1490. /// <summary>
  1491. /// 服务工单拓展信息
  1492. /// </summary>
  1493. /// <param name="dto"></param>
  1494. /// <returns></returns>
  1495. private async Task SubmitCaseExtendsAsync(OrderDto dto, CancellationToken cancellationToken)
  1496. {
  1497. var orderExtension = dto.OrderExtension;
  1498. if (orderExtension is null)
  1499. return;
  1500. //工单类型
  1501. string formType = orderExtension.OrderTypeCode;
  1502. //处理为统一的市场监管表单
  1503. if (formType == "scjgjts" || formType == "scjgjjb")
  1504. formType = "scjgj";
  1505. DataSharing.Share.Dtos.Province.HuiJu.SubmitCaseExtendsInfo submitCaseExtendsInfo = new()
  1506. {
  1507. CaseSerial = dto.ProvinceNo,
  1508. FormType = formType
  1509. };
  1510. //处理扩展信息
  1511. switch (formType.ToLower())
  1512. {
  1513. case "yl"://医疗表单
  1514. //转换数据
  1515. submitCaseExtendsInfo.FormMedical = _mapper.Map<FormMedicalInfo>(orderExtension);
  1516. break;
  1517. case "zwfw"://四川政务服务网技术工单
  1518. submitCaseExtendsInfo.FormNetWorktec = _mapper.Map<FormNetWorktecInfo>(orderExtension);
  1519. break;
  1520. case "th"://电视购物及商铺购买退换货工单
  1521. submitCaseExtendsInfo.FormReturnexChange = _mapper.Map<FormReturnexChangeInfo>(orderExtension);
  1522. break;
  1523. case "gsgl"://高速公路工单
  1524. submitCaseExtendsInfo.FormExpressWay = _mapper.Map<FormExpressWayInfo>(orderExtension);
  1525. break;
  1526. case "xjgg"://电视台虚假广告工单
  1527. submitCaseExtendsInfo.FormShamPub = _mapper.Map<FormShamPubInfo>(orderExtension);
  1528. break;
  1529. case "swfwsq"://12366热线诉求交办
  1530. submitCaseExtendsInfo.FormTaxationComplaint = _mapper.Map<FormTaxationComplaintInfo>(orderExtension);
  1531. break;
  1532. case "swfwzx"://12366热线咨询交办
  1533. submitCaseExtendsInfo.FormTaxationConsulting = _mapper.Map<FormTaxationConsultingInfo>(orderExtension);
  1534. break;
  1535. case "jtfwjd"://12328服务监督
  1536. submitCaseExtendsInfo.FormTraffic = _mapper.Map<FormTrafficInfo>(orderExtension);
  1537. break;
  1538. case "yzxf"://邮政业消费者申诉
  1539. submitCaseExtendsInfo.FormPost = _mapper.Map<FormPostInfo>(orderExtension);
  1540. break;
  1541. case "hbjb"://环保举报业务
  1542. submitCaseExtendsInfo.FormEnvironMent = _mapper.Map<FormEnvironMentInfo>(orderExtension);
  1543. break;
  1544. case "scjgj"://12315个性化表单
  1545. var formMarket = _mapper.Map<FormMarketInfo>(orderExtension);
  1546. //转换数据
  1547. switch (orderExtension.OrderTypeCode)
  1548. {
  1549. case "scjgjjb":
  1550. formMarket.Rqsttypy = "25";
  1551. break;
  1552. case "scjgjts":
  1553. formMarket.Rqsttypy = "20";
  1554. foreach (var item in orderExtension.ComplainTypes)
  1555. formMarket.AppealContent += item.Value + ",";
  1556. formMarket.AppealContent = formMarket.AppealContent.TrimEnd(',');
  1557. break;
  1558. default:
  1559. break;
  1560. }
  1561. formMarket.HandDepCode = dto.AcceptorOrgCode;
  1562. formMarket.HandDep = dto.AcceptorOrgName;
  1563. formMarket.Zxgh = dto.AcceptorStaffNo;
  1564. formMarket.AccregperId = dto.AcceptorId;
  1565. formMarket.AccregperName = dto.AcceptorName;
  1566. formMarket.RegTime = Convert.ToDateTime(dto.CreationTime);
  1567. formMarket.CmTime = dto.StartTime;
  1568. submitCaseExtendsInfo.FormMarket = formMarket;
  1569. break;
  1570. default:
  1571. break;
  1572. }
  1573. #region 处理请求参数
  1574. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1575. var request = new ProvinceRequest<DataSharing.Share.Dtos.Province.HuiJu.SubmitCaseExtendsInfo>(configProvince.ClientId, configProvince.ClientSecret);
  1576. request.SetData(submitCaseExtendsInfo);
  1577. var jsonData = request.ToString();
  1578. #endregion
  1579. //将待推送数据写入待推送表
  1580. await _initPushDataService.InitDsSendTaskProvinceOther("SubmitCaseExtends", "submit_case_extends", submitCaseExtendsInfo.CaseSerial,
  1581. jsonData, JsonSerializer.Serialize(submitCaseExtendsInfo, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.HuiJu, generationTime: dto.StartTime, cancellationToken: cancellationToken);
  1582. }
  1583. /// <summary>
  1584. /// 附件处理
  1585. /// </summary>
  1586. /// <param name="fileJson">附件</param>
  1587. /// <param name="caseSerial">工单编号</param>
  1588. /// <param name="cliengGuid">附件ID</param>
  1589. /// <param name="materialType">附件类型 10:受理材料,20:环节材料,30:结果材料,40:回访评价材料,50:督办材料,60:知识库材料</param>
  1590. /// <param name="areaCode">区域ID</param>
  1591. /// <param name="cancellationToken"></param>
  1592. /// <returns></returns>
  1593. private async Task FileDataAsync(List<Hotline.Share.Dtos.File.FileJson> fileJson, string caseSerial, string cliengGuid, EMaterialType materialType, string areaCode, CancellationToken cancellationToken)
  1594. {
  1595. if (fileJson != null && fileJson.Count > 0)
  1596. {
  1597. //将受到的数据写入本地数据库
  1598. GetCaseMaterialInfoModel materialInfo = new()
  1599. {
  1600. CaseSerial = caseSerial,
  1601. CliengGuid = cliengGuid,
  1602. AreaCode = areaCode.Length > 6 ? areaCode.Substring(0, 6) : areaCode,
  1603. MaterialType = materialType switch
  1604. {
  1605. EMaterialType.Acceptance => "10",
  1606. EMaterialType.Process => "20",
  1607. EMaterialType.Result => "30",
  1608. EMaterialType.Visit => "40",
  1609. EMaterialType.Supervise => "50",
  1610. EMaterialType.Knowledge => "60",
  1611. _ => "20",
  1612. }
  1613. };
  1614. var configProvince = _channelConfigurationManager.GetConfigurationProvince();
  1615. var request = new ProvinceRequest<GetCaseMaterialInfoModel>(configProvince.ClientId, configProvince.ClientSecret);
  1616. request.SetData(materialInfo);
  1617. var jsonData = request.ToString();
  1618. foreach (var item in fileJson)
  1619. {
  1620. // 新增文件到列表
  1621. var fileData = new DsGetCaseMaterialInfo()
  1622. {
  1623. CaseSerial = caseSerial,
  1624. MaterialType = materialInfo.MaterialType,
  1625. CliengGuid = materialInfo.CliengGuid,
  1626. AreaCode = materialInfo.AreaCode,
  1627. FileName = item.FileName,
  1628. Type = item.FileType,
  1629. Additions = item.Id,
  1630. Path = item.Path,
  1631. Direction = "1",
  1632. SyncState = "1"
  1633. };
  1634. await _getCaseMaterialInfoRepository.AddAsync(fileData, cancellationToken);
  1635. List<FileJson> fileJsons = new() { _mapper.Map<FileJson>(item) };
  1636. //待推送数据写入待推送表
  1637. await _initPushDataService.InitDsSendTaskProvinceOther("GetCaseMaterialInfo", "get_case_material_info", materialInfo.CaseSerial,
  1638. jsonData, JsonSerializer.Serialize(materialInfo, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions), pathType: EPathType.File,
  1639. fileJson: fileJsons, cancellationToken: cancellationToken);
  1640. }
  1641. }
  1642. }
  1643. /// <summary>
  1644. /// 处理通话记录队列时间
  1645. /// </summary>
  1646. /// <param name="recordInfo"></param>
  1647. /// <returns></returns>
  1648. private void SetCallTime(SubmitCaseRecordInfo recordInfo)
  1649. {
  1650. // 电话进入顺序 进IVR时间→进队列时间→振铃时间→开始时间→结束时间
  1651. //进入IVR时间为空
  1652. if (recordInfo.InIvr == DateTime.MinValue)
  1653. {
  1654. if (recordInfo.InQueue == DateTime.MinValue)
  1655. {
  1656. if (recordInfo.CallStart == DateTime.MinValue)
  1657. {
  1658. recordInfo.CallStart = recordInfo.CallEnd.AddSeconds(-2);
  1659. }
  1660. recordInfo.InQueue = recordInfo.CallStart.AddSeconds(-2);
  1661. }
  1662. recordInfo.InIvr = recordInfo.InQueue.AddSeconds(-2);
  1663. }
  1664. //进入队列时间为空
  1665. if (recordInfo.InQueue == DateTime.MinValue)
  1666. {
  1667. if (recordInfo.InIvr == DateTime.MinValue)
  1668. {
  1669. if (recordInfo.CallStart == DateTime.MinValue)
  1670. {
  1671. recordInfo.CallStart = recordInfo.CallEnd.AddSeconds(-2);
  1672. }
  1673. recordInfo.InQueue = recordInfo.CallStart.AddSeconds(-2);
  1674. recordInfo.InIvr = recordInfo.InQueue.AddSeconds(-2);
  1675. }
  1676. else
  1677. recordInfo.InQueue = recordInfo.InIvr.AddSeconds(2);
  1678. }
  1679. //振铃时间为空
  1680. if (recordInfo.CallTime == DateTime.MinValue && recordInfo.CallStart != DateTime.MinValue)
  1681. recordInfo.CallTime = recordInfo.CallStart.AddSeconds(-2);
  1682. }
  1683. /// <summary>
  1684. /// 检查是否需要推送未接通话记录
  1685. /// </summary>
  1686. /// <param name="endTime"></param>
  1687. /// <param name="cancellationToken"></param>
  1688. /// <returns></returns>
  1689. private async Task<bool> IsPublishMissedCall(DateTime endTime, CancellationToken cancellationToken)
  1690. {
  1691. var key = MissedCallKey + DateTime.Now.ToString("yyyyMMdd");
  1692. int missedCallCount = 0;
  1693. //获取系统配置
  1694. var configurationInformation = await _configurationInformationCache.GetAsync(ConstantSettings.ConfigurationInformationCacheKey, cancellationToken);
  1695. if (configurationInformation != null)
  1696. missedCallCount = configurationInformation.MissedCallCount;
  1697. //如果配置为空或者配置的数量为0
  1698. if (configurationInformation == null && missedCallCount <= 0)
  1699. return true;
  1700. _logger.LogWarning("获取到的不上传的值:------------------------" + missedCallCount);
  1701. var dataCache = await _missedCallModelCache.GetAsync(key, cancellationToken);
  1702. _logger.LogWarning("获取到缓存的值:------------------------" + JsonSerializer.Serialize(dataCache));
  1703. if (dataCache != null)
  1704. {
  1705. //如果存在值,检查是否已经达到推送最大值
  1706. if (dataCache.IsMax == false && dataCache.DateTimeList.Count > 0)
  1707. {
  1708. //没有达到最大值
  1709. //检查第一条数据是否匹配当前推送时间
  1710. var list = dataCache.DateTimeList;
  1711. if (list[0] < endTime)
  1712. {
  1713. _logger.LogWarning("匹配到需要上传的,原始数据:------------------------" + JsonSerializer.Serialize(list));
  1714. //处理数据
  1715. list.RemoveAt(0);
  1716. dataCache.DateTimeList = list;
  1717. //是否推送完成
  1718. if (list == null || list.Count == 0)
  1719. dataCache.IsMax = true;
  1720. _logger.LogWarning("处理后数据:------------------------" + JsonSerializer.Serialize(list));
  1721. //从新写入数据
  1722. await _missedCallModelCache.SetAsync(key, dataCache, TimeSpan.FromDays(1), cancellationToken);
  1723. return true;
  1724. }
  1725. }
  1726. }
  1727. else
  1728. {
  1729. #region 生成时间
  1730. //生成时间
  1731. List<DateTime> timeLists = new();
  1732. Random random = new((int)(DateTime.Now.Ticks));
  1733. for (int i = 0; i < missedCallCount; i++)
  1734. {
  1735. int hour = random.Next(2, 23);
  1736. int minute = random.Next(0, 60);
  1737. int second = random.Next(0, 60);
  1738. string tempStr = string.Format("{0} {1}:{2}:{3}", DateTime.Now.ToString("yyyy-MM-dd"), hour, minute, second);
  1739. DateTime rTime = Convert.ToDateTime(tempStr);
  1740. timeLists.Add(rTime);
  1741. }
  1742. timeLists.Sort();
  1743. #endregion
  1744. if (timeLists[0] < endTime)
  1745. //处理数据
  1746. timeLists.RemoveAt(0);
  1747. MissedCallModelDto missedCall = new()
  1748. {
  1749. DateTimeList = timeLists
  1750. };
  1751. if (timeLists == null || timeLists.Count == 0)
  1752. missedCall.IsMax = true;
  1753. await _missedCallModelCache.SetAsync(key, missedCall, TimeSpan.FromDays(1), cancellationToken);
  1754. return true;
  1755. }
  1756. return false;
  1757. }
  1758. /// <summary>
  1759. /// 初始化上传通话记录
  1760. /// </summary>
  1761. /// <param name="dto"></param>
  1762. /// <param name="ProvinceNo"></param>
  1763. /// <param name="cancellationToken"></param>
  1764. /// <returns></returns>
  1765. private async Task InitTelCallData(TrCallDto dto, string ProvinceNo, string taskId, CancellationToken cancellationToken)
  1766. {
  1767. var tellCall = await _dsTelCallRepository.GetAsync(p => p.CallId == dto.OtherAccept, cancellationToken);
  1768. if (tellCall != null)
  1769. {
  1770. //修改
  1771. _mapper.Map(dto, tellCall);
  1772. tellCall.ProvinceNo = ProvinceNo;
  1773. tellCall.CallId = dto.OtherAccept;
  1774. tellCall.TaskId = taskId;
  1775. await _dsTelCallRepository.UpdateAsync(tellCall, cancellationToken);
  1776. }
  1777. else
  1778. {
  1779. //新增
  1780. tellCall = new DsTelCall();
  1781. tellCall = _mapper.Map<DsTelCall>(dto);
  1782. tellCall.ProvinceNo = ProvinceNo;
  1783. tellCall.CallId = dto.OtherAccept;
  1784. tellCall.TaskId = taskId;
  1785. tellCall.Id = dto.OtherAccept;
  1786. try
  1787. {
  1788. await _dsTelCallRepository.AddAsync(tellCall, cancellationToken);
  1789. }
  1790. catch (Exception ex)
  1791. {
  1792. var tellCallNew = await _dsTelCallRepository.GetAsync(p => p.CallId == dto.OtherAccept, cancellationToken);
  1793. if (tellCallNew != null)
  1794. {
  1795. //修改
  1796. _mapper.Map(dto, tellCallNew);
  1797. tellCallNew.ProvinceNo = ProvinceNo;
  1798. tellCallNew.CallId = dto.OtherAccept;
  1799. tellCallNew.TaskId = taskId;
  1800. await _dsTelCallRepository.UpdateAsync(tellCallNew, cancellationToken);
  1801. }
  1802. }
  1803. }
  1804. }
  1805. /// <summary>
  1806. /// 初始化上传通话记录----丰窝
  1807. /// </summary>
  1808. /// <param name="dto"></param>
  1809. /// <param name="ProvinceNo"></param>
  1810. /// <param name="cancellationToken"></param>
  1811. /// <returns></returns>
  1812. private async Task InitTelFwCallData(CallNativeDto dto, string ProvinceNo, string taskId, CancellationToken cancellationToken)
  1813. {
  1814. var tellCall = await _dsTelCallRepository.GetAsync(p => p.CallId == dto.Id, cancellationToken);
  1815. if (tellCall != null)
  1816. {
  1817. //修改
  1818. _mapper.Map(dto, tellCall);
  1819. tellCall.ProvinceNo = ProvinceNo;
  1820. tellCall.TaskId = taskId;
  1821. await _dsTelCallRepository.UpdateAsync(tellCall, cancellationToken);
  1822. }
  1823. else
  1824. {
  1825. //新增
  1826. tellCall = new DsTelCall();
  1827. tellCall = _mapper.Map<DsTelCall>(dto);
  1828. tellCall.ProvinceNo = ProvinceNo;
  1829. tellCall.TaskId = taskId;
  1830. tellCall.Id = dto.Id;
  1831. try
  1832. {
  1833. await _dsTelCallRepository.AddAsync(tellCall, cancellationToken);
  1834. }
  1835. catch (Exception ex)
  1836. {
  1837. var tellCallNew = await _dsTelCallRepository.GetAsync(p => p.CallId == dto.Id, cancellationToken);
  1838. if (tellCallNew != null)
  1839. {
  1840. //修改
  1841. _mapper.Map(dto, tellCallNew);
  1842. tellCallNew.ProvinceNo = ProvinceNo;
  1843. tellCallNew.TaskId = taskId;
  1844. await _dsTelCallRepository.UpdateAsync(tellCallNew, cancellationToken);
  1845. }
  1846. }
  1847. }
  1848. }
  1849. #endregion
  1850. #endregion
  1851. }
  1852. }