You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
379 lines
12 KiB
C#
379 lines
12 KiB
C#
using Furion.DistributedIDGenerator;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Myshipping.Application.Entity;
|
|
using Myshipping.Core;
|
|
using Myshipping.Core.Service;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Myshipping.Application
|
|
{
|
|
/// <summary>
|
|
/// 派车任务
|
|
/// </summary>
|
|
[ApiDescriptionSettings("Application", Name = "TaskManageTruck", Order = 10)]
|
|
public class TaskManageTruckService : ITaskManageTruckService, IDynamicApiController
|
|
{
|
|
private readonly ISysCacheService _cache;
|
|
private readonly ILogger<BookingTruckService> _logger;
|
|
|
|
private readonly SqlSugarRepository<TaskTruckInfo> _taskTruckRepository;
|
|
private readonly SqlSugarRepository<TaskTruckCtn> _taskTruckContaRepository;
|
|
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
|
|
|
|
public TaskManageTruckService(SqlSugarRepository<TaskTruckInfo> taskTruckRepository,
|
|
SqlSugarRepository<TaskTruckCtn> taskTruckContaRepository,
|
|
SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
|
|
ISysCacheService cache, ILogger<BookingTruckService> logger)
|
|
{
|
|
_cache = cache;
|
|
_logger = logger;
|
|
|
|
_taskTruckRepository = taskTruckRepository;
|
|
_taskTruckContaRepository = taskTruckContaRepository;
|
|
_taskBaseRepository = taskBaseRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存派车
|
|
/// </summary>
|
|
/// <param name="info">派车信息</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpPost("/TaskManageTruck/Save")]
|
|
public async Task<TaskManageOrderResultDto> Save(TaskTruckDto info)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
try
|
|
{
|
|
var id = await InnerSave(info);
|
|
|
|
result.succ = true;
|
|
result.msg = "保存成功";
|
|
result.ext = id;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.succ = false;
|
|
result.msg = $"保存派车异常,原因:{ex.Message}";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存内部方法
|
|
/// </summary>
|
|
/// <param name="info">派车信息</param>
|
|
/// <returns>返回派车Id</returns>
|
|
[SqlSugarUnitOfWork]
|
|
private async Task<string> InnerSave(TaskTruckDto info)
|
|
{
|
|
TaskTruckInfo entity = info.Adapt<TaskTruckInfo>();
|
|
|
|
if (entity == null)
|
|
throw Oops.Oh($"派车信息不能为空");
|
|
|
|
List<TaskTruckCtn> entityCtnList = info.ContaList.Adapt<List<TaskTruckCtn>>();
|
|
|
|
if (entityCtnList != null && entityCtnList.Count > 0)
|
|
{
|
|
//保存时默认统计箱型箱量
|
|
entity.CntrTotal = string.Join(";", entityCtnList.GroupBy(a => a.CTNALL)
|
|
.Select(a =>
|
|
{
|
|
return $"{a.Key}*{a.ToList().Sum(b => b.CTNNUM.HasValue ? b.CTNNUM.Value : 1)}";
|
|
}).ToArray());
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.PK_ID))
|
|
{
|
|
entity.Status = BookingTruckStatus.TEMP.ToString();
|
|
entity.PK_ID = IDGen.NextID().ToString();
|
|
|
|
_taskTruckRepository.Insert(entity);
|
|
|
|
if (entityCtnList != null && entityCtnList.Count > 0)
|
|
{
|
|
entityCtnList.ForEach(async ctn =>
|
|
{
|
|
ctn.P_ID = entity.PK_ID;
|
|
ctn.PK_ID = IDGen.NextID().ToString();
|
|
|
|
await _taskTruckContaRepository.InsertAsync(ctn);
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var model = _taskTruckRepository.AsQueryable().First(a => a.PK_ID == entity.PK_ID);
|
|
|
|
if (model == null)
|
|
throw Oops.Oh($"派车信息获取失败,派车信息不存在或已作废");
|
|
|
|
//校验
|
|
ValidateTruck(OperateTypeEnum.Save, new TaskTruckInfo[] { model });
|
|
|
|
entity.UpdatedTime = DateTime.Now;
|
|
entity.UpdatedUserId = UserManager.UserId;
|
|
entity.UpdatedUserName = UserManager.Name;
|
|
|
|
await _taskTruckRepository.AsUpdateable(entity).IgnoreColumns(it => new
|
|
{
|
|
it.TenantId,
|
|
it.CreatedTime,
|
|
it.CreatedUserId,
|
|
it.CreatedUserName,
|
|
it.IsDeleted,
|
|
it.BookingId,
|
|
it.TruckId,
|
|
it.TruckName,
|
|
it.TruckCode,
|
|
it.Status,
|
|
}).ExecuteCommandAsync();
|
|
|
|
await _taskTruckContaRepository.DeleteAsync(x => x.P_ID == model.PK_ID);
|
|
|
|
if (entityCtnList != null && entityCtnList.Count > 0)
|
|
{
|
|
entityCtnList.ForEach(async ctn =>
|
|
{
|
|
ctn.P_ID = entity.PK_ID;
|
|
ctn.PK_ID = IDGen.NextID().ToString();
|
|
|
|
//await _bookingTruckContaRepository.AsUpdateable(ctn).IgnoreColumns(it => new
|
|
//{
|
|
// it.TenantId,
|
|
// it.CreatedTime,
|
|
// it.CreatedUserId,
|
|
// it.CreatedUserName,
|
|
// it.IsDeleted,
|
|
//}).ExecuteCommandAsync();
|
|
|
|
await _taskTruckContaRepository.InsertAsync(ctn);
|
|
});
|
|
}
|
|
}
|
|
|
|
return entity.PK_ID;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取派车详情
|
|
/// </summary>
|
|
/// <param name="pkId">派车主键</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpGet("/TaskManageTruck/GetInfo")]
|
|
public async Task<TaskManageOrderResultDto> GetInfo(string pkId)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
try
|
|
{
|
|
var truckOrder = _taskTruckRepository.AsQueryable().First(a => a.PK_ID == pkId);
|
|
|
|
if (truckOrder == null)
|
|
throw Oops.Oh($"派车主键{pkId}无法获取业务信息");
|
|
|
|
var truckCtnList = _taskTruckContaRepository.AsQueryable().Where(a => a.P_ID == pkId).ToList();
|
|
|
|
TaskTruckShowDto model = truckOrder.Adapt<TaskTruckShowDto>();
|
|
|
|
if (truckCtnList.Count > 0)
|
|
model.ContaList = truckCtnList.Adapt<List<TaskTruckCtnDto>>();
|
|
|
|
|
|
result.succ = true;
|
|
result.ext = model;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.succ = false;
|
|
result.msg = $"获取派车详情异常,原因:{ex.Message}";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过任务主键获取派车详情
|
|
/// </summary>
|
|
/// <param name="taskPkId">派车主键</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpGet("/TaskManageTruck/GetInfoByTaskId")]
|
|
public async Task<TaskManageOrderResultDto> GetInfoByTaskId(string taskPkId)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
try
|
|
{
|
|
var taskBase =_taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId);
|
|
|
|
if(taskBase == null)
|
|
throw Oops.Oh($"任务主键{taskPkId}无法获取业务信息");
|
|
|
|
var truckOrder = _taskTruckRepository.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
|
|
|
|
if (truckOrder == null)
|
|
throw Oops.Oh($"任务主键{taskPkId}无法获取派车业务信息");
|
|
|
|
var truckCtnList = _taskTruckContaRepository.AsQueryable().Where(a => a.P_ID == truckOrder.PK_ID).ToList();
|
|
|
|
TaskTruckShowDto model = truckOrder.Adapt<TaskTruckShowDto>();
|
|
|
|
if (truckCtnList.Count > 0)
|
|
model.ContaList = truckCtnList.Adapt<List<TaskTruckCtnDto>>();
|
|
|
|
result.succ = true;
|
|
result.ext = model;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.succ = false;
|
|
result.msg = $"获取派车详情异常,原因:{ex.Message}";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印派车
|
|
/// </summary>
|
|
/// <param name="pkId">派车主键</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpGet("/TaskManageTruck/Print")]
|
|
public async Task<TaskManageOrderResultDto> Print(string pkId)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量派车
|
|
/// </summary>
|
|
/// <param name="pkIds">派车主键组</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpPost("/TaskManageTruck/SendDispatchBatch")]
|
|
public async Task<TaskManageOrderResultDto> SendDispatchBatch([FromBody] string[] pkIds)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消派车
|
|
/// </summary>
|
|
/// <param name="pkId">派车主键</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpGet("/TaskManageTruck/CancelDispatch")]
|
|
public async Task<TaskManageOrderResultDto> CancelDispatch(string pkId)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量取消派车
|
|
/// </summary>
|
|
/// <param name="pkIds">派车主键组</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpPost("/TaskManageTruck/CancelDispatchBatch")]
|
|
public async Task<TaskManageOrderResultDto> CancelDispatchBatch([FromBody] string[] pkIds)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#region 校验派车
|
|
/// <summary>
|
|
/// 校验派车
|
|
/// </summary>
|
|
/// <param name="operateType">操作类型</param>
|
|
/// <param name="entityArg">派车信息列表</param>
|
|
private void ValidateTruck(OperateTypeEnum operateType, TaskTruckInfo[] entityArg)
|
|
{
|
|
if (operateType == OperateTypeEnum.Save)
|
|
{
|
|
if (entityArg.Any(a => a.Status != BookingTruckStatus.TEMP.ToString()
|
|
&& a.Status != BookingTruckStatus.CANCELED.ToString()))
|
|
{
|
|
throw Oops.Oh($"派车状态只有暂存、已撤销才能保存");
|
|
}
|
|
}
|
|
else if (operateType == OperateTypeEnum.Submit)
|
|
{
|
|
if (entityArg.Any(a => a.Status != BookingTruckStatus.TEMP.ToString()
|
|
&& a.Status != BookingTruckStatus.CANCELED.ToString()))
|
|
{
|
|
throw Oops.Oh($"派车状态只有暂存、已撤销才能提交");
|
|
}
|
|
}
|
|
else if (operateType == OperateTypeEnum.Cancel)
|
|
{
|
|
if (entityArg.Any(a => a.Status != BookingTruckStatus.SUBMITED.ToString()))
|
|
{
|
|
throw Oops.Oh($"派车状态只有已提交才能撤销派车");
|
|
}
|
|
}
|
|
else if (operateType == OperateTypeEnum.Delete)
|
|
{
|
|
if (entityArg.Any(a => a.Status != BookingTruckStatus.TEMP.ToString()
|
|
&& a.Status != BookingTruckStatus.CANCELED.ToString()))
|
|
{
|
|
throw Oops.Oh($"派车状态只有暂存、已撤销才能作废");
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|