修改派车任务

optimize
jianghaiqing 2 years ago
parent e1bd5a87bc
commit 972a88ca6a

@ -143,5 +143,10 @@ namespace Myshipping.Application
/// </summary>
[Description("VGM反馈详情")]
VGM_FEEDBACK,
/// <summary>
/// 派车
/// </summary>
[Description("派车")]
TRUCK_DISPATCH
}
}

@ -646,6 +646,14 @@ namespace Myshipping.Application
if (contaList.Count > 0)
messageInfo.Main.TruckInfo.ContaList = contaList.Adapt<List<TaskManageOrderTruckContaInfo>>();
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<TaskManageOrderTruckInfo>(),
}
};
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<TaskManageOrderMessageInfo>();
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;

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 用户和租户信息
/// </summary>
public class UserTendDto
{
/// <summary>
/// 用户ID
/// </summary>
public long userId { get; set; }
/// <summary>
/// 用户名称
/// </summary>
public string userName { get; set; }
/// <summary>
/// 租户ID
/// </summary>
public long tendId { get; set; }
/// <summary>
/// 租户名称
/// </summary>
public string tenantName { get; set; }
}
}

@ -133,6 +133,8 @@ namespace Myshipping.Application
SqlSugarRepository<TaskStoreMsgInfo> taskStoreMsgInfoRepository,
SqlSugarRepository<TaskChangeShipHisInfo> taskChangeShipHisInfoRepository,
SqlSugarRepository<BookingOrderContact> bookingOrderContactRepository,
SqlSugarRepository<TaskTruckInfo> taskTruckInfoRepository,
SqlSugarRepository<TaskTruckCtn> taskTruckCtnRepository,
INamedServiceProvider<IBookingOrderService> 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
/// </summary>
/// <param name="info">任务详情</param>
/// <returns>返回回执</returns>
[SqlSugarUnitOfWork]
private async Task<TaskManageOrderResultDto> 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<dynamic>("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
/// <summary>
/// 查询订舱表查询用户和租户信息
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
private UserTendDto GetUserTendInfo(string userId)
{
UserTendDto userTendDto = null;
//这里因为接口是不做授权验证的所以这里直接写的动态sql提取了用户和租户信息
var userTendInfo = _sysUserRepository.EntityContext.Queryable<dynamic>("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 获取查询参数
/// <summary>
/// 获取查询参数
@ -4435,12 +4465,75 @@ namespace Myshipping.Application
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
/*
1Head.GID
2
3
4SEND_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;

Loading…
Cancel
Save