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/TaskManagePODDischargeGateo...

279 lines
12 KiB
C#

9 months ago
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Application.Service.TaskManagePlat.Interface;
using Myshipping.Core;
using Myshipping.Core.Helper;
using Npoi.Mapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 任务目的港未提货未返箱
/// </summary>
[ApiDescriptionSettings("Application", Name = "PODDischargeGateoutFull", Order = 10)]
public class TaskManagePODDischargeGateoutFullService: ITaskManagePODDischargeGateoutFullService, IDynamicApiController
{
private readonly SqlSugarRepository<TaskPODDischargeGateoutFullInfo> _taskPODDischargeGateoutFullInfoRep;
private readonly SqlSugarRepository<TaskPODDischargeGateoutFullDetailInfo> _taskPODDischargeGateoutFullDetailInfoRep;
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
private readonly ILogger<TaskManagePODDischargeGateoutFullService> _logger;
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
public TaskManagePODDischargeGateoutFullService(ILogger<TaskManagePODDischargeGateoutFullService> logger,
SqlSugarRepository<TaskPODDischargeGateoutFullInfo> taskPODDischargeGateoutFullInfoRep,
SqlSugarRepository<TaskPODDischargeGateoutFullDetailInfo> taskPODDischargeGateoutFullDetailInfoRep,
SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
SqlSugarRepository<BookingOrder> bookingOrderRepository)
{
_taskPODDischargeGateoutFullInfoRep = taskPODDischargeGateoutFullInfoRep;
_taskBaseRepository = taskBaseRepository;
_taskPODDischargeGateoutFullDetailInfoRep = taskPODDischargeGateoutFullDetailInfoRep;
_logger = logger;
_bookingOrderRepository = bookingOrderRepository;
}
#region 获取目的港未提货未返箱详情
/// <summary>
/// 获取目的港未提货未返箱详情
/// </summary>
/// <param name="pkId">目的港未提货未返箱主键</param>
/// <returns>返回回执</returns>
[HttpGet("/PODDischargeGateoutFull/GetInfo")]
public async Task<List<TaskPODDischargeGateoutFullShowDto>> GetInfo(string pkId)
{
List<TaskPODDischargeGateoutFullShowDto> list = new List<TaskPODDischargeGateoutFullShowDto>();
var dischargeFull = _taskPODDischargeGateoutFullInfoRep.AsQueryable()
.First(a => a.PK_ID == pkId);
if (dischargeFull == null)
throw Oops.Oh($"目的港未提货未返箱主键{pkId}无法获取业务信息");
var dischargeFullDetail = _taskPODDischargeGateoutFullDetailInfoRep.AsQueryable()
.Where(a => a.P_ID == dischargeFull.PK_ID).ToList();
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == dischargeFull.TASK_ID);
if (taskBase == null)
throw Oops.Oh($"任务主键无法获取业务信息");
list = dischargeFullDetail.Select(x => {
var dto = x.Adapt<TaskPODDischargeGateoutFullShowDto>();
dto.PKId = dischargeFull.PK_ID;
dto.TaskId = dischargeFull.TASK_ID;
dto.IsComplete = taskBase.IS_COMPLETE == 1 ? true : false;
dto.CompleteTime = taskBase.COMPLETE_DATE;
dto.NoticeType = dischargeFull.NOTICE_TYPE;
dto.NoticeTypeName = dischargeFull.NOTICE_TYPE_NAME;
return dto;
}).ToList();
return list;
}
#endregion
#region 通过任务主键获取目的港未提货未返箱详情
/// <summary>
/// 通过任务主键获取目的港未提货未返箱详情
/// </summary>
/// <param name="taskPkId">目的港未提货未返箱任务主键</param>
/// <returns>返回回执</returns>
[HttpGet("/PODDischargeGateoutFull/GetInfoByTaskId")]
public async Task<List<TaskPODDischargeGateoutFullShowDto>> GetInfoByTaskId(string taskPkId)
{
List<TaskPODDischargeGateoutFullShowDto> list = new List<TaskPODDischargeGateoutFullShowDto>();
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId);
if (taskBase == null)
throw Oops.Oh($"任务主键{taskPkId}无法获取业务信息");
var dischargeFull = _taskPODDischargeGateoutFullInfoRep.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (dischargeFull == null)
throw Oops.Oh($"目的港未提货未返箱主键{taskPkId}无法获取业务信息");
var dischargeFullDetail = _taskPODDischargeGateoutFullDetailInfoRep.AsQueryable()
.Where(a => a.P_ID == dischargeFull.PK_ID).ToList();
list = dischargeFullDetail.Select(x => {
var dto = x.Adapt<TaskPODDischargeGateoutFullShowDto>();
dto.PKId = dischargeFull.PK_ID;
dto.TaskId = dischargeFull.TASK_ID;
dto.IsComplete = taskBase.IS_COMPLETE == 1 ? true : false;
dto.CompleteTime = taskBase.COMPLETE_DATE;
dto.NoticeType = dischargeFull.NOTICE_TYPE;
dto.NoticeTypeName = dischargeFull.NOTICE_TYPE_NAME;
return dto;
}).ToList();
return list;
}
#endregion
#region 推送及时消息
/// <summary>
/// 推送及时消息
/// </summary>
/// <param name="taskPkId">目的港未提货未返箱任务主键</param>
/// <returns>返回回执</returns>
[HttpGet("/PODDischargeGateoutFull/SendInstantMessage")]
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 dischargeFull = _taskPODDischargeGateoutFullInfoRep.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (dischargeFull == null)
throw Oops.Oh($"目的港未提货未返箱主键{taskPkId}无法获取业务信息");
var detailList = _taskPODDischargeGateoutFullDetailInfoRep.AsQueryable()
.Where(a => a.P_ID == dischargeFull.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 =>
{
string title = "目的港未提货消息";
if (dischargeFull.NOTICE_TYPE == "GATEOUT_FULL")
title = "提箱未返空箱消息";
DingTalkGroupHelper.SendDingTalkGroupMessage("KangqianNotify", title, $"@{t.Key} 收到如下提单号{(string.Join(",", t.Value.ToArray()))}的{title}消息");
});
}
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
#region 重新处理目的港未提货未返箱任务
/// <summary>
/// 重新处理目的港未提货未返箱任务
/// 对未匹配目的港未提货未返箱的任务记录重新对应订单
/// </summary>
/// <param name="taskPkId">目的港未提货未返箱任务主键</param>
/// <returns>返回回执</returns>
[HttpGet("/PODDischargeGateoutFull/SearchAndConnectBookingInfo")]
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 dischargeFull = _taskPODDischargeGateoutFullInfoRep.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
if (dischargeFull == null)
throw Oops.Oh($"目的港未提货未返箱主键{taskPkId}无法获取业务信息");
var detailList = _taskPODDischargeGateoutFullDetailInfoRep.AsQueryable()
.Where(a => a.P_ID == dischargeFull.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 _taskPODDischargeGateoutFullDetailInfoRep.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
}
}