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.
320 lines
14 KiB
C#
320 lines
14 KiB
C#
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using Myshipping.Application.Entity;
|
|
using Myshipping.Core;
|
|
using Myshipping.Core.Service;
|
|
using MySqlX.XDevAPI.Common;
|
|
using NPOI.XWPF.UserModel;
|
|
using StackExchange.Profiling.Internal;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Myshipping.Application
|
|
{
|
|
/// <summary>
|
|
/// 预甩货通知
|
|
/// </summary>
|
|
[ApiDescriptionSettings("Application", Name = "TaskManageRollingNomination", Order = 10)]
|
|
public class TaskManageRollingNominationService : ITaskManageRollingNominationService, IDynamicApiController
|
|
{
|
|
private readonly ISysCacheService _cache;
|
|
private readonly ILogger<TaskManageRollingNominationService> _logger;
|
|
|
|
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
|
|
private readonly SqlSugarRepository<TaskRollingNominationInfo> _taskRollingNominationInfoRepository;
|
|
private readonly SqlSugarRepository<TaskRollingNominationShipInfo> _taskRollingNominationShipInfoRepository;
|
|
private readonly SqlSugarRepository<TaskRollingNominationDetailInfo> _taskRollingNominationDetailInfoRepository;
|
|
private readonly SqlSugarRepository<TaskRollingNominationDispatchInfo> _taskRollingNominationDispatchInfoRepository;
|
|
private readonly SqlSugarRepository<TaskShareLinkInfo> _taskShareLinkInfoRepository;
|
|
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
|
|
private readonly SqlSugarRepository<BookingCtn> _bookingCtnRepository;
|
|
|
|
public TaskManageRollingNominationService(SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
|
|
SqlSugarRepository<TaskRollingNominationInfo> taskRollingNominationInfoRepository,
|
|
SqlSugarRepository<TaskRollingNominationDetailInfo> taskRollingNominationDetailInfoRepository,
|
|
SqlSugarRepository<TaskRollingNominationDispatchInfo> taskRollingNominationDispatchInfoRepository,
|
|
SqlSugarRepository<TaskRollingNominationShipInfo> taskRollingNominationShipInfoRepository,
|
|
SqlSugarRepository<TaskShareLinkInfo> taskShareLinkInfoRepository,
|
|
SqlSugarRepository<BookingOrder> bookingOrderRepository,
|
|
SqlSugarRepository<BookingCtn> bookingCtnRepository)
|
|
{
|
|
_taskBaseRepository = taskBaseRepository;
|
|
_taskRollingNominationInfoRepository = taskRollingNominationInfoRepository;
|
|
_taskRollingNominationDetailInfoRepository = taskRollingNominationDetailInfoRepository;
|
|
_taskRollingNominationDispatchInfoRepository = taskRollingNominationDispatchInfoRepository;
|
|
_taskRollingNominationShipInfoRepository = taskRollingNominationShipInfoRepository;
|
|
_taskShareLinkInfoRepository = taskShareLinkInfoRepository;
|
|
_bookingOrderRepository = bookingOrderRepository;
|
|
_bookingCtnRepository = bookingCtnRepository;
|
|
}
|
|
|
|
#region 获取预甩详情
|
|
/// <summary>
|
|
/// 获取预甩详情
|
|
/// </summary>
|
|
/// <param name="pkId">预甩主键</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpGet("/TaskManageRollingNomination/GetInfo")]
|
|
public async Task<TaskRollingNominationShowDto> GetInfo(string pkId)
|
|
{
|
|
TaskRollingNominationShowDto model = null;
|
|
|
|
try
|
|
{
|
|
var rollModel = _taskRollingNominationInfoRepository.AsQueryable()
|
|
.First(a => a.PK_ID == pkId && !a.IsDeleted);
|
|
|
|
if (rollModel == null)
|
|
throw Oops.Oh($"预甩货主键{pkId}无法获取业务信息");
|
|
|
|
model = await InnerGetInfo(rollModel);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"获取预甩详情异常,原因:{ex.Message}");
|
|
|
|
throw ex;
|
|
}
|
|
return model;
|
|
}
|
|
#endregion
|
|
|
|
#region 通过任务主键获取预甩详情
|
|
/// <summary>
|
|
/// 通过任务主键获取预甩详情
|
|
/// </summary>
|
|
/// <param name="taskPkId">预甩任务主键</param>
|
|
/// <returns>返回回执</returns>
|
|
[HttpGet("/TaskManageRollingNomination/GetInfoByTaskId")]
|
|
public async Task<TaskRollingNominationShowDto> GetInfoByTaskId(string taskPkId)
|
|
{
|
|
TaskRollingNominationShowDto model = null;
|
|
|
|
try
|
|
{
|
|
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId && !a.IsDeleted);
|
|
|
|
if (taskBase == null)
|
|
throw Oops.Oh($"预甩货任务主键{taskPkId}无法获取任务信息");
|
|
|
|
var rollModel = _taskRollingNominationInfoRepository.AsQueryable()
|
|
.First(a => a.TASK_ID == taskBase.PK_ID && !a.IsDeleted);
|
|
|
|
if (rollModel == null)
|
|
throw Oops.Oh($"预甩货任务主键{taskBase.PK_ID}无法获取业务信息");
|
|
|
|
model = await InnerGetInfo(rollModel);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_logger.LogError($"获取预甩详情异常,原因:{ex.Message}");
|
|
|
|
throw ex;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取预甩详情
|
|
/// <summary>
|
|
/// 获取预甩详情
|
|
/// </summary>
|
|
/// <param name="rollModel">预甩货详情实体类</param>
|
|
/// <returns>返回详情</returns>
|
|
private async Task<TaskRollingNominationShowDto> InnerGetInfo(TaskRollingNominationInfo rollModel)
|
|
{
|
|
TaskRollingNominationShowDto model = null;
|
|
|
|
try
|
|
{
|
|
List<string> rollingPlanList = new List<string>();
|
|
|
|
if (!string.IsNullOrWhiteSpace(rollModel.PLAN_TXT))
|
|
{
|
|
rollingPlanList = rollModel.PLAN_TXT.Split("\\n").ToList();
|
|
}
|
|
|
|
model = new TaskRollingNominationShowDto
|
|
{
|
|
PlanType = rollModel.PLAN_TYPE,
|
|
CarrierId = rollModel.CARRIERID,
|
|
Carrier = rollModel.CARRIER,
|
|
ConfirmDeadLine = rollModel.CONFIRM_DEAD_LINE,
|
|
CreateTime = rollModel.READ_CREATE_TIME,
|
|
RollingTouchDoubleRollRemark = rollModel.ROLL_DOUBLE_REMARK,
|
|
LoadDetailList = new List<TaskRollingNominationShipDetailShowDto>(),
|
|
RollingPlanList = rollingPlanList,
|
|
PreBillList = new List<TaskRollingNominationShipPreBillShowDto>()
|
|
};
|
|
|
|
var shipList = _taskRollingNominationShipInfoRepository.AsQueryable()
|
|
.Where(a => a.NOM_ID == rollModel.PK_ID && a.GROUP_INDX == 1 && !a.IsDeleted).ToList();
|
|
|
|
var fromEntity = shipList.FirstOrDefault(a =>
|
|
a.SHIP_TYPE.Equals("From", StringComparison.OrdinalIgnoreCase));
|
|
|
|
if (fromEntity != null)
|
|
model.From = fromEntity.Adapt<TaskRollingNominationShipDto>();
|
|
|
|
var toEntity = shipList.FirstOrDefault(a =>
|
|
a.SHIP_TYPE.Equals("To", StringComparison.OrdinalIgnoreCase));
|
|
|
|
if (toEntity != null)
|
|
model.To = toEntity.Adapt<TaskRollingNominationShipDto>();
|
|
|
|
|
|
var withDispatchList = _taskRollingNominationDetailInfoRepository.AsQueryable().Filter(null, true)
|
|
.LeftJoin<TaskRollingNominationDispatchInfo>((detail, dispatch) => detail.PK_ID == dispatch.DETAIL_ID)
|
|
.Where((detail, dispatch) => detail.NOM_ID == rollModel.PK_ID && detail.IsDeleted == false
|
|
&& (string.IsNullOrWhiteSpace(dispatch.PK_ID) || (!string.IsNullOrWhiteSpace(dispatch.PK_ID) && dispatch.IsDeleted == false)))
|
|
.Select((detail, dispatch) => new { Detail = detail, Dispatch = dispatch }).ToList();
|
|
|
|
model.PreBillList = withDispatchList.Where(a=>
|
|
a.Dispatch != null || (a.Dispatch == null && !a.Detail.NOM_STATUS_NOTE.Equals("Load",StringComparison.OrdinalIgnoreCase)))
|
|
.GroupBy(a => a.Detail.CUSTOMERID)
|
|
.SelectMany((a,idx) => {
|
|
var cArg = a.ToList();
|
|
|
|
return a.GroupBy(b=> b.Detail.SHIPMENT).Select(
|
|
b => {
|
|
|
|
var preBillArg = b.ToList();
|
|
|
|
var preBillDetail = preBillArg.FirstOrDefault().Detail;
|
|
var preBillDispatch = preBillArg.FirstOrDefault().Dispatch;
|
|
|
|
string ctnStat = string.Join(",", preBillArg.GroupBy(x => x.Detail.CTNALL)
|
|
.Select(x =>
|
|
$"{x.Key}*{x.Sum(t => t.Detail.CTNNUM)}").ToArray());
|
|
|
|
TaskRollingNominationShipPreBillShowDto preBillInfo = new TaskRollingNominationShipPreBillShowDto
|
|
{
|
|
Bookedby = preBillDetail.BOOKED_BY,
|
|
ConfirmDate = preBillDispatch?.CONFIRM_DATE,
|
|
ConfirmDeadLine = preBillDispatch?.CONFIRM_DEAD_LINE,
|
|
CtnStat = ctnStat,
|
|
CustomerId = preBillDetail.CUSTOMERID,
|
|
CustomerName = preBillDetail.CUSTOMERNAME,
|
|
ContractualName = preBillDetail.CONTRACTUAL_NAME,
|
|
CreateShareLinkDate = preBillDispatch?.CREATE_SHARE_LINK_DATE,
|
|
DischargePortName = preBillDetail.DISCHARGEPORT_NAME,
|
|
IsSend = preBillDispatch != null ? preBillDispatch.IS_SEND : false,
|
|
IsUserManual = preBillDispatch != null ? preBillDispatch.IS_USER_MANUAL : false,
|
|
LoadPortName = preBillDetail.LOADPORT_NAME,
|
|
PlaceOfDelivery = preBillDetail.PLACEOF_DELIVERY,
|
|
PlaceOfReceipt = preBillDetail.PLACEOF_RECEIPT,
|
|
Shipment = preBillDetail.SHIPMENT,
|
|
Status = preBillDispatch?.STATUS,
|
|
ShareLinkKey = preBillDispatch?.SHARE_LINK_KEY,
|
|
UserOpinion = preBillDispatch?.USER_OPINION,
|
|
UserOpinionTxt = preBillDispatch?.USER_OPINION_TXT,
|
|
BatchId = preBillDispatch?.BATCH_ID,
|
|
BookingId = preBillDetail.BOOKING_ID,
|
|
GroupName = $"CUST_{idx + 1}",
|
|
};
|
|
|
|
return preBillInfo;
|
|
}).ToList();
|
|
}).ToList();
|
|
|
|
if(withDispatchList.Any(a=>a.Dispatch == null
|
|
&& a.Detail.NOM_STATUS_NOTE.Equals("Load", StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
model.LoadDetailList = withDispatchList.Where(a => a.Dispatch == null
|
|
&& a.Detail.NOM_STATUS_NOTE.Equals("Load", StringComparison.OrdinalIgnoreCase))
|
|
.Select(a => a.Detail.Adapt<TaskRollingNominationShipDetailShowDto>()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError($"获取预甩详情异常,原因:{ex.Message}");
|
|
|
|
throw ex;
|
|
}
|
|
return model;
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 生成预甩货客户访问链接
|
|
/// </summary>
|
|
/// <param name="taskPkIds">预甩货任务主键组</param>
|
|
/// <returns>返回回执</returns>
|
|
public async Task<TaskManageOrderResultDto> CreateShareLink(string[] taskPkIds)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消预甩货客户访问链接
|
|
/// </summary>
|
|
/// <param name="taskPkIds">预甩货任务主键组</param>
|
|
/// <returns>返回回执</returns>
|
|
public async Task<TaskManageOrderResultDto> CancelShareLink(string[] taskPkIds)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 推送预甩货客户访问链接
|
|
/// </summary>
|
|
/// <param name="taskPkIds">预甩货任务主键组</param>
|
|
/// <returns>返回回执</returns>
|
|
public async Task<TaskManageOrderResultDto> PushShareLink(string[] taskPkIds)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成预甩货调度
|
|
/// </summary>
|
|
/// <param name="nominationShipId">预甩货船信息主键</param>
|
|
/// <param name="loadDetailIds">预甩货可Load明细信息主键组</param>
|
|
/// <returns>返回回执</returns>
|
|
public async Task<TaskManageOrderResultDto> DispatchRollingNomination(string nominationShipId, string[] loadDetailIds)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查看分享链接
|
|
/// </summary>
|
|
/// <param name="batchId">预甩任务主键</param>
|
|
/// <returns>返回回执</returns>
|
|
public async Task<TaskManageOrderResultDto> GetUrl(string batchId)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取Status是load的可配载的列表
|
|
/// </summary>
|
|
/// <param name="taskPkId">预甩货任务主键</param>
|
|
/// <returns>返回回执</returns>
|
|
public async Task<TaskManageOrderResultDto> GetLoadStatusDetailList(string taskPkId)
|
|
{
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|