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 JobGetCrInvD6Data : IJob { private ILog log = LogManager.GetLogger(typeof(JobGetCrInvD6Data)); public void Execute(IJobExecutionContext context) { log.Debug($"Execute开始"); try { string connStr = context.JobDetail.JobDataMap.GetString("ConnectString"); string reqUrl = context.JobDetail.JobDataMap.GetString("ReqUrl"); string USER_KEY = context.JobDetail.JobDataMap.GetString("USER_KEY"); string USER_SECRET = context.JobDetail.JobDataMap.GetString("USER_SECRET"); int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout")); string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TempPath"); var JsonGetCrInvData = new GetCrInvData(); JsonGetCrInvData.pageIndex =1; JsonGetCrInvData.pageSize =1000; JsonGetCrInvData.kprqks = DateTime.Now.ToString("yyyy-MM-dd")+" 00:00:00"; JsonGetCrInvData.kprqjs = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var PCNO = DateTime.Now.ToString("yyyyMMddhhmmss"); var sendstr = JsonConvert.SerializeObject(JsonGetCrInvData); log.Debug($"发送包:{sendstr}"); //发送请求数据 string rtn = WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000); log.Debug($"数据返回:{rtn}"); var parseJsonObj = JsonConvert.DeserializeObject(rtn); if (parseJsonObj.data.data!=null&& parseJsonObj.data.data.Count!=0) { using (SqlConnection dbcon = new SqlConnection(connStr)) { dbcon.Open(); foreach (var bankdata in parseJsonObj.data.data) { if (!GETDISADD(bankdata.fphm, 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(); } //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(); } 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 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 InvData { /// /// 达飞轮船(中国)有限公司深圳分公司 /// public string xfkpmc { get; set; } /// /// /// public DateTime kprq { get; set; } /// /// /// public string je { get; set; } /// /// /// public string hjse { get; set; } /// /// /// public string jshj { get; set; } /// /// /// public string fphm { get; set; } /// /// /// public string fpdm { get; set; } /// /// /// public string fplxdm { get; set; } } public class Data { /// /// /// public List data { get; set; } /// /// /// public int dataCount { get; set; } /// /// /// public int pageIndex { get; set; } /// /// /// public int pageCount { get; set; } /// /// /// public int pageSize { get; set; } } public class ResultData { /// /// /// public int code { get; set; } /// /// /// public bool success { get; set; } /// /// /// public string msg { get; set; } /// /// /// public string msgDev { get; set; } /// /// /// public Data data { get; set; } } public class GetCrInvData { public int pageIndex { get; set; } public int pageSize { get; set; } public string kprqks { get; set; } public string kprqjs { get; set; } } }