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/JobYt2D6Fee.cs

373 lines
20 KiB
C#

1 year 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 JobYtD6Fee : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobYtD6Fee));
//private const string CfgFileName = "starttime.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("YTReqUrl");
string YTUserName = context.JobDetail.JobDataMap.GetString("YTUserName");
string YTPassWord = context.JobDetail.JobDataMap.GetString("YTPassWord");
string CustName = context.JobDetail.JobDataMap.GetString("CustName");
string CustPsw = context.JobDetail.JobDataMap.GetString("CustPsw");
int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
var yesterday = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
JsonYtSend reqObj = new JsonYtSend();
reqObj.custname = CustName;
reqObj.custpsw= CustPsw;
reqObj.username = YTUserName;
reqObj.password = YTPassWord;
reqObj.start_time = yesterday;
reqObj.end_time= yesterday;
var sendstr = JsonConvert.SerializeObject(reqObj);
log.Debug($"发送包:{sendstr}");
//发送请求数据
string rtn = WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000);
log.Debug($"数据返回:{rtn}");
1 year ago
//var objRtn = JsonConvert.DeserializeAnonymousType(rtn, new { status = "", message = "" });
var objRtn = JsonConvert.DeserializeObject<josnYtData>(rtn);
1 year ago
if (objRtn.status == "1")
{
1 year ago
//var parseJsonObj = JsonConvert.DeserializeObject<List<JsonYtFee>>(objRtn.message);
1 year ago
try
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
1 year ago
var FEELIST = new List<D6BS>();
1 year ago
dbcon.Open();
1 year ago
foreach (var returndata in objRtn.message)
1 year ago
{
if (returndata.fee == "" || returndata.fee == null) returndata.fee = "0";
if (returndata.ydFee == "" || returndata.ydFee == null) returndata.ydFee = "0";
if (returndata.secondPrintFee == "" || returndata.secondPrintFee == null) returndata.secondPrintFee = "0";
var D6BS = GETD6BS(returndata.bookingno, dbcon);
string sql = " INSERT INTO t_op_ytfee_log([bsno],[vessel],[voyage],[bookingno],[ctn_type],[ctn_no],[yard],[operatetime],[operatetype]";
sql = sql + ",[printType],[fee],[ydFee],[secondPrintFee],[applicant_code]) values ('" + D6BS.BSNO + "','" + returndata.vessel + "'";
sql = sql + ",'" + returndata.voyage + "','" + returndata.bookingno + "','" + returndata.ctn_type + "','" + returndata.ctn_no + "','" + returndata.yard + "'";
1 year ago
sql = sql + ",'" + returndata.operatetime + "','" + returndata.operatetype + "','" + returndata.printType + "','" + returndata.fee
1 year ago
+ "','" + returndata.ydFee + "','" + returndata.secondPrintFee + "','" + returndata.applicant_code + "')";
SqlCommand cmd = new SqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
1 year ago
if (!string.IsNullOrEmpty(D6BS.BSNO))
{
decimal txxpf = 0;
decimal dxf = 0;
if (Convert.ToDecimal(returndata.ydFee) != 0)
{
dxf = Convert.ToDecimal(returndata.ydFee);
var fee = FEELIST.Find(x => x.BSNO == D6BS.BSNO && x.FEETYPE == "调箱费");
if (fee != null)
{
fee.AMOUNT = fee.AMOUNT + dxf;
fee.QUANTITY = fee.QUANTITY + 1;
}
else
{
var newfee = new D6BS();
newfee.BSNO = D6BS.BSNO;
newfee.CUSTOMERNAME = D6BS.CUSTOMERNAME;
newfee.AMOUNT = dxf;
newfee.FEETYPE = "调箱费";
newfee.QUANTITY = 1;
FEELIST.Add(newfee);
}
}
1 year ago
if (Convert.ToDecimal(returndata.fee) != 0)
{
1 year ago
txxpf = Convert.ToDecimal(returndata.fee);
var fee = FEELIST.Find(x => x.BSNO == D6BS.BSNO && x.FEETYPE == "提箱小票费"&& x.ISDX ==false);
if (fee != null)
{
fee.AMOUNT = fee.AMOUNT + txxpf;
fee.QUANTITY = fee.QUANTITY +1;
}
else
{
var newfee = new D6BS();
newfee.BSNO = D6BS.BSNO;
newfee.CUSTOMERNAME = D6BS.CUSTOMERNAME;
newfee.AMOUNT = txxpf;
newfee.FEETYPE = "提箱小票费";
newfee.QUANTITY = 1;
newfee.ISDX = false;
FEELIST.Add(newfee);
}
}
if (Convert.ToDecimal(returndata.secondPrintFee) != 0)
{
txxpf = Convert.ToDecimal(returndata.secondPrintFee);
var fee = FEELIST.Find(x => x.BSNO == D6BS.BSNO && x.FEETYPE == "提箱小票费" && x.ISDX == true);
if (fee != null)
{
fee.AMOUNT = fee.AMOUNT + txxpf;
fee.QUANTITY = fee.QUANTITY + 1;
}
else
{
var newfee = new D6BS();
newfee.BSNO = D6BS.BSNO;
newfee.CUSTOMERNAME = D6BS.CUSTOMERNAME;
newfee.AMOUNT = txxpf;
newfee.FEETYPE = "提箱小票费";
newfee.ISDX = true;
newfee.QUANTITY = 1;
FEELIST.Add(newfee);
}
}
1 year ago
1 year ago
}
1 year ago
1 year ago
var headstr = "";
if (returndata.bookingno.Length > 3)
{
headstr = returndata.bookingno.Substring(0, 3);
}
1 year ago
1 year ago
if (string.IsNullOrEmpty(D6BS.BSNO) && (headstr == "QGD" || headstr == "AMQ" || headstr == "AMG" || headstr == "AYQ"))
{
var DELETBS = GETDELETED6BS(returndata.bookingno, dbcon);
1 year ago
1 year ago
SaveMail(dbcon, "CMABKG@SDSMARTLOGISTICS.COM", returndata.bookingno+ DELETBS .CUSTOMERNAME+ "此单号已退仓,但是系统检测到打印过小票" + returndata.printType + ",请知悉,谢谢", returndata.bookingno + "此单号已退仓,但是系统检测到打印过小票" + returndata.printType + ",请知悉,谢谢", "1");
1 year ago
1 year ago
}
1 year ago
1 year ago
}
if (FEELIST != null && FEELIST.Count!=0) {
foreach(var FEE in FEELIST)
{
var DRAMOUNT = FEE.AMOUNT;
var CRCUST = "C亿通付费";
if (FEE.FEETYPE == "提箱小票费" && FEE.ISDX == false)
1 year ago
{
1 year ago
DRAMOUNT = FEE.AMOUNT * 5;
CRCUST = "亿通(付费)";
}
1 year ago
string Feesql = "INSERT INTO [t_ch_fee] ([类型],[费用状态],[编号],[费用名称],[结算单位],[客户名称],[标准]";
Feesql = Feesql + ",[单价],[数量],[金额],[币别],[汇率],[备注],[结算金额],[开票金额]";
Feesql = Feesql + ",[录入人],[录入日期],[是否对帐],[顺序],[冲抵金额]";
Feesql = Feesql + ",[机密],[是否垫付],[申请金额],[不开发票],[费用英文名称]";
Feesql = Feesql + ",[申请开票],[提交],[不含税价],[税率],[税额],PROJECTFEEID) VALUES ";
1 year ago
Feesql = Feesql + "('收','录入状态','" + FEE.BSNO + "','"+FEE.FEETYPE+"','委托单位','" + FEE.CUSTOMERNAME + "','单票'";
Feesql = Feesql + ","+ DRAMOUNT.ToString() + ",1," + DRAMOUNT.ToString() + ",'RMB',1,'" + FEE.QUANTITY.ToString() + "次',0,0";
1 year ago
Feesql = Feesql + ",'DEMO-SA',GETDATE(),0,100,0";
Feesql = Feesql + ",0,0,0,0,''";
1 year ago
Feesql = Feesql + ",0,0," + DRAMOUNT.ToString() + ",0,0,'易通小票费')";
1 year ago
Feesql = Feesql + " INSERT INTO [t_ch_fee] ([类型],[费用状态],[编号],[费用名称],[结算单位],[客户名称],[标准]";
Feesql = Feesql + ",[单价],[数量],[金额],[币别],[汇率],[备注],[结算金额],[开票金额]";
Feesql = Feesql + ",[录入人],[录入日期],[是否对帐],[顺序],[冲抵金额]";
Feesql = Feesql + ",[机密],[是否垫付],[申请金额],[不开发票],[费用英文名称]";
Feesql = Feesql + ",[申请开票],[提交],[不含税价],[税率],[税额],PROJECTFEEID) VALUES ";
1 year ago
Feesql = Feesql + "('付','审核通过','" + FEE.BSNO + "','"+ FEE.FEETYPE + "','代理','"+ CRCUST + "','单票'";
1 year ago
Feesql = Feesql + "," + FEE.AMOUNT.ToString() + ",1," + FEE.AMOUNT.ToString() + ",'RMB',1,'"+FEE.QUANTITY.ToString()+"次',0,0";
1 year ago
Feesql = Feesql + ",'DEMO-SA',GETDATE(),0,100,0";
Feesql = Feesql + ",0,0,0,0,''";
1 year ago
Feesql = Feesql + ",0,0," + FEE.AMOUNT.ToString() + ",0,0,'易通小票费')";
1 year ago
log.Debug($"费用语句-{Feesql}");
1 year ago
//dbcon.Open();
1 year ago
SqlCommand Feecmd = new SqlCommand(Feesql, dbcon);
Feecmd.ExecuteNonQuery();
1 year ago
//dbcon.Close();
//if (Convert.ToDecimal(returndata.ydFee) != 0)
//{
// string Feesql = "INSERT INTO [t_ch_fee] ([类型],[费用状态],[编号],[费用名称],[结算单位],[客户名称],[标准]";
// Feesql = Feesql + ",[单价],[数量],[金额],[币别],[汇率],[备注],[结算金额],[开票金额]";
// Feesql = Feesql + ",[录入人],[录入日期],[是否对帐],[顺序],[冲抵金额]";
// Feesql = Feesql + ",[机密],[是否垫付],[申请金额],[不开发票],[费用英文名称]";
// Feesql = Feesql + ",[申请开票],[提交],[不含税价],[税率],[税额],PROJECTFEEID) VALUES ";
// Feesql = Feesql + "('收','审核通过','" + D6BS.BSNO + "','调箱费','委托单位','" + D6BS.CUSTOMERNAME + "','单票'";
// Feesql = Feesql + "," + returndata.ydFee + ",1," + returndata.ydFee + ",'RMB',1,'',0,0";
// Feesql = Feesql + ",'DEMO-SA',GETDATE(),0,100,0";
// Feesql = Feesql + ",0,0,0,0,''";
// Feesql = Feesql + ",0,0," + returndata.ydFee + ",0,0,'易通小票费')";
// Feesql = Feesql + " INSERT INTO [t_ch_fee] ([类型],[费用状态],[编号],[费用名称],[结算单位],[客户名称],[标准]";
// Feesql = Feesql + ",[单价],[数量],[金额],[币别],[汇率],[备注],[结算金额],[开票金额]";
// Feesql = Feesql + ",[录入人],[录入日期],[是否对帐],[顺序],[冲抵金额]";
// Feesql = Feesql + ",[机密],[是否垫付],[申请金额],[不开发票],[费用英文名称]";
// Feesql = Feesql + ",[申请开票],[提交],[不含税价],[税率],[税额],PROJECTFEEID) VALUES ";
// Feesql = Feesql + "('付','审核通过','" + D6BS.BSNO + "','提箱小票费','代理','C亿通付费','单票'";
// Feesql = Feesql + "," + returndata.ydFee + ",1," + returndata.ydFee + ",'RMB',1,'',0,0";
// Feesql = Feesql + ",'DEMO-SA',GETDATE(),0,100,0";
// Feesql = Feesql + ",0,0,0,0,''";
// Feesql = Feesql + ",0,0," + returndata.ydFee + ",0,0,'易通小票费')";
// log.Debug($"费用语句-{Feesql}");
// //dbcon.Open();
// SqlCommand Feecmd = new SqlCommand(Feesql, dbcon);
// Feecmd.ExecuteNonQuery();
// //dbcon.Close();
//}
1 year ago
}
1 year ago
}
1 year ago
dbcon.Close();
}
}
catch (Exception e) {
log.Debug($"记录插入错误:{e.Message}");
}
}
else {
log.Debug($"数据返回错误:{objRtn.message}");
}
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
public static int SaveMail(SqlConnection dbcon, string sendto, string title, string body, string smtpid)
{
var sqlstr = $" INSERT INTO [Mail_Send] ([GID],[SendTo],[Title],[Body],[SendStatus],[TryCount],[CreateTime],[SmtpConfig],[Sender],[ShowName]) select newid(),'{sendto}','{title}','{body.Replace("'", "''")}','Create',0,GETDATE(),'{smtpid}','','' ";
SqlCommand cmd = new SqlCommand(sqlstr, dbcon);
return cmd.ExecuteNonQuery();
}
static public D6BS GETD6BS(string MBLNO, SqlConnection dbcon)
{
var newbs = new D6BS();
var strSql = new StringBuilder();
strSql.Append("SELECT TOP 1 编号 BSNO,委托单位 CUSTOMERNAME from t_op_seae where 主提单号='" + 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)
{
newbs.BSNO = row["BSNO"].ToString();
newbs.CUSTOMERNAME = row["CUSTOMERNAME"].ToString();
}
}
1 year ago
return newbs;
}
static public D6BS GETDELETED6BS(string MBLNO, SqlConnection dbcon)
{
var newbs = new D6BS();
var strSql = new StringBuilder();
strSql.Append("SELECT TOP 1 删除人 CUSTOMERNAME from t_op_delete where 主提单号='" + 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)
{
newbs.CUSTOMERNAME = row["CUSTOMERNAME"].ToString();
}
}
1 year ago
return newbs;
}
}
public class JsonYtSend
{
public string custname { get; set; }
public string custpsw { get; set; }
public string username { get; set; }
public string password { get; set; }
public string start_time { get; set; }
public string end_time { get; set; }
}
1 year ago
public class josnYtData
{
public string status { get; set; }
public List<JsonYtFee> message { get; set; }
1 year ago
1 year ago
}
1 year ago
public class JsonYtFee
{
public string vessel { get; set; }
public string voyage { get; set; }
public string bookingno { get; set; }
public string ctn_type { get; set; }
public string ctn_no { get; set; }
public string yard { get; set; }
public string trans_port_code { get; set; }
public string operatetime { get; set; }
public string operatetype { get; set; }
public string printType { get; set; }
public string fee { get; set; }
public string ydFee { get; set; }
public string secondPrintFee { get; set; }
public string applicant_code { get; set; }
}
public class D6BS
{
public string BSNO { get; set; }
public string CUSTOMERNAME { get; set; }
1 year ago
public string FEETYPE { get; set; }
public bool ISDX { get; set; }
public decimal AMOUNT { get; set; }
public int QUANTITY { get; set; }
1 year ago
}
}