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

470 lines
23 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"));
1 year ago
var yesterday = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd");
1 year ago
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 + "金额:"+ (Convert.ToDecimal(returndata.ydFee)+Convert.ToDecimal(returndata.secondPrintFee) + Convert.ToDecimal(returndata.fee)).ToString() + ",请知悉,谢谢", 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();
1 year ago
strSql.Append("SELECT TOP 1 编号 BSNO,委托单位 CUSTOMERNAME from t_op_seae where 主提单号 like '" + MBLNO + "%'");
1 year ago
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; }
9 months ago
public List<JsonYtFee> message { get; set; }=new List<JsonYtFee>();
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; }
9 months ago
public string barcode { get; set; }
4 months ago
public string company { get; set; }
9 months ago
}
public class YTSumFee
{
public string MBLNO { get; set; }
public string BSNO { get; set; }
public int fee_count { get; set; } = 0;
public decimal fee_amount { get; set; } = 0;
public int ydFee1_count { get; set; } = 0;
public decimal ydFee1_amount { get; set; } = 0;
public int ydFee2_count { get; set; } = 0;
public decimal ydFee2_amount { get; set; } = 0;
public int secondPrintFee_count { get; set; } = 0;
public decimal secondPrintFee_amount { get; set; } = 0;
9 months ago
public string CTN20 { get; set; }//业务中的20尺柜
public string CTN40 { get; set; }//业务中的20尺柜
public string CTN
{
get
{
if (!string.IsNullOrWhiteSpace(CTN40))
{
return CTN40;
}
else
{
return CTN20;
}
}
}
public string ENTEROPERATOR { get; set; }//费用录入人
9 months ago
public string mailtitle { get; set; }//用于发邮件
public string mailbody { get; set; }//用于发邮件
9 months ago
public YTSumFee() { }
public YTSumFee(JsonYtFee addrec) {
//this = AutoMapperHelper.MapTo<JsonYtFee, YTSumFee>(addrec);
MBLNO = addrec.bookingno;
if (!string.IsNullOrWhiteSpace(addrec.fee))
{
fee_count = 1;
fee_amount = Convert.ToDecimal(addrec.fee);
}
if (!string.IsNullOrWhiteSpace(addrec.ydFee))
{
var _amount= Convert.ToDecimal(addrec.ydFee);
if (_amount == 250) {
ydFee1_count = 1;
ydFee1_amount = _amount;
}
if (_amount == 350)
{
ydFee2_count = 1;
ydFee2_amount = _amount;
}
}
if (!string.IsNullOrWhiteSpace(addrec.secondPrintFee))
{
secondPrintFee_count = 1;
secondPrintFee_amount = Convert.ToDecimal(addrec.secondPrintFee);
}
}
public void addfee(JsonYtFee addrec)
{
9 months ago
if (MBLNO == addrec.bookingno)
9 months ago
{
var newrec = new YTSumFee(addrec);
fee_count += newrec.fee_count;
fee_amount += newrec.fee_amount;
ydFee1_count += newrec.ydFee1_count;
ydFee1_amount += newrec.ydFee1_amount;
ydFee2_count += newrec.ydFee2_count;
ydFee2_amount += newrec.ydFee2_amount;
secondPrintFee_count += newrec.secondPrintFee_count;
secondPrintFee_amount += newrec.secondPrintFee_amount;
}
}
1 year ago
}
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
}
}