修改预甩货任务

optimize
jianghaiqing 10 months ago
parent 2f53f2e7a0
commit a87273b940

@ -67,6 +67,16 @@ namespace Myshipping.Application
/// Load列表
/// </summary>
public List<TaskRollingNominationShipDetailShowDto> LoadDetailList { get; set; }
/// <summary>
/// 合计单票汇总合计箱型箱量
/// </summary>
public string TotalPreBillCtnStat { get; set; }
/// <summary>
/// 合计load汇总合计箱型箱量
/// </summary>
public string TotalLoadCtnStat { get; set; }
}
/// <summary>
@ -291,5 +301,15 @@ namespace Myshipping.Application
/// 预甩货调度主键
/// </summary>
public string NominationDispatchId { get; set; }
/// <summary>
/// 箱备注(主要)
/// </summary>
public string CtnNote { get; set; }
/// <summary>
/// 明细主键
/// </summary>
public string PKId { get; set; }
}
}

@ -940,7 +940,8 @@ namespace Myshipping.Application
.Map(dest => dest.BBYMAIL, src => src.BBYMAIL)
.Map(dest => dest.CtnCode, src => src.CTNCODE)
.Map(dest => dest.CtnAll, src => src.CTNALL)
.Map(dest => dest.CtnNum, src => src.CTNNUM);
.Map(dest => dest.CtnNum, src => src.CTNNUM)
.Map(dest => dest.PKId, src => src.PK_ID);
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
public interface ITaskManageAccessShareLinkService
{
/// <summary>
/// 访问链接
/// </summary>
/// <param name="Url">请求链接</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> AccessRollingNomination(string shareKey);
}
}

@ -37,11 +37,6 @@ namespace Myshipping.Application
Task<TaskManageOrderResultDto> ValidateShareLink(string Url);
/// <summary>
/// 访问链接
/// </summary>
/// <param name="Url">请求链接</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> QueryShareLink(string Url);
}
}

@ -1,4 +1,5 @@
using Furion.DistributedIDGenerator;
using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
@ -23,7 +24,7 @@ namespace Myshipping.Application
/// 预甩货通知
/// </summary>
[ApiDescriptionSettings("Application", Name = "TaskManageRollingNomination", Order = 10)]
public class TaskManageRollingNominationService : ITaskManageRollingNominationService, IDynamicApiController
public class TaskManageRollingNominationService : ITaskManageRollingNominationService, IDynamicApiController, ITransient
{
private readonly ISysCacheService _cache;
private readonly ILogger<TaskManageRollingNominationService> _logger;
@ -178,6 +179,8 @@ namespace Myshipping.Application
&& (string.IsNullOrWhiteSpace(dispatch.PK_ID) || (!string.IsNullOrWhiteSpace(dispatch.PK_ID) && dispatch.IsDeleted == false)))
.Select((detail, dispatch) => new { Detail = detail, Dispatch = dispatch }).ToList();
List<Tuple<string,int>> tuples = new List<Tuple<string,int>>();
model.PreBillList = withDispatchList.Where(a=>
a.Dispatch != null || ((a.Dispatch == null || string.IsNullOrWhiteSpace(a.Dispatch.PK_ID))
&& !a.Detail.NOM_STATUS_NOTE.Equals("Load",StringComparison.OrdinalIgnoreCase)))
@ -193,9 +196,14 @@ namespace Myshipping.Application
var preBillDetail = preBillArg.FirstOrDefault().Detail;
var preBillDispatch = preBillArg.FirstOrDefault().Dispatch;
string ctnStat = string.Join(",", preBillArg.GroupBy(x => x.Detail.CTNALL)
var cStaticlst = preBillArg.GroupBy(x => x.Detail.CTNALL)
.Select(x =>
$"{x.Key}*{x.Sum(t => t.Detail.CTNNUM)}").ToArray());
new { Key = x.Key, Num = x.Sum(t => t.Detail.CTNNUM) }).ToList();
string ctnStat = string.Join(",", cStaticlst.Select(x =>
$"{x.Key}*{x.Num}").ToArray());
cStaticlst.ForEach(y => tuples.Add(new Tuple<string, int>(y.Key, y.Num)));
TaskRollingNominationShipPreBillShowDto preBillInfo = new TaskRollingNominationShipPreBillShowDto
{
@ -220,7 +228,7 @@ namespace Myshipping.Application
UserOpinionTxt = preBillDispatch?.USER_OPINION_TXT,
BatchId = preBillDispatch?.BATCH_ID,
BookingId = preBillDetail.BOOKING_ID,
GroupName = $"CUST_{idx + 1}",
GroupName = preBillDetail.CUSTOMERID.HasValue?$"CUST_{idx + 1}":"",
};
return preBillInfo;
@ -235,6 +243,20 @@ namespace Myshipping.Application
&& a.Detail.NOM_STATUS_NOTE.Equals("Load", StringComparison.OrdinalIgnoreCase))
.Select(a => a.Detail.Adapt<TaskRollingNominationShipDetailShowDto>()).ToList();
}
if(tuples.Count > 0)
{
model.TotalPreBillCtnStat = string.Join(",", tuples.GroupBy(x => x.Item1)
.Select(x =>
$"{x.Key}*{x.Sum(t => t.Item2)}").ToArray());
}
if (model.LoadDetailList.Count > 0)
{
model.TotalLoadCtnStat = string.Join(",", model.LoadDetailList.GroupBy(x => x.CtnAll)
.Select(x =>
$"{x.Key}*{x.Sum(t => t.CtnNum)}").ToArray());
}
}
catch (Exception ex)
{
@ -341,43 +363,43 @@ namespace Myshipping.Application
2ID
3IDID
*/
if (model.loadDetailIds == null || model.loadDetailIds.Length == 0)
{
throw Oops.Oh($"预甩货可Load明细信息不能为空");
}
DateTime nowDate = DateTime.Now;
if (!model.isAdd && string.IsNullOrWhiteSpace(model.nominationBatchId))
if (!model.isAdd)
{
throw Oops.Oh($"改配调度需要提供预甩货调度批次ID");
}
if(string.IsNullOrWhiteSpace(model.nominationBatchId))
{
throw Oops.Oh($"改配调度需要提供预甩货调度批次ID");
}
var detailList = _taskRollingNominationDetailInfoRepository.AsQueryable()
.Where(a => model.loadDetailIds.Contains(a.PK_ID) && a.IsDeleted == false).ToList();
if (model.loadDetailIds == null || model.loadDetailIds.Length == 0)
{
throw Oops.Oh($"预甩货可Load明细信息不能为空");
}
if (detailList.Count != model.loadDetailIds.Length)
{
throw Oops.Oh($"预甩货明细部分获取失败,请重新获取预甩货明细");
}
var detailList = _taskRollingNominationDetailInfoRepository.AsQueryable()
.Where(a => model.loadDetailIds.Contains(a.PK_ID) && a.IsDeleted == false).ToList();
if (detailList.Any(a => !a.BOOKING_ID.HasValue || !a.CUSTOMERID.HasValue))
{
throw Oops.Oh($"预甩货明细存在未对应订舱的记录,不能生成调度");
}
if (detailList.Count != model.loadDetailIds.Length)
{
throw Oops.Oh($"预甩货明细部分获取失败,请重新获取预甩货明细");
}
var nomId = detailList.FirstOrDefault().NOM_ID;
if (detailList.Any(a => !a.BOOKING_ID.HasValue || !a.CUSTOMERID.HasValue))
{
throw Oops.Oh($"预甩货明细存在未对应订舱的记录,不能生成调度");
}
var nomModel = _taskRollingNominationInfoRepository.AsQueryable()
.First(a => a.PK_ID == nomId);
var nomId = detailList.FirstOrDefault().NOM_ID;
var shipmentList = detailList.Select(a => a.SHIPMENT).Distinct().ToList();
var nomModel = _taskRollingNominationInfoRepository.AsQueryable()
.First(a => a.PK_ID == nomId);
Dictionary<string, string> batchDict = shipmentList.Select(a => new { Key = a, BatchId = IDGen.NextID().ToString() })
.ToDictionary(a => a.Key, b => b.BatchId);
var shipmentList = detailList.Select(a => a.SHIPMENT).Distinct().ToList();
Dictionary<string, string> batchDict = shipmentList.Select(a => new { Key = a, BatchId = IDGen.NextID().ToString() })
.ToDictionary(a => a.Key, b => b.BatchId);
DateTime nowDate = DateTime.Now;
if (!model.isAdd)
{
List<TaskRollingNominationDispatchInfo> dispatchList = new List<TaskRollingNominationDispatchInfo>();
List<TaskRollingNominationDetailInfo> withDispatchDetailList = new List<TaskRollingNominationDetailInfo>();
@ -479,45 +501,62 @@ namespace Myshipping.Application
}
else
{
var withDispatchList = _taskRollingNominationDetailInfoRepository.AsQueryable().Filter(null, true)
.InnerJoin<TaskRollingNominationDispatchInfo>((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID)
.Where((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID && detail.IsDeleted == false
&& shipmentList.Contains(detail.SHIPMENT) && detail.NOM_ID == nomId
&& dispatch.IsDeleted == false)
.Select((detail, dispatch) => new { Detail = detail, Dispatch = dispatch }).ToList();
if (withDispatchList.Count > 0)
var withDispatchList =
_taskRollingNominationInfoRepository.AsQueryable().Filter(null, true)
.InnerJoin<TaskRollingNominationDetailInfo>((nom, detail) => nom.PK_ID == detail.NOM_ID)
.LeftJoin<TaskRollingNominationDispatchInfo>((nom, detail, dispatch) =>
detail.PK_ID == dispatch.DETAIL_ID && dispatch.IsDeleted == false)
.Where((nom, detail, dispatch) =>
detail.IsDeleted == false
&& detail.NOM_ID == model.nominationId)
.Select((nom, detail, dispatch) =>
new { Nom = nom, Detail = detail, Dispatch = dispatch }).ToList();
if (withDispatchList.Any(p => p.Dispatch != null
&& !string.IsNullOrWhiteSpace(p.Dispatch.PK_ID)))
{
throw Oops.Oh($"预甩货明细已生成调度不能重复");
}
detailList = _taskRollingNominationDetailInfoRepository.AsQueryable()
.Where(a => shipmentList.Contains(a.SHIPMENT) && a.IsDeleted == false && a.NOM_ID == nomId).ToList();
var nomiInfo = withDispatchList.FirstOrDefault().Nom;
var shipmentList = withDispatchList
.Select(a => a.Detail.SHIPMENT)
.Distinct().ToList();
Dictionary<string, string> batchDict = shipmentList.Select(a => new { Key = a, BatchId = IDGen.NextID().ToString() })
.ToDictionary(a => a.Key, b => b.BatchId);
DateTime deadLine = nomiInfo.CONFIRM_DEAD_LINE.Value.AddHours(2);
//开始写入调度
detailList.ForEach(a =>
withDispatchList.ForEach(info =>
{
TaskRollingNominationDispatchInfo dispatchInfo = new TaskRollingNominationDispatchInfo
{
PK_ID = IDGen.NextID().ToString(),
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name,
DETAIL_ID= a.PK_ID,
NOM_ID= a.NOM_ID,
NOM_SHIP_ID= a.NOM_SHIP_ID,
IsDeleted= false,
STATUS = "WAIT",
TASK_ID = nomModel.TASK_ID,
TenantId = UserManager.TENANT_ID,
TenantName = UserManager.TENANT_NAME,
BATCH_ID = batchDict[a.SHIPMENT],
};
var a = info.Detail;
_taskRollingNominationDispatchInfoRepository.Insert(dispatchInfo);
if (!a.NOM_STATUS_NOTE.Equals("Load", StringComparison.OrdinalIgnoreCase))
{
TaskRollingNominationDispatchInfo dispatchInfo = new TaskRollingNominationDispatchInfo
{
PK_ID = IDGen.NextID().ToString(),
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name,
DETAIL_ID = a.PK_ID,
NOM_ID = a.NOM_ID,
NOM_SHIP_ID = a.NOM_SHIP_ID,
IsDeleted = false,
STATUS = "WAIT",
TASK_ID = nomiInfo.TASK_ID,
TenantId = UserManager.TENANT_ID,
TenantName = UserManager.TENANT_NAME,
BATCH_ID = batchDict[a.SHIPMENT],
CONFIRM_DEAD_LINE = deadLine
};
_taskRollingNominationDispatchInfoRepository.Insert(dispatchInfo);
}
});
}

@ -112,6 +112,7 @@ namespace Myshipping.Application
private readonly ISysDataUserMenu _sysDataUserMenuService;
private readonly INamedServiceProvider<IBookingOrderService> _namedBookingOrderServiceProvider;
private readonly INamedServiceProvider<ITaskManageRollingNominationService> _namedRollingNominationServiceProvider;
const string CONST_WEB_ACCOUNT_TYPE = "CmaWeb";
const string CONST_BOOK_ORIGINAL_DOWN_URL_CODE = "bookOriginalDownUrl";
@ -157,6 +158,7 @@ namespace Myshipping.Application
IDjyWebsiteAccountConfigService webAccountConfig,
ISysCacheService cache,
ISysDataUserMenu sysDataUserMenuService,
INamedServiceProvider<ITaskManageRollingNominationService> namedRollingNominationServiceProvider,
ILogger<BookingOrderService> logger)
{
_taskBaseInfoRepository = taskBaseInfoRepository;
@ -190,6 +192,7 @@ namespace Myshipping.Application
_taskRollingNominationDetailInfoRepository = taskRollingNominationDetailInfoRepository;
_namedBookingOrderServiceProvider = namedBookingOrderServiceProvider;
_namedRollingNominationServiceProvider = namedRollingNominationServiceProvider;
_sysDataUserMenuService = sysDataUserMenuService;
@ -881,7 +884,14 @@ namespace Myshipping.Application
});
}
//异步生成调度
var rollNominationService = _namedRollingNominationServiceProvider
.GetService<ITransient>(nameof(TaskManageRollingNominationService));
var dispatchRlt = await rollNominationService.DispatchRollingNomination(new RollingNominationDispatchRequestDto {
isAdd = true,
nominationId = rollingNomination.PK_ID
});
}
#endregion

Loading…
Cancel
Save