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.
BookingHeChuan/Myshipping.Application/Service/TaskManagePlat/TaskManageCutDateChangeServ...

264 lines
11 KiB
C#

using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Myshipping.Application.Entity;
using Myshipping.Core;
9 months ago
using Myshipping.Core.Helper;
using Npoi.Mapper;
using NPOI.OpenXmlFormats.Wordprocessing;
using Org.BouncyCastle.Crypto;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 截止时间变更
/// </summary>
[ApiDescriptionSettings("Application", Name = "TaskManageCutDateChange", Order = 10)]
public class TaskManageCutDateChangeService: ITaskManageCutDateChangeService, IDynamicApiController
{
private readonly SqlSugarRepository<TaskCutDateChangeInfo> _taskCutDateChangeInfoRepository;
private readonly SqlSugarRepository<TaskCutDateChangeDetailInfo> _taskCutDateChangeDetailInfoRepository;
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
9 months ago
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
public TaskManageCutDateChangeService(SqlSugarRepository<TaskCutDateChangeInfo> taskCutDateChangeInfoRepository,
SqlSugarRepository<TaskCutDateChangeDetailInfo> taskCutDateChangeDetailInfoRepository,
9 months ago
SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
SqlSugarRepository<BookingOrder> bookingOrderRepository)
{
_taskCutDateChangeInfoRepository = taskCutDateChangeInfoRepository;
_taskCutDateChangeDetailInfoRepository = taskCutDateChangeDetailInfoRepository;
_taskBaseRepository = taskBaseRepository;
9 months ago
_bookingOrderRepository = bookingOrderRepository;
}
#region 获取截止时间变更详情
/// <summary>
/// 获取截止时间变更详情
/// </summary>
9 months ago
/// <param name="pkId">截止时间变更主键</param>
/// <returns>返回回执</returns>
[HttpGet("/TaskManageCutDate/GetInfo")]
public async Task<List<TaskCutDateChangeShowDto>> GetInfo(string pkId)
{
List<TaskCutDateChangeShowDto> list = new List<TaskCutDateChangeShowDto>();
var cutChangeOrder = _taskCutDateChangeInfoRepository.AsQueryable().First(a => a.PK_ID == pkId);
if (cutChangeOrder == null)
throw Oops.Oh($"截止时间变更主键{pkId}无法获取业务信息");
var detailList = _taskCutDateChangeDetailInfoRepository.AsQueryable()
.Where(a => a.P_ID == pkId).ToList();
if (detailList.Count > 0)
{
list = detailList.OrderBy(p => p.MBL_NO).Select(p =>
{
TaskCutDateChangeShowDto model = p.Adapt<TaskCutDateChangeShowDto>();
9 months ago
model.NoticeDate = cutChangeOrder.NOTICE_DATE;
model.Carrier = cutChangeOrder.CARRIER;
return model;
}).ToList();
}
return list;
}
#endregion
#region 通过任务主键获取截止时间变更详情
/// <summary>
/// 通过任务主键获取截止时间变更详情
/// </summary>
9 months ago
/// <param name="taskPkId">截止时间变更任务主键</param>
/// <returns>返回回执</returns>
[HttpGet("/TaskManageCutDate/GetInfoByTaskId")]
public async Task<List<TaskCutDateChangeShowDto>> GetInfoByTaskId(string taskPkId)
{
List<TaskCutDateChangeShowDto> list = new List<TaskCutDateChangeShowDto>();
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId);
if (taskBase == null)
throw Oops.Oh($"任务主键{taskPkId}无法获取业务信息");
var cutChangeOrder = _taskCutDateChangeInfoRepository.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (cutChangeOrder == null)
throw Oops.Oh($"截止时间变更主键{taskPkId}无法获取业务信息");
var detailList = _taskCutDateChangeDetailInfoRepository.AsQueryable()
.Where(a => a.P_ID == cutChangeOrder.PK_ID).ToList();
if (detailList.Count > 0)
{
list = detailList.OrderBy(p => p.MBL_NO).Select(p =>
{
TaskCutDateChangeShowDto model = p.Adapt<TaskCutDateChangeShowDto>();
9 months ago
model.NoticeDate = cutChangeOrder.NOTICE_DATE;
model.Carrier = cutChangeOrder.CARRIER;
return model;
}).ToList();
}
return list;
}
#endregion
9 months ago
#region 重新处理截止时间变更任务
/// <summary>
/// 重新处理截止时间变更任务
/// 对未匹配订舱订单的任务记录,重新对应订单订单
/// </summary>
/// <param name="taskPkId">截止时间变更任务主键</param>
/// <returns>返回回执</returns>
public async Task<TaskManageOrderResultDto> SearchAndConnectBookingInfo(string taskPkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId);
if (taskBase == null)
throw Oops.Oh($"任务主键{taskPkId}无法获取业务信息");
var cutDateChange = _taskCutDateChangeInfoRepository.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (cutDateChange == null)
throw Oops.Oh($"截止时间变更主键{taskPkId}无法获取业务信息");
var detailList = _taskCutDateChangeDetailInfoRepository.AsQueryable()
.Where(a => a.P_ID == cutDateChange.PK_ID).ToList();
//如果都有订单订单记录,则提示错误不进行对应
if (!detailList.Any(t => !t.BOOKING_ID.HasValue))
{
throw Oops.Oh($"当前截止时间变更已有匹配的订舱订单,不能执行操作");
}
var mblList = detailList.Select(a => a.MBL_NO).Distinct().ToList();
var bookingList = _bookingOrderRepository.AsQueryable().Filter(null, true)
.Where(a => mblList.Contains(a.MBLNO) && a.IsDeleted == false && (a.ParentId == null || a.ParentId == 0)).ToList();
if (bookingList.Count == 0)
throw Oops.Oh($"提单号未提取有效的订舱订单");
List<string> msgList = new List<string>();
detailList.ForEach(async t =>
{
//只处理没有订舱ID的记录
if (!t.BOOKING_ID.HasValue)
{
var currBook = bookingList.FirstOrDefault(p => p.MBLNO == t.MBL_NO);
if (currBook != null)
{
t.BOOKING_ID = currBook.Id;
t.UpdatedUserId = UserManager.UserId;
t.UpdatedUserName = UserManager.Name;
//更新任务BC
await _taskCutDateChangeDetailInfoRepository.AsUpdateable(t).UpdateColumns(it => new
{
it.BOOKING_ID,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
}
else
{
msgList.Add(t.MBL_NO);
}
}
});
if (msgList.Count > 0)
throw Oops.Oh($"提单号{(string.Join(",", msgList.ToArray()))}未提取有效的订舱订单");
result.succ = true;
result.msg = "成功";
return result;
}
#endregion
#region 推送及时消息
/// <summary>
/// 推送及时消息
/// </summary>
/// <param name="taskPkId">截止时间任务主键</param>
/// <returns>返回回执</returns>
public async Task<TaskManageOrderResultDto> SendInstantMessage(string taskPkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId);
if (taskBase == null)
throw Oops.Oh($"任务主键{taskPkId}无法获取业务信息");
var cutDateChange = _taskCutDateChangeInfoRepository.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (cutDateChange == null)
throw Oops.Oh($"截止时间变更主键{taskPkId}无法获取业务信息");
var detailList = _taskCutDateChangeDetailInfoRepository.AsQueryable()
.Where(a => a.P_ID == cutDateChange.PK_ID).ToList();
//如果都有订单订单记录,则提示错误不进行对应
if (!detailList.Any(t => t.BOOKING_ID.HasValue))
{
throw Oops.Oh($"当前截止时间变更没有匹配的订舱订单,不能执行操作");
}
var ids = detailList.Where(a => a.BOOKING_ID.HasValue).Select(a => a.BOOKING_ID.Value).ToList();
var bookingList = _bookingOrderRepository.AsQueryable().Filter(null, true)
.Where(a => ids.Contains(a.Id) && a.IsDeleted == false && (a.ParentId == null || a.ParentId == 0)).ToList();
if (bookingList.Count == 0)
throw Oops.Oh($"提单号未提取有效的订舱订单");
Dictionary<string, List<string>> msgList = new Dictionary<string, List<string>>();
msgList = bookingList.GroupBy(a => a.OP).Select(a =>
{
var currList = a.ToList();
return new { Key = a.Key, list = currList.Select(a => a.MBLNO).ToList() };
}).ToDictionary(a => a.Key, b => b.list);
if (msgList.Count > 0)
{
msgList.ForEach(t =>
{
DingTalkGroupHelper.SendDingTalkGroupMessage("KangqianNotify", "截止时间变更消息", $"@{t.Key} 收到如下提单号{(string.Join(",",t.Value.ToArray()))}的截止时间变更消息");
});
}
if(detailList.Any(t=>!t.BOOKING_ID.HasValue))
throw Oops.Oh($"提单号{(string.Join(",", detailList.Where(t => !t.BOOKING_ID.HasValue).Select(t=>t.MBL_NO).ToArray()))}未提取有效的订舱订单");
result.succ = true;
result.msg = "成功";
return result;
}
#endregion
}
}