using DSWeb.Common.DB; using DSWeb.Common.Extentions; using DSWeb.Common.Helper; using FluentFTP.Helpers; using JobReqWebData; using log4net; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Quartz.Impl; using RabbitMQ.Client; using RabbitMQ.Client.Events; using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Data.Entity.Migrations; using System.Data.SqlClient; using System.Linq; using System.Security.Policy; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using Topshelf; namespace DSWeb.Service.Output.DS7 { public class DS7Service : ServiceControl { private const string ExchangeName = "output"; private static ILog logger = LogManager.GetLogger("DS7Service"); //private const string QueuePrefixCangDan = "djy.output.cangdan.ds7."; //private const string QueuePrefixBaoguan = "djy.output.baoguan.ds7."; //private const string QueuePrefixBG = "djy.output.baoguan.bg.ds7."; private const string QueuePrefix_DingCang = "djy.output.dingcang.ds6."; /// /// 在大简云的公司ID /// private static string CompanyId = ConfigurationManager.AppSettings["CompanyId"].ToLower(); //private static string Corpid = ConfigurationManager.AppSettings["Corpid"]; //private static string DS7ConnStr = ConfigurationManager.ConnectionStrings["DongShengDB"].ConnectionString; private static string DS6ConnStr = ConfigurationManager.ConnectionStrings["DS6DB"].ConnectionString; private string RecMqUri = ConfigurationManager.AppSettings["ReceiveMQUri"]; //private string FeeInputUserId = ConfigurationManager.AppSettings["FeeInputUserId"]; private static string UserNameStr = ConfigurationManager.AppSettings["UserNameStr"]; private IConnection mqConn; //费用相关配置 //private static string FeePayName = ConfigurationManager.AppSettings["FeePayName"]; //private static string FeePayCustomer = ConfigurationManager.AppSettings["FeePayCustomer"]; //private static string FeePayCustomerType = ConfigurationManager.AppSettings["FeePayCustomerType"]; //private static decimal FeePayPrice = Convert.ToDecimal(ConfigurationManager.AppSettings["FeePayPrice"]); //private static string FeePayMyshippingName = ConfigurationManager.AppSettings["FeePayMyshippingName"]; //private static string FeePayMyshippingCustomer = ConfigurationManager.AppSettings["FeePayMyshippingCustomer"]; //private static decimal FeePayMyshippingPrice = Convert.ToDecimal(ConfigurationManager.AppSettings["FeePayMyshippingPrice"]); //private static string FeeShouName = ConfigurationManager.AppSettings["FeeShouName"]; private CommonDataContext dS7Data = new CommonDataContext(); public List usernamelist=new List(); public bool Start(HostControl hostControl) { // 开始具体的业务逻辑 logger.Debug("开始运行"); dS7Data.Database.Log = (x => { logger.Debug(x); }); if (!string.IsNullOrWhiteSpace(UserNameStr)) { usernamelist = UserNameStr.Split(',').ToList() ; } try { ConnectionFactory factory = new ConnectionFactory(); factory.Uri = new Uri(RecMqUri); mqConn = factory.CreateConnection(); IModel modelDingCang = mqConn.CreateModel(); modelDingCang.ExchangeDeclare(ExchangeName, ExchangeType.Direct); modelDingCang.QueueDeclare($"{QueuePrefix_DingCang}{CompanyId}", false, false, false, null); var consumerDingCang = new EventingBasicConsumer(modelDingCang); consumerDingCang.Received += (ch, ea) => { var body = ea.Body; var strBody = Encoding.UTF8.GetString(body.ToArray()); logger.Debug($"收到大简云订舱输出数据:{strBody}"); try { //导出到东胜6 DingCangToDS6(JArray.Parse(strBody)); } catch (Exception ex) { var excep = ex; while (excep != null) { logger.Error(excep.Message); logger.Error(excep.StackTrace); excep = excep.InnerException; } } }; //第二个参数控制【是否消费掉队列里的数据】 modelDingCang.BasicConsume($"{QueuePrefix_DingCang}{CompanyId}", true, consumerDingCang); } catch (Exception e) { logger.Error(e.Message); } return true; } public bool Stop(HostControl hostControl) { // 结束 logger.Debug("停止运行"); //StdSchedulerFactory.GetDefaultScheduler().Shutdown(); mqConn.Close(); return true; } #region 舱单数据解析实体类 public class Ctnlist { /// /// /// public string ctn_id { get; set; } /// /// /// public string MFNO { get; set; } /// /// /// public string CTNCODE { get; set; } /// /// /// public int? SIZE { get; set; } /// /// /// public string CTN { get; set; } /// /// /// public int? CTNNUM { get; set; } /// /// /// public int? TEU { get; set; } /// /// /// public string CTNALL { get; set; } /// /// /// public string CNTRNO { get; set; } /// /// /// public string SEALNO { get; set; } /// /// /// public int? PKGS { get; set; } /// /// /// public decimal? KGS { get; set; } /// /// /// public decimal? CBM { get; set; } /// /// /// public string KINDPKGS { get; set; } /// /// /// public string DESCRIPTION { get; set; } /// /// /// public string MARKS { get; set; } /// /// /// public string PO { get; set; } /// /// /// public string SKU { get; set; } /// /// /// public string SKUDESCRIP { get; set; } /// /// /// public string DUNNO { get; set; } /// /// /// public string HTS { get; set; } /// /// /// public string CTOFORIGIN { get; set; } /// /// /// public decimal? GOODVALUE { get; set; } /// /// /// public string CTNOWNER { get; set; } /// /// /// public string ShiFengRen { get; set; } /// /// /// public string LeiXingFa { get; set; } /// /// /// public string LeiXingShou { get; set; } /// /// /// public string LeiXingTong { get; set; } /// /// /// public int ZhongKongBiaoShi { get; set; } /// /// /// public string ChengZhongZhongLiang { get; set; } /// /// /// public string ChengZhongFangShi { get; set; } /// /// /// public string ChengZhongShiJian { get; set; } /// /// /// public decimal? PIZHONG { get; set; } /// /// /// public string APICTNID { get; set; } /// /// /// public DateTime? VGMCLOSETIME { get; set; } } public class OpSeaeEdi { /// /// /// public string MBLNO { get; set; } /// /// /// public string HBLNO { get; set; } /// /// /// public string CARRIERID { get; set; } /// /// /// public string CARRIER { get; set; } /// /// /// public string WeiTuoFaSongFang { get; set; } /// /// /// public string DESTINATION { get; set; } /// /// /// public string DESTINATIONID { get; set; } /// /// /// public string PORTDISCHARGE { get; set; } /// /// /// public string PORTDISCHARGEID { get; set; } /// /// /// public DateTime? ETD { get; set; } /// /// /// public string CompId { get; set; } /// /// 东方海外物流(中国)有限公司青岛分公司 /// public string CompName { get; set; } /// /// /// public string MFNO { get; set; } /// /// /// public string BSNO { get; set; } /// /// /// public string MASTERNO { get; set; } /// /// /// public string SHIPPERNAME { get; set; } /// /// /// public string SHIPPERADDR1 { get; set; } /// /// /// public string SHIPPERCOUNTRY { get; set; } /// /// /// public string SHIPPERTEL { get; set; } /// /// /// public string CONSIGNEENAME { get; set; } /// /// /// public string CONSIGNEEADDR1 { get; set; } /// /// /// public string CONSIGNEECOUNTRY { get; set; } public string CONSIGNEETEL { get; set; } public string NOTIFYPARTYNAME { get; set; } public string NOTIFYPARTYADDR1 { get; set; } /// /// /// public string NOTIFYPARTYCOUNTRY { get; set; } /// /// /// public string NOTIFYPARTYTEL { get; set; } /// /// /// public string SHIPPER { get; set; } /// /// /// public string CONSIGNEE { get; set; } /// /// /// public string NOTIFYPARTY { get; set; } /// /// /// public string VESSEL { get; set; } /// /// /// public string VOYNO { get; set; } /// /// /// public string PORTLOADID { get; set; } /// /// /// public string PORTLOAD { get; set; } /// /// /// public string PLACEDELIVERYID { get; set; } /// /// /// public string PLACEDELIVERY { get; set; } /// /// /// public string SERVICE { get; set; } /// /// /// public string MARKS { get; set; } /// /// /// public string DESCRIPTION { get; set; } /// /// /// public int? PKGS { get; set; } /// /// /// public string KINDPKGS { get; set; } /// /// /// public decimal? KGS { get; set; } /// /// /// public decimal? CBM { get; set; } /// /// /// public string CARGOID { get; set; } /// /// /// public string DCLASS { get; set; } /// /// /// public string DUNNO { get; set; } /// /// /// public string REEFERF { get; set; } /// /// /// public string TEMPID { get; set; } /// /// /// public string TEMPSET { get; set; } /// /// /// public string TEMPMAX { get; set; } /// /// /// public string TEMPMIN { get; set; } /// /// /// public string FREIGHTAGMNO { get; set; } /// /// /// public string HUMIDITY { get; set; } /// /// /// public string SHIPIMO { get; set; } /// /// /// public DateTime? ETA { get; set; } /// /// /// public string BLFRT { get; set; } /// /// /// public DateTime? SENDTIME { get; set; } /// /// /// public string YARD { get; set; } /// /// 外代 /// public string FORWARDER { get; set; } /// /// /// public List ctnlist { get; set; } } #endregion /// /// 舱单数据生成到OPOther版本的舱单业务中 经汉专用 /// /// //public void CangdanDataToDS7_OPOther(JArray jarr) //{ // try // { // var opUser = dS7Data.User.AsNoTracking().First(u => u.GID == FeeInputUserId); // foreach (var item in jarr) // { // var obj = item as JObject; // var itemstr = item.ToString(); // var _edi = JsonConvert.DeserializeObject(itemstr); // var MBLNO = obj.GetValue("MBLNO").ToString(); // var HBLNO = obj.GetValue("HBLNO").ToString(); // var CARRIERID = obj.GetValue("CARRIERID").ToString(); // var CARRIER = obj.GetValue("CARRIER").ToString(); // var WeiTuoFaSongFang = obj.GetValue("WeiTuoFaSongFang").ToString(); // var DESTINATION = obj.GetValue("DESTINATION").ToString(); // var DESTINATIONID = obj.GetValue("DESTINATIONID").ToString(); // var PORTDISCHARGE = obj.GetValue("PORTDISCHARGE").ToString(); // var PORTDISCHARGEID = obj.GetValue("PORTDISCHARGEID").ToString(); // var strETD = obj.GetValue("ETD").ToString(); // var ETD = Convert.ToDateTime(strETD); // var CompId = obj.GetValue("CompId").ToString(); // var ORDERNO = obj.GetValue("ORDERNO").ToString(); // var 对账约号 = obj.GetValue("REMARKS").ToString(); // //看op_other当中有没有该业务主单 如无则增加 // var 主单mfno = "topother" + _edi.MFNO; // if (!string.IsNullOrWhiteSpace(_edi.BSNO)) 主单mfno = "topother" + _edi.BSNO; // op_other_md op_other = dS7Data.op_other.FirstOrDefault(x => x.BSNO == 主单mfno); // var BSNO = ""; // var CUSTNOHEAD = ""; // var CUSTOMERNAME = ""; // var SOURCEOP = ""; // var 费用标准结算对象 = ""; // var 船代 = ""; // var custEdi = dS7Data.CodeCustEdi.AsNoTracking().FirstOrDefault(x => x.EDINAME == "DJY_OUTPUT" && x.EDICODE == WeiTuoFaSongFang); // if (custEdi != null) // { // 费用标准结算对象 = custEdi.CUST; // } // var 船代Edi= dS7Data.CodeCustEdi.AsNoTracking().FirstOrDefault(x => x.EDINAME == "DJY_OUTPUT" && x.EDICODE == _edi.FORWARDER); // if (船代Edi != null) { // 船代 = 船代Edi.CUST; // } // //如果大简云业务中的【订舱编号】空着,则用大简云舱单界面的【委托发送方】 ,寻找EDI代码设置中的EDICODE =【委托发送方】 EDINAME = 大简云的客户 填入【委托单位】字段的内容 // //如果大简云业务中的【订舱编号】不为空, 录入的是"市场部/海运部,MKT1(英文逗号分割)" // //根据【订舱编号】录入的"市场部/海运部"对应到东胜系统里的【委托单位】,通过EDI代码设置中的EDICODE = 市场部 / 海运部 EDINAME = 大简云选择填入【委托单位】字段的内容 // //订舱编号里逗号后面的“MKT1”放到源操作SOURCEOP上 // //导入舱单时产生的舱单费 // //1 单价从cust_fee_templatedetail当中的舱单费选取 // //选取标准为:根据大简云舱单界面的【委托发送方】,寻找EDI代码设置中的EDICODE =【委托发送方】 EDINAME = 大简云的客户 ,用这个客户名称查询cust_fee_templatedetail当中的舱单费 // //2费用的结算对象 为这票业务在东胜系统中的委托单位 // if (string.IsNullOrWhiteSpace(ORDERNO)) // { // //var custEdi = dS7Data.CodeCustEdi.AsNoTracking().FirstOrDefault(x => x.EDINAME == "DJY_OUTPUT" && x.EDICODE == WeiTuoFaSongFang); // //if (custEdi != null) // //{ // // CUSTOMERNAME = custEdi.CUST; // //} // CUSTOMERNAME = 费用标准结算对象; // } // else { // ORDERNO=ORDERNO.Replace(",", ","); // var orderinfo = ORDERNO.Split(',').ToList(); // if (orderinfo.Count == 0) { // orderinfo.Add(""); // orderinfo.Add(""); // } // if (orderinfo.Count == 1) // { // orderinfo.Add(""); // } // var cust = orderinfo[0]; // var custEdi2 = dS7Data.CodeCustEdi.AsNoTracking().FirstOrDefault(x => x.EDINAME == "DJY_OUTPUT" && x.EDICODE == cust); // if (custEdi2 != null) // { // CUSTOMERNAME = custEdi2.CUST; // } // SOURCEOP = orderinfo[1]; // } // var 委托单位 = dS7Data.info_client.FirstOrDefault(x => x.SHORTNAME == CUSTOMERNAME); // if (op_other == null || op_other.BSNO == null || op_other.BSNO == "") // { // logger.Debug($"未找到委托数据:{MBLNO}"); // BSNO = 主单mfno; // //件数 毛重 净重 尺码 sum // var PKGS = 0; // var KGS = 0M; // var CBM = 0M; // foreach (var ja in jarr) // { // var _edi2= JsonConvert.DeserializeObject(ja.ToString()); // PKGS += _edi2.PKGS==null?0:(int)_edi2.PKGS; // KGS += _edi2.KGS == null ? 0M : (decimal)_edi2.KGS; // CBM += _edi2.CBM == null ? 0M : (decimal)_edi2.CBM; // } // var newrec = new op_other_md // { // BSNO = BSNO, // OPLB = "op_other", // OPLBNAME = "舱单申报", // BSSTATUS = false, // FEESTATUS = false, // MBLNO = MBLNO, // HBLNO = "", // CUSTOMERNAME = 委托单位.SHORTNAME, // //CUSTOMERNAME2 = WeiTuoFaSongFang,//20230313-大简云舱单界面的【委托发送方】录入东胜系统的实际客户, // //CARRIER // BSDATE = DateTime.Today, // ACCDATE = DateTime.Now.ToString("yyyy-MM"), // BSSOURCE = 委托单位.BSSOURCE, // OP = opUser.SHOWNAME, // CUSTSERVICE = opUser.SHOWNAME, // SALE = opUser.SHOWNAME, // CORPID = Corpid, // ETD = ETD,//业务日期 // //SR2023011000005 // PORTLOAD = _edi.PORTLOAD,//装货港 // PORTDISCHARGE = _edi.PORTDISCHARGE,//卸货港 // PKGS = PKGS, // KGS = KGS, // NETWEIGHT = 0, // CBM = CBM, // //SOURCEOP = SOURCEOP, // //SHIPAGENT = 船代 // }; // //,DUIYUEHAO = 对账约号 // //20230317 对账约号存于opLogic // var cdc = new CommonDataContext(); // var dic = new Dictionary // { // { "DUIYUEHAO",对账约号 } // }; // SaveLogicInfo(BSNO, "舱单业务", dic); // var billnoset = dS7Data.SysBillNoSet.AsNoTracking().FirstOrDefault(x => x.COMPANYID == Corpid && x.OPLBNAME == "舱单申报" && x.RULEBLNO == "委托编号"); // if (billnoset != null) // newrec.CUSTNO = GetBillNo(billnoset, newrec.ETD.ToString(), newrec.ACCDATE, opname: opUser.SHOWNAME, corpid: Corpid); // else // { // logger.Debug($"SysBillNoSet数据未找到,无法生成编号:{MBLNO}"); // } // dS7Data.op_other.Add(newrec); // dS7Data.SaveChanges(); // op_other= dS7Data.op_other.FirstOrDefault(x => x.BSNO == 主单mfno); // } // else // { // logger.Debug($"委托数据已存在:{MBLNO}"); // BSNO = op_other.BSNO; // CUSTNOHEAD = op_other.CUSTNO; // } // //看op_seae_edi当中有没有该业务 如无则增加 // var ediList = dS7Data.op_seae_edi.Where(x => x.BSNO == BSNO).ToList(); // if (!ediList.Exists(x => x.MBLNO == MBLNO && x.HBLNO == HBLNO)) // { // var newedi = new op_seae_edi_md { // MFNO = _edi.MFNO, // BSNO = 主单mfno, // MASTERNO = 主单mfno, // CUSTNO = CUSTNOHEAD + (ediList.Count + 1).ToString(), // MBLNO =_edi.MBLNO, // HBLNO = _edi.HBLNO, // CARRIERID = _edi.CARRIERID, // CARRIER = _edi.CARRIER, // //WeiTuoFaSongFang = _edi.WeiTuoFaSongFang, // DESTINATION = _edi.DESTINATION, // DESTINATIONID = _edi.DESTINATIONID, // PORTDISCHARGE = _edi.PORTDISCHARGE, // PORTDISCHARGEID = _edi.PORTDISCHARGEID, // ETD = _edi.ETD, // SHIPPERNAME = _edi.SHIPPERNAME, // SHIPPERADDR1 = _edi.SHIPPERADDR1, // SHIPPERCOUNTRY = _edi.SHIPPERCOUNTRY, // SHIPPERTEL = _edi.SHIPPERTEL, // CONSIGNEENAME = _edi.CONSIGNEENAME, // CONSIGNEEADDR1 = _edi.CONSIGNEEADDR1, // CONSIGNEECOUNTRY = _edi.CONSIGNEECOUNTRY, // CONSIGNEETEL = _edi.CONSIGNEETEL, // NOTIFYPARTYNAME = _edi.NOTIFYPARTYNAME, // NOTIFYPARTYADDR1 = _edi.NOTIFYPARTYADDR1, // NOTIFYPARTYCOUNTRY = _edi.NOTIFYPARTYCOUNTRY, // NOTIFYPARTYTEL = _edi.NOTIFYPARTYTEL, // SHIPPER = _edi.SHIPPER, // CONSIGNEE = _edi.CONSIGNEE, // NOTIFYPARTY = _edi.NOTIFYPARTY, // VESSEL = _edi.VESSEL, // VOYNO = _edi.VOYNO, // PORTLOADID = _edi.PORTLOADID, // PORTLOAD = _edi.PORTLOAD, // PLACEDELIVERYID = _edi.PLACEDELIVERYID, // PLACEDELIVERY = _edi.PLACEDELIVERY, // SERVICE = _edi.SERVICE, // MARKS = _edi.MARKS, // DESCRIPTION = _edi.DESCRIPTION, // PKGS = _edi.PKGS, // KINDPKGS = _edi.KINDPKGS, // KGS = _edi.KGS, // CBM = _edi.CBM, // CARGOID = _edi.CARGOID, // DCLASS = _edi.DCLASS, // DUNNO = _edi.DUNNO, // REEFERF = _edi.REEFERF, // TEMPID = _edi.TEMPID, // TEMPSET = _edi.TEMPSET, // TEMPMAX = _edi.TEMPMAX, // TEMPMIN = _edi.TEMPMIN, // FREIGHTAGMNO = _edi.FREIGHTAGMNO, // HUMIDITY = _edi.HUMIDITY, // SHIPIMO = _edi.SHIPIMO, // ETA = _edi.ETA, // BLFRT = _edi.BLFRT, // SENDTIME = _edi.SENDTIME, // YARD = _edi.YARD, // FORWARDER = _edi.FORWARDER, // CORPID= Corpid // }; // dS7Data.op_seae_edi.Add(newedi); // if (_edi.ctnlist != null && _edi.ctnlist.Count > 0) { // foreach (var ctn in _edi.ctnlist) { // var newctn = new op_seae_edi_ctn_md // { // ctn_id = Guid.NewGuid().ToString(),//ctn.ctn_id, // MFNO = _edi.MFNO, // CTNCODE = ctn.CTNCODE, // CNTRNO= ctn.CNTRNO, // SEALNO = ctn.SEALNO, // SIZE = ctn.SIZE.ToString(), // CTN = ctn.CTN, // CTNNUM = ctn.CTNNUM, // TEU = ctn.TEU, // CTNALL = ctn.CTNALL, // PKGS = ctn.PKGS, // KGS = ctn.KGS, // CBM = ctn.CBM, // KINDPKGS = ctn.KINDPKGS, // DESCRIPTION = ctn.DESCRIPTION, // MARKS = ctn.MARKS, // PO = ctn.PO, // SKU = ctn.SKU, // SKUDESCRIP = ctn.SKUDESCRIP, // DUNNO = ctn.DUNNO, // HTS = ctn.HTS, // CTOFORIGIN = ctn.CTOFORIGIN, // GOODVALUE = ctn.GOODVALUE, // CTNOWNER = ctn.CTNOWNER // }; // dS7Data.op_seae_edi_ctn.Add(newctn); // } // } // dS7Data.SaveChanges(); // } // //只要有对应的往来单位=委托发送方 主分单都产生相应的应收 // info_client_md infoClient = null; // if (!string.IsNullOrEmpty(CUSTOMERNAME)) // { // infoClient = dS7Data.info_client.AsNoTracking().FirstOrDefault(x => x.SHORTNAME == CUSTOMERNAME); // if (infoClient != null) // { // op_other.SALE = infoClient.SALE; //揽货人赋值 // //查询配置,生成应收 // var fee = dS7Data.CustFeeTemplateDetail.AsNoTracking().FirstOrDefault(x => x.CUSTOMERNAME == 费用标准结算对象 && x.FEENAME == FeeShouName); // if (fee == null) { // fee = dS7Data.CustFeeTemplateDetail.AsNoTracking().FirstOrDefault(x => x.CUSTOMERNAME == 委托单位.SHORTNAME && x.FEENAME == FeeShouName); // } // if (fee != null ) // { // var feeShou = new ch_fee_md(); // feeShou.GID = Guid.NewGuid().ToString().Replace("-", ""); // feeShou.BSNO = op_other.BSNO; // feeShou.FEETYPE = 1; // feeShou.FEENAME = FeeShouName; // feeShou.CUSTOMERTYPE = "其他"; // feeShou.CUSTOMERNAME = infoClient.SHORTNAME; // feeShou.UNIT = fee.UNIT; // feeShou.UNITPRICE = fee.UNITPRICE; // feeShou.QUANTITY = 1; // feeShou.AMOUNT = fee.UNITPRICE; // feeShou.EXCHANGERATE = 1; // feeShou.CURRENCY = "RMB"; // feeShou.ENTEROPERATOR = FeeInputUserId; // feeShou.ENTERDATE = DateTime.Now; // feeShou.MODIFIEDUSER = FeeInputUserId; // feeShou.MODIFIEDTIME = DateTime.Now; // feeShou.LOCALCURR = feeShou.CURRENCY; // feeShou.FEEDESCRIPTION = feeShou.FEENAME; // feeShou.FEESTATUS = 0;//费用插入时状态为提交审核;2021-12-8,要求插入时状态改为录入状态:1;2021-12-9,要求状态为审核通过状态:0 // //2021-12-8,下列字段不能为空,写入默认值 // feeShou.SETTLEMENT = 0; // feeShou.ORDERAMOUNT = 0; // feeShou.ORDERINVOICE = 0; // feeShou.ORDERINVSETTLEMENT = 0; // feeShou.ORDERSETTLEMENT = 0; // feeShou.INVOICE = 0; // feeShou.TAXRATE = 0; // feeShou.ISADVANCEDPAY = false; // feeShou.ISINVOICE = false; // feeShou.ISCRMORDERFEE = false; // feeShou.TAXUNITPRICE = fee.UNITPRICE;//2021-12-29,于菲:同样赋值单价和金额 // feeShou.NOTAXAMOUNT = fee.UNITPRICE;//2021-12-29,于菲:同样赋值单价和金额 // //2021-12-9,要求下列字段不能为空,填写0或false // feeShou.COMMISSIONRATE = 0; // feeShou.AUDITSTATUS = 0; // feeShou.LINENUM = 0; // feeShou.ISDEBIT = false; // feeShou.ISOPEN = false; // feeShou.ACCTAXRATE = 0; // feeShou.ISVOU = false; // feeShou.TAX = 0; // feeShou.PREAMOUNT = 0; // feeShou.ISACC = false; // feeShou.CUSTDUI = false; // feeShou.BXGID = HBLNO; // //2021-12-23:分单号写入备注 // //if (!string.IsNullOrEmpty(HBLNO)) // //{ // // feeShou.REMARK += $" {HBLNO} "; // //} // dS7Data.ch_fee.Add(feeShou); // } // } // } // if (FeePayCustomerType == "船代") { // //20230327 改为: // //如应付对象类型为船代 则结算对象改为该业务的船代公司 // FeePayCustomer = 船代; // } // var 分单号 = HBLNO; // if (string.IsNullOrWhiteSpace(HBLNO)) { // 分单号 = MBLNO; // } // //应付 // if (string.IsNullOrEmpty(HBLNO) && FeePayPrice>0) //主单才插入船代费用 // { // var feeFu = new ch_fee_md(); // feeFu.GID = Guid.NewGuid().ToString().Replace("-", ""); // feeFu.BSNO = op_other.BSNO; // feeFu.FEETYPE = 2; // feeFu.FEENAME = FeePayName; // feeFu.CUSTOMERTYPE = FeePayCustomerType; // feeFu.CUSTOMERNAME = FeePayCustomer; // feeFu.UNIT = "票"; // feeFu.UNITPRICE = FeePayPrice; // feeFu.QUANTITY = 1; // feeFu.AMOUNT = FeePayPrice; // feeFu.EXCHANGERATE = 1; // feeFu.CURRENCY = "RMB"; // feeFu.ENTEROPERATOR = FeeInputUserId; // feeFu.ENTERDATE = DateTime.Now; // feeFu.MODIFIEDUSER = FeeInputUserId; // feeFu.MODIFIEDTIME = DateTime.Now; // feeFu.LOCALCURR = feeFu.CURRENCY; // feeFu.FEEDESCRIPTION = feeFu.FEENAME; // feeFu.FEESTATUS = 0;//费用插入时状态为提交审核;2021-12-8,要求插入时状态改为录入状态:1;2021-12-9,要求状态为审核通过状态:0 // //2021-12-8,下列字段不能为空,写入默认值 // feeFu.SETTLEMENT = 0; // feeFu.ORDERAMOUNT = 0; // feeFu.ORDERINVOICE = 0; // feeFu.ORDERINVSETTLEMENT = 0; // feeFu.ORDERSETTLEMENT = 0; // feeFu.INVOICE = 0; // feeFu.TAXRATE = 0; // feeFu.ISADVANCEDPAY = false; // feeFu.ISINVOICE = false; // feeFu.ISCRMORDERFEE = false; // feeFu.TAXUNITPRICE = FeePayPrice; // feeFu.NOTAXAMOUNT = 0; // //2021-12-9,要求下列字段不能为空,填写0或false // feeFu.COMMISSIONRATE = 0; // feeFu.AUDITSTATUS = 0; // feeFu.LINENUM = 0; // feeFu.ISDEBIT = false; // feeFu.ISOPEN = false; // feeFu.ACCTAXRATE = 0; // feeFu.ISVOU = false; // feeFu.TAX = 0; // feeFu.PREAMOUNT = 0; // feeFu.ISACC = false; // feeFu.CUSTDUI = false; // feeFu.BXGID = 分单号; // dS7Data.ch_fee.Add(feeFu); // dS7Data.SaveChanges(); // } // if (FeePayMyshippingPrice > 0) { // //不管主单分单都要付费给大简云 // var feeFuDJY = new ch_fee_md(); // feeFuDJY.GID = Guid.NewGuid().ToString().Replace("-", ""); // feeFuDJY.BSNO = op_other.BSNO; // feeFuDJY.FEETYPE = 2; // feeFuDJY.FEENAME = FeePayMyshippingName; // feeFuDJY.CUSTOMERTYPE = "其他"; // feeFuDJY.CUSTOMERNAME = FeePayMyshippingCustomer; // feeFuDJY.UNIT = "票"; // feeFuDJY.UNITPRICE = FeePayMyshippingPrice; // feeFuDJY.QUANTITY = 1; // feeFuDJY.AMOUNT = FeePayMyshippingPrice; // feeFuDJY.EXCHANGERATE = 1; // feeFuDJY.CURRENCY = "RMB"; // feeFuDJY.ENTEROPERATOR = FeeInputUserId; // feeFuDJY.ENTERDATE = DateTime.Now; // feeFuDJY.MODIFIEDUSER = FeeInputUserId; // feeFuDJY.MODIFIEDTIME = DateTime.Now; // feeFuDJY.LOCALCURR = feeFuDJY.CURRENCY; // feeFuDJY.FEEDESCRIPTION = feeFuDJY.FEENAME; // feeFuDJY.FEESTATUS = 0;//费用插入时状态为提交审核;2021-12-8,要求插入时状态改为录入状态:1;2021-12-9,要求状态为审核通过状态:0 // //2021-12-8,下列字段不能为空,写入默认值 // feeFuDJY.SETTLEMENT = 0; // feeFuDJY.ORDERAMOUNT = 0; // feeFuDJY.ORDERINVOICE = 0; // feeFuDJY.ORDERINVSETTLEMENT = 0; // feeFuDJY.ORDERSETTLEMENT = 0; // feeFuDJY.INVOICE = 0; // feeFuDJY.TAXRATE = 0; // feeFuDJY.ISADVANCEDPAY = false; // feeFuDJY.ISINVOICE = false; // feeFuDJY.ISCRMORDERFEE = false; // feeFuDJY.TAXUNITPRICE = FeePayMyshippingPrice; // feeFuDJY.NOTAXAMOUNT = 0; // //2021-12-9,要求下列字段不能为空,填写0或false // feeFuDJY.COMMISSIONRATE = 0; // feeFuDJY.AUDITSTATUS = 0; // feeFuDJY.LINENUM = 0; // feeFuDJY.ISDEBIT = false; // feeFuDJY.ISOPEN = false; // feeFuDJY.ACCTAXRATE = 0; // feeFuDJY.ISVOU = false; // feeFuDJY.TAX = 0; // feeFuDJY.PREAMOUNT = 0; // feeFuDJY.ISACC = false; // feeFuDJY.CUSTDUI = false; // feeFuDJY.BXGID = 分单号; // dS7Data.ch_fee.Add(feeFuDJY); // //dS7Data.Database.Log = (x => { logger.Debug(x); }); // dS7Data.SaveChanges(); // } // } // } // catch (Exception e) { // logger.Error($"导入舱单出错:{e}"); // } //} /// /// 生成编号(从东胜7移植并修改) /// /// /// /// /// /// /// /// /// private string GetBillNo(SysBillNoSet billType, string bsdate, string accdate, string dbname = "", string opname = "", string corpid = "", string bshead = "") { var orgCode = ""; var UserCode = ""; UserCode = GetUserCode(opname, dbname); orgCode = GetCorpCode(corpid, dbname); //List paramArray = new List(); //paramArray.Add(new SqlParameter("@ps_BillType", billType.BILLTYPE)); //paramArray.Add(new SqlParameter("@ps_OrgCode", orgCode)); //paramArray.Add(new SqlParameter("@ps_EmpCode", UserCode)); //paramArray.Add(new SqlParameter("@ps_bshead", bshead)); //if (billType.RULEDATETYPE == "业务日期") // paramArray.Add(new SqlParameter("@ps_Date", bsdate)); //else if (billType.RULEDATETYPE == "会计期间" && accdate.Length == 7) // paramArray.Add(new SqlParameter("@ps_Date", accdate + "-01")); //else // paramArray.Add(new SqlParameter("@ps_Date", accdate + "")); //paramArray.Add(new SqlParameter("@ps_BillNo", 20)); //SqlParameter sqlParaOut = new SqlParameter("@ps_RefBillNo", SqlDbType.VarChar, 50); //sqlParaOut.Direction = ParameterDirection.Output; //paramArray.Add(sqlParaOut); //dS7Data.Database.ExecuteSqlCommand("EXEC [sSysGetBillNo_new] @ps_BillType,@ps_OrgCode,@ps_EmpCode,@ps_bshead,@ps_Date,@ps_BillNo,@ps_RefBillNo output", paramArray.ToArray()); //ExecStoredProcedure("sSysGetBillNo_new", paramArray.ToArray()); var bsDate = string.Empty; if (!string.IsNullOrWhiteSpace(bsdate)) bsdate = Convert.ToDateTime(bsdate).ToString("yyyy-MM-dd"); if (billType.RULEDATETYPE == "业务日期") bsDate = bsdate; else if (billType.RULEDATETYPE == "会计期间" && accdate.Length == 7) bsDate = accdate + "-01"; else bsDate = accdate; var cmd = $@"DECLARE @ps_BillNo varchar(20) EXEC [sSysGetBillNo_new] @ps_BillType = N'{billType.BILLTYPE}', @ps_OrgCode = N'{orgCode}', @ps_EmpCode = N'{UserCode}', @ps_Date = N'{bsDate}', @ps_bshead = N'{bshead}', @ps_BillNo = @ps_BillNo OUTPUT, @ps_RefBillNo = N'' SELECT @ps_BillNo as N'billno'"; return dS7Data.Database.SqlQuery(cmd).First(); } /// /// 获取用户code(参考东胜7修改) /// /// /// /// private string GetUserCode(string username, string dbname = "") { //string EDICODE = ""; //var strSql = new StringBuilder(); //strSql.Append("select CODENAME from [user] where SHOWNAME='" + username + "'"); //Database db = string.IsNullOrWhiteSpace(dbname) ? DatabaseFactory.CreateDatabase() : DatabaseFactory.CreateDatabase(dbname); //using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) //{ // while (reader.Read()) // { // EDICODE = Convert.ToString(reader["CODENAME"]); // } // reader.Close(); //} //return EDICODE; return dS7Data.Database.SqlQuery("select CODENAME from [user] where SHOWNAME='" + username + "'").FirstOrDefault(); } /// /// 获取公司code(参考东胜7修改) /// /// /// /// private string GetCorpCode(string Corpid, string dbname = "") { //string EDICODE = ""; //var strSql = new StringBuilder(); //strSql.Append("select CODENAME from [company] where GID='" + Corpid + "'"); //Database db = string.IsNullOrWhiteSpace(dbname) ? DatabaseFactory.CreateDatabase() : DatabaseFactory.CreateDatabase(dbname); //using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) //{ // while (reader.Read()) // { // EDICODE = Convert.ToString(reader["CODENAME"]); // } // reader.Close(); //} //return EDICODE; return dS7Data.Database.SqlQuery("select CODENAME from [company] where GID='" + Corpid + "'").FirstOrDefault(); } public static int ExecStoredProcedure(string procName, params SqlParameter[] parameters) { int rtn = 0; using (SqlConnection conn = new SqlConnection(DS6ConnStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { SqlTransaction st = conn.BeginTransaction(); cmd.Transaction = st; try { cmd.CommandText = procName; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddRange(parameters); var rr = cmd.ExecuteScalar(); st.Commit(); return rtn; } catch (SqlException sqlex) { st.Rollback(); throw sqlex; } } } } #region 大简云通过消息队列发布的订舱数据,保存至DS6 用于合川家业务从大简云发布的消息队列中解析至DS6数据库 public void DingCangToDS6(JArray jarr) { try { DS6DataContext DS6Data = new DS6DataContext(); foreach (var item in jarr) { var obj = item as JObject; var itemstr = item.ToString(); var head = JsonConvert.DeserializeObject(itemstr); //判断业务是否存在。判断依据为head. //如果不存在 则新增 //如存在,则删除原有箱信息。ETD ATD 使用原有数据而不用大简云发布的信息覆盖 var currentBillList = DS6Data.t_op_seae.Where(x => x.业务编号 == head.bsno).ToList(); if (currentBillList != null && currentBillList.Count > 0) { //更新当前业务 var updrec = currentBillList[0]; var headid = updrec.编号; var newhead = head.GetOpseae(); //过滤权限 var cando = 人员是否具备权限(newhead.录入人, "776"); if (!cando) continue; newhead.ETD = updrec.ETD; newhead.开船日期= updrec.开船日期; newhead.编号 = updrec.编号; newhead.主编号 = updrec.主编号; newhead.业务状态 = updrec.业务状态; newhead.费用状态 = updrec.费用状态; DS6Data.t_op_seae.AddOrUpdate(newhead); var ctnlist = DS6Data.t_op_ctn.Where(x => x.编号 == headid).ToList(); DS6Data.t_op_ctn.RemoveRange(ctnlist); var newctnList = head.GetCtnList(newhead); DS6Data.t_op_ctn.AddRange(newctnList); var amslist = DS6Data.t_op_ams.Where(x => x.编号 == headid).ToList(); DS6Data.t_op_ams.RemoveRange(amslist); var newamslist = head.GetAmsList(newhead); DS6Data.t_op_ams.AddRange(newamslist); var old_assistantList = DS6Data.t_op_seae_assistant.Where(x => x.编号 == headid).ToList(); var assistantUpdList = new List(); var assistantAddList = new List(); var assistantDelList = new List(); //DS6Data.t_op_seae_assistant.RemoveRange(amslist); var newassistantList = head.GetAssistantList(newhead); foreach (var newassis in newassistantList) { var needinsert = true; if (old_assistantList != null && old_assistantList.Count > 0) { foreach (var oldassis in old_assistantList) { if (newassis.BSNO == oldassis.BSNO) { var updassis = newassis; updassis.AS_ID = oldassis.AS_ID; assistantUpdList.Add(updassis); needinsert = false; } else { assistantDelList.Add(oldassis); } } } if (needinsert) assistantAddList.Add(newassis); } if (assistantDelList.Count > 0) DS6Data.t_op_seae_assistant.RemoveRange(assistantDelList); if (assistantUpdList.Count > 0) { foreach(var upd in assistantUpdList) DS6Data.t_op_seae_assistant.AddOrUpdate(upd); } if (assistantAddList.Count > 0) DS6Data.t_op_seae_assistant.AddRange(assistantAddList); DS6Data.SaveChanges(); } else { //新增业务 var newhead = head.GetOpseae(); //过滤权限 var cando = 人员是否具备权限(newhead.录入人, "776"); if (!cando) continue; var 编号 = DS6Data.t_op_seae.Max(m => m.编号); var new编号 = (int.Parse(编号) + 1).ToString().PadLeft(10,' '); newhead.编号 = new编号; newhead.主编号 = new编号; DS6Data.t_op_seae.Add(newhead); DS6Data.SaveChanges(); newhead = DS6Data.t_op_seae.First(x => x.业务编号 == head.bsno); var headid = newhead.编号; var ctnlist = DS6Data.t_op_ctn.Where(x => x.编号 == headid).ToList(); DS6Data.t_op_ctn.RemoveRange(ctnlist); var newctnList = head.GetCtnList(newhead); DS6Data.t_op_ctn.AddRange(newctnList); var amslist = DS6Data.t_op_ams.Where(x => x.编号 == headid).ToList(); DS6Data.t_op_ams.RemoveRange(amslist); var newamslist = head.GetAmsList(newhead); DS6Data.t_op_ams.AddRange(newamslist); var old_assistantList = DS6Data.t_op_seae_assistant.Where(x => x.编号 == headid).ToList(); var assistantUpdList = new List(); var assistantAddList = new List(); var assistantDelList = new List(); //DS6Data.t_op_seae_assistant.RemoveRange(amslist); var newassistantList = head.GetAssistantList(newhead); foreach (var newassis in newassistantList) { var needinsert = true; if (old_assistantList != null && old_assistantList.Count > 0) { foreach (var oldassis in old_assistantList) { if (newassis.BSNO == oldassis.BSNO) { var updassis = newassis; updassis.AS_ID = oldassis.AS_ID; assistantUpdList.Add(updassis); needinsert = false; } else { assistantDelList.Add(oldassis); } } } if (needinsert) assistantAddList.Add(newassis); } if (assistantDelList.Count > 0) DS6Data.t_op_seae_assistant.RemoveRange(assistantDelList); if (assistantUpdList.Count > 0) { foreach (var upd in assistantUpdList) DS6Data.t_op_seae_assistant.AddOrUpdate(upd); } if (assistantAddList.Count > 0) DS6Data.t_op_seae_assistant.AddRange(assistantAddList); DS6Data.SaveChanges(); } } } catch (Exception e) { logger.Error($"导入订舱信息出错:{e}"); } } public bool 人员是否具备权限(string username, string 权限值) { //SELECT [人员] FROM[dbo].[t_sys_code_emp] where 权限代码 = '776' and 是否可操作 = 1 /* var ds6 = new DS6DataContext(); var _userinfo = ds6.t_sys_code_emp.Where(x => x.人员 == username && x.权限代码 == "776" && x.是否可操作 == true).ToList(); if (_userinfo != null && _userinfo.Count > 0) { return true; } else { return false; }*/ //测试期逻辑 判断是否在配置文件字段中存在 if (usernamelist.IndexOf(username) > 0) { return true; } else { return false; } } #endregion #region 大简云订舱数据解析类 public class DingCangHead { public string bsno { get; set; } //"string", public string bsstatus { get; set; } //"string", public string bsstatusname { get; set; } //"string", public DateTime? bsdate { get; set; } //"2023-03-30T03:12:51.033Z", public string mblno { get; set; } //"string", public string hblno { get; set; } //"string", public string bookingno { get; set; } //"string", public string contractno { get; set; } //"string", public string servicecontractno { get; set; } //"string", public string shipperid { get; set; } //"string", public string consigneeid { get; set; } //"string", public string notifypartyid { get; set; } //"string", public string shipper { get; set; } //"string", public string consignee { get; set; } //"string", public string notifyparty { get; set; } //"string", public string notifypartY2 { get; set; } //"string", public string yardid { get; set; } //"string", public string yard { get; set; } //"string", public string vesselid { get; set; } //"string", public string vessel { get; set; } //"string", public string voyno { get; set; } //"string", public string voynoinner { get; set; } //"string", public DateTime? etd { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? atd { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? closingdate { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? closedocdate { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? closevgmdate { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? eta { get; set; } //"2023-03-30T03:12:51.033Z", public string placereceiptid { get; set; } //"string", public string placereceipt { get; set; } //"string", public string portloadid { get; set; } //"string", public string portload { get; set; } //"string", public string portdischargeid { get; set; } //"string", public string portdischarge { get; set; } //"string", public string placedeliveryid { get; set; } //"string", public string placedelivery { get; set; } //"string", public string destinationid { get; set; } //"string", public string destination { get; set; } //"string", public string nobill { get; set; } //"string", public string copynobill { get; set; } //"string", public string issuetype { get; set; } //"string", public DateTime? issuedate { get; set; } //"2023-03-30T03:12:51.033Z", public string issueplaceid { get; set; } //"string", public string issueplace { get; set; } //"string", public string blfrt { get; set; } //"string", public string prepardat { get; set; } //"string", public string payableat { get; set; } //"string", public string service { get; set; } //"string", public string marks { get; set; } //"string", public string hscode { get; set; } //"string", public string description { get; set; } //"string", public int? pkgs { get; set; } = 0; public string kindpkgs { get; set; } //"string", public decimal? kgs { get; set; } = 0; public decimal? cbm { get; set; } = 0; public string totalno { get; set; } //"string", public string cntrtotal { get; set; } //"string", public string carrierid { get; set; } //"string", public string carrier { get; set; } //"string", public string cargoid { get; set; } //"string", public string dclass { get; set; } //"string", public string dunno { get; set; } //"string", public string dpage { get; set; } //"string", public string dlabel { get; set; } //"string", public string linkman { get; set; } //"string", public string tempid { get; set; } //"string", public string tempset { get; set; } //"string", public string reeferf { get; set; } //"string", public string humidity { get; set; } //"string", public string tempmin { get; set; } //"string", public string tempmax { get; set; } //"string", public bool? iscontainersoc { get; set; } //true, public string soremark { get; set; } //"string", public string siremark { get; set; } //"string", public string yardremark { get; set; } //"string", public string compid { get; set; } //"string", public string compname { get; set; } //"string", public string shippername { get; set; } //"string", public string shipperaddR1 { get; set; } //"string", public string shipperaddR2 { get; set; } //"string", public string shipperaddR3 { get; set; } //"string", public string shippercity { get; set; } //"string", public string shipperprovince { get; set; } //"string", public string shipperpostcode { get; set; } //"string", public string shippercountry { get; set; } //"string", public string shipperattn { get; set; } //"string", public string shippertel { get; set; } //"string", public string consigneename { get; set; } //"string", public string consigneeaddR1 { get; set; } //"string", public string consigneeaddR2 { get; set; } //"string", public string consigneeaddR3 { get; set; } //"string", public string consigneecity { get; set; } //"string", public string consigneeprovince { get; set; } //"string", public string consigneepostcode { get; set; } //"string", public string consigneercountry { get; set; } //"string", public string consigneeattn { get; set; } //"string", public string consigneetel { get; set; } //"string", public string notifypartyname { get; set; } //"string", public string notifypartyaddR1 { get; set; } //"string", public string notifypartyaddR2 { get; set; } //"string", public string notifypartyaddR3 { get; set; } //"string", public string notifypartycity { get; set; } //"string", public string notifypartyprovince { get; set; } //"string", public string notifypartypostcode { get; set; } //"string", public string notifypartycountry { get; set; } //"string", public string notifypartyattn { get; set; } //"string", public string notifypartytel { get; set; } //"string", public string pono { get; set; } //"string", public string opid { get; set; } //"string", public string docid { get; set; } //"string", public string op { get; set; } //"string", public string doc { get; set; } //"string", public string saleid { get; set; } //"string", public string sale { get; set; } //"string", public string custserviceid { get; set; } //"string", public string custservice { get; set; } //"string", public string customername { get; set; } //"string", public string forwarder { get; set; } //"string", public string shipagency { get; set; } //"string", public string customser { get; set; } //"string", public string trucker { get; set; } //"string", public string agentid { get; set; } //"string", public int? customerid { get; set; } //= 0; public string forwarderid { get; set; } //"string", public string shipagencyid { get; set; } //"string", public string customserid { get; set; } //"string", public string truckerid { get; set; } //"string", public string agentname { get; set; } //"string", public string weituo { get; set; } //"string", public string consigneedooraddr { get; set; } //"string", public string shipperdooraddr { get; set; } //"string", public string scaccode { get; set; } //"string", public string itncode { get; set; } //"string", public string prepardatid { get; set; } //"string", public string payableatid { get; set; } //"string", public string custno { get; set; } //"string", public string transportid { get; set; } //"string", public string transport { get; set; } //"string", public string thirdpayaddr { get; set; } //"string", public string yardcontract { get; set; } //"string", public string yardcontracttel { get; set; } //"string", public string yardcontractemail { get; set; } //"string", public bool? feeself { get; set; } //true, public string lanecode { get; set; } //"string", public string lanename { get; set; } //"string", public string freightpayer { get; set; } //"string", public string goodscode { get; set; } //"string", public string goodsname { get; set; } //"string", public string pkgstotal { get; set; } //"string", public string kgstotal { get; set; } //"string", public string cbmtotal { get; set; } //"string", public string routeid { get; set; } //"string", public string route { get; set; } //"string", public string warehouse { get; set; } //"string", public string warehouseID { get; set; } //"string", public string epCode { get; set; } //"string", public string lineName { get; set; } //"string", public string dzRemark { get; set; } //"string", public string czRemark { get; set; } //"string", public string createdUserName { get; set; } //"string", public List ctnInputs { get; set; } public DingCangbookingEDIExt bookingEDIExt { get; set; } public List childrens { get; set; } public List goodsStatus { get; set; } public t_op_seae_md GetOpseae() { DateTime dateTime = new DateTime(((DateTime)etd).Year, 1, 1); TimeSpan ts1 = ((DateTime)etd).Subtract(dateTime).Duration(); var days = ts1.Days; var weeks=(int)( Math.Ceiling(days / 7.0)); var result = new t_op_seae_md { 业务编号 = bsno, 业务状态="接受委托", 费用状态="录入状态", 会计期间= etd, 装运方式="整票", 周次= weeks, 录入日期 = bsdate, 主提单号 = mblno, 分提单号= hblno, 订舱序列号= bookingno, 运费协议号= contractno, 发货人代码= shipper, 收货人代码= consignee, 通知人代码= notifyparty, 场站= yard, 船名= vessel, 航次= voyno, 开船日期= etd, 截港日期= closingdate, 卸货代码= portdischargeid, 卸货港= portdischarge, 交货代码= placedeliveryid, 交货地点= placedelivery, 目的地代码= destinationid, 目的地= destination, 提单份数= nobill, 副本提单份数= copynobill, 签单方式= issuetype, 签单日期= issuedate, 签单地点= issueplace, 付费方式= blfrt, 预付地点= prepardat, 到付地点= payableat, 运输条款= service, 唛头= marks, 运输方式 = hscode, 货物描述 = description, 件数= pkgs, 包装= kindpkgs, 重量= kgs, 尺码= cbm, 件数大写= totalno, 集装箱= cntrtotal, 船公司= carrier, 货物标识= cargoid, 危险品分类= dclass, 危险品编号= dunno, 设置温度= tempset, 冷藏通风量= reeferf, 最低温度= tempmin, 最高温度= tempmax, 是否自有箱= iscontainersoc, EDI备注= soremark, //全称= compname, 委托编号= pono, 操作员= op, 单证员= doc, 揽货人= sale, 航线操作= route, 委托单位= customername, 报关行= customser, 承运车队= trucker, 货代公司= agentname, 备案号= lanecode, 航线=lanename, 船代= shipagency, 代理= agentname, 其他备注= dzRemark, 占舱备注= czRemark, 货物名称= goodsname, 录入人= createdUserName, 订舱人说明 = (bookingEDIExt==null) ?"": bookingEDIExt.orderRemark, }; return result; } public List GetCtnList(t_op_seae_md head) { var result = new List (); foreach (var ctn in ctnInputs) { var d6 = new DS6DataContext(); var 箱型infoList = d6.t_code_ctn.Where(x => (x.尺寸 + x.箱型) == ctn.ctnall).ToList(); var 箱型info = new t_code_ctn_md(); if (箱型infoList != null && 箱型infoList.Count > 0) { 箱型info = 箱型infoList[0]; } else { continue; } var newctn = new t_op_ctn_md { 代码 = 箱型info.代码, 尺寸 = 箱型info.尺寸, 箱型 = 箱型info.箱型, 编号 = head.编号, 表现形式 = ctn.ctnall, 数量 = ctn.ctnnum, 箱号 = ctn.cntrno, 封号 = ctn.sealno, 件数 = ctn.pkgs, 包装 = ctn.kindpkgs, 重量 = ctn.kgs, 尺码 = ctn.cbm, 皮重 = ctn.tareweight, TEU = (箱型info.尺寸 == "20" ? 1 : 2), 称重重量 =ctn.weighkgs }; result.Add (newctn); } return result; } public List GetAmsList(t_op_seae_md head) { var result = new List(); //foreach (var item in bookingEDIExt) //{ var item = bookingEDIExt; var newrec = new t_op_ams_md { 编号 = head.编号, 发货人代码 = item.shipperEdiCode, 收货人代码 = item.consigneeEdiCode, 销售代码 = item.salerCode, 危险品联系人 = item.ediAttn, 危险品联系方式 = item.ediAttnTel, 欧盟HSCODE = item.ckhi, 南美东NCM = item.cncm, 巴西木质包装说明 = item.wncm, }; result.Add (newrec); //} return result; } public List GetAssistantList(t_op_seae_md head) { var result = new List(); foreach (var item in childrens) { var newrec = new t_op_seae_assistant_md { 编号 = head.编号, 主编号 = head.编号, BSNO= item.bsno, 录入日期 = item.bsdate, 主提单号 = item.mblno, 分提单号 = item.hblno, //订舱序列号 = item.bookingno, 发货人代码 = item.shipper, 收货人代码 = item.consignee, 通知人代码 = item.notifyparty, 提单份数= item.nobill, 签单方式=item.issuetype, 签单日期 = item.issuedate, 签单地点=item.issueplace, 付费方式=item.blfrt, 预付地点=item.prepardat, 到付地点=item.payableat, 运输条款=item.service, 唛头=item.marks, 运输方式=item.hscode, 货物描述=item.description, 件数=item.pkgs, 包装=item.kindpkgs, 重量=item.kgs, 尺码= item.cbm, 件数大写=item.totalno, 集装箱= item.totalno, 船公司 = item.carrier, 货物标识 = item.cargoid, 危险品分类=item.dclass, 危险品编号= item.dunno, 设置温度=item.tempset, 冷藏通风量=item.reeferf, 最低温度=item.tempmin, 最高温度=item.tempmax, 是否自有箱=item.iscontainersoc, 委托编号=item.pono, 操作员=item.op, 揽货人 = item.sale, 客服员=item.custservice, //预付地点= item.prepardatid, //到付地点= item.payableatid, }; result.Add(newrec); } return result; } } public class DingCangCtn { public long? id { get; set; } public long? billid { get; set; } public string ctncode { get; set; } //"string", public string ctnall { get; set; } //"string", public int? ctnnum { get; set; } = 0; public int? teu { get; set; } = 0; public string cntrno { get; set; } //"string", public string sealno { get; set; } //"string", public int? pkgs { get; set; } = 0; public string kindpkgs { get; set; } //"string", public decimal? kgs { get; set; } = 0M; public decimal? cbm { get; set; } = 0M; public decimal? tareweight { get; set; } = 0M; public string ctnstatus { get; set; } //"string", public string weightype { get; set; } //"string", public decimal? weighkgs { get; set; } = 0M; public string weighattn { get; set; } //"string", public string vgmconncom { get; set; } //"string", public string weightel { get; set; } //"string", public string weighdate { get; set; } //"string", public string vgmaddr { get; set; } //"string", public string vgmemail { get; set; } //"string", public string remark { get; set; } //"string", public List ctnDetailInputs { get; set; } } public class DingCangCtnDetail { public long? id { get; set; } public string ctnid { get; set; } public decimal? pkgs { get; set; } = 0M; public string kindpkgs { get; set; } //"string", public decimal? kgs { get; set; } = 0M; public decimal? cbm { get; set; } = 0M; public string hscode { get; set; } //"string", public string marks { get; set; } //"string", public string description { get; set; } //"string", public string remark { get; set; } } public class DingCangbookingEDIExt { public string weiTuoFang { get; set; } //"string", public string sendCode { get; set; } //"string", public string receiveCode { get; set; } //"string", public string notifyCdoe { get; set; } //"string", public string salerCode { get; set; } //"string", public string masterBolIndicator { get; set; } //"string", public string emanifestHbl { get; set; } //"string", public string consigneeEdiCode { get; set; } //"string", public string shipperEdiCode { get; set; } //"string", public string ediAttn { get; set; } //"string", public string ediAttnTel { get; set; } //"string", public string ediAttnMail { get; set; } //"string", public string amsConsignee { get; set; } //"string", public string amsNotifyParty { get; set; } //"string", public string opEName { get; set; } //"string", public string opTel { get; set; } //"string", public string opEmail { get; set; } //"string", public string acihbl { get; set; } //"string", public string s0CC0C { get; set; } //"string", public string goodsName { get; set; } //"string", public string masterBolIndicatorName { get; set; } //"string", public string salerCodeName { get; set; } //"string", public string ckhi { get; set; } //"string", public string cncm { get; set; } //"string", public string wncm { get; set; } //"string", public string orderRemark { get; set; } //"string", public string exRemark1 { get; set; } //"string", public string exRemark2 { get; set; } //"string", public string exRemark3 { get; set; } //"string", public string exRemark4 { get; set; } //"string", public decimal? kingTareweight { get; set; } = 0M; } /// /// 提单信息 /// public class DingCangTDXX { public string bsno { get; set; } //"string", public string bsstatus { get; set; } //"string", public string bsstatusname { get; set; } //"string", public DateTime? bsdate { get; set; } //"2023-03-30T03:12:51.033Z", public string mblno { get; set; } //"string", public string hblno { get; set; } //"string", public string bookingno { get; set; } //"string", public string contractno { get; set; } //"string", public string servicecontractno { get; set; } //"string", public string shipperid { get; set; } //"string", public string consigneeid { get; set; } //"string", public string notifypartyid { get; set; } //"string", public string shipper { get; set; } //"string", public string consignee { get; set; } //"string", public string notifyparty { get; set; } //"string", public string notifypartY2 { get; set; } //"string", public string yardid { get; set; } //"string", public string yard { get; set; } //"string", public string vesselid { get; set; } //"string", public string vessel { get; set; } //"string", public string voyno { get; set; } //"string", public string voynoinner { get; set; } //"string", public DateTime? etd { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? atd { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? closingdate { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? closedocdate { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? closevgmdate { get; set; } //"2023-03-30T03:12:51.033Z", public DateTime? eta { get; set; } //"2023-03-30T03:12:51.033Z", public string placereceiptid { get; set; } //"string", public string placereceipt { get; set; } //"string", public string portloadid { get; set; } //"string", public string portload { get; set; } //"string", public string portdischargeid { get; set; } //"string", public string portdischarge { get; set; } //"string", public string placedeliveryid { get; set; } //"string", public string placedelivery { get; set; } //"string", public string destinationid { get; set; } //"string", public string destination { get; set; } //"string", public string nobill { get; set; } //"string", public string copynobill { get; set; } //"string", public string issuetype { get; set; } //"string", public DateTime? issuedate { get; set; } //"2023-03-30T03:12:51.033Z", public string issueplaceid { get; set; } //"string", public string issueplace { get; set; } //"string", public string blfrt { get; set; } //"string", public string prepardat { get; set; } //"string", public string payableat { get; set; } //"string", public string service { get; set; } //"string", public string marks { get; set; } //"string", public string hscode { get; set; } //"string", public string description { get; set; } //"string", public int? pkgs { get; set; } = 0; public string kindpkgs { get; set; } //"string", public decimal? kgs { get; set; } = 0; public decimal? cbm { get; set; } = 0; public string totalno { get; set; } //"string", public string cntrtotal { get; set; } //"string", public string carrierid { get; set; } //"string", public string carrier { get; set; } //"string", public string cargoid { get; set; } //"string", public string dclass { get; set; } //"string", public string dunno { get; set; } //"string", public string dpage { get; set; } //"string", public string dlabel { get; set; } //"string", public string linkman { get; set; } //"string", public string tempid { get; set; } //"string", public string tempset { get; set; } //"string", public string reeferf { get; set; } //"string", public string humidity { get; set; } //"string", public string tempmin { get; set; } //"string", public string tempmax { get; set; } //"string", public bool? iscontainersoc { get; set; } //true, public string soremark { get; set; } //"string", public string siremark { get; set; } //"string", public string yardremark { get; set; } //"string", public string compid { get; set; } //"string", public string compname { get; set; } //"string", public string shippername { get; set; } //"string", public string shipperaddR1 { get; set; } //"string", public string shipperaddR2 { get; set; } //"string", public string shipperaddR3 { get; set; } //"string", public string shippercity { get; set; } //"string", public string shipperprovince { get; set; } //"string", public string shipperpostcode { get; set; } //"string", public string shippercountry { get; set; } //"string", public string shipperattn { get; set; } //"string", public string shippertel { get; set; } //"string", public string consigneename { get; set; } //"string", public string consigneeaddR1 { get; set; } //"string", public string consigneeaddR2 { get; set; } //"string", public string consigneeaddR3 { get; set; } //"string", public string consigneecity { get; set; } //"string", public string consigneeprovince { get; set; } //"string", public string consigneepostcode { get; set; } //"string", public string consigneercountry { get; set; } //"string", public string consigneeattn { get; set; } //"string", public string consigneetel { get; set; } //"string", public string notifypartyname { get; set; } //"string", public string notifypartyaddR1 { get; set; } //"string", public string notifypartyaddR2 { get; set; } //"string", public string notifypartyaddR3 { get; set; } //"string", public string notifypartycity { get; set; } //"string", public string notifypartyprovince { get; set; } //"string", public string notifypartypostcode { get; set; } //"string", public string notifypartycountry { get; set; } //"string", public string notifypartyattn { get; set; } //"string", public string notifypartytel { get; set; } //"string", public string pono { get; set; } //"string", public string opid { get; set; } //"string", public string docid { get; set; } //"string", public string op { get; set; } //"string", public string doc { get; set; } //"string", public string saleid { get; set; } //"string", public string sale { get; set; } //"string", public string custserviceid { get; set; } //"string", public string custservice { get; set; } //"string", public string customername { get; set; } //"string", public string forwarder { get; set; } //"string", public string shipagency { get; set; } //"string", public string customser { get; set; } //"string", public string trucker { get; set; } //"string", public string agentid { get; set; } //"string", public int? customerid { get; set; } //= 0; public string forwarderid { get; set; } //"string", public string shipagencyid { get; set; } //"string", public string customserid { get; set; } //"string", public string truckerid { get; set; } //"string", public string agentname { get; set; } //"string", public string weituo { get; set; } //"string", public string consigneedooraddr { get; set; } //"string", public string shipperdooraddr { get; set; } //"string", public string scaccode { get; set; } //"string", public string itncode { get; set; } //"string", public string prepardatid { get; set; } //"string", public string payableatid { get; set; } //"string", public string custno { get; set; } //"string", public string transportid { get; set; } //"string", public string transport { get; set; } //"string", public string thirdpayaddr { get; set; } //"string", public string yardcontract { get; set; } //"string", public string yardcontracttel { get; set; } //"string", public string yardcontractemail { get; set; } //"string", public bool? feeself { get; set; } //true, public string lanecode { get; set; } //"string", public string lanename { get; set; } //"string", public string freightpayer { get; set; } //"string", public string goodscode { get; set; } //"string", public string goodsname { get; set; } //"string", public string pkgstotal { get; set; } //"string", public string kgstotal { get; set; } //"string", public string cbmtotal { get; set; } //"string", public string routeid { get; set; } //"string", public string route { get; set; } //"string", public string warehouse { get; set; } //"string", public string warehouseID { get; set; } //"string", public string epCode { get; set; } //"string", public string lineName { get; set; } //"string", public List ctnInputs { get; set; } public List bookingEDIExt { get; set; } } public class DingCanggoodsStatus { public string statusName { get; set; } //"string", public DateTime? finishTime { get; set; }//2023-03-30T03:12:51.034Z", public string remark { get; set; } //"string", public string extData { get; set; }//"string", } #endregion #region 逻辑信息子表操作 #region 将一个dictionary转化为用;;和::隔开的文本 public static string DicToStr(Dictionary dic) { var result = ""; foreach (var item in dic) { result += item.Key + "::" + item.Value + ";;"; } return result; } #endregion #region 将一个用;;和::隔开的文本转化为dictionary public static Dictionary StrToDic(string dicstr) { var result = new Dictionary(); var list = Regex.Split(dicstr, ";;").ToList(); foreach (var item in list) { var itemarray = Regex.Split(item, "::"); if (itemarray.Length < 2) continue; result.Add(itemarray[0], itemarray[1] == null ? "" : itemarray[1]); } return result; } #endregion public static Dictionary GetLogicInfo(string BSNO, string PROPNAME) { CommonDataContext cdc = new CommonDataContext(); var result = new Dictionary(); var infoList = cdc.OP_LOGICINFO.Where(x => x.BSNO == BSNO && x.PROPNAME == PROPNAME).ToList(); if (infoList != null && infoList.Count > 0) { result = StrToDic(infoList[0].PROPVALUE); } return result; } public static void SaveLogicInfo(string BSNO, string PROPNAME, Dictionary InfoDic) { CommonDataContext cdc = new CommonDataContext(); var result = new Dictionary(); var infoList = cdc.OP_LOGICINFO.Where(x => x.BSNO == BSNO && x.PROPNAME == PROPNAME).ToList(); if (infoList != null && infoList.Count > 0) { infoList[0].PROPVALUE = DicToStr(InfoDic); cdc.OP_LOGICINFO.AddOrUpdate(infoList[0]); cdc.SaveChanges(); } else { var newinfo = new OP_LOGICINFO_md(); newinfo.GID = Guid.NewGuid(); newinfo.BSNO = BSNO; newinfo.PROPNAME = PROPNAME; newinfo.PROPVALUE = DicToStr(InfoDic); cdc.OP_LOGICINFO.Add(newinfo); cdc.SaveChanges(); } } #endregion } }