|
|
@ -29,6 +29,14 @@ using StackExchange.Profiling.Internal;
|
|
|
|
using SqlSugar;
|
|
|
|
using SqlSugar;
|
|
|
|
using static Aliyun.OSS.Model.InventoryConfigurationModel;
|
|
|
|
using static Aliyun.OSS.Model.InventoryConfigurationModel;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
using MathNet.Numerics;
|
|
|
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
|
|
|
|
using HtmlAgilityPack;
|
|
|
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
|
|
using Myshipping.Application.ConfigOption;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -41,6 +49,9 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
private readonly SqlSugarRepository<BookingDeliveryRecord> _bookingDeliveryRecordRep;
|
|
|
|
private readonly SqlSugarRepository<BookingDeliveryRecord> _bookingDeliveryRecordRep;
|
|
|
|
private readonly SqlSugarRepository<BookingDeliveryRecordCtn> _bookingDeliveryRecordCtnRep;
|
|
|
|
private readonly SqlSugarRepository<BookingDeliveryRecordCtn> _bookingDeliveryRecordCtnRep;
|
|
|
|
private readonly SqlSugarRepository<BookingDeliveryRecordShipSchedule> _bookingDeliveryRecordShipScheduleRep;
|
|
|
|
private readonly SqlSugarRepository<BookingDeliveryRecordShipSchedule> _bookingDeliveryRecordShipScheduleRep;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingDeliveryRecordJobRun> _bookingDeliveryRecordJobRunScheduleRep;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<DjyUserMailAccount> _djyUserMailAccount;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRepository;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
|
|
|
|
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
|
|
|
@ -55,7 +66,8 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
public BookingMSKAPIService(ILogger<BookingMSKAPIService> logger, ISysCacheService cache,
|
|
|
|
public BookingMSKAPIService(ILogger<BookingMSKAPIService> logger, ISysCacheService cache,
|
|
|
|
IDjyWebsiteAccountConfigService webAccountConfig, SqlSugarRepository<BookingDeliveryRecord> bookingDeliveryRecordRep,
|
|
|
|
IDjyWebsiteAccountConfigService webAccountConfig, SqlSugarRepository<BookingDeliveryRecord> bookingDeliveryRecordRep,
|
|
|
|
ISysDataUserMenu sysDataUserMenuService,
|
|
|
|
ISysDataUserMenu sysDataUserMenuService,
|
|
|
|
SqlSugarRepository<BookingDeliveryRecordCtn> bookingDeliveryRecordCtnRep, SqlSugarRepository<BookingDeliveryRecordShipSchedule> bookingDeliveryRecordShipScheduleRep)
|
|
|
|
SqlSugarRepository<BookingDeliveryRecordCtn> bookingDeliveryRecordCtnRep, SqlSugarRepository<BookingDeliveryRecordShipSchedule> bookingDeliveryRecordShipScheduleRep,
|
|
|
|
|
|
|
|
SqlSugarRepository<DjyUserMailAccount> djyUserMailAccount, SqlSugarRepository<BookingDeliveryRecordJobRun> bookingDeliveryRecordJobRunScheduleRep)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
_cache = cache;
|
|
|
|
_cache = cache;
|
|
|
@ -64,6 +76,8 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
_bookingDeliveryRecordCtnRep = bookingDeliveryRecordCtnRep;
|
|
|
|
_bookingDeliveryRecordCtnRep = bookingDeliveryRecordCtnRep;
|
|
|
|
_sysDataUserMenuService = sysDataUserMenuService;
|
|
|
|
_sysDataUserMenuService = sysDataUserMenuService;
|
|
|
|
_bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep;
|
|
|
|
_bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep;
|
|
|
|
|
|
|
|
_djyUserMailAccount = djyUserMailAccount;
|
|
|
|
|
|
|
|
_bookingDeliveryRecordJobRunScheduleRep = bookingDeliveryRecordJobRunScheduleRep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 检索海运船期详情
|
|
|
|
#region 检索海运船期详情
|
|
|
@ -2293,5 +2307,212 @@ namespace Myshipping.Application.Service.BookingOrder
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 发送马士基订舱请求
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 发送马士基订舱请求
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="id">请求订舱ID</param>
|
|
|
|
|
|
|
|
/// <returns>返回检索结果</returns>
|
|
|
|
|
|
|
|
[HttpGet("/BookingMSKAPI/SendMSKBookingById")]
|
|
|
|
|
|
|
|
public async Task<MSKBookingResultDto> SendMSKBookingById(long id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var model = await GetInfo(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return await InnerSendMSKBooking(model, id, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new MSKBookingResultDto
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
succ = false,
|
|
|
|
|
|
|
|
msg = "预订舱信息不存在"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 生成订舱订舱报告邮件并自动转发
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 生成订舱订舱报告邮件并自动转发
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpGet("/BookingMSKAPI/GenerateTimerReportEmail")]
|
|
|
|
|
|
|
|
public async Task<string> GenerateTimerReportEmail()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime startDate = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var runList = _bookingDeliveryRecordJobRunScheduleRep.AsQueryable().Filter(null, true)
|
|
|
|
|
|
|
|
.Where(a => a.CreatedTime >= startDate && a.IsDeleted == false && a.IS_SEND_REPORT == false).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (runList.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var idList = runList.Select(a => a.RECORD_ID).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var orderList = _bookingDeliveryRecordRep.AsQueryable().Filter(null, true)
|
|
|
|
|
|
|
|
.Where(a => a.IsDeleted == false && idList.Contains(a.Id)).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
orderList.GroupBy(a => a.CreatedUserId.Value).ToList().ForEach(b =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var nextJobTime = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var nextOrder = _bookingDeliveryRecordRep.AsQueryable().Filter(null, true)
|
|
|
|
|
|
|
|
.Where(a => a.IsDeleted == false && a.JOB_TIME != null && a.JOB_TIME.Value >= nowDate && a.CreatedUserId == b.Key).OrderBy(a=>a.JOB_TIME.Value).First();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nextOrder != null)
|
|
|
|
|
|
|
|
nextJobTime = nextOrder.JOB_TIME.Value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var opUser = _sysUserRepository.AsQueryable().Filter(null, true).First(a => a.Id == b.Key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DjyUserMailAccount publicMailAccount = _djyUserMailAccount.AsQueryable().Filter(null, true).First(x => x.TenantId == opUser.TenantId && x.ShowName == "PublicSend"
|
|
|
|
|
|
|
|
&& x.SmtpPort > 0 && x.SmtpServer != null && x.SmtpServer != "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (publicMailAccount == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Oh($"提取公共邮箱配置失败,请在用户邮箱账号管理增加配置显示名为PublicSend或者配置个人邮箱");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string emailHtml = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var currList = b.OrderBy(t=>t.SEND_TIME.Value).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string templatePath = App.Configuration["EmailTemplateFilePath"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
|
|
|
var dirAbs = opt.basePath;
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
templatePath = $"{dirAbs}{templatePath}\\MSKAPITimerReportTemplate.html";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string baseHtml = File.ReadAllText(templatePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HtmlDocument html = new HtmlDocument();
|
|
|
|
|
|
|
|
html.LoadHtml(baseHtml);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#ReportTime#", nowDate.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#total#", currList.Count.ToString());
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#succ#", currList.Count(x=>x.STATUS == "SUCC").ToString());
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#failure#", currList.Count(x => x.STATUS == "FAILURE").ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nextJobTime != DateTime.MinValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#NextTime#", nextJobTime.ToString("yyyy-MM-dd HH:mm"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
baseHtml = baseHtml.Replace("#NextTime#", "");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tableNode = html.DocumentNode.SelectSingleNode(".//table[@id='show-table']");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tableNode != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StringBuilder tableBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < currList.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tableBuilder.Append($"<tr><td>{(currList[i].SEND_TIME.HasValue ? currList[i].SEND_TIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "")}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{currList[i].STATUS_NAME}</td><td>{currList[i].BOOKING_REFERENCE}</td><td>{currList[i].PLACERECEIPT}</td><td>{currList[i].PLACEDELIVERY}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{currList[i].CTN_STAT}</td><td>{(currList[i].ETD.HasValue ? currList[i].ETD.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{(currList[i].TOTAL_CARGO_WEIGHT.HasValue? currList[i].TOTAL_CARGO_WEIGHT.Value.ToString():"")}</td><td>{currList[i].PRICE_OWNER_REFERENCE}</td>");
|
|
|
|
|
|
|
|
tableBuilder.Append($"<td>{(currList[i].IS_RECV_BC ? "1" : "")}</td><td>{(currList[i].IS_RECV_BK_CANCEL ? "1" : "")}</td><td>{(currList[i].JOB_TIME.HasValue ? currList[i].JOB_TIME.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td></tr>");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//生成From Vessel的table列表
|
|
|
|
|
|
|
|
tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EmailApiUserDefinedDto emailApiUserDefinedDto = new EmailApiUserDefinedDto
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SendTo = opUser.Email,
|
|
|
|
|
|
|
|
//CCTo = opEmail,
|
|
|
|
|
|
|
|
Title = $"马士基API定时订舱统计报告 {nowDate.ToString("yyyy-MM-dd HH:mm:ss")}",
|
|
|
|
|
|
|
|
Body = emailHtml,
|
|
|
|
|
|
|
|
Account = publicMailAccount.MailAccount?.Trim(),
|
|
|
|
|
|
|
|
Password = publicMailAccount.Password?.Trim(),
|
|
|
|
|
|
|
|
Server = publicMailAccount.SmtpServer?.Trim(),
|
|
|
|
|
|
|
|
Port = publicMailAccount.SmtpPort.HasValue ? publicMailAccount.SmtpPort.Value : 465,
|
|
|
|
|
|
|
|
UseSSL = publicMailAccount.SmtpSSL.HasValue ? publicMailAccount.SmtpSSL.Value : true,
|
|
|
|
|
|
|
|
Attaches = new List<AttachesInfo>()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<EmailApiUserDefinedDto> emailList = new List<EmailApiUserDefinedDto>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var emailUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
|
|
|
|
|
|
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "email_api_url")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (emailUrl == null)
|
|
|
|
|
|
|
|
_logger.LogInformation("字典未配置 url_set->email_api_url 请联系管理员");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emailList.Add(emailApiUserDefinedDto);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//string strJoin = System.IO.File.ReadAllText(filePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponseMessage res = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
res = emailUrl.SetBody(emailList, "application/json").PostAsync().GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation($"发送邮件异常:{ex.Message}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
|
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"发送邮件返回:{JSON.Serialize(res)}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res != null && res.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var userResult = res.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var respObj = JsonConvert.DeserializeAnonymousType(userResult, new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Success = false,
|
|
|
|
|
|
|
|
Message = string.Empty,
|
|
|
|
|
|
|
|
Code = -9999,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(respObj.Success)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var updateList = currList.Join(runList, l => l.Id, r => r.RECORD_ID, (l, r) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var update in updateList) {
|
|
|
|
|
|
|
|
update.IS_SEND_REPORT = true;
|
|
|
|
|
|
|
|
update.REPORT_TIME = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_bookingDeliveryRecordJobRunScheduleRep.AsUpdateable(update).UpdateColumns(x => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
x.IS_SEND_REPORT,
|
|
|
|
|
|
|
|
x.REPORT_TIME
|
|
|
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|