From da05ffac25b38e4654fbe5d0e9c064b3970a0254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Wed, 18 Sep 2024 15:05:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=AE=A1=E6=A0=B8=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Constants/MultiLanguageConst.cs | 2 + .../DS.Module.Core/Data/DataResult.cs | 1 - .../Flow/Method/FlowInstanceService.cs | 57 ++++++++++---- .../DS.WMS.Core/Flow/Method/FlowRuntime.cs | 27 +++++-- .../Op/Method/TaskInteraction/TaskService.cs | 77 ++++++++++++------- .../Method/InvoiceSettlementService.cs | 5 +- .../DS.WMS.FeeApi/DS.WMS.FeeApi.csproj.user | 6 +- 7 files changed, 117 insertions(+), 58 deletions(-) diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index d61fb392..2bfabc88 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -1529,6 +1529,8 @@ public static class MultiLanguageConst public const string TaskMailReceiverNotNull = "Task_Mail_Receiver_Not_Null"; [Description("任务邮件必须设置发件人")] public const string TaskMailSenderNotNull = "Task_Mail_Sender_Not_Null"; + [Description("驳回成功")] + public const string TaskRejected = "Task_Rejected"; #endregion #region 任务台相关 diff --git a/ds-wms-service/DS.Module.Core/Data/DataResult.cs b/ds-wms-service/DS.Module.Core/Data/DataResult.cs index 5329dc63..92bd0c1b 100644 --- a/ds-wms-service/DS.Module.Core/Data/DataResult.cs +++ b/ds-wms-service/DS.Module.Core/Data/DataResult.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using System.Net.Http; using System.Reflection; using DS.Module.Core.Data; using DS.Module.Core.Extensions; diff --git a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs index 04d775f7..9f3ae038 100644 --- a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs +++ b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs @@ -127,8 +127,45 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService if (instance == null) return DataResult.Failed("该流程模板已不存在,请重新设计流程!", MultiLanguageConst.FlowTemplateNotExist); + var userName = Db.Queryable().Where(x => x.Id == long.Parse(User.UserId)).Select(x => x.UserName).First(); + //创建运行实例 var runtime = CreateRuntimeService(instance); + if (runtime.ShouldSkip) + { + instance.FlowStatus = FlowStatusEnum.Approve; + instance.Note = "已设置为自动跳过工作流执行"; + Db.Insertable(instance).ExecuteCommand(); + + var history1 = new FlowInstanceHistory + { + InstanceId = instance.Id, + Content = "【创建】" + + userName + + "创建了一个流程进程【" + + instance.CustomName + "】", + UserName = userName + }; + + var history2 = new FlowInstanceHistory + { + InstanceId = instance.Id, + Content = "【审核】" + + userName + + "流程条件触发自动审核【" + + instance.CustomName + "】", + UserName = userName + }; + + FlowInstanceHistory[] histories = [history1, history2]; + Db.Insertable(histories).ExecuteCommand(); + + if (!string.IsNullOrEmpty(instance.CallbackURL)) + Task.Factory.StartNew(() => RunCallbackAsync(instance)); + + var result = DataResult.Successed("创建工作流实例成功!", instance, MultiLanguageConst.FlowInstanceCreateSuccess); + return result; + } if (runtime.CurrentNode is { AssigneeType: "user", Users.Count: > 0 }) { @@ -158,8 +195,6 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService instance.MakerList = GetCurrentMakers(runtime); instance.FlowStatus = FlowStatusEnum.Ready; - runtime.FlowInstanceId = instance.Id; - #endregion 根据运行实例改变当前节点状态 Db.Insertable(instance).ExecuteCommand(); @@ -170,22 +205,18 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService Task.Factory.StartNew(() => RunCallbackAsync(instance)); } - var userInfo = Db.Queryable().First(x => x.Id == long.Parse(User.UserId)); + var history = new FlowInstanceHistory { InstanceId = instance.Id, Content = "【创建】" - + userInfo.UserName + + userName + "创建了一个流程进程【" + instance.CustomName + "】", - UserName = userInfo.UserName + UserName = userName }; Db.Insertable(history).ExecuteCommand(); - // var info = db.Queryable().Where(x => x.Id == req.Id).First(); - // - // info = req.Adapt(info); - // - // db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); + return DataResult.Successed("创建工作流实例成功!", instance, MultiLanguageConst.FlowInstanceCreateSuccess); } @@ -219,11 +250,9 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService instance.ActivityId = startNodeId; instance.ActivityType = wfruntime.GetNodeType(startNodeId); instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name; - instance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1"); + instance.MakerList = wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1"; instance.FlowStatus = FlowStatusEnum.Draft; - wfruntime.FlowInstanceId = instance.Id; - #endregion 根据运行实例改变当前节点状态 var serializerSettings = new JsonSerializerSettings { @@ -289,8 +318,6 @@ public class FlowInstanceService : ServiceBase, IFlowInstanceService instance.MakerList = wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1"; instance.FlowStatus = (wfruntime.GetNextNodeType() == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running); - wfruntime.FlowInstanceId = instance.Id; - #endregion 根据运行实例改变当前节点状态 Db.Updateable(instance).ExecuteCommand(); diff --git a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntime.cs b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntime.cs index ff5d0809..7d26ba87 100644 --- a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntime.cs +++ b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntime.cs @@ -33,7 +33,6 @@ public class FlowRuntime CurrentNodeId = instance.ActivityId == "" ? StartNodeId : instance.ActivityId; CurrentNodeType = GetNodeType(CurrentNodeId); PreviousId = instance.PreviousId; - FlowInstanceId = instance.Id; //会签开始节点和流程结束节点没有下一步 if (CurrentNodeType == 0 || CurrentNodeType == 4) @@ -49,7 +48,15 @@ public class FlowRuntime else { NextNodeId = GetNextNodeId(CurrentNodeId); //下一个节点 - NextNodeType = GetNodeType(NextNodeId); + if (string.IsNullOrEmpty(NextNodeId) && CurrentNodeType == 3) + { + //当前节点类型为开始节点,且没有下一级节点,则认为应跳出工作流 + ShouldSkip = true; + } + else + { + NextNodeType = GetNodeType(NextNodeId); + } } } @@ -61,9 +68,14 @@ public class FlowRuntime IUser user { get; set; } /// - /// 运行实例的Id + /// 是否应跳过工作流执行 /// - public long FlowInstanceId { get; set; } + public bool ShouldSkip { get; private set; } + + ///// + ///// 运行实例的Id + ///// + //public long FlowInstanceId { get; set; } /// /// 开始节点的ID @@ -209,7 +221,6 @@ public class FlowRuntime { return ChildNodes.Where(x => x.Id == "end").First().Id; } - // return ChildNodes.Where(x => x.Pid == nodeId).First().Id; } } @@ -218,7 +229,7 @@ public class FlowRuntime /// /// /// - public string GetNextConditionNodeId(FlowChild parent) + public string? GetNextConditionNodeId(FlowChild parent) { var conditionNodes = GetFlowConditions(parent); var conditionId = string.Empty; @@ -226,7 +237,6 @@ public class FlowRuntime { if (i == conditionNodes.Count - 1) { - // return ChildNodes.Where(x => x.Pid == conditionNodes[i].Id).First().Id; conditionId = conditionNodes[i].Id; } else @@ -301,7 +311,8 @@ public class FlowRuntime } } - return ChildNodes.Where(x => x.Pid == conditionId).FirstOrDefault()?.Id; + var node = ChildNodes.Find(x => x.Pid == conditionId); + return node?.Id; } /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs index dc1a0520..16873390 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskService.cs @@ -410,22 +410,36 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction if (result.Succeeded) { var instance = result.Data as FlowInstance; - task.FlowId = instance.Id; + task.FlowId = instance!.Id; await TenantDb.Updateable(task).UpdateColumns(x => x.FlowId).ExecuteCommandAsync(); - result = FlowService.Value.StartFlowInstance(instance.Id.ToString()); - instance = result.Data as FlowInstance; - - if (result.Succeeded && changeMarker) + if (instance.FlowStatus == FlowStatusEnum.Approve) { - string[] ids = FlowInstanceService.GetMarkers(instance); - //变更任务接收人为所有审批执行人 - var users = await FillInUserInfoAsync(ids.Select(long.Parse).ToArray()); - result = await ManagerService.TransferTask(task.BusinessId, task.TaskType, users, TenantDb); - if (result.Succeeded) + await SetTaskStatusAsync(new TaskUpdateRequest + { + BusinessId = task.BusinessId, + BusinessType = task.BusinessType, + RejectReason = instance.Note, + TaskTypeName = task.TaskType.ToString(), + TaskStatus = TaskStatusEnum.Complete + }, false); + } + else + { + result = FlowService.Value.StartFlowInstance(instance.Id.ToString()); + instance = result.Data as FlowInstance; + + if (result.Succeeded && changeMarker) { - task.RecvUsers = string.Join(",", ids); - await TenantDb.Updateable(task).UpdateColumns(x => x.RecvUsers).ExecuteCommandAsync(); + string[] ids = FlowInstanceService.GetMarkers(instance); + //变更任务接收人为所有审批执行人 + var users = await FillInUserInfoAsync(ids.Select(long.Parse).ToArray()); + result = await ManagerService.TransferTask(task.BusinessId, task.TaskType, users, TenantDb); + if (result.Succeeded) + { + task.RecvUsers = string.Join(",", ids); + await TenantDb.Updateable(task).UpdateColumns(x => x.RecvUsers).ExecuteCommandAsync(); + } } } @@ -774,25 +788,30 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction Instance = instance }); - if (result.Succeeded) + if (!result.Succeeded) + return result; + + var req = new TaskUpdateRequest { - var req = new TaskUpdateRequest - { - BusinessId = instance.BusinessId, - BusinessType = instance.BusinessType, - RejectReason = request.Remark, - TaskTypeName = request.TaskType.ToString(), - TaskStatus = request.Result == 1 ? TaskStatusEnum.Complete : TaskStatusEnum.Pending, - AutoCreateNext = true - }; - //根据审批结果更新任务状态 - await SetTaskStatusAsync(req); + BusinessId = instance.BusinessId, + BusinessType = instance.BusinessType, + RejectReason = request.Remark, + TaskTypeName = request.TaskType.ToString(), + TaskStatus = request.Result == 1 ? TaskStatusEnum.Complete : TaskStatusEnum.Pending, + AutoCreateNext = true + }; + //根据审批结果更新任务状态 + await SetTaskStatusAsync(req); + if (instance.FlowStatus == FlowStatusEnum.Approve) + { //终审通过且任务类型为审单,则生成费用 - if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT && instance.FlowStatus == FlowStatusEnum.Approve && instance.IsCompleted) + if (request.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT && instance.IsCompleted) { - UriBuilder builder = new UriBuilder(configuration["FeeService:BaseUrl"]); - builder.Path = configuration["FeeService:GenerateFees"]; + UriBuilder builder = new(configuration["FeeService:BaseUrl"]) + { + Path = configuration["FeeService:GenerateFees"] + }; string url = builder.ToString(); if (string.IsNullOrEmpty(url)) { @@ -808,6 +827,10 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction Api.SendRequestAsync(HttpMethod.Post, url, json); } } + else if (instance.FlowStatus == FlowStatusEnum.Reject) + { + result.Message = MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.TaskRejected)); + } if (IsOrderType(request.TaskType)) result.Data = new { instance.IsCompleted, instance.FlowStatus }; diff --git a/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs b/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs index 2c7dfd4e..a4c06d5d 100644 --- a/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs +++ b/ds-wms-service/DS.WMS.Core/Settlement/Method/InvoiceSettlementService.cs @@ -2,7 +2,6 @@ using DS.Module.Core.Extensions; using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Application.Entity; -using DS.WMS.Core.Code.Entity; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Settlement.Entity; @@ -35,8 +34,10 @@ namespace DS.WMS.Core.Settlement.Method var result = await TenantDb.Queryable() .InnerJoin((a, d) => a.Id == d.ApplicationId && d.OriginalAmount - d.OriginalProcessedAmount != 0) .InnerJoin((a, d, f) => d.RecordId == f.Id && - (f.Amount > 0 && d.OriginalAmount - d.OriginalSettlementAmount <= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) || + ((f.Amount > 0 && d.OriginalAmount - d.OriginalSettlementAmount <= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) || (f.Amount < 0 && d.OriginalAmount - d.OriginalSettlementAmount >= f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount)) + ) + .GroupBy((a, d, f) => a.Id) .Select((a, d, f) => new InvoiceApplicationDto { diff --git a/ds-wms-service/DS.WMS.FeeApi/DS.WMS.FeeApi.csproj.user b/ds-wms-service/DS.WMS.FeeApi/DS.WMS.FeeApi.csproj.user index fca00097..fb7be066 100644 --- a/ds-wms-service/DS.WMS.FeeApi/DS.WMS.FeeApi.csproj.user +++ b/ds-wms-service/DS.WMS.FeeApi/DS.WMS.FeeApi.csproj.user @@ -1,11 +1,7 @@  - - ProjectDebugger - - http - D:\Source\Repos\DS8\ds-wms-service\DS.WMS.FeeApi\Properties\PublishProfiles\FolderProfile1.pubxml + D:\Source\Repos\DS8\ds-wms-service\DS.WMS.OpApi\Properties\PublishProfiles\FolderProfile.pubxml MvcControllerEmptyScaffolder root/Common/MVC/Controller