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

765 lines
42 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DSWeb.Common.DB;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Migrations;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Data.Entity;
using JobAutoCreateFee.Model;
using System.Runtime.Remoting;
namespace JobCreateFee
{
public class JobYtD7Fee : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobYtD7Fee));
//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"));
string YTD7Condition = context.JobDetail.JobDataMap.GetString("YTD7Condition");
string YTD7NoUseCORPID = context.JobDetail.JobDataMap.GetString("YTD7NoUseCORPID");
Database.SetInitializer<CommonDataContext>(null);
YTFEEHelper.feeName = context.JobDetail.JobDataMap.GetString("feeName");
YTFEEHelper.ydFeeName = context.JobDetail.JobDataMap.GetString("ydFeeName");
YTFEEHelper.secondPrintFeeName = context.JobDetail.JobDataMap.GetString("secondPrintFeeName");
YTFEEHelper.feeCustName = context.JobDetail.JobDataMap.GetString("feeCustName");
YTFEEHelper.CarrierCustName = context.JobDetail.JobDataMap.GetString("CarrierCustName");
YTFEEHelper.connStr = connStr;
YTFEEHelper. = context.JobDetail.JobDataMap.GetString("AlertMail");
int DAYS = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("DAYS"));
string ENTEROPERATOR = context.JobDetail.JobDataMap.GetString("ENTEROPERATOR");
var yesterday = DateTime.Now.AddDays(DAYS).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;
reqObj.company = "CMA_TAO";
//var testrtnobject = new josnYtData();
//testrtnobject.status = "1";
//var testfee = new JsonYtFee();
//testfee.applicant_code = "0005559535";
//testfee.barcode = "1079136935036731";
//testfee.bookingno = "I240369027";
//testfee.ctn_no = "CGMU5629072";
//testfee.ctn_type = "40RH";
//testfee.fee = "1.0";
//testfee.operatetime = "2024-03-19 16:02:28";
//testfee.operatetype = "打印通知单";
//testfee.printType = "纸面";
//testfee.trans_port_code = "PECLL";
//testfee.vessel = "CMA CGM IGUACU";
//testfee.voyage = "0MHIME";
//testfee.yard = "青岛港联欣国际物流有限公司";
//testrtnobject.message.Add(testfee);
//var rtn = JsonConvert.SerializeObject(testrtnobject);
var sendstr = JsonConvert.SerializeObject(reqObj);
log.Debug($"发送包{reqObj.company}{sendstr}");
//发送请求数据
string rtnStr_CMA_TAO = "{\"message\":\"未查询出数据\",\"status\":\"0\"}";
rtnStr_CMA_TAO=WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000);
log.Debug($"数据返回{reqObj.company}{rtnStr_CMA_TAO}");
//var objRtn = JsonConvert.DeserializeAnonymousType(rtn, new { status = "", message = "" });
reqObj.company = "CMA_DLC";
sendstr = JsonConvert.SerializeObject(reqObj);
log.Debug($"发送包{reqObj.company}{sendstr}");
string rtnStr_CMA_DLC = "{\"message\":\"未查询出数据\",\"status\":\"0\"}";
rtnStr_CMA_DLC=WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000);
log.Debug($"数据返回{reqObj.company}{rtnStr_CMA_DLC}");
reqObj.company = "CMA_TXG";
sendstr = JsonConvert.SerializeObject(reqObj);
log.Debug($"发送包{reqObj.company}{sendstr}");
string rtnStr_CMA_TXG = "{\"message\":\"未查询出数据\",\"status\":\"0\"}";
//"{\"message\":[{\"applicant_code\":\"hhcma\",\"barcode\":\"1056936938466968\",\"bookingno\":\"TJN0471222\",\"ctn_no\":\"TEMU0083340\",\"ctn_type\":\"20ST\",\"fee\":\"1.0\",\"operatetime\":\"2024-08-18 12:27:00\",\"operatetype\":\"打印通知单\",\"printType\":\"纸面\",\"secondPrintFee\":\"30.0\",\"trans_port_code\":\"MXZLO\",\"vessel\":\"GREGOS\",\"voyage\":\"0WU0VE\",\"yard\":\"克运物流\"},{\"applicant_code\":\"hhcma\",\"barcode\":\"1058836938466967\",\"bookingno\":\"TJN0471222\",\"ctn_no\":\"CMAU3066259\",\"ctn_type\":\"20ST\",\"fee\":\"1.0\",\"operatetime\":\"2024-08-18 12:27:00\",\"operatetype\":\"打印通知单\",\"printType\":\"纸面\",\"secondPrintFee\":\"30.0\",\"trans_port_code\":\"MXZLO\",\"vessel\":\"GREGOS\",\"voyage\":\"0WU0VE\",\"yard\":\"克运物流\"},{\"applicant_code\":\"hhcma\",\"barcode\":\"1084536938466966\",\"bookingno\":\"TJN0471222\",\"ctn_no\":\"TEMU5580118\",\"ctn_type\":\"20ST\",\"fee\":\"1.0\",\"operatetime\":\"2024-08-18 12:27:00\",\"operatetype\":\"打印通知单\",\"printType\":\"纸面\",\"secondPrintFee\":\"30.0\",\"trans_port_code\":\"MXZLO\",\"vessel\":\"GREGOS\",\"voyage\":\"0WU0VE\",\"yard\":\"克运物流\"},{\"applicant_code\":\"hhcma\",\"barcode\":\"1041136938466965\",\"bookingno\":\"TJN0471222\",\"ctn_no\":\"TCLU7442738\",\"ctn_type\":\"20ST\",\"fee\":\"1.0\",\"operatetime\":\"2024-08-18 12:27:00\",\"operatetype\":\"打印通知单\",\"printType\":\"纸面\",\"secondPrintFee\":\"30.0\",\"trans_port_code\":\"MXZLO\",\"vessel\":\"GREGOS\",\"voyage\":\"0WU0VE\",\"yard\":\"克运物流\"}],\"status\":\"1\"}";
/*
"\"{\"message\":[{ \"applicant_code\": \"0005559535\", \"barcode\": \"1037536938978644\", \"bookingno\": \"QGD1188350\", \"ctn_no\": \"XTCU3695596\", \"ctn_type\": \"40HC\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 19:51:52\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"secondPrintFee\": \"30.0\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"},{ \"applicant_code\": \"0005559535\", \"barcode\": \"1065536938978647\", \"bookingno\": \"QGD1188350\", \"ctn_type\": \"20ST\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 16:49:05\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"},{ \"applicant_code\": \"0005559535\", \"barcode\": \"1046236938978646\", \"bookingno\": \"QGD1188350\", \"ctn_type\": \"20ST\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 16:49:05\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"},{ \"applicant_code\": \"0005559535\", \"barcode\": \"1032736938978645\", \"bookingno\": \"QGD1188350\", \"ctn_type\": \"20ST\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 10:23:54\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"},{ \"applicant_code\": \"0005559535\", \"barcode\": \"1037536938978644\", \"bookingno\": \"QGD1188350\", \"ctn_no\": \"XTCU3695596\", \"ctn_type\": \"40HC\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 19:51:52\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"secondPrintFee\": \"30.0\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"},{ \"applicant_code\": \"0005559535\", \"barcode\": \"1065536938978647\", \"bookingno\": \"QGD1188350\", \"ctn_type\": \"20ST\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 16:49:05\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"}{ \"applicant_code\": \"0005559535\", \"barcode\": \"1046236938978646\", \"bookingno\": \"QGD1188350\", \"ctn_type\": \"20ST\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 16:49:05\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"},{ \"applicant_code\": \"0005559535\", \"barcode\": \"1032736938978645\", \"bookingno\": \"QGD1188350\", \"ctn_type\": \"20ST\", \"fee\": \"1.0\", \"operatetime\": \"2024-09-08 10:23:54\", \"operatetype\": \"打印通知单\", \"printType\": \"纸面\", \"trans_port_code\": \"PECLL\", \"vessel\": \"XIN HONG KONG\", \"voyage\": \"073E\", \"yard\": \"青岛港联捷国际物流有限公司\"},\"status\":\"1\"}";*/
rtnStr_CMA_TXG = WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000);
log.Debug($"数据返回{reqObj.company}{rtnStr_CMA_TXG}");
DealReturnJson(rtnStr_CMA_TAO,"TAO");
DealReturnJson(rtnStr_CMA_DLC,"DLC");
DealReturnJson(rtnStr_CMA_TXG,"TXG");
void DealReturnJson(string rtn,string PORT)
{
try
{
log.Debug($"开始解析:{rtn}");
try
{
var candeal = JsonConvert.DeserializeObject<josnYtData_State>(rtn);
if (candeal.status == "0")
{
log.Debug($"解析结束:status={candeal.status}:{candeal.message}");
var hp = new YTFEEHelper();
hp.SendAlarmMail($"{PORT}:当日没有数据", $"{PORT}:{candeal.message}");
return;
}
}
catch (Exception e) {
var hp = new YTFEEHelper();
hp.SendAlarmMail($"{PORT}:数据解析错误", $"{JsonConvert.SerializeObject(e)}");
log.Debug($"解析错误:{JsonConvert.SerializeObject(e)}");
}
var objRtn = JsonConvert.DeserializeObject<josnYtData>(rtn);
if (objRtn.status == "1")
{
//var parseJsonObj = JsonConvert.DeserializeObject<List<JsonYtFee>>(objRtn.message);
try
{
//1 记录进t_op_ytfee_log 表
//2 遍历信息,将同提单号的费用合起来
//3 遍历提单号,寻找业务,判断业务能否增加费用
//3.1 业务是否已退仓
//3.2 业务是否费用锁定
//3.3 业务会计期间是否已锁帐
//以上情况分别发送邮件提醒
//4 如能增加费用 则插入费用
using (SqlConnection dbcon = new SqlConnection(connStr))
{
var hp = new YTFEEHelper();
var FEELIST = new List<D7BS>();
dbcon.Open();
foreach (var returndata in objRtn.message)
{
//测试数据
//if (returndata.bookingno != "QGD0721089") continue;
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 D7BS = GETD7OPSEAEBS(returndata, YTD7Condition, 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 ('" + D7BS.BSNO + "','" + returndata.vessel + "'";
sql = sql + ",'" + returndata.voyage + "','" + returndata.bookingno + "','" + returndata.ctn_type + "','" + returndata.ctn_no + "','" + returndata.yard + "'";
sql = sql + ",'" + returndata.operatetime + "','" + returndata.operatetype + "','" + returndata.printType + "','" + returndata.fee
+ "','" + returndata.ydFee + "','" + returndata.secondPrintFee + "','" + returndata.applicant_code + "')";
SqlCommand cmd = new SqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
D7BS.ENTEROPERATOR = ENTEROPERATOR;
hp.addYTFee(returndata, D7BS, YTD7NoUseCORPID);
}
//hp.makefee();
hp.SendMail();
dbcon.Close();
hp.makefee_();
}
}
catch (Exception e)
{
log.Debug($"记录插入错误:{e.Message}");
}
}
else
{
log.Debug($"数据返回错误:{objRtn.message}");
}
}
catch (Exception e)
{
var hp = new YTFEEHelper();
hp.SendAlarmMail($"execute错误", $"{JsonConvert.SerializeObject(e)}");
log.Debug($"解析错误:{JsonConvert.SerializeObject(e) }");
}
finally {
log.Debug($"解析完成");
}
}
//var objRtn = JsonConvert.DeserializeObject<josnYtData>(rtn);
//if (objRtn.status == "1")
//{
// //var parseJsonObj = JsonConvert.DeserializeObject<List<JsonYtFee>>(objRtn.message);
// try
// {
// //1 记录进t_op_ytfee_log 表
// //2 遍历信息,将同提单号的费用合起来
// //3 遍历提单号,寻找业务,判断业务能否增加费用
// //3.1 业务是否已退仓
// //3.2 业务是否费用锁定
// //3.3 业务会计期间是否已锁帐
// //以上情况分别发送邮件提醒
// //4 如能增加费用 则插入费用
// using (SqlConnection dbcon = new SqlConnection(connStr))
// {
// var hp = new YTFEEHelper();
// var FEELIST = new List<D7BS>();
// dbcon.Open();
// foreach (var returndata in objRtn.message)
// {
// //测试数据
// //if (returndata.bookingno != "QGD0721089") continue;
// 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 D7BS = GETD7OPSEAEBS(returndata, YTD7Condition, 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 ('" + D7BS.BSNO + "','" + returndata.vessel + "'";
// sql = sql + ",'" + returndata.voyage + "','" + returndata.bookingno + "','" + returndata.ctn_type + "','" + returndata.ctn_no + "','" + returndata.yard + "'";
// sql = sql + ",'" + returndata.operatetime + "','" + returndata.operatetype + "','" + returndata.printType + "','" + returndata.fee
// + "','" + returndata.ydFee + "','" + returndata.secondPrintFee + "','" + returndata.applicant_code + "')";
// SqlCommand cmd = new SqlCommand(sql, dbcon);
// cmd.ExecuteNonQuery();
// D7BS.ENTEROPERATOR = ENTEROPERATOR;
// hp.addYTFee(returndata, D7BS, YTD7NoUseCORPID);
// }
// //hp.makefee();
// hp.SendMail();
// dbcon.Close();
// hp.makefee_应付();
// }
// }
// catch (Exception e)
// {
// log.Debug($"记录插入错误:{e.Message}");
// }
//}
//else
//{
// log.Debug($"数据返回错误:{objRtn.message}");
//}
}
catch (Exception ex)
{
var hp = new YTFEEHelper();
hp.SendAlarmMail($"execute错误", $"{JsonConvert.SerializeObject(ex)}");
//log.Debug($"解析错误:{JsonConvert.SerializeObject(ex)}");
log.Error($"execute错误:{JsonConvert.SerializeObject(ex)}");
//log.Error(ex.StackTrace);
}
}
public class MAILINFO {
public SqlConnection dbcon { get; set; }
public string sendto { get; set; }
public string title { get; set; }
public string body { get; set; }
public string smtpid { get; set; }
}
//public void SendAlarmMail(string msg)
//{
// SaveMail(dbcon, 告警邮箱, nofeeitem.mailtitle, nofeeitem.mailbody, "1");
//}
public static int SaveMail(MAILINFO mailinfo)
{
return SaveMail(mailinfo.dbcon, mailinfo.sendto, mailinfo.title, mailinfo.body, mailinfo.smtpid);
}
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 D7BS GETD7OPSEAEBS(JsonYtFee YtFee,string YTD7Condition, SqlConnection dbcon)
{
var newbs = new D7BS();
newbs.BSNO = "";
var strSql = new StringBuilder();
strSql.Append("SELECT TOP 1 BSNO,CORPID, CUSTOMERNAME,FEESTATUS,ISCANCEL,isnull((select top 1 CTNALL from op_ctn where bsno=op_seae.BSNO and CTNALL like '20%'),'') CTN20,isnull((select top 1 CTNALL from op_ctn where bsno=op_seae.BSNO and CTNALL like '40%'),'') CTN40 from op_seae where MBLNO like '" + YtFee.bookingno + "%' and isnull(ISCANCEL,'0')='0' ");
if (!string.IsNullOrWhiteSpace(YTD7Condition))
{
strSql.Append(" and " + YTD7Condition);
}
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();
newbs.FEESTATUS = row["FEESTATUS"].ToString() == "True" ? true : false;
newbs.ISCANCEL = row["ISCANCEL"].ToString() == "1" ? true : false;
newbs.CTN20 = row["CTN20"].ToString();
newbs.CTN40 = row["CTN40"].ToString();
newbs.CORPID = row["CORPID"].ToString();
}
}
else {
strSql = new StringBuilder();
strSql.Append("SELECT TOP 1 BSNO,CORPID, CUSTOMERNAME,FEESTATUS,ISCANCEL,isnull((select top 1 CTNALL from op_ctn where bsno=op_seae.BSNO and CTNALL like '20%'),'') CTN20,isnull((select top 1 CTNALL from op_ctn where bsno=op_seae.BSNO and CTNALL like '40%'),'') CTN40 from op_seae where MBLNO like '" + YtFee.bookingno + "%' ");
if (!string.IsNullOrWhiteSpace(YTD7Condition))
{
strSql.Append(" and " + YTD7Condition);
}
adapter.Fill(table);
BSNO = "";
if (table.Rows.Count > 0)
{
foreach (DataRow row in table.Rows)
{
newbs.BSNO = row["BSNO"].ToString();
newbs.CUSTOMERNAME = row["CUSTOMERNAME"].ToString();
newbs.FEESTATUS = row["FEESTATUS"].ToString() == "True" ? true : false;
newbs.ISCANCEL = row["ISCANCEL"].ToString() == "1" ? true : false;
newbs.CTN20 = row["CTN20"].ToString();
newbs.CTN40 = row["CTN40"].ToString();
newbs.CORPID = row["CORPID"].ToString();
}
}
}
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();
// }
// }
// return newbs;
// }
//}
public class D7BS
{
public string BSNO { get; set; }
public string CUSTOMERNAME { get; set; }
public string FEETYPE { get; set; }
public bool FEESTATUS { get; set; }
public bool ISCANCEL { get; set; }
public decimal AMOUNT { get; set; }
public int QUANTITY { get; set; }
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; }
public string CORPID { get; set; }
}
public class YTFEEHelper
{
private ILog log = LogManager.GetLogger(typeof(JobYtD7Fee));
public static string feeCustName { get; set; } = "上海亿通国际";
public static string CarrierCustName { get; set; } = "达飞轮船(中国)";
public static string feeName { get; set; } = "小票费";
public static string ydFeeName { get; set; } = "调箱费";
public static string secondPrintFeeName { get; set; } = "取消小票费";
public static string { get; set; } = "hhytcma@logisticsyt.com";
public static string connStr { get; set; }
//public List<JsonYtFee> YTFeeList { get; set; } = new List<JsonYtFee>();
public List<YTSumFee> YTSUMFeeList { get; set; } = new List<YTSumFee>();
//public List<JsonYtFee> noFeeList { get; set; } = new List<JsonYtFee>();
public List<YTSumFee> NOFeeYTSUMFeeList { get; set; } = new List<YTSumFee>();
//public List<MAILINFO> 无业务List { get; set; } = new List<MAILINFO>();
//public List<MAILINFO> 退舱业务List { get; set; } = new List<MAILINFO>();
//public List<MAILINFO> 费用锁定业务List { get; set; } = new List<MAILINFO>();
//void add无业务(SqlConnection dbcon, string sendto, string title, string body, string smtpid)
//{
// if (无业务List.Exists(x => x.title == title))
// {
// }
// else {
// var newrec = new MAILINFO();
// newrec.dbcon= dbcon;
// newrec.title = title;
// newrec.body = body;
// newrec.smtpid = smtpid;
// 无业务List.Add(newrec);
// }
//}
//private addmailList
public void addYTFee(JsonYtFee addrec, D7BS ds7info,string YTD7NoUseCORPID="")
{
if (string.IsNullOrWhiteSpace(ds7info.BSNO) || ds7info.ISCANCEL || ds7info.FEESTATUS)
{
//using (SqlConnection dbcon = new SqlConnection(connStr))
//{
// //var FEELIST = new List<D6BS>();
// dbcon.Open();
// if (string.IsNullOrWhiteSpace(ds7info.BSNO))
// {
// SaveMail(dbcon,
// 告警邮箱,
// addrec.bookingno + ds7info.CUSTOMERNAME + "此单号没有找到业务," + addrec.printType + ",金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢",
// addrec.bookingno + "此单号没有找到业务," + addrec.printType + ",金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢", "1");
// return;
// }
// else
// if (ds7info.ISCANCEL)
// {
// SaveMail(dbcon, 告警邮箱, addrec.bookingno + ds7info.CUSTOMERNAME + "此单号已退仓,但仍产生了费用。" + addrec.printType + "金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢", addrec.bookingno + "此单号已退仓,但仍产生了费用。" + addrec.printType + "金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢", "1");
// return;
// }
// else
// if (ds7info.FEESTATUS)
// {
// SaveMail(dbcon, 告警邮箱, addrec.bookingno + ds7info.CUSTOMERNAME + "此单号已费用锁定,但仍产生了费用。" + addrec.printType + "金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢", addrec.bookingno + "此单号已费用锁定,但仍产生了费用。请知悉,谢谢", "1");
// return;
// }
//}
if (string.IsNullOrWhiteSpace(ds7info.BSNO))
{
addNoFee(addrec, ds7info, addrec.bookingno + ds7info.CUSTOMERNAME + "此单号没有找到业务,请知悉,谢谢。" , addrec.bookingno + ds7info.CUSTOMERNAME + "此单号没有找到业务。" + addrec.printType+ "金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢");
}
else
if (ds7info.ISCANCEL)
{
addNoFee(addrec, ds7info, addrec.bookingno + ds7info.CUSTOMERNAME + "此单号已退仓,但仍产生了费用,请知悉,谢谢。", addrec.bookingno + ds7info.CUSTOMERNAME + "此单号已退仓,但仍产生了费用。" + addrec.printType + "金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢");
}
else
if (ds7info.FEESTATUS)
{
addNoFee(addrec, ds7info, addrec.bookingno + ds7info.CUSTOMERNAME + "此单号已费用锁定,但仍产生了费用,请知悉,谢谢。", addrec.bookingno + ds7info.CUSTOMERNAME + "此单号已费用锁定,但仍产生了费用。" + addrec.printType + "金额:" + (Convert.ToDecimal(addrec.ydFee) + Convert.ToDecimal(addrec.secondPrintFee) + Convert.ToDecimal(addrec.fee)).ToString() + ",请知悉,谢谢");
}
}
else {
if (!string.IsNullOrWhiteSpace(YTD7NoUseCORPID) && YTD7NoUseCORPID.IndexOf(ds7info.CORPID) >= 0)
{
//如果YTD7NoUseCORPID 不处理公司id不为空 且 YTD7NoUseCORPID当中包含ds7info.CORPID
//则不报警 也不记录费用
log.Debug($"亿通账单 跳过业务:{JsonConvert.SerializeObject(addrec)}");
}
else {
log.Debug($"亿通账单 添加费用:{JsonConvert.SerializeObject(addrec)}");
addFee(addrec, ds7info);
}
}
}
private void addFee(JsonYtFee addrec, D7BS ds7info)
{
if (!YTSUMFeeList.Exists(x => x.MBLNO == addrec.bookingno))
{
var newrec = new YTSumFee(addrec);
newrec.BSNO = ds7info.BSNO;
newrec.CTN20 = ds7info.CTN20;
newrec.CTN40 = ds7info.CTN40;
newrec.ENTEROPERATOR = ds7info.ENTEROPERATOR;
YTSUMFeeList.Add(newrec);
}
else
{
YTSUMFeeList.First(x => x.MBLNO == addrec.bookingno).addfee(addrec);
}
}
private void addNoFee(JsonYtFee addrec, D7BS ds7info,string mailtitle, string mailbody)
{
if (!NOFeeYTSUMFeeList.Exists(x => x.MBLNO == addrec.bookingno))
{
var newrec = new YTSumFee(addrec);
newrec.BSNO = ds7info.BSNO;
newrec.CTN20 = ds7info.CTN20;
newrec.CTN40 = ds7info.CTN40;
//newrec.ENTEROPERATOR = NOFEEReason;
newrec.mailtitle = mailtitle;
newrec.mailbody = mailbody;
NOFeeYTSUMFeeList.Add(newrec);
}
else
{
NOFeeYTSUMFeeList.First(x => x.MBLNO == addrec.bookingno).addfee(addrec);
}
}
public void SendMail()
{
if (NOFeeYTSUMFeeList != null && NOFeeYTSUMFeeList.Count > 0)
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
foreach (var nofeeitem in NOFeeYTSUMFeeList)
{
SaveMail(dbcon, , nofeeitem.mailtitle, nofeeitem.mailbody, "1");
}
}
}
}
public void SendAlarmMail(string title,string body)
{
if (NOFeeYTSUMFeeList != null && NOFeeYTSUMFeeList.Count > 0)
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
foreach (var nofeeitem in NOFeeYTSUMFeeList)
{
SaveMail(dbcon, , title, body, "1");
}
}
}
}
private List<ch_fee_md> FeeList { get; set; } = new List<ch_fee_md>();
private List<ch_fee_md> InsertFeeList { get; set; } = new List<ch_fee_md>();
private List<ch_fee_md> updFeeList { get; set; } = new List<ch_fee_md>();
public void makefee_()
{
if (YTSUMFeeList.Count > 0)
{
foreach (var item in YTSUMFeeList)
{
makefee_(item);
}
var cdc = new CommonDataContext(connStr);
var bsnoList = FeeList.Select(s=>s.BSNO).Distinct().ToList();
var CurrFeeList = cdc.ch_fee.Where(x => bsnoList.Contains(x.BSNO) && x.FEETYPE == 2 && (x.FEESTATUS == 1 || x.FEESTATUS == 6)).ToList();
foreach (var fee in FeeList) {
if (CurrFeeList.Exists(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE))
{
//var updrec = CurrFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE);
CurrFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).AMOUNT += fee.AMOUNT;
CurrFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).NOTAXAMOUNT += fee.NOTAXAMOUNT;
CurrFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).QUANTITY += fee.QUANTITY;
//ChFeeHelper.setTax(ref updrec);
CurrFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).MODIFIEDUSER = fee.ENTEROPERATOR;
CurrFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).MODIFIEDTIME = DateTime.Now;
//updFeeList.Add(fee);
}
else
if (InsertFeeList.Exists(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE))
{
InsertFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).AMOUNT += fee.AMOUNT;
InsertFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).NOTAXAMOUNT += fee.NOTAXAMOUNT;
InsertFeeList.First(x => x.BSNO == fee.BSNO && x.FEENAME == fee.FEENAME && x.UNITPRICE == fee.UNITPRICE).QUANTITY += fee.QUANTITY;
}
else
{
fee.ENTERDATE= DateTime.Now;
InsertFeeList.Add(fee);
}
}
cdc.ch_fee.AddRange(InsertFeeList);
cdc.SaveChanges();
}
}
private void makefee_(YTSumFee YTSumFee)
{
if (YTSumFee.fee_amount > 0)
{
//var newfee = ChFeeHelper.getNewChfee();
//newfee.BSNO = YTSumFee.BSNO;
//newfee.CUSTOMERNAME = feeCustName;
//newfee.FEETYPE = 2;
//newfee.AMOUNT = YTSumFee.fee_amount;
//newfee.QUANTITY = YTSumFee.fee_count;
//newfee.UNIT = "箱";
//newfee.ENTEROPERATOR = YTSumFee.OP;
//newfee.EXCHANGERATE = 1;
//newfee.FEENAME = "小票费";
//20240708 小票费价格固定为1元 票数依此计算
var newfee = ChFeeHelper.getChFee(YTSumFee.ENTEROPERATOR, YTSumFee.BSNO, feeCustName, 2, "小票费", YTSumFee.fee_amount, YTSumFee.CTN, YTSumFee.fee_amount, "", "");
newfee.CUSTOMERTYPE = "其他";
newfee.INPUTMODE = "导入亿通账单";
ChFeeHelper.setTax(ref newfee);
FeeList.Add(newfee);
}
if (YTSumFee.ydFee1_amount > 0)
{
//var newfee = ChFeeHelper.getNewChfee();
//newfee.BSNO = YTSumFee.BSNO;
//newfee.CUSTOMERNAME = CarrierCustName;
//newfee.FEETYPE = 2;
//newfee.AMOUNT = YTSumFee.ydFee1_amount;
//newfee.QUANTITY = YTSumFee.ydFee1_count;
//newfee.UNIT = "20'";
//newfee.ENTEROPERATOR = YTSumFee.OP;
//newfee.EXCHANGERATE = 1;
//newfee.FEENAME = "调箱费";
var newfee = ChFeeHelper.getChFee(YTSumFee.ENTEROPERATOR, YTSumFee.BSNO, CarrierCustName, 2, "调箱费", YTSumFee.ydFee1_amount, YTSumFee.CTN20, YTSumFee.ydFee1_count, "", "");
newfee.CUSTOMERTYPE = "其他";
newfee.INPUTMODE = "导入亿通账单";
ChFeeHelper.setTax(ref newfee);
FeeList.Add(newfee);
}
if (YTSumFee.ydFee2_amount > 0)
{
//var newfee = ChFeeHelper.getNewChfee();
//newfee.BSNO = YTSumFee.BSNO;
//newfee.CUSTOMERNAME = CarrierCustName;
//newfee.FEETYPE = 2;
//newfee.AMOUNT = YTSumFee.ydFee2_amount;
//newfee.QUANTITY = YTSumFee.ydFee2_count;
//newfee.UNIT = "40'";
//newfee.ENTEROPERATOR = YTSumFee.OP;
//newfee.EXCHANGERATE = 1;
//newfee.FEENAME = "调箱费";
var newfee = ChFeeHelper.getChFee(YTSumFee.ENTEROPERATOR, YTSumFee.BSNO, CarrierCustName, 2, "调箱费", YTSumFee.ydFee2_amount, YTSumFee.CTN40, YTSumFee.ydFee2_count, "", "");
newfee.CUSTOMERTYPE = "其他";
newfee.INPUTMODE = "导入亿通账单";
ChFeeHelper.setTax(ref newfee);
FeeList.Add(newfee);
}
if (YTSumFee.secondPrintFee_amount > 0)
{
//var newfee = ChFeeHelper.getNewChfee();
//newfee.BSNO = YTSumFee.BSNO;
//newfee.CUSTOMERNAME = CarrierCustName;
//newfee.FEETYPE = 2;
//newfee.AMOUNT = YTSumFee.secondPrintFee_amount;
//newfee.QUANTITY = YTSumFee.secondPrintFee_count;
//newfee.UNIT = "箱";
//newfee.ENTEROPERATOR = YTSumFee.OP;
//newfee.EXCHANGERATE = 1;
//newfee.FEENAME = "取消小票费";
var newfee = ChFeeHelper.getChFee(YTSumFee.ENTEROPERATOR, YTSumFee.BSNO, CarrierCustName, 2, "取消小票费", YTSumFee.secondPrintFee_amount, YTSumFee.CTN, YTSumFee.secondPrintFee_count, "", "");
newfee.CUSTOMERTYPE = "其他";
newfee.INPUTMODE = "导入亿通账单";
ChFeeHelper.setTax(ref newfee);
FeeList.Add(newfee);
}
}
}
}
}