|
|
@ -10,6 +10,7 @@ using Myshipping.Core.Entity;
|
|
|
|
using Myshipping.Core.Helper;
|
|
|
|
using Myshipping.Core.Helper;
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
|
using SqlSugar;
|
|
|
|
using SqlSugar;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
@ -45,8 +46,16 @@ namespace Myshipping.Application.EDI
|
|
|
|
return new KeyValuePair<bool, string>(false, "订舱信息未找到");
|
|
|
|
return new KeyValuePair<bool, string>(false, "订舱信息未找到");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var yardArr = new string[] { "GLJ", "GJF", "JIEFENG", "GANGLIANXIN", "ZHONGCHUANG" };
|
|
|
|
var ctns = repCtn.Where(c => c.BILLID == bookingId).ToList();
|
|
|
|
if (!yardArr.Contains(order.YARDID.ToUpper()))
|
|
|
|
|
|
|
|
|
|
|
|
var dictData = await cacheService.GetAllDictData();
|
|
|
|
|
|
|
|
var yardCodeSetList = dictData.Where(x => x.TypeCode == "XiaHuoZhiYardCodeSet").ToList(); //所有支持下货纸的场站代码配置
|
|
|
|
|
|
|
|
var gljEdiCarrierSetList = dictData.Where(x => x.TypeCode == "XiaHuoZhiGLJEdiCarrierSet").ToList();//港联捷通过EDI发送下货纸船司配置
|
|
|
|
|
|
|
|
var gljExcelMailCarrierSetList = dictData.Where(x => x.TypeCode == "XiaHuoZhiGLJExcelMailCarrierSet").ToList();//港联捷通过邮件Excel下货纸船司配置
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var yardArr = yardCodeSetList.Select(x => x.Value).ToArray();
|
|
|
|
|
|
|
|
if (!yardArr.Contains(order.YARDID))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new KeyValuePair<bool, string>(false, "不支持的场站");
|
|
|
|
return new KeyValuePair<bool, string>(false, "不支持的场站");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -72,119 +81,356 @@ namespace Myshipping.Application.EDI
|
|
|
|
fileOpt.basePath = App.WebHostEnvironment.WebRootPath;
|
|
|
|
fileOpt.basePath = App.WebHostEnvironment.WebRootPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 港联捷场站
|
|
|
|
var yardCodeGLJ = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGLJ");
|
|
|
|
if (order.YARDID == "GLJ")
|
|
|
|
if (yardCodeGLJ == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//租户参数-港联捷下货纸代号
|
|
|
|
return new KeyValuePair<bool, string>(false, "港联捷场站代码未配置");
|
|
|
|
var paraXHZ = (await cacheService.GetAllTenantParam()).FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "CODE_GLJ_XHZ");
|
|
|
|
}
|
|
|
|
if (paraXHZ == null || string.IsNullOrEmpty(paraXHZ.ItemCode))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"{order.TenantName} 港联捷场站 下货纸代号未找到或配置有误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ediFileName = $"{paraXHZ.ItemCode}_{order.MBLNO}_{DateTime.Now.Ticks}.txt";
|
|
|
|
var yardCodeGJF = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGJF");
|
|
|
|
var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName);
|
|
|
|
if (yardCodeGJF == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "港捷丰场站代码未配置");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var yardCodeJieFeng = yardCodeSetList.FirstOrDefault(x => x.Code == "YardJieFeng");
|
|
|
|
|
|
|
|
if (yardCodeJieFeng == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "捷丰场站代码未配置");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var yardCodeGLX = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGLX");
|
|
|
|
|
|
|
|
if (yardCodeGLX == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "港联欣站代码未配置");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var yardCodeZhongChuang = yardCodeSetList.FirstOrDefault(x => x.Code == "YardZhongChuang");
|
|
|
|
|
|
|
|
if (yardCodeZhongChuang == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "中创站代码未配置");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 港联捷场站
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (order.YARDID == yardCodeGLJ.Value)
|
|
|
|
|
|
|
|
{
|
|
|
|
var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath);
|
|
|
|
var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath);
|
|
|
|
var ediFileAbs = Path.Combine(ediPathAbs, ediFileName);
|
|
|
|
|
|
|
|
if (!Directory.Exists(ediPathAbs))
|
|
|
|
if (!Directory.Exists(ediPathAbs))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(ediPathAbs);
|
|
|
|
Directory.CreateDirectory(ediPathAbs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var ediSettints = await cacheService.GetAllEdiSetting();
|
|
|
|
|
|
|
|
var dicData = await cacheService.GetAllDictData();
|
|
|
|
|
|
|
|
//港联捷所有用户使用一个ftp用户名和密码发送报文,使用文件名中的下货纸代号进行区分
|
|
|
|
|
|
|
|
var paraServer = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "ftp_server");
|
|
|
|
|
|
|
|
var paraUser = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "username");
|
|
|
|
|
|
|
|
var paraPwd = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "pwd");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (paraServer == null || paraUser == null || paraPwd == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"港联捷下货纸FTP服务地址参数未配置");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sbData = new StringBuilder();
|
|
|
|
//通过EDI发送下货纸的船司
|
|
|
|
sbData.AppendLine($"01:{order.VESSEL}:{order.VOYNO}"); //船名 航次
|
|
|
|
if (gljEdiCarrierSetList.Select(x => x.Value).ToList().Contains(order.CARRIERID))
|
|
|
|
sbData.AppendLine($"12:{order.MBLNO}:{order.TRANSPORTID}:{order.PORTDISCHARGEID}:{paraXHZ.ItemCode}:{order.CARRIERID}::{ExchangeStr(order.YARDREMARK)}"); //主提单 中转港代码 目的港代码 货代代码 船公司 HPL参考号 备注
|
|
|
|
|
|
|
|
//2021-8-17,报文中不能体现英文字符①【:】②【,】,以空格代替
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 表象:QDAC064651 客户毛重28600 EDI进来28
|
|
|
|
|
|
|
|
港联捷回复:是前面货名太长,后面内容截断了,每行不超过255字符就行
|
|
|
|
|
|
|
|
解决方案:每行不超过255,品名只取前100就行
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var despStr = ExchangeStr(order.DESCRIPTION.Replace(":", " ").Replace(",", " ")).Replace("\r\n", " ").Replace("\n", " ");
|
|
|
|
|
|
|
|
if (despStr.Length > 100)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
despStr = despStr.Substring(0, 100);
|
|
|
|
//租户参数-港联捷下货纸代号
|
|
|
|
}
|
|
|
|
var paraXHZ = (await cacheService.GetAllTenantParam()).FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "CODE_GLJ_XHZ");
|
|
|
|
|
|
|
|
if (paraXHZ == null || string.IsNullOrEmpty(paraXHZ.ItemCode))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"{order.TenantName} 港联捷场站 下货纸代号未找到或配置有误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sbData.AppendLine($"22:{despStr}:{order.PKGS}:{order.KINDPKGS}:{order.KGS}:{order.CBM}:{(order.CARGOID == "D" ? "Y" : "N")}:{order.DCLASS}:{order.DUNNO}::{order.TEMPSET}:{order.REEFERF}:{order.HUMIDITY}");//货名 件数 包装代码 总重量 总体积 危品标志 危品等级 危规号 副危品等级 副危规号 温度 通风度 湿度
|
|
|
|
var ediFileName = $"{paraXHZ.ItemCode}_{order.MBLNO}_{DateTime.Now.Ticks}.txt";
|
|
|
|
|
|
|
|
var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName);
|
|
|
|
|
|
|
|
var ediFileAbs = Path.Combine(ediPathAbs, ediFileName);
|
|
|
|
|
|
|
|
var ediSettints = await cacheService.GetAllEdiSetting();
|
|
|
|
|
|
|
|
var dicData = await cacheService.GetAllDictData();
|
|
|
|
|
|
|
|
//港联捷所有用户使用一个ftp用户名和密码发送报文,使用文件名中的下货纸代号进行区分
|
|
|
|
|
|
|
|
var paraServer = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "ftp_server");
|
|
|
|
|
|
|
|
var paraUser = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "username");
|
|
|
|
|
|
|
|
var paraPwd = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "pwd");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (paraServer == null || paraUser == null || paraPwd == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"港联捷下货纸FTP服务地址参数未配置");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList();
|
|
|
|
StringBuilder sbData = new StringBuilder();
|
|
|
|
var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLJ").ToList();
|
|
|
|
sbData.AppendLine($"01:{order.VESSEL}:{order.VOYNO}"); //船名 航次
|
|
|
|
|
|
|
|
sbData.AppendLine($"12:{order.MBLNO}:{order.TRANSPORTID}:{order.PORTDISCHARGEID}:{paraXHZ.ItemCode}:{order.CARRIERID}::{ExchangeStr(order.YARDREMARK)}"); //主提单 中转港代码 目的港代码 货代代码 船公司 HPL参考号 备注
|
|
|
|
|
|
|
|
//2021-8-17,报文中不能体现英文字符①【:】②【,】,以空格代替
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 表象:QDAC064651 客户毛重28600 EDI进来28
|
|
|
|
|
|
|
|
港联捷回复:是前面货名太长,后面内容截断了,每行不超过255字符就行
|
|
|
|
|
|
|
|
解决方案:每行不超过255,品名只取前100就行
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var despStr = ExchangeStr(order.DESCRIPTION.Replace(":", " ").Replace(",", " ")).Replace("\r\n", " ").Replace("\n", " ");
|
|
|
|
|
|
|
|
if (despStr.Length > 100)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
despStr = despStr.Substring(0, 100);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ctns = repCtn.Where(c => c.BILLID == bookingId).ToList();
|
|
|
|
sbData.AppendLine($"22:{despStr}:{order.PKGS}:{order.KINDPKGS}:{order.KGS}:{order.CBM}:{(order.CARGOID == "D" ? "Y" : "N")}:{order.DCLASS}:{order.DUNNO}::{order.TEMPSET}:{order.REEFERF}:{order.HUMIDITY}");//货名 件数 包装代码 总重量 总体积 危品标志 危品等级 危规号 副危品等级 副危规号 温度 通风度 湿度
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
|
|
|
|
{
|
|
|
|
var ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList();
|
|
|
|
var ctnFind = ctnCodes.FirstOrDefault(c => c.Code == ctn.CTNCODE);
|
|
|
|
var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLJ").ToList();
|
|
|
|
if (ctnFind == null)
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new KeyValuePair<bool, string>(false, $"未找到箱型 {ctn.CTNALL},请联系管理员");
|
|
|
|
var ctnFind = ctnCodes.FirstOrDefault(c => c.Code == ctn.CTNCODE);
|
|
|
|
|
|
|
|
if (ctnFind == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"未找到箱型 {ctn.CTNALL},请联系管理员");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ctnEdi = ctnEdiList.FirstOrDefault(cc => cc.Code == ctn.CTNCODE);
|
|
|
|
|
|
|
|
if (ctnEdi == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"箱型({ctn.CTNALL})不匹配(EDI类型:XHZ_GLJ),无法发送下货纸,请联系管理员");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sbData.AppendLine($"13:{(order.ISCONTAINERSOC.HasValue && order.ISCONTAINERSOC.Value ? "SOC" : order.CARRIERID)}:{ctnFind.Size}:{ctnEdi.MapCode}:{ctn.CTNNUM}:{ExchangeStr(ctn.REMARK)}:N");//箱经营人代码 尺寸 箱型 箱数 备注 加重箱
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ctnEdi = ctnEdiList.FirstOrDefault(cc => cc.Code == ctn.CTNCODE);
|
|
|
|
Log.Information($"生成下货纸报文:{sbData.ToString()}");
|
|
|
|
if (ctnEdi == null)
|
|
|
|
File.WriteAllText(ediFileAbs, sbData.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//挂载附件
|
|
|
|
|
|
|
|
var attFile = new BookingFile();
|
|
|
|
|
|
|
|
attFile.BookingId = order.Id;
|
|
|
|
|
|
|
|
attFile.FileName = ediFileName;
|
|
|
|
|
|
|
|
attFile.FilePath = ediFileRela;
|
|
|
|
|
|
|
|
attFile.TypeCode = "xiahuozhi";
|
|
|
|
|
|
|
|
attFile.TypeName = "下货纸";
|
|
|
|
|
|
|
|
attFile.TenantName = order.TenantName;
|
|
|
|
|
|
|
|
repBookingFile.Insert(attFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送ftp
|
|
|
|
|
|
|
|
SplitFtpServerAndPort(paraServer.Value, out string server, out int port);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ftpSpiderUrl = dicData.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "booking_edi_ftp_server").Value;
|
|
|
|
|
|
|
|
NameValueCollection par = new NameValueCollection();
|
|
|
|
|
|
|
|
par.Add("host", server);
|
|
|
|
|
|
|
|
par.Add("port", port.ToString());
|
|
|
|
|
|
|
|
par.Add("username", paraUser.Value);
|
|
|
|
|
|
|
|
par.Add("pwd", paraPwd.Value);
|
|
|
|
|
|
|
|
par.Add("path", "/");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.Information($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{par.ToJsonString()},文件:{ediFileName}");
|
|
|
|
|
|
|
|
var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new KeyValuePair<bool, string>(false, $"箱型({ctn.CTNALL})不匹配(EDI类型:XHZ_GLJ),无法发送下货纸,请联系管理员");
|
|
|
|
file = "file",
|
|
|
|
|
|
|
|
fileName = Path.GetFileName(ediFileName),
|
|
|
|
|
|
|
|
fileBytes = Encoding.UTF8.GetBytes(sbData.ToString())
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Log.Information($"发送ftp返回:{res}");
|
|
|
|
|
|
|
|
var jobjRetn = JObject.Parse(res);
|
|
|
|
|
|
|
|
if (jobjRetn.GetStringValue("status") != "1")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"ftp发送失败:{jobjRetn.GetStringValue("message")}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sbData.AppendLine($"13:{(order.ISCONTAINERSOC.HasValue && order.ISCONTAINERSOC.Value ? "SOC" : order.CARRIERID)}:{ctnFind.Size}:{ctnEdi.MapCode}:{ctn.CTNNUM}:{ExchangeStr(ctn.REMARK)}:N");//箱经营人代码 尺寸 箱型 箱数 备注 加重箱
|
|
|
|
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(true, $"已发送");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//通过邮件发送Excel的船司
|
|
|
|
|
|
|
|
else if (gljExcelMailCarrierSetList.Select(x => x.Value).ToList().Contains(order.CARRIERID))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ediFileName = $"{order.CARRIERID}_{order.VESSEL}_{order.VOYNO}_{DateTime.Now.Ticks}.xls";
|
|
|
|
|
|
|
|
var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName);
|
|
|
|
|
|
|
|
var ediFileAbs = Path.Combine(ediPathAbs, ediFileName);
|
|
|
|
|
|
|
|
|
|
|
|
Log.Information($"生成下货纸报文:{sbData.ToString()}");
|
|
|
|
var templateFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XhzGljTemplate.xls");
|
|
|
|
File.WriteAllText(ediFileAbs, sbData.ToString());
|
|
|
|
if (!File.Exists(templateFile))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"模板EXCEL文件未找到,请联系管理员");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//挂载附件
|
|
|
|
if (string.IsNullOrEmpty(order.YARDCONTRACTEMAIL))
|
|
|
|
var attFile = new BookingFile();
|
|
|
|
{
|
|
|
|
attFile.BookingId = order.Id;
|
|
|
|
return new KeyValuePair<bool, string>(false, $"场站联系人邮箱未填写");
|
|
|
|
attFile.FileName = ediFileName;
|
|
|
|
}
|
|
|
|
attFile.FilePath = ediFileRela;
|
|
|
|
|
|
|
|
attFile.TypeCode = "xiahuozhi";
|
|
|
|
|
|
|
|
attFile.TypeName = "下货纸";
|
|
|
|
|
|
|
|
attFile.TenantName = order.TenantName;
|
|
|
|
|
|
|
|
repBookingFile.Insert(attFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送ftp
|
|
|
|
var userMail = repUserMail.FirstOrDefault(x => x.CreatedUserId == order.CreatedUserId);
|
|
|
|
SplitFtpServerAndPort(paraServer.Value, out string server, out int port);
|
|
|
|
if (userMail == null
|
|
|
|
|
|
|
|
|| string.IsNullOrEmpty(userMail.SmtpServer)
|
|
|
|
|
|
|
|
|| userMail.SmtpPort == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"发件邮箱未配置");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ftpSpiderUrl = dicData.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "booking_edi_ftp_server").Value;
|
|
|
|
MemoryStream ms = new MemoryStream(File.ReadAllBytes(templateFile));
|
|
|
|
NameValueCollection par = new NameValueCollection();
|
|
|
|
var workbook = new HSSFWorkbook(ms);
|
|
|
|
par.Add("host", server);
|
|
|
|
var sheet = workbook.GetSheetAt(0);
|
|
|
|
par.Add("port", port.ToString());
|
|
|
|
|
|
|
|
par.Add("username", paraUser.Value);
|
|
|
|
|
|
|
|
par.Add("pwd", paraPwd.Value);
|
|
|
|
|
|
|
|
par.Add("path", "/");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.Information($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{par.ToJsonString()},文件:{ediFileName}");
|
|
|
|
//第一行标题
|
|
|
|
var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new
|
|
|
|
var title = $"下货纸清单-{order.LANENAME} SERVICE";
|
|
|
|
{
|
|
|
|
sheet.GetRow(0).GetCell(0).SetCellValue(title);
|
|
|
|
file = "file",
|
|
|
|
|
|
|
|
fileName = Path.GetFileName(ediFileName),
|
|
|
|
//船期B2
|
|
|
|
fileBytes = Encoding.UTF8.GetBytes(sbData.ToString())
|
|
|
|
sheet.GetRow(1).GetCell(1).SetCellValue(order.ETD.HasValue ? order.ETD.Value.ToString("yyyy.MM.dd") : "");
|
|
|
|
});
|
|
|
|
|
|
|
|
Log.Information($"发送ftp返回:{res}");
|
|
|
|
//船名B3
|
|
|
|
var jobjRetn = JObject.Parse(res);
|
|
|
|
sheet.GetRow(2).GetCell(1).SetCellValue(order.VESSEL);
|
|
|
|
if (jobjRetn.GetStringValue("status") != "1")
|
|
|
|
|
|
|
|
|
|
|
|
//航次F3
|
|
|
|
|
|
|
|
sheet.GetRow(2).GetCell(5).SetCellValue(order.VOYNO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//代理B4
|
|
|
|
|
|
|
|
sheet.GetRow(3).GetCell(1).SetCellValue(order.TenantName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//联系电话F4
|
|
|
|
|
|
|
|
var usr = repUser.AsQueryable().Filter(null, true).First(u => u.Id == order.CreatedUserId);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(usr.Tel))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(3).GetCell(5).SetCellValue(usr.Tel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!string.IsNullOrEmpty(usr.Phone))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(3).GetCell(5).SetCellValue(usr.Phone);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(3).GetCell(5).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//订舱号B7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(1).SetCellValue(order.CUSTNO);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//目的港C7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(2).SetCellValue(order.PORTDISCHARGE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//中转港D7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(3).SetCellValue(order.TRANSPORTID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//货名E7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(4).SetCellValue(order.DESCRIPTION);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//件数F7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(5).SetCellValue(order.PKGS.Value.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//重量G7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(6).SetCellValue(Convert.ToDouble(order.KGS.Value).ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//尺码H7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(7).SetCellValue(Convert.ToDouble(order.CBM.Value).ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//冻柜信息 温度C I7
|
|
|
|
|
|
|
|
if (order.CARGOID == "R")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(8).SetCellValue(order.TEMPSET);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(8).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//冻柜信息 通风CBM/H J7
|
|
|
|
|
|
|
|
if (order.CARGOID == "R")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(9).SetCellValue(order.REEFERF);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(9).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//冻柜信息 湿度% K7
|
|
|
|
|
|
|
|
if (order.CARGOID == "R")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(10).SetCellValue(order.HUMIDITY);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(10).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//整理箱型箱量
|
|
|
|
|
|
|
|
var groupList = ctns.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => new { CTNALL = g.Key.Replace("'", ""), CTNNUM = g.Sum(gg => gg.CTNNUM) });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//箱量 20GP L7
|
|
|
|
|
|
|
|
var findCtn = groupList.FirstOrDefault(x => x.CTNALL == "20GP");
|
|
|
|
|
|
|
|
if (findCtn != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(11).SetCellValue(findCtn.CTNNUM.Value.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(11).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//箱量 40GP M7
|
|
|
|
|
|
|
|
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40GP");
|
|
|
|
|
|
|
|
if (findCtn != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(12).SetCellValue(findCtn.CTNNUM.Value.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(12).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//箱量 40HC N7
|
|
|
|
|
|
|
|
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40HC");
|
|
|
|
|
|
|
|
if (findCtn != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(13).SetCellValue(findCtn.CTNNUM.Value.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(13).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//箱量 20RF O7
|
|
|
|
|
|
|
|
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "20RF");
|
|
|
|
|
|
|
|
if (findCtn != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(14).SetCellValue(findCtn.CTNNUM.Value.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(14).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//箱量 40RH P7
|
|
|
|
|
|
|
|
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40RH");
|
|
|
|
|
|
|
|
if (findCtn != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(15).SetCellValue(findCtn.CTNNUM.Value.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(15).SetCellValue("");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//备注 场站/特殊要求 Q7
|
|
|
|
|
|
|
|
sheet.GetRow(6).GetCell(16).SetCellValue(order.YARDREMARK);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MemoryStream msResult = new MemoryStream();
|
|
|
|
|
|
|
|
workbook.Write(msResult);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File.WriteAllBytes(ediFileAbs, msResult.GetBuffer());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//挂载附件
|
|
|
|
|
|
|
|
var attFile = new BookingFile();
|
|
|
|
|
|
|
|
attFile.BookingId = order.Id;
|
|
|
|
|
|
|
|
attFile.FileName = ediFileName;
|
|
|
|
|
|
|
|
attFile.FilePath = ediFileRela;
|
|
|
|
|
|
|
|
attFile.TypeCode = "xiahuozhi";
|
|
|
|
|
|
|
|
attFile.TypeName = "下货纸";
|
|
|
|
|
|
|
|
attFile.TenantName = order.TenantName;
|
|
|
|
|
|
|
|
repBookingFile.Insert(attFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送邮件
|
|
|
|
|
|
|
|
var sendResult = await MailSendHelper.SendMail(userMail, title, "", order.YARDCONTRACTEMAIL,new KeyValuePair<string, byte[]>(ediFileName, msResult.GetBuffer()));
|
|
|
|
|
|
|
|
if (!sendResult.Key)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(false, sendResult.Value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(true, $"已发送");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new KeyValuePair<bool, string>(false, $"ftp发送失败:{jobjRetn.GetStringValue("message")}");
|
|
|
|
return new KeyValuePair<bool, string>(false, "该船司不支持发送港联捷下货纸");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(true, $"已发送");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 港捷丰场站 捷丰场站 NOTE:港捷丰场站和捷丰场站下货纸功能,根据东胜7同功能模块代码翻译而来
|
|
|
|
#region 港捷丰场站 捷丰场站 NOTE:港捷丰场站和捷丰场站下货纸功能,根据东胜7同功能模块代码翻译而来
|
|
|
|
else if (order.YARDID == "GJF" || order.YARDID == "JIEFENG")
|
|
|
|
|
|
|
|
|
|
|
|
else if (order.YARDID == yardCodeGJF.Value || order.YARDID == yardCodeJieFeng.Value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!order.PKGS.HasValue || order.PKGS.Value == 0)
|
|
|
|
if (!order.PKGS.HasValue || order.PKGS.Value == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -216,11 +462,11 @@ namespace Myshipping.Application.EDI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DjyEdiSetting ftpset = null;
|
|
|
|
DjyEdiSetting ftpset = null;
|
|
|
|
if (order.YARDID == "GJF")
|
|
|
|
if (order.YARDID == yardCodeGJF.Value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GJF" && f.TenantId == order.TenantId);
|
|
|
|
ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GJF" && f.TenantId == order.TenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (order.YARDID == "JIEFENG")
|
|
|
|
else if (order.YARDID == yardCodeJieFeng.Value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_JIEFENG" && f.TenantId == order.TenantId);
|
|
|
|
ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_JIEFENG" && f.TenantId == order.TenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -231,7 +477,7 @@ namespace Myshipping.Application.EDI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ediParaName = "XHZ_GJF";
|
|
|
|
var ediParaName = "XHZ_GJF";
|
|
|
|
if (order.YARDID == "JIEFENG")
|
|
|
|
if (order.YARDID == yardCodeJieFeng.Value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ediParaName = "XHZ_JIEFENG";
|
|
|
|
ediParaName = "XHZ_JIEFENG";
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -386,7 +632,6 @@ namespace Myshipping.Application.EDI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//集装箱
|
|
|
|
//集装箱
|
|
|
|
var ctns = repCtn.Where(c => c.BILLID == bookingId).ToList();
|
|
|
|
|
|
|
|
var groupList = ctns.Where(c => c.CTNNUM.HasValue).GroupBy(c => c.CTNCODE).Select(c => new { c.Key, CTNNUM = c.Sum(cc => cc.CTNNUM) }).ToList();
|
|
|
|
var groupList = ctns.Where(c => c.CTNNUM.HasValue).GroupBy(c => c.CTNCODE).Select(c => new { c.Key, CTNNUM = c.Sum(cc => cc.CTNNUM) }).ToList();
|
|
|
|
foreach (var g in groupList)
|
|
|
|
foreach (var g in groupList)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -450,12 +695,12 @@ namespace Myshipping.Application.EDI
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 港联欣场站
|
|
|
|
#region 港联欣场站
|
|
|
|
else if (order.YARDID.ToUpper() == "GANGLIANXIN" || order.YARDID.ToUpper() == "ZHONGCHUANG")
|
|
|
|
else if (order.YARDID == yardCodeGLX.Value || order.YARDID == yardCodeZhongChuang.Value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//2022年6月15日增加:港联欣场站若配置了通过港联捷EDI发送,则使用港联捷报文格式
|
|
|
|
//2022年6月15日增加:港联欣场站若配置了通过港联捷EDI发送,则使用港联捷报文格式
|
|
|
|
var tenantParam = await cacheService.GetAllTenantParam();
|
|
|
|
var tenantParam = await cacheService.GetAllTenantParam();
|
|
|
|
var pGlxEdi = tenantParam.FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "XIAHUOZHI_GLX_SEND_TYPE");
|
|
|
|
var pGlxEdi = tenantParam.FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "XIAHUOZHI_GLX_SEND_TYPE");
|
|
|
|
if (order.YARDID.ToUpper() == "GANGLIANXIN" && pGlxEdi != null && pGlxEdi.ItemCode == "EDI_GLX")
|
|
|
|
if (order.YARDID == yardCodeGLX.Value && pGlxEdi != null && pGlxEdi.ItemCode == "EDI_GLX")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GLX" && f.TenantId == order.TenantId);
|
|
|
|
var ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GLX" && f.TenantId == order.TenantId);
|
|
|
|
if (ftpset == null)
|
|
|
|
if (ftpset == null)
|
|
|
@ -492,7 +737,6 @@ namespace Myshipping.Application.EDI
|
|
|
|
var ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList();
|
|
|
|
var ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList();
|
|
|
|
var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLX").ToList();
|
|
|
|
var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLX").ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var ctns = repCtn.Where(c => c.BILLID == bookingId).ToList();
|
|
|
|
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var ctnFind = ctnCodes.FirstOrDefault(c => c.Code == ctn.CTNCODE);
|
|
|
|
var ctnFind = ctnCodes.FirstOrDefault(c => c.Code == ctn.CTNCODE);
|
|
|
|