From a0d6e769c2bf2f5add91ecdc70b90fa1cf925b5a Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Thu, 1 Aug 2024 15:39:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=86=E9=85=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD+=E4=BB=BB=E5=8A=A1=E5=88=9B=E5=BB=BA=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskPlat/Dtos/TaskAllocationDtos.cs | 16 --- .../TaskPlat/Dtos/TaskBaseAllocationDto.cs | 63 ++++++++ .../Dtos/TaskManageOrderMessageMainInfo.cs | 5 + .../TaskPlat/Entity/TaskAllocationtSet.cs | 26 +++- .../TaskPlat/Interface/ITaskManageService.cs | 4 + .../TaskPlat/Method/TaskManageService.cs | 134 +++++++++++++++++- .../Controllers/TaskAllocationController.cs | 46 ------ .../Controllers/TaskManageController.cs | 9 ++ 8 files changed, 234 insertions(+), 69 deletions(-) delete mode 100644 ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskAllocationDtos.cs create mode 100644 ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskBaseAllocationDto.cs delete mode 100644 ds-wms-service/DS.WMS.TaskApi/Controllers/TaskAllocationController.cs diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskAllocationDtos.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskAllocationDtos.cs deleted file mode 100644 index 0c97edf8..00000000 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskAllocationDtos.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace DS.WMS.Core.TaskPlat.Dtos -{ - public class TaskAllocationSaveDto - { - /// - /// 分配对象编码 Operator=操作 VouchingClerk=单证 Sale=销售 Custom=报关员 FinancialStaff=财务 CustomerService=客服 Driver=司机 Dispatcher=派车调度人员 - /// - public string AllocationTargetCode { get; set; } - - - /// - /// 任务类型编码列表 - /// - public List TaskTypeCodeList { get; set; } - } -} diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskBaseAllocationDto.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskBaseAllocationDto.cs new file mode 100644 index 00000000..8f6f51c0 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskBaseAllocationDto.cs @@ -0,0 +1,63 @@ +using SqlSugar; + +namespace DS.WMS.Core.TaskPlat.Dtos +{ + public class SaveTaskAllocationSettingDto + { + /// + /// 分配对象编码 Operator=操作 VouchingClerk=单证 Sale=销售 Custom=报关员 FinancialStaff=财务 CustomerService=客服 Driver=司机 Dispatcher=派车调度人员 + /// + public string AllocationTargetCode { get; set; } + + /// + /// 船公司ID + /// + public long? CarrierId { get; set; } + + /// + /// 船公司代码 + /// + public string? CarrierCode { get; set; } + + /// + /// 船公司 + /// + public string? Carrier { get; set; } + + /// + /// 任务类型列表 + /// + public List TaskTypeList { get; set; } + } + + public class TaskTypeInfoDto + { + /// + /// 任务类型编码 + /// + public string TaskTypeCode { get; set; } + + /// + /// 任务类型名称 + /// + public string TaskTypeName { get; set; } + } + + public class CarrierInfoDto + { + /// + /// 船公司ID + /// + public long? CarrierId { get; set; } + + /// + /// 船公司代码 + /// + public string? CarrierCode { get; set; } + + /// + /// 船公司 + /// + public string? Carrier { get; set; } + } +} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs index 7b6889c0..27c8ff5b 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Dtos/TaskManageOrderMessageMainInfo.cs @@ -13,6 +13,11 @@ namespace DS.WMS.Core.TaskPlat.Dtos /// public TaskBaseTypeEnum TaskType { get; set; } + /// + /// 校验任务类型重复是否判断任务类型 + /// + public bool IsCheckExistsByTaskType { get; set; } + /// /// 任务来源 /// diff --git a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskAllocationtSet.cs b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskAllocationtSet.cs index fe5dc0ab..8ac2a95c 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskAllocationtSet.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Entity/TaskAllocationtSet.cs @@ -13,7 +13,31 @@ namespace DS.WMS.Core.TaskPlat.Entity /// 任务类型 /// [SugarColumn(ColumnDescription = "任务类型编码", IsNullable = false, Length = 40)] - public string TaskType { get; set; } + public string TaskTypeCode { get; set; } + + /// + /// 任务类型名称 + /// + [SugarColumn(ColumnDescription = "任务类型名称", IsNullable = false, Length = 40)] + public string TaskTypeName { get; set; } + + /// + /// 船公司ID + /// + [SugarColumn(ColumnDescription = "船公司ID", IsNullable = true)] + public long? CarrierId { get; set; } + + /// + /// 船公司代码 + /// + [SugarColumn(ColumnDescription = "船公司代码", IsNullable = true, Length = 20)] + public string? CarrierCode { get; set; } + + /// + /// 船公司 + /// + [SugarColumn(ColumnDescription = "船公司", IsNullable = true, Length = 20)] + public string? Carrier { get; set; } /// /// 是否分配至操作 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 c9b59734..f23aeb8d 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Interface/ITaskManageService.cs @@ -67,5 +67,9 @@ namespace DS.WMS.Core.TaskPlat.Interface /// 要转交的人员信息列表 Task TransferTask(long bsno, TaskBaseTypeEnum taskBaseTypeEnum, List userInfos); + /// + /// 保存任务分配设置 + /// + Task SaveTaskAllocationSetting(SaveTaskAllocationSettingDto saveDto); } } 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 7aec72cc..4c85920f 100644 --- a/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskPlat/Method/TaskManageService.cs @@ -207,10 +207,7 @@ namespace DS.WMS.Core.TaskPlat.Method public async Task InitTaskJob(TaskManageOrderMessageInfo info, IFormFile file = null, IFormFile modifyFile = null) { string batchNo = Guid.NewGuid().ToString(); - //var a = user.UserId; - //var b = user.UserName; - //var c = user.TenantId; - //var d = user.OrgId; + try { logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JsonConvert.SerializeObject(info)); @@ -223,15 +220,19 @@ namespace DS.WMS.Core.TaskPlat.Method if (info.Head.BSNO is not null or 0) { taskInfo = await tenantDb.Queryable() + .Where(t => t.OUT_BS_NO == info.Head.BSNO) + .WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == info.Main.TaskType.ToString()) .OrderByDescending(a => a.CreateTime) - .FirstAsync(t => t.OUT_BS_NO == info.Head.BSNO); + .FirstAsync(); } // 否则通过Head.GID进行判断 else { taskInfo = await tenantDb.Queryable() + .Where(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}") + .WhereIF(info.Main.IsCheckExistsByTaskType, t => t.TASK_TYPE == info.Main.TaskType.ToString()) .OrderByDescending(a => a.CreateTime) - .FirstAsync(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}"); + .FirstAsync(); } @@ -1845,5 +1846,126 @@ namespace DS.WMS.Core.TaskPlat.Method //var sql = queryable.Select(t => t).Distinct().ToSqlString(); //.WhereIF(taskStatLevel == TaskStatLevelEnum.EXCPTION, (t, a) => t.IS_EXCEPT == 1) } + #region 任务分配相关 + /// + /// 获取任务分配保存列表 + /// + /// 船公司Id(可选) + public async Task>> GetTaskAllocationSettingList(long? carrierId) + { + var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); + + var list = await tenantDb.Queryable() + .WhereIF(carrierId != null, x => x.CarrierId == carrierId) + .ToListAsync(); + return DataResult>.Success(list); + } + + /// + /// 获取任务分配表中已存在的船公司列表(用于查询) + /// + public async Task>> GetTaskAllocationSettingCarrierList() + { + var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); + + var carrierList = await tenantDb.Queryable().Select(x => new CarrierInfoDto() + { + CarrierId = x.CarrierId, + Carrier = x.Carrier, + CarrierCode = x.CarrierCode + }).Distinct().ToListAsync(); + + return DataResult>.Success(carrierList); + } + + /// + /// 保存任务分配设置 + /// + public async Task SaveTaskAllocationSetting(SaveTaskAllocationSettingDto saveDto) + { + var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); + + if (string.IsNullOrEmpty(saveDto.CarrierCode)) + { + saveDto.CarrierCode = null; + } + if (string.IsNullOrEmpty(saveDto.Carrier)) + { + saveDto.Carrier = null; + } + if (saveDto.CarrierId == 0) + { + saveDto.CarrierId = null; + } + + var fieldName = saveDto.AllocationTargetCode switch + { + "Operator" => nameof(TaskAllocationtSet.IsAllotOperator), + "VouchingClerk" => nameof(TaskAllocationtSet.IsAllotVouchingClerk), + "Sale" => nameof(TaskAllocationtSet.IsAllotSale), + "Custom" => nameof(TaskAllocationtSet.IsAllotCustom), + "FinancialStaff" => nameof(TaskAllocationtSet.IsAllotFinancialStaff), + "CustomerService" => nameof(TaskAllocationtSet.IsAllotCustomerService), + "Driver" => nameof(TaskAllocationtSet.IsAllotDriver), + "Dispatcher" => nameof(TaskAllocationtSet.IsAllotDispatcher), + _ => throw new NotImplementedException(), + }; + + try + { + // 先查出来已有的、指定船公司的配置 + var oldSettingList = await tenantDb.Queryable().Where(x => x.CarrierId == saveDto.CarrierId).Select(x => new { x.Id, x.TaskTypeCode }).ToListAsync(); + + var oldSettingIdList = oldSettingList.Select(x => x.Id); + var oldSettingTypeCodeList = oldSettingList.Select(x => x.TaskTypeCode); + + await tenantDb.Ado.BeginTranAsync(); + + // 将原有的状态设置为未分配 + await tenantDb.Updateable() + .SetColumns(fieldName, false) + .Where(x => oldSettingIdList.Contains(x.Id)) + .ExecuteCommandAsync(); + + // 补充缺少的任务类型 + if (saveDto.TaskTypeList?.Any() == true) + { + var waitAddTypeCodeList = saveDto.TaskTypeList.Select(x => x.TaskTypeCode).Except(oldSettingTypeCodeList).ToList(); + + if (waitAddTypeCodeList.Count > 0) + { + waitAddTypeCodeList.Select(x => new TaskAllocationtSet() + { + CarrierId = saveDto.CarrierId, + Carrier = saveDto.Carrier, + CarrierCode = saveDto.CarrierCode, + TaskTypeCode = x, + TaskTypeName = saveDto.TaskTypeList.First(t => t.TaskTypeCode == x).TaskTypeName, + }); + + await tenantDb.Insertable(waitAddTypeCodeList).ExecuteCommandAsync(); + } + + var setTaskCodeList = saveDto.TaskTypeList.Select(x => x.TaskTypeCode); + + // 更新指定船公司的配置 + await tenantDb.Updateable() + .SetColumns(fieldName, true) + .Where(x => x.CarrierId == saveDto.CarrierId && setTaskCodeList.Contains(x.TaskTypeCode)) + .ExecuteCommandAsync(); + } + + await tenantDb.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await tenantDb.Ado.RollbackTranAsync(); + logger.LogError(ex, "保存任务分配设置异常"); + throw; + } + return DataResult.Successed(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.DataUpdateSuccess))); + } + #endregion + } } diff --git a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskAllocationController.cs b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskAllocationController.cs deleted file mode 100644 index 9503ed79..00000000 --- a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskAllocationController.cs +++ /dev/null @@ -1,46 +0,0 @@ -using DS.Module.Core; -using DS.Module.Core.Attributes; -using DS.Module.DjyServiceStatus; -using DS.WMS.Core.TaskPlat.Dtos; -using DS.WMS.Core.TaskPlat.Interface; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; - -namespace DS.WMS.TaskApi.Controllers; - - -/// -/// 任务分配相关接口 -/// -public class TaskAllocationController : ApiController -{ - private readonly ITaskManageService taskManageService; - - - public TaskAllocationController(ITaskManageService taskManageService) - { - this.taskManageService = taskManageService; - } - /// - /// 获取未设置分配的任务类型列表 - /// - [HttpGet("GetUnSetTaskTypeList")] - public async Task GetUnSetTaskTypeList([FromQuery] long[] taskIds, [FromBody] List userInfo) - { - //await taskManageService.SetTaskOwner(taskIds, userInfo); - //return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.OperationSuccess)); - return default; - } - - /// - /// 任务分配设置保存 - /// - [HttpPost("Save")] - public async Task Save() - { - //await taskManageService.SetTaskOwner(taskIds, userInfo); - //return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.OperationSuccess)); - return default; - } -} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs index 5b1edc8a..a83f2c42 100644 --- a/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs +++ b/ds-wms-service/DS.WMS.TaskApi/Controllers/TaskManageController.cs @@ -208,4 +208,13 @@ public class TaskManageController : ApiController return PhysicalFile(fileFullPath, "application/octet-stream", fileName); } + ///// + ///// 保存任务分配设置 + ///// + //[HttpPost("SaveTaskAllocationSetting")] + //public async Task SaveTaskAllocationSetting(SaveTaskAllocationSettingDto saveDto) + //{ + // var result = await taskManageService.SaveTaskAllocationSetting(saveDto); + // return result; + //} } \ No newline at end of file