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.
861 lines
42 KiB
C#
861 lines
42 KiB
C#
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;
|
|
using DSWeb.Common;
|
|
using JobAutoCreateFee.Model;
|
|
using System.Security.Policy;
|
|
using System.Xml.Linq;
|
|
using System.Diagnostics.Eventing.Reader;
|
|
|
|
namespace JobCreateFee
|
|
{
|
|
public class JobD7CoscoFee : IJob
|
|
{
|
|
private ILog log = LogManager.GetLogger(typeof(JobD7CoscoFee));
|
|
|
|
public void Execute(IJobExecutionContext context)
|
|
{
|
|
log.Debug($"Execute开始");
|
|
try
|
|
{
|
|
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
|
|
string reqUrl = context.JobDetail.JobDataMap.GetString("CoscoReqFeeUrl");
|
|
|
|
string UserKey = context.JobDetail.JobDataMap.GetString("UserKey");
|
|
string UserSecret = context.JobDetail.JobDataMap.GetString("UserSecret");
|
|
string WebAccount = context.JobDetail.JobDataMap.GetString("WebAccount");
|
|
string WebPassword = context.JobDetail.JobDataMap.GetString("WebPassword");
|
|
|
|
string CompanyCode = context.JobDetail.JobDataMap.GetString("CompanyCode");
|
|
|
|
string BsSql = context.JobDetail.JobDataMap.GetString("BsSql");
|
|
string FEECUSTNAME = context.JobDetail.JobDataMap.GetString("FEECUSTNAME");
|
|
string ENTEROPERATOR = context.JobDetail.JobDataMap.GetString("ENTEROPERATOR");
|
|
string FEESTATUS = context.JobDetail.JobDataMap.GetString("FEESTATUS");
|
|
|
|
|
|
int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
|
|
long ts = DataTableToJsonHelper.ConvertDateTimeToInt(DateTime.Now);
|
|
|
|
|
|
log.Debug($"获取数据");
|
|
|
|
|
|
using (SqlConnection dbcon = new SqlConnection(connStr))
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append(BsSql);
|
|
|
|
SqlCommand cmd = new SqlCommand();
|
|
cmd.CommandText = strSql.ToString();
|
|
cmd.CommandTimeout = 120000; //要加这一句
|
|
cmd.Connection = dbcon;
|
|
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
|
|
DataTable table = new DataTable();
|
|
adapter.Fill(table);
|
|
var feebacklist = new List<feeback>();
|
|
if (table.Rows.Count > 0)
|
|
{
|
|
log.Debug($"数据{table.Rows.Count}条");
|
|
var FeeTemplateDetailList = GetFeeTemplate(FEECUSTNAME, dbcon);
|
|
|
|
|
|
foreach (DataRow row in table.Rows)
|
|
{
|
|
var MBLNO = row["MBLNO"].ToString();
|
|
var BSNO = row["BSNO"].ToString();
|
|
var ETD = row["ETD"].ToString();
|
|
if (!string.IsNullOrEmpty(MBLNO) && MBLNO.Length > 4) {
|
|
MBLNO = MBLNO.Substring(4);
|
|
}
|
|
|
|
var JsonCoscoFeeSend = new JsonCoscoFeeSend();
|
|
JsonCoscoFeeSend.userKey = UserKey;
|
|
JsonCoscoFeeSend.userSecret = UserSecret;
|
|
JsonCoscoFeeSend.companyCode = CompanyCode;
|
|
JsonCoscoFeeSend.webAccount = WebAccount;
|
|
JsonCoscoFeeSend.webPassword = WebPassword;
|
|
JsonCoscoFeeSend.bno = MBLNO;
|
|
JsonCoscoFeeSend.summaryFlag = false;
|
|
var sendstr = JsonConvert.SerializeObject(JsonCoscoFeeSend);
|
|
log.Debug($"发送包:{sendstr}");
|
|
//发送请求数据
|
|
string rtn = WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000);
|
|
log.Debug($"数据返回:{rtn}");
|
|
var objRtn = JsonConvert.DeserializeAnonymousType(rtn, new { code = "", msg = "" });
|
|
if (objRtn.code=="200")
|
|
{
|
|
var objreturn= JsonConvert.DeserializeObject<JsonCoscoRec>(rtn);
|
|
|
|
var returnlist = objreturn.data;
|
|
if (returnlist != null && returnlist.Count != 0)
|
|
{
|
|
var feelist = new List<MsChFee>();
|
|
var unitlist = GetFeeUnit(BSNO, dbcon);
|
|
var isctnnum = 1;
|
|
var findunitlist = unitlist.FindAll(x=>x.ISCTN);
|
|
if (findunitlist != null && findunitlist.Count >= 2) {
|
|
isctnnum = 2;
|
|
}
|
|
|
|
|
|
string sql = "";
|
|
try
|
|
{
|
|
|
|
|
|
foreach (var returndata in returnlist)
|
|
{
|
|
|
|
|
|
if (!GETINVNOISUSE(BSNO, returndata.itemUuid, dbcon))
|
|
{
|
|
|
|
|
|
if (Convert.ToDecimal(returndata.totalAmount.Trim())!=0)
|
|
{
|
|
var price = returndata.totalAmount;
|
|
if (price == "") price = "0";
|
|
var curr = returndata.currencyUnit;
|
|
if (curr == "CNY") curr = "RMB";
|
|
var FEENAME = GETFEENAME(returndata.feeName.Replace("'", "").Replace(",", "").Replace(".", ""), dbcon, curr);
|
|
decimal exrate = 1;
|
|
var AMOUNT = returndata.totalAmount;
|
|
var COUNT = "1";
|
|
if (curr != "RMB")
|
|
{
|
|
exrate = GetUsdExrate(dbcon, curr, ETD);
|
|
}
|
|
price = price.Replace(",", "");
|
|
if (string.IsNullOrEmpty(FEENAME))
|
|
{
|
|
var feeback = new feeback();
|
|
feeback.ReceiveId = returndata.bno;
|
|
feeback.Success = false;
|
|
feeback.Reason = $"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 未匹配";
|
|
feebacklist.Add(feeback);
|
|
log.Debug($"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 未匹配");
|
|
}
|
|
else
|
|
{
|
|
bool isadd = false;
|
|
var FindFeeTemplateDetailList = FeeTemplateDetailList.FindAll(x=>x.FEENAME==FEENAME);
|
|
if (FindFeeTemplateDetailList != null&& FindFeeTemplateDetailList.Count!=0)
|
|
{
|
|
foreach (var FeeTemplateDetail in FindFeeTemplateDetailList)
|
|
{
|
|
|
|
if (FeeTemplateDetail.ISCTN)
|
|
{
|
|
var addfeelist = new List<MsChFee>();
|
|
decimal ttlamount = 0;
|
|
if (isctnnum != 2)
|
|
{
|
|
|
|
var unit = unitlist.Find(x => x.UNIT == FeeTemplateDetail.UNIT);
|
|
if (unit != null)
|
|
{
|
|
var newfee = new MsChFee();
|
|
newfee.FA_ID = returndata.itemUuid;
|
|
newfee.Currency = curr;
|
|
newfee.CustomerName = FEECUSTNAME;
|
|
newfee.BSNO = BSNO;
|
|
newfee.ExChangerate = exrate;
|
|
newfee.FeeName = FEENAME;
|
|
newfee.Quantity = unit.QUANTITY;
|
|
newfee.Unit = FeeTemplateDetail.UNIT;
|
|
if (FeeTemplateDetail.UNITPRICE == 0)
|
|
{
|
|
newfee.UnitPrice = Convert.ToDecimal(returndata.totalAmount) / newfee.Quantity;
|
|
}
|
|
else
|
|
{
|
|
newfee.UnitPrice = FeeTemplateDetail.UNITPRICE;
|
|
}
|
|
newfee.Amount = Convert.ToDecimal(returndata.totalAmount);
|
|
newfee.FeeEName = returndata.feeName.Replace("'", "").Replace(",", "").Replace(".", "");
|
|
// addfeelist.Add(newfee);
|
|
ttlamount = ttlamount + newfee.Amount;
|
|
feelist.Add(newfee);
|
|
isadd = true;
|
|
|
|
}
|
|
}
|
|
else {
|
|
log.Debug($"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 存在多箱型无法匹配");
|
|
|
|
}
|
|
|
|
|
|
//}
|
|
|
|
//if (ttlamount == Convert.ToDecimal(returndata.totalAmount))
|
|
//{
|
|
|
|
//}
|
|
//else
|
|
//{
|
|
// var feeback = new feeback();
|
|
// feeback.ReceiveId = returndata.bno;
|
|
// feeback.Success = false;
|
|
// feeback.Reason = $"提单号:{MBLNO},编号:{BS.BSNO},费用金额:{ttlamount} 未匹配{returndata.totalAmount}";
|
|
// feebacklist.Add(feeback);
|
|
// log.Debug($"提单号:{MBLNO},编号:{BS.BSNO},费用金额:{ttlamount} 未匹配{returndata.totalAmount}");
|
|
|
|
//}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
var newfee = new MsChFee();
|
|
newfee.FA_ID = returndata.itemUuid;
|
|
newfee.Currency = curr;
|
|
newfee.CustomerName = FEECUSTNAME;
|
|
newfee.BSNO = BSNO;
|
|
newfee.ExChangerate = exrate;
|
|
newfee.FeeName = FEENAME;
|
|
newfee.Quantity = 1;
|
|
newfee.Unit = FeeTemplateDetail.UNIT;
|
|
newfee.UnitPrice = Convert.ToDecimal(returndata.totalAmount);
|
|
newfee.Amount = Convert.ToDecimal(returndata.totalAmount);
|
|
newfee.FeeEName = returndata.feeName.Replace("'", "").Replace(",", "").Replace(".", "");
|
|
feelist.Add(newfee);
|
|
isadd = true;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var newfee = new MsChFee();
|
|
newfee.FA_ID = returndata.itemUuid;
|
|
newfee.Currency = curr;
|
|
newfee.CustomerName = FEECUSTNAME;
|
|
newfee.BSNO = BSNO;
|
|
newfee.ExChangerate = exrate;
|
|
newfee.FeeName = FEENAME;
|
|
newfee.Quantity = 1;
|
|
newfee.Unit = "票";
|
|
newfee.UnitPrice =Convert.ToDecimal(returndata.totalAmount);
|
|
newfee.Amount= Convert.ToDecimal(returndata.totalAmount);
|
|
newfee.FeeEName = returndata.feeName.Replace("'", "").Replace(",", "").Replace(".", "");
|
|
feelist.Add(newfee);
|
|
isadd = true;
|
|
|
|
}
|
|
|
|
if (!isadd) {
|
|
var feeback = new feeback();
|
|
feeback.ReceiveId = returndata.bno;
|
|
feeback.Success = false;
|
|
feeback.Reason = $"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 金额:{returndata.totalAmount}未匹配添加";
|
|
feebacklist.Add(feeback);
|
|
log.Debug($"提单号:{MBLNO},编号:{BSNO},费用名称:{returndata.feeName} 金额:{returndata.totalAmount} 未匹配添加");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Debug($"记录插入错误:{e.Message}" + sql);
|
|
|
|
}
|
|
try
|
|
{
|
|
|
|
if (feelist != null && feelist.Count != 0)
|
|
{
|
|
dbcon.Open();
|
|
foreach (var fee in feelist)
|
|
{
|
|
sql = "INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME,CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY,";
|
|
sql = sql + "EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT,CARGO_GID,";
|
|
sql = sql + "TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,ISINVOICE,INPUTMODE,LOCALCURR,MANAGER,ISACC,FEEDESCRIPTION,DELIVERYNO,SETTLEMENT,INVOICE,ORDERAMOUNT,ORDERINVOICE,ORDERSETTLEMENT,ORDERINVSETTLEMENT)";
|
|
sql = sql + "VALUES ";
|
|
sql = sql + "('" + Guid.NewGuid().ToString() + "','" + fee.BSNO + "',2,'" + fee.FeeName + "','船公司','" + fee.CustomerName + "','" + fee.Unit + "'";
|
|
sql = sql + "," + fee.UnitPrice + "," + fee.Quantity + "," + fee.Amount + ",'" + fee.Currency + "'," + fee.ExChangerate + ",'','',0";
|
|
sql = sql + ",'" + ENTEROPERATOR + "',GETDATE(),0,0,10," + FEESTATUS + ",'',''";
|
|
sql = sql + ",0," + fee.Amount + ",0,0," + fee.UnitPrice + ",'" + ENTEROPERATOR + "',GETDATE(),'',0,0,'COSCO账单回写','RMB','',0,'" + fee.FeeEName + "'";
|
|
sql = sql + ",'" + fee.FA_ID + "',0,0,0,0,0,0)";
|
|
// log.Debug($"更新语句:{sql}");
|
|
SqlCommand cmd2 = new SqlCommand(sql, dbcon);
|
|
cmd2.ExecuteNonQuery();
|
|
|
|
}
|
|
dbcon.Close();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug($"插入费用出错:{ex.Message+sql}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
log.Debug($"数据返回错误:{rtn}");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.Message);
|
|
log.Error(ex.StackTrace);
|
|
}
|
|
}
|
|
|
|
static public D7OPSEAE GETBSNO(string MBLNO, SqlConnection dbcon,string BsSql)
|
|
{
|
|
var OPSEAE = new D7OPSEAE();
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT BSNO,BSSTATUS,FEESTATUS,ETD from op_seae where BSNO='" + MBLNO + "' and ISNULL(ISCANCEL,'')<>'1'");
|
|
if (!string.IsNullOrEmpty(BsSql))
|
|
strSql.Append(" and "+BsSql);
|
|
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)
|
|
{
|
|
OPSEAE.BSNO = row["BSNO"].ToString();
|
|
OPSEAE.FEESTATUS = Convert.ToBoolean(row["FEESTATUS"].ToString());
|
|
OPSEAE.BSSTATUS = Convert.ToBoolean(row["BSSTATUS"].ToString());
|
|
OPSEAE.ETD = Convert.ToString(row["ETD"].ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return OPSEAE;
|
|
}
|
|
|
|
static public bool GETINVNOISUSE(string BSNO,string INVNO, SqlConnection dbcon)
|
|
{
|
|
var result = false;
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT COUNT(1) CT from ch_fee where BSNO='" + BSNO + "' AND DELIVERYNO='" + INVNO + "'");
|
|
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
|
|
DataTable table = new DataTable();
|
|
adapter.Fill(table);
|
|
|
|
if (table.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in table.Rows)
|
|
{
|
|
if (Convert.ToInt32(row["CT"].ToString()) != 0)
|
|
result = true;
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
static public List<CodeFeeTemplateDetailAuto> GetFeeTemplate(string FA_ID, SqlConnection dbcon)
|
|
{
|
|
|
|
var headList = new List<CodeFeeTemplateDetailAuto>();
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT GID,TEMPLATEID,FEENAME,CUSTOMERNAME,CLIENT,UNIT");
|
|
strSql.Append(",CURRENCY,UNITPRICE,REMARK,SORT,CREATEUSER,CREATETIME,EXCHANGERATE,ISCTN,TAXRATE,TAXUNITPRICE,TAX,ACCTAXRATE");
|
|
strSql.Append(",(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=96201 and EnumValueID=code_fee_templatedetail_auto.CLIENT) as CLIENTREF");
|
|
strSql.Append(",(case ISCTN when 1 then '是' else '否' end) as ISCTNREF,ISINVOICE,ISADVANCEDPAY,FEEFRT,SALECORP,FEEDESCRIPTION,UNITPRICEDESCRPTION ");
|
|
strSql.Append(" from code_fee_templatedetail_auto WHERE CUSTOMERNAME='" + FA_ID + "'");
|
|
strSql.Append(" order by SORT ");
|
|
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
|
|
DataTable table = new DataTable();
|
|
adapter.Fill(table);
|
|
|
|
if (table.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in table.Rows)
|
|
{
|
|
var data = new CodeFeeTemplateDetailAuto();
|
|
data.GID = Convert.ToString(row["GID"]);
|
|
data.TEMPLATEID = Convert.ToString(row["TEMPLATEID"]);
|
|
if (row["UNITPRICE"] != DBNull.Value)
|
|
data.UNITPRICE = Convert.ToDecimal(row["UNITPRICE"]);
|
|
if (row["EXCHANGERATE"] != DBNull.Value)
|
|
data.EXCHANGERATE = Convert.ToDecimal(row["EXCHANGERATE"]);
|
|
if (row["TAXRATE"] != DBNull.Value)
|
|
data.TAXRATE = Convert.ToDecimal(row["TAXRATE"]);
|
|
if (row["TAX"] != DBNull.Value)
|
|
data.TAX = Convert.ToDecimal(row["TAX"]);
|
|
data.FEENAME = Convert.ToString(row["FEENAME"]);
|
|
data.FEEDESCRIPTION = Convert.ToString(row["FEEDESCRIPTION"]);
|
|
data.CUSTOMERNAME = Convert.ToString(row["CUSTOMERNAME"]);
|
|
if (row["CLIENT"] != DBNull.Value)
|
|
data.CLIENT = Convert.ToString(row["CLIENT"]);
|
|
data.CLIENTREF = Convert.ToString(row["CLIENTREF"]);
|
|
data.UNIT = Convert.ToString(row["UNIT"]);
|
|
data.CURRENCY = Convert.ToString(row["CURRENCY"]);
|
|
data.REMARK = Convert.ToString(row["REMARK"]);
|
|
if (row["SORT"] != DBNull.Value)
|
|
data.SORT = Convert.ToInt16(row["SORT"]);
|
|
data.FEEFRT = Convert.ToString(row["FEEFRT"]);
|
|
data.CREATEUSER = Convert.ToString(row["CREATEUSER"]);
|
|
data.CREATETIME = Convert.ToString(row["CREATETIME"]);
|
|
if (row["ISCTN"] != DBNull.Value)
|
|
data.ISCTN = Convert.ToBoolean(row["ISCTN"]);
|
|
data.ISCTNREF = Convert.ToString(row["ISCTNREF"]);
|
|
if (row["ISINVOICE"] != DBNull.Value)
|
|
data.ISINVOICE = Convert.ToBoolean(row["ISINVOICE"]);
|
|
if (row["ISADVANCEDPAY"] != DBNull.Value)
|
|
data.ISADVANCEDPAY = Convert.ToBoolean(row["ISADVANCEDPAY"]);
|
|
data.SALECORP = Convert.ToString(row["SALECORP"]);
|
|
if (row["TAXUNITPRICE"] != DBNull.Value)
|
|
data.TAXUNITPRICE = Convert.ToDecimal(row["TAXUNITPRICE"]);
|
|
if (row["ACCTAXRATE"] != DBNull.Value)
|
|
data.ACCTAXRATE = Convert.ToDecimal(row["ACCTAXRATE"]);
|
|
data.UNITPRICEDESCRPTION = Convert.ToString(row["UNITPRICEDESCRPTION"]);
|
|
headList.Add(data);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
return headList;
|
|
}
|
|
|
|
static public List<MsFeeUnitD7> GetFeeUnit(string bsno, SqlConnection dbcon)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
|
|
if (!string.IsNullOrEmpty(bsno))
|
|
{
|
|
strSql.Append("SELECT PKGS,KGS,CBM,KGS AS NETWEIGHT,");
|
|
strSql.Append("'' as SIZE,'' AS CTN,0 AS CTNNUM,0 AS TEU,'' AS CTNALL");
|
|
strSql.Append(" from op_seae ");
|
|
strSql.Append(" where bsno='" + bsno + "'");
|
|
strSql.Append(" union ");
|
|
strSql.Append("SELECT 0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,");
|
|
strSql.Append("P.SIZE,P.CTN,SUM(P.CTNNUM) AS CTNNUM,SUM(P.TEU) AS TEU,P.CTNALL");
|
|
strSql.Append(" from OP_CTN P ");
|
|
strSql.Append(" where p.bsno='" + bsno + "'");
|
|
strSql.Append(" GROUP BY P.SIZE,P.CTN,P.CTNALL order by PKGS desc");
|
|
}
|
|
else
|
|
{
|
|
strSql.Append("SELECT top 1 1 PKGS,0 KGS,0 CBM,0 AS NETWEIGHT,");
|
|
strSql.Append("'' as SIZE,'' AS CTN,0 AS CTNNUM,0 AS TEU,'' AS CTNALL");
|
|
strSql.Append(" from op_seae ");
|
|
strSql.Append(" union ");
|
|
strSql.Append("SELECT distinct 0 AS PKGS,0 AS KGS,0 AS CBM,0 AS NETWEIGHT,");
|
|
strSql.Append("P.SIZE,P.CTN,0 AS CTNNUM,0 AS TEU,P.CTNALL");
|
|
strSql.Append(" from OP_CTN P ");
|
|
|
|
|
|
}
|
|
return SetSeaeCtnUnitData(strSql, dbcon);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static List<MsFeeUnitD7> SetSeaeCtnUnitData(StringBuilder strSql,SqlConnection dbcon)
|
|
{
|
|
var bodyList = new List<MsFeeUnitD7>();
|
|
decimal TEUNUM;
|
|
TEUNUM = 0;
|
|
decimal PKGS;
|
|
PKGS = 0;
|
|
decimal KGS;
|
|
KGS = 0;
|
|
decimal CBM;
|
|
CBM = 0;
|
|
decimal NETWEIGHT = 0;
|
|
decimal CTNNUM;
|
|
CTNNUM = 0;
|
|
|
|
int isfirst = 0;
|
|
|
|
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
|
|
DataTable table = new DataTable();
|
|
adapter.Fill(table);
|
|
if (table.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in table.Rows)
|
|
{
|
|
#region Set DB data to Object
|
|
if (isfirst == 0)
|
|
{
|
|
var data = new MsFeeUnitD7();
|
|
data.SUNIT = "P-单票";
|
|
data.UNIT = "单票";
|
|
data.QUANTITY = 1;
|
|
data.ISCTN = false;
|
|
bodyList.Add(data);
|
|
if (row["PKGS"] != DBNull.Value)
|
|
PKGS = Convert.ToDecimal(row["PKGS"]);
|
|
if (row["KGS"] != DBNull.Value)
|
|
KGS = Convert.ToDecimal(row["KGS"]);
|
|
if (row["CBM"] != DBNull.Value)
|
|
CBM = Convert.ToDecimal(row["CBM"]);
|
|
if (row["NETWEIGHT"] != DBNull.Value)
|
|
NETWEIGHT = Convert.ToDecimal(row["NETWEIGHT"]);
|
|
var kgsdata = new MsFeeUnitD7();
|
|
kgsdata.SUNIT = "Z-重量";
|
|
kgsdata.UNIT = "重量";
|
|
kgsdata.QUANTITY = KGS;
|
|
kgsdata.ISCTN = false;
|
|
bodyList.Add(kgsdata);
|
|
var cbmdata = new MsFeeUnitD7();
|
|
cbmdata.SUNIT = "C-尺码";
|
|
cbmdata.UNIT = "尺码";
|
|
cbmdata.QUANTITY = CBM;
|
|
cbmdata.ISCTN = false;
|
|
bodyList.Add(cbmdata);
|
|
var pkgsdata = new MsFeeUnitD7();
|
|
pkgsdata.SUNIT = "J-件数";
|
|
pkgsdata.UNIT = "件数";
|
|
pkgsdata.QUANTITY = PKGS;
|
|
pkgsdata.ISCTN = false;
|
|
bodyList.Add(pkgsdata);
|
|
|
|
var netkgsdata = new MsFeeUnitD7();
|
|
netkgsdata.SUNIT = "N-净重";
|
|
netkgsdata.UNIT = "净重";
|
|
netkgsdata.QUANTITY = NETWEIGHT;
|
|
netkgsdata.ISCTN = false;
|
|
bodyList.Add(netkgsdata);
|
|
|
|
var Bdata = new MsFeeUnitD7();
|
|
Bdata.SUNIT = "B-BILL";
|
|
Bdata.UNIT = "BILL";
|
|
Bdata.QUANTITY = 1;
|
|
Bdata.ISCTN = false;
|
|
bodyList.Add(Bdata);
|
|
|
|
var ton = KGS / 1000;
|
|
if (ton > CBM)
|
|
{
|
|
var jfd = Math.Round(KGS / 1000, 3, MidpointRounding.AwayFromZero);
|
|
if (jfd < 1) jfd = 1;
|
|
var feetondata = new MsFeeUnitD7();
|
|
feetondata.SUNIT = "JF-计费吨";
|
|
feetondata.UNIT = "计费吨";
|
|
feetondata.QUANTITY = jfd;
|
|
feetondata.ISCTN = false;
|
|
bodyList.Add(feetondata);
|
|
}
|
|
else
|
|
{
|
|
var jfd = CBM;
|
|
if (jfd < 1) jfd = 1;
|
|
var feetondata = new MsFeeUnitD7();
|
|
feetondata.SUNIT = "JF-计费吨";
|
|
feetondata.UNIT = "计费吨";
|
|
feetondata.QUANTITY = jfd;
|
|
feetondata.ISCTN = false;
|
|
bodyList.Add(feetondata);
|
|
}
|
|
var jzton = Math.Round(NETWEIGHT / 1000, 3, MidpointRounding.AwayFromZero);
|
|
var feejztondata = new MsFeeUnitD7();
|
|
feejztondata.SUNIT = "JZD-净重吨";
|
|
feejztondata.UNIT = "净重吨";
|
|
feejztondata.QUANTITY = jzton;
|
|
feejztondata.ISCTN = false;
|
|
bodyList.Add(feejztondata);
|
|
|
|
}
|
|
if (Convert.ToString(row["CTNALL"]) != "")
|
|
{
|
|
var ctndata = new MsFeeUnitD7();
|
|
ctndata.SUNIT = Convert.ToString(row["CTNALL"]);
|
|
ctndata.UNIT = Convert.ToString(row["CTNALL"]);
|
|
if (row["CTNNUM"] != DBNull.Value)
|
|
ctndata.QUANTITY = Convert.ToDecimal(row["CTNNUM"]);
|
|
CTNNUM = CTNNUM + ctndata.QUANTITY;
|
|
if (row["TEU"] != DBNull.Value)
|
|
TEUNUM = TEUNUM + Convert.ToDecimal(row["TEU"]);
|
|
ctndata.ISCTN = true;
|
|
bodyList.Add(ctndata);
|
|
}
|
|
isfirst = isfirst + 1;
|
|
#endregion
|
|
}
|
|
var teudata = new MsFeeUnitD7();
|
|
teudata.SUNIT = "TEU";
|
|
teudata.UNIT = "TEU";
|
|
teudata.QUANTITY = TEUNUM;
|
|
teudata.ISCTN = false;
|
|
bodyList.Add(teudata);
|
|
var ctnalldata = new MsFeeUnitD7();
|
|
ctnalldata.SUNIT = "自然箱";
|
|
ctnalldata.UNIT = "自然箱";
|
|
ctnalldata.QUANTITY = CTNNUM;
|
|
ctnalldata.ISCTN = false;
|
|
bodyList.Add(ctnalldata);
|
|
var data9 = new MsFeeUnitD7();
|
|
data9.SUNIT = "T-天";
|
|
data9.UNIT = "天";
|
|
data9.QUANTITY = 0;
|
|
data9.ISCTN = false;
|
|
bodyList.Add(data9);
|
|
var data10 = new MsFeeUnitD7();
|
|
data10.SUNIT = "G-个";
|
|
data10.UNIT = "个";
|
|
data10.QUANTITY = 0;
|
|
data10.ISCTN = false;
|
|
bodyList.Add(data10);
|
|
var data11 = new MsFeeUnitD7();
|
|
data11.SUNIT = "S-小时";
|
|
data11.UNIT = "小时";
|
|
data11.QUANTITY = 0;
|
|
data11.ISCTN = false;
|
|
bodyList.Add(data11);
|
|
var data12 = new MsFeeUnitD7();
|
|
data12.SUNIT = "S-票";
|
|
data12.UNIT = "票";
|
|
data12.QUANTITY = 0;
|
|
data12.ISCTN = false;
|
|
bodyList.Add(data12);
|
|
var data13 = new MsFeeUnitD7();
|
|
data13.SUNIT = "D-吨";
|
|
data13.UNIT = "吨";
|
|
data13.QUANTITY = 0;
|
|
data13.ISCTN = false;
|
|
bodyList.Add(data13);
|
|
|
|
|
|
}
|
|
return bodyList;
|
|
}
|
|
|
|
|
|
static public string GETUNIT(string UNIT,string CTNALL)
|
|
{
|
|
var BSNO = UNIT;
|
|
if (BSNO == "FIX") BSNO = "单票";
|
|
if (BSNO == "UNI") BSNO = CTNALL;
|
|
|
|
return BSNO.Replace("'", "''");
|
|
}
|
|
|
|
static public string GETFEENAME(string FEECODE, SqlConnection dbcon, string curr)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("select top 1 [FEENAME] from code_fee_edi where [FEEENAME]='" + FEECODE + "'");
|
|
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
|
|
DataTable table = new DataTable();
|
|
adapter.Fill(table);
|
|
var FEENAME = "";
|
|
if (table.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in table.Rows)
|
|
{
|
|
FEENAME = row["FEENAME"].ToString();
|
|
|
|
}
|
|
|
|
}
|
|
if (string.IsNullOrEmpty(FEENAME))
|
|
{
|
|
//if (curr == "USD")
|
|
//{
|
|
// FEENAME = "海运费";
|
|
//} else
|
|
FEENAME ="";
|
|
}
|
|
return FEENAME;
|
|
}
|
|
|
|
|
|
|
|
static public List<jffee> GetFeeList(string constr, SqlConnection dbcon) {
|
|
var feelist = new List<jffee>();
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("select GID,BSNO from ch_fee where " + constr);
|
|
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
|
|
DataTable table = new DataTable();
|
|
adapter.Fill(table);
|
|
if (table.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in table.Rows)
|
|
{
|
|
var fee = new jffee();
|
|
fee.ch_id = row["GID"].ToString();
|
|
fee.bsno = row["BSNO"].ToString();
|
|
feelist.Add(fee);
|
|
}
|
|
|
|
}
|
|
|
|
return feelist;
|
|
}
|
|
|
|
|
|
static public decimal GetUsdExrate(SqlConnection dbcon,string curr,string ETD)
|
|
{
|
|
decimal usdexrate = 0;
|
|
var startdate = ETD;
|
|
if (string.IsNullOrEmpty(startdate)) startdate = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
if (curr == "USD")
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("select VALUE from currency_exchange where STARTTIME<='"+ startdate + "' and ENDTIME>='"+ startdate + "'");
|
|
strSql.Append(" and CURRENCYID in (select GID from code_currency where CODENAME='"+curr+"') ");
|
|
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
|
|
DataTable table = new DataTable();
|
|
adapter.Fill(table);
|
|
if (table.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in table.Rows)
|
|
{
|
|
usdexrate = Convert.ToDecimal(row["VALUE"].ToString());
|
|
}
|
|
}
|
|
}
|
|
if (usdexrate == 0)
|
|
{
|
|
SqlDataAdapter adapter2 = new SqlDataAdapter("select DEFAULTRATE from code_currency where CODENAME='" + curr + "'", dbcon);
|
|
DataTable table2 = new DataTable();
|
|
adapter2.Fill(table2);
|
|
if (table2.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow row in table2.Rows)
|
|
{
|
|
usdexrate = Convert.ToDecimal(row["DEFAULTRATE"].ToString());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return usdexrate;
|
|
}
|
|
|
|
}
|
|
|
|
public class JsonCoscoFeeSend
|
|
{
|
|
|
|
public string userKey { get; set; }
|
|
public string userSecret { get; set; }
|
|
public string webAccount { get; set; }
|
|
public string webPassword { get; set; }
|
|
public string bno { get; set; }
|
|
public string companyCode { get; set; }
|
|
public bool summaryFlag { get; set; }
|
|
}
|
|
|
|
public class JsonCoscoFeeRec
|
|
{
|
|
|
|
public string bno { get; set; }
|
|
public string companyName { get; set; }
|
|
public string feeName { get; set; }
|
|
public string currencyUnit { get; set; }
|
|
public string totalAmount { get; set; }
|
|
public string notInvoicedAmount { get; set; }
|
|
public string notPaymentAmount { get; set; }
|
|
public string tradeType { get; set; }
|
|
public string departureDate { get; set; }
|
|
public string feeConfirmDate { get; set; }
|
|
public string itemUuid { get; set; }
|
|
}
|
|
public class JsonCoscoRec
|
|
{
|
|
|
|
public string code { get; set; }
|
|
public string msg { get; set; }
|
|
public List<JsonCoscoFeeRec> data { get; set; }
|
|
|
|
}
|
|
|
|
//public class JsonFeeResponse
|
|
//{
|
|
// public string ReceiveId { get; set; }
|
|
// public string MBLNO { get; set; }
|
|
// public string INVOICE_NO { get; set; }
|
|
// public string CANCEL_NO { get; set; }
|
|
// public string TOTAL_AMOUNT { get; set; }
|
|
// public List<DJYFEE> DATA { get; set; }
|
|
//}
|
|
//public class DJYFEE
|
|
//{
|
|
// public string FEECODE { get; set; }
|
|
// public string AMOUNT { get; set; }
|
|
// public string AMOUNT_USD { get; set; }
|
|
// public string CURRENCY { get; set; }
|
|
// public string CTNALL { get; set; }
|
|
// public string TAX { get; set; }
|
|
// public string COUNT { get; set; }
|
|
// public string UNIT { get; set; }
|
|
// public string RATE { get; set; }
|
|
|
|
|
|
//}
|
|
|
|
|
|
//public class feeback
|
|
//{
|
|
// public string ReceiveId { get; set; }
|
|
// public bool Success { get; set; }
|
|
// public string Reason { get; set; }
|
|
|
|
//}
|
|
//public class jffee
|
|
//{
|
|
// public string ch_id { get; set; }
|
|
// public string bsno { get; set; }
|
|
|
|
//}
|
|
|
|
|
|
}
|