You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/EDI/SITCEdiHelper.cs

622 lines
18 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DocumentFormat.OpenXml.ExtendedProperties;
using Google.Protobuf.WellKnownTypes;
using Myshipping.Application.EDI.ESL;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json;
using NPOI.Util;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application.EDI.SITC
{
public class SITCEdiHelper
{
public SITCEdiHelper()
{
}
#region 基本函数
#endregion
#region 检查
public static string IsCreateSITCEDI(EDIBaseModel InttrEdi)
{
var error = "";
if (InttrEdi.filerole == "E")
{
error = error + "<br />SITC接口只支持订舱不能截单";
}
foreach (var bill in InttrEdi.BSLIST)
{
}
return error;
}
#endregion
#region 生成报文(订舱(filetype=="B"),截单(filetype=="E"))
public static CommonWebApiResult CreateEdiSITC(EDIBaseModel InttrEdi)
{
CommonWebApiResult result = new CommonWebApiResult { succ = false };
string dir = InttrEdi.filerpath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "\\";
//如果是部署linux需要修改路径
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
dir = dir.Replace("\\", "/");
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
string filename = dir + InttrEdi.BSLIST[0].ORDERNO + ".json";
FileStream f = new FileStream(filename, FileMode.Create);
StreamWriter r = new StreamWriter(f, Encoding.Default);
SitcApiPostModel postModel = new SitcApiPostModel();
postModel.consignorCustName = InttrEdi.SENDCODE;
postModel.polId = InttrEdi.BSLIST[0].PORTLOADID;
postModel.polName = InttrEdi.BSLIST[0].PORTLOAD;
postModel.podId = InttrEdi.BSLIST[0].PORTDISCHARGEID;
postModel.podName = InttrEdi.BSLIST[0].PORTDISCHARGE;
postModel.deliveryId = InttrEdi.BSLIST[0].PLACEDELIVERYID;
postModel.deliveryName = InttrEdi.BSLIST[0].PLACEDELIVERY;
postModel.porId = InttrEdi.BSLIST[0].PLACERECEIPTID;
postModel.porName = InttrEdi.BSLIST[0].PLACERECEIPT;
postModel.poWtatName = InttrEdi.BSLIST[0].TRANSPORT;
postModel.vesselName = InttrEdi.BSLIST[0].VESSEL;
postModel.lineCode = InttrEdi.BSLIST[0].ESLLINECODE;
postModel.voyNo = InttrEdi.BSLIST[0].VOYNO;
postModel.etd = InttrEdi.BSLIST[0].ETD;
postModel.eta = InttrEdi.BSLIST[0].ETA;
postModel.consigneeName = InttrEdi.BSLIST[0].CONSIGNEE;
postModel.consigneeAddr = InttrEdi.BSLIST[0].CONSIGNEEADDR;
//postModel.consigneeFax = InttrEdi.BSLIST[0].CONSIGNEEFAX;
//postModel.consigneeTel = InttrEdi.BSLIST[0].CONSIGNEETEL;
//postModel.consigneeBsCode = InttrEdi.BSLIST[0].CONSIGNEEBSCODE;
//postModel.consigneeEmail = InttrEdi.BSLIST[0].CONSIGNEEEMAIL;
postModel.consignorName = InttrEdi.BSLIST[0].SHIPPER;
postModel.consignorAddr = InttrEdi.BSLIST[0].SHIPPERADDR;
//postModel.consignorFax = InttrEdi.BSLIST[0].CONSIGNORFAX;
//postModel.consignorTel = InttrEdi.BSLIST[0].CONSIGNORTEL;
//postModel.consignorBsCode = InttrEdi.BSLIST[0].CONSIGNORBSCODE;
//postModel.consignorEmail = InttrEdi.BSLIST[0].CONSIGNOREMAIL;
postModel.notifyName = InttrEdi.BSLIST[0].NOTIFYPARTY;
postModel.notifyAddr = InttrEdi.BSLIST[0].NOTIFYPARTYADDR;
//postModel.notifyFax = InttrEdi.BSLIST[0].NOTIFYFAX;
//postModel.notifyTel = InttrEdi.BSLIST[0].NOTIFYTEL;
//postModel.notifyBsCode = InttrEdi.BSLIST[0].NOTIFYBSCODE;
//postModel.notifyEmail = InttrEdi.BSLIST[0].NOTIFYEMAIL;
postModel.movementType = InttrEdi.BSLIST[0].SERVICE;
postModel.weight = InttrEdi.BSLIST[0].KGS;
postModel.cube = InttrEdi.BSLIST[0].CBM;
postModel.packages = InttrEdi.BSLIST[0].PKGS;
postModel.packingType = InttrEdi.BSLIST[0].KINDPKGS;
postModel.packageDesc = InttrEdi.BSLIST[0].KINDPKGS;
postModel.marks = InttrEdi.BSLIST[0].MARKS;
postModel.cargoDesc = InttrEdi.BSLIST[0].DESCRIPTION;
postModel.cargoType = CargoIdStr(InttrEdi.BSLIST[0].CARGOID);
postModel.isDanger = InttrEdi.BSLIST[0].CARGOID == "D" ? true : false;
postModel.isRf = InttrEdi.BSLIST[0].CARGOID == "R" ? true : false;
postModel.contactInfo = InttrEdi.BSLIST[0].OpEmail;
postModel.remark = InttrEdi.BSLIST[0].EDIREMARK;
postModel.payTerm = InttrEdi.BSLIST[0].BLFRT;
postModel.containers = new List<SitcApiPostModelContainer>();
foreach (var container in InttrEdi.BSLIST[0].CTNLIST)
{
SitcApiPostModelContainer c = new SitcApiPostModelContainer();
c.ctnSize = container.CTNALLCODE.Substring(0, 2);
c.ctnType = container.CTNALLCODE.Substring(2, 2);
c.ctnNum = container.CTNNUM;
postModel.containers.Add(c);
}
if (InttrEdi.BSLIST[0].CARGOID == "R")
{
postModel.extras = new List<SitcApiPostModelExtra>();
SitcApiPostModelExtra e = new SitcApiPostModelExtra();
e.ctype = "RF";
e.tempMin = InttrEdi.BSLIST[0].TEMPMIN;
e.tempMax = InttrEdi.BSLIST[0].TEMPMAX;
e.tempSetting = InttrEdi.BSLIST[0].TEMPSET;
e.unit = "C";
e.humdity = InttrEdi.BSLIST[0].HUMIDITY;
e.vent = InttrEdi.BSLIST[0].REEFERF;
postModel.extras.Add(e);
}
if (InttrEdi.BSLIST[0].CARGOID == "D")
{
postModel.dangerInfo = new List<SitcApiPostModelDangerInfo>();
SitcApiPostModelDangerInfo d = new SitcApiPostModelDangerInfo();
d.classNo = InttrEdi.BSLIST[0].DCLASS;
//d.commodityChem = danger.COMMODITYCHEM;
//d.commodityTran = danger.COMMODITYTRAN;
//d.emergencyContact = danger.EMERGENCYCONTACT;
//d.emsNo = danger.EMSNO;
//d.flashPoint = danger.FLASHPOINT;
//d.flashUnit = danger.FLASHUNIT;
//d.grossWeight = danger.GROSSWEIGHT;
//d.isMpt = danger.ISMPT;
//d.labels = danger.LABELS;
//d.netWeight = danger.NETWEIGHT;
//d.nums = danger.NUMS;
//d.packageClass = danger.PACKAGECLASS;
//d.packageType = danger.PACKAGETYPE;
//d.packageName = danger.PACKAGENAME;
d.page = InttrEdi.BSLIST[0].DPAGE;
d.undgNo = InttrEdi.BSLIST[0].DUNNO;
//d.contactName = InttrEdi.BSLIST[0].;
//d.contactNum = InttrEdi.BSLIST[0].;
//d.packagingCode = danger.PACKAGINGCODE;
postModel.dangerInfo.Add(d);
}
string json = JsonConvert.SerializeObject(postModel);
r.Write(json);
r.Flush();
r.Close();
f.Close();
result.succ = true;
result.extra = filename;
result.extra2 = postModel;
return result;
}
#endregion
/// <summary>
/// 货物类型翻译
/// </summary>
/// <param name="cargoId"></param>
/// <returns></returns>
private static string CargoIdStr(string cargoId)
{
if (cargoId == "S")
{
return "ORDI";
}
else if (cargoId == "R")
{
return "REEF";
}
else if (cargoId == "D")
{
return "DNGR";
}
return "";
}
}
public class SitcApiPostModel
{
/// <summary>
/// 客户名称
/// </summary>
public string consignorCustName { get; set; }
/// <summary>
/// 启运港代码
/// </summary>
public string polId { get; set; }
/// <summary>
/// 启运港名称
/// </summary>
public string polName { get; set; }
/// <summary>
/// 目的港代码
/// </summary>
public string podId { get; set; }
/// <summary>
/// 目的港名称
/// </summary>
public string podName { get; set; }
/// <summary>
/// 交货地代码
/// </summary>
public string deliveryId { get; set; }
/// <summary>
/// 交货地名称
/// </summary>
public string deliveryName { get; set; }
/// <summary>
/// 收货地代码
/// </summary>
public string porId { get; set; }
/// <summary>
/// 收货地名称
/// </summary>
public string porName { get; set; }
/// <summary>
/// 中转港名称
/// </summary>
public string poWtatName { get; set; }
/// <summary>
/// 船名
/// </summary>
public string vesselName { get; set; }
/// <summary>
/// 航线
/// </summary>
public string lineCode { get; set; }
/// <summary>
/// 航次
/// </summary>
public string voyNo { get; set; }
/// <summary>
/// 离港时间
/// </summary>
public string etd { get; set; }
/// <summary>
/// 到港时间
/// </summary>
public string eta { get; set; }
/// <summary>
/// 收货人名称
/// </summary>
public string consigneeName { get; set; }
///// <summary>
///// 收货人地址
///// </summary>
public string consigneeAddr { get; set; }
///// <summary>
///// 传真
///// </summary>
//public string consigneeFax { get; set; }
///// <summary>
///// 电话
///// </summary>
//public string consigneeTel { get; set; }
///// <summary>
///// 企业代码
///// </summary>
//public string consigneeBsCode { get; set; }
///// <summary>
///// 邮件
///// </summary>
//public string consigneeEmail { get; set; }
/// <summary>
/// 发货人名称
/// </summary>
public string consignorName { get; set; }
///// <summary>
///// 发货人地址
///// </summary>
public string consignorAddr { get; set; }
///// <summary>
///// 传真
///// </summary>
//public string consignorFax { get; set; }
///// <summary>
///// 电话
///// </summary>
//public string consignorTel { get; set; }
///// <summary>
///// 企业代码
///// </summary>
//public string consignorBsCode { get; set; }
///// <summary>
///// 邮件
///// </summary>
//public string consignorEmail { get; set; }
/// <summary>
/// 通知人名称
/// </summary>
public string notifyName { get; set; }
///// <summary>
///// 通知人地址
///// </summary>
public string notifyAddr { get; set; }
///// <summary>
///// 传真
///// </summary>
//public string notifyFax { get; set; }
///// <summary>
///// 电话
///// </summary>
//public string notifyTel { get; set; }
///// <summary>
///// 企业代码
///// </summary>
//public string notifyBsCode { get; set; }
///// <summary>
///// 邮件
///// </summary>
//public string notifyEmail { get; set; }
/// <summary>
/// 运输条款
/// </summary>
public string movementType { get; set; }
/// <summary>
/// 毛重
/// </summary>
public decimal weight { get; set; }
/// <summary>
/// 体积
/// </summary>
public decimal cube { get; set; }
/// <summary>
/// 件数
/// </summary>
public int packages { get; set; }
/// <summary>
/// 包装类型
/// </summary>
public string packingType { get; set; }
/// <summary>
/// 包装类型
/// </summary>
public string packageDesc { get; set; }
/// <summary>
/// 唛头
/// </summary>
public string marks { get; set; }
/// <summary>
/// 货物描述
/// </summary>
public string cargoDesc { get; set; }
/// <summary>
/// 货物类型
/// </summary>
public string cargoType { get; set; }
/// <summary>
/// 是否危险品
/// </summary>
public bool isDanger { get; set; }
/// <summary>
/// 是否冻柜
/// </summary>
public bool isRf { get; set; }
/// <summary>
/// 是否特种箱
/// </summary>
public bool isSpec { get; set; }
/// <summary>
/// 是否挂衣箱
/// </summary>
public bool isGoh { get; set; }
/// <summary>
/// 是否SOC
/// </summary>
public bool isSoc { get; set; }
/// <summary>
/// 联系信息
/// </summary>
public string contactInfo { get; set; }
/// <summary>
/// 委托备注
/// </summary>
public string remark { get; set; }
/// <summary>
/// 支付方式
/// </summary>
public string payTerm { get; set; }
/// <summary>
/// 委托类型
/// </summary>
public string blType { get; set; }
/// <summary>
/// 放单方式
/// </summary>
public string releaseModeMbl { get; set; }
/// <summary>
/// 箱信息
/// </summary>
public List<SitcApiPostModelContainer> containers { get; set; }
/// <summary>
/// 其它特殊货物信息
/// </summary>
public List<SitcApiPostModelExtra> extras { get; set; }
/// <summary>
/// 危险品信息
/// </summary>
public List<SitcApiPostModelDangerInfo> dangerInfo { get; set; }
}
public class SitcApiPostModelContainer
{
/// <summary>
/// 尺寸
/// </summary>
public string ctnSize { get; set; }
/// <summary>
/// 类型
/// </summary>
public string ctnType { get; set; }
/// <summary>
/// 数量
/// </summary>
public int ctnNum { get; set; }
}
public class SitcApiPostModelExtra
{
/// <summary>
/// 最高温度
/// </summary>
public string tempMax { get; set; }
/// <summary>
/// 最低温度
/// </summary>
public string tempMin { get; set; }
/// <summary>
/// 温度设置
/// </summary>
public string tempSetting { get; set; }
/// <summary>
/// 温度单位
/// </summary>
public string unit { get; set; }
/// <summary>
/// 湿度
/// </summary>
public string humdity { get; set; }
/// <summary>
/// 通风口
/// </summary>
public string vent { get; set; }
/// <summary>
/// 类型
/// </summary>
public string ctype { get; set; }
}
public class SitcApiPostModelDangerInfo
{
/// <summary>
/// 危险品等级
/// </summary>
public string classNo { get; set; }
/// <summary>
/// 化学品名
/// </summary>
public string commodityChem { get; set; }
/// <summary>
/// 运输品名
/// </summary>
public string commodityTran { get; set; }
/// <summary>
///
/// </summary>
public string emergencyContact { get; set; }
/// <summary>
/// 应急措施号
/// </summary>
public string emsNo { get; set; }
/// <summary>
/// 闪点
/// </summary>
public string flashPoint { get; set; }
/// <summary>
/// 闪电单位
/// </summary>
public string flashUnit { get; set; }
/// <summary>
/// 毛重
/// </summary>
public int grossWeight { get; set; }
/// <summary>
/// 是否海污
/// </summary>
public string isMpt { get; set; }
/// <summary>
/// 危险品标签
/// </summary>
public string labels { get; set; }
/// <summary>
/// 净重
/// </summary>
public int netWeight { get; set; }
/// <summary>
/// 件数
/// </summary>
public int nums { get; set; }
/// <summary>
/// 包装等级
/// </summary>
public string packageClass { get; set; }
/// <summary>
/// 包装类型
/// </summary>
public string packageType { get; set; }
/// <summary>
/// 包装名称
/// </summary>
public string packageName { get; set; }
/// <summary>
/// 危险品页号
/// </summary>
public string page { get; set; }
/// <summary>
/// 联合国编号
/// </summary>
public string undgNo { get; set; }
/// <summary>
/// 紧急联系人
/// </summary>
public string contactName { get; set; }
/// <summary>
/// 联系号码
/// </summary>
public string contactNum { get; set; }
/// <summary>
///
/// </summary>
public string packagingCode { get; set; }
}
}