|
@@ -0,0 +1,287 @@
|
|
|
+using DotNetCore.CAP;
|
|
|
+using Hotline.Application.FlowEngine;
|
|
|
+using Hotline.File;
|
|
|
+using Hotline.FlowEngine.Workflows;
|
|
|
+using Hotline.Orders;
|
|
|
+using Hotline.Repository.SqlSugar.Orders;
|
|
|
+using Hotline.Settings.TimeLimits;
|
|
|
+using Hotline.Share.Dtos;
|
|
|
+using Hotline.Share.Dtos.FlowEngine;
|
|
|
+using Hotline.Share.Dtos.Order;
|
|
|
+using Hotline.Share.Enums.Order;
|
|
|
+using MapsterMapper;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using SqlSugar;
|
|
|
+using System.Threading;
|
|
|
+using Hotline.Repository.SqlSugar.Extensions;
|
|
|
+using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Dependency;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+using XF.Domain.Repository;
|
|
|
+
|
|
|
+namespace Hotline.Application.Orders
|
|
|
+{
|
|
|
+ public class OrderSecondaryHandlingApplication : IOrderSecondaryHandlingApplication, IScopeDependency
|
|
|
+ {
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly IRepository<OrderSecondaryHandling> _orderSecondaryHandlingRepository;
|
|
|
+ private readonly IFileRepository _fileRepository;
|
|
|
+ private readonly IRepository<OrderVisit> _orderVisitRepository;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly IOrderRepository _orderRepository;
|
|
|
+ private readonly ITimeLimitDomainService _timeLimitDomainService;
|
|
|
+ private readonly ICapPublisher _capPublisher;
|
|
|
+ private readonly IWorkflowApplication _workflowApplication;
|
|
|
+ private readonly IRepository<OrderPublish> _orderPublishRepository;
|
|
|
+ private readonly IRepository<OrderPublishHistory> _orderPublishHistoryRepository;
|
|
|
+ private readonly IWorkflowDomainService _workflowDomainService;
|
|
|
+ private readonly IRepository<OrderVisitDetail> _orderVisitedDetailRepository;
|
|
|
+
|
|
|
+ public OrderSecondaryHandlingApplication(
|
|
|
+ IMapper mapper,
|
|
|
+ IRepository<OrderSecondaryHandling> orderSecondaryHandlingRepository,
|
|
|
+ IFileRepository fileRepository,
|
|
|
+ IRepository<OrderVisit> orderVisitRepository,
|
|
|
+ ISessionContext sessionContext,
|
|
|
+ IOrderRepository orderRepository,
|
|
|
+ ITimeLimitDomainService timeLimitDomainService,
|
|
|
+ ICapPublisher capPublisher,
|
|
|
+ IWorkflowApplication workflowApplication,
|
|
|
+ IRepository<OrderPublish> orderPublishRepository,
|
|
|
+ IRepository<OrderPublishHistory> orderPublishHistoryRepository,
|
|
|
+ IWorkflowDomainService workflowDomainService,
|
|
|
+ IRepository<OrderVisitDetail> orderVisitedDetailRepository
|
|
|
+ ) {
|
|
|
+ _mapper = mapper;
|
|
|
+ _orderSecondaryHandlingRepository = orderSecondaryHandlingRepository;
|
|
|
+ _fileRepository = fileRepository;
|
|
|
+ _orderVisitRepository = orderVisitRepository;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ _orderRepository = orderRepository;
|
|
|
+ _timeLimitDomainService = timeLimitDomainService;
|
|
|
+ _capPublisher = capPublisher;
|
|
|
+ _workflowApplication = workflowApplication;
|
|
|
+ _orderPublishRepository = orderPublishRepository;
|
|
|
+ _orderPublishHistoryRepository = orderPublishHistoryRepository;
|
|
|
+ _workflowDomainService = workflowDomainService;
|
|
|
+ _orderVisitedDetailRepository = orderVisitedDetailRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 二次办理新增
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task AddAsync(AddOrderSecondaryHandlingDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var model = _mapper.Map<OrderSecondaryHandling>(dto);
|
|
|
+ if (string.IsNullOrEmpty(dto.Id))
|
|
|
+ {
|
|
|
+ model.InitId();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ model = await _orderSecondaryHandlingRepository.GetAsync(dto.Id , cancellationToken);
|
|
|
+ model.Content = dto.Content;
|
|
|
+ }
|
|
|
+ model.State = ESecondaryHandlingState.Apply;
|
|
|
+ model.ApplyOrgId = _sessionContext.OrgId;
|
|
|
+ model.ApplyOrgName = _sessionContext.OrgName;
|
|
|
+
|
|
|
+ if (dto.Files.Any())
|
|
|
+ model.FileJson = await _fileRepository.AddFileAsync(dto.Files, model.Id, "", cancellationToken);
|
|
|
+
|
|
|
+ var visit = await _orderVisitRepository.GetAsync(x => x.Id == dto.VisitId && x.VisitState != EVisitState.None, cancellationToken);
|
|
|
+ if (visit != null)
|
|
|
+ {
|
|
|
+ model.VisitState = visit.VisitState;
|
|
|
+ visit.VisitState = EVisitState.None;
|
|
|
+ await _orderVisitRepository.UpdateAsync(visit, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(dto.Id))
|
|
|
+ {
|
|
|
+ await _orderSecondaryHandlingRepository.UpdateAsync(model, cancellationToken);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ await _orderSecondaryHandlingRepository.AddAsync(model, cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task SendBackAsync(SendBackOrderSecondaryHandlingDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var model =await _orderSecondaryHandlingRepository.GetAsync(dto.Id, cancellationToken);
|
|
|
+ model.State = ESecondaryHandlingState.NotApply;
|
|
|
+ model.SendBackContent = dto.SendBackContent;
|
|
|
+ await _orderSecondaryHandlingRepository.UpdateAsync(model, cancellationToken);
|
|
|
+ var visit = await _orderVisitRepository.GetAsync(x => x.Id == model.VisitId , cancellationToken);
|
|
|
+ if (visit != null)
|
|
|
+ {
|
|
|
+ visit.VisitState = model.VisitState;
|
|
|
+ await _orderVisitRepository.UpdateAsync(visit, cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 二次办理审批
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task AuditAsync(AuditOrderSecondaryHandlingDto dto, OrderSecondaryHandling model, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+
|
|
|
+ model.State = dto.State;
|
|
|
+ model.AuditContent = dto.AuditContent;
|
|
|
+ model.AuditId = _sessionContext.UserId;
|
|
|
+ model.AuditUser = _sessionContext.UserName;
|
|
|
+ model.AuditTime = DateTime.Now;
|
|
|
+ if (model.State == ESecondaryHandlingState.End)
|
|
|
+ {
|
|
|
+ var order = await _orderRepository.GetAsync(x => x.Id == model.OrderId, cancellationToken);
|
|
|
+ if (string.IsNullOrEmpty(order.WorkflowId))
|
|
|
+ throw UserFriendlyException.SameMessage("无效二次办理审批信息,没有找到对应流程信息!");
|
|
|
+ var step = await _workflowDomainService.FindLastHandleStepAsync(order.WorkflowId, model.ApplyOrgId, cancellationToken);
|
|
|
+ if (step == null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效二次办理审批信息,没有找到对应流程节点!");
|
|
|
+ var recall = new RecallDto
|
|
|
+ {
|
|
|
+ WorkflowId = order.WorkflowId!,
|
|
|
+ NextStepCode = step.Code,
|
|
|
+ NextStepName = step.Name,
|
|
|
+ NextHandlers = step.Handlers,
|
|
|
+ Opinion = dto.AuditContent,
|
|
|
+ FlowDirection = Share.Enums.FlowEngine.EFlowDirection.CenterToOrg,
|
|
|
+ HandlerType = step.HandlerType,
|
|
|
+ BusinessType = step.BusinessType
|
|
|
+ };
|
|
|
+ var expiredTime = _timeLimitDomainService.CalcEndTime(DateTime.Now, order.AcceptTypeCode);
|
|
|
+ await _orderRepository.Updateable().SetColumns(o => new Order() { ExpiredTime = expiredTime.ExpiredTime, NearlyExpiredTime = expiredTime.NearlyExpiredTime })
|
|
|
+ .Where(o => o.Id == order.Id).ExecuteCommandAsync(cancellationToken);
|
|
|
+ var orderDto = _mapper.Map<OrderDto>(order);
|
|
|
+ await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderExpiredTimeUpdate, orderDto, cancellationToken: cancellationToken);
|
|
|
+
|
|
|
+ await _workflowApplication.RecallAsync(recall, expiredTime.ExpiredTime, cancellationToken);
|
|
|
+ var publish = await _orderPublishRepository.GetAsync(x => x.OrderId == model.OrderId);
|
|
|
+ if (publish != null)
|
|
|
+ {
|
|
|
+ var publishHistory = _mapper.Map<OrderPublishHistory>(publish);
|
|
|
+ publishHistory.OrderPublishId = publish.Id;
|
|
|
+ publishHistory.ArrangeTitleAfter = publish.ArrangeTitle;
|
|
|
+ publishHistory.ArrangeTitleBefor = publish.ArrangeTitle;
|
|
|
+ publishHistory.ArrangeContentAfter = publish.ArrangeContent;
|
|
|
+ publishHistory.ArrangeContentBefor = publish.ArrangeContent;
|
|
|
+ publishHistory.ArrangeOpinionAfter = publish.ArrangeOpinion;
|
|
|
+ publishHistory.ArrangeOpinionBefor = publish.ArrangeOpinion;
|
|
|
+ await _orderPublishHistoryRepository.AddAsync(publishHistory, cancellationToken);
|
|
|
+ await _orderPublishRepository.RemoveAsync(publish, false, cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var visit = await _orderVisitRepository.GetAsync(x => x.OrderId == model.OrderId, cancellationToken);
|
|
|
+ visit.VisitState = model.VisitState;
|
|
|
+ await _orderVisitRepository.UpdateAsync(visit, cancellationToken);
|
|
|
+ }
|
|
|
+ await _orderSecondaryHandlingRepository.UpdateAsync(model, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取申请列表
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public ISugarQueryable<OrderVisitDetail> ApplyQuery(MayScreenListDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ dto.CreationTimeEnd = DateTime.Now;
|
|
|
+ dto.CreationTimeStart = DateTime.Now;
|
|
|
+ if (dto.IsHomePage != null && dto.IsHomePage == true)
|
|
|
+ {
|
|
|
+ dto.CreationTimeStart = _timeLimitDomainService.CalcWorkTimeReduce(DateTime.Now, 5);
|
|
|
+ }
|
|
|
+
|
|
|
+ var query = _orderVisitedDetailRepository.Queryable(false, true)
|
|
|
+ .Includes(x => x.OrderVisit)
|
|
|
+ .Includes(x => x.OrderVisit, y => y.Order)
|
|
|
+ .Includes(x => x.OrderVisit, y => y.Employee)
|
|
|
+ .Includes(x=>x.SecondaryHandling)
|
|
|
+ .LeftJoin<OrderScreen>((x, s) => x.Id == s.VisitDetailId && s.Status < EScreenStatus.End && s.IsDeleted == false)
|
|
|
+ .Where((x, s) => s.Id == null && (x.SecondaryHandling.State == ESecondaryHandlingState.NotApply || x.SecondaryHandling.Id == null))
|
|
|
+ .WhereIF(dto.IsHomePage.HasValue && dto.IsHomePage == true, x => x.OrderVisit.VisitTime < dto.CreationTimeEnd && x.OrderVisit.VisitTime > dto.CreationTimeStart)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.No), x => x.OrderVisit.Order!.No!.Contains(dto.No!))
|
|
|
+ .WhereIF(dto.IsProvince.HasValue, x => x.OrderVisit.Order!.IsProvince == dto.IsProvince)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.Title), x => x.OrderVisit.Order!.Title!.Contains(dto.Title!))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.SourceChannel), x => x.OrderVisit.Order!.SourceChannelCode! == dto.SourceChannel!)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.AcceptType), x => x.OrderVisit.Order!.AcceptTypeCode! == dto.AcceptType!)
|
|
|
+ .WhereIF(dto.CounterSignType.HasValue, x => x.OrderVisit.Order!.CounterSignType == dto.CounterSignType)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.OrgLevelOneName), x => x.OrderVisit.Order!.OrgLevelOneName!.Contains(dto.OrgLevelOneName!))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.ActualHandleOrgName), x => x.OrderVisit.Order!.ActualHandleOrgName!.Contains(dto.ActualHandleOrgName!))
|
|
|
+ .WhereIF(dto.ActualHandleTime.HasValue && dto.EndActualHandleTime.HasValue, x => x.OrderVisit.Order!.ActualHandleTime >= dto.ActualHandleTime && x.OrderVisit.Order!.ActualHandleTime <= dto.EndActualHandleTime)
|
|
|
+ .WhereIF(dto.FiledTime.HasValue && dto.EndFiledTime.HasValue, x => x.OrderVisit.Order!.FiledTime == dto.FiledTime && x.OrderVisit.Order!.FiledTime <= dto.EndFiledTime)
|
|
|
+ .WhereIF(dto.CreationTime.HasValue && dto.EndCreationTime.HasValue, x => x.OrderVisit.Order!.CreationTime == dto.CreationTime && x.OrderVisit.Order!.CreationTime <= dto.EndCreationTime)
|
|
|
+ .WhereIF(dto.VisitTime.HasValue && dto.EndVisitTime.HasValue, x => x.OrderVisit.VisitTime == dto.VisitTime && x.OrderVisit.VisitTime <= dto.EndVisitTime)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.VisitOrgName), x => x.VisitOrgName!.Contains(dto.VisitOrgName!))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.OrgProcessingResults), x => SqlFunc.JsonField(x.OrgProcessingResults, "Key") == dto.OrgProcessingResults)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.OrgHandledAttitude), x => SqlFunc.JsonListObjectAny(x.OrgHandledAttitude, "Key", dto.OrgHandledAttitude))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.OrgNoSatisfiedReason), x => SqlFunc.JsonField(x.OrgNoSatisfiedReason, "Key") == dto.OrgNoSatisfiedReason)
|
|
|
+ .Where((x, s) => x.OrderVisit.VisitState != EVisitState.None && x.OrderVisit.IsCanHandle);
|
|
|
+ if (_sessionContext.OrgId != null && !_sessionContext.OrgIsCenter)
|
|
|
+ {
|
|
|
+ query.WhereIF(!string.IsNullOrEmpty(dto.Keyword),
|
|
|
+ (x, s) => x.OrderVisit.Order.Title.Contains(dto.Keyword!) ||
|
|
|
+ x.OrderVisit.Order.No.Contains(dto.Keyword!))
|
|
|
+ .Where((x, s) => x.VisitTarget == EVisitTarget.Org && x.VisitOrgCode.StartsWith(_sessionContext.OrgId) && (
|
|
|
+ SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "1" ||
|
|
|
+ SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2" ||
|
|
|
+ SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "1" ||
|
|
|
+ SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "2"
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ query.WhereIF(!string.IsNullOrEmpty(dto.Keyword),
|
|
|
+ (x, s) => x.OrderVisit.Order.Title.Contains(dto.Keyword!) ||
|
|
|
+ x.OrderVisit.Order.No.Contains(dto.Keyword!))
|
|
|
+ .Where((x, s) => x.VisitTarget == EVisitTarget.Org && (
|
|
|
+ SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "1" ||
|
|
|
+ SqlFunc.JsonField(x.OrgProcessingResults, "Key") == "2" ||
|
|
|
+ SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "1" ||
|
|
|
+ SqlFunc.JsonField(x.OrgHandledAttitude, "Key") == "2"
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ return query.OrderByDescending((x, s) => x.CreationTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 二次办理列表查询
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public ISugarQueryable<OrderSecondaryHandling> Query(SecondaryHandlingListDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return _orderSecondaryHandlingRepository.Queryable()
|
|
|
+ .Includes(x => x.Order)
|
|
|
+ .Includes(x => x.VisitDetail)
|
|
|
+ .Includes(x => x.Visit, d => d.Order)
|
|
|
+ .Where(x=>x.State> ESecondaryHandlingState.NotApply)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.Keyword),
|
|
|
+ x => x.Visit.Order.Title.Contains(dto.Keyword!) || x.Visit.Order.No.Contains(dto.Keyword!))
|
|
|
+ .WhereIF(dto.Status is ESecondaryHandlingState.Apply, x => x.State == ESecondaryHandlingState.Apply)
|
|
|
+ .WhereIF(dto.Status is ESecondaryHandlingState.Handled, x => x.State != ESecondaryHandlingState.Apply)
|
|
|
+ .WhereIF(dto.Status is ESecondaryHandlingState.End, x => x.State == ESecondaryHandlingState.End)
|
|
|
+ .WhereIF(dto.Status is ESecondaryHandlingState.Refuse, x => x.State == ESecondaryHandlingState.Refuse)
|
|
|
+ .WhereIF(dto.CreationTimeStart.HasValue, x => x.CreationTime >= dto.CreationTimeStart)
|
|
|
+ .WhereIF(dto.CreationTimeEnd.HasValue, x => x.CreationTime <= dto.CreationTimeEnd)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.OrderId), x => x.OrderId == dto.OrderId)
|
|
|
+ .OrderByDescending(x => x.CreationTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取实体
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<OrderSecondaryHandling> Entity(string id, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ return await _orderSecondaryHandlingRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.Id == id, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|