|
|
|
|
using Furion;
|
|
|
|
|
using Furion.Logging;
|
|
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Myshipping.Application.ConfigOption;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Application.Helper;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
|
using Myshipping.Core.Helper;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using Myshipping.Core.Service.Dict.Dto;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application.EDI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下货纸辅助类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class XiahuozhiHelpler
|
|
|
|
|
{
|
|
|
|
|
private static readonly string EdiFilePath = "XHZ";
|
|
|
|
|
|
|
|
|
|
public static async Task<KeyValuePair<bool, string>> Send(
|
|
|
|
|
long bookingId, string filerole)
|
|
|
|
|
{
|
|
|
|
|
var repUser = App.GetService<SqlSugarRepository<SysUser>>();
|
|
|
|
|
var repOrder = App.GetService<SqlSugarRepository<BookingOrder>>();
|
|
|
|
|
var repCtn = App.GetService<SqlSugarRepository<BookingCtn>>();
|
|
|
|
|
var repBookingFile = App.GetService<SqlSugarRepository<BookingFile>>();
|
|
|
|
|
var repUserMail = App.GetService<SqlSugarRepository<DjyUserMailAccount>>();
|
|
|
|
|
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
|
|
|
|
|
var order = repOrder.FirstOrDefault(o => o.Id == bookingId);
|
|
|
|
|
if (order == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "订舱信息未找到");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ctns = repCtn.Where(c => c.BILLID == bookingId).ToList();
|
|
|
|
|
|
|
|
|
|
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 mappingCarrierAll = await cacheService.GetAllMappingCarrier();
|
|
|
|
|
var mappingCarrierLetterYard = mappingCarrierAll.Where(x => x.Module == "LetterYardCarrier").ToList(); //针对和川这种公共库不同的船司代码,需要匹配
|
|
|
|
|
|
|
|
|
|
var yardArr = yardCodeSetList.Select(x => x.Value).ToArray();
|
|
|
|
|
if (!yardArr.Contains(order.YARDID))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "不支持的场站");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(order.MBLNO))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "主提单号不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(order.VESSEL))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "船名不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(order.VOYNO))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "海关航次不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (order.CARGOID == "R")
|
|
|
|
|
{
|
|
|
|
|
//2023年10月11日,下货纸“货物标志”为“冻柜”时,对部分字段做校验
|
|
|
|
|
Regex regexSign = new Regex("^[-+]?([1-9][0-9]*|0)(\\.[0-9]+)?$");
|
|
|
|
|
if (!regexSign.IsMatch(order.TEMPSET))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "冻柜的【设置温度】校验不通过,要求:必填、数字格式、可包含+或-");
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(order.TEMPMIN) && !regexSign.IsMatch(order.TEMPMIN))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "冻柜的【最低温度】校验不通过,要求:非必填、数字格式、可包含+或-");
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(order.TEMPMAX) && !regexSign.IsMatch(order.TEMPMAX))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "冻柜的【最高温度】校验不通过,要求:非必填、数字格式、可包含+或-");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Regex regex = new Regex("^([1-9][0-9]*|0)(\\.[0-9]+)?$");
|
|
|
|
|
if (!regex.IsMatch(order.HUMIDITY))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "冻柜的【湿度】校验不通过,要求:必填(无要求可以填0)、数字格式、不能含有+或-");
|
|
|
|
|
}
|
|
|
|
|
if (!regex.IsMatch(order.REEFERF))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "冻柜的【冷藏通风量】校验不通过,要求:必填、数字格式、不能含有+或-");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//增加货描里的温度、湿度、通风与单个填写项的比对,必需一致才能提交 2024-04-17 JHQ
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2023年7月12日,下货纸为危险品时,需填写等级和编号
|
|
|
|
|
if (order.CARGOID == "D" && (string.IsNullOrEmpty(order.DUNNO) || string.IsNullOrEmpty(order.DCLASS)))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "危险品的等级和编号必须填写");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fileOpt = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
if (string.IsNullOrEmpty(fileOpt.basePath))
|
|
|
|
|
{
|
|
|
|
|
fileOpt.basePath = App.WebHostEnvironment.WebRootPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var yardCodeGLJ = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGLJ");
|
|
|
|
|
if (yardCodeGLJ == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "港联捷场站代码未配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var yardCodeGJF = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGJF");
|
|
|
|
|
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, "中创站代码未配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//针对和川这种公共库不同的船司代码,需要匹配转换为当前的船司代码才能逻辑判断
|
|
|
|
|
var hlcCode = "HLC";
|
|
|
|
|
var mapCodeHLC = mappingCarrierLetterYard.FirstOrDefault(x => x.MapCode == "HLC");
|
|
|
|
|
if (mapCodeHLC != null)
|
|
|
|
|
{
|
|
|
|
|
hlcCode = mapCodeHLC.Code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 港联捷场站
|
|
|
|
|
|
|
|
|
|
if (order.YARDID == yardCodeGLJ.Value)
|
|
|
|
|
{
|
|
|
|
|
var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath);
|
|
|
|
|
if (!Directory.Exists(ediPathAbs))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(ediPathAbs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//通过EDI发送下货纸的船司
|
|
|
|
|
if (gljEdiCarrierSetList.Select(x => x.Value).ToList().Contains(order.CARRIERID))
|
|
|
|
|
{
|
|
|
|
|
//租户参数-港联捷下货纸代号
|
|
|
|
|
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 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服务地址参数未配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder sbData = new StringBuilder();
|
|
|
|
|
sbData.AppendLine($"01:{order.VESSEL}:{order.VOYNO}"); //船名 航次
|
|
|
|
|
|
|
|
|
|
// 12:提单号:中转港:目的港:货代代码:船公司:HPL参考号:特殊说明
|
|
|
|
|
sbData.AppendLine($"12:{order.MBLNO}:{order.TRANSPORTID}:{GetMappingPortDischarge(order.PORTDISCHARGEID, "XHZ_GLJ")}:{paraXHZ.ItemCode}:{GetCarrierEDICode(order.CARRIERID, "XHZ_GLJ")}:{(order.CARRIERID == hlcCode ? order.CUSTNO : "")}:{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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//22:货名:件数:包装:重量:体积:危品标志:危品等级:危规号:副危品等级:副危规号:海污:温度:通风:湿度
|
|
|
|
|
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 ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList();
|
|
|
|
|
var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLJ").ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
|
{
|
|
|
|
|
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" : GetCtnForCarrier(order.CARRIERID, "XHZ_GLJ", dictData))}:{ctnFind.Size}:{ctnEdi.MapCode}:{ctn.CTNNUM}:{ExchangeStr(ctn.REMARK)}:N");//箱经营人代码 尺寸 箱型 箱数 备注 加重箱
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.Information($"生成下货纸报文:{sbData.ToString()}");
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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")}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
var templateFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XhzGljTemplate.xls");
|
|
|
|
|
if (!File.Exists(templateFile))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"模板EXCEL文件未找到,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(order.YARDCONTRACTEMAIL))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"场站联系人邮箱未填写");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userMail = repUserMail.FirstOrDefault(x => x.CreatedUserId == order.CreatedUserId);
|
|
|
|
|
if (userMail == null
|
|
|
|
|
|| string.IsNullOrEmpty(userMail.SmtpServer)
|
|
|
|
|
|| userMail.SmtpPort == 0)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"发件邮箱未配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemoryStream ms = new MemoryStream(File.ReadAllBytes(templateFile));
|
|
|
|
|
var workbook = new HSSFWorkbook(ms);
|
|
|
|
|
var sheet = workbook.GetSheetAt(0);
|
|
|
|
|
|
|
|
|
|
//第一行标题
|
|
|
|
|
var title = $"下货纸清单-{order.LANENAME} SERVICE";
|
|
|
|
|
sheet.GetRow(0).GetCell(0).SetCellValue(title);
|
|
|
|
|
|
|
|
|
|
//船期B2
|
|
|
|
|
sheet.GetRow(1).GetCell(1).SetCellValue(order.ETD.HasValue ? order.ETD.Value.ToString("yyyy.MM.dd") : "");
|
|
|
|
|
|
|
|
|
|
//船名B3
|
|
|
|
|
sheet.GetRow(2).GetCell(1).SetCellValue(order.VESSEL);
|
|
|
|
|
|
|
|
|
|
//航次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, "该船司不支持发送港联捷下货纸");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 港捷丰场站 捷丰场站 NOTE:港捷丰场站和捷丰场站下货纸功能,根据东胜7同功能模块代码翻译而来
|
|
|
|
|
|
|
|
|
|
else if (order.YARDID == yardCodeGJF.Value || order.YARDID == yardCodeJieFeng.Value)
|
|
|
|
|
{
|
|
|
|
|
if (!order.PKGS.HasValue || order.PKGS.Value == 0)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"件数不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(order.KINDPKGS))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"件数包装不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!order.KGS.HasValue || order.KGS.Value == 0)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"重量不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!order.CBM.HasValue || order.CBM.Value == 0)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"尺码不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ediFileName = $"{order.VESSEL}_{order.VOYNO}_{order.MBLNO}_{DateTime.Now.Ticks}.txt";
|
|
|
|
|
var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName);
|
|
|
|
|
var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath);
|
|
|
|
|
var ediFileAbs = Path.Combine(ediPathAbs, ediFileName);
|
|
|
|
|
if (!Directory.Exists(ediPathAbs))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(ediPathAbs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DjyEdiSetting ftpset = null;
|
|
|
|
|
if (order.YARDID == yardCodeGJF.Value)
|
|
|
|
|
{
|
|
|
|
|
ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GJF" && f.TenantId == order.TenantId);
|
|
|
|
|
}
|
|
|
|
|
else if (order.YARDID == yardCodeJieFeng.Value)
|
|
|
|
|
{
|
|
|
|
|
ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_JIEFENG" && f.TenantId == order.TenantId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ftpset == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"ftp设置未找到");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ediParaName = "XHZ_GJF";
|
|
|
|
|
if (order.YARDID == yardCodeJieFeng.Value)
|
|
|
|
|
{
|
|
|
|
|
ediParaName = "XHZ_JIEFENG";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<string> listJoinStr = new List<string>();
|
|
|
|
|
listJoinStr.Add("00:IFCSUM:BK:" + filerole + ":" + ftpset.SENDCODE + ":" + ftpset.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + ":2.1'");
|
|
|
|
|
|
|
|
|
|
//提单号
|
|
|
|
|
listJoinStr.Add("02:" + order.Id.ToString() + ":" + order.MBLNO.Trim() + ":" + order.SERVICE + ":" + ftpset.SENDNAME + ":" + ftpset.RECEIVECODE + "::::::::::" + order.CONTRACTNO + ":" + (order.CARRIERID == hlcCode ? order.CUSTNO : "") + ":'");
|
|
|
|
|
|
|
|
|
|
//提单地址
|
|
|
|
|
var ISSUETYPE = "";
|
|
|
|
|
if (order.ISSUETYPE == "正本")
|
|
|
|
|
{
|
|
|
|
|
ISSUETYPE = "ORI";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ISSUETYPE = "EXP";
|
|
|
|
|
}
|
|
|
|
|
listJoinStr.Add("03:" + ISSUETYPE + ":" + order.ISSUEPLACEID + ":" + order.ISSUEPLACE + ":" + GetDateStr(order.ISSUEDATE, "yyyyMMdd") + ":" + GetBillNum2(order.NOBILL) + ":" + order.PORTLOADID + ":" + order.PREPARDAT + ":" + order.PAYABLEAT + "::'");//美国AMS标志、加拿大AMS标志
|
|
|
|
|
|
|
|
|
|
//船
|
|
|
|
|
listJoinStr.Add("11:" + GetVesselEDICode(order.VESSEL, ediParaName) + ":" + order.VESSEL + ":" + order.VOYNO + ":::" + GetCarrierEDICode(order.CARRIERID, ediParaName) + "::" + GetDateStr(order.ETD, "yyyyMMdd") + "::::::" + order.YARDCONTRACT + ":" + formatEdiStr("txt", order.YARDREMARK) + ":'");
|
|
|
|
|
|
|
|
|
|
//港口
|
|
|
|
|
listJoinStr.Add("12:" + order.PLACERECEIPTID + ":" + order.PLACERECEIPT + ":" + order.PORTLOADID + ":" + order.PORTLOAD + ":" + GetMappingPortDischarge(order.PORTDISCHARGEID, ediParaName) + ":" + order.PORTDISCHARGE + ":::" + order.PLACEDELIVERYID + ":" + order.PLACEDELIVERY + ":" + order.DESTINATIONID + ":" + order.DESTINATION + "'");
|
|
|
|
|
|
|
|
|
|
//付费方式
|
|
|
|
|
var frtstr = GetFrtEDICode(order.BLFRT);
|
|
|
|
|
if (frtstr != "")
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("14:" + frtstr + ":" + order.BLFRT + "'");
|
|
|
|
|
listJoinStr.Add("15:::" + frtstr + ":::::::'");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("14:P:" + order.BLFRT + "'");
|
|
|
|
|
listJoinStr.Add("15:::P:::::::'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Shipping = "";
|
|
|
|
|
List<string> ShippingList = null;
|
|
|
|
|
|
|
|
|
|
//2021年9月1日修改,17行取消,放到11行原FAX位置(于斐)
|
|
|
|
|
////EDI备注
|
|
|
|
|
//if (!string.IsNullOrWhiteSpace(order.YardRemark))
|
|
|
|
|
//{
|
|
|
|
|
// Shipping = formatEdiStr("txt", order.YardRemark);
|
|
|
|
|
// ShippingList = formatlengthStr(Shipping, 70);
|
|
|
|
|
// if (Shipping != "")
|
|
|
|
|
// {
|
|
|
|
|
// listJoinStr.Add("17:" + formatListStr(ShippingList, 5) + "'");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//发货人
|
|
|
|
|
Shipping = formatEdiStr("txt", order.SHIPPER);
|
|
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("18::" + formatListStr(ShippingList, 6) + "'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//收货人
|
|
|
|
|
Shipping = formatEdiStr("txt", order.CONSIGNEE);
|
|
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("19::" + formatListStr(ShippingList, 6) + "'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//通知人
|
|
|
|
|
Shipping = formatEdiStr("txt", order.NOTIFYPARTY);
|
|
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("20::" + formatListStr(ShippingList, 6) + "'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//货物标识
|
|
|
|
|
var cargoid = order.CARGOID;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(cargoid))
|
|
|
|
|
{
|
|
|
|
|
cargoid = "S";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listJoinStr.Add("41:1::" + cargoid + ":" + order.PKGS.ToString() + ":" + order.KINDPKGS + ":" + order.KINDPKGS + ":" + order.KGS.ToString() + ":" + order.CBM.ToString() + "::::::" + order.KGS.ToString() + ":::'");//bill.HSCODE
|
|
|
|
|
|
|
|
|
|
if (cargoid == "R")
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("43:::::::::::" + order.REEFERF + ":C:" + order.TEMPSET + ":" + order.TEMPMIN + ":" + order.TEMPMAX + "::::::" + order.HUMIDITY + "::::'");
|
|
|
|
|
}
|
|
|
|
|
else if (cargoid == "D")
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("43:" + order.DCLASS + ":" + order.DPAGE + ":" + order.DUNNO + ":" + order.DLABEL + "::::::::::::::::::::'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//唛头
|
|
|
|
|
Shipping = formatEdiStr("txt", order.MARKS);
|
|
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(9))); i++)
|
|
|
|
|
{
|
|
|
|
|
var tempstr = "44:";
|
|
|
|
|
for (var z = 0; z < 9; z++)
|
|
|
|
|
{
|
|
|
|
|
if ((i * 9 + z) < ShippingList.Count)
|
|
|
|
|
tempstr = tempstr + ShippingList[i * 9 + z];
|
|
|
|
|
if (z < 8) tempstr = tempstr + ":";
|
|
|
|
|
}
|
|
|
|
|
if (tempstr != "44:")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
listJoinStr.Add(tempstr + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//货物描述
|
|
|
|
|
Shipping = formatEdiStr("txt", order.DESCRIPTION);
|
|
|
|
|
ShippingList = formatlengthStr(Shipping, 70);
|
|
|
|
|
var m = 1;
|
|
|
|
|
var strtemp = "";
|
|
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < ShippingList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (m <= 5)
|
|
|
|
|
{
|
|
|
|
|
if (m == 1) strtemp = "47:" + ShippingList[i] + ":";
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (m == 5)
|
|
|
|
|
strtemp = strtemp + ShippingList[i];
|
|
|
|
|
else
|
|
|
|
|
strtemp = strtemp + ShippingList[i] + ":";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m = 1;
|
|
|
|
|
listJoinStr.Add(strtemp + "'");
|
|
|
|
|
strtemp = "47:" + ShippingList[i] + ":";
|
|
|
|
|
}
|
|
|
|
|
m = m + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strtemp != "")
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add(strtemp + "'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//集装箱
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("48:" + GetCtnEDICode(g.Key, ediParaName) + ":" + g.CTNNUM + $":F:::::{(order.ISCONTAINERSOC.HasValue && order.ISCONTAINERSOC.Value ? "Y" : "N")}'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
|
{
|
|
|
|
|
if (ctn.CNTRNO != "")
|
|
|
|
|
{
|
|
|
|
|
listJoinStr.Add("51:" + ctn.CNTRNO + ":" + GetCtnEDICode(ctn.CTNCODE, ediParaName) + ":" + ctn.SEALNO + ":M:CA:F:" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString() + "::" + ctn.CBM + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listJoinStr.Add("99:" + listJoinStr.Count + 1 + "'");
|
|
|
|
|
|
|
|
|
|
var strJoin = string.Join(Environment.NewLine, listJoinStr);
|
|
|
|
|
Log.Information($"生成下货纸报文:{strJoin}");
|
|
|
|
|
File.WriteAllText(ediFileAbs, strJoin, Encoding.Default);
|
|
|
|
|
|
|
|
|
|
//挂载附件
|
|
|
|
|
var attFile = new BookingFile();
|
|
|
|
|
attFile.BookingId = order.Id;
|
|
|
|
|
attFile.FileName = ediFileName;
|
|
|
|
|
attFile.FilePath = ediFileRela;
|
|
|
|
|
attFile.TypeCode = "xiahuozhi";
|
|
|
|
|
attFile.TypeName = "下货纸";
|
|
|
|
|
attFile.TenantName = order.TenantName;
|
|
|
|
|
await repBookingFile.InsertAsync(attFile);
|
|
|
|
|
|
|
|
|
|
//发送ftp
|
|
|
|
|
SplitFtpServerAndPort(ftpset.SERVERIP, out string server, out int port);
|
|
|
|
|
|
|
|
|
|
var ftpSpiderUrl = (await cacheService.GetAllDictData()).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", ftpset.USERNAME);
|
|
|
|
|
par.Add("pwd", ftpset.PASSWORD);
|
|
|
|
|
par.Add("path", ftpset.FOLDERNAME);
|
|
|
|
|
par.Add("pasv", (!ftpset.FtpModeActive).ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.Information($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{par.ToJsonString()},文件:{ediFileName}");
|
|
|
|
|
var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new
|
|
|
|
|
{
|
|
|
|
|
file = "file",
|
|
|
|
|
fileName = Path.GetFileName(ediFileName),
|
|
|
|
|
fileBytes = Encoding.UTF8.GetBytes(strJoin)
|
|
|
|
|
});
|
|
|
|
|
Log.Information($"发送ftp返回:{res}");
|
|
|
|
|
var jobjRetn = JObject.Parse(res);
|
|
|
|
|
if (jobjRetn.GetStringValue("status") != "1")
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"ftp发送失败:{jobjRetn.GetStringValue("message")}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new KeyValuePair<bool, string>(true, $"完成");
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 港联欣场站
|
|
|
|
|
else if (order.YARDID == yardCodeGLX.Value || order.YARDID == yardCodeZhongChuang.Value)
|
|
|
|
|
{
|
|
|
|
|
//2022年6月15日增加:港联欣场站若配置了通过港联捷EDI发送,则使用港联捷报文格式
|
|
|
|
|
var tenantParam = await cacheService.GetAllTenantParam();
|
|
|
|
|
var pGlxEdi = tenantParam.FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "XIAHUOZHI_GLX_SEND_TYPE");
|
|
|
|
|
if (order.YARDID == yardCodeGLX.Value && pGlxEdi != null && pGlxEdi.ItemCode == "EDI_GLX")
|
|
|
|
|
{
|
|
|
|
|
var glxCarrierList = dictData.Where(x => x.TypeCode == "XiaHuoZhiGLXCarrierConfig").Select(x => x.Value).ToList();//港联欣支持的船司
|
|
|
|
|
if (!glxCarrierList.Contains(order.CARRIERID))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"港联欣下货纸当前不支持此船公司");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GLX" && f.TenantId == order.TenantId);
|
|
|
|
|
if (ftpset == null)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"港联欣下货纸ftp设置未找到");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var paraXHZ = tenantParam.FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "CODE_GLX_XHZ");
|
|
|
|
|
if (paraXHZ == null || string.IsNullOrEmpty(paraXHZ.ItemCode))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"下货纸代号未找到或配置有误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ediFileName = $"{paraXHZ.ItemCode}_{order.MBLNO}_{DateTime.Now.Ticks}.txt";
|
|
|
|
|
var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName);
|
|
|
|
|
var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath);
|
|
|
|
|
var ediFileAbs = Path.Combine(ediPathAbs, ediFileName);
|
|
|
|
|
if (!Directory.Exists(ediPathAbs))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(ediPathAbs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder sbData = new StringBuilder();
|
|
|
|
|
sbData.AppendLine($"01:{order.VESSEL}:{order.VOYNO}"); //船名 航次
|
|
|
|
|
|
|
|
|
|
sbData.AppendLine($"12:{order.MBLNO}:{order.TRANSPORTID}:{GetMappingPortDischarge(order.PORTDISCHARGEID, "XHZ_GLX")}:{paraXHZ.ItemCode}:{GetCarrierEDICode(order.CARRIERID, "XHZ_GLX")}:{(order.CARRIERID == hlcCode ? order.CUSTNO : "")}:{order.PORTDISCHARGE}"); //主提单 中转港代码 目的港代码 货代代码 船公司 HPL参考号 备注
|
|
|
|
|
var despStr = ExchangeStr(order.DESCRIPTION.Replace(":", " ").Replace(",", " ")).Replace("\r\n", " ").Replace("\n", " ");
|
|
|
|
|
if (despStr.Length > 100)
|
|
|
|
|
{
|
|
|
|
|
despStr = despStr.Substring(0, 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
“22” 2 字符 货物信息开始
|
|
|
|
|
货名 20 字符 必填
|
|
|
|
|
件数 10 字符 必填
|
|
|
|
|
包装代码 6 字符 必填
|
|
|
|
|
总重量 11 字符 公斤 必填
|
|
|
|
|
总体积 6 字符 立方米 必填
|
|
|
|
|
危品标志 1 字符 Y/N 必填
|
|
|
|
|
危品等级 5 字符
|
|
|
|
|
危规号 5 字符
|
|
|
|
|
副危品等级 5 字符
|
|
|
|
|
副危规号 5 字符
|
|
|
|
|
温度 5 字符 不带单位,默认C
|
|
|
|
|
通风度 5 字符 不带单位,默认CBM/H
|
|
|
|
|
湿度 5 字符 不带单位,默认%
|
|
|
|
|
回车换行 2 ASC码 ASC码“0D”“0A”
|
|
|
|
|
*/
|
|
|
|
|
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 ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList();
|
|
|
|
|
var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLX").ToList();
|
|
|
|
|
var groupList = ctns.GroupBy(x => new { x.CTNALL, x.CTNCODE }).Select(x => new { CTNCODE = x.Key.CTNCODE, CTNALL = x.Key.CTNALL, COUNT = x.Sum(y => y.CTNNUM) }).ToList();
|
|
|
|
|
foreach (var ctn in groupList)
|
|
|
|
|
{
|
|
|
|
|
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_GLX),无法发送下货纸,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sbData.AppendLine($"13:{(order.ISCONTAINERSOC.HasValue && order.ISCONTAINERSOC.Value ? "SOC" : GetCtnForCarrier(order.CARRIERID, "XHZ_GLJ", dictData))}:{ctnFind.Size}:{ctnEdi.MapCode}:{ctn.COUNT}::N");//箱经营人代码 尺寸 箱型 箱数 备注 加重箱
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.Information($"生成下货纸报文:{sbData.ToString()}");
|
|
|
|
|
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(ftpset.SERVERIP, out string server, out int port);
|
|
|
|
|
|
|
|
|
|
var ftpSpiderUrl = (await cacheService.GetAllDictData()).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", ftpset.USERNAME);
|
|
|
|
|
par.Add("pwd", ftpset.PASSWORD);
|
|
|
|
|
par.Add("path", ftpset.FOLDERNAME);
|
|
|
|
|
par.Add("pasv", (!ftpset.FtpModeActive).ToString());
|
|
|
|
|
|
|
|
|
|
Log.Information($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{par.ToJsonString()},文件:{ediFileName}");
|
|
|
|
|
var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new
|
|
|
|
|
{
|
|
|
|
|
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")}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else //邮件方式
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(order.YARDCONTRACTEMAIL))
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"场站联系人邮箱不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userMail = repUserMail.FirstOrDefault(x => x.CreatedUserId == order.CreatedUserId);
|
|
|
|
|
if (userMail == null
|
|
|
|
|
|| string.IsNullOrEmpty(userMail.SmtpServer)
|
|
|
|
|
|| userMail.SmtpPort == 0)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, $"发件邮箱未配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var userbase = repUser.FirstOrDefault(u => u.Id == order.CreatedUserId);
|
|
|
|
|
var title = $"下货纸:{order.MBLNO}/{order.CARRIER}/{order.VESSEL}/{order.VOYNO}/{order.TenantName}";
|
|
|
|
|
|
|
|
|
|
var bodyExt = string.Empty;
|
|
|
|
|
if (order.CARGOID == "R")
|
|
|
|
|
{
|
|
|
|
|
bodyExt = $@"温度:{order.TEMPSET}{order.TEMPID}<br/>
|
|
|
|
|
通风:{order.REEFERF}<br/>
|
|
|
|
|
湿度:{order.HUMIDITY}<br/>";
|
|
|
|
|
}
|
|
|
|
|
else if (order.CARGOID == "D")
|
|
|
|
|
{
|
|
|
|
|
bodyExt = $@"危险品等级:{order.DCLASS}<br/>
|
|
|
|
|
危险品编号:{order.DUNNO}<br/>
|
|
|
|
|
危险品联系方式:{order.LINKMAN}<br/>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var body = $@"提单号:{order.MBLNO}<br/>
|
|
|
|
|
船名航次:{order.VESSEL}/{order.VOYNO}<br/>
|
|
|
|
|
起运港:{order.PORTLOAD},{order.PORTLOADID}<br/>
|
|
|
|
|
目的港:{order.PORTDISCHARGE},{GetMappingPortDischarge(order.PORTDISCHARGEID, "XHZ_GLX")}<br/>
|
|
|
|
|
目的地:{order.DESTINATION},{order.DESTINATIONID}<br/>
|
|
|
|
|
预计船期:{(order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : "")}<br/>
|
|
|
|
|
箱型箱量:{order.CNTRTOTAL}<br/>
|
|
|
|
|
件重尺:{order.PKGS} {order.KINDPKGS}/{order.KGS}KGS/{order.CBM}CBM<br/>
|
|
|
|
|
货物描述:{order.DESCRIPTION}<br/>
|
|
|
|
|
{bodyExt}
|
|
|
|
|
备注:{order.YARDREMARK}<br/>
|
|
|
|
|
<br/>
|
|
|
|
|
订舱代理:{order.TenantName}<br/>
|
|
|
|
|
联系人:{order.CreatedUserName}<br/>
|
|
|
|
|
电话:{userbase.Tel} 手机:{userbase.Phone}<br/>
|
|
|
|
|
邮箱:{userbase.Email}<br/>
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
var sendResult = await MailSendHelper.SendMail(userMail, title, body, order.YARDCONTRACTEMAIL);
|
|
|
|
|
if (!sendResult.Key)
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, sendResult.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new KeyValuePair<bool, string>(true, "已发送");
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new KeyValuePair<bool, string>(false, "不支持的场站");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//转义处理字符串中的特殊字符
|
|
|
|
|
private static string ExchangeStr(string str)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str.Replace("?", "??").Replace("'", "?'").Replace("+", "?+").Replace(":", "?:");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//根据船名,获取船名edi代码(根据东胜7同功能模块代码翻译而成)
|
|
|
|
|
public static string GetVesselEDICode(string vessel, string EDINAME)
|
|
|
|
|
{
|
|
|
|
|
string EDICODE = "";
|
|
|
|
|
vessel = vessel.Replace("'", "''");
|
|
|
|
|
|
|
|
|
|
var codeVesselEdi = GetAllMappingVessel().Result.FirstOrDefault(v => v.Name == vessel && v.Module == EDINAME);
|
|
|
|
|
if (codeVesselEdi != null)
|
|
|
|
|
{
|
|
|
|
|
EDICODE = codeVesselEdi.MapName.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(EDICODE))
|
|
|
|
|
{
|
|
|
|
|
var codeVessel = GetAllCodeVessel().Result.FirstOrDefault(v => v.Name == vessel);
|
|
|
|
|
if (codeVessel != null && !string.IsNullOrEmpty(codeVessel.EdiCode))
|
|
|
|
|
{
|
|
|
|
|
EDICODE = codeVessel.EdiCode.Trim();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EDICODE = vessel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EDICODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取时间字符串
|
|
|
|
|
public static string GetDateStr(DateTime? dt, string dateformat)
|
|
|
|
|
{
|
|
|
|
|
var result = "";
|
|
|
|
|
if (!dt.HasValue)
|
|
|
|
|
{
|
|
|
|
|
result = "";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = dt.Value.ToString(dateformat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取客户edi代码(根据东胜7同功能模块代码翻译而成)
|
|
|
|
|
public static string GetCarrierEDICode(string carrierCode, string EDINAME)
|
|
|
|
|
{
|
|
|
|
|
string EDICODE = "";
|
|
|
|
|
|
|
|
|
|
var custEdi = GetAllMappingCarrier().Result.FirstOrDefault(c => c.Code == carrierCode && c.Module == EDINAME);
|
|
|
|
|
if (custEdi != null)
|
|
|
|
|
{
|
|
|
|
|
EDICODE = custEdi.MapCode.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(EDICODE))
|
|
|
|
|
{
|
|
|
|
|
var infoclient = GetAllCodeCarrier().Result.FirstOrDefault(c => c.Code == carrierCode);
|
|
|
|
|
if (infoclient != null)
|
|
|
|
|
{
|
|
|
|
|
EDICODE = infoclient.EdiCode.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EDICODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取箱属船司代码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetCtnForCarrier(string carrid, string EDINAME, List<DictDataDto> dictData)
|
|
|
|
|
{
|
|
|
|
|
var xiaHuoZhiCarrierBelongMapping = dictData.Where(x => x.TypeCode == "XiaHuoZhiCarrierBelongMapping").ToList();//港联捷、港联欣下货纸的箱属映射配置
|
|
|
|
|
var map = xiaHuoZhiCarrierBelongMapping.FirstOrDefault(x => x.Code == carrid);
|
|
|
|
|
if (map != null)
|
|
|
|
|
{
|
|
|
|
|
return map.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return GetCarrierEDICode(carrid, EDINAME);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取付费方式edi代码(根据东胜7同功能模块代码翻译而成)
|
|
|
|
|
public static string GetFrtEDICode(string FRT)
|
|
|
|
|
{
|
|
|
|
|
string EDICODE = "P";
|
|
|
|
|
|
|
|
|
|
var ediFRT = GetAllMappingFrt().Result.FirstOrDefault(c => c.Code == FRT);
|
|
|
|
|
if (ediFRT != null)
|
|
|
|
|
{
|
|
|
|
|
EDICODE = ediFRT.MapCode.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EDICODE;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取edi代码(根据东胜7同功能模块移植)
|
|
|
|
|
public static string GetBillNum2(string str)
|
|
|
|
|
{
|
|
|
|
|
if (str == "ZERO") return "00";
|
|
|
|
|
if (str == "ONE") return "01";
|
|
|
|
|
if (str == "TWO") return "02";
|
|
|
|
|
if (str == "THREE") return "03";
|
|
|
|
|
if (str == "FOUR") return "04";
|
|
|
|
|
if (str == "FIVE") return "05";
|
|
|
|
|
if (str == "SIX") return "06";
|
|
|
|
|
if (str == "SERVEN") return "07";
|
|
|
|
|
if (str == "EIGHT") return "08";
|
|
|
|
|
if (str == "NINE") return "09";
|
|
|
|
|
if (str == "TEN") return "10";
|
|
|
|
|
else return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 各种文本转义字符(东胜7移植)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="fileType">文件类型(例如:txt、xml)</param>
|
|
|
|
|
/// <param name="str">文本字符串</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string formatEdiStr(string fileType, string str)
|
|
|
|
|
{
|
|
|
|
|
if (str == null)
|
|
|
|
|
str = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (str == null)
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fileType == "txt")
|
|
|
|
|
{
|
|
|
|
|
return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'");
|
|
|
|
|
}
|
|
|
|
|
else if (fileType == "xml")
|
|
|
|
|
{
|
|
|
|
|
return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'");
|
|
|
|
|
}
|
|
|
|
|
else if (fileType == "sitc")
|
|
|
|
|
{
|
|
|
|
|
return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//东胜7移植
|
|
|
|
|
public static List<string> formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false)
|
|
|
|
|
{
|
|
|
|
|
str = str.Replace("\r\n", "\\");
|
|
|
|
|
str = str.Replace("\n", "\\");
|
|
|
|
|
str = str.Replace("\r", " ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string[] StrList = str.Split('\\');
|
|
|
|
|
|
|
|
|
|
//List<System.String> StrListtmp = new List<System.String>();
|
|
|
|
|
//for (var i = StrList.Length - 1; i >=0; i--)
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
var strtemp = "";
|
|
|
|
|
var strnewline = "";
|
|
|
|
|
var strtempnewline = "";
|
|
|
|
|
char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' };
|
|
|
|
|
List<System.String> DestList = new List<System.String>();
|
|
|
|
|
for (var i = 0; i <= StrList.Length - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
if (StrList[i].Length <= length)
|
|
|
|
|
{
|
|
|
|
|
if (formatstr)
|
|
|
|
|
DestList.Add(formatEdiStr("txt", StrList[i]));
|
|
|
|
|
else
|
|
|
|
|
DestList.Add(StrList[i]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strtemp = StrList[i] + " ";
|
|
|
|
|
strtempnewline = "";
|
|
|
|
|
strnewline = "";
|
|
|
|
|
for (var j = 0; j < strtemp.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
strtempnewline = strtempnewline + strtemp[j];
|
|
|
|
|
if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/'
|
|
|
|
|
|| strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-')
|
|
|
|
|
{
|
|
|
|
|
if ((strnewline.Length + strtempnewline.Length) <= length)
|
|
|
|
|
strnewline = strnewline + strtempnewline;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (formatstr)
|
|
|
|
|
DestList.Add(formatEdiStr("txt", strnewline));
|
|
|
|
|
else
|
|
|
|
|
DestList.Add(strnewline);
|
|
|
|
|
strnewline = strtempnewline;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strtempnewline = "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (nodelsp)
|
|
|
|
|
{
|
|
|
|
|
if (formatstr)
|
|
|
|
|
DestList.Add(formatEdiStr("txt", strnewline));
|
|
|
|
|
else DestList.Add(strnewline);
|
|
|
|
|
}
|
|
|
|
|
else if (strnewline.Trim() != "")
|
|
|
|
|
{
|
|
|
|
|
if (formatstr)
|
|
|
|
|
DestList.Add(formatEdiStr("txt", strnewline));
|
|
|
|
|
else DestList.Add(strnewline);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DestList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//东胜7移植
|
|
|
|
|
public static string formatListStr(List<string> DestList, int lineCount)
|
|
|
|
|
{
|
|
|
|
|
var result = "";
|
|
|
|
|
for (var i = 0; i < lineCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (DestList.Count > i)
|
|
|
|
|
{
|
|
|
|
|
result = result + DestList[i];
|
|
|
|
|
}
|
|
|
|
|
if (i != (lineCount - 1))
|
|
|
|
|
result = result + ":";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取箱型的EDI代码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ctnCode"></param>
|
|
|
|
|
/// <param name="EDINAME"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetCtnEDICode(string ctnCode, string EDINAME)
|
|
|
|
|
{
|
|
|
|
|
string EDICODE = "";
|
|
|
|
|
|
|
|
|
|
var ctnEdi = GetAllMappingCtn().Result.FirstOrDefault(c => c.Code == ctnCode && c.Module == EDINAME);
|
|
|
|
|
if (ctnEdi != null)
|
|
|
|
|
{
|
|
|
|
|
EDICODE = ctnEdi.MapCode.Trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(EDICODE))
|
|
|
|
|
{
|
|
|
|
|
var infoclient = GetAllCodeCtn().Result.FirstOrDefault(c => c.Code == ctnCode);
|
|
|
|
|
if (infoclient != null)
|
|
|
|
|
{
|
|
|
|
|
EDICODE = infoclient.EdiCode.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return EDICODE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有箱型(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<CodeCtn>> GetAllCodeCtn()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var ctnList = await cacheService.GetAllCodeCtn();
|
|
|
|
|
if (ctnList == null || ctnList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<CodeCtn>>();
|
|
|
|
|
ctnList = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllCodeCtn(ctnList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ctnList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有船司(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<CodeCarrier>> GetAllCodeCarrier()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var list = await cacheService.GetAllCodeCarrier();
|
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<CodeCarrier>>();
|
|
|
|
|
list = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllCodeCarrier(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有箱型映射(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<MappingCtn>> GetAllMappingCtn()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var ctnList = await cacheService.GetAllMappingCtn();
|
|
|
|
|
if (ctnList == null || ctnList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<MappingCtn>>();
|
|
|
|
|
ctnList = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllMappingCtn(ctnList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ctnList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有船司映射(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<MappingCarrier>> GetAllMappingCarrier()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var list = await cacheService.GetAllMappingCarrier();
|
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<MappingCarrier>>();
|
|
|
|
|
list = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllMappingCarrier(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有付费方式(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<CodeFrt>> GetAllCodeFrt()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var list = await cacheService.GetAllCodeFrt();
|
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<CodeFrt>>();
|
|
|
|
|
list = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllCodeFrt(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有付费方式映射(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<MappingFrt>> GetAllMappingFrt()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var list = await cacheService.GetAllMappingFrt();
|
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<MappingFrt>>();
|
|
|
|
|
list = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllMappingFrt(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 获取所有公司参数(使用缓存)
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//private static async Task<List<DjyTenantParamValue>> GetAllTenantParam()
|
|
|
|
|
//{
|
|
|
|
|
// var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
// var list = await cacheService.GetAllTenantParam();
|
|
|
|
|
// if (list == null || list.Count == 0)
|
|
|
|
|
// {
|
|
|
|
|
// var rep = App.GetService<SqlSugarRepository<DjyTenantParamValue>>();
|
|
|
|
|
// list = await sugerClient.Queryable<DjyTenantParamValue>().ToListAsync();
|
|
|
|
|
// await cacheService.SetAllTenantParam(list);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return list;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有船名(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<CodeVessel>> GetAllCodeVessel()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var list = await cacheService.GetAllCodeVessel();
|
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<CodeVessel>>();
|
|
|
|
|
list = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllCodeVessel(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有船名映射(使用缓存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static async Task<List<MappingVessel>> GetAllMappingVessel()
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var list = await cacheService.GetAllMappingVessel();
|
|
|
|
|
if (list == null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var rep = App.GetService<SqlSugarRepository<MappingVessel>>();
|
|
|
|
|
list = await rep.ToListAsync();
|
|
|
|
|
await cacheService.SetAllMappingVessel(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分割ftp服务器地址和端口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="str"></param>
|
|
|
|
|
private static void SplitFtpServerAndPort(string str, out string server, out int port)
|
|
|
|
|
{
|
|
|
|
|
if (str.IndexOf(':') > -1)
|
|
|
|
|
{
|
|
|
|
|
var arr = str.Split(':');
|
|
|
|
|
server = arr[0];
|
|
|
|
|
port = Convert.ToInt32(arr[1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
server = str;
|
|
|
|
|
port = 21;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据订舱中的卸货港代码查找映射代码
|
|
|
|
|
///
|
|
|
|
|
/// 2023年8月18日,董怡含:
|
|
|
|
|
/// 因客户平台维护港口五字代码于场站下货纸识别的五字代码不一致,
|
|
|
|
|
/// 可否给场站下货纸模块增加目的港映射,可以单独配置场站能取到的五字代码(目前通过映射
|
|
|
|
|
/// 配置,下货纸中港口五字代码仍是订舱页面选择的港口代码)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="portDischargeEdiCode">订舱中的卸货港五字码</param>
|
|
|
|
|
/// <param name="module">映射模块代码,例如XHZ_GLJ</param>
|
|
|
|
|
private static string GetMappingPortDischarge(string portDischargeEdiCode, string module)
|
|
|
|
|
{
|
|
|
|
|
var cacheService = App.GetService<ISysCacheService>();
|
|
|
|
|
var portList = cacheService.GetAllCodePort().Result;
|
|
|
|
|
var portMapping = cacheService.GetAllMappingPort().Result;
|
|
|
|
|
var q = from p in portList
|
|
|
|
|
join pm in portMapping on p.Code equals pm.Code
|
|
|
|
|
where pm.Module == module && p.EdiCode == portDischargeEdiCode
|
|
|
|
|
select pm;
|
|
|
|
|
|
|
|
|
|
var mapList = q.ToList();
|
|
|
|
|
if (mapList.Any())
|
|
|
|
|
{
|
|
|
|
|
return mapList[0].MapCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return portDischargeEdiCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 校验货描里的温度、湿度、通风与单个填写项进行比对
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="order">订舱详情</param>
|
|
|
|
|
public static void CheckGoodsDescriptionWithInput(BookingOrder order)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|