12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019 |
- using DotNetCore.CAP;
- using Hotline.Caching.Interfaces;
- using Hotline.Share.Dtos.Order;
- using Hotline.Share.Enums.Order;
- using MapsterMapper;
- using Microsoft.Extensions.Logging;
- using XF.Domain.Authentications;
- using XF.Domain.Cache;
- using XF.Domain.Dependency;
- using XF.Domain.Exceptions;
- using XF.Domain.Repository;
- using Hotline.CallCenter.Calls;
- using Hotline.File;
- using Hotline.FlowEngine.Workflows;
- using Hotline.Schedulings;
- using Hotline.SeedData;
- using Hotline.Users;
- using Hotline.Share.Dtos;
- using Hotline.Settings.Hotspots;
- using Hotline.Share.Dtos.FlowEngine;
- using Microsoft.AspNetCore.Http;
- using Hotline.Settings;
- using SqlSugar;
- using Hotline.Push.Notifies;
- using Hotline.Share.Enums.Push;
- using MediatR;
- using Hotline.Authentications;
- using Hotline.ContingencyManagement.Notifies;
- using Hotline.EventBus;
- using Hotline.Share.Enums.FlowEngine;
- using Mapster;
- using Microsoft.AspNetCore.Builder.Extensions;
- using Hotline.Configurations;
- using Microsoft.Extensions.Options;
- using Hotline.Share.Tools;
- using Hotline.Orders.Notifications;
- using Hotline.Share.Mq;
- using System.Security.Cryptography;
- using Hotline.FlowEngine.Definitions;
- using Hotline.Share.Dtos.FlowEngine.Workflow;
- using Hotline.Share.Enums.Settings;
- using Hotline.Settings.TimeLimitDomain;
- using Hotline.Snapshot.IRepository;
- namespace Hotline.Orders;
- public class OrderDomainService : IOrderDomainService, IScopeDependency
- {
- private readonly IOrderRepository _orderRepository;
- private readonly IRepository<OrderRedo> _orderRedoRepository;
- private readonly IRepository<OrderPublish> _orderPublishRepository;
- private readonly IRepository<OrderVisit> _orderVisitRepository;
- private readonly IRepository<OrderExtension> _orderExtensionRepository;
- private readonly IRepository<OrderComplement> _orderComplementRepository;
- private readonly ITypedCache<CacheOrderNO> _cacheOrderNo;
- private readonly ISessionContext _sessionContext;
- private readonly ICapPublisher _capPublisher;
- private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
- private readonly IMapper _mapper;
- private readonly ILogger<OrderDomainService> _logger;
- private readonly IFileRepository _fileRepository;
- private readonly IRepository<Scheduling> _schedulingRepository;
- private readonly Publisher _publisher;
- private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
- private readonly IRepository<User> _userRepository;
- private readonly ISystemSettingCacheManager _systemSettingCacheManager;
- private readonly IWorkflowDomainService _workflowDomainService;
- private readonly IRepository<Hotspot> _hotspotRepository;
- private readonly IMediator _mediator;
- private readonly IRepository<WorkflowStep> _workflowStepRepository;
- private readonly ISystemLogRepository _systemLogRepository;
- private readonly IOrderSnapshotRepository _orderSnapshotRepository;
- private readonly ICalcExpireTime _expireTime;
- private readonly ICallDomainService _callDomainService;
- private readonly IOrderVisitDomainService _orderVisitDomainService;
- public OrderDomainService(
- IOrderRepository orderRepository,
- IRepository<OrderRedo> orderRedoRepository,
- IRepository<OrderPublish> orderPublishRepository,
- IRepository<OrderVisit> orderVisitRepository,
- IRepository<OrderExtension> orderExtensionRepository,
- IRepository<OrderComplement> orderComplementRepository,
- ITypedCache<CacheOrderNO> cacheOrderNo,
- ISessionContext sessionContext,
- ICapPublisher capPublisher,
- IMapper mapper,
- ILogger<OrderDomainService> logger,
- IFileRepository fileRepository,
- IRepository<WexCallRecord> wexCallRecordRepository,
- IRepository<User> userRepository,
- ISystemSettingCacheManager systemSettingCacheManager,
- IRepository<Scheduling> schedulingRepository,
- IWorkflowDomainService workflowDomainService,
- IRepository<Hotspot> hotspotRepository,
- IMediator mediator,
- Publisher publisher,
- IRepository<OrderVisitDetail> orderVisitDetailRepository,
- IRepository<WorkflowStep> workflowStepRepository,
- ISystemLogRepository systemLogRepository,
- IOptionsSnapshot<AppConfiguration> appOptions,
- IOrderSnapshotRepository orderSnapshotRepository,
- ICalcExpireTime expireTime,
- ICallDomainService callDomainService,
- IOrderVisitDomainService orderVisitDomainService)
- {
- _orderRepository = orderRepository;
- _orderRedoRepository = orderRedoRepository;
- _orderPublishRepository = orderPublishRepository;
- _orderVisitRepository = orderVisitRepository;
- _orderExtensionRepository = orderExtensionRepository;
- _orderComplementRepository = orderComplementRepository;
- _cacheOrderNo = cacheOrderNo;
- _sessionContext = sessionContext;
- _capPublisher = capPublisher;
- _mapper = mapper;
- _logger = logger;
- _fileRepository = fileRepository;
- _userRepository = userRepository;
- _schedulingRepository = schedulingRepository;
- _systemSettingCacheManager = systemSettingCacheManager;
- _workflowDomainService = workflowDomainService;
- _hotspotRepository = hotspotRepository;
- _mediator = mediator;
- _publisher = publisher;
- _orderVisitDetailRepository = orderVisitDetailRepository;
- _workflowStepRepository = workflowStepRepository;
- _systemLogRepository = systemLogRepository;
- _appOptions = appOptions;
- _orderSnapshotRepository = orderSnapshotRepository;
- _expireTime = expireTime;
- _callDomainService = callDomainService;
- _orderVisitDomainService = orderVisitDomainService;
- }
- /// <summary>
- /// 归档后自动发布
- /// </summary>
- /// <param name="order"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task OrderAutomaticPublishAsync(Order order, CancellationToken cancellationToken)
- {
- var name = "中心直办件归档后默认自动发布";
- var msg = $"OrderId: {order.Id}, No: {order.No}";
- try
- {
- if (_systemSettingCacheManager.AutomaticPublishOrder == false)
- {
- return;
- }
- var isSnapshot = await _orderSnapshotRepository.AnyAsync(m => m.Id == order.Id, cancellationToken);
- if (isSnapshot == true)
- {
- _systemLogRepository.Add(name, msg, "随手拍工单不允许自动发布");
- return;
- }
- var checkResult = order.AutoPublishCheck();
- if (checkResult.NotNullOrEmpty())
- {
- _systemLogRepository.Add(name, msg, checkResult);
- return;
- }
- if (order.FileOrgIsCenter == null || order.FileOrgIsCenter == false)
- {
- _systemLogRepository.Add(name, msg, "非中心直办件");
- return;
- }
- await OrderPublishAsync(order, cancellationToken);
- }
- catch (Exception e)
- {
- _systemLogRepository.Add(name, msg, $"系统异常: {e.Message}");
- }
- }
- public async Task OrderPublishAsync(Order order, CancellationToken cancellationToken)
- {
- OrderPublish orderPublish = new()
- {
- OrderId = order.Id,
- No = order.No,
- PublishState = false, //当前写死为false
- ArrangeTitle = order.Title,
- ArrangeContent = order.Content,
- ArrangeOpinion = order.FileOpinion,
- ProPublishState = false,
- FeedBackPhone = order.Contact,
- CreatorName = _sessionContext.UserName
- };
- var id = await _orderPublishRepository.AddAsync(orderPublish, cancellationToken);
- order.Publish(orderPublish.PublishState);
- await _orderRepository.UpdateAsync(order, cancellationToken);
- //推省上
- var publishPublishOrder = orderPublish.Adapt<PublishPublishOrderDto>();
- publishPublishOrder.Order = order.Adapt<OrderDto>();
- //查询实际办理附件
- if (!string.IsNullOrEmpty(order.ActualHandleStepId))
- {
- var actualHandleStep = await _workflowStepRepository.GetAsync(order.ActualHandleStepId, cancellationToken);
- publishPublishOrder.FileJsons = actualHandleStep?.FileJson;
- }
- await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderPublishOrder, publishPublishOrder, cancellationToken: cancellationToken);
- //推应急管理局
- //是否开启
- var isOpenContingencyManagement =
- _systemSettingCacheManager.GetSetting(SettingConstants.IsOpenContingencyManagement)?.SettingValue[0];
- if (isOpenContingencyManagement == "true")
- await _publisher.PublishAsync(new ContingencyManagementNotify(order, order.Title, order.Content, order.ActualOpinion),
- PublishStrategy.ParallelWhenAll, cancellationToken);
- // 取消发布的工单数量
- var orderPublishDeletedCount = await _orderPublishRepository.Queryable(includeDeleted: true)
- .Where(m => m.OrderId == order.Id && m.IsDeleted == true)
- .CountAsync(cancellationToken);
- var orderVisitVisitedCount = await _orderVisitRepository.Queryable()
- .Where(m => m.OrderId == order.Id && m.VisitState == EVisitState.Visited)
- .CountAsync(cancellationToken);
- // 若取消发布的工单,已经被回访过了,没有经过重新办理,再次发布后,自动跳过回访环节,展示取消发布前的回访结果
- if (orderPublishDeletedCount != 0 && orderVisitVisitedCount != 0)
- {
- return;
- }
- var orderVisit = new OrderVisit
- {
- No = order.No,
- OrderId = order.Id,
- VisitState = EVisitState.WaitForVisit,
- PublishTime = DateTime.Now,
- IsCanHandle = true,
- EmployeeId = _sessionContext.RequiredUserId
- };
- if (!order.IsProvince)
- {
- orderVisit.EmployeeId = _sessionContext.RequiredUserId;
- }
- var isReturn = false;
- if (_appOptions.Value.IsZiGong)
- {
- orderVisit.EmployeeId = string.Empty;
- //自贡任务 348 语音评价不满意的工单需回访
- var callNative = await GetReplyVoiceOrDefaultByOrderIdAsync(orderVisit.OrderId);
- if (callNative == EVoiceEvaluate.NoSatisfied || callNative == EVoiceEvaluate.VeryNoSatisfied)
- isReturn = true;
- }
- if (isReturn == false)
- {
- if (order is { FileOrgIsCenter: true, CounterSignType: null } && !order.IsProvince)
- {
- orderVisit.VisitState = EVisitState.Visited;
- orderVisit.VisitTime = DateTime.Now;
- orderVisit.VisitType = EVisitType.OtherVisit;
- orderVisit.NowEvaluate = new Kv() { Key = "4", Value = "满意" };
- if (_appOptions.Value.IsZiGong)
- {
- // 根据禅道 自贡需求 Id_361, 第一条, 3小条需求;
- // 直办件归档后自动回访量需统计在“胡玲”的默认回访量中;
- orderVisit.EmployeeId = _systemSettingCacheManager.DefaultVisitEmployeeId;
- }
- }
- if (order.CounterSignType != ECounterSignType.Center)
- {
- orderVisit.IsCanAiVisit = true;
- }
- }
- string visitId = await _orderVisitRepository.AddAsync(orderVisit);
- //新增回访信息
- var visitedDetail = new List<OrderVisitDetail>();
- //坐席回访明细
- var seatDetail = new OrderVisitDetail
- {
- VisitId = visitId,
- VisitTarget = EVisitTarget.Seat
- };
- //部门回访明细
- var orgDetail = new OrderVisitDetail
- {
- VisitId = visitId,
- VisitOrgCode = order.ActualHandleOrgCode,
- VisitOrgName = order.ActualHandleOrgName,
- VisitTarget = EVisitTarget.Org
- };
- if (isReturn == false)
- {
- if (order is { FileOrgIsCenter: true, CounterSignType: null, IsProvince: false })
- {
- var satisfy = new Kv() { Key = "4", Value = "满意" };
- orgDetail.OrgProcessingResults = satisfy;
- //orgDetail.OrgHandledAttitude = satisfy;
- }
- if (order is { FileOrgIsCenter: true, CounterSignType: null })
- {
- seatDetail.VoiceEvaluate = EVoiceEvaluate.Satisfied;
- seatDetail.SeatEvaluate = ESeatEvaluate.Satisfied;
- order.Visited("4", "满意");
- order.Status = EOrderStatus.Visited;
- await _orderRepository.UpdateAsync(order, cancellationToken);
- }
- }
- visitedDetail.Add(orgDetail);
- visitedDetail.Add(seatDetail);
- await _orderVisitDetailRepository.AddRangeAsync(visitedDetail, cancellationToken);
- await _publisher.PublishAsync(new ContingencyManagementNotify(order, order.Title, order.Content, order.ActualOpinion),
- PublishStrategy.ParallelWhenAll, cancellationToken);
- //handle publish trace
- var acceptor = new UserInfo(orderPublish.CreatorId, orderPublish.CreatorName,
- orderPublish.CreatorOrgId, orderPublish.CreatorOrgName);
- var handler = new UserInfo(orderPublish.CreatorId, orderPublish.CreatorName,
- orderPublish.CreatorOrgId, orderPublish.CreatorOrgName);
- //上面回访人取值当前操作人,所以暂时可取值SessionContext,如需求有变需取值ordervisit中指定的回访人
- var visitAcceptor = string.IsNullOrEmpty(orderVisit.EmployeeId)
- ? new UserInfo()
- : new UserInfo(_sessionContext.UserId, _sessionContext.UserName, _sessionContext.OrgId,
- _sessionContext.OrgName, _sessionContext.OrgIsCenter);
- await _workflowDomainService.HandlePublishTraceAsync(order.WorkflowId, orderPublish.Id, acceptor, handler,
- orderPublish.CreationTime, visitAcceptor, orderVisit.Id, cancellationToken);
- //需求251 某些工单需自动发送短信
- //任何类型的省工单都不需要发送短信
- var isOpenSendEndSms = _systemSettingCacheManager.GetSetting(SettingConstants.IsOpenSendEndSms)?.SettingValue[0];
- if (isOpenSendEndSms == "true")
- {
- try
- {
- if (_appOptions.Value.IsZiGong)
- {
- if (order.Source == ESource.ProvinceStraight)
- {
- //发送查询短信
- var messageDto = new Share.Dtos.Push.MessageDto
- {
- PushBusiness = EPushBusiness.SearchSms,
- ExternalId = visitId,
- OrderId = order.Id,
- PushPlatform = EPushPlatform.Sms,
- Remark = order.Title,
- Name = order.FromName,
- TemplateCode = "1021",
- Params = new List<string>() { order.No, order.Password },
- TelNumber = order.Contact,
- };
- await _mediator.Publish(new PushMessageNotify(messageDto), cancellationToken);
- }
- }
- else
- {
- if (order.Source != ESource.ProvinceStraight && order.FileOrgIsCenter.Value == false)
- {
- var isOpenSendVisitSms = _systemSettingCacheManager.GetSetting(SettingConstants.IsOpenSendVisitSms)?.SettingValue[0];
- var code = "";
- //受理类型为“投诉、举报”
- if ((order.AcceptTypeCode == "30" || order.AcceptTypeCode == "35") && orderVisit.VisitState != EVisitState.Visited && isOpenSendVisitSms == "true")
- {
- code = "1017";
- orderVisit.VisitState = EVisitState.SMSVisiting;
- await _orderVisitRepository.UpdateAsync(orderVisit);
- }
- else
- code = "1018";
- //发送查询短信
- var messageDto = new Share.Dtos.Push.MessageDto
- {
- PushBusiness = EPushBusiness.SearchSms,
- ExternalId = visitId,
- OrderId = order.Id,
- PushPlatform = EPushPlatform.Sms,
- Remark = order.Title,
- Name = order.FromName,
- TemplateCode = code,
- Params = new List<string>() { order.No, order.Password },
- TelNumber = order.Contact,
- };
- await _mediator.Publish(new PushMessageNotify(messageDto), cancellationToken);
- // 发送短信后推送一个 48小时的延迟消息队列. 当消息队列收到消息时, 判断用户是否回复了, 如果未回复短信就 默认满意
- var delaySecond = _systemSettingCacheManager.DefaultVisitSmsDelaySecond;
- await _capPublisher.PublishDelayAsync(
- TimeSpan.FromSeconds(delaySecond),
- EventNames.UpdateVisitDelaySms,
- messageDto,
- cancellationToken: cancellationToken);
- }
- }
- }
- catch (Exception)
- {
- }
- }
- if (order.IsProvince == false && orderVisit.VisitState == EVisitState.Visited)
- {
- //推省上
- await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderVisited,
- new PublishVisitDto()
- {
- Order = order.Adapt<OrderDto>(),
- No = orderVisit.No,
- VisitType = orderVisit.VisitType,
- VisitName = orderVisit.CreatorName,
- VisitTime = orderVisit.VisitTime,
- VisitRemark = orderVisit.NowEvaluate?.Value,
- AreaCode = order.AreaCode!,
- SubjectResultSatifyCode = orderVisit.NowEvaluate?.Key,
- FirstSatisfactionCode = orderVisit.NowEvaluate?.Key,
- ClientGuid = ""
- }, cancellationToken: cancellationToken);
- }
- //推门户
- await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderVisitedWeb, new PublishVisitAllDto()
- {
- Id = orderVisit.Id,
- Order = order.Adapt<OrderDto>(),
- OrderVisitDetails = orderVisit.OrderVisitDetails.Adapt<List<VisitDetailDto>>(),
- VisitName = _sessionContext.UserName,
- VisitTime = orderVisit.VisitTime,
- VisitType = orderVisit.VisitType,
- VisitState = orderVisit.VisitState,
- PublishTime = orderVisit.PublishTime,
- }, cancellationToken: cancellationToken);
- }
- /// <summary>
- /// 重办和退回工单时如果有取消发布的工单, 清除回访待办和回访列表中的数据
- /// </summary>
- /// <param name="orderId"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- public async Task VisitNoneByCancelPublishAsync(string orderId, CancellationToken cancellationToken)
- {
- var cancelPublishOrderEnabled = _systemSettingCacheManager.CancelPublishOrderEnabled;
- // 取消发布的工单数量
- var orderPublishDeletedCount = await _orderPublishRepository.Queryable(includeDeleted: true)
- .Where(m => m.OrderId == orderId && m.IsDeleted == true)
- .CountAsync(cancellationToken);
- if (orderPublishDeletedCount == 0 || cancelPublishOrderEnabled == false) return;
- var visit = await _orderVisitRepository.GetAsync(x => x.OrderId == orderId && x.VisitState != EVisitState.None, cancellationToken);
- if (visit != null)
- {
- visit.VisitState = EVisitState.None;
- await _orderVisitRepository.UpdateAsync(visit, cancellationToken);
- }
- }
- public async Task<Order> GetOrderAsync(string? orderId, bool withHotspot = false, bool withAcceptor = false,
- bool withExtension = false, CancellationToken cancellationToken = default)
- {
- if (string.IsNullOrEmpty(orderId))
- throw UserFriendlyException.SameMessage("无效工单编号");
- var query = _orderRepository.Queryable().Includes(d => d.OrderPushTypes);
- if (withHotspot)
- query = query.Includes(d => d.Hotspot);
- if (withAcceptor)
- query = query.Includes(d => d.Acceptor);
- if (withExtension)
- query = query.Includes(d => d.OrderExtension);
- var order = await query.FirstAsync(d => d.Id == orderId, cancellationToken);
- if (order == null)
- throw new UserFriendlyException($"无效工单编号, orderId: {orderId}", "无效工单编号");
- return order;
- }
- public async Task<string> AddAsync(Order order, bool autoAccept = false, CancellationToken cancellationToken = default)
- {
- if (autoAccept)
- {
- order.AutoAccept(_sessionContext.RequiredUserId, _sessionContext.UserName, _sessionContext.StaffNo);
- order.Sign(_sessionContext.RequiredUserId, _sessionContext.UserName);
- }
- order.Init();
- order.No = GenerateNewOrderNo();
- if (order.Source == ESource.Police110)
- {
- order.Title = @"(非警情工单-" + order.No.Substring(order.No.Length - 6) + ")";
- }
- order.Password = Random.Shared.Next(100000, 1000000).ToString();
- order.ProvinceNo = string.IsNullOrEmpty(order.ProvinceNo) ? GenerateNewProvinceNo(order.No, order.SourceChannelCode) : order.ProvinceNo;
- return await _orderRepository.AddOrderNavAsync(order, cancellationToken);
- }
- /// <summary>
- /// 撤回或跳转前处理数据及校验
- /// <remarks>
- ///工单撤回时需校验工单当前是否存在待发布记录、待回访记录,若存在需删除对应记录(跳转同理)
- ///工单撤回时需校验工单是否存在甄别中记录,若存在不允许撤回当前工单(跳转同理)
- /// </remarks>
- /// </summary>
- public async Task ReadyToRecallAsync(string orderId, CancellationToken cancellationToken)
- {
- var order = await _orderRepository.Queryable()
- .Includes(d => d.OrderPublish)
- .Includes(d => d.OrderVisits.Where(d => d.VisitState == EVisitState.WaitForVisit))
- .Includes(d => d.OrderScreens)
- .FirstAsync(d => d.Id == orderId, cancellationToken);
- if (order.OrderScreens.Any())
- throw UserFriendlyException.SameMessage("已甄别工单无法撤回或跳转");
- //todo 需求调整:P72, 4,5,6,7,8,9,10
- if (order.OrderPublish is not null)
- await _orderPublishRepository.RemoveAsync(order.OrderPublish, cancellationToken: cancellationToken);
- if (order.OrderVisits.Any())
- await _orderVisitRepository.RemoveNav(order.OrderVisits)
- .Include(d => d.OrderVisitDetails)
- .ExecuteCommandAsync();
- }
- public Task<string> AddOrderRedoAsync(OrderRedo orderRedo, CancellationToken cancellationToken) =>
- _orderRedoRepository.AddAsync(orderRedo, cancellationToken);
- public Task RemoveOrderRedoAsync(string id, CancellationToken cancellationToken) =>
- _orderRedoRepository.RemoveAsync(id, cancellationToken: cancellationToken);
- public Task UpdateOrderRedoAsync(OrderRedo orderRedo, CancellationToken cancellationToken) =>
- _orderRedoRepository.UpdateAsync(orderRedo, cancellationToken);
- #region 工单扩展信息
- public async Task<OrderExtension?> GetOrderExtensionsAsync(string provinceNo, CancellationToken cancellationToken) =>
- await _orderExtensionRepository.GetAsync(d => d.ProvinceNo == provinceNo, cancellationToken);
- public Task UpdateExtensionAsync(OrderExtension orderExtension, CancellationToken cancellationToken) =>
- _orderExtensionRepository.UpdateAsync(orderExtension, cancellationToken);
- /// <summary>
- /// 新增工单扩展信息
- /// </summary>
- public async Task AddExtensionAsync(OrderExtension extension, CancellationToken cancellationToken) =>
- await _orderExtensionRepository.AddAsync(extension, cancellationToken);
- /// <summary>
- /// 新增工单补充信息
- /// </summary>
- public async Task<string> AddOrderComplementAsync(AddOrderComplementDto dto, CancellationToken cancellationToken)
- {
- var complement = _mapper.Map<OrderComplement>(dto);
- complement.InitId();
- if (dto.Files.Any()) complement.FileJson = await _fileRepository.AddFileAsync(dto.Files, complement.Id, "", cancellationToken);
- return await _orderComplementRepository.AddAsync(complement, cancellationToken);
- }
- #endregion
- /// <summary>
- /// 验证是否是管理员
- /// </summary>
- /// <returns></returns>
- public bool IsCheckAdmin()
- {
- var systemAdministrator = _systemSettingCacheManager.GetSetting(SettingConstants.SystemAdministrator)?.SettingValue[0];
- if (!string.IsNullOrEmpty(systemAdministrator) && (_sessionContext.Roles.Contains(systemAdministrator) || _sessionContext.Roles.Contains(RoleSeedData.AdminRole)))
- return true;
- else
- return false;
- }
- #region 平均派单
- /// <summary>
- /// 平均派单
- /// </summary>
- /// <returns></returns>
- public async Task<StepAssignInfo> AverageOrder(CancellationToken cancellationToken)
- {
- var time = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
- var scheduling = await _schedulingRepository.Queryable().Includes(x => x.SchedulingUser)
- .Where(x => x.SchedulingTime == time && x.WorkingTime <= DateTime.Now.TimeOfDay && x.OffDutyTime >= DateTime.Now.TimeOfDay && x.AtWork == true)
- .OrderBy(x => x.SendOrderNum).FirstAsync(cancellationToken);
- var centerOrgName = _systemSettingCacheManager.GetSetting(SettingConstants.CenterOrgName)?.SettingValue[0];
- var roleId = _systemSettingCacheManager.GetSetting(SettingConstants.RolePaiDan)?.SettingValue[0];
- if (scheduling is null)
- return new StepAssignInfo
- {
- Key = AppDefaults.SendPoolId,
- Value = "待派单池",
- UserId = AppDefaults.SendPoolId,
- Username = "待派单池",
- OrgId = OrgSeedData.CenterId,
- OrgName = centerOrgName,
- RoleId = roleId,
- RoleName = "派单员",
- FlowAssignType = EFlowAssignType.User,
- };
- scheduling.SendOrderNum++;
- await _schedulingRepository.UpdateAsync(scheduling, cancellationToken);
- var user = scheduling.SchedulingUser;
- return new StepAssignInfo
- {
- Key = user.UserId,
- Value = user.UserName,
- UserId = user.UserId,
- Username = user.UserName,
- OrgId = user.OrgId,
- OrgName = user.OrgIdName,
- RoleId = roleId,
- RoleName = "派单员",
- FlowAssignType = EFlowAssignType.User,
- };
- }
- /// <summary>
- /// 登录平均派单
- /// </summary>
- /// <param name="userId"></param>
- /// <returns></returns>
- public async Task LogAverageOrder(string userId, Scheduling scheduling, CancellationToken cancellationToken)
- {
- //1.获取默认派单员所属的工单
- //2.获取今天上班的人员
- //3.给当前这个用户平均派单
- var steps = await _workflowDomainService.GetStepsBelongsToAsync(AppDefaults.SendPoolId,
- cancellationToken);
- var roleId = _systemSettingCacheManager.GetSetting(SettingConstants.RolePaiDan)?.SettingValue[0];
- var user = await _userRepository.Queryable()
- .Includes(d => d.Organization)
- .FirstAsync(d => d.Id == userId, cancellationToken);
- var time = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
- var schedulings = await _schedulingRepository.Queryable().Includes(x => x.SchedulingUser)
- .Where(x => x.SchedulingTime == time).CountAsync(cancellationToken);
- if (schedulings > 0)
- {
- var sendNum = steps.Count / schedulings;
- scheduling.SendOrderNum += sendNum;
- if (!scheduling.LoginSendOrderNum.HasValue)
- {
- scheduling.LoginSendOrderNum = scheduling.LoginSendOrderNum.HasValue && scheduling.LoginSendOrderNum > sendNum ? scheduling.LoginSendOrderNum : sendNum;
- await _schedulingRepository.Updateable()
- .SetColumns(s => new Scheduling() { LoginSendOrderNum = scheduling.LoginSendOrderNum })
- .Where(s => s.SchedulingTime == scheduling.SchedulingTime).ExecuteCommandAsync(cancellationToken);
- }
- sendNum = scheduling.LoginSendOrderNum.Value;
- await _schedulingRepository.Updateable()
- .SetColumns(s => new Scheduling() { SendOrderNum = scheduling.SendOrderNum, AtWork = scheduling.AtWork })
- .Where(s => s.Id == scheduling.Id).ExecuteCommandAsync(cancellationToken);
- if (sendNum <= 0) return;
- var sendSteps = steps.Take(sendNum).ToList();
- await _orderRepository.Updateable().SetColumns(o => new Order()
- {
- CenterToOrgHandlerId = user.OrgId,
- CenterToOrgHandlerName = user.Name
- }).Where(o => sendSteps.Any(s => s.ExternalId == o.Id)).ExecuteCommandAsync(cancellationToken);
- await _workflowDomainService.ChangeHandlerBatchAsync(new List<(string userId, string username, string orgId, string orgName, string? roleId, string? roleName, ICollection<WorkflowStep> steps)>
- {
- new(user.Id, user.Name, user.OrgId, user.Organization.Name,roleId,"派单员", sendSteps)
- }, cancellationToken);
- }
- }
- /// <summary>
- /// 触发平均派单
- /// </summary>
- /// <returns></returns>
- public async Task TriggerAverageOrder(CancellationToken cancellationToken)
- {
- //1.从排班里面获取今天上班的人
- //2.获取默认派单员剩下的工单
- //3.平均分配剩下的工单给今天上班的人
- DateTime time = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
- var schedulings = await _schedulingRepository.Queryable().Includes(x => x.SchedulingUser)
- .Where(x => x.SchedulingTime!.Value == time && x.WorkingTime!.Value <= DateTime.Now.TimeOfDay && x.OffDutyTime!.Value >= DateTime.Now.TimeOfDay && x.AtWork == true)
- .OrderBy(x => x.SendOrderNum).ToListAsync(cancellationToken);
- var roleId = _systemSettingCacheManager.GetSetting(SettingConstants.RolePaiDan)?.SettingValue[0];
- if (schedulings.Any())
- {
- var steps = await _workflowDomainService.GetStepsBelongsToAsync(AppDefaults.SendPoolId,
- cancellationToken);
- if (steps.Any())
- {
- List<(string userId, string username, string orgId, string orgName, string? roleId, string? roleName, ICollection<WorkflowStep> steps)> handlers = new();
- var avg = steps.Count / schedulings.Count;
- var remaining = steps.Count % schedulings.Count;
- var skip = 0;
- for (var i = 0; i < schedulings.Count; i++)
- {
- var scheduling = schedulings[i];
- var size = avg + (i < remaining ? 1 : 0);
- if (size > 0)
- {
- var stSteps = steps.Skip(skip).Take(size).ToList();
- handlers.Add(new(
- scheduling.SchedulingUser.UserId,
- scheduling.SchedulingUser.UserName,
- scheduling.SchedulingUser.OrgId,
- scheduling.SchedulingUser.OrgIdName,
- roleId, "派单员",
- stSteps));
- skip += size;
- scheduling.SendOrderNum += size;
- await _schedulingRepository.Updateable()
- .SetColumns(s => new Scheduling() { SendOrderNum = scheduling.SendOrderNum })
- .Where(s => s.Id == scheduling.Id).ExecuteCommandAsync(cancellationToken);
- await _orderRepository.Updateable().SetColumns(o => new Order()
- {
- CenterToOrgHandlerId = scheduling.SchedulingUser.UserId,
- CenterToOrgHandlerName = scheduling.SchedulingUser.UserName
- })
- .Where(o => stSteps.Any(s => s.ExternalId == o.Id)).ExecuteCommandAsync(cancellationToken);
- }
- }
- if (handlers.Any())
- await _workflowDomainService.ChangeHandlerBatchAsync(handlers, cancellationToken);
- }
- }
- }
- #endregion
- #region 工单校验- 交通类工单
- /// <summary>
- /// 工单校验 - 交通类工单
- /// </summary>
- /// <returns></returns>
- public async Task<OrderValidation> OrderValidation(AddOrderDto dto, CancellationToken cancellationToken)
- {
- var valid = new OrderValidation { Validation = false, Result = "" };
- var hotspot = await _hotspotRepository.GetAsync(dto.HotspotId, cancellationToken);
- if (hotspot != null && hotspot.TrunkNum.Equals(AppDefaults.TrafficTrunkNum))
- {
- switch (dto.AcceptTypeCode)
- {
- //投诉举报
- case "30":
- case "35":
- valid.Validation = dto.Title.Contains("意见") || dto.Title.Contains("建议") || dto.Title.Contains("咨询")
- || dto.Content.Contains("意见") || dto.Content.Contains("建议") || dto.Content.Contains("咨询");
- if (dto.Content.Length < 25)
- {
- valid.Validation = true;
- valid.Result = "保存失败,受理内容字数不足,需要至少25个字!";
- }
- break;
- // 意见
- case "1":
- valid.Validation = dto.Title.Contains("投诉") || dto.Title.Contains("举报") || dto.Title.Contains("咨询")
- || dto.Content.Contains("投诉") || dto.Content.Contains("举报") || dto.Content.Contains("咨询");
- if (dto.Content.Length < 5)
- {
- valid.Validation = true;
- valid.Result = "保存失败,受理内容字数不足,需要至少5个字!";
- }
- break;
- //建议求助
- case "15":
- case "20":
- valid.Validation = dto.Title.Contains("投诉") || dto.Title.Contains("举报") || dto.Title.Contains("咨询")
- || dto.Content.Contains("投诉") || dto.Content.Contains("举报") || dto.Content.Contains("咨询");
- if (dto.Content.Length < 25)
- {
- valid.Validation = true;
- valid.Result = "保存失败,受理内容字数不足,需要至少25个字!";
- }
- break;
- // 咨询
- case "10":
- valid.Validation = dto.Title.Contains("投诉") || dto.Title.Contains("举报") || dto.Title.Contains("意见")
- || dto.Title.Contains("建议") || dto.Content.Contains("投诉") || dto.Content.Contains("举报") || dto.Content.Contains("意见") || dto.Content.Contains("建议");
- if (dto.Content.Length < 5)
- {
- valid.Validation = true;
- valid.Result = "保存失败,受理内容字数不足,需要至少5个字!";
- }
- break;
- // 表扬
- case "25":
- if (dto.Content.Length < 25)
- {
- valid.Validation = true;
- valid.Result = "保存失败,受理内容字数不足,需要至少25个字!";
- }
- break;
- default:
- if (dto.Content.Length < 5)
- {
- valid.Validation = true;
- valid.Result = "保存失败,受理内容字数不足,需要至少5个字!";
- }
- break;
- }
- }
- if (valid.Validation && string.IsNullOrEmpty(valid.Result))
- valid.Result = "标题或受理内容出现限制词,请检查!";
- return valid;
- }
- #endregion
- #region 即将超期和超期短信
- /// <summary>
- /// 即将超期和超期短信
- /// </summary>
- /// <returns></returns>
- public async Task SendOverTimeSms(CancellationToken cancellationToken)
- {
- var now = DateTime.Now;
- var isSend = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.IsSendOverTimeSms).SettingValue[0]);
- if (!isSend)
- {
- return;
- }
- //查询即将超期和超期工单
- var orderList = await _orderRepository.Queryable()
- .Where(x => x.Status < EOrderStatus.Filed && !string.IsNullOrEmpty(x.CurrentHandleOrgId))
- .GroupBy(x => x.CurrentHandleOrgId)
- .Select(x => new OverTimeOrderDto
- {
- OrgId = x.CurrentHandleOrgId,
- NearlyOrderCount = SqlFunc.AggregateSum(SqlFunc.IIF(now >= x.NearlyExpiredTime && now < x.ExpiredTime, 1, 0)),
- ExpiredTimeOrderCount = SqlFunc.AggregateSum(SqlFunc.IIF(x.ExpiredTime < now, 1, 0))
- })
- .ToListAsync(cancellationToken);
- foreach (var item in orderList)
- {
- if (item.NearlyOrderCount == 0 && item.ExpiredTimeOrderCount == 0)
- {
- continue;
- }
- var acceptSmsRoleIds = _systemSettingCacheManager.GetSetting(SettingConstants.AcceptSmsRoleIds)?.SettingValue;
- //查询部门所有账号
- var userlist = await _userRepository.Queryable().Where(x =>
- x.OrgId == item.OrgId && !string.IsNullOrEmpty(x.PhoneNo) &&
- x.Roles.Any(d => acceptSmsRoleIds.Contains(d.Id))).ToListAsync();
- //发送短信
- foreach (var user in userlist)
- {
- var messageDto = new Share.Dtos.Push.MessageDto
- {
- PushBusiness = EPushBusiness.OrderExpire,
- PushPlatform = EPushPlatform.Sms,
- Name = user.Name,
- TemplateCode = "1009",
- Params = new List<string>() { item.NearlyOrderCount.ToString(), item.ExpiredTimeOrderCount.ToString() },
- TelNumber = user.PhoneNo,
- };
- await _mediator.Publish(new PushMessageNotify(messageDto), cancellationToken);
- }
- }
- }
- #endregion
- #region 计算甄别申请截至日期
- public async Task<DateTime> GetScreenByEndTime()
- {
- var endTime = DateTime.Now;
- var beginTime = DateTime.Now;
- var timeValue = 1;
- if (_appOptions.Value.IsZiGong)
- {
- timeValue = 2;
- }
- else if (_appOptions.Value.IsLuZhou)
- {
- DateTime firstDayOfMonth = new DateTime(beginTime.Year, beginTime.Month, 1);
- DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);
- beginTime = new DateTime(lastDayOfMonth.Year, lastDayOfMonth.Month, lastDayOfMonth.Day, 23, 59, 59);
- }
- else
- {
- var setting = _systemSettingCacheManager.GetSetting(SettingConstants.ScreenApplyEndTime);
- if (int.Parse(setting?.SettingValue[0]) > 0)
- {
- timeValue = int.Parse(setting?.SettingValue[0]);
- }
- }
- endTime = (await _expireTime.CalcEndTime(beginTime, beginTime, ETimeType.WorkDay, timeValue, 0, 0)).EndTime;
- return endTime;
- }
- #endregion
- #region private
- private async Task<Order> GetOrderByFlowIdAsync(string workflowId, CancellationToken cancellationToken)
- {
- if (string.IsNullOrEmpty(workflowId))
- throw UserFriendlyException.SameMessage("无效流程编号");
- var order = await _orderRepository.Queryable()
- .Includes(d => d.Hotspot)
- .FirstAsync(d => d.WorkflowId == workflowId);
- if (order == null)
- throw new UserFriendlyException($"无效流程编号, workflowId: {workflowId}", "无效流程编号");
- return order;
- }
- private CacheOrderNO GetCurrentOrderNo()
- {
- var today = DateTime.Today;
- var cacheKey = today.ToString("yyyyMMdd");
- var cacheOrderNo = _cacheOrderNo.GetOrSet(cacheKey, f =>
- {
- var todayOrderCount = _orderRepository.Queryable(includeDeleted: true)
- .CountAsync(d => d.CreationTime.Date == today.Date)
- .GetAwaiter()
- .GetResult();
- return new CacheOrderNO { TotalCount = todayOrderCount };
- }, TimeSpan.FromDays(1));
- return cacheOrderNo;
- }
- public string GenerateNewOrderNo()
- {
- var today = DateTime.Today;
- var cacheKey = $"{today:yyyyMMdd}";
- var cacheOrderNo = _cacheOrderNo.GetOrSet(cacheKey, f =>
- {
- var todayOrderCount = _orderRepository.Queryable(true)
- .CountAsync(d => d.CreationTime.Date == today.Date)
- .GetAwaiter()
- .GetResult();
- return new CacheOrderNO { TotalCount = todayOrderCount };
- }, TimeSpan.FromDays(1));
- cacheOrderNo!.TotalCount += 1;
- var no = GenerateOrderNo(today, cacheOrderNo.TotalCount);
- _cacheOrderNo.Set(cacheKey, cacheOrderNo);
- return no;
- }
- private string GenerateNewProvinceNo(string no, string sourceChannelCode)
- {
- //诉求渠道+成员单位标识+行政区划代码+年月日+流水号
- //成员单位标识 99
- //宜宾市 511500 市级
- var today = DateTime.Today;
- //var count = no.Substring(no.Length - 5);
- var setting = _systemSettingCacheManager.GetSetting(SettingConstants.VersionsAreaCode);
- var versionsAreaCode = setting?.SettingValue[0];
- //todo 双系统并行暂时执行此方案
- var count = no.Substring(no.Length - 4);
- count = (Convert.ToInt32(count) + 50000).ToString();
- var provinceCodes = new[] { "RGDH", "WX", "WB", "AP", "WZ", "YJ", "SCZWFWW", "XCX", "QT" };
- var prefix = provinceCodes.Any(d => d.Equals(sourceChannelCode))
- ? sourceChannelCode
- : "QT";
- return $"{prefix}99{versionsAreaCode}{today:yyMMdd}{count}";
- }
- private string GenerateOrderNo(DateTime today, int count)
- {
- return $"{today:yyyyMMdd}{count:000000}";
- }
- /// <summary>
- /// 根据 OrderId 返回用户电话评价枚举
- /// 默认返回 默认满意
- /// </summary>
- /// <param name="orderId"></param>
- /// <returns></returns>
- private async Task<EVoiceEvaluate> GetReplyVoiceOrDefaultByOrderIdAsync(string orderId)
- {
- var callNative = await _callDomainService.GetByOrderIdAsync(orderId);
- if (callNative is null || callNative.ReplyTxt.IsNullOrEmpty())
- return EVoiceEvaluate.DefaultSatisfied;
- try
- {
- var smsReply = _orderVisitDomainService.GetVisitEvaluateByReplyTxt(callNative.ReplyTxt!.Trim());
- return smsReply!.VoiceEvaluate!.Value;
- }
- catch (UserFriendlyException)
- {
- return EVoiceEvaluate.DefaultSatisfied;
- }
- }
- #endregion
- }
- public class CacheOrderNO
- {
- public int TotalCount { get; set; }
- }
- public class OrderValidation
- {
- public bool Validation { get; set; }
- public string Result { get; set; }
- }
|