From bb89b21bd9b6d50662c98f8c9afd01d09a6c6312 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Tue, 24 Sep 2024 10:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=EF=BC=9A?= =?UTF-8?q?=E9=A2=86=E5=8F=96=E4=BB=BB=E5=8A=A1=E5=88=B0=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E7=99=BB=E9=99=86=E4=BA=BA(=E5=8F=AF=E6=89=B9=E9=87=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskPlat/Interface/ITaskManageService.cs | 5 + .../TaskPlat/Method/TaskManageBaseService.cs | 7 +- .../TaskPlat/Method/TaskManageService.cs | 122 ++++++++++++++++-- .../Controllers/TaskManageController.cs | 9 ++ .../DS.WMS.Test/SaasDBUpdateTest.cs | 4 +- 5 files changed, 130 insertions(+), 17 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs index 95c0de54..7f96b1eb 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs @@ -79,5 +79,10 @@ namespace DS.WMS.Core.TaskPlat.Interface /// 测试用 /// Task TestTaskFlow(string taskType, long taskId, int testType); + + /// + /// 领取任务到当前登陆人(可批量) + /// + Task PullTask(long[] ids); } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs index 8789639a..6b90daeb 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageBaseService.cs @@ -148,7 +148,6 @@ namespace DS.WMS.Core.TaskPlat.Method } // 用于更新工作流的任务 var userIdStr = string.Join(',', userInfo.Select(x => x.RecvUserId)); - var businessIdList = taskList.Where(x => x.OUT_BS_NO != null && x.OUT_BS_NO != 0).Select(x => x.OUT_BS_NO).Distinct().ToList(); //await tenantDb.Ado.BeginTranAsync(); await tenantDb.AsTenant().BeginTranAsync(); @@ -171,17 +170,17 @@ namespace DS.WMS.Core.TaskPlat.Method .Where(x => x.BusinessId == item.OUT_BS_NO && x.TaskType == (TaskBaseTypeEnum)taskType) .ExecuteCommandAsync(); - var id = await db.Queryable() + var flowInstanceId = await db.Queryable() .ClearFilter(typeof(ITenantId)) .Where(y => y.BusinessId == item.OUT_BS_NO && y.AuditType == (TaskBaseTypeEnum)taskType) .OrderByDescending(y => y.Id) .Select(y => y.Id) .FirstAsync(); - if (id != 0) + if (flowInstanceId != 0) { await db.Updateable() .SetColumns(x => x.MakerList == userIdStr) - .Where(x => x.Id == id) + .Where(x => x.Id == flowInstanceId) .ExecuteCommandAsync(); } } diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs index 6c2f4496..47221f13 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -11,10 +11,12 @@ using DS.Module.UserModule; using DS.WMS.Core.Code.Dtos; using DS.WMS.Core.Code.Entity; using DS.WMS.Core.Code.Interface; +using DS.WMS.Core.Flow.Entity; using DS.WMS.Core.Map.Dtos; using DS.WMS.Core.Map.Interface; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Entity; +using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Sys.Entity; using DS.WMS.Core.Sys.Interface; using DS.WMS.Core.TaskPlat.Dtos; @@ -2805,7 +2807,7 @@ namespace DS.WMS.Core.TaskPlat.Method // 下属任务统计 /* 备注:在之前已经清除了删除过滤器 - * 未配置: 登陆人所属机构下的人员【接收】的任务(需要调整为“无权限查询”) + * 未配置的情况: 登陆人所属机构下的人员【接收】的任务(需要调整为“无权限查询”) * 超级管理员: 登陆人所属机构下的人员【接收】的任务(带了机构筛选)(与self_org相同) * all: 登陆人所属租户下的全部数据 * none: 无权限查询 @@ -3419,6 +3421,105 @@ namespace DS.WMS.Core.TaskPlat.Method } + /// + /// 领取任务到当前登陆人(可批量) + /// + public async Task PullTask(long[] ids) + { + if (ids == null || ids.Length == 0) + { + throw new ArgumentNullException(nameof(ids)); + } + + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); + tenantDb.QueryFilter.Clear(); + + var userId = long.Parse(user.UserId); + try + { + var taskList = await tenantDb.Queryable().Where(x => ids.Contains(x.Id)).ToListAsync(x => new + { + x.Id, + x.STATUS, + x.STATUS_NAME, + x.TASK_TYPE, + x.OUT_BS_NO, + x.TASK_SOURCE + }); + + var taskIdList = taskList.Select(x => x.Id).ToList(); + var taskTypeList = taskList.Where(x => x.TASK_SOURCE == TaskSourceEnum.WORK_FLOW.ToString() && x.OUT_BS_NO != null).Select(x => x.TASK_TYPE).Distinct().ToList(); + + var taskCompleteStatusCodeList = taskTypeList.Count > 0 ? await tenantDb.Queryable() + .Where(x => x.ModuleType == 2 && taskTypeList.Contains(x.TaskType)) + .Select(x => new { x.TaskType, x.CompletedBusinessStatusCode }) + .ToListAsync() + : []; + + + var userOrgId = await db.Queryable().Where(x => x.Id == userId).Select(x => x.DefaultOrgId).FirstAsync(); + List allocationList = new(); + foreach (var item in taskList) + { + allocationList.Add(new TaskBaseAllocation() + { + TaskId = item.Id, + UserId = userId, + UserName = user.UserName, + Status = item.STATUS, + StatusName = item.STATUS_NAME, + StatusTime = DateTime.Now, + BusinessId = item.OUT_BS_NO, + GoodStatusCode = taskCompleteStatusCodeList.FirstOrDefault(x => x.TaskType == item.TASK_TYPE)?.CompletedBusinessStatusCode, + OrgId = userOrgId + }); + } + await tenantDb.AsTenant().BeginTranAsync(); + + var idList = await tenantDb.Queryable().Where(x => taskIdList.Contains(x.TaskId)).Select(x => x.Id).ToListAsync(); + await tenantDb.Deleteable(x => idList.Contains(x.Id)).ExecuteCommandAsync(); + + await tenantDb.Insertable(allocationList).ExecuteCommandAsync(); + + await tenantDb.Updateable() + .SetColumns(x => x.IS_PUBLIC == 0) + .Where(x => taskIdList.Contains(x.Id)) + .ExecuteCommandAsync(); + foreach (var item in taskList) + { + if (item.OUT_BS_NO is not null or 0 && Enum.TryParse(typeof(TaskBaseTypeEnum), item.TASK_TYPE, out object? taskType)) + { + await tenantDb.Updateable() + .SetColumns(x => x.RecvUsers == user.UserId) + .Where(x => x.BusinessId == item.OUT_BS_NO && x.TaskType == (TaskBaseTypeEnum)taskType) + .ExecuteCommandAsync(); + + var flowInstanceId = await db.Queryable() + .ClearFilter(typeof(ITenantId)) + .Where(y => y.BusinessId == item.OUT_BS_NO && y.AuditType == (TaskBaseTypeEnum)taskType) + .OrderByDescending(y => y.Id) + .Select(y => y.Id) + .FirstAsync(); + if (flowInstanceId != 0) + { + await db.Updateable() + .SetColumns(x => x.MakerList == user.UserId) + .Where(x => x.Id == flowInstanceId) + .ExecuteCommandAsync(); + } + } + } + await tenantDb.AsTenant().CommitTranAsync(); + return DataResult.Successed("操作成功", MultiLanguageConst.OperationSuccess); + } + catch (Exception ex) + { + await tenantDb.AsTenant().RollbackTranAsync(); + return DataResult.Failed("任务领取失败,原因:" + ex.Message); + } + } @@ -3451,15 +3552,16 @@ namespace DS.WMS.Core.TaskPlat.Method try { await tenantDb.Ado.BeginTranAsync(); - var t1 = tenantDb.ContextID; - var t2 = await tenantDb.Queryable().Where(x => x.Id == taskId).ToListAsync(); - var m = new TaskFlowLogDetail() - { - ModuleName = taskId.ToString() - }; - var t3 = await tenantDb.Insertable(m).ExecuteCommandAsync(); - - var service = serviceProvider.GetRequiredService(); + await tenantDb.Deleteable().Where(x => x.BusinessStatus == "0123123").ExecuteCommandAsync(); + //var t1 = tenantDb.ContextID; + //var t2 = await tenantDb.Queryable().Where(x => x.Id == taskId).ToListAsync(); + //var m = new TaskFlowLogDetail() + //{ + // ModuleName = taskId.ToString() + //}; + //var t3 = await tenantDb.Insertable(m).ExecuteCommandAsync(); + + //var service = serviceProvider.GetRequiredService(); //await service.TestDelete(taskId); await tenantDb.Ado.CommitTranAsync(); diff --git a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs index e7fc12e6..52279a56 100644 --- a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs +++ b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs @@ -219,4 +219,13 @@ public class TaskManageController : ApiController { return await taskManageService.TestTaskFlow(taskType, taskId, testType); } + + /// + /// 领取任务到当前登陆人(可批量) + /// + [HttpPost("PullTask")] + public async Task PullTask([FromBody] long[] Ids) + { + return await taskManageService.PullTask(Ids); + } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Test/SaasDBUpdateTest.cs b/ds-wms-service/DS.WMS.Test/SaasDBUpdateTest.cs index e482d309..b7be0410 100644 --- a/ds-wms-service/DS.WMS.Test/SaasDBUpdateTest.cs +++ b/ds-wms-service/DS.WMS.Test/SaasDBUpdateTest.cs @@ -93,11 +93,9 @@ public class SaasDBUpdateTest //tenantDb.CodeFirst.InitTables(typeof(TaskBaseAllocation)); // SQL更新 - string sql = @"ALTER TABLE `task_base_allocation` -MODIFY COLUMN `OrgId` bigint(0) NULL DEFAULT NULL COMMENT '机构Id' AFTER `BusinessId`;"; + string sql = @"update task_base_allocation b set OrgId = ifnull((select defaultOrgId from shippingweb8_dev.sys_user where id = b.UserId),0)"; tenantDb.Ado.ExecuteCommand(sql); - // DROP TRIGGER `tr_task_no`; }