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

161 lines
6.7 KiB
C#

3 years 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 JobDjyXf : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobDjyXf));
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("DjyReqUrl");
string companyCode = context.JobDetail.JobDataMap.GetString("DjyCompanyCode");
string companySecret = context.JobDetail.JobDataMap.GetString("DjyCompanySecret");
string bsType = context.JobDetail.JobDataMap.GetString("DjybsType");
string carrier = context.JobDetail.JobDataMap.GetString("DjyCarrier");
int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
long ts = DataTableToJsonHelper.ConvertDateTimeToInt(DateTime.Now);
JsonXFSend reqObj = new JsonXFSend();
var runid = Guid.NewGuid().ToString();
reqObj.runid = runid;
reqObj.userId = companyCode;
reqObj.module = "expendlist";
reqObj.bsType = bsType;
reqObj.sendType = "0";
reqObj.timestamp = ts;
var md5str = DataTableToJsonHelper.MD5Encrypt32(runid + companyCode + "expendlist" + bsType + "0" + ts.ToString() + companySecret);
reqObj.md5 = md5str;
//JArray jarrTemps = new JArray();
JsonXFData jobjTemp = new JsonXFData();
jobjTemp.page = 1;
jobjTemp.limit = 10000;
jobjTemp.BsType =5;
var starttimestr = File.ReadAllText(CfgFilePath);
if (!string.IsNullOrEmpty(starttimestr)) {
long startts = DataTableToJsonHelper.ConvertDateTimeToInt(Convert.ToDateTime(starttimestr));
jobjTemp.starttime = startts;
}
var endtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
long endts = DataTableToJsonHelper.ConvertDateTimeToInt(Convert.ToDateTime(endtime));
jobjTemp.endtime = endts;
reqObj.data = jobjTemp;
var sendstr = JsonConvert.SerializeObject(reqObj);
log.Debug($"发送包:{sendstr}");
//发送请求数据
string rtn = WebRequestHelper.DoPost(reqUrl, sendstr, reqTimeout * 1000);
//var objRtn = JsonConvert.DeserializeAnonymousType(rtn, new { status = "", message = "" });
log.Debug($"数据返回:{rtn}");
var parseJsonObj = JsonConvert.DeserializeObject<JsonXFResponse>(rtn);
if (parseJsonObj.status)
{
var returnlist = parseJsonObj.data;
try
{
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
foreach (var returndata in returnlist)
{
if (returndata.price == ""||returndata.price == null) returndata.price = "0";
if (returndata.ctnrCount == "" || returndata.ctnrCount == null) returndata.ctnrCount = "0";
string sql = " if (select GID from t_op_txxp_log where GID='" + returndata.gid + "') is null INSERT INTO t_op_txxp_log([编号],[GID],[beizhu],[mblno],[bsstatus],[bstype],[createtime]";
sql = sql + ",[price],[sendtype],[ctnrCount],[ctnrInfo]) values ((SELECT TOP 1 编号 from t_op_seae where 主提单号='" + returndata.mblno + "'),'" + returndata.gid + "'";
sql = sql + ",'" + returndata.beizhu + "','" + returndata.mblno + "','" + returndata.bsstatus + "','" + returndata.bstype + "','" + returndata.createtime + "'";
sql = sql + "," + returndata.price + ",'" + returndata.sendtype + "'," + returndata.ctnrCount + ",'" + returndata.ctnrInfo + "')";
SqlCommand cmd = new SqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
}
dbcon.Close();
}
}
catch (Exception e) {
log.Debug($"记录插入错误:{e.Message}");
}
File.WriteAllText(CfgFilePath, endtime);
}
else {
log.Debug($"数据返回错误:{parseJsonObj.message}");
}
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
}
public class JsonXFSend
{
public string runid { get; set; }
public string userId { get; set; }
public string module { get; set; }
public string bsType { get; set; }
public string sendType { get; set; }
public long timestamp { get; set; }
public string md5 { get; set; }
public JsonXFData data { get; set; }
}
public class JsonXFData
{
public int page { get; set; }
public int limit { get; set; }
public int BsType { get; set; }
public long starttime { get; set; }
public long endtime { get; set; }
}
public class JsonXFResponse
{
public bool status { get; set; }
public string message { get; set; }
public string code { get; set; }
public string count { get; set; }
public List<XFData> data { get; set; }
}
public class XFData
{
public string gid { get; set; }
public string beizhu { get; set; }
public string bsno { get; set; }
public string mblno { get; set; }
public string bsstatus { get; set; }
public string bstype { get; set; }
public string createtime { get; set; }
public string price { get; set; }
public string sendtype { get; set; }
public string ctnrCount { get; set; }
public string ctnrInfo { get; set; }
}
}