using DSWeb.Common.DB;
using DSWeb.Common.Extentions;
using DSWeb.Common.Helper;
using FluentFTP.Helpers;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip;
using JobReqWebData;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Quartz;
using Quartz.Impl;
using Quartz.Util;
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.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Security.Policy;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Topshelf;
using static DSWeb.Service.Output.DS7.DS6Service;
using static System.Data.Entity.Infrastructure.Design.Executor;
namespace DSWeb.Service.Output.DS7
{
public class DS6Service : ServiceControl
{
private const string ExchangeName = "output";
private static ILog logger = LogManager.GetLogger("DS6Service");
//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.";
private const string QueuePrefix_Del = "djy.output.dingcang.ds6_delete.";
private const string QueuePrefix_Letter_RH = "djy.output.dingcang.ds6_fangcang.";
private const string QueuePrefix_Letter_PC = "djy.output.booktruck.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 消费数据 = ConfigurationManager.AppSettings["USEDATA"];
//private string FeeInputUserId = ConfigurationManager.AppSettings["FeeInputUserId"];
//private static string UserNameStr = ConfigurationManager.AppSettings["UserNameStr"];
private IConnection mqConn;
//private IConnection mqConn2;
private IConnection mqConn3;
private IConnection mqConn4;
//费用相关配置
//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); });
//测试时为false
var 消费队列数据 = (消费数据 == "true");
//if (!string.IsNullOrWhiteSpace(UserNameStr)) {
// usernamelist = UserNameStr.Split(',').ToList() ;
//}
try
{
//测试数据
#region 测试文本
/* 测试时前面增加两个注释号
var testjson = @"[{""Id"":476086087065670,""BSNO"":null,""BSSTATUS"":null,""BSSTATUSNAME"":""已派车"",""BSDATE"":""2023-10-27T00:00:00"",""MBLNO"":""177RZHZHQ2432VRF"",""HBLNO"":""CMTA2023D502"",""BOOKINGNO"":""476086087065669"",""CONTRACTNO"":""没有0"",""SERVICECONTRACTNO"":null,""SHIPPERID"":null,""CONSIGNEEID"":null,""NOTIFYPARTYID"":null,""SHIPPER"":""CIMC WETRANS LEADING FRESH LOGISTICS \nTECHNOLOGY (SHANDONG) CO.,LTD\n1-47 NO. 44 JIAHU ROAD HETOUDIAN TOWN \nLAIXI QINGDAO SHANDONG CHINA 266621\n"",""CONSIGNEE"":""REJOICE LOGISTICS (CANADA) INC.\n#260-11780 HAMMERSMITH WAY,\nRICHMOND, B.C. CANADA V7A 5E9\nTEL : 604-204-2668\nFAX : 604-204-2568\nE-MAIL :INFO@REJOICELOGISTICS.CA"",""NOTIFYPARTY"":""REJOICE LOGISTICS (CANADA) INC.\n#260-11780 HAMMERSMITH WAY,\nRICHMOND, B.C. CANADA V7A 5E9\nTEL : 604-204-2668\nFAX : 604-204-2568\nE-MAIL :INFO@REJOICELOGISTICS.CA"",""NOTIFYPARTY2"":"""",""YARDID"":""GLCZ"",""YARD"":""港陆场站"",""VESSELID"":null,""VESSEL"":""MSC IVANA"",""VOYNO"":""UK343A"",""VOYNOINNER"":""UK343A"",""ETD"":""2023-11-04T00:00:00"",""ATD"":null,""CLOSINGDATE"":null,""CLOSEDOCDATE"":null,""CLOSEVGMDATE"":null,""ETA"":null,""PLACERECEIPTID"":"""",""PLACERECEIPT"":"""",""PORTLOADID"":""CNTAO"",""PORTLOAD"":""QINGDAO,CHINA"",""PORTDISCHARGEID"":""CAVAN"",""PORTDISCHARGE"":""VANCOUVER"",""PLACEDELIVERYID"":"""",""PLACEDELIVERY"":"""",""DESTINATIONID"":""CAVAN"",""DESTINATION"":""VANCOUVER"",""NOBILL"":"""",""COPYNOBILL"":"""",""ISSUETYPE"":"""",""ISSUEDATE"":null,""ISSUEPLACEID"":"""",""ISSUEPLACE"":""QINGDAO,CHINA"",""BLFRT"":""FREIGHT PREPAID"",""PREPARDAT"":""QINGDAO,CHINA"",""PAYABLEAT"":"""",""SERVICE"":""CY-CY"",""MARKS"":""N/M"",""HSCODE"":"""",""DESCRIPTION"":""FRESH WHITE RADISH\nHS CODE:070690\nTEMP:-1'C\nVENT:20CBM/H"",""PKGS"":1440,""KINDPKGS"":""CARTONS"",""KGS"":27000.00000,""CBM"":50.0000,""TOTALNO"":""SAY:ONE THOUSAND FOUR HUNDRED AND FORTY CARTONS ONLY."",""CNTRTOTAL"":""40'RH*1"",""CARRIERID"":""MSC"",""CARRIER"":""MSC"",""CARGOID"":""R"",""DCLASS"":"""",""DUNNO"":"""",""DPAGE"":"""",""DLABEL"":"""",""LINKMAN"":"""",""TEMPID"":"""",""TEMPSET"":"""",""REEFERF"":"""",""HUMIDITY"":"""",""TEMPMIN"":"""",""TEMPMAX"":"""",""ISCONTAINERSOC"":false,""SOREMARK"":""1660+AMS35,分单"",""SIREMARK"":"""",""YARDREMARK"":"""",""COMPID"":null,""COMPNAME"":null,""SHIPPERNAME"":null,""SHIPPERADDR1"":null,""SHIPPERADDR2"":null,""SHIPPERADDR3"":null,""SHIPPERCITY"":null,""SHIPPERPROVINCE"":null,""SHIPPERPOSTCODE"":null,""SHIPPERCOUNTRY"":null,""SHIPPERATTN"":null,""SHIPPERTEL"":null,""CONSIGNEENAME"":null,""CONSIGNEEADDR1"":null,""CONSIGNEEADDR2"":null,""CONSIGNEEADDR3"":null,""CONSIGNEECITY"":null,""CONSIGNEEPROVINCE"":null,""CONSIGNEEPOSTCODE"":null,""CONSIGNEERCOUNTRY"":null,""CONSIGNEEATTN"":null,""CONSIGNEETEL"":null,""NOTIFYPARTYNAME"":null,""NOTIFYPARTYADDR1"":null,""NOTIFYPARTYADDR2"":null,""NOTIFYPARTYADDR3"":null,""NOTIFYPARTYCITY"":null,""NOTIFYPARTYPROVINCE"":null,""NOTIFYPARTYPOSTCODE"":null,""NOTIFYPARTYCOUNTRY"":null,""NOTIFYPARTYATTN"":null,""NOTIFYPARTYTEL"":null,""PONO"":""报-BPGM23012"",""OPID"":""356029261668421"",""DOCID"":""409864742023237"",""OP"":""张艺凡"",""DOC"":""刘乙洁"",""SALEID"":""386904850808901"",""SALE"":""王寅"",""CUSTSERVICEID"":""399290671059013"",""CUSTSERVICE"":""柴婷"",""CUSTOMERNAME"":""沂水宝平-沂水宝平"",""FORWARDER"":""订舱中心"",""SHIPAGENCY"":"""",""CUSTOMSER"":""顺之航报关"",""TRUCKER"":"""",""AGENTID"":"""",""CUSTOMERID"":410507280597061,""FORWARDERID"":""DCZX"",""SHIPAGENCYID"":"""",""CUSTOMSERID"":""SZHBG"",""TRUCKERID"":"""",""AGENTNAME"":"""",""WEITUO"":"""",""CONSIGNEEDOORADDR"":null,""SHIPPERDOORADDR"":null,""SCACCODE"":"""",""ITNCODE"":"""",""PREPARDATID"":""CNTAO"",""PAYABLEATID"":"""",""CUSTNO"":"""",""TRANSPORTID"":"""",""TRANSPORT"":"""",""THIRDPAYADDR"":"""",""YARDCONTRACT"":"""",""YARDCONTRACTTEL"":"""",""YARDCONTRACTEMAIL"":"""",""FEESELF"":false,""LANECODE"":"""",""LANENAME"":""ZCP"",""FREIGHTPAYER"":"""",""GOODSCODE"":""020"",""GOODSNAME"":""ANIMAL FEEDS (SHRIMPS FEED,HAYS)"",""PKGSTOTAL"":"""",""KGSTOTAL"":"""",""CBMTOTAL"":"""",""ROUTEID"":"""",""ROUTE"":"""",""Warehouse"":"""",""WarehouseID"":"""",""EPCode"":"""",""LineName"":""美西"",""DZRemark"":""分单"",""CZRemark"":""菜 1号莱西"",""TMBLNO"":""MEDUEM280834"",""ShippingMethod"":null,""CtnDayNum"":null,""CreatedUserName"":""张艺凡"",""ZhanCangFlag"":""否"",""SourceCode"":null,""SourceName"":null,""YgtETD"":""2023-11-04T23:00:00"",""StartETA"":""2023-11-04T14:00:00"",""StartATA"":null,""MiddleETA"":null,""MiddleETD"":null,""MiddleATA"":null,""MiddleATD"":null,""ATA"":null,""ShenQingXiangShi"":""2+2"",""ForeignAgent"":null,""VERSION"":""e247e3dd-b0af-4a98-9352-0eaece3fabdb"",""ThirdPay"":null,""ThirdPayCode"":null,""ctnInputs"":[{""Id"":476086087102533,""BILLID"":476086087065670,""CTNCODE"":""4"",""CTNALL"":""40'RH"",""CTNNUM"":1,""TEU"":0,""CNTRNO"":"""",""SEALNO"":"""",""PKGS"":1440,""KINDPKGS"":""CARTONS"",""KGS"":27000.0000,""CBM"":50.0000,""TAREWEIGHT"":0.0000,""CTNSTATUS"":null,""WEIGHTYPE"":""累加"",""WEIGHKGS"":27000.0000,""WEIGHATTN"":null,""VGMCONNCOM"":null,""WEIGHTEL"":null,""WEIGHDATE"":"""",""VGMADDR"":null,""VGMEMAIL"":null,""REMARK"":null,""ctnDetailInputs"":[]}],""BookingEDIExt"":{""WeiTuoFang"":"""",""SendCode"":"""",""ReceiveCode"":"""",""NotifyCdoe"":"""",""SalerCode"":"""",""MasterBolIndicator"":"""",""EmanifestHbl"":"""",""ConsigneeEdiCode"":"""",""ShipperEdiCode"":"""",""EDIAttn"":"""",""EDIAttnTel"":"""",""EDIAttnMail"":"""",""AMSConsignee"":"""",""AMSNotifyParty"":"""",""OpEName"":"""",""OpTel"":"""",""OpEmail"":"""",""ACIHBL"":"""",""S0CC0C"":"""",""GoodsName"":"""",""MasterBolIndicatorName"":"""",""SalerCodeName"":"""",""CKHI"":"""",""CNCM"":"""",""WNCM"":"""",""OrderRemark"":"""",""ExRemark1"":"""",""ExRemark2"":"""",""ExRemark3"":"""",""ExRemark4"":"""",""KingTareweight"":null,""CNPTNo"":null,""XMCYWY"":null,""EmcNameAccount"":null},""LineManage"":""王书岚"",""LineManageID"":""356029268410437"",""childrens"":[{""Id"":477405946093638,""BSNO"":null,""BSSTATUS"":null,""BSSTATUSNAME"":""已收到BC"",""BSDATE"":""2023-10-31T00:00:00"",""MBLNO"":""177RZHZHQ2432VRF"",""HBLNO"":""CMTA2023D502 "",""BOOKINGNO"":""477405946093637"",""CONTRACTNO"":""没有0"",""SERVICECONTRACTNO"":null,""SHIPPERID"":null,""CONSIGNEEID"":null,""NOTIFYPARTYID"":null,""SHIPPER"":""YISHUI BAOPING FOODSTUFF CO.,LTD.\nYAODIANZI TOWN YISHUI COUNTY LINYI \nCITY SHANDONG PROVINCE,CHINA"",""CONSIGNEE"":""GOLDENWAY INTERNATIONAL TRADE \nCO.LTD/GOLDEN MUSHROOM\n6265 KENWAY DR. MISSISSAUGA \nONT L5T 2L3,CANADA"",""NOTIFYPARTY"":""GOLDENWAY INTERNATIONAL TRADE \nCO.LTD/GOLDEN MUSHROOM\n6265 KENWAY DR. MISSISSAUGA \nONT L5T 2L3,CANADA"",""NOTIFYPARTY2"":"""",""YARDID"":""GLCZ"",""YARD"":""港陆场站"",""VESSELID"":null,""VESSEL"":""MSC IVANA"",""VOYNO"":""UK343A"",""VOYNOINNER"":""UK343A"",""ETD"":""2023-11-04T00:00:00"",""ATD"":null,""CLOSINGDATE"":null,""CLOSEDOCDATE"":null,""CLOSEVGMDATE"":null,""ETA"":null,""PLACERECEIPTID"":"""",""PLACERECEIPT"":"""",""PORTLOADID"":""CNTAO"",""PORTLOAD"":""QINGDAO,CHINA"",""PORTDISCHARGEID"":""CAVAN"",""PORTDISCHARGE"":""VANCOUVER"",""PLACEDELIVERYID"":"""",""PLACEDELIVERY"":"""",""DESTINATIONID"":""CAVAN"",""DESTINATION"":""VANCOUVER"",""NOBILL"":"""",""COPYNOBILL"":"""",""ISSUETYPE"":"""",""ISSUEDATE"":null,""ISSUEPLACEID"":"""",""ISSUEPLACE"":""QINGDAO,CHINA"",""BLFRT"":"""",""PREPARDAT"":"""",""PAYABLEAT"":"""",""SERVICE"":""CY-CY"",""MARKS"":""N/M"",""HSCODE"":"""",""DESCRIPTION"":""FRESH WHITE RADISH\nHS CODE:070690\nTEMP:-1'C\nVENT:20CBM/H"",""PKGS"":1440,""KINDPKGS"":""CARTONS"",""KGS"":27000.00000,""CBM"":50.0000,""TOTALNO"":""SAY:ONE THOUSAND FOUR HUNDRED AND FORTY CARTONS ONLY."",""CNTRTOTAL"":""40'RH*1"",""CARRIERID"":""MSC"",""CARRIER"":""MSC"",""CARGOID"":""R"",""DCLASS"":"""",""DUNNO"":"""",""DPAGE"":"""",""DLABEL"":"""",""LINKMAN"":"""",""TEMPID"":"""",""TEMPSET"":"""",""REEFERF"":"""",""HUMIDITY"":"""",""TEMPMIN"":"""",""TEMPMAX"":"""",""ISCONTAINERSOC"":false,""SOREMARK"":""1660+AMS35,分单"",""SIREMARK"":"""",""YARDREMARK"":"""",""COMPID"":null,""COMPNAME"":null,""SHIPPERNAME"":null,""SHIPPERADDR1"":null,""SHIPPERADDR2"":null,""SHIPPERADDR3"":null,""SHIPPERCITY"":null,""SHIPPERPROVINCE"":null,""SHIPPERPOSTCODE"":null,""SHIPPERCOUNTRY"":null,""SHIPPERATTN"":null,""SHIPPERTEL"":null,""CONSIGNEENAME"":null,""CONSIGNEEADDR1"":null,""CONSIGNEEADDR2"":null,""CONSIGNEEADDR3"":null,""CONSIGNEECITY"":null,""CONSIGNEEPROVINCE"":null,""CONSIGNEEPOSTCODE"":null,""CONSIGNEERCOUNTRY"":null,""CONSIGNEEATTN"":null,""CONSIGNEETEL"":null,""NOTIFYPARTYNAME"":null,""NOTIFYPARTYADDR1"":null,""NOTIFYPARTYADDR2"":null,""NOTIFYPARTYADDR3"":null,""NOTIFYPARTYCITY"":null,""NOTIFYPARTYPROVINCE"":null,""NOTIFYPARTYPOSTCODE"":null,""NOTIFYPARTYCOUNTRY"":null,""NOTIFYPARTYATTN"":null,""NOTIFYPARTYTEL"":null,""PONO"":""报-BPGM23012 "",""OPID"":""356029261668421"",""DOCID"":""409864742023237"",""OP"":""张艺凡"",""DOC"":""刘乙洁"",""SALEID"":""386904850808901"",""SALE"":""王寅"",""CUSTSERVICEID"":""399290671059013"",""CUSTSERVICE"":""柴婷"",""CUSTOMERNAME"":""沂水宝平-沂水宝平"",""FORWARDER"":""订舱中心"",""SHIPAGENCY"":"""",""CUSTOMSER"":""顺之航报关"",""TRUCKER"":"""",""AGENTID"":"""",""CUSTOMERID"":410507280597061,""FORWARDERID"":""DCZX"",""SHIPAGENCYID"":"""",""CUSTOMSERID"":""SZHBG"",""TRUCKERID"":"""",""AGENTNAME"":"""",""WEITUO"":"""",""CONSIGNEEDOORADDR"":null,""SHIPPERDOORADDR"":null,""SCACCODE"":"""",""ITNCODE"":"""",""PREPARDATID"":"""",""PAYABLEATID"":"""",""CUSTNO"":"""",""TRANSPORTID"":"""",""TRANSPORT"":"""",""THIRDPAYADDR"":"""",""YARDCONTRACT"":"""",""YARDCONTRACTTEL"":"""",""YARDCONTRACTEMAIL"":"""",""FEESELF"":false,""LANECODE"":"""",""LANENAME"":""ZCP"",""FREIGHTPAYER"":"""",""GOODSCODE"":""020"",""GOODSNAME"":""ANIMAL FEEDS (SHRIMPS FEED,HAYS)"",""PKGSTOTAL"":"""",""KGSTOTAL"":"""",""CBMTOTAL"":"""",""ROUTEID"":"""",""ROUTE"":"""",""Warehouse"":"""",""WarehouseID"":"""",""LineName"":""美西"",""EPCode"":"""",""ctnInputs"":[{""Id"":477405946122309,""BILLID"":477405946093638,""CTNCODE"":""4"",""CTNALL"":""40'RH"",""CTNNUM"":1,""TEU"":0,""CNTRNO"":"""",""SEALNO"":"""",""PKGS"":1440,""KINDPKGS"":""CARTONS"",""KGS"":27000.0000,""CBM"":50.0000,""TAREWEIGHT"":0.0000,""CTNSTATUS"":null,""WEIGHTYPE"":""累加"",""WEIGHKGS"":27000.0000,""WEIGHATTN"":null,""VGMCONNCOM"":null,""WEIGHTEL"":null,""WEIGHDATE"":"""",""VGMADDR"":null,""VGMEMAIL"":null,""REMARK"":null,""ctnDetailInputs"":[]}],""BookingEDIExt"":{""WeiTuoFang"":"""",""SendCode"":"""",""ReceiveCode"":"""",""NotifyCdoe"":"""",""SalerCode"":"""",""MasterBolIndicator"":"""",""EmanifestHbl"":"""",""ConsigneeEdiCode"":"""",""ShipperEdiCode"":"""",""EDIAttn"":"""",""EDIAttnTel"":"""",""EDIAttnMail"":"""",""AMSConsignee"":"""",""AMSNotifyParty"":"""",""OpEName"":"""",""OpTel"":"""",""OpEmail"":"""",""ACIHBL"":"""",""S0CC0C"":"""",""GoodsName"":"""",""MasterBolIndicatorName"":"""",""SalerCodeName"":"""",""CKHI"":"""",""CNCM"":"""",""WNCM"":"""",""OrderRemark"":"""",""ExRemark1"":"""",""ExRemark2"":"""",""ExRemark3"":"""",""ExRemark4"":"""",""KingTareweight"":null,""CNPTNo"":null,""XMCYWY"":null,""EmcNameAccount"":null},""DZRemark"":""分单"",""CZRemark"":""菜 1号莱西"",""TMBLNO"":""MEDUEM280834"",""ShippingMethod"":null,""ZhanCangFlag"":""否"",""SourceCode"":null,""SourceName"":null,""YgtETD"":""2023-11-04T23:00:00"",""StartETA"":""2023-11-04T14:00:00"",""StartATA"":null,""MiddleETA"":null,""MiddleETD"":null,""MiddleATA"":null,""MiddleATD"":null,""ATA"":null,""ShenQingXiangShi"":""2+2"",""ThirdPay"":null,""ThirdPayCode"":null,""LineManage"":""王书岚"",""LineManageID"":""356029268410437""}],""GoodsStatus"":[{""StatusName"":""已收到BC"",""FinishTime"":""2023-10-31T10:29:56"",""Remark"":null,""ExtData"":null},{""StatusName"":""已派车"",""FinishTime"":""2023-10-31T09:46:34"",""Remark"":null,""ExtData"":null}]}]
";
//byte[] byteArray = System.Text.Encoding.Default.GetBytes(testjson);
//var _e = Encoding.GetEncoding("iso-8859-1");
//byte[] _e2 = _e.GetBytes(testjson);
//var strBody = Encoding.UTF8.GetString(byteArray.ToArray());
//var strBody = Encoding.UTF8.GetString(_e2);
DingCangToDS6(JArray.Parse(testjson));
//*/
/* 测试时前面增加两个注释号入货通知
///442375279099973 //457570071453766
var testjson = @"{""TenantId"":349708986646597,""BookingId"":457570071453766,""ToName"":"""",""Attn"":"""",""AttnTel"":"""",""AttnMail"":"""",""AttnPhone"":"""",""FromName"":""张艺凡"",""FromTel"":""0532-81609998"",""FromMail"":""op12@hightrans.net"",""FromPhone"":""15165298210"",""Description"":""FRESH APPLE\nTEMP:-1'C\nVENT:15CBM/H \nIMPORTER'S REGN NO.260315110118719(NEW),BA-161281(OLD),PROFORMA INVOICE NO.YBS230009\n DATED 20.08.2023, H.S. CODE NO. 0808.10.90 AND TIN\n NO.489053990850, VAT REG. (BIN ) NO. 000285414-0503, BANKS BIN\n NO. 000875839-0101, L/C NUMBER:100123010787 AND DATE:230821 THE IMPORT PERMIT (IP) NUMBER 2023-24-3047 DATED 03.08.2023"",""CloseDocTime"":null,""ClosingTime"":null,""VgmTime"":null,""Remark"":""预计拖13\n截单 9.8 12.00\n最早9.6号背箱\n条码9.7号过期 建议早点背箱/指号\n截港9.11 15.00 晚于截港时间集港有加急费\n条码过期/指号不走有费用"",""YARDID"":""GJF"",""YARD"":""港捷丰场站"",""YARDCONTRACT"":"""",""YARDCONTRACTTEL"":"""",""CreatedTime"":""2023-09-05T09:28:03"",""UpdatedTime"":""2023-09-05T12:45:15"",""CreatedUserId"":356029261668421,""CreatedUserName"":""张艺凡"",""UpdatedUserId"":356029261668421,""UpdatedUserName"":""张艺凡"",""IsDeleted"":false,""Id"":457572683534405}";
byte[] byteArray = System.Text.Encoding.Default.GetBytes(testjson);
var strBody = Encoding.UTF8.GetString(byteArray.ToArray());
DS6OpLetter_RH(strBody);
//*/
/* 测试时前面增加两个注释号 派车
///436354079932485
var testjson = @"{""head"":{""gid"":""441000874426437"",""messageType"":""TRUCK_SYNC"",""senderId"":""BOOKING_TRUCK"",""senderName"":""\u8BA2\u8231\u6D3E\u8F66"",""receiverId"":""DongshengHeChuan"",""receiverName"":""\u4E1C\u80DC\u548C\u5DDD"",""token"":null,""version"":""1.0"",""requestDate"":""2023-07-20 15:41:04"",""senderKey"":""BOOKING_TRUCK"",""requestAction"":""Sync""},""main"":{""operType"":""AddOrUpdate"",""tenantId"":349708986646597,""id"":441000874426437,""bookingId"":436086681477189,""truckId"":409875318820933,""truckCode"":""ASJCD"",""truckName"":""\u5B89\u76DB\u6377\u8F66\u961F"",""toName"":null,""attn"":null,""attnTel"":null,""attnMail"":null,""attnFax"":null,""fromName"":""\u738B\u8D77\u51E4"",""fromTel"":""0532-85888610"",""fromMobile"":""15689135576"",""fromMail"":""OP76@hightrans.net"",""fromFax"":null,""kgs"":29.0000,""fee"":null,""payMethod"":""OWN_COMPANY"",""payMethodName"":""\u672C\u516C\u53F8\u53D1\u7968"",""truckTime"":""2023-07-20T13:36:37"",""yardid"":""ZHONGCHUANG"",""yard"":""\u4E2D\u521B\u573A\u7AD9"",""yardcontract"":"""",""yardcontracttel"":"""",""factoryId"":null,""factoryCode"":null,""factoryName"":null,""factoryContact"":""\u5C0F\u80E1 13562918972"",""factoryTel"":null,""returnTime"":""2023-07-23T09:00:00"",""inYardID"":""ZHONGCHUANG"",""inYard"":""\u4E2D\u521B\u573A\u7AD9"",""inYardContact"":"""",""inYardContractTel"":"""",""needArriveTime"":""2023-07-23T05:00:00"",""closingTime"":""2023-07-23T09:00:00"",""pickUpTime"":null,""isGuaJi"":false,""attention"":null,""remark"":null,""dispatcherId"":356029261152325,""dispatcherName"":""\u7F57\u6C5F"",""factoryAddr"":""\u5C71\u4E1C\u7701\u4E34\u6C82\u5E02\u5170\u9675\u53BFX005\u4E0EX111\u4EA4\u53C9\u53E3\u4E1C\u5357\u65B9\u5411650\u7C73\u5DE6\u53F3\n\n\u5170\u9675\u53BF\u5FD7\u5408\u98DF\u54C1\u6709\u9650\u516C\u53F8"",""callBackStatus"":""SEND_DISPATCH"",""contaList"":[{""ctncode"":""4"",""ctnall"":""40\u0027RH"",""ctnnum"":1,""teu"":null,""cntrno"":"""",""sealno"":"""",""pkgs"":2900,""kindpkgs"":""BAGS"",""kgs"":29000.0000,""cbm"":50.0000,""tareweight"":null,""ctnstatus"":null,""weightype"":null,""weighkgs"":null,""weighattn"":null,""vgmconncom"":null,""weightel"":null,""weighdate"":null,""vgmaddr"":null,""vgmemail"":null,""remark"":null,""carNumber"":null,""carDriver"":null,""carDriverTel"":null},{""ctncode"":""4"",""ctnall"":""40\u0027RH"",""ctnnum"":1,""teu"":null,""cntrno"":"""",""sealno"":"""",""pkgs"":2900,""kindpkgs"":""BAGS"",""kgs"":29000.0000,""cbm"":50.0000,""tareweight"":null,""ctnstatus"":null,""weightype"":null,""weighkgs"":null,""weighattn"":null,""vgmconncom"":null,""weightel"":null,""weighdate"":null,""vgmaddr"":null,""vgmemail"":null,""remark"":null,""carNumber"":null,""carDriver"":null,""carDriverTel"":null}]}}";
byte[] byteArray = System.Text.Encoding.Default.GetBytes(testjson);
var strBody = Encoding.UTF8.GetString(byteArray.ToArray());
DS6OpLetter_PC(strBody);
//*/
#endregion
//测试删除
//DelToDS6("410977390837829,410261333442630,410590260686917");
//this.Stop(hostControl);
///* 测试时删去前面两个注释号
#region 订舱业务
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;
try
{
////不压缩
//var strBody = Encoding.UTF8.GetString(body.ToArray());
////压缩
var strBodyZip = Encoding.UTF8.GetString(body.ToArray());
//logger.Debug($"收到大简云订舱输出压缩数据:{strBodyZip}");
var strBody = BasicDataRefDAL.Decompress(strBodyZip);
logger.Debug($"收到大简云订舱输出数据:{strBody}");
//导出到东胜6
//if(strBody.Contains("TAHT30633700"))
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}", 消费队列数据, consumerDingCang);
///删除
///删除改为通过接口调用方式
////ConnectionFactory factory2 = new ConnectionFactory();
////factory2.Uri = new Uri(RecMqUri);
////mqConn2 = factory2.CreateConnection();
////IModel modelDel = mqConn2.CreateModel();
////modelDel.ExchangeDeclare(ExchangeName, ExchangeType.Direct);
////modelDel.QueueDeclare($"{QueuePrefix_Del}{CompanyId}", false, false, false, null);
////var consumerDel = new EventingBasicConsumer(modelDel);
////consumerDel.Received += (ch, ea) =>
////{
//// var body = ea.Body;
//// var strBody = Encoding.UTF8.GetString(body.ToArray());
//// logger.Debug($"收到大简云删除订舱:{strBody}");
//// try
//// {
//// //导出到东胜6
//// DelToDS6(strBody);
//// }
//// catch (Exception ex)
//// {
//// var excep = ex;
//// while (excep != null)
//// {
//// logger.Error(excep.Message);
//// logger.Error(excep.StackTrace);
//// excep = excep.InnerException;
//// }
//// }
////};
//////第二个参数控制【是否消费掉队列里的数据】
////modelDel.BasicConsume($"{QueuePrefix_Del}{CompanyId}", 消费队列数据, consumerDel);
#endregion
//*/
///*
#region 业务函电 入货通知
ConnectionFactory factory3 = new ConnectionFactory();
factory3.Uri = new Uri(RecMqUri);
mqConn3 = factory3.CreateConnection();
IModel model_Letter_RH = mqConn3.CreateModel();
model_Letter_RH.ExchangeDeclare(ExchangeName, ExchangeType.Direct);
model_Letter_RH.QueueDeclare($"{QueuePrefix_Letter_RH}{CompanyId}", false, false, false, null);
var consumer_Letter_RH = new EventingBasicConsumer(model_Letter_RH);
consumer_Letter_RH.Received += (ch, ea) =>
{
var body = ea.Body;
var strBody = Encoding.UTF8.GetString(body.ToArray());
logger.Debug($"收到大简云入货通知:{strBody}");
try
{
//导出到东胜6
DS6OpLetter_RH(strBody);
}
catch (Exception ex)
{
var excep = ex;
while (excep != null)
{
logger.Error(excep.Message);
logger.Error(excep.StackTrace);
excep = excep.InnerException;
}
}
};
//第二个参数控制【是否消费掉队列里的数据】
model_Letter_RH.BasicConsume($"{QueuePrefix_Letter_RH}{CompanyId}", 消费队列数据, consumer_Letter_RH);
#endregion
//*/
///*
#region 业务函电 派车
ConnectionFactory factory4 = new ConnectionFactory();
factory4.Uri = new Uri(RecMqUri);
mqConn4 = factory4.CreateConnection();
IModel model_Letter_PC = mqConn4.CreateModel();
model_Letter_PC.ExchangeDeclare(ExchangeName, ExchangeType.Direct);
model_Letter_PC.QueueDeclare($"{QueuePrefix_Letter_PC}{CompanyId}", false, false, false, null);
var consumer_Letter_PC = new EventingBasicConsumer(model_Letter_PC);
consumer_Letter_PC.Received += (ch, ea) =>
{
var body = ea.Body;
var strBody = Encoding.UTF8.GetString(body.ToArray());
logger.Debug($"收到大简云派车通知:{strBody}");
try
{
//导出到东胜6
DS6OpLetter_PC(strBody);
}
catch (Exception ex)
{
var excep = ex;
while (excep != null)
{
logger.Error(excep.Message);
logger.Error(excep.StackTrace);
excep = excep.InnerException;
}
}
};
//第二个参数控制【是否消费掉队列里的数据】
model_Letter_PC.BasicConsume($"{QueuePrefix_Letter_PC}{CompanyId}", 消费队列数据, consumer_Letter_PC);
#endregion
//*/
}
catch (Exception e) {
logger.Error(e.Message);
}
return true;
}
public bool Stop(HostControl hostControl)
{
// 结束
logger.Debug("停止运行");
//StdSchedulerFactory.GetDefaultScheduler().Shutdown();
mqConn.Close();
//mqConn2.Close();
mqConn3.Close();
mqConn4.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}");
// }
//}
public string GetUserRefList(string itemstr)
{
return itemstr;
}
///
/// 生成编号(从东胜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 static void DingCangToDS6(JArray jarr)
{
try
{
var itemstr = "";
DS6DataContext DS6Data = new DS6DataContext();
var dolist = new List();
foreach (var item in jarr)
{
var obj = item as JObject;
itemstr = item.ToString();
//var head = JsonConvert.DeserializeObject(itemstr);
//ThreadSaveDS6_Single SaveThread = new ThreadSaveDS6_Single();
//有参调用实例方法,ParameterizedThreadStart是一个委托,input为object,返回值为void
//Thread thread1 = new Thread(new ParameterizedThreadStart(SaveThread.FuncSend));
//thread1.Start(itemstr);
Task.Run(()=> { Do_DingCangToDS6(itemstr); });
//Do_DingCangToDS6(itemstr);
}
//注释部分 为每消息队列文本包 起一个线程
//ThreadSaveDS6_List SaveThread = new ThreadSaveDS6_List();
////有参调用实例方法,ParameterizedThreadStart是一个委托,input为object,返回值为void
//Thread thread1 = new Thread(new ParameterizedThreadStart(SaveThread.FuncSend));
//thread1.Start(dolist);
}
catch (Exception e)
{
var errorobjstr = JsonConvert.SerializeObject(e);
logger.Error($"导入出错:{e}//{errorobjstr}");
}
}
public class 执行订舱单 {
public long DJYID { get; set; }
public DateTime StartTime { get; set; }
public 执行订舱单(long id) {
DJYID = id;
StartTime = DateTime.Now;
}
}
//执行中列表 已废弃
/*
public sealed class 执行中对象2
{
private static readonly Lazy<执行中对象2> lazy = new Lazy<执行中对象2>(() => new 执行中对象2());
public static 执行中对象2 Instance { get { return lazy.Value; } }
private 执行中对象2() { }
//private static bool inworking { get; set; } = false;
private static List<执行订舱单> 执行中idList { get; set; } = new List<执行订舱单>();
public void 执行完成(long DJYID)
{
try
{
//if (inworking)
//{
// logger.Debug($"列表处理中重试(333)_删除:{DJYID}");
// DateTime dt1 = DateTime.Now;
// while ((DateTime.Now - dt1).TotalMilliseconds < 333)
// {
// continue;
// }
// 执行完成(DJYID);
// return;
//}
//inworking = true;
logger.Debug($"lock_del:{DJYID};");
if (执行中idList != null && 执行中idList.Count > 0)
{
if (执行中idList.Exists(x => x.DJYID == DJYID))
{
try
{
执行中idList.RemoveAll(x => x.DJYID == DJYID);
logger.Debug($"移除执行:{DJYID};");
//inworking = false;
}
catch (Exception e2)
{
//inworking = false;
var str = JsonConvert.SerializeObject(e2);
logger.Error($"移除执行出错:{DJYID}:{str}");
}
}
try
{
if (执行中idList != null && 执行中idList.Count > 0)
{
var str = JsonConvert.SerializeObject(执行中idList);
logger.Debug($"剩余执行:{str};");
}
}
catch (Exception e1)
{
}
}
}
catch (Exception e)
{
var str = JsonConvert.SerializeObject(e);
logger.Debug($"执行完成失败:{str}");
//inworking = false;
}
finally
{
//if (执行中idList != null && 执行中idList.Count > 0)
//{
// if (执行中idList.Exists(x => x.StartTime <= DateTime.Now.AddSeconds(-15)))
// {
// 执行中idList.RemoveAll(x => x.StartTime <= DateTime.Now.AddSeconds(-15));
// logger.Debug($"移除超时15秒业务1;");
// }
//}
logger.Debug($"unlock_del:{DJYID};");
//inworking = false;
}
}
public bool 添加执行(long DJYID)
{
//if (inworking)
//{
// logger.Debug($"列表处理中重试(333)_添加:{DJYID}");
// DateTime dt1 = DateTime.Now;
// while ((DateTime.Now - dt1).TotalMilliseconds < 333)
// {
// continue;
// }
// //var head0 = JsonConvert.DeserializeObject(itemstr);
// return 添加执行(DJYID);
//}
//inworking = true;
var result = true;
try
{
logger.Debug($"lock:{DJYID};");
if (执行中idList == null) 执行中idList = new List<执行订舱单>();
if (执行中idList.Exists(x => x.DJYID == DJYID))
{
//logger.Debug($"执行中重试(100):{DJYID}");
//Thread.Sleep(100);
//result = false;
result = true;
}
else
{
执行中idList.Add(new 执行订舱单(DJYID));
result = true;
}
//inworking = false;
return result;
}
catch (Exception e)
{
//inworking = false;
var str = JsonConvert.SerializeObject(e);
logger.Debug($"添加执行失败:{str}");
result = false;
return result;
}
finally
{
if (执行中idList != null && 执行中idList.Count > 0)
{
//if (执行中idList.Exists(x => x.StartTime <= DateTime.Now.AddSeconds(-15)))
//{
// try
// {
// var delobj = 执行中idList.FirstOrDefault(x => x.StartTime <= DateTime.Now.AddSeconds(-15));
// 执行中idList.RemoveAll(x => x.StartTime <= DateTime.Now.AddSeconds(-15));
// //inworking = false;
// logger.Debug($"移除超时15秒业务2;{delobj.DJYID}");
// }
// catch (Exception e)
// {
// //inworking = false;
// var str = JsonConvert.SerializeObject(e);
// logger.Error($"移除超时15秒业务2错误;{str}");
// }
//}
}
logger.Debug($"unlock:{DJYID};");
//inworking = false;
}
}
public static void 执行列表数(string name = "")
{
var docount = 0;
if (执行中idList != null)
{
try
{
docount = 执行中idList.Count();
}
catch (Exception e1)
{
}
}
logger.Debug($"执行列表数({name}):{docount};");
}
}
//public static class 执行中对象 {
// public static void 执行完成(long DJYID)
// {
// try
// {
// if (inworking)
// {
// logger.Debug($"列表处理中重试(333)_删除:{DJYID}");
// DateTime dt1 = DateTime.Now;
// while ((DateTime.Now - dt1).TotalMilliseconds < 333)
// {
// continue;
// }
// 执行完成(DJYID);
// return;
// }
// inworking = true;
// logger.Debug($"lock_del:{DJYID};");
// if (执行中idList != null && 执行中idList.Count > 0)
// {
// if (执行中idList.Exists(x => x.DJYID == DJYID))
// {
// try
// {
// 执行中idList.RemoveAll(x => x.DJYID == DJYID);
// logger.Debug($"移除执行:{DJYID};");
// inworking = false;
// }
// catch (Exception e2)
// {
// inworking = false;
// var str = JsonConvert.SerializeObject(e2);
// logger.Error($"移除执行出错:{DJYID}:{str}");
// }
// }
// try
// {
// if (执行中idList != null && 执行中idList.Count > 0)
// {
// var str = JsonConvert.SerializeObject(执行中idList);
// logger.Debug($"剩余执行:{str};");
// }
// }
// catch (Exception e1)
// {
// }
// }
// }
// catch (Exception e)
// {
// var str = JsonConvert.SerializeObject(e);
// logger.Debug($"执行完成失败:{str}");
// inworking = false;
// }
// finally
// {
// if (执行中idList != null && 执行中idList.Count > 0)
// {
// if (执行中idList.Exists(x => x.StartTime <= DateTime.Now.AddSeconds(-15)))
// {
// 执行中idList.RemoveAll(x => x.StartTime <= DateTime.Now.AddSeconds(-15));
// logger.Debug($"移除超时15秒业务1;");
// }
// }
// logger.Debug($"unlock_del:{DJYID};");
// inworking = false;
// }
// }
// public static bool 添加执行(long DJYID)
// {
// if (inworking)
// {
// logger.Debug($"列表处理中重试(333)_添加:{DJYID}");
// DateTime dt1 = DateTime.Now;
// while ((DateTime.Now - dt1).TotalMilliseconds < 333)
// {
// continue;
// }
// //var head0 = JsonConvert.DeserializeObject(itemstr);
// return 添加执行(DJYID);
// }
// inworking = true;
// var result = true;
// try
// {
// logger.Debug($"lock:{DJYID};");
// if (执行中idList == null) 执行中idList = new List<执行订舱单>();
// if (执行中idList.Exists(x => x.DJYID == DJYID))
// {
// logger.Debug($"执行中重试(500):{DJYID}");
// DateTime dt1 = DateTime.Now;
// while ((DateTime.Now - dt1).TotalMilliseconds < 1000)
// {
// continue;
// }
// result =false;
// }
// else {
// 执行中idList.Add(new 执行订舱单(DJYID));
// result = true;
// }
// inworking = false;
// return result;
// }
// catch (Exception e)
// {
// inworking = false;
// var str = JsonConvert.SerializeObject(e);
// logger.Debug($"添加执行失败:{str}");
// result = false;
// return result;
// }
// finally
// {
// if (执行中idList != null && 执行中idList.Count > 0)
// {
// if (执行中idList.Exists(x => x.StartTime <= DateTime.Now.AddSeconds(-15)))
// {
// try
// {
// var delobj = 执行中idList.FirstOrDefault(x=> x.StartTime <= DateTime.Now.AddSeconds(-15));
// 执行中idList.RemoveAll(x => x.StartTime <= DateTime.Now.AddSeconds(-15));
// inworking = false;
// logger.Debug($"移除超时15秒业务2;{delobj}");
// }
// catch (Exception e) {
// inworking = false;
// var str = JsonConvert.SerializeObject(e);
// logger.Error($"移除超时15秒业务2错误;{str}");
// }
// }
// }
// logger.Debug($"unlock:{DJYID};");
// //inworking = false;
// }
// }
// public static void 执行列表数(string name = "")
// {
// var docount = 0;
// if (执行中idList != null)
// {
// try
// {
// docount = 执行中idList.Count();
// }
// catch (Exception e1)
// {
// }
// }
// logger.Debug($"执行列表数({name}):{docount};");
// }
//}
*/
public static void Do_DingCangToDS6(string itemstr,int count=0)
{
//logger.Debug($"线程开始:{Thread.CurrentThread.ManagedThreadId}");
if (count > 3) {
logger.Debug($"重试完结");
return;
}
var head = JsonConvert.DeserializeObject(itemstr);
var errorobjstr = "";
decimal mark = 0.0m;
try
{
DS6DataContext DS6Data = new DS6DataContext();
//判断业务是否存在。判断依据为head.
//如果不存在 则新增
//如存在,则删除原有箱信息。
//logger.Debug($"查询业务:{head.Id}");
var currentBillList = DS6Data.t_op_seae.Where(x => x.DJYID == head.Id).ToList();
if (currentBillList != null && currentBillList.Count > 0)
{
//更新当前业务
var updrec = currentBillList[0];
var headid = updrec.编号;
var newhead = head.GetOpseae();
//过滤权限 20230421 正式使用后不做人员限制
//var cando = 人员是否具备权限(newhead.录入人, "776");
//if (!cando)
//{
// logger.Debug($"录入人无权限:{newhead.录入人}");
// continue;
//}
//ETD ATD 使用原有数据而不用大简云发布的信息覆盖(已取消)
//newhead.ETD = updrec.ETD;
//newhead.开船日期= updrec.开船日期;
newhead.编号 = updrec.编号;
newhead.主编号 = updrec.主编号;
//20230523 改为接收业务状态
//newhead.业务状态 = updrec.业务状态;
newhead.费用状态 = updrec.费用状态;
//20230726 会计期间改为:如果有实际开船日期 ATD/预抵日期 则按实际开船日期计算,如果没有,则按当前日期计算
//如果费用封账
if (updrec.费用状态 == "费用封帐") {
newhead.会计期间 = updrec.会计期间;
//newhead.ETD= updrec.ETD;
newhead.预抵日期 = updrec.预抵日期;
//20230927 增加四个在费用封账状态下不更新的字段
newhead.揽货人 = updrec.揽货人;
newhead.委托单位 = updrec.委托单位;
newhead.货代公司 = updrec.货代公司;//订舱代理
newhead.船公司 = updrec.船公司;
//newhead.三
}
newhead.主提单标准 = string.IsNullOrWhiteSpace(head.mblno) ? updrec.编号 : head.mblno;
newhead.报关标准 = updrec.报关标准;
newhead.报检标准 = updrec.报检标准;
newhead.分提单标准 = updrec.分提单标准;
newhead.核销标准 = updrec.核销标准;
newhead.委托标准 = updrec.委托标准;
newhead.业务编号 = updrec.业务编号;
newhead.派车日期 = updrec.派车日期;
//20230803 根据马静怡的要求
//在同步时 如果目的港ETA为空 则不用空值更新东胜的ETA当前值
if (newhead.ETA == null) {
newhead.ETA = updrec.ETA;
}
logger.Debug($"开始处理(更新):{newhead.主提单号};{newhead.DJYID}");
//执行中对象2.执行列表数();
Set头表箱封号件重尺(ref newhead, head);
DS6Data.t_op_seae.AddOrUpdate(newhead);
DS6Data.SaveChanges();
//logger.Debug($"更新业务1:{head.Id}");
#region 箱信息
DS6Data = new DS6DataContext();
var Currctnlist = DS6Data.t_op_ctn.Where(x => x.编号 == headid).ToList();
var ctn_addlist = new List();
//var ctn_updlist = new List();
var ctn_dellist = new List();
var newctnList = head.GetCtnList(newhead.编号);
foreach (var ctn in newctnList)
{
//if (Currctnlist.Exists(x => x.DJYCTNID == ctn.DJYCTNID))
//{
// var currctn = Currctnlist.First(x => x.DJYCTNID == ctn.DJYCTNID);
// DingCangHead.GetCtn(ref currctn, ctn);
// ctn_updlist.Add(currctn);
//}
//else
{
ctn_addlist.Add(ctn);
}
}
foreach (var oldctn in Currctnlist)
{
//if (newctnList.Exists(x => x.DJYCTNID == oldctn.DJYCTNID))
//{
//}
//else
//{
// ctn_dellist.Add(oldctn);
//}
ctn_dellist.Add(oldctn);
}
if (ctn_dellist.Count > 0)
{
mark = 1.11m;
DS6Data.t_op_ctn.RemoveRange(ctn_dellist);
DS6Data.SaveChanges();
//logger.Debug($"更新箱信息1:{head.Id}");
}
if (ctn_addlist.Count > 0)
{
mark = 1.112m;
DS6Data.t_op_ctn.AddRange(ctn_addlist);
DS6Data.SaveChanges();
//logger.Debug($"更新箱信息2:{head.Id}");
}
//if (ctn_updlist.Count > 0)
//{
// foreach (var updctn in ctn_updlist)
// {
// DS6Data.t_op_ctn.AddOrUpdate(updctn);
// }
//}
#endregion
#region 提单信息
DS6Data = new DS6DataContext();
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);
mark = 1.12m;
DS6Data.SaveChanges();
//logger.Debug($"更新提单信息:{head.Id}");
#endregion
#region 分单
//分单列表
DS6Data = new DS6DataContext();
var newassistantList = head.GetAssistantList(newhead);
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);
foreach (var assistant in newassistantList)
{
//if (old_assistantList.Exists(x => x.DJYCHILDRENID == assistant.DJYCHILDRENID))
//{
// var curr = old_assistantList.First(x => x.DJYCHILDRENID == assistant.DJYCHILDRENID);
// DingCangHead.GetAssistant(ref curr, assistant);
// assistantUpdList.Add(curr);
//}
//else
//{
assistantAddList.Add(assistant);
//}
}
foreach (var old in old_assistantList)
{
//if (newassistantList.Exists(x => x.DJYCHILDRENID == old.DJYCHILDRENID))
//{
//}
//else
//{
assistantDelList.Add(old);
//}
}
if (assistantDelList.Count > 0)
{
mark = 1.13m;
DS6Data.t_op_seae_assistant.RemoveRange(assistantDelList);
DS6Data.SaveChanges();
//logger.Debug($"更新分单信息1:{head.Id}");
}
if (assistantAddList.Count > 0)
{
mark = 1.132m;
DS6Data.t_op_seae_assistant.AddRange(assistantAddList);
DS6Data.SaveChanges();
//logger.Debug($"更新分单信息2:{head.Id}");
}
//if (assistantUpdList.Count > 0)
//{
// foreach (var upd in assistantUpdList)
// {
// DS6Data.t_op_seae_assistant.AddOrUpdate(upd);
// }
//}
//DS6Data.SaveChanges();
#endregion
#region 业务状态
DS6Data = new DS6DataContext();
var Currstatuslist = DS6Data.t_op_state.Where(x => x.编号 == headid).ToList();
if (Currstatuslist != null && Currstatuslist.Count > 0)
{
DS6Data.t_op_state.RemoveRange(Currstatuslist);
DS6Data.SaveChanges();
}
var statusList = head.GetOpStatus(newhead);
if (statusList != null && statusList.Count > 0)
{
DS6Data.t_op_state.AddRange(statusList);
DS6Data.SaveChanges();
}
#endregion
mark = 1.2m;
DS6Data = new DS6DataContext();
var ob = new
{
head = newhead,
ctnlist = ctn_addlist,
amslist = newamslist,
ass1 = assistantAddList,
//ass2 = assistantUpdList,
ass3 = assistantDelList,
};
errorobjstr = JsonConvert.SerializeObject(ob);
//logger.Debug($"更新完成:{newhead.主提单号};{newhead.DJYID}");
AfterSave(newhead.编号);
//DS6Data.SaveChanges();
logger.Debug($"完成处理(更新):{newhead.主提单号};{newhead.DJYID}");
}
else
{
//新增业务
var newhead = head.GetOpseae();
//过滤权限
//var cando = 人员是否具备权限(newhead.录入人, "776");
//if (!cando) continue;
var new编号 = 获取编号Helper.Instance.DoGet();
newhead.编号 = new编号;
newhead.主编号 = new编号;
newhead.主提单标准 = string.IsNullOrWhiteSpace(head.mblno) ? new编号 : head.mblno;
newhead.报关标准 = new编号;
newhead.报检标准 = new编号;
newhead.分提单标准 = new编号;
newhead.核销标准 = new编号;
newhead.委托标准 = new编号;
logger.Debug($"开始处理(新增):{newhead.主提单号};{newhead.DJYID}");
//执行中对象2.执行列表数();
//var 业务编号Code = "SE" + ((DateTime)(newhead.会计期间)).Year.ToString() + ((DateTime)(newhead.会计期间)).Month.ToString().PadLeft(2, '0');
DateTime now = DateTime.Now;
DateTime today2 = new DateTime(now.Year, now.Month, now.Day);
var 业务编号Code = "SE" + today2.Year.ToString() + today2.Month.ToString().PadLeft(2, '0');
newhead.业务编号 = 获取业务编号Helper.Instance. DS6GetBSNO(业务编号Code);
Set头表箱封号件重尺(ref newhead, head);
DS6Data.t_op_seae.Add(newhead);
mark = 2.1m;
DS6Data.SaveChanges();
//logger.Debug($"新增save1:{newhead.主提单号};{newhead.DJYID}");
newhead = DS6Data.t_op_seae.First(x => x.业务编号 == newhead.业务编号);
var headid = newhead.编号;
var ctnlist = DS6Data.t_op_ctn.Where(x => x.编号 == headid).ToList();
if (ctnlist != null && ctnlist.Count > 0)
DS6Data.t_op_ctn.RemoveRange(ctnlist);
var newctnList = head.GetCtnList(newhead.编号);
if (newctnList != null && newctnList.Count > 0) {
DS6Data.t_op_ctn.AddRange(newctnList);
//logger.Debug($"新增ctn:{newhead.主提单号};{newhead.DJYID}");
}
var amslist = DS6Data.t_op_ams.Where(x => x.编号 == headid).ToList();
DS6Data.t_op_ams.RemoveRange(amslist);
var newamslist = head.GetAmsList(newhead);
if (newamslist != null && newamslist.Count > 0)
{
DS6Data.t_op_ams.AddRange(newamslist);
//logger.Debug($"新增ams:{newhead.主提单号};{newhead.DJYID}");
}
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)
{
if (old_assistantList != null && old_assistantList.Count > 0)
{
foreach (var oldassis in old_assistantList)
{
if (newassis.BSNO == oldassis.BSNO)
{
assistantDelList.Add(oldassis);
}
else
{
}
}
}
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.Add(upd);
//}
if (assistantAddList!=null && assistantAddList.Count > 0) {
DS6Data.t_op_seae_assistant.AddRange(assistantAddList);
//logger.Debug($"新增assistant:{newhead.主提单号};{newhead.DJYID}");
}
mark = 3.1m;
#region 业务状态
var Currstatuslist = DS6Data.t_op_state.Where(x => x.编号 == headid).ToList();
if (Currstatuslist != null && Currstatuslist.Count > 0)
{
DS6Data.t_op_state.RemoveRange(Currstatuslist);
mark = 3.21m;
}
var statusList = head.GetOpStatus(newhead);
if (statusList != null && statusList.Count > 0)
{
DS6Data.t_op_state.AddRange(statusList);
//logger.Debug($"新增statusList:{newhead.主提单号};{newhead.DJYID}");
mark = 3.22m;
}
#endregion
mark = 3.3m;
DS6Data.SaveChanges();
//logger.Debug($"新增完成:{newhead.主提单号};{newhead.DJYID}");
AfterSave(newhead.编号);
logger.Debug($"完成处理(新增):{newhead.主提单号};{newhead.DJYID}");
}
}
catch (Exception e)
{
errorobjstr = JsonConvert.SerializeObject(e);
logger.Error($"导入订舱信息出错{mark}:{e}//{errorobjstr}");
logger.Error($"出错重试{count}:{head.Id}");
Thread.Sleep(100);
Task.Run(() => { Do_DingCangToDS6(itemstr, count + 1); });
}
finally {
//var dh = 执行中对象2.Instance;
//dh.执行完成(head.Id);
//执行中对象2.执行列表数("完成");
////ThreadSaveDS6_Single.处理完成(head.Id);
}
}
public static void AfterSave(string 编号) {
try
{
//20230717 保存业务后,执行一个存储过程
using (DS6DataContext context = new DS6DataContext())
{
SqlParameter bsno = new SqlParameter("@bsno", 编号);
int count = context.Database.ExecuteSqlCommand("exec p_exec_accmonth @bsno", bsno);
context.SaveChanges();
count = context.Database.ExecuteSqlCommand($" update t_op_seae set 应结日期=ISNULL(dbo.GetCustStlDay(预抵日期,委托单位,揽货人),预抵日期) where 编号='{编号}' and 预抵日期 is not null ");
context.SaveChanges();
logger.Debug($"AfterSave:{编号};{count}");
}
}
catch (Exception e) {
var str=JsonConvert.SerializeObject(e);
logger.Error($"AfterSave:{str}");
}
return ;
}
#region 原保存逻辑
//public static void DingCangToDS6_OLD(JArray jarr)
//{
// var itemstr = "";
// decimal mark = 0.0M;
// var errorobjstr = "";
// try
// {
// DS6DataContext DS6Data = new DS6DataContext();
// foreach (var item in jarr)
// {
// var obj = item as JObject;
// itemstr = item.ToString();
// var head = JsonConvert.DeserializeObject(itemstr);
// //判断业务是否存在。判断依据为head.
// //如果不存在 则新增
// //如存在,则删除原有箱信息。
// var currentBillList = DS6Data.t_op_seae.Where(x => x.DJYID == head.Id).ToList();
// if (currentBillList != null && currentBillList.Count > 0)
// {
// //更新当前业务
// var updrec = currentBillList[0];
// var headid = updrec.编号;
// var newhead = head.GetOpseae();
// //过滤权限 20230421 正式使用后不做人员限制
// //var cando = 人员是否具备权限(newhead.录入人, "776");
// //if (!cando)
// //{
// // logger.Debug($"录入人无权限:{newhead.录入人}");
// // continue;
// //}
// //ETD ATD 使用原有数据而不用大简云发布的信息覆盖(已取消)
// //newhead.ETD = updrec.ETD;
// //newhead.开船日期= updrec.开船日期;
// newhead.编号 = updrec.编号;
// newhead.主编号 = updrec.主编号;
// //20230523 改为接收业务状态
// //newhead.业务状态 = updrec.业务状态;
// newhead.费用状态 = updrec.费用状态;
// newhead.主提单标准 = string.IsNullOrWhiteSpace(head.mblno) ? updrec.编号 : head.mblno;
// newhead.报关标准 = updrec.报关标准;
// newhead.报检标准 = updrec.报检标准;
// newhead.分提单标准 = updrec.分提单标准;
// newhead.核销标准 = updrec.核销标准;
// newhead.委托标准 = updrec.委托标准;
// newhead.业务编号 = updrec.业务编号;
// newhead.派车日期 = updrec.派车日期;
// Set头表箱封号件重尺(ref newhead, head);
// DS6Data.t_op_seae.AddOrUpdate(newhead);
// #region 箱信息
// var Currctnlist = DS6Data.t_op_ctn.Where(x => x.编号 == headid).ToList();
// var ctn_addlist = new List();
// //var ctn_updlist = new List();
// var ctn_dellist = new List();
// var newctnList = head.GetCtnList(newhead.编号);
// foreach (var ctn in newctnList)
// {
// //if (Currctnlist.Exists(x => x.DJYCTNID == ctn.DJYCTNID))
// //{
// // var currctn = Currctnlist.First(x => x.DJYCTNID == ctn.DJYCTNID);
// // DingCangHead.GetCtn(ref currctn, ctn);
// // ctn_updlist.Add(currctn);
// //}
// //else
// //{
// ctn_addlist.Add(ctn);
// //}
// }
// foreach (var oldctn in Currctnlist)
// {
// //if (newctnList.Exists(x => x.DJYCTNID == oldctn.DJYCTNID))
// //{
// //}
// //else
// //{
// ctn_dellist.Add(oldctn);
// //}
// }
// if (ctn_dellist.Count > 0)
// {
// DS6Data.t_op_ctn.RemoveRange(ctn_dellist);
// }
// if (ctn_addlist.Count > 0)
// {
// DS6Data.t_op_ctn.AddRange(ctn_addlist);
// }
// //if (ctn_updlist.Count > 0)
// //{
// // foreach (var updctn in ctn_updlist)
// // {
// // DS6Data.t_op_ctn.AddOrUpdate(updctn);
// // }
// //}
// #endregion
// #region 提单信息
// 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);
// #endregion
// #region 分单
// //分单列表
// var newassistantList = head.GetAssistantList(newhead);
// 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);
// foreach (var assistant in newassistantList)
// {
// if (old_assistantList.Exists(x => x.DJYCHILDRENID == assistant.DJYCHILDRENID))
// {
// var curr = old_assistantList.First(x => x.DJYCHILDRENID == assistant.DJYCHILDRENID);
// DingCangHead.GetAssistant(ref curr, assistant);
// assistantUpdList.Add(curr);
// }
// else
// {
// assistantAddList.Add(assistant);
// }
// }
// foreach (var old in old_assistantList)
// {
// if (newassistantList.Exists(x => x.DJYCHILDRENID == old.DJYCHILDRENID))
// {
// }
// else
// {
// assistantDelList.Add(old);
// }
// }
// if (assistantAddList.Count > 0)
// {
// DS6Data.t_op_seae_assistant.AddRange(assistantAddList);
// }
// if (assistantUpdList.Count > 0)
// {
// foreach (var upd in assistantUpdList)
// {
// DS6Data.t_op_seae_assistant.AddOrUpdate(upd);
// }
// }
// if (assistantDelList.Count > 0)
// {
// DS6Data.t_op_seae_assistant.RemoveRange(assistantDelList);
// }
// #endregion
// #region 业务状态
// var Currstatuslist = DS6Data.t_op_state.Where(x => x.编号 == headid).ToList();
// if (Currstatuslist != null && Currstatuslist.Count > 0)
// {
// DS6Data.t_op_state.RemoveRange(Currstatuslist);
// mark = 1.11m;
// }
// var statusList = head.GetOpStatus(newhead);
// if (statusList != null && statusList.Count > 0)
// {
// DS6Data.t_op_state.AddRange(statusList);
// mark = 1.12m;
// }
// #endregion
// mark = 1.2m;
// var ob = new
// {
// head = newhead,
// ctnlist = ctn_addlist,
// amslist = newamslist,
// ass1 = assistantAddList,
// ass2 = assistantUpdList,
// ass3 = assistantDelList,
// };
// errorobjstr = JsonConvert.SerializeObject(ob);
// DS6Data.SaveChanges();
// }
// else
// {
// //新增业务
// var newhead = head.GetOpseae();
// //过滤权限
// //var cando = 人员是否具备权限(newhead.录入人, "776");
// //if (!cando) continue;
// var dh = new 获取编号Helper();
// var new编号 = dh.DoGet();
// newhead.编号 = new编号;
// newhead.主编号 = new编号;
// newhead.主提单标准 = string.IsNullOrWhiteSpace(head.mblno) ? new编号 : head.mblno;
// newhead.报关标准 = new编号;
// newhead.报检标准 = new编号;
// newhead.分提单标准 = new编号;
// newhead.核销标准 = new编号;
// newhead.委托标准 = new编号;
// var 业务编号Code = "SE" + ((DateTime)(newhead.会计期间)).Year.ToString() + ((DateTime)(newhead.会计期间)).Month.ToString().PadLeft(2, '0');
// newhead.业务编号 = DS6GetBSNO(业务编号Code);
// Set头表箱封号件重尺(ref newhead, head);
// DS6Data.t_op_seae.Add(newhead);
// mark = 2.1m;
// DS6Data.SaveChanges();
// newhead = DS6Data.t_op_seae.First(x => x.业务编号 == newhead.业务编号);
// var headid = newhead.编号;
// var ctnlist = DS6Data.t_op_ctn.Where(x => x.编号 == headid).ToList();
// if (ctnlist != null && ctnlist.Count > 0)
// 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)
// {
// if (old_assistantList != null && old_assistantList.Count > 0)
// {
// foreach (var oldassis in old_assistantList)
// {
// if (newassis.BSNO == oldassis.BSNO)
// {
// assistantDelList.Add(oldassis);
// }
// else
// {
// }
// }
// }
// 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.Add(upd);
// //}
// if (assistantAddList.Count > 0)
// DS6Data.t_op_seae_assistant.AddRange(assistantAddList);
// logger.Debug($"添加数据:{newhead}");
// mark = 3.1m;
// #region 业务状态
// var Currstatuslist = DS6Data.t_op_state.Where(x => x.编号 == headid).ToList();
// if (Currstatuslist != null && Currstatuslist.Count > 0)
// {
// DS6Data.t_op_state.RemoveRange(Currstatuslist);
// mark = 3.21m;
// }
// var statusList = head.GetOpStatus(newhead);
// if (statusList != null && statusList.Count > 0)
// {
// DS6Data.t_op_state.AddRange(statusList);
// mark = 3.22m;
// }
// #endregion
// mark = 3.3m;
// DS6Data.SaveChanges();
// }
// }
// }
// catch (Exception e)
// {
// logger.Error($"导入订舱信息出错{mark}:{e}//{errorobjstr}");
// }
//}
#endregion
public static void Set头表箱封号件重尺(ref t_op_seae_md newhead, DingCangHead head) {
var ctnList = head.GetCtnList(newhead.编号);
newhead.箱号封号 = "";
newhead.件数包装 = head.pkgs.ToString()+ head.kindpkgs;
newhead.货物重量 = head.kgs.ToString() + "KGS";
newhead.货物尺码 = head.cbm.ToString() + "CBM";
if (ctnList != null && ctnList.Count > 0) {
foreach (var ctn in ctnList)
{
if (!string.IsNullOrWhiteSpace(ctn.箱号) || !string.IsNullOrWhiteSpace(ctn.封号))
{
if (newhead.箱号封号 != "") newhead.箱号封号 += "\r\n";
newhead.箱号封号 += (string.IsNullOrWhiteSpace(ctn.箱号) ? "" : ctn.箱号) + (string.IsNullOrWhiteSpace(ctn.封号) ? "" : "/" + ctn.封号);
}
//if (ctn.件数 != null && ctn.件数 != 0 && !string.IsNullOrWhiteSpace(ctn.包装)) {
// if (newhead.件数包装 != "") newhead.件数包装 += "\r\n";
// newhead.件数包装 += ctn.件数.ToString() + ctn.包装;
//}
//if (ctn.重量 != null)// && ctn.重量 != 0
//{
// if (newhead.货物重量 != "") newhead.货物重量 += "\r\n";
// newhead.货物重量 += ctn.重量.ToString() + "KGS";
//}
//if (ctn.尺码 != null)//&& ctn.尺码 != 0
//{
// if (newhead.货物尺码 != "") newhead.货物尺码 += "\r\n";
// newhead.货物尺码 += ctn.尺码.ToString() + "CBM";
//}
}
}
}
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;
}
}
public bool CanDelete(t_op_seae_md opseae) {
var ds6 = new DS6DataContext();
var chfeeList = ds6.t_ch_fee.Where(x => x.编号 == opseae.编号).ToList();
if (chfeeList == null || chfeeList.Count == 0)
{
return true;
}
else {
return false;
}
}
//删除订舱 已废弃
/*
public void DelToDS6(string Ids)
{
//try
//{
DS6DataContext DS6Data = new DS6DataContext();
List IdList = Ids.Split(',').ToList();
foreach (var id in IdList)
{
logger.Debug($"删除订舱信息:DJYID:{id}");
long idlong = Convert.ToInt64(id);
var currentBillList = DS6Data.t_op_seae.Where(x => x.DJYID == idlong).ToList();
if (currentBillList != null && currentBillList.Count > 0)
{
var delrec = currentBillList[0];
var headid = delrec.编号;
if (!CanDelete(delrec))
{
return;
}
logger.Debug($"删除订舱信息:delrec:{JsonConvert.SerializeObject(delrec)}");
DS6Data.t_op_seae.Remove(delrec);
var ctnlist = DS6Data.t_op_ctn.Where(x => x.编号 == headid).ToList();
if (ctnlist.Count > 0)
{
logger.Debug($"删除订舱信息:ctnlist:{JsonConvert.SerializeObject(ctnlist)}");
DS6Data.t_op_ctn.RemoveRange(ctnlist);
}
var amslist = DS6Data.t_op_ams.Where(x => x.编号 == headid).ToList();
if (amslist.Count > 0) {
logger.Debug($"删除订舱信息:amslist:{JsonConvert.SerializeObject(amslist)}");
DS6Data.t_op_ams.RemoveRange(amslist);
}
var old_assistantList = DS6Data.t_op_seae_assistant.Where(x => x.编号 == headid).ToList();
if (old_assistantList.Count > 0) {
logger.Debug($"删除订舱信息:old_assistantList:{JsonConvert.SerializeObject(old_assistantList)}");
DS6Data.t_op_seae_assistant.RemoveRange(old_assistantList);
}
logger.Debug($"删除订舱信息:DJYID:{id}");
DS6Data.SaveChanges();
logger.Debug($"删除订舱信息:DJYID:OK");
}
}
//}
//catch (Exception e)
//{
// logger.Error($"删除订舱信息出错:{e}");
//}
}
*/
#endregion
#region 处理业务函电
public static void DS6OpLetter_RH(string itemstr)
{
/*测试时前方增加注释
if (!itemstr.Contains("457570071453766")) {
return;
}
//*/
try
{
DS6DataContext DS6Data = new DS6DataContext();
var rh= JsonConvert.DeserializeObject<大简云入货通知>(itemstr);
if (rh != null)
{
var letter = rh.GetLetter();
letter.SaveLetter();
}
else {
logger.Error($"入货通知空:////" + itemstr);
}
}
catch (Exception e)
{
logger.Error($"入货通知出错:{e}////" + itemstr);
}
}
public static void DS6OpLetter_PC(string itemstr)
{
try
{
DS6DataContext DS6Data = new DS6DataContext();
var rh = JsonConvert.DeserializeObject<大简云派车>(itemstr);
if (rh != null)
{
var letter = rh.GetLetter();
letter.SaveLetter(rh);
}
else {
logger.Error($"派车通知空:////" + itemstr);
}
}
catch (Exception e)
{
logger.Error($"派车通知出错:{e}////" + itemstr);
}
}
#endregion
#region 大简云订舱数据解析类
public class DingCangHead
{
public long Id { get; set; }
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 tmblno { 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 foreignAgent { 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",
///
/// 云港通ETD(爬取的ETD) 写入
///
public DateTime? YgtETD { 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; } //"订舱备注",
public string siremark { get; set; } //"截单备注",
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 thirdPay { get; set; } //"第三方 第三方付费",
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 long? 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 string ZhanCangFlag { get; set; } = ""; //"string",
public string SourceName { get; set; } = ""; //"string",
//public string CtnDayNum { get; set; } = "";//箱使堆存 废弃
public string ShenQingXiangShi { get; set; } = "";//箱使堆存
public string VERSION { get; set; } = "";//版本号 内容为一个gid,用来记录数据是否为最新
public string LineManage { get; set; } = "";//航线管理
public string ShippingMethod { get; set; } = "";//装运方式 整箱/拼箱
public List ctnInputs { get; set; }
public DingCangbookingEDIExt bookingEDIExt { get; set; }
///
/// 原来使用DingCangTDXX
///
public List childrens { get; set; }
public List goodsStatus { get; set; }
class 箱型箱量item
{
public t_code_ctn_md 箱型 { get; set; }
public int 箱量 { get; set; } = 0;
public 箱型箱量item(t_code_ctn_md _箱型, int _箱量)
{
箱型 = _箱型;
箱量 = _箱量;
}
}
class 箱型箱量
{
public List<箱型箱量item> 箱型箱量信息 { get; set; }
public t_code_ctn_de_md 箱型对应 { get; set; }
public 箱型箱量()
{
var ds6 = new DS6DataContext();
箱型箱量信息 = new List<箱型箱量item>();
箱型对应 = ds6.t_code_ctn_de.FirstOrDefault(x => x.id==1);
}
public void Add(箱型箱量item newitem)
{
if (箱型箱量信息.Exists(x => x.箱型 == newitem.箱型))
{
箱型箱量信息.First(x => x.箱型 == newitem.箱型).箱量 += newitem.箱量;
}
else
{
箱型箱量信息.Add(newitem);
}
}
public string get集装箱()
{
var result = "";
foreach (var item in 箱型箱量信息)
{
if (result != "") result += " ";
result += item.箱型.表现形式 + "*" + item.箱量.ToString();
}
return result;
}
public string get计费标准()
{
var result = "";
foreach (var item in 箱型箱量信息)
{
if (result != "") result += "\r\n";
result += item.箱型.表现形式 + "*" + item.箱量.ToString()+"-"+ item.箱型.表现形式;
}
return result;
}
public string get箱数大写()
{
var result = "SAY: ";
foreach (var item in 箱型箱量信息)
{
if (result != "SAY: ") result += " AND ";
result += NumberToEnglishString(item.箱量).ToUpper() + " (" + item.箱型.表现形式 + "*" + item.箱量.ToString() + ")";
}
result += " CONTAINER ONLY. ";
return result;
}
#region 箱型对应
public int get箱型1()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型1)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型1) return item.箱量;
}
return 0;
}
public int get箱型2()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型2)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型2) return item.箱量;
}
return 0;
}
public int get箱型3()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型3)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型3) return item.箱量;
}
return 0;
}
public int get箱型4()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型4)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型4) return item.箱量;
}
return 0;
}
public int get箱型5()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型5)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型5) return item.箱量;
}
return 0;
}
public int get箱型6()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型6)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型6) return item.箱量;
}
return 0;
}
public int get箱型7()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型7)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型7) return item.箱量;
}
return 0;
}
public int get箱型8()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型8)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型8) return item.箱量;
}
return 0;
}
public int get箱型9()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型9)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型9) return item.箱量;
}
return 0;
}
public int get箱型10()
{
if (string.IsNullOrWhiteSpace(箱型对应.箱型10)) return 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.代码 == 箱型对应.箱型10) return item.箱量;
}
return 0;
}
#endregion
public int getTeu()
{
var result = 0;
foreach (var item in 箱型箱量信息)
{
if (item.箱型.尺寸 == "20")
{
result += 1 * item.箱量;
}
else
{
result += 2 * item.箱量;
}
}
return result;
}
}
public int get周次(DateTime? etd) {
try
{
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));
return weeks;
}
catch (Exception e) {
return 0;
}
}
//记录品名
public t_op_seae_md GetOpseae()
{
var weeks = get周次(etd);
//20230410 根据箱信息重新计算 集装箱 和 箱数大写
var d6 = new DS6DataContext();
var 箱型箱量 = new 箱型箱量();
var tcodectn= d6.t_code_ctn.Where(x=>1==1).ToList();
if (ctnInputs!=null)
foreach (var ctn in ctnInputs)
{
var 箱型infoList = tcodectn.Where(x => (x.尺寸 + x.箱型) == ctn.ctnall|| (x.尺寸 +"'"+ x.箱型) == ctn.ctnall||x.表现形式==ctn.ctnall).ToList();
var 箱型info = new t_code_ctn_md();
if (箱型infoList != null && 箱型infoList.Count > 0)
{
箱型info = 箱型infoList[0];
}
else
{
continue;
}
箱型箱量.Add(new 箱型箱量item(箱型info, ctn.ctnnum == null ? 1 : (int)ctn.ctnnum));
}
var 集装箱 = 箱型箱量.get集装箱();
var 箱数大写 = 箱型箱量.get箱数大写();
var 计费标准 = 箱型箱量.get计费标准();
//处理货名
//HS编码 = hscode,
//货物名称 = bookingEDIExt.goodsName,
//货物描述 = description,
var 货物名称 = "";
//var 当前货名 = d6.t_code_goods.Where(x => x.代码 == goodscode).ToList();
//if (当前货名 == null || 当前货名.Count == 0)
//{
// if(!string.IsNullOrWhiteSpace(goodscode)) {
// var newrec = new t_code_goods_md();
// newrec.代码 = SetLength(goodscode, 10);
// newrec.货物名称 = SetLength(goodsname, 100);
// 货物名称 = newrec.货物名称;
// newrec.货物描述 = SetLength(description, 600);
// newrec.商品编码 = SetLength(hscode, 10);
// d6.t_code_goods.Add(newrec);
// d6.SaveChanges();
// }
//}
//else
//{
// 货物名称 = 当前货名[0].货物名称;
//}
货物名称 = dealGoodsinfo(goodscode, goodsname,description,hscode);
var _etd = new DateTime();
var _eta = new DateTime();
if (etd != null) _etd = new DateTime(((DateTime)etd).Year, ((DateTime)etd).Month, ((DateTime)etd).Day);
if (eta != null) _eta = new DateTime(((DateTime)etd).Year, ((DateTime)etd).Month, ((DateTime)etd).Day);
var 操作 = op;
var 操作部门名称 = "";
var 操作部门 = d6.t_sys_employee.FirstOrDefault(x => x.姓名 == 操作);
if (操作部门 != null) 操作部门名称 = 操作部门.部门名称;
var 销售 = sale;
var 销售部门名称 = "";
var 销售部门 = d6.t_sys_employee.FirstOrDefault(x => x.姓名 == 销售);
if (销售部门 != null) 销售部门名称 = 销售部门.部门名称;
//carrier
var 船公司 = carrier;
var carrier_clientList = d6.t_crm_client.Where(x => x.代码 == carrier).ToList();
if (carrier_clientList!=null && carrier_clientList.Count>0) {
var carrier_client = carrier_clientList[0];
船公司 = carrier_client.客户简称;
}
//int? 申请箱使天数 = null;
DateTime now = DateTime.Now;
DateTime today2 = new DateTime(now.Year, now.Month, now.Day);
var 装运方式 = "整箱";
if (!string.IsNullOrWhiteSpace(ShippingMethod))
{
//if (船公司.IndexOf("拼箱") >= 0)
//{
// 装运方式 = "拼箱";
//}
装运方式 = ShippingMethod;
}
var result = new t_op_seae_md
{
业务编号 = bsno,
业务状态 = string.IsNullOrWhiteSpace( bsstatusname)? "接受委托": bsstatusname,
费用状态 = "录入状态",
会计期间 = SetDayZero(atd),
装运方式 = 装运方式,
周次 = weeks,
录入日期 = bsdate, //bsdate new DateTime(2070, 1, 1) ? DateTime.Now: bsdate,
主提单号 = mblno,
真提单号 = tmblno,
//主提单标准 = string.IsNullOrWhiteSpace( mblno)?,
分提单号 = hblno,
订舱序列号 = custno,
运费协议号 = contractno,
发货人代码 = 设置换行(shipper),
收货人代码 = 设置换行(consignee),
通知人代码 = 设置换行(notifyparty),
场站 = yard,
船名 = vessel,
航次 = voynoinner,
开船日期 = SetDayMinute(etd),
ETD = SetDayMinute(YgtETD),
ETA = SetDayZero(eta),
预抵日期 = SetDayMinute(atd),
截港日期 = SetDayZero(closingdate),
装港代码 = portloadid,
装货港 = portload,
卸货代码 = portdischargeid,
卸货港 = portdischarge,
交货代码 = placedeliveryid,
交货地点 = placedelivery,
目的地代码 = destinationid,
目的地 = destination,
提单份数 = nobill,
副本提单份数 = copynobill,
签单方式 = issuetype,
签单日期 = issuedate,
签单地点 = issueplace,
付费方式 = blfrt,
预付地点 = prepardat,
到付地点 = payableat,
运输条款 = service,
唛头 = 设置换行(marks),
运输方式 = service,
HS编码 = hscode,
货物名称 = 货物名称,
货物描述 = 设置换行(description),
件数 = pkgs,
包装 = kindpkgs,
重量 = kgs,
尺码 = cbm,
件数大写 = totalno,
集装箱 = 集装箱,//cntrtotal,//
箱数大写 = 箱数大写,
计费标准 = 计费标准,
船公司 = 船公司,//carrier,
货物标识 = cargoid,
危险品分类 = dclass,
危险品编号 = dunno,
设置温度 = tempset,
冷藏通风量 = reeferf,
最低温度 = tempmin,
最高温度 = tempmax,
是否自有箱 = iscontainersoc,
EDI备注 = 设置换行(soremark),//订舱备注
//分单列表 = 设置换行(soremark),
附加条款 = 设置换行(soremark),
//全称= compname,
合同号 = pono,
合同号备注 = pono,
客服员 = custservice,
操作员 = op,
单证员 = doc,
揽货人 = sale,
航线操作 = route,
委托单位 = customername,
第三方付费 = thirdPay,
报关行 = customser,
承运车队 = trucker,
货代公司 = forwarder,//大简云“订舱代理”,ds6界面的“订舱代理”,ds6数据库的货代
备案号 = lanename,
航线 = lineName,
船代 = shipagency,
代理 = agentname,//大简云“国外代理”,ds6界面的“代理”,ds6数据库的代理
其他备注 = 设置换行(dzRemark),
是否占舱 = ZhanCangFlag == "是" ? "Y" : "N",
占舱备注 = 设置换行(czRemark),
录入人 = createdUserName,
订舱人说明 = (bookingEDIExt == null) ? "" : 设置换行(bookingEDIExt.orderRemark),
DJYID = Id,
通知到港 = null,
是否提货 = null,
是否提交VGM = null,
是否提交舱单 = null,
是否装载放行 = null,
业务来源 = SourceName,
箱使堆存 = 设置换行(ShenQingXiangShi),
总价 = (bookingEDIExt == null) ? "" : bookingEDIExt.kingTareweight == null ? "" : bookingEDIExt.kingTareweight.ToString().Replace(".0", ""),
箱TEU = 箱型箱量.getTeu(),
箱型1 = 箱型箱量.get箱型1(),
箱型2 = 箱型箱量.get箱型2(),
箱型3 = 箱型箱量.get箱型3(),
箱型4 = 箱型箱量.get箱型4(),
箱型5 = 箱型箱量.get箱型5(),
箱型6 = 箱型箱量.get箱型6(),
箱型7 = 箱型箱量.get箱型7(),
箱型8 = 箱型箱量.get箱型8(),
箱型9 = 箱型箱量.get箱型9(),
箱型10 = 箱型箱量.get箱型10(),
辅助字段一 = 设置换行(bookingEDIExt == null ? "" : bookingEDIExt.exRemark1),
辅助字段二 = 设置换行(bookingEDIExt == null ? "" : bookingEDIExt.exRemark2),
辅助字段三 = 设置换行(bookingEDIExt == null ? "" : bookingEDIExt.exRemark3),
辅助字段四 = 设置换行(bookingEDIExt == null ? "" : bookingEDIExt.exRemark4),
操作部门 = 操作部门名称,
销售部门 = 销售部门名称,
DJYVERSION = VERSION,
航线管理= LineManage
};
if(goodsStatus!=null)
foreach (var status in goodsStatus)
{
if (status.statusName == "通知到港")
{
if (status.finishTime != null)
result.通知到港 = true;
}
if (status.statusName == "是否提货")
{
if (status.finishTime != null)
result.是否提货 = true;
}
if (status.statusName == "提交VGM")
{
if (status.finishTime != null)
result.是否提交VGM = true;
}
if (status.statusName == "提交舱单")
{
if (status.finishTime != null)
result.是否提交舱单 = true;
}
if (status.statusName == "装载放行")
{
if (status.finishTime != null)
result.是否装载放行 = true;
}
}
#region 设定字符串长度 超长的截断
var lengthDic = new Dictionary
{
{"业务状态",80},
{"主提单号",20},
{"分提单号",30},
{"委托编号",20},
{"装运方式",8},
{"委托单位",20},
{"发货人",20},
{"收货人",20},
{"通知人",20},
{"发货人代码",1000},
{"收货人代码",1000},
{"通知人代码",1000},
{"代理",20},
{"代理内容",1000},
{"场站",20},
{"船名",60},
{"航次",20},
{"起运港",60},
{"装货港",60},
{"装港代码",10},
{"卸货港",100},
{"卸货代码",10},
{"二程港口",60},
{"二程船名",60},
{"二程航次",20},
{"目的地",30},
{"交货地点",100},
{"交货代码",10},
{"提单份数",10},
{"签单方式",50},
{"签单地点",30},
{"付费方式",60},
{"预付地点",100},
{"到付地点",100},
{"运输条款",10},
{"唛头",800},
{"箱号封号",3000},
{"件数包装",1000},
{"货物描述",1400},
{"货物名称",100},
{"货物重量",1000},
{"货物尺码",1000},
{"包装",60},
{"件数大写",100},
{"箱数大写",100},
{"集装箱",200},
{"录入人",12},
{"操作员",10},
{"揽货人",10},
{"客服员",10},
{"航线",30},
{"船公司",20},
{"货代公司",20},
{"备注",800},
{"报关行",20},
{"承运车队",20},
{"分单列表",2000},
{"计费标准",1000},
{"报关员",10},
{"报关单号",20},
{"核销单号",50},
{"手册号",20},
{"经营单位",60},
{"单位代码",20},
{"合同号",50},
{"合同号备注",50},
{"报关备注",600},
{"危险品分类",5},
{"危险品编号",20},
{"冷藏通风量",12},
{"温度单位",1},
{"设置温度",16},
{"最低温度",5},
{"最高温度",5},
{"货物标识",1},
{"发票号",20},
{"商品编码",400},
{"销售部门",30},
{"操作部门",30},
{"业务来源",8},
{"英文船期",12},
{"三程港口",60},
{"三程船名",60},
{"三程航次",20},
{"辅助字段一",600},
{"辅助字段二",600},
{"辅助字段三",600},
{"辅助字段四",600},
{"解锁人",10},
{"主提单标准",30},
{"分提单标准",30},
{"委托标准",30},
{"财务凭证",30},
{"附加条款",600},
{"备案号",20},
{"运抵国",60},
{"境内货源地",60},
{"批准文号",20},
{"成交方式",20},
{"单价",100},
{"总价",100},
{"商品名称",400},
{"数量单位",400},
{"报检单号",20},
{"实验内容",100},
{"报关操作",10},
{"报检操作",10},
{"币制",100},
{"单证信息",100},
{"核销标准",20},
{"报关标准",20},
{"报检标准",20},
{"目的地代码",10},
{"包装代码",10},
{"发货人编号",10},
{"运输方式",10},
{"运费协议号",20},
{"航线操作",10},
//{"分票编号",12},
//{"特殊要求",30},
{"HS编码",30},
{"船代",20},
{"单证员",10},
{"箱使堆存",30},
{"EDI备注",2000},
{"航线管理",20}
};
foreach (var item in lengthDic)
{
try
{
var property = result.GetType().GetProperty(item.Key);
if (property != null)
{
var _v = result.GetType().GetProperty(item.Key).GetValue(result);
if (_v != null)
{
var newvalue = SetLength(_v.ToString(), item.Value);
result.GetType().GetProperty(item.Key).SetValue(result, newvalue);
}
}
//var value = result.GetType().GetProperty(item.Key).GetValue(result).ToString();
//var newvalue = SetLength(value, item.Value);
//result.GetType().GetProperty(item.Key).SetValue(result, newvalue);
}
catch (Exception e)
{
continue;
}
}
#endregion
return result;
}
public List GetCtnList(string 编号)
{
var result = new List();
if(ctnInputs!=null)
foreach (var ctn in ctnInputs)
{
var d6 = new DS6DataContext();
var 箱型infoList = d6.t_code_ctn.Where(x =>
(x.尺寸 + "'" + x.箱型) == ctn.ctnall
|| (x.尺寸 + x.箱型) == ctn.ctnall
||( x.尺寸 + "'" + x.箱型.Replace("OT","O/T")) == ctn.ctnall
|| (x.尺寸 + x.箱型.Replace("OT", "O/T")) == 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.箱型,
编号 = 编号,
表现形式 = ctn.ctnall,
数量 = ctn.ctnnum,
箱号 = ctn.cntrno,
封号 = ctn.sealno,
件数 = ctn.pkgs,
包装 = ctn.kindpkgs,
重量 = ctn.kgs,
尺码 = ctn.cbm,
皮重 = ctn.tareweight,
TEU = (箱型info.尺寸 == "20" ? 1 * ctn.ctnnum : 2 * ctn.ctnnum),
称重重量 = ctn.weighkgs,
DJYCTNID = ctn.id
};
result.Add(newctn);
}
return result;
}
public string dealGoodsinfo(string goodscode, string goodsname,string description,string hscode) {
var result = "";
try
{
var d6 = new DS6DataContext();
var 当前货名 = d6.t_code_goods.Where(x => x.货物名称 == goodsname).ToList();
if (当前货名 == null || 当前货名.Count == 0)
{
if (!string.IsNullOrWhiteSpace(goodsname))
{
var newrec = new t_code_goods_md();
newrec.代码 = SetLength(goodscode, 10);
newrec.货物名称 = SetLength(goodsname, 100);
result = newrec.货物名称;
newrec.货物描述 = SetLength(description, 600);
newrec.商品编码 = SetLength(hscode, 10);
d6.t_code_goods.Add(newrec);
d6.SaveChanges();
}
}
else
{
result = 当前货名[0].货物名称;
}
}
catch (Exception e) {
var str=JsonConvert.SerializeObject(e);
logger.Error(str);
}
return result;
}
public static void GetCtn(ref t_op_ctn_md curr, t_op_ctn_md ctn)
{
curr.代码 = ctn.代码;
curr.尺寸 = ctn.尺寸;
curr.箱型 = ctn.箱型;
//curr.编号 = head.编号,
curr.表现形式 = ctn.表现形式;
curr.数量 = ctn.数量;
curr.箱号 = ctn.箱号;
curr.封号 = ctn.封号;
curr.件数 = ctn.件数;
curr.包装 = ctn.包装;
curr.重量 = ctn.重量;
curr.尺码 = ctn.尺码;
curr.皮重 = ctn.皮重;
curr.TEU = ctn.TEU;
curr.称重重量 = ctn.称重重量;
curr.DJYCTNID = ctn.DJYCTNID;
}
public List GetAmsList(t_op_seae_md head)
{
var result = new List();
//foreach (var item in bookingEDIExt)
//{
var item = bookingEDIExt;
if (bookingEDIExt != null)
{
var newrec = new t_op_ams_md
{
编号 = head.编号,
发货人代码 = SetLength(item.shipperEdiCode, 10),
收货人代码 = SetLength(item.consigneeEdiCode, 10),
销售代码 = SetLength(item.salerCode, 10),
危险品联系人 = SetLength(item.ediAttn, 30),
危险品联系方式 = SetLength(item.ediAttnTel, 50),
欧盟HSCODE = SetLength(item.ckhi, 100),
南美东NCM = 设置换行(SetLength(item.cncm, 600)),
巴西木质包装说明 = 设置换行(SetLength(item.wncm, 300)),
实际开船日期 = head.开船日期,
HBL发送方式 = SetLength(item.masterBolIndicator, 1),
ESL航线代码 = SetLength(lanename, 20),
SI备注 = 设置换行(SetLength(siremark, 1000))
};
//20230530 如果船公司不是太平PIL 则将部分字段设为空白
if (head.船公司 == "PIL") {
newrec.HBL发送方式 = "";
newrec.销售代码 = "";
newrec.实际开船日期 = null;
newrec.南美东NCM = "";
newrec.巴西木质包装说明 = "";
newrec.欧盟HSCODE = "";
}
result.Add(newrec);
}
//}
return result;
}
public List GetAssistantList(t_op_seae_md head)
{
var result = new List();
var d6 = new DS6DataContext();
var 货物名称 = "";
if(childrens!=null)
foreach (var item in childrens)
{
var weeks = get周次(item.etd);
var 箱型箱量 = new 箱型箱量();
var 箱号封号 = "";
var 件数包装 = item.pkgs.ToString() + item.kindpkgs;
var 货物重量 = item.kgs.ToString() + "KGS";
var 货物尺码 = item.cbm.ToString() + "CBM";
foreach (var ctn in item.ctnInputs)
{
var 箱型infoList = d6.t_code_ctn.Where(x =>
(x.尺寸 + "'" + x.箱型) == ctn.ctnall
|| (x.尺寸 + x.箱型) == ctn.ctnall
|| (x.尺寸 + "'" + x.箱型.Replace("OT", "O/T")) == ctn.ctnall
|| (x.尺寸 + x.箱型.Replace("OT", "O/T")) == ctn.ctnall
).ToList();
var 箱型info = new t_code_ctn_md();
if (箱型infoList != null && 箱型infoList.Count > 0)
{
箱型info = 箱型infoList[0];
}
else
{
continue;
}
箱型箱量.Add(new 箱型箱量item(箱型info, ctn.ctnnum == null ? 1 : (int)ctn.ctnnum));
if (!string.IsNullOrWhiteSpace(ctn.cntrno) || !string.IsNullOrWhiteSpace(ctn.sealno))
{
if (箱号封号 != "") 箱号封号 += "\r\n";
箱号封号 += (string.IsNullOrWhiteSpace(ctn.cntrno) ? "" : ctn.cntrno) + (string.IsNullOrWhiteSpace(ctn.sealno) ? "" : "/" + ctn.sealno);
}
//if (ctn.pkgs != null && ctn.pkgs != 0 && !string.IsNullOrWhiteSpace(ctn.kindpkgs))
//{
// if (件数包装 != "") 件数包装 += "\r\n";
// 件数包装 += ctn.pkgs.ToString() + ctn.kindpkgs;
//}
//if (ctn.kgs != null)// && ctn.重量 != 0
//{
// if (货物重量 != "") 货物重量 += "\r\n";
// 货物重量 += ctn.kgs.ToString() + "KGS";
//}
//if (ctn.cbm != null)//&& ctn.尺码 != 0
//{
// if (货物尺码 != "") 货物尺码 += "\r\n";
// 货物尺码 += ctn.cbm.ToString() + "CBM";
//}
}
var 集装箱 = 箱型箱量.get集装箱();
var 箱数大写 = 箱型箱量.get箱数大写();
//var 当前货名 = new t_code_goods_md();
货物名称 = dealGoodsinfo(item.goodscode, item.goodsname,item.description,item.hscode);
// var 当前货名 = d6.t_code_goods.Where(x => x.代码 == item.goodscode).ToList();
//if (当前货名 == null || 当前货名.Count == 0)
//{
// if (!string.IsNullOrWhiteSpace(item.goodscode))
// {
// var newcodegoods = new t_code_goods_md();
// newcodegoods.代码 = SetLength(item.goodscode, 10);
// newcodegoods.货物名称 = SetLength(item.goodsname, 100);
// 货物名称 = newcodegoods.货物名称;
// newcodegoods.货物描述 = SetLength(item.description, 600);
// newcodegoods.商品编码 = SetLength(item.hscode, 10);
// d6.t_code_goods.Add(newcodegoods);
// d6.SaveChanges();
// }
//}
//else
//{
// 货物名称 = 当前货名[0].货物名称;
//}
var newrec = new t_op_seae_assistant_md
{
编号 = head.编号,
主编号 = head.编号,
DJYCHILDRENID = item.Id,
BSNO = item.bsno,
录入日期 = item.bsdate,
主提单号 = item.mblno,
分提单号 = item.hblno,
//订舱序列号 = item.bookingno,
发货人代码 = 设置换行(item.shipper),
收货人代码 = 设置换行(item.consignee),
通知人代码 = 设置换行(item.notifyparty),
//20230605
代理内容 = 设置换行(item.foreignAgent),
提单份数 = 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.cntrtotal,
船公司 = 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.bookingEDIExt == null) ? 0M : item.bookingEDIExt.kingTareweight == null ? 0M : item.bookingEDIExt.kingTareweight,
//预付地点= item.prepardatid,
//到付地点= item.payableatid,
周次 = weeks,
运费协议号 = item.contractno,
场站 = item.yard,
船名 = item.vessel,
航次 = item.voynoinner,
开船日期 = SetDayMinute(item.etd),
截港日期 = SetDayZero(item.closingdate),
预抵日期 = SetDayMinute(item.eta),
装港代码 = item.portloadid,
装货港 = item.portload,
卸货代码 = item.portdischargeid,
卸货港 = item.portdischarge,
交货代码 = item.placedeliveryid,
交货地点 = item.placedelivery,
目的地代码 = item.destinationid,
目的地 = item.destination,
//集装箱 = 集装箱,
箱数大写 = 箱数大写,
合同号 = item.pono,
委托单位 = item.customername,
报关行 = item.customser,
承运车队 = item.trucker,
货代公司 = item.forwarder,//大简云“订舱代理”,ds6界面的“订舱代理”,ds6数据库的货代
备案号 = item.lanename,
航线 = item.lineName,
代理 = item.agentname,//大简云“国外代理”,ds6界面的“代理”,ds6数据库的代理
录入人 = createdUserName,
箱TEU = 箱型箱量.getTeu(),
箱型1 = 箱型箱量.get箱型1(),
箱型2 = 箱型箱量.get箱型2(),
箱型3 = 箱型箱量.get箱型3(),
箱型4 = 箱型箱量.get箱型4(),
箱型5 = 箱型箱量.get箱型5(),
箱型6 = 箱型箱量.get箱型6(),
箱型7 = 箱型箱量.get箱型7(),
箱型8 = 箱型箱量.get箱型8(),
箱型9 = 箱型箱量.get箱型9(),
箱型10 = 箱型箱量.get箱型10(),
辅助字段一 = 设置换行(item.bookingEDIExt.exRemark1),
辅助字段二 = 设置换行(item.bookingEDIExt.exRemark2),
辅助字段三 = 设置换行(item.bookingEDIExt.exRemark3),
辅助字段四 = 设置换行(item.bookingEDIExt.exRemark4),
箱号封号 = 箱号封号,
件数包装 = 件数包装,
货物重量 = 货物重量,
货物尺码 = 货物尺码
};
var lengthDic = new Dictionary
{
{"主提单号",20},
{"分提单号",20},
{"发货人代码",1000},
{"收货人代码",1000},
{"通知人代码",1000},
{"提单份数",10},
{"签单方式",10},
{"签单地点",30},
{"付费方式",60},
{"预付地点",100},
{"到付地点",100},
{"运输条款",10},
{"唛头",800},
{"运输方式",10},
{"HS编码",30},
{"货物描述",1000},
//{"货物描述",1000},
{"包装",60},
{"件数大写",100},
{"集装箱",200},
{"船公司",20},
{"货物标识",1},
{"危险品分类",5},
{"危险品编号",20},
{"设置温度",16},
{"冷藏通风量",12},
{"最低温度",5},
{"最高温度",5},
{"委托编号",20},
{"操作员",10},
{"揽货人",10},
{"客服员",10},
{"运费协议号",20},
{"场站",20},
{"船名",60},
{"航次",20},
{"装港代码",10},
{"装货港",60},
{"卸货代码",10},
{"卸货港",100},
{"交货代码",10},
{"交货地点",100},
{"目的地代码",10},
{"目的地",30},
{"合同号",50},
{"委托单位",20},
{"报关行",20},
{"承运车队",20},
{"货代公司",20},
{"备案号",20},
{"航线",30},
{"代理",20},
{"录入人",12},
{"辅助字段一",600},
{"辅助字段二",600},
{"辅助字段三",600},
{"辅助字段四",600},
};
//Set分单箱封号件重尺(ref newrec, item);
foreach (var _item in lengthDic)
{
try
{
var value = newrec.GetType().GetProperty(_item.Key).GetValue(newrec).ToString();
var newvalue = SetLength(value, _item.Value);
newrec.GetType().GetProperty(_item.Key).SetValue(newrec, newvalue);
}
catch (Exception e)
{
continue;
}
}
result.Add(newrec);
}
return result;
}
public static void GetAssistant(ref t_op_seae_assistant_md curr, t_op_seae_assistant_md item)
{
//curr.编号 = head.编号;
//curr.主编号 = item.编号;
curr.DJYCHILDRENID = item.DJYCHILDRENID;
curr.BSNO = item.BSNO;
curr.录入日期 = item.录入日期;
curr.主提单号 = item.主提单号;
curr.分提单号 = item.分提单号;
//订舱序列号 = item.bookingno;
curr.发货人代码 = item.发货人代码;
curr.收货人代码 = item.收货人代码;
curr.通知人代码 = item.通知人代码;
curr.代理内容 = item.代理内容;
curr.提单份数 = item.提单份数;
curr.签单方式 = item.签单方式;
curr.签单日期 = item.签单日期;
curr.签单地点 = item.签单地点;
curr.付费方式 = item.付费方式;
curr.预付地点 = item.预付地点;
curr.到付地点 = item.到付地点;
curr.运输条款 = item.运输条款;
curr.唛头 = item.唛头;
curr.运输方式 = item.运输方式;
curr.货物名称 = item.货物名称;
curr.货物描述 = item.货物描述;
curr.件数 = item.件数;
curr.包装 = item.包装;
curr.重量 = item.重量;
curr.尺码 = item.尺码;
curr.件数大写 = item.件数大写;
curr.集装箱 = item.集装箱;
curr.船公司 = item.船公司;
curr.货物标识 = item.货物标识;
curr.危险品分类 = item.危险品分类;
curr.危险品编号 = item.危险品编号;
curr.设置温度 = item.设置温度;
curr.冷藏通风量 = item.冷藏通风量;
curr.最低温度 = item.最低温度;
curr.最高温度 = item.最高温度;
curr.是否自有箱 = item.是否自有箱;
curr.委托编号 = item.委托编号;
curr.操作员 = item.操作员;
curr.揽货人 = item.揽货人;
curr.客服员 = item.客服员;
curr.周次 = item.周次;
curr.运费协议号 = item.运费协议号;
curr.运费协议号 = item.运费协议号;
curr.场站 = item.场站;
curr.船名 = item.船名;
curr.航次 = item.航次;
curr.开船日期 = item.开船日期;
curr.截港日期 = item.截港日期;
curr.预抵日期 = item.预抵日期;
curr.装港代码 = item.装港代码;
curr.装货港 = item.装货港;
curr.卸货代码 = item.卸货代码;
curr.卸货港 = item.卸货港;
curr.交货代码 = item.交货代码;
curr.交货地点 = item.交货地点;
curr.目的地代码 = item.目的地代码;
curr.目的地 = item.目的地;
curr.箱数大写 = item.箱数大写;
curr.合同号 = item.合同号;
curr.委托单位 = item.委托单位;
curr.报关行 = item.报关行;
curr.承运车队 = item.承运车队;
curr.货代公司 = item.货代公司;
curr.备案号 = item.备案号;
curr.航线 = item.航线;
curr.代理 = item.代理;
curr.录入人 = item.录入人;
curr.箱TEU = item.箱TEU;
curr.箱型1 = item.箱型1;
curr.箱型2 = item.箱型2;
curr.箱型3 = item.箱型3;
curr.箱型4 = item.箱型4;
curr.箱型5 = item.箱型5;
curr.箱型6 = item.箱型6;
curr.箱型7 = item.箱型7;
curr.箱型8 = item.箱型8;
curr.箱型9 = item.箱型9;
curr.箱型10 = item.箱型10;
curr.辅助字段一 = item.辅助字段一;
curr.辅助字段二 = item.辅助字段二;
curr.辅助字段三 = item.辅助字段三;
curr.辅助字段四 = item.辅助字段四;
curr.箱号封号 = item.箱号封号;
curr.件数包装 = item.件数包装;
curr.货物重量 = item.货物重量;
curr.货物尺码 = item.货物尺码;
}
public List GetOpStatus(t_op_seae_md head) {
var result = new List();
if (goodsStatus!=null && goodsStatus.Count>0)
{
foreach (var item in goodsStatus) {
var status= new t_op_state_md() {
编号 = head.编号,
业务状态 = item.statusName,
是否完成 = item.finishTime == null ? false : true,
完成时间 = item.finishTime ,
完成人 = item.finishTime == null ?null: head.操作员,
备注 = item.remark,
录入人 = head.操作员,
录入日期 = item.finishTime==null?DateTime.Now: item.finishTime
};
result.Add(status);
}
var _order = 1;
foreach (var item in result.OrderBy(x => x.录入日期)) {
item.顺序 = _order;
_order++;
}
}
return result;
}
public DateTime StartDatetime { get; set; }
//public DingCangHead() {
// StartDatetime=DateTime.Now;
//}
}
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 long Id { get; set; }
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 long? 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 foreignAgent { get; set; } //境外代理,
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 DingCangbookingEDIExt 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",
}
public class 大简云业务函电 {
public t_op_seae_md opseae { get; set; }
public t_op_letter_md HeadLetter { get; set; } = new t_op_letter_md();
public OpLetterBase ChildLetter { get; set; }
public 大简云业务函电() { }
public bool IsDeleted { get; set; } = false;
public static 大简云业务函电 getHelper(string lettername, OpLetterBase childletter) {
var ds6 = new DS6DataContext();
var opseaeList = ds6.t_op_seae.Where(x => x.DJYID == childletter.DJYBOOKINGID).ToList();
var result = new 大简云业务函电();
if (opseaeList == null || opseaeList.Count == 0) {
return result;
}
result.opseae = opseaeList[0];
result.HeadLetter = new t_op_letter_md();
result.HeadLetter.编号 = result.opseae.编号;
result.HeadLetter.函电名称 = lettername;
//该字段用于:保存新增的业务函电时,需先保存op_letter ,但该表是自增序列号表,
//如这种业务函电在一个订舱中多于一个(如派车),则无法定位到正确的新增op_letter
//故增加此字段,以记录该条业务函电的主键。
//如这种业务函电在一个订舱中只有一个(如订舱),则djyid和DJYBOOKINGID字符串相同;
//如多于一个(如派车),则op_letter.djybookingid=op_letter_pc.djybookingid
//且这种业务函电 需要在调用getHelper方法获得【大简云业务函电】对象时,传DJYBOOKINGID字段值
result.HeadLetter.DJYBOOKINGID = childletter.DJYBOOKINGID;
result.HeadLetter.DJYLETTERID = childletter.DJYLETTERID;
result.ChildLetter = childletter;
return result;
}
public void DoSave() {
if (string.IsNullOrWhiteSpace(HeadLetter.编号))
{
return;
}
else {
//如果具体业务函电已存在 则更新之
//判断依据为是否存在
SaveLetter();
}
}
public void SaveLetter(object 大简云对象=null) {
var result = new OpLetterBase();
var ds6 = new DS6DataContext();
void SaveHeadLetter(string 函电名称) {
//
ds6.t_op_letter.Add(HeadLetter);
ds6.SaveChanges();
var letterheads = ds6.t_op_letter.Where(x => x.编号 == opseae.编号 && x.函电名称 == HeadLetter.函电名称).ToList();
if (letterheads != null || letterheads.Count > 0) {
HeadLetter = letterheads[0];
}
//return new t_op_letter_md();
}
void UpdHeadLetter(string 函电名称)
{
//
var UpdHeadLetterList = ds6.t_op_letter.Where(x => x.编号 == opseae.编号 && x.函电名称== 函电名称).ToList();
if (UpdHeadLetterList != null || UpdHeadLetterList.Count > 0)
{
var UpdHead = UpdHeadLetterList[0];
UpdHead.HEAD_TO = HeadLetter.HEAD_TO;
UpdHead.HEAD_ATTN = HeadLetter.HEAD_ATTN;
UpdHead.签发人 = HeadLetter.签发人;
UpdHead.签发日期 = HeadLetter.签发日期;
}
//return new t_op_letter_md();
}
void DelHeadLetter(string 函电名称)
{
var delheadList = ds6.t_op_letter.Where(x => x.编号 == opseae.编号 && x.函电名称 == 函电名称).ToList();
if (delheadList != null && delheadList.Count > 0) {
var delhead= delheadList[0];
ds6.t_op_letter.Remove(delhead);
}
}
//没有找到业务 也就没有可以保存的op_letter 直接退出
if (HeadLetter == null) return;
//var currlist = new List();
if (HeadLetter.函电名称 == "入货通知") {
var currHeadLetterList= ds6.t_op_letter.Where(x => x.编号 == opseae.编号 && x.函电名称== HeadLetter.函电名称).ToList();
var currlist = new List();
if (currHeadLetterList != null && currHeadLetterList.Count > 0) {
var headid = currHeadLetterList[0].LE_ID;
currlist = ds6.t_op_letter_rh.Where(x => x.LE_ID == headid).ToList();
}
//首先判断是否为删除 如果是 执行删除
if (IsDeleted)
{
//找到具体letter 如有则定位到opletter
//两个都要删除
if (currHeadLetterList != null && currHeadLetterList.Count > 0)
{
//ds6.t_op_letter.Remove(currHeadLetterList[0]);
if (currlist != null && currlist.Count > 0)
{
var delrec = currlist[0];
ds6.t_op_letter_rh.Remove(delrec);
}
DelHeadLetter(HeadLetter.函电名称);
ds6.SaveChanges();
return;
}
}
else
{
if (currlist != null && currlist.Count > 0)
{
UpdHeadLetter(HeadLetter.函电名称);
//寻找
var updrec = currlist[0];
updrec.getCopy(ChildLetter, typeof(t_op_letter_rh_md));
ds6.t_op_letter_rh.AddOrUpdate(updrec);
}
else
{
SaveHeadLetter(HeadLetter.函电名称);
if (HeadLetter.LE_ID == 0) return;
ChildLetter.LE_ID = HeadLetter.LE_ID;
ds6.t_op_letter_rh.Add((t_op_letter_rh_md)ChildLetter);
}
}
}
if (HeadLetter.函电名称 == "派车通知")
{
var 派车对象 = (大简云派车)大简云对象;
var currHeadLetterList = ds6.t_op_letter.Where(x => x.编号 == opseae.编号 && x.函电名称 == HeadLetter.函电名称 && x.DJYLETTERID== HeadLetter.DJYLETTERID).ToList();
var currlist = new List();
if (currHeadLetterList != null && currHeadLetterList.Count > 0)
{
var headid = currHeadLetterList[0].LE_ID;
currlist = ds6.t_op_letter_pc.Where(x => x.LE_ID == headid).ToList();
}
if (IsDeleted)
{
//找到具体letter 如有则定位到opletter
//两个都要删除
if (currlist != null && currlist.Count > 0)
{
var delrec = currlist[0];
ds6.t_op_letter_pc.Remove(delrec);
DelHeadLetter(HeadLetter.函电名称);
ds6.SaveChanges();
return;
}
opseae.承运车队 = "";
opseae.派车日期 = null;
ds6.t_op_seae.AddOrUpdate(opseae);
}
else {
opseae.承运车队 = ((t_op_letter_pc_md)ChildLetter).承运车队;
var 派车日 =new DateTime();
try
{
if (派车对象.main.truckTime != null)
{
派车日 = (DateTime)(派车对象.main.truckTime);
派车日 = new DateTime(派车日.Year, 派车日.Month, 派车日.Day);
}
}
catch (Exception)
{
}
opseae.派车日期 = 派车日;
ds6.t_op_seae.AddOrUpdate(opseae);
if (currHeadLetterList == null || currHeadLetterList.Count == 0)
{
ds6.t_op_letter.Add(HeadLetter);
ds6.SaveChanges();
var letterheads = ds6.t_op_letter.Where(x => x.编号 == opseae.编号 && x.DJYLETTERID== HeadLetter.DJYLETTERID).ToList();
if (letterheads != null || letterheads.Count > 0)
{
HeadLetter = letterheads[0];
}
}
if (currlist != null && currlist.Count > 0)
{
//寻找
var updrec = currlist[0];
updrec.getCopy(ChildLetter, typeof(t_op_letter_pc_md));
ds6.t_op_letter_pc.AddOrUpdate(updrec);
}
else
{
if (HeadLetter.LE_ID == 0) return;
ChildLetter.LE_ID = HeadLetter.LE_ID;
ds6.t_op_letter_pc.Add((t_op_letter_pc_md)ChildLetter);
}
var ctninfo = 派车对象.main.contaList;
var currctn = ds6.t_op_letter_pc_ctn.Where(x => x.LE_ID == HeadLetter.LE_ID).ToList();
if (currctn != null && currctn.Count > 0)
{
ds6.t_op_letter_pc_ctn.RemoveRange(currctn);
}
if (ctninfo != null && ctninfo.Count > 0)
{
foreach (var djyctn in ctninfo)
{
var newctn = djyctn.GetPcCtn(HeadLetter);
ds6.t_op_letter_pc_ctn.Add(newctn);
}
}
}
}
ds6.SaveChanges();
}
}
public class 大简云入货通知
{
public long BookingId { get; set; }
public long Id { get; set; }
///
/// TO
///
public string ToName { get; set; }
///
/// ATTN
///
public string Attn { get; set; }
///
/// ATTN电话
///
public string AttnTel { get; set; }
///
/// ATTN邮箱
///
public string AttnMail { get; set; }
///
/// FROM
///
public string FromName { get; set; }
///
/// FROM电话
///
public string FromTel { get; set; }
///
/// FROM邮箱
///
public string FromMail { get; set; }
///
/// 描述
///
public string Description { get; set; }
///
/// 截单时间
///
public DateTime? CloseDocTime { get; set; }
///
/// 截港时间
///
public DateTime? ClosingTime { get; set; }
///
/// 截VGM时间
///
public DateTime? VgmTime { get; set; }
///
/// 备注
///
public string Remark { get; set; }
///
/// 场站代码
///
public string YARDID { get; set; }
///
/// 场站
///
public string YARD { get; set; }
///
/// 场站联系人
///
public string YARDCONTRACT { get; set; }
///
/// 场站联系人电话
///
public string YARDCONTRACTTEL { get; set; }
///
/// 是否删除 ture删除 否则新增或修改
///
public bool IsDeleted { get; set; } = false;
public 大简云业务函电 GetLetter() {
var letterchild = new t_op_letter_rh_md
{
LE_ID = 0,
入货场站 = SetLength( YARD,30),
入货截至时间 = ClosingTime == null ? "" : ((DateTime)ClosingTime).ToString("yyyy-MM-dd"),
场站联系人 = SetLength(YARDCONTRACT,60),
场站联系电话 = SetLength(YARDCONTRACTTEL,60),
备注 = SetLength(Remark,200),
DJYLETTERID = Id,
DJYBOOKINGID= BookingId
};
var result = 大简云业务函电.getHelper( "入货通知", letterchild);
result.HeadLetter.HEAD_TO = SetLength(ToName,60);
result.HeadLetter.HEAD_ATTN = SetLength(Attn,60);
result.HeadLetter.签发人 = SetLength(FromName,10);
result.HeadLetter.签发日期 = DateTime.Now;
result.IsDeleted= IsDeleted;
//result.IsDeleted = true;
return result;
}
}
public class 大简云派车
{
public class 派车head
{
public long gid { get; set; }
public string messageType { get; set; }
public string senderId { get; set; }
public string senderName { get; set; }
public string receiverId { get; set; }
public string receiverName { get; set; }
public string token { get; set; }
public string version { get; set; }
public string requestDate { get; set; }
public string senderKey { get; set; }
public string requestAction { get; set; }
}
public class 派车main
{
public string operType { get; set; }
//tenantId
///
/// 派车单ID
///
public long id { get; set; }
///
/// 订舱ID
///
public long bookingId { get; set; }
public long? truckId { get; set; }
public string truckCode { get; set; }
public string truckName { get; set; }
public string toName { get; set; }
public string attn { get; set; }
public string attnTel { get; set; }
public string attnMail { get; set; }
public string attnFax { get; set; }
public string fromName { get; set; }
public string fromTel { get; set; }
public string fromMail { get; set; }
public string fromFax { get; set; }
public decimal? kgs { get; set; }
public decimal? fee { get; set; }
public string payMethod { get; set; }
public string payMethodName { get; set; }
public DateTime? truckTime { get; set; }
public string yardid { get; set; }
public string yard { get; set; }
public string yardcontract { get; set; }
public string yardcontracttel { get; set; }
public string factoryId { get; set; }
public string factoryCode { get; set; }
public string factoryName { get; set; }
public string factoryContact { get; set; }
public string factoryTel { get; set; }
public string returnTime { get; set; }
public string inYardID { get; set; }
public string inYard { get; set; }
public string inYardContact { get; set; }
public string inYardContractTel { get; set; }
public DateTime? needArriveTime { get; set; }
public string closingTime { get; set; }
public string pickUpTime { get; set; }
public string isGuaJi { get; set; }
public string attention { get; set; }
public string remark { get; set; }
public string dispatcherId { get; set; }
public string dispatcherName { get; set; }
public string factoryAddr { get; set; }
public string callBackStatus { get; set; }
public bool IsDeleted { get {
return operType == "Delete";
}
}
public List contaList { get; set; }=new List();
public string 箱型箱量() {
var result = "";
var 箱型箱量dic=new Dictionary();
foreach (var conta in contaList) {
if (箱型箱量dic.ContainsKey(conta.ctnall))
{
箱型箱量dic[conta.ctnall] += conta.ctnnum == null ? 0 : (int)conta.ctnnum;
}
else {
箱型箱量dic.Add(conta.ctnall, conta.ctnnum == null ? 0 : (int)conta.ctnnum);
}
}
if (箱型箱量dic.Count > 0) {
foreach (var item in 箱型箱量dic) {
if (result == "") result += " ";
result += item.Key+"*"+item.Value.ToString();
}
}
return result;
}
}
public class conta
{
public string ctncode { get; set; }
public string ctnall { get; set; }
public int? ctnnum { get; set; }
public int? teu { get; set; }
public string cntrno { get; set; }
public string sealno { get; set; }
public decimal? pkgs { get; set; }
public string kindpkgs { get; set; }
public decimal? kgs { get; set; }
public decimal? cbm { get; set; }
public decimal? tareweight { get; set; }
public string ctnstatus { get; set; }
public string weightype { get; set; }
public string weighkgs { get; set; }
public string weighattn { get; set; }
public string vgmconncom { get; set; }
public string weightel { get; set; }
public string weighdate { get; set; }
public string vgmaddr { get; set; }
public string vgmemail { get; set; }
public string remark { get; set; }
public string carNumber { get; set; }
public string carDriver { get; set; }
public string carDriverTel { get; set; }
public t_op_letter_pc_ctn_md GetPcCtn(t_op_letter_md HeadLetter) {
var result =new t_op_letter_pc_ctn_md()
{
LE_ID= HeadLetter.LE_ID,
表现形式= ctnall,
箱号 = cntrno,
封号 = sealno,
数量 = ctnnum==null?0:(int)ctnnum,
件数 = pkgs==null?0:(int)pkgs,
包装 = kindpkgs,
重量 = kgs,
尺码 = cbm,
车牌号 = carNumber,
司机 = carDriver,
司机电话 = carDriverTel
};
return result;
}
}
public 派车head head { get; set; }
public 派车main main { get; set; }
public 大简云业务函电 GetLetter()
{
var letterchild = new t_op_letter_pc_md
{
承运车队 = SetLength(main.truckName,30),
箱型箱量 = SetLength(main.箱型箱量(),50),
背箱场站 = SetLength(main.yard,30),
场站联系人 = SetLength(main.yardcontract,60),
场站电话 = SetLength(main.yardcontracttel,60),
要求到厂时间 = main.needArriveTime == null ? "" : ((DateTime)main.needArriveTime).ToString("yyyy-MM-dd HH:mm:ss"),
厂家地址 = SetLength(main.factoryAddr,100),
厂家联系人 = SetLength(main.factoryContact,60),
厂家联系电话 = SetLength(main.factoryTel,60),
返箱地址 = SetLength(main.inYard,100),
返箱联系人 = SetLength(main.inYardContact,60),
返箱联系电话 = SetLength(main.inYardContractTel,60),
备注 = SetLength(main.remark,200),
陆运费 = main.fee,
结算方式 = main.payMethodName,
DJYLETTERID = main.id,
DJYBOOKINGID = main.bookingId
};
var result = 大简云业务函电.getHelper( "派车通知", letterchild);
if (result.HeadLetter == null) return result;
result.IsDeleted = main.IsDeleted;
if(!string.IsNullOrWhiteSpace(main.toName))
result.HeadLetter.HEAD_TO = SetLength(main.toName,60);
if (!string.IsNullOrWhiteSpace(main.attn))
result.HeadLetter.HEAD_ATTN = SetLength(main.attn,60);
if (!string.IsNullOrWhiteSpace(main.fromName))
result.HeadLetter.签发人 = SetLength(main.fromName,10);
if (!string.IsNullOrWhiteSpace(main.fromName))
result.HeadLetter.签发日期 = DateTime.Now;
return result;
}
}
public class 获取编号Helper {
private static readonly Lazy<获取编号Helper> lazy = new Lazy<获取编号Helper>(() => new 获取编号Helper());
public static 获取编号Helper Instance { get { return lazy.Value; } }
private 获取编号Helper() { }
public static int newno { get; set; } = 0;
public string DoGet() {
try
{
//logger.Debug("获取编号");
DS6DataContext DS6Data = new DS6DataContext();
var 编号 = DS6Data.t_op_seae.Max(m => m.编号);
if (编号 == null) 编号 = "0";
var new编号 = (int.Parse(编号) + 1).ToString().PadLeft(10, ' ');
return new编号;
}
catch (Exception ex)
{
logger.Debug("获取编号错误");
return DoGet();
}
finally {
}
}
}
public class 获取业务编号Helper
{
private static readonly Lazy<获取业务编号Helper> lazy = new Lazy<获取业务编号Helper>(() => new 获取业务编号Helper());
public static 获取业务编号Helper Instance { get { return lazy.Value; } }
private 获取业务编号Helper() { }
///
/// 调用DS6的委托编号存储过程
///
///
/// SE加会计期间年月 共8位
///
public string DS6GetBSNO(string Code)
{
//string strConnection = "user id=sa;password=sa;initial catalog=MyTest;Server=YHB;Connect Timeout=30";
using (SqlConnection conn = new SqlConnection(DS6ConnStr))
{
conn.Open();
using (SqlCommand sqlComm = conn.CreateCommand())
{
//设置要调用的存储过程的名称
sqlComm.CommandText = "p_no_get";
//指定SqlCommand对象传给数据库的是存储过程的名称而不是sql语句
sqlComm.CommandType = CommandType.StoredProcedure;
SqlParameter username = sqlComm.Parameters.Add(new SqlParameter("@Code", SqlDbType.VarChar, 20));
//指明"@username"是输入参数
username.Direction = ParameterDirection.Input;
//为“@username”参数赋值
username.Value = Code;
SqlParameter Num = sqlComm.Parameters.Add(new SqlParameter("@Num", SqlDbType.VarChar, 20));
//指定"@password"为输出参数
Num.Direction = ParameterDirection.Output;
//执行
sqlComm.ExecuteNonQuery();
//得到输出参数的值,把赋值给name,注意,这里得到的是object类型的,要进行相应的类型轮换
string num = Convert.ToString(sqlComm.Parameters["@Num"].Value);
return num;
//MessageBox.Show(passwrod);
}
}
return "";
}
}
#endregion
static string NumberToEnglishString(int number)
{
if (number < 0) //暂不考虑负数
{
return "";
}
if (number < 20) //0到19
{
switch (number)
{
case 0:
return "zero";
case 1:
return "one";
case 2:
return "two";
case 3:
return "three";
case 4:
return "four";
case 5:
return "five";
case 6:
return "sex";
case 7:
return "seven";
case 8:
return "eight";
case 9:
return "nine";
case 10:
return "ten";
case 11:
return "eleven";
case 12:
return "twelve";
case 13:
return "thirteen";
case 14:
return "fourteen";
case 15:
return "fifteen";
case 16:
return "sixteen";
case 17:
return "seventeen";
case 18:
return "eighteen";
case 19:
return "nineteen";
default:
return "";
}
}
if (number < 100) //20到99
{
if (number % 10 == 0) //20,30,40,...90的输出
{
switch (number)
{
case 20:
return "twenty";
case 30:
return "thirty";
case 40:
return "forty";
case 50:
return "fifty";
case 60:
return "sixty";
case 70:
return "seventy";
case 80:
return "eighty";
case 90:
return "ninety";
default:
return "";
}
}
else //21.22,.99 思路:26=20+6
{
return string.Format("{0} {1}", NumberToEnglishString(10 * (number / 10)),
NumberToEnglishString(number % 10));
}
}
if (number < 1000) //100到999 百级
{
if (number % 100 == 0)
{
return string.Format("{0} hundred", NumberToEnglishString(number / 100));
}
else
{
return string.Format("{0} hundred and {1}", NumberToEnglishString(number / 100),
NumberToEnglishString(number % 100));
}
}
if (number < 1000000) //1000到999999 千级
{
if (number % 1000 == 0)
{
return string.Format("{0} thousand", NumberToEnglishString(number / 1000));
}
else
{
return string.Format("{0} thousand and {1}", NumberToEnglishString(number / 1000),
NumberToEnglishString(number % 1000));
}
}
if (number < 1000000000) //1000 000到999 999 999 百万级
{
if (number % 1000 == 0)
{
return string.Format("{0} million", NumberToEnglishString(number / 1000000));
}
else
{
return string.Format("{0} million and {1}", NumberToEnglishString(number / 1000000),
NumberToEnglishString(number % 1000000));
}
}
if (number <= int.MaxValue) //十亿 级
{
if (number % 1000000000 == 0)
{
return string.Format("{0} billion", NumberToEnglishString(number / 1000000000));
}
else
{
return string.Format("{0} billion and {1}", NumberToEnglishString(number / 1000000000),
NumberToEnglishString(number % 1000000000));
}
}
return "";
}
public static string SetLength(string oldstr, int length)
{
var str = string.IsNullOrWhiteSpace(oldstr) ? "" : (len(oldstr) > length) ? SubString2( oldstr,0, length) : oldstr;
return str;
}
public static int len(string str)
{
System.Text.ASCIIEncoding n = new System.Text.ASCIIEncoding();
byte[] b = n.GetBytes(str);
int length = 0; // l 为字符串的实际长度
for (int i = 0; i <= b.Length - 1; i++)
{
if (b[i] == 63) //判断是否为汉字或全脚符号
{
length++;
}
length++;
}
return length;
}
public static string SubString2(string str, int startIndex, int length)
{
byte[] b = System.Text.Encoding.Default.GetBytes(str);
if(length> b.Length)
{
length = b.Length;
}
return System.Text.Encoding.Default.GetString(b, startIndex, length);
}
public static DateTime? SetDayZero(DateTime? dt)
{
var result = new DateTime?();
result = null;
if (dt != null) result = new DateTime(((DateTime)dt).Year, ((DateTime)dt).Month, ((DateTime)dt).Day);
return result;
}
public static DateTime? SetDayMinute(DateTime? dt)
{
var result = new DateTime?();
result = null;
if (dt != null) result = new DateTime(((DateTime)dt).Year, ((DateTime)dt).Month, ((DateTime)dt).Day, ((DateTime)dt).Hour, ((DateTime)dt).Minute, ((DateTime)dt).Second);
return result;
}
public static string 设置换行(string str) {
if (string.IsNullOrWhiteSpace(str)) return "";
var myStr = Regex.Replace(str, "(? 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
//public class ThreadSaveDS6_List
//{
// public static bool inworking { get; set; } = false;
// public static List 待处理列表 = new List();
// public static List 处理中列表 = new List();
// public static List 当前处理中DJYID列表 = new List();
// public static void 处理完成(long DJYID) {
// if (处理中列表 != null && 处理中列表.Count > 0) {
// if (处理中列表.Exists(x => x.Id == DJYID)) {
// try {
// var delrec = 处理中列表.FirstOrDefault(x => x.Id == DJYID);
// 处理中列表.Remove(delrec);
// }catch (Exception e)
// {
// //
// }
// }
// }
// }
// public void FuncSend(object o)
// {
// if (inworking == true) return;
// inworking = true;
// if (处理中列表 == null || 处理中列表.Count == 0)
// {
// 当前处理中DJYID列表 = new List();
// }
// else {
// 当前处理中DJYID列表 = 处理中列表.Select(s => s.Id).ToList();
// }
// var newrec = (List)o;
// foreach (var item in newrec) {
// item.StartDatetime=DateTime.Now;
// }
// 待处理列表.AddRange(newrec);
// //var 待处理
// void 执行待处理() {
// var dellist = new List();
// foreach (var item in 待处理列表)
// {
// if (当前处理中DJYID列表.Exists(x => x == item.Id))
// {
// continue;
// }
// else
// {
// dellist.Add(item.Id);
// 当前处理中DJYID列表.Add(item.Id);
// 处理中列表.Add(item);
// //Do_DingCangToDS6(item);
// }
// }
// if (dellist != null && dellist.Count > 0)
// {
// foreach (var delid in dellist)
// {
// if (待处理列表.Exists(x => x.Id == delid))
// {
// var delrec = 待处理列表.FirstOrDefault(x => x.Id == delid);
// 待处理列表.Remove(delrec);
// }
// }
// }
// }
// try
// {
// while (待处理列表 != null && 待处理列表.Count > 0) {
// DateTime dt1 = DateTime.Now;
// while ((DateTime.Now - dt1).TotalMilliseconds < 100)
// {
// continue;
// }
// 执行待处理();
// }
// }
// catch (Exception e)
// {
// }
// finally {
// inworking = false;
// }
// }
//}
public class ThreadSaveDS6_Single
{
//public static bool inworking { get; set; } = false;
//public static List 处理中id列表 = new List();
public void FuncSend(object o)
{
var itemstr = (string)o;
try
{
Do_DingCangToDS6(itemstr);
}
catch (Exception e)
{
var errorobjstr = JsonConvert.SerializeObject(e);
logger.Error($"导入出错:{e}//{errorobjstr}");
}
finally
{
//inworking = false;
}
}
}
}
///
/// 汉字转拼音类
///
public class Hz2Py
{
private static int[] pyValue = new int[]
{
-20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-20230,-20051,-20036,
-20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-19775,-19774,-19763,
-19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-19531,-19525,-19515,
-19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-19263,-19261,-19249,
-19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-19023,-19018,-19006,
-19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-18756,-18741,-18735,
-18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-18478,-18463,-18448,
-18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-18183, -18181,-18012,
-17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-17922,-17759,-17752,
-17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-17496,-17487,-17482,
-17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-16942,-16915,-16733,
-16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-16459,-16452,-16448,
-16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-16393,-16220,-16216,
-16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-15959,-15958,-15944,
-15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-15667,-15661,-15659,
-15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-15416,-15408,-15394,
-15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-15158,-15153,-15150,
-15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-15117,-15110,-15109,
-14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-14914,-14908,-14902,
-14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-14668,-14663,-14654,
-14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-14355,-14353,-14345,
-14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-14123,-14122,-14112,
-14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-13914,-13910,-13907,
-13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-13658,-13611,-13601,
-13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-13359,-13356,-13343,
-13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076,
-13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-12849,-12838,-12831,
-12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-12346,-12320,-12300,
-12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-11847,-11831,-11798,
-11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-11097,-11077,-11067,
-11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-11014,-10838,-10832,
-10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,
-10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-10260,-10256,-10254
};
private static string[] pyName = new string[]
{
"A","Ai","An","Ang","Ao","Ba","Bai","Ban","Bang","Bao","Bei","Ben",
"Beng","Bi","Bian","Biao","Bie","Bin","Bing","Bo","Bu","Ba","Cai","Can",
"Cang","Cao","Ce","Ceng","Cha","Chai","Chan","Chang","Chao","Che","Chen","Cheng",
"Chi","Chong","Chou","Chu","Chuai","Chuan","Chuang","Chui","Chun","Chuo","Ci","Cong",
"Cou","Cu","Cuan","Cui","Cun","Cuo","Da","Dai","Dan","Dang","Dao","De",
"Deng","Di","Dian","Diao","Die","Ding","Diu","Dong","Dou","Du","Duan","Dui",
"Dun","Duo","E","En","Er","Fa","Fan","Fang","Fei","Fen","Feng","Fo",
"Fou","Fu","Ga","Gai","Gan","Gang","Gao","Ge","Gei","Gen","Geng","Gong",
"Gou","Gu","Gua","Guai","Guan","Guang","Gui","Gun","Guo","Ha","Hai","Han",
"Hang","Hao","He","Hei","Hen","Heng","Hong","Hou","Hu","Hua","Huai","Huan",
"Huang","Hui","Hun","Huo","Ji","Jia","Jian","Jiang","Jiao","Jie","Jin","Jing",
"Jiong","Jiu","Ju","Juan","Jue","Jun","Ka","Kai","Kan","Kang","Kao","Ke",
"Ken","Keng","Kong","Kou","Ku","Kua","Kuai","Kuan","Kuang","Kui","Kun","Kuo",
"La","Lai","Lan","Lang","Lao","Le","Lei","Leng","Li","Lia","Lian","Liang",
"Liao","Lie","Lin","Ling","Liu","Long","Lou","Lu","Lv","Luan","Lue","Lun",
"Luo","Ma","Mai","Man","Mang","Mao","Me","Mei","Men","Meng","Mi","Mian",
"Miao","Mie","Min","Ming","Miu","Mo","Mou","Mu","Na","Nai","Nan","Nang",
"Nao","Ne","Nei","Nen","Neng","Ni","Nian","Niang","Niao","Nie","Nin","Ning",
"Niu","Nong","Nu","Nv","Nuan","Nue","Nuo","O","Ou","Pa","Pai","Pan",
"Pang","Pao","Pei","Pen","Peng","Pi","Pian","Piao","Pie","Pin","Ping","Po",
"Pu","Qi","Qia","Qian","Qiang","Qiao","Qie","Qin","Qing","Qiong","Qiu","Qu",
"Quan","Que","Qun","Ran","Rang","Rao","Re","Ren","Reng","Ri","Rong","Rou",
"Ru","Ruan","Rui","Run","Ruo","Sa","Sai","San","Sang","Sao","Se","Sen",
"Seng","Sha","Shai","Shan","Shang","Shao","She","Shen","Sheng","Shi","Shou","Shu",
"Shua","Shuai","Shuan","Shuang","Shui","Shun","Shuo","Si","Song","Sou","Su","Suan",
"Sui","Sun","Suo","Ta","Tai","Tan","Tang","Tao","Te","Teng","Ti","Tian",
"Tiao","Tie","Ting","Tong","Tou","Tu","Tuan","Tui","Tun","Tuo","Wa","Wai",
"Wan","Wang","Wei","Wen","Weng","Wo","Wu","Xi","Xia","Xian","Xiang","Xiao",
"Xie","Xin","Xing","Xiong","Xiu","Xu","Xuan","Xue","Xun","Ya","Yan","Yang",
"Yao","Ye","Yi","Yin","Ying","Yo","Yong","You","Yu","Yuan","Yue","Yun",
"Za", "Zai","Zan","Zang","Zao","Ze","Zei","Zen","Zeng","Zha","Zhai","Zhan",
"Zhang","Zhao","Zhe","Zhen","Zheng","Zhi","Zhong","Zhou","Zhu","Zhua","Zhuai","Zhuan",
"Zhuang","Zhui","Zhun","Zhuo","Zi","Zong","Zou","Zu","Zuan","Zui","Zun","Zuo"
};
///
/// 把汉字转换成拼音(全拼)
///
/// 汉字字符串
/// 转换后的拼音(全拼)字符串
public static string Convert(string hzString)
{
// 匹配中文字符
Regex regex = new Regex("^[\u4e00-\u9fa5]$");
byte[] array = new byte[2];
string pyString = "";
int chrAsc = 0;
int i1 = 0;
int i2 = 0;
char[] noWChar = hzString.ToCharArray();
for (int j = 0; j < noWChar.Length; j++)
{
// 中文字符
if (regex.IsMatch(noWChar[j].ToString()))
{
array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString());
i1 = (short)(array[0]);
i2 = (short)(array[1]);
chrAsc = i1 * 256 + i2 - 65536;
if (chrAsc > 0 && chrAsc < 160)
{
pyString += noWChar[j];
}
else
{
// 修正部分文字
if (chrAsc == -9254) // 修正“圳”字
pyString += "Zhen";
else
{
for (int i = (pyValue.Length - 1); i >= 0; i--)
{
if (pyValue[i] <= chrAsc)
{
pyString += pyName[i];
break;
}
}
}
}
}
// 非中文字符
else
{
pyString += noWChar[j].ToString();
}
}
return pyString;
}
}
//private static string GetCharSpellCode(string CnChar)
//{
// long iCnChar;
// byte[] ZW = System.Text.Encoding.Default.GetBytes(CnChar);
// //如果是字母,则直接返回
// if (ZW.Length == 1)
// {
// return CnChar.ToUpper();
// }
// else
// {
// // get the array of byte from the single char
// int i1 = (short)(ZW[0]);
// int i2 = (short)(ZW[1]);
// iCnChar = i1 * 256 + i2;
// }
// #region table of the constant list
// //expresstion
// //table of the constant list
// // 'A'; //45217..45252
// // 'B'; //45253..45760
// // 'C'; //45761..46317
// // 'D'; //46318..46825
// // 'E'; //46826..47009
// // 'F'; //47010..47296
// // 'G'; //47297..47613
// // 'H'; //47614..48118
// // 'J'; //48119..49061
// // 'K'; //49062..49323
// // 'L'; //49324..49895
// // 'M'; //49896..50370
// // 'N'; //50371..50613
// // 'O'; //50614..50621
// // 'P'; //50622..50905
// // 'Q'; //50906..51386
// // 'R'; //51387..51445
// // 'S'; //51446..52217
// // 'T'; //52218..52697
// //没有U,V
// // 'W'; //52698..52979
// // 'X'; //52980..53640
// // 'Y'; //53689..54480
// // 'Z'; //54481..55289
// #endregion
// // iCnChar match the constant
// if ((iCnChar >= 45217) && (iCnChar <= 45252))
// {
// return "A";
// }
// else if ((iCnChar >= 45253) && (iCnChar <= 45760))
// {
// return "B";
// }
// else if ((iCnChar >= 45761) && (iCnChar <= 46317))
// {
// return "C";
// }
// else if ((iCnChar >= 46318) && (iCnChar <= 46825))
// {
// return "D";
// }
// else if ((iCnChar >= 46826) && (iCnChar <= 47009))
// {
// return "E";
// }
// else if ((iCnChar >= 47010) && (iCnChar <= 47296))
// {
// return "F";
// }
// else if ((iCnChar >= 47297) && (iCnChar <= 47613))
// {
// return "G";
// }
// else if ((iCnChar >= 47614) && (iCnChar <= 48118))
// {
// return "H";
// }
// else if ((iCnChar >= 48119) && (iCnChar <= 49061))
// {
// return "J";
// }
// else if ((iCnChar >= 49062) && (iCnChar <= 49323))
// {
// return "K";
// }
// else if ((iCnChar >= 49324) && (iCnChar <= 49895))
// {
// return "L";
// }
// else if ((iCnChar >= 49896) && (iCnChar <= 50370))
// {
// return "M";
// }
// else if ((iCnChar >= 50371) && (iCnChar <= 50613))
// {
// return "N";
// }
// else if ((iCnChar >= 50614) && (iCnChar <= 50621))
// {
// return "O";
// }
// else if ((iCnChar >= 50622) && (iCnChar <= 50905))
// {
// return "P";
// }
// else if ((iCnChar >= 50906) && (iCnChar <= .51386))
// {
// return "Q";
// }
// else if ((iCnChar >= 51387) && (iCnChar <= 51445))
// {
// return "R";
// }
// else if ((iCnChar >= 51446) && (iCnChar <= 52217))
// {
// return "S";
// }
// else if ((iCnChar >= 52218) && (iCnChar <= 52697))
// {
// return "T";
// }
// else if ((iCnChar >= 52698) && (iCnChar <= 52979))
// {
// return "W";
// }
// else if ((iCnChar >= 52980) && (iCnChar <= 53640))
// {
// return "X";
// }
// else if ((iCnChar >= 53689) && (iCnChar <= 54480))
// {
// return "Y";
// }
// else if ((iCnChar >= 54481) && (iCnChar <= 55289))
// {
// return "Z";
// }
// else return ("?");
//}
}