|
|
|
|
using log4net;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Quartz;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace JobReqWebData
|
|
|
|
|
{
|
|
|
|
|
public class JobDs7ToWeb : IJob
|
|
|
|
|
{
|
|
|
|
|
private ILog log = LogManager.GetLogger(typeof(JobDs7ToWeb));
|
|
|
|
|
//private const string CfgFileName = "requestjson.cfg";
|
|
|
|
|
//private static string CfgFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CfgFileName);
|
|
|
|
|
public void Execute(IJobExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
|
|
|
|
|
string WebconnStr = context.JobDetail.JobDataMap.GetString("WebConnectString");
|
|
|
|
|
string sqlQuery = context.JobDetail.JobDataMap.GetString("QuerySql");
|
|
|
|
|
|
|
|
|
|
log.Debug($"连接字符串:{connStr}");
|
|
|
|
|
|
|
|
|
|
SqlConnection conn = new SqlConnection(connStr);
|
|
|
|
|
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlQuery, conn);
|
|
|
|
|
DataTable tQuery = new DataTable();
|
|
|
|
|
dataAdapter.Fill(tQuery);
|
|
|
|
|
|
|
|
|
|
if (tQuery.Rows.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
log.Debug("没有要发送的数据!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var mblno = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (SqlConnection db = new SqlConnection(WebconnStr))
|
|
|
|
|
{
|
|
|
|
|
db.Open();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 运踪
|
|
|
|
|
if (tQuery.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (DataRow row in tQuery.Rows)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
string cmdDelete = "delete from tb_order where BSNO='"+ row["AS_ID"].ToString() + "' delete from tb_ctn where BSNO='" + row["AS_ID"].ToString() + "'";
|
|
|
|
|
SqlCommand cmddelete = new SqlCommand(cmdDelete, db);
|
|
|
|
|
cmddelete.ExecuteNonQuery();
|
|
|
|
|
using (SqlTransaction trans = db.BeginTransaction())
|
|
|
|
|
{
|
|
|
|
|
log.Debug("插入"+ row["MBLNO"].ToString()+"-"+ row["HBLNO"].ToString());
|
|
|
|
|
string sql = "insert into tb_order(BSNO,业务编号,提单号,分单号,客户名称,发货人,收货人,启运港,目的港,国家名称" +
|
|
|
|
|
",船名,航次,箱量表示,出口类型,运输条款,预计离港,实际离港,联系客户时间,建立时间,出号时间" +
|
|
|
|
|
",操作时间,船公司,PO,品名,HS编码,件数文本,重量文本,尺码文本,保险联系人)";
|
|
|
|
|
sql = sql + " values (@BSNO,@CUSTNO,@MBLNO,@HBLNO,@CUSTOMERNAME,@SHIPPER,@CONSIGNEE,@PORTLOAD,@DESTINATION,@COUNTRY" +
|
|
|
|
|
",@VESSEL,@VOYNO,@CNTRTOTAL,@BLTYPE,@SERVICE,@ETD,@ATD,@LINKCUSTTIME,@CREATETIME,@MBLNOTIME" +
|
|
|
|
|
",@BSDATE,@CARRIER,@PONO,@GOODSNAME,@HSCODE,@NOPKGS,@GROSSWEIGHT,@MEASUREMENT,@INSURANCEOP)";
|
|
|
|
|
SqlCommand cmd = new SqlCommand(sql, db, trans);
|
|
|
|
|
cmd.Parameters.AddWithValue("@BSNO", row["AS_ID"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@CUSTNO", row["CUSTNO"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@MBLNO", row["MBLNO"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@HBLNO", row["HBLNO"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@CUSTOMERNAME", row["CUSTOMERNAME"].ToString());
|
|
|
|
|
var Shipping = row["SHIPPER"].ToString();
|
|
|
|
|
Shipping = Shipping.Replace("\n", "\\");
|
|
|
|
|
Shipping = Shipping.Replace("\r", " ");
|
|
|
|
|
string[] ShippingList = Shipping.Split('\\');
|
|
|
|
|
if (ShippingList.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
cmd.Parameters.AddWithValue("@SHIPPER", ShippingList[0]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cmd.Parameters.AddWithValue("@SHIPPER","");
|
|
|
|
|
}
|
|
|
|
|
Shipping = row["CONSIGNEE"].ToString();
|
|
|
|
|
Shipping = Shipping.Replace("\n", "\\");
|
|
|
|
|
Shipping = Shipping.Replace("\r", " ");
|
|
|
|
|
ShippingList = Shipping.Split('\\');
|
|
|
|
|
if (ShippingList.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
cmd.Parameters.AddWithValue("@CONSIGNEE", ShippingList[0]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cmd.Parameters.AddWithValue("@CONSIGNEE", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd.Parameters.AddWithValue("@PORTLOAD", row["PORTLOAD"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@DESTINATION", row["DESTINATION"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@COUNTRY", row["COUNTRY"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@VESSEL", row["VESSEL"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@VOYNO", row["VOYNO"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@CNTRTOTAL", row["CNTRTOTAL"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@BLTYPE", row["BLTYPE"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@SERVICE", row["SERVICE"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@ETD", row["ETD"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@ATD", row["ATD"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@LINKCUSTTIME", row["LINKCUSTTIME"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@CREATETIME", row["CREATETIME"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@MBLNOTIME", row["MBLNOTIME"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@BSDATE", row["BSDATE"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@CARRIER", row["CARRIER"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@PONO", row["PONO"].ToString());
|
|
|
|
|
Shipping = row["DESCRIPTION"].ToString();
|
|
|
|
|
Shipping = Shipping.Replace("\n", "\\");
|
|
|
|
|
Shipping = Shipping.Replace("\r", " ");
|
|
|
|
|
ShippingList = Shipping.Split('\\');
|
|
|
|
|
if (ShippingList.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
cmd.Parameters.AddWithValue("@GOODSNAME", ShippingList[0]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cmd.Parameters.AddWithValue("@GOODSNAME", "");
|
|
|
|
|
}
|
|
|
|
|
cmd.Parameters.AddWithValue("@HSCODE", row["HSCODE"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@NOPKGS", row["NOPKGS"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@GROSSWEIGHT", row["GROSSWEIGHT"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@MEASUREMENT", row["MEASUREMENT"].ToString());
|
|
|
|
|
cmd.Parameters.AddWithValue("@INSURANCEOP", row["INSURANCEOP"].ToString());
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
var sqlctn = "select * from op_ctn where BSNO='"+ row["AS_ID"].ToString() + "'";
|
|
|
|
|
SqlDataAdapter dataAdapterCtn = new SqlDataAdapter(sqlctn, conn);
|
|
|
|
|
DataTable tQueryCtn = new DataTable();
|
|
|
|
|
dataAdapterCtn.Fill(tQueryCtn);
|
|
|
|
|
if (tQueryCtn.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (DataRow rowctn in tQueryCtn.Rows)
|
|
|
|
|
{
|
|
|
|
|
var cmdInsertCtnSQL = "insert into tb_ctn (CTN_ID,BSNO,CTNCODE,[SIZE],CTN,CTNNUM,TEU,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,KINDPKGS,TAREWEIGHT,GOODSNAME,CTNSTATUS,MASTERNO,WEIGHTYPE,WEIGHKGS,WEIGHATTN,WEIGHTEL,WEIGHSIGN,WEIGHDATE,TRUCKER,TRUCKFEE,FREESTORAGEDAY,STORAGEDAY,STORAGEPRICE,STORAGEFEE,FREECTNDAY,CTNDAY,CTNPRICE,CTNFEE,TRUCKNO,VGMCONNCOM,VGMADDR,VGMEMAIL,ISTEMP,TIXIANGSHIJIAN) values ("
|
|
|
|
|
+ "NEWID(),'" + row["AS_ID"].ToString() + "','" + rowctn["CTNCODE"].ToString() + "','" + rowctn["SIZE"].ToString() + "','" + rowctn["CTN"].ToString() + "'," + rowctn["CTNNUM"].ToString()+ "," + rowctn["TEU"].ToString()+ ",'" + rowctn["CTNALL"].ToString().Replace("'", "''") + "','" + rowctn["CNTRNO"].ToString() + "','" + rowctn["SEALNO"].ToString() + "','" + rowctn["PKGS"].ToString() + "'," + rowctn["KGS"].ToString()+ "," + rowctn["CBM"].ToString() + ",'" + rowctn["REMARK"].ToString() + "','" + rowctn["KINDPKGS"].ToString()+ "'," + rowctn["TAREWEIGHT"].ToString()+ ",'','"
|
|
|
|
|
+ rowctn["CTNSTATUS"].ToString() + "','" + rowctn["MASTERNO"].ToString()+ "','',0,'0','','','','',0"
|
|
|
|
|
+ ",0,0,0,0,0,0,0,0,'','','','','','')";
|
|
|
|
|
SqlCommand cmdInsertCtn = new SqlCommand(cmdInsertCtnSQL, db, trans);
|
|
|
|
|
cmdInsertCtn.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
trans.Commit();
|
|
|
|
|
}
|
|
|
|
|
log.Debug("插入" + row["MBLNO"].ToString() + "-" + row["HBLNO"].ToString()+"完成!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(item.SJLGSJ))
|
|
|
|
|
//{
|
|
|
|
|
// string sql ="update op_seae set ATD='"+ item.SJLGSJ + "' where VESSEL='"+ item.YWCM + "' AND VOYNO='"+ item.CKHC+ "'";
|
|
|
|
|
// SqlCommand cmd = new SqlCommand(sql, dbcon, trans);
|
|
|
|
|
// cmd.ExecuteNonQuery();
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (DataRow row in tQuery.Rows)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (DataColumn col in tQuery.Columns)
|
|
|
|
|
{
|
|
|
|
|
mblno = row["MBLNO"].ToString();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error(ex.Message);
|
|
|
|
|
log.Error(ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public string GETBSNO(string MBLNO, SqlConnection dbcon)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT BSNO from V_OP_BS where MBLNO='" + MBLNO + "'");
|
|
|
|
|
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
|
|
|
|
|
DataTable table = new DataTable();
|
|
|
|
|
adapter.Fill(table);
|
|
|
|
|
var BSNO = "";
|
|
|
|
|
if (table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
|
|
{
|
|
|
|
|
BSNO = row["BSNO"].ToString();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return BSNO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|