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 + "
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.BSLIST[0].CUSTNAME;
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].CONSIGNORADDR;
//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].NOTIFYADDR;
//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();
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 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 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
///
/// 货物类型翻译
///
///
///
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
{
///
/// 客户名称
///
public string consignorCustName { get; set; }
///
/// 启运港代码
///
public string polId { get; set; }
///
/// 启运港名称
///
public string polName { get; set; }
///
/// 目的港代码
///
public string podId { get; set; }
///
/// 目的港名称
///
public string podName { get; set; }
///
/// 交货地代码
///
public string deliveryId { get; set; }
///
/// 交货地名称
///
public string deliveryName { get; set; }
///
/// 收货地代码
///
public string porId { get; set; }
///
/// 收货地名称
///
public string porName { get; set; }
///
/// 中转港名称
///
public string poWtatName { get; set; }
///
/// 船名
///
public string vesselName { get; set; }
///
/// 航线
///
public string lineCode { get; set; }
///
/// 航次
///
public string voyNo { get; set; }
///
/// 离港时间
///
public string etd { get; set; }
///
/// 到港时间
///
public string eta { get; set; }
///
/// 收货人名称
///
public string consigneeName { get; set; }
/////
///// 收货人地址
/////
//public string consigneeAddr { get; set; }
/////
///// 传真
/////
//public string consigneeFax { get; set; }
/////
///// 电话
/////
//public string consigneeTel { get; set; }
/////
///// 企业代码
/////
//public string consigneeBsCode { get; set; }
/////
///// 邮件
/////
//public string consigneeEmail { get; set; }
///
/// 发货人名称
///
public string consignorName { get; set; }
/////
///// 发货人地址
/////
//public string consignorAddr { get; set; }
/////
///// 传真
/////
//public string consignorFax { get; set; }
/////
///// 电话
/////
//public string consignorTel { get; set; }
/////
///// 企业代码
/////
//public string consignorBsCode { get; set; }
/////
///// 邮件
/////
//public string consignorEmail { get; set; }
///
/// 通知人名称
///
public string notifyName { get; set; }
/////
///// 通知人地址
/////
//public string notifyAddr { get; set; }
/////
///// 传真
/////
//public string notifyFax { get; set; }
/////
///// 电话
/////
//public string notifyTel { get; set; }
/////
///// 企业代码
/////
//public string notifyBsCode { get; set; }
/////
///// 邮件
/////
//public string notifyEmail { get; set; }
///
/// 运输条款
///
public string movementType { get; set; }
///
/// 毛重
///
public decimal weight { get; set; }
///
/// 体积
///
public decimal cube { get; set; }
///
/// 件数
///
public int packages { get; set; }
///
/// 包装类型
///
public string packingType { get; set; }
///
/// 包装类型
///
public string packageDesc { get; set; }
///
/// 唛头
///
public string marks { get; set; }
///
/// 货物描述
///
public string cargoDesc { get; set; }
///
/// 货物类型
///
public string cargoType { get; set; }
///
/// 是否危险品
///
public bool isDanger { get; set; }
///
/// 是否冻柜
///
public bool isRf { get; set; }
///
/// 是否特种箱
///
public bool isSpec { get; set; }
///
/// 是否挂衣箱
///
public bool isGoh { get; set; }
///
/// 是否SOC
///
public bool isSoc { get; set; }
///
/// 联系信息
///
public string contactInfo { get; set; }
///
/// 委托备注
///
public string remark { get; set; }
///
/// 支付方式
///
public string payTerm { get; set; }
///
/// 委托类型
///
public string blType { get; set; }
///
/// 放单方式
///
public string releaseModeMbl { get; set; }
///
/// 箱信息
///
public List containers { get; set; }
///
/// 其它特殊货物信息
///
public List extras { get; set; }
///
/// 危险品信息
///
public List dangerInfo { get; set; }
}
public class SitcApiPostModelContainer
{
///
/// 尺寸
///
public string ctnSize { get; set; }
///
/// 类型
///
public string ctnType { get; set; }
///
/// 数量
///
public int ctnNum { get; set; }
}
public class SitcApiPostModelExtra
{
///
/// 最高温度
///
public string tempMax { get; set; }
///
/// 最低温度
///
public string tempMin { get; set; }
///
/// 温度设置
///
public string tempSetting { get; set; }
///
/// 温度单位
///
public string unit { get; set; }
///
/// 湿度
///
public string humdity { get; set; }
///
/// 通风口
///
public string vent { get; set; }
///
/// 类型
///
public string ctype { get; set; }
}
public class SitcApiPostModelDangerInfo
{
///
/// 危险品等级
///
public string classNo { get; set; }
///
/// 化学品名
///
public string commodityChem { get; set; }
///
/// 运输品名
///
public string commodityTran { get; set; }
///
///
///
public string emergencyContact { get; set; }
///
/// 应急措施号
///
public string emsNo { get; set; }
///
/// 闪点
///
public string flashPoint { get; set; }
///
/// 闪电单位
///
public string flashUnit { get; set; }
///
/// 毛重
///
public int grossWeight { get; set; }
///
/// 是否海污
///
public string isMpt { get; set; }
///
/// 危险品标签
///
public string labels { get; set; }
///
/// 净重
///
public int netWeight { get; set; }
///
/// 件数
///
public int nums { get; set; }
///
/// 包装等级
///
public string packageClass { get; set; }
///
/// 包装类型
///
public string packageType { get; set; }
///
/// 包装名称
///
public string packageName { get; set; }
///
/// 危险品页号
///
public string page { get; set; }
///
/// 联合国编号
///
public string undgNo { get; set; }
///
/// 紧急联系人
///
public string contactName { get; set; }
///
/// 联系号码
///
public string contactNum { get; set; }
///
///
///
public string packagingCode { get; set; }
}
}