From 972a88ca6a6e57e8c778cdee193f937b10938562 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Thu, 20 Apr 2023 15:24:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B4=BE=E8=BD=A6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Enum/TaskBusiTypeEnum.cs | 5 + .../BookingTruck/BookingTruckService.cs | 44 +++++- .../TaskManagePlat/Dtos/UserTendDto.cs | 31 ++++ .../TaskManagePlat/TaskManageService.cs | 133 +++++++++++++++--- 4 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 Myshipping.Application/Service/TaskManagePlat/Dtos/UserTendDto.cs diff --git a/Myshipping.Application/Enum/TaskBusiTypeEnum.cs b/Myshipping.Application/Enum/TaskBusiTypeEnum.cs index a779317a..4245ba51 100644 --- a/Myshipping.Application/Enum/TaskBusiTypeEnum.cs +++ b/Myshipping.Application/Enum/TaskBusiTypeEnum.cs @@ -143,5 +143,10 @@ namespace Myshipping.Application /// [Description("VGM反馈详情")] VGM_FEEDBACK, + /// + /// 派车 + /// + [Description("派车")] + TRUCK_DISPATCH } } diff --git a/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs b/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs index 21674dc4..4058b976 100644 --- a/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs +++ b/Myshipping.Application/Service/BookingTruck/BookingTruckService.cs @@ -646,6 +646,14 @@ namespace Myshipping.Application if (contaList.Count > 0) messageInfo.Main.TruckInfo.ContaList = contaList.Adapt>(); + messageInfo.Main.TaskUserId = UserManager.UserId.ToString(); + messageInfo.Main.TaskUserName = UserManager.Name; + + messageInfo.Main.TaskTitle = $"{model.MBLNo}_派车任务"; + messageInfo.Main.TaskDesp = $"{model.MBLNo}_派车任务"; + messageInfo.Main.TaskSource = TaskSourceEnum.CUSTOMER_SUBMIT; + + _logger.LogInformation("批次={no} 请求报文msg={msg}", batchNo, JSON.Serialize(messageInfo)); //推送新增派车任务接口 @@ -896,11 +904,43 @@ namespace Myshipping.Application ValidateTruck(OperateTypeEnum.Cancel, new BookingTruck[] { model }); DateTime bDate = DateTime.Now; + + TaskManageOrderMessageInfo messageInfo = new TaskManageOrderMessageInfo + { + Head = new TaskManageOrderMessageHeadInfo + { + GID = id.ToString(),//直接用派车的主键 + MessageType = "TASK", + SenderId = "BookingOrder", + SenderName = "订舱派车", + ReceiverId = "TaskManage", + ReceiverName = "派车任务", + RequestDate = bDate.ToString("yyyy-MM-dd HH:mm:ss.fff"), + Version = "1.0", + RequestAction = "Add" + }, + Main = new TaskManageOrderMessageMainInfo + { + TaskType = TaskBaseTypeEnum.TRUCK_DISPATCH, + TruckInfo = model.Adapt(), + } + }; + + messageInfo.Main.TaskUserId = UserManager.UserId.ToString(); + messageInfo.Main.TaskUserName = UserManager.Name; + + messageInfo.Main.TaskTitle = $"{model.MBLNo}_派车任务"; + messageInfo.Main.TaskDesp = $"{model.MBLNo}_派车任务"; + messageInfo.Main.TaskSource = TaskSourceEnum.CUSTOMER_SUBMIT; + + _logger.LogInformation("批次={no} 请求报文msg={msg}", batchNo, JSON.Serialize(messageInfo)); + //推送新增派车任务接口 - var msgModel = model.Adapt(); - var taskRlt = await _taskManageExternalService.CancelTruckDispatchAsync(msgModel); + var taskRlt = await _taskManageExternalService.CancelTruckDispatchAsync(messageInfo); DateTime eDate = DateTime.Now; + + TimeSpan ts = eDate.Subtract(bDate); var timeDiff = ts.TotalMilliseconds; diff --git a/Myshipping.Application/Service/TaskManagePlat/Dtos/UserTendDto.cs b/Myshipping.Application/Service/TaskManagePlat/Dtos/UserTendDto.cs new file mode 100644 index 00000000..11552fe8 --- /dev/null +++ b/Myshipping.Application/Service/TaskManagePlat/Dtos/UserTendDto.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Myshipping.Application +{ + /// + /// 用户和租户信息 + /// + public class UserTendDto + { + /// + /// 用户ID + /// + public long userId { get; set; } + /// + /// 用户名称 + /// + public string userName { get; set; } + /// + /// 租户ID + /// + public long tendId { get; set; } + /// + /// 租户名称 + /// + public string tenantName { get; set; } + } +} diff --git a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs index cc5838ae..34a7cb1d 100644 --- a/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs +++ b/Myshipping.Application/Service/TaskManagePlat/TaskManageService.cs @@ -133,6 +133,8 @@ namespace Myshipping.Application SqlSugarRepository taskStoreMsgInfoRepository, SqlSugarRepository taskChangeShipHisInfoRepository, SqlSugarRepository bookingOrderContactRepository, + SqlSugarRepository taskTruckInfoRepository, + SqlSugarRepository taskTruckCtnRepository, INamedServiceProvider namedBookingOrderServiceProvider, IDjyWebsiteAccountConfigService webAccountConfig, ISysCacheService cache, @@ -159,6 +161,8 @@ namespace Myshipping.Application _taskStoreMsgInfoRepository = taskStoreMsgInfoRepository; _taskChangeShipHisInfoRepository = taskChangeShipHisInfoRepository; _bookingOrderContactRepository = bookingOrderContactRepository; + _taskTruckInfoRepository = taskTruckInfoRepository; + _taskTruckCtnRepository = taskTruckCtnRepository; _namedBookingOrderServiceProvider = namedBookingOrderServiceProvider; @@ -199,16 +203,21 @@ namespace Myshipping.Application /// /// 任务详情 /// 返回回执 + [SqlSugarUnitOfWork] private async Task InitTaskJob(TaskManageOrderMessageInfo info) { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); try { - var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}"); + var taskInfo = _taskBaseInfoRepository.AsQueryable().OrderByDescending(a=>a.CreatedTime) + .First(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}"); - if (taskInfo != null) - throw Oops.Oh($"任务已经存在不能重复提交"); + /* + 只要任务最后一次处理任务的状态是已取消、已完成,就可以重入新的任务 + */ + if(taskInfo != null && taskInfo.STATUS != TaskStatusEnum.Cancel.ToString() && taskInfo.STATUS != TaskStatusEnum.Complete.ToString()) + throw Oops.Oh($"状态已存在,不能重复创建任务"); taskInfo = new TaskBaseInfo { @@ -222,26 +231,19 @@ namespace Myshipping.Application CARRIER_ID = info.Main.CarrierId?.Trim(), IS_PUBLIC = string.IsNullOrWhiteSpace(info.Main.TaskUserId) ? 1 : 0, BOOK_ORDER_NO = info.Main.BookingOrderNo, - OUT_BUSI_NO = info.Head.GID, + OUT_BUSI_NO = $"{info.Head.SenderId}_{info.Head.GID}", TASK_TITLE = info.Main.TaskTitle, TASK_DESP = info.Main.TaskDesp, TASK_SOURCE = info.Main.TaskSource.ToString(), TASK_TYPE = info.Main.TaskType.ToString(), }; - //这里因为接口是不做授权验证的,所以这里直接写的动态sql提取了用户和租户信息 - var userTendInfo = await _sysUserRepository.EntityContext.Queryable("user").AS("sys_user") - .AddJoinInfo("sys_tenant", "ten", "user.TenantId=ten.Id") - .Where("user.Id=@id", new { id = long.Parse(info.Main.TaskUserId) }) - .Select("user.Id as UserId,user.Name as UserName,ten.Id as TendId,ten.Name as TendName").FirstAsync(); - - if (userTendInfo == null || userTendInfo.TendId == null) - throw Oops.Oh("当前用户详情获取失败,请确认{0}赋值是否准确",nameof(TaskManageOrderMessageInfo.Main.TaskUserId)); + UserTendDto userTendInfo = GetUserTendInfo(info.Main.TaskUserId); - taskInfo.CreatedUserId = long.Parse(userTendInfo.UserId.ToString()); - taskInfo.CreatedUserName = userTendInfo.UserName.ToString(); - taskInfo.TenantId = long.Parse(userTendInfo.TendId.ToString()); - taskInfo.TenantName = userTendInfo.TendName.ToString(); + taskInfo.CreatedUserId = userTendInfo.userId; + taskInfo.CreatedUserName = userTendInfo.userName; + taskInfo.TenantId = userTendInfo.tendId; + taskInfo.TenantName = userTendInfo.tenantName; taskInfo.CreatedTime = DateTime.Now; taskInfo.UpdatedTime = taskInfo.CreatedTime; @@ -257,7 +259,7 @@ namespace Myshipping.Application } //新增 - await _taskBaseInfoRepository.InsertAsync(taskInfo); + _taskBaseInfoRepository.Insert(taskInfo); #region 附件 //附件 @@ -493,8 +495,6 @@ namespace Myshipping.Application }); //异步集装箱 } - - } #endregion @@ -521,8 +521,9 @@ namespace Myshipping.Application result.succ = true; result.msg = "新增任务成功"; + var md = _taskBaseInfoRepository.AsQueryable().First(a => a.PK_ID == taskInfo.PK_ID); //回写任务号 - result.ext = taskInfo.TASK_NO; + result.ext = md?.TASK_NO; } catch (Exception ex) { @@ -533,6 +534,35 @@ namespace Myshipping.Application } #endregion + /// + /// 查询订舱表查询用户和租户信息 + /// + /// + /// + private UserTendDto GetUserTendInfo(string userId) + { + UserTendDto userTendDto = null; + + //这里因为接口是不做授权验证的,所以这里直接写的动态sql提取了用户和租户信息 + var userTendInfo = _sysUserRepository.EntityContext.Queryable("user").AS("sys_user") + .AddJoinInfo("sys_tenant", "ten", "user.TenantId=ten.Id") + .Where("user.Id=@id", new { id = long.Parse(userId) }) + .Select("user.Id as UserId,user.Name as UserName,ten.Id as TendId,ten.Name as TendName").First(); + + if (userTendInfo == null || userTendInfo.TendId == null) + throw Oops.Oh("当前用户详情获取失败,请确认{0}赋值是否准确", nameof(TaskManageOrderMessageInfo.Main.TaskUserId)); + + userTendDto = new UserTendDto + { + userId = long.Parse(userTendInfo.UserId.ToString()), + userName = userTendInfo.UserName.ToString(), + tendId = long.Parse(userTendInfo.TendId.ToString()), + tenantName = userTendInfo.TendName.ToString() + }; + + return userTendDto; + } + #region 获取查询参数 /// /// 获取查询参数 @@ -4435,12 +4465,75 @@ namespace Myshipping.Application { TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + /* + 1、通过Head.GID检索任务表。 + 2、任务不存在提示检索失败。 + 3、任务存在判断当前状态已完成、已取消、已挂起不能撤销。 + 4、派车任务业务状态是SEND_DISPATCH不能撤销。 + 5、更新任务状态、更新派车任务状态。 + 6、返回结果 + */ try { + var taskInfo = _taskBaseInfoRepository.AsQueryable() + .First(t => t.OUT_BUSI_NO == $"{info.Head.SenderId}_{info.Head.GID}"); + + if(taskInfo == null) + throw Oops.Oh($"任务不存在"); + + if(new string[] { TaskStatusEnum.Complete.ToString(), TaskStatusEnum.Pending.ToString(),TaskStatusEnum.Pending.ToString() } + .Contains(taskInfo.STATUS)) + throw Oops.Oh($"任务状态是已完成/已挂起/已取消的不能撤销"); + + var truckInfo = _taskTruckInfoRepository.AsQueryable().First(a => a.TASK_ID == taskInfo.PK_ID); + + if (truckInfo == null) + throw Oops.Oh($"派车任务不存在"); + + if(truckInfo.Status == BookingTruckStatus.SEND_DISPATCH.ToString()) + throw Oops.Oh($"派车任务状态是已派车不能撤销"); + + DateTime nowDate = DateTime.Now; + + truckInfo.Status = BookingTruckStatus.CANCELED.ToString(); + + UserTendDto userTendInfo = GetUserTendInfo(info.Main.TaskUserId); + + truckInfo.UpdatedUserId = userTendInfo.userId; + truckInfo.UpdatedUserName = userTendInfo.userName; + truckInfo.UpdatedTime = nowDate; + + //更新派车任务 + await _taskTruckInfoRepository.AsUpdateable(truckInfo).UpdateColumns(it => new + { + it.UpdatedUserId, + it.Status, + it.UpdatedUserName, + it.UpdatedTime + }).ExecuteCommandAsync(); + + taskInfo.UpdatedUserId = userTendInfo.userId; + taskInfo.UpdatedUserName = userTendInfo.userName; + taskInfo.UpdatedTime = nowDate; + taskInfo.STATUS = TaskStatusEnum.Cancel.ToString(); + + //更新任务 + await _taskBaseInfoRepository.AsUpdateable(taskInfo).UpdateColumns(it => new + { + it.UpdatedUserId, + it.STATUS, + it.UpdatedUserName, + it.UpdatedTime + }).ExecuteCommandAsync(); + + result.succ = true; + result.msg = "撤销成功"; } catch (Exception ex) { + _logger.LogError("撤销任务异常,原因:{error}", ex.Message); + throw Oops.Oh($"{ex.Message}"); } return result;