|
|
using Furion;
|
|
|
using Furion.DependencyInjection;
|
|
|
using Furion.DynamicApiController;
|
|
|
using Furion.FriendlyException;
|
|
|
using Mapster;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
using Myshipping.Application.Entity;
|
|
|
using Myshipping.Application.Helper;
|
|
|
using Myshipping.Application.Service.TaskManagePlat.Interface;
|
|
|
using Myshipping.Core;
|
|
|
using Myshipping.Core.Entity;
|
|
|
using Myshipping.Core.Helper;
|
|
|
using MySqlX.XDevAPI.Common;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Reflection.Metadata.Ecma335;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
/// VGM任务
|
|
|
/// </summary>
|
|
|
[ApiDescriptionSettings("Application", Name = "TaskManageVGM", Order = 10)]
|
|
|
public class TaskManageVGMService: ITaskManageVGMService, IDynamicApiController, ITransient
|
|
|
{
|
|
|
private readonly SqlSugarRepository<TaskVGMInfo> _taskVGMInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskVGMCtnInfo> _taskVGMCtnInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
|
|
|
private readonly ILogger<TaskManageVGMService> _logger;
|
|
|
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
|
|
|
private readonly SqlSugarRepository<BookingCtn> _bookingOrderContaRepository;
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRepository;
|
|
|
|
|
|
public TaskManageVGMService(SqlSugarRepository<TaskVGMInfo> taskVGMInfoRepository,
|
|
|
SqlSugarRepository<TaskVGMCtnInfo> taskVGMCtnInfoRepository,
|
|
|
SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
|
|
|
SqlSugarRepository<BookingOrder> bookingOrderRepository,
|
|
|
SqlSugarRepository<BookingCtn> bookingOrderContaRepository,
|
|
|
SqlSugarRepository<SysUser> sysUserRepository,
|
|
|
ILogger<TaskManageVGMService> logger)
|
|
|
{
|
|
|
_taskVGMInfoRepository = taskVGMInfoRepository;
|
|
|
_taskVGMCtnInfoRepository = taskVGMCtnInfoRepository;
|
|
|
_taskBaseRepository = taskBaseRepository;
|
|
|
_logger = logger;
|
|
|
_bookingOrderRepository = bookingOrderRepository;
|
|
|
_bookingOrderContaRepository = bookingOrderContaRepository;
|
|
|
_sysUserRepository = sysUserRepository;
|
|
|
}
|
|
|
|
|
|
#region 获取VGM成功回执详情
|
|
|
/// <summary>
|
|
|
/// 获取VGM成功回执详情
|
|
|
/// </summary>
|
|
|
/// <param name="pkId">BC主键</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
[HttpGet("/TaskManageVGM/GetVGMSubmissionInfo")]
|
|
|
public async Task<List<TaskVGMShowDto>> GetVGMSubmissionInfo(string pkId)
|
|
|
{
|
|
|
List<TaskVGMShowDto> list = new List<TaskVGMShowDto>();
|
|
|
|
|
|
var vgmOrder = _taskVGMInfoRepository.AsQueryable().First(a => a.PK_ID == pkId);
|
|
|
|
|
|
if (vgmOrder == null)
|
|
|
throw Oops.Oh($"VGM主键{pkId}无法获取业务信息");
|
|
|
|
|
|
var CtnList = _taskVGMCtnInfoRepository.AsQueryable()
|
|
|
.Where(a => a.P_ID == pkId).ToList();
|
|
|
|
|
|
if (CtnList.Count > 0)
|
|
|
{
|
|
|
list = CtnList.OrderBy(p => p.P_ID).ThenBy(p => p.CNTRNO).Select(p =>
|
|
|
{
|
|
|
TaskVGMShowDto model = vgmOrder.Adapt<TaskVGMShowDto>();
|
|
|
|
|
|
model.CntrNo = p.CNTRNO;
|
|
|
model.VGMWeight = p.VGM_WEIGHT;
|
|
|
model.VGMWeightMethod = p.VGM_METHOD;
|
|
|
model.VGMWeightUnit = p.VGM_WEIGHT_UNIT;
|
|
|
|
|
|
return model;
|
|
|
}).ToList();
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 通过任务主键获取VGM成功回执详情
|
|
|
/// <summary>
|
|
|
/// 通过任务主键获取VGM成功回执详情
|
|
|
/// </summary>
|
|
|
/// <param name="taskPkId">VGM任务主键</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
[HttpGet("/TaskManageVGM/GetVGMSubmissionInfoByTaskId")]
|
|
|
public async Task<List<TaskVGMShowDto>> GetVGMSubmissionInfoByTaskId(string taskPkId)
|
|
|
{
|
|
|
List<TaskVGMShowDto> list = new List<TaskVGMShowDto>();
|
|
|
|
|
|
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId);
|
|
|
|
|
|
if (taskBase == null)
|
|
|
throw Oops.Oh($"任务主键{taskPkId}无法获取业务信息");
|
|
|
|
|
|
var vgmOrder = _taskVGMInfoRepository.AsQueryable().First(a => a.TASK_ID == taskBase.PK_ID);
|
|
|
|
|
|
if (vgmOrder == null)
|
|
|
throw Oops.Oh($"任务主键{taskPkId}无法获取VGM信息");
|
|
|
|
|
|
var CtnList = _taskVGMCtnInfoRepository.AsQueryable()
|
|
|
.Where(a => a.P_ID == vgmOrder.PK_ID).ToList();
|
|
|
|
|
|
if (CtnList.Count > 0)
|
|
|
{
|
|
|
list = CtnList.OrderBy(p => p.P_ID).ThenBy(p => p.CNTRNO).Select(p =>
|
|
|
{
|
|
|
TaskVGMShowDto model = vgmOrder.Adapt<TaskVGMShowDto>();
|
|
|
|
|
|
model.CntrNo = p.CNTRNO;
|
|
|
model.VGMWeight = p.VGM_WEIGHT;
|
|
|
model.VGMWeightMethod = p.VGM_METHOD;
|
|
|
model.VGMWeightUnit = p.VGM_WEIGHT_UNIT;
|
|
|
|
|
|
return model;
|
|
|
}).ToList();
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取VGM未提交详情
|
|
|
/// <summary>
|
|
|
/// 获取VGM未提交详情
|
|
|
/// </summary>
|
|
|
/// <param name="pkId">BC主键</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
[HttpGet("/TaskManageVGM/GetVGMMissingInfo")]
|
|
|
public async Task<List<TaskVGMShowDto>> GetVGMMissingInfo(string pkId)
|
|
|
{
|
|
|
List<TaskVGMShowDto> list = new List<TaskVGMShowDto>();
|
|
|
|
|
|
var vgmOrder = _taskVGMInfoRepository.AsQueryable().First(a => a.PK_ID == pkId);
|
|
|
|
|
|
if (vgmOrder == null)
|
|
|
throw Oops.Oh($"VGM主键{pkId}无法获取业务信息");
|
|
|
|
|
|
var CtnList = _taskVGMCtnInfoRepository.AsQueryable()
|
|
|
.Where(a => a.P_ID == pkId).ToList();
|
|
|
|
|
|
if (CtnList.Count > 0)
|
|
|
{
|
|
|
list = CtnList.OrderBy(p => p.P_ID).ThenBy(p => p.CNTRNO).Select(p =>
|
|
|
{
|
|
|
TaskVGMShowDto model = vgmOrder.Adapt<TaskVGMShowDto>();
|
|
|
|
|
|
model.CntrNo = p.CNTRNO;
|
|
|
model.VGMWeight = p.VGM_WEIGHT;
|
|
|
model.VGMWeightMethod = p.VGM_METHOD;
|
|
|
model.VGMWeightUnit = p.VGM_WEIGHT_UNIT;
|
|
|
|
|
|
return model;
|
|
|
}).ToList();
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 通过任务主键获取VGM未提交详情
|
|
|
/// <summary>
|
|
|
/// 通过任务主键获取VGM未提交详情
|
|
|
/// </summary>
|
|
|
/// <param name="taskPkId">VGM任务主键</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
[HttpGet("/TaskManageVGM/GetVGMMissingInfoByTaskId")]
|
|
|
public async Task<List<TaskVGMShowDto>> GetVGMMissingInfoByTaskId(string taskPkId)
|
|
|
{
|
|
|
List<TaskVGMShowDto> list = new List<TaskVGMShowDto>();
|
|
|
|
|
|
var taskBase = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPkId);
|
|
|
|
|
|
if (taskBase == null)
|
|
|
throw Oops.Oh($"任务主键{taskPkId}无法获取业务信息");
|
|
|
|
|
|
var vgmOrderList = _taskVGMInfoRepository.AsQueryable().Where(a => a.TASK_ID == taskBase.PK_ID).ToList();
|
|
|
|
|
|
if (vgmOrderList.Count == 0)
|
|
|
throw Oops.Oh($"任务主键{taskPkId}无法获取VGM信息");
|
|
|
|
|
|
var vgmPkList = vgmOrderList.Select(a => a.PK_ID).ToList();
|
|
|
|
|
|
var CtnList = _taskVGMCtnInfoRepository.AsQueryable()
|
|
|
.Where(a => vgmPkList.Contains(a.P_ID)).ToList();
|
|
|
|
|
|
if (CtnList.Count > 0)
|
|
|
{
|
|
|
vgmOrderList.ForEach(v => {
|
|
|
|
|
|
list.AddRange(CtnList.Where(p => p.P_ID == v.PK_ID).OrderBy(p => p.CNTRNO).Select(p =>
|
|
|
{
|
|
|
TaskVGMShowDto model = v.Adapt<TaskVGMShowDto>();
|
|
|
|
|
|
model.CntrNo = p.CNTRNO;
|
|
|
model.VGMWeight = p.VGM_WEIGHT;
|
|
|
model.VGMWeightMethod = p.VGM_METHOD;
|
|
|
model.VGMWeightUnit = p.VGM_WEIGHT_UNIT;
|
|
|
|
|
|
return model;
|
|
|
}).ToList());
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送VGM未提交通知(钉钉消息、邮件通知)
|
|
|
/// </summary>
|
|
|
/// <param name="taskPKId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/TaskManageVGM/SendVGMMissingNotice")]
|
|
|
public async Task<TaskManageOrderResultDto> SendVGMMissingNotice(string taskPKId)
|
|
|
{
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
string billnoMsg = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
/*
|
|
|
检索对应的订舱订单,提取相关人推送消息和
|
|
|
*/
|
|
|
var taskBase = _taskBaseRepository.AsQueryable().Filter(null, true).First(a => a.PK_ID == taskPKId && a.IsDeleted == false && a.TenantId == UserManager.TENANT_ID);
|
|
|
|
|
|
if (taskBase == null)
|
|
|
throw Oops.Oh($"任务主键{taskPKId}无法获取业务信息");
|
|
|
|
|
|
var vgmTaskList = _taskVGMInfoRepository.AsQueryable().Filter(null, true).Where(a => a.TASK_ID == taskPKId && a.IsDeleted == false && a.TenantId == UserManager.TENANT_ID).ToList();
|
|
|
|
|
|
if (vgmTaskList.Count == 0)
|
|
|
throw Oops.Oh($"VGM未提交通知任务主键{taskPKId}无法获取业务信息");
|
|
|
|
|
|
var blnoList = vgmTaskList.Select(a=>a.MBL_NO).Distinct().ToList();
|
|
|
|
|
|
//关联提单号
|
|
|
var bookList = _bookingOrderRepository.AsQueryable().Filter(null, true)
|
|
|
.Where(a => (blnoList.Contains(a.MBLNO) || a.SPLIT_OR_MERGE_FLAG != null && a.SPLIT_OR_MERGE_FLAG.Value == 1
|
|
|
&& blnoList.Contains(a.CUSTNO)) && a.IsDeleted == false && a.TenantId == UserManager.TENANT_ID).ToList();
|
|
|
|
|
|
if (bookList.Count == 0)
|
|
|
{
|
|
|
billnoMsg = (string.Join(",", blnoList.ToArray()));
|
|
|
|
|
|
throw Oops.Oh($"VGM任务主键{taskPKId} 提单号:{billnoMsg} 没有对应的订舱记录");
|
|
|
}
|
|
|
|
|
|
bookList.Select(a => new { Key = $"{a.VESSEL}/{(!string.IsNullOrWhiteSpace(a.VOYNO) ? a.VOYNO : a.VOYNOINNER)}", obj = a })
|
|
|
.GroupBy(a => a.Key).ToList()
|
|
|
.ForEach(async a =>
|
|
|
{
|
|
|
var bkList = a.Select(a=>a.obj).ToList();
|
|
|
|
|
|
var currBillNoList = bkList.Select(a=>a.MBLNO).Distinct().ToList();
|
|
|
|
|
|
if (bkList.Any(b => !string.IsNullOrWhiteSpace(b.CUSTNO)))
|
|
|
currBillNoList.AddRange(bkList.Select(a => a.CUSTNO).Distinct().ToList());
|
|
|
|
|
|
var taskVgmList = vgmTaskList.Where(b => currBillNoList.Contains(b.MBL_NO)).ToList();
|
|
|
|
|
|
await PushDingdingNotice(bkList, taskVgmList,taskPKId);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
_logger.LogInformation($"VGM未提交通知任务主键{taskPKId} 推送钉钉通知异常,相关提单号-{billnoMsg} 原因:{ex.Message}");
|
|
|
|
|
|
new EmailNoticeHelper().SendEmailNotice($"VGM未提交通知任务主键{taskPKId} 推送钉钉通知异常", $"VGM未提交通知任务主键{taskPKId} 推送钉钉通知异常,相关提单号-{billnoMsg} 原因:{ex.Message}", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
|
|
|
}
|
|
|
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private async Task PushDingdingNotice(List<BookingOrder> bookingOrderList, List<TaskVGMInfo> taskVgmList, string taskPKId)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var bookingInfo = bookingOrderList.FirstOrDefault();
|
|
|
|
|
|
var tenantId = bookingInfo.TenantId;
|
|
|
|
|
|
StringBuilder contentBuilder = new StringBuilder();
|
|
|
|
|
|
contentBuilder.AppendLine("起运港:" + bookingInfo.PORTLOAD);
|
|
|
contentBuilder.AppendLine("目的港:" + bookingInfo.PORTDISCHARGE);
|
|
|
contentBuilder.AppendLine("船名/航次:" + $"{bookingInfo.VESSEL}/{(!string.IsNullOrWhiteSpace(bookingInfo.VOYNO) ? bookingInfo.VOYNO : bookingInfo.VOYNOINNER)}");
|
|
|
contentBuilder.AppendLine("ETD:" + (bookingInfo.ETD.HasValue ? bookingInfo.ETD.Value.ToString("yyyy-MM-dd") : ""));
|
|
|
contentBuilder.AppendLine("船公司:" + bookingInfo.CARRIER);
|
|
|
contentBuilder.AppendLine("=================");
|
|
|
|
|
|
contentBuilder.AppendLine("提单号 |对应操作 ");
|
|
|
|
|
|
List<long> userIdList = new List<long>();
|
|
|
|
|
|
bookingOrderList.ForEach(t =>
|
|
|
{
|
|
|
if (!string.IsNullOrWhiteSpace(t.OPID))
|
|
|
userIdList.Add(long.Parse(t.OPID));
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(t.CUSTSERVICEID))
|
|
|
userIdList.Add(long.Parse(t.CUSTSERVICEID));
|
|
|
|
|
|
List<string> userNameList = new List<string>();
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(t.OP))
|
|
|
userNameList.Add(t.OP);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(t.CUSTSERVICE))
|
|
|
userNameList.Add(t.CUSTSERVICE);
|
|
|
|
|
|
|
|
|
string billno = t.MBLNO;
|
|
|
|
|
|
if (t.SPLIT_OR_MERGE_FLAG.HasValue && t.SPLIT_OR_MERGE_FLAG.Value == 2)
|
|
|
billno = t.CUSTNO;
|
|
|
|
|
|
|
|
|
contentBuilder.AppendLine($"{billno.PadRight(15, ' ')}|{(string.Join(",", userNameList.ToArray()).PadRight(40, ' '))}");
|
|
|
});
|
|
|
|
|
|
var userInfoList = _sysUserRepository.AsQueryable().Filter(null, true)
|
|
|
.Where(x => userIdList.Contains(x.Id) && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList();
|
|
|
|
|
|
var mobileArg = userInfoList.Select(p => p.Phone).Distinct().ToArray();
|
|
|
|
|
|
_logger.LogInformation($"准备钉钉通知,内容:\r\n{contentBuilder.ToString()}");
|
|
|
|
|
|
DingTalkGroupHelper.SendDingTalkGroupMessage($"{tenantId}_Notify", "VGM未提交通知提醒", $"{contentBuilder.ToString()}", false, mobileArg, null);
|
|
|
|
|
|
_logger.LogInformation($"钉钉通知完成");
|
|
|
|
|
|
taskVgmList.ForEach(async t =>
|
|
|
{
|
|
|
t.IS_DINGDING = true;
|
|
|
t.LST_SEND_DINGDING_DATE = DateTime.Now;
|
|
|
t.LST_SEND_STATUS = "SUCC";
|
|
|
|
|
|
await _taskVGMInfoRepository.AsUpdateable(t).UpdateColumns(p => new
|
|
|
{
|
|
|
p.IS_DINGDING,
|
|
|
p.LST_SEND_DINGDING_DATE,
|
|
|
t.LST_SEND_STATUS
|
|
|
}).ExecuteCommandAsync();
|
|
|
});
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
_logger.LogInformation($"VGM未提交通知任务主键{taskPKId} 推送钉钉通知异常 原因:{ex.Message}");
|
|
|
|
|
|
new EmailNoticeHelper().SendEmailNotice($"VGM未提交通知任务主键{taskPKId} 推送钉钉通知异常", $"VGM未提交通知任务主键{taskPKId} 推送钉钉通知异常 原因:{ex.Message}", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public async Task<TaskManageOrderResultDto> SyncBookingOrder()
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
}
|