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

381 lines
23 KiB
C#

3 years ago
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
namespace JobCreateFee
{
public class JobHaireBooking : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobHaireBooking));
private const string CfgFileName = "hairebookingstarttime.cfg";
private static string CfgFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CfgFileName);
public void Execute(IJobExecutionContext context)
{
log.Debug($"Execute开始");
try
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string reqUrl = context.JobDetail.JobDataMap.GetString("ReqUrl");
string CustomerName = context.JobDetail.JobDataMap.GetString("CustomerName");
string TaskEmployee = context.JobDetail.JobDataMap.GetString("TaskEmployee");
int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
if (reqTimeout == 0) reqTimeout = 3;
long ts = DataTableToJsonHelper.ConvertDateTimeToInt(DateTime.Now);
JObject reqObj = new JObject();
var starttimestr = File.ReadAllText(CfgFilePath);
long startts = 0;
if (!string.IsNullOrEmpty(starttimestr))
{
startts = DataTableToJsonHelper.ConvertDateTimeToInt(Convert.ToDateTime(starttimestr));
reqObj.Add("assignBeginTime", new JValue(startts*1000));
}
var endtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
long endts = DataTableToJsonHelper.ConvertDateTimeToInt(Convert.ToDateTime(endtime));
reqObj.Add("assignEndTime", new JValue(endts*1000));
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("notifyid", endts.ToString());
dic.Add("notifytime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
dic.Add("butype","Json");
dic.Add("source", "JF");
dic.Add("content", reqObj.ToString().Replace("\r\n",""));
log.Debug($"数据上传:{dic.ToList()}");
//发送请求数据
string rtn = WebRequestHelper.DoPost(reqUrl, dic, reqTimeout * 1000);
//var objRtn = JsonConvert.DeserializeAnonymousType(rtn, new { status = "", message = "" });
log.Debug($"数据返回:{rtn}");
var parseJsonObj = JsonConvert.DeserializeObject<JsonHBData>(rtn);
if (parseJsonObj.flag&& parseJsonObj.data!= null)
{
//var returnlist = JsonConvert.DeserializeObject<List<JsonBook>>(parseJsonObj.data);
try
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
foreach (var returndata in parseJsonObj.data)
{
var BSNO = Guid.NewGuid().ToString();
var ctnlist = returndata.contains;
if (ctnlist == null) ctnlist = returndata.containerDTOS;
var REEFERF = "";
var temperature = "";
var temperatureUnit = "";
var humidity = "";
3 years ago
if (string.IsNullOrEmpty(returndata.senderName)) returndata.senderName = "";
if (string.IsNullOrEmpty(returndata.scope)) returndata.scope = "";
if (string.IsNullOrEmpty(returndata.orderNo)) returndata.orderNo = "";
if (string.IsNullOrEmpty(returndata.trustDate)) returndata.trustDate = "";
if (string.IsNullOrEmpty(returndata.@operator)) returndata.@operator = "";
if (string.IsNullOrEmpty(returndata.operatorPhone)) returndata.operatorPhone = "";
if (string.IsNullOrEmpty(returndata.saleMan)) returndata.saleMan = "";
if (string.IsNullOrEmpty(returndata.businessType)) returndata.businessType = "";
if (string.IsNullOrEmpty(returndata.trustType)) returndata.trustType = "";
if (string.IsNullOrEmpty(returndata.reqShipmentDate)) returndata.reqShipmentDate = "";
if (string.IsNullOrEmpty(returndata.reqArrivalDate)) returndata.reqArrivalDate = "";
if (string.IsNullOrEmpty(returndata.goodDeliveryDate)) returndata.goodDeliveryDate = "";
if (string.IsNullOrEmpty(returndata.protocol)) returndata.protocol = "";
if (string.IsNullOrEmpty(returndata.senderCode)) returndata.senderCode = "";
if (string.IsNullOrEmpty(returndata.senderDesc)) returndata.senderDesc = "";
if (string.IsNullOrEmpty(returndata.receiverCode)) returndata.receiverCode = "";
if (string.IsNullOrEmpty(returndata.receiverName)) returndata.receiverName = "";
if (string.IsNullOrEmpty(returndata.receiverDesc)) returndata.receiverDesc = "";
if (string.IsNullOrEmpty(returndata.notifierCode)) returndata.notifierCode = "";
if (string.IsNullOrEmpty(returndata.notifierName)) returndata.notifierName = "";
if (string.IsNullOrEmpty(returndata.notifierDesc)) returndata.notifierDesc = "";
if (string.IsNullOrEmpty(returndata.secondnotifierCode)) returndata.secondnotifierCode = "";
if (string.IsNullOrEmpty(returndata.secondnotifierName)) returndata.secondnotifierName = "";
if (string.IsNullOrEmpty(returndata.secondnotifierDesc)) returndata.secondnotifierDesc = "";
if (string.IsNullOrEmpty(returndata.secondNotifierCode)) returndata.secondNotifierCode = "";
if (string.IsNullOrEmpty(returndata.secondNotifierName)) returndata.secondNotifierName = "";
if (string.IsNullOrEmpty(returndata.secondNotifierDesc)) returndata.secondNotifierDesc = "";
if (string.IsNullOrEmpty(returndata.loadingPortCode)) returndata.loadingPortCode = "";
if (string.IsNullOrEmpty(returndata.loadingPort)) returndata.loadingPort = "";
if (string.IsNullOrEmpty(returndata.loadingPortWcode)) returndata.loadingPortWcode = "";
if (string.IsNullOrEmpty(returndata.dischargePortCode)) returndata.dischargePortCode = "";
if (string.IsNullOrEmpty(returndata.dischargePort)) returndata.dischargePort = "";
if (string.IsNullOrEmpty(returndata.dischargePortWcode)) returndata.dischargePortWcode = "";
if (string.IsNullOrEmpty(returndata.transPortCode)) returndata.transPortCode = "";
if (string.IsNullOrEmpty(returndata.transPort)) returndata.transPort = "";
if (string.IsNullOrEmpty(returndata.transPortWcode)) returndata.transPortWcode = "";
if (string.IsNullOrEmpty(returndata.loadPlace)) returndata.loadPlace = "";
if (string.IsNullOrEmpty(returndata.deliveryPlace)) returndata.deliveryPlace = "";
if (string.IsNullOrEmpty(returndata.shipCompanyCode)) returndata.shipCompanyCode = "";
if (string.IsNullOrEmpty(returndata.shipCompany)) returndata.shipCompany = "";
if (string.IsNullOrEmpty(returndata.shipName)) returndata.shipName = "";
if (string.IsNullOrEmpty(returndata.voyageNum)) returndata.voyageNum = "";
if (string.IsNullOrEmpty(returndata.transClause)) returndata.transClause = "";
if (string.IsNullOrEmpty(returndata.freightClause)) returndata.freightClause = "";
if (string.IsNullOrEmpty(returndata.priceClause)) returndata.priceClause = "";
if (string.IsNullOrEmpty(returndata.signType)) returndata.signType = "";
if (string.IsNullOrEmpty(returndata.goodsNum)) returndata.goodsNum = "";
if (string.IsNullOrEmpty(returndata.goodUnit)) returndata.goodUnit = "";
if (string.IsNullOrEmpty(returndata.grossWeight)) returndata.grossWeight = "0";
if (string.IsNullOrEmpty(returndata.volume)) returndata.volume = "0";
if (string.IsNullOrEmpty(returndata.productName)) returndata.productName = "";
if (string.IsNullOrEmpty(returndata.goodsType)) returndata.goodsType = "";
if (string.IsNullOrEmpty(returndata.shipMarks)) returndata.shipMarks = "";
if (string.IsNullOrEmpty(returndata.goodsDesc)) returndata.goodsDesc = "";
if (string.IsNullOrEmpty(returndata.bookingComment)) returndata.bookingComment = "";
if (string.IsNullOrEmpty(returndata.airLine)) returndata.airLine = "";
3 years ago
foreach (var ctn in ctnlist) {
var insertctnstr = "insert into op_seaeorderctn (CTN_ID,ORDNO,CTNALL,CTNNUM,REMARK,KINDPKGS,PKGS,KGS,CBM,GOODSNAME,HSCODE,CNTRNO,SEALNO)";
3 years ago
var kgs = "0";
if (ctn.grossWeight!= null) kgs = ctn.grossWeight;
3 years ago
var valuectnstr = $" values ('{Guid.NewGuid().ToString().Replace("'", "''")}'," +//
$"'{BSNO.Replace("'", "''")}'," + //ORDNO
$"'{ctn.boxType.Replace("'", "''")}'," + //CTNALL
$"'{ctn.boxQuantity.Replace("'", "''")}'," + //CTNNUM
$"''," + //REMARK
$"''," + //KINDPKGS
$"0," + //PKGS
3 years ago
$"'{kgs}'," + //KGS
3 years ago
$"0," + //CBM
$"''," + //GOODSNAME
$"''," + //HSCODE
$"''," + //CNTRNO
$"''" + //SEALNO
$")";
var headctnStr = insertctnstr + valuectnstr;
SqlCommand cmdctn = new SqlCommand(headctnStr, dbcon);
cmdctn.ExecuteNonQuery();
REEFERF = ctn.ventilate;
if (string.IsNullOrEmpty(REEFERF)) REEFERF = "";
temperature = ctn.temperature;
if (string.IsNullOrEmpty(temperature)) temperature = "";
if (ctn.temperatureUnit== "CEL")
temperatureUnit ="C";
if (ctn.temperatureUnit == "FAH")
temperatureUnit = "F";
}
var insertstr = "insert into op_seaeorder (BSNO,ORSTATUS,BSDATE,MBLNO,CUSTOMERNAME,SHIPPER,CONSIGNEE,NOTIFYPARTY,CARRIER,VESSEL,VOYNO,ETD,PlACERECEIPT,PORTLOADID,PORTLOAD,PORTDISCHARGEID,PORTDISCHARGE,PLACEDELIVERYID,PLACEDELIVERY,DESTINATIONID,DESTINATION,NOBILL,ISSUETYPE,ISSUEDATE,ISSUEPLACE,BLFRT,PREPARDAT,PAYABLEAT,SERVICE,MARKS,NOPKGS,DESCRIPTION,GOODSNAME,GROSSWEIGHT,MEASUREMENT,PKGS,KINDPKGS,KGS,CBM,TOTALNO,CNTRTOTAL,INPUTBY,INVNO,CARGOID,DCLASS,DUNNO,REEFERF,TEMPID,TEMPSET,TEMPMAX,TEMPMIN,CUSTOMSNUM,REMARK,DPAGE,DLABEL,LANE,SERVICECONTRACTNO,CUSTNO,CUSTATTN,CUSTTEL,BLTYPE)";
var CARGOID = "S";
if (returndata.goodsType == "01") CARGOID = "R";
if (returndata.goodsType == "02") CARGOID = "D";
var ETD = "";
if (!string.IsNullOrEmpty(returndata.reqShipmentDate)) {
ETD = DataTableToJsonHelper.GetDateTime(long.Parse(returndata.reqShipmentDate)).ToString("yyyy-MM-dd");
}
var BSDATE = "";
if (!string.IsNullOrEmpty(returndata.trustDate))
{
BSDATE = DataTableToJsonHelper.GetDateTime(long.Parse(returndata.trustDate)).ToString("yyyy-MM-dd");
}
var valuestr = $" values ('{BSNO.Replace("'", "''")}'," +//BSNO
$"'{returndata.scope.Replace("'", "''")}'," + //ORSTATUS
$"'{BSDATE.Replace("'", "''")}'," + //BSDATE
$"''," + //MBLNO
$"'{CustomerName.Replace("'", "''")}'," + //CUSTOMERNAME
$"'{returndata.senderName + Environment.NewLine + returndata.senderDesc}'," + //SHIPPER
$"'{returndata.receiverName + Environment.NewLine + returndata.receiverDesc}'," + //CONSIGNEE
$"'{returndata.notifierName + Environment.NewLine + returndata.notifierDesc}'," + //NOTIFYPARTY
//$"'{returndata.secondnotifierName.Replace("'", "''") + Environment.NewLine + returndata.secondnotifierDesc.Replace("'", "''")}'," + //NOTIFYPARTY
$"'{returndata.shipCompany}'," + //CARRIER
$"'{returndata.shipName}'," + //VESSEL
$"'{returndata.voyageNum}'," + //VOYNO
$"'{ETD.Replace("'", "''")}'," + //ETD
$"'{returndata.loadPlace}'," + //PlACERECEIPT
3 years ago
$"'{returndata.loadingPortWcode}'," + //PORTLOADID
3 years ago
$"'{returndata.loadingPort}'," + //PORTLOAD
3 years ago
$"'{returndata.dischargePortWcode}'," + //PORTDISCHARGEID
3 years ago
$"'{returndata.dischargePort}'," + //PORTDISCHARGE
$"''," + //PLACEDELIVERYID
$"'{returndata.deliveryPlace.Replace("'", "''")}'," + //PLACEDELIVERY
3 years ago
$"'{returndata.dischargePortWcode.Replace("'", "''")}'," + //DESTINATIONID
3 years ago
$"'{returndata.dischargePort.Replace("'", "''")}'," + //DESTINATION
$"''," + //NOBILL
$"''," + //ISSUETYPE
$"''," + //ISSUEDATE
$"''," + //ISSUEPLACE
$"'{returndata.freightClause.Replace("'", "''")}'," + //BLFRT
$"''," + //PREPARDAT
$"''," + //PAYABLEAT
$"'{returndata.transClause}'," + //SERVICE
$"'{returndata.shipMarks.Replace("'", "''")}'," + //MARKS
$"'{returndata.goodsNum+ returndata.goodUnit}'," + //NOPKGS
$"'{returndata.goodsDesc}'," + //DESCRIPTION
$"'{returndata.productName}'," + //GOODSNAME
$"'{returndata.grossWeight}KGS'," + //GROSSWEIGHT
$"'{returndata.volume.Replace("'", "''")}CBM'," + //MEASUREMENT
$"'{returndata.goodsNum.Replace("'", "''")}'," + //PKGS
$"'{returndata.goodUnit.Replace("'", "''")}'," + //KINDPKGS
$"'{returndata.grossWeight.Replace("'", "''")}'," + //KGS
$"'{returndata.volume.Replace("'", "''")}'," + //CBM
$"''," + //TOTALNO
$"''," + //CNTRTOTAL
$"''," + //INPUTBY
$"''," + //INVNO
$"'{CARGOID}'," + //CARGOID
$"''," + //DCLASS
$"''," + //DUNNO
$"'{REEFERF.Replace("'", "''")}'," + //REEFERF
$"'{temperatureUnit.Replace("'", "''")}'," + //TEMPID
$"'{temperature.Replace("'", "''")}'," + //TEMPSET
$"''," + //TEMPMAX
$"''," + //TEMPMIN
$"0," + //CUSTOMSNUM
$"'{returndata.bookingComment.Replace("'", "''")}'," + //REMARK
$"''," + //DPAGE
$"''," + //DLABEL
$"'{returndata.airLine}'," + //LANE
$"'{returndata.protocol}'," + //SERVICECONTRACTNO
$"'{returndata.orderNo}'," + //CUSTNO
$"'{returndata.@operator}'," + //CUSTATTN
$"'{returndata.operatorPhone}'," + //CUSTTEL
$"''" + //CUSTTEL
$")";
var headStr = insertstr + valuestr;
SqlCommand cmd = new SqlCommand(headStr, dbcon);
cmd.ExecuteNonQuery();
var tastStr = $" INSERT INTO [t_op_task] ([任务编号],[上级任务号],[任务类型],[任务来源],[任务状态],[任务说明],[发起人],[录入日期],[任务开始时间],[完成方式],[完成时间],[KPI值],[提单号],[文件编号],[邮件编号],[电子档案路径],[是否公共],[任务相关人员],[SEA编号]) select newid(),null,'EDI订舱','FTP','未开始','海尔订舱:{returndata.dischargePort}','DEMO-SA',GETDATE(),GETDATE(),'手动',NULL,0,'',null,null,null,0,'{TaskEmployee}','{BSNO}' ";
SqlCommand cmdtast = new SqlCommand(tastStr, dbcon);
cmdtast.ExecuteNonQuery();
}
dbcon.Close();
}
}
catch (Exception e) {
log.Debug($"记录插入错误:{e.Message}");
}
}
else {
log.Debug($"数据返回信息:{parseJsonObj.msg}");
}
File.WriteAllText(CfgFilePath, endtime);
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
}
public class JsonBook
{
public string scope { get; set; }
public string orderNo { get; set; }
public string trustDate { get; set; }
public string @operator { get; set; }
public string operatorPhone { get; set; }
public string saleMan { get; set; }
public string businessType { get; set; }
public string trustType { get; set; }
public string reqShipmentDate { get; set; }
public string reqArrivalDate { get; set; }
public string goodDeliveryDate { get; set; }
public string protocol { get; set; }
public string senderCode { get; set; }
public string senderName { get; set; }
public string senderDesc { get; set; }
public string receiverCode { get; set; }
public string receiverName { get; set; }
public string receiverDesc { get; set; }
public string notifierCode { get; set; }
public string notifierName { get; set; }
public string notifierDesc { get; set; }
public string secondnotifierCode { get; set; }
public string secondnotifierName { get; set; }
public string secondnotifierDesc { get; set; }
public string secondNotifierCode { get; set; }
public string secondNotifierName { get; set; }
public string secondNotifierDesc { get; set; }
public string loadingPortCode { get; set; }
public string loadingPort { get; set; }
3 years ago
public string loadingPortWcode { get; set; }
3 years ago
public string dischargePortCode { get; set; }
public string dischargePort { get; set; }
3 years ago
public string dischargePortWcode { get; set; }
3 years ago
public string transPortCode { get; set; }
public string transPort { get; set; }
3 years ago
public string transPortWcode { get; set; }
3 years ago
public string loadPlace { get; set; }
public string deliveryPlace { get; set; }
public string country { get; set; }
public string airLine { get; set; }
public string shipCompanyCode { get; set; }
public string shipCompany { get; set; }
public string shipName { get; set; }
public string voyageNum { get; set; }
public string transClause { get; set; }
public string freightClause { get; set; }
public string priceClause { get; set; }
public string signType { get; set; }
public string goodsNum { get; set; }
public string goodUnit { get; set; }
public string grossWeight { get; set; }
public string volume { get; set; }
public string productName { get; set; }
public string goodsType { get; set; }
public string shipMarks { get; set; }
public string goodsDesc { get; set; }
public string bookingComment { get; set; }
public List<JsonCtn> contains { get; set; }
public List<JsonCtn> containerDTOS { get; set; }
}
public class JsonCtn
{
public string itemNo { get; set; }
public string boxType { get; set; }
public string boxQuantity { get; set; }
public string grossWeight { get; set; }
public string grossWeightUnit { get; set; }
public string temperature { get; set; }
public string temperatureUnit { get; set; }
public string ventilate { get; set; }
public string ventilateUnit { get; set; }
public string humidity { get; set; }
public string humidityUnit { get; set; }
}
public class JsonHBData
{
public bool flag { get; set; }
public List<JsonBook> data { get; set; }
public string msg { get; set; }
public string code { get; set; }
}
}