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

406 lines
14 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 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.Net;
using System.Runtime.Remoting;
using System.Text;
namespace JobCreateFee
{
public class JobBankData : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobBankData));
public void Execute(IJobExecutionContext context)
{
log.Debug($"Execute开始");
try
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string reqUrl = context.JobDetail.JobDataMap.GetString("ReqUrl");
string companyName = context.JobDetail.JobDataMap.GetString("CompanyName");
string companyId = context.JobDetail.JobDataMap.GetString("CompanyId");
string CustId = context.JobDetail.JobDataMap.GetString("CustId");
string userId = context.JobDetail.JobDataMap.GetString("UserId");
string D7Url = context.JobDetail.JobDataMap.GetString("D7Url");
int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
var JsonGetBankData = new GetBankData();
JsonGetBankData.AccountName = companyName;
JsonGetBankData.AccountKey = CustId;
JsonGetBankData.BeginDate = DateTime.Now.AddDays(-3).ToString("yyyyMMdd");
JsonGetBankData.EndDate = DateTime.Now.ToString("yyyyMMdd");
var PCNO = DateTime.Now.ToString("yyyyMMddhhmmss");
var sendstr = JsonConvert.SerializeObject(JsonGetBankData);
log.Debug($"发送包:{sendstr}");
//发送请求数据
string rtn = WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000);
log.Debug($"数据返回:{rtn}");
var parseJsonObj = JsonConvert.DeserializeObject<BankResult>(rtn);
if (parseJsonObj.result!=null&& parseJsonObj.result.Count!=0)
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
foreach (var bankdata in parseJsonObj.result)
{
if (!GETDISADD(bankdata.RecordID, dbcon))
{
string sql = " INSERT INTO ch_fee_bankdata([GID],[PCNO],[SFNO],[TRANSTYPE],[DRAWEE_BANK],[DRAWEE_ACCOUNT],[DRAWEE_NAME],[PAYEE_BANK],[PAYEE_ACCOUNT]";
sql = sql + ",[PAYEE_NAME],[TRANSDATE],[CURRENCY],[AMOUNT],BALANCE,[TRANSNO],[IMPORTDATE],[IMPORTER],[ATTITIONAL],[REMARK],[SUMMARY],[CREATEUSER],[CREATETIME],[ACCOUNT],[BANK],[BANKGID],CORPID) values (NEWID(),'" + PCNO + "'";
sql = sql + ",'1','" + bankdata.TransactionType + "','" + bankdata.PayerAccountBank + "','" + bankdata.PayerAccountNumber + "','" + bankdata.PayerName + "'";
sql = sql + ",'" + bankdata.PayeeAccountBank+ "','" + bankdata.PayeeAccountNumber+ "','" + bankdata.PayeeName + "','" + bankdata.TransactionDate.Substring(0,4)+"-"+ bankdata.TransactionDate.Substring(4, 2)+"-"+ bankdata.TransactionDate.Substring(6, 2)+" "+ bankdata.TransactionTime
+ "','" + bankdata.TradeCurrency + "'," + bankdata.TradeAmount + "," + bankdata.AfterTransactionBalance + ",'" + bankdata.TransactionReferenceNumber + "',GETDATE(),'系统自动'"
+",'" + bankdata.Reference + "','" + bankdata.Purpose + "','" + bankdata.Remark+ bankdata.Remarks + "','系统自动',GETDATE(),'" + bankdata.AccountId + "'"
+",'" + bankdata.AccountName+ "','" + bankdata.RecordID + "','"+ companyId + "')";
log.Debug($"插入语句:{sql}");
SqlCommand cmd = new SqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
}
}
//hp.makefee();
dbcon.Close();
}
Dictionary<string, string> dicData = new Dictionary<string, string>();
dicData.Add("PCNO", PCNO);
dicData.Add("CORPID", companyId);
dicData.Add("USERID", userId);
// log.Debug($"发送包(自动结算){dicData.ToString()}");
var autostlrtn = DoPostHead(D7Url, dicData,"");
log.Debug($"数据返回:{autostlrtn}");
}
else {
log.Debug($"数据返回为空");
}
}
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();
}
public static void SaveImageToSql(string connectionString, byte[] imageData)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// 使用参数化的SQL查询来避免SQL注入
string sql = "INSERT INTO Images (Image) VALUES (@Image)";
using (SqlCommand command = new SqlCommand(sql, connection))
{
// 将图像数据作为参数传递
command.Parameters.Add(new SqlParameter("@Image", SqlDbType.Image) { Value = imageData });
command.ExecuteNonQuery();
}
}
}
public static byte[] ReadImageFromFile(string filePath)
{
// 确保文件存在
if (!File.Exists(filePath))
throw new FileNotFoundException("The file could not be found.", filePath);
// 读取图像文件并转换为字节数组
return File.ReadAllBytes(filePath);
}
static public bool GETDISADD(string RECOUNTID, SqlConnection dbcon)
{
var strSql = new StringBuilder();
strSql.Append("SELECT COUNT(1) CT from ch_fee_bankdata where BANKGID='" + RECOUNTID + "'");
SqlDataAdapter adapter = new SqlDataAdapter(strSql.ToString(), dbcon);
DataTable table = new DataTable();
adapter.Fill(table);
var result =false;
if (table.Rows.Count > 0)
{
foreach (DataRow row in table.Rows)
{
if (Convert.ToInt32(row["CT"].ToString()) != 0)
result = true;
}
}
return result;
}
public static string DoPostHead(string url, Dictionary<string, string> headdic, string json)
{
string responseString = "";//post返回的结果
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, err) => { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "POST";
if (headdic.Count > 0)
{
foreach (var item in headdic)
{
req.Headers.Add(item.Key, item.Value);
}
}
if (!string.IsNullOrWhiteSpace(json))
{
byte[] postBytes = Encoding.UTF8.GetBytes(json);
req.ContentType = "application/json; charset=utf-8";
req.ContentLength = Encoding.UTF8.GetByteCount(json);
Stream stream = req.GetRequestStream();
stream.Write(postBytes, 0, postBytes.Length);
req.Timeout = 100000;
stream.Close();
}
else
{
req.ContentLength = 0;
}
var response = req.GetResponse();
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
responseString = streamRead.ReadToEnd();
response.Close();
streamRead.Close();
return responseString;
}
}
public class BankData
{
/// <summary>
/// 青岛东胜伟业软件有限公司
/// </summary>
public string Custom { get; set; }
/// <summary>
/// 中国银行
/// </summary>
public string BankName { get; set; }
/// <summary>
/// 青岛大简云物流科技有限公司
/// </summary>
public string AccountName { get; set; }
/// <summary>
///
/// </summary>
public string AccountId { get; set; }
/// <summary>
/// 来账
/// </summary>
public string TransactionType { get; set; }
/// <summary>
/// 小额普通
/// </summary>
public string BusinessType { get; set; }
/// <summary>
///
/// </summary>
public string AccountHoldingBankNumberOfPayer { get; set; }
/// <summary>
/// 平安银行青岛经济技术开发区支行
/// </summary>
public string PayerAccountBank { get; set; }
/// <summary>
///
/// </summary>
public string PayerAccountNumber { get; set; }
/// <summary>
/// 青岛海泰优升国际物流有限公司
/// </summary>
public string PayerName { get; set; }
/// <summary>
///
/// </summary>
public string AccountHoldingBankNumberOfPayee { get; set; }
/// <summary>
/// 中国银行青岛香港西路支行
/// </summary>
public string PayeeAccountBank { get; set; }
/// <summary>
///
/// </summary>
public string PayeeAccountNumber { get; set; }
/// <summary>
/// 青岛大简云物流科技有限公司
/// </summary>
public string PayeeName { get; set; }
/// <summary>
///
/// </summary>
public string TransactionDate { get; set; }
/// <summary>
///
/// </summary>
public string TransactionTime { get; set; }
/// <summary>
///
/// </summary>
public string TradeCurrency { get; set; }
/// <summary>
///
/// </summary>
public string TradeAmount { get; set; }
/// <summary>
///
/// </summary>
public string AfterTransactionBalance { get; set; }
/// <summary>
///
/// </summary>
public string ValueDate { get; set; }
/// <summary>
///
/// </summary>
public string ExchangeRate { get; set; }
/// <summary>
///
/// </summary>
public string TransactionReferenceNumber { get; set; }
/// <summary>
///
/// </summary>
public string OnlineBankingTransactionRef { get; set; }
/// <summary>
///
/// </summary>
public string CustomerTransactionRef { get; set; }
/// <summary>
///
/// </summary>
public string VoucherType { get; set; }
/// <summary>
///
/// </summary>
public string VoucherNumber { get; set; }
/// <summary>
///
/// </summary>
public string RecordID { get; set; }
/// <summary>
///
/// </summary>
public string Reference { get; set; }
/// <summary>
///
/// </summary>
public string Purpose { get; set; }
/// <summary>
/// 舱单
/// </summary>
public string Remark { get; set; }
/// <summary>
/// beps.121.001.01 A100 R104100000004 中国银行总行
/// </summary>
public string Remarks { get; set; }
/// <summary>
///
/// </summary>
public string Reserve1 { get; set; }
/// <summary>
///
/// </summary>
public string Reserve2 { get; set; }
/// <summary>
///
/// </summary>
public string Reserve3 { get; set; }
/// <summary>
///
/// </summary>
public string OpeningBankNumberOfNominalPayer { get; set; }
/// <summary>
///
/// </summary>
public string OpeningBankNameOfNominalPayer { get; set; }
/// <summary>
///
/// </summary>
public string AccountNumberOfNominalPayer { get; set; }
/// <summary>
///
/// </summary>
public string NameOfNominalPayer { get; set; }
/// <summary>
///
/// </summary>
public string OpeningBankNumberOfNominalPayee { get; set; }
/// <summary>
///
/// </summary>
public string OpeningBankNameOfNominalPayee { get; set; }
/// <summary>
///
/// </summary>
public string AccountNumberOfNominalPayee { get; set; }
/// <summary>
///
/// </summary>
public string NameOfNominalPayee { get; set; }
/// <summary>
///
/// </summary>
public string CreateTime { get; set; }
/// <summary>
///
/// </summary>
public string FilePaths { get; set; }
}
public class BankResult
{
/// <summary>
///
/// </summary>
public List<BankData> result { get; set; }
}
public class GetBankData
{
public string AccountName { get; set; }
public string BeginDate { get; set; }
public string EndDate { get; set; }
public string AccountKey { get; set; }
}
}