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/JobReqWebData/JobGetATDData.cs

96 lines
4.4 KiB
C#

3 years ago
using log4net;
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace JobReqWebData
{
public class JobGetATDData : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobGetATDData));
private const string CfgFileName = "requestjson.cfg";
private static string CfgFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CfgFileName);
public void Execute(IJobExecutionContext context)
{
var requestjson = File.ReadAllText(CfgFilePath);
if (string.IsNullOrEmpty(requestjson)) return;
try
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string reqUrl = context.JobDetail.JobDataMap.GetString("ReqUrl");
string UpdateSql = context.JobDetail.JobDataMap.GetString("UpdateSql");
int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
log.Debug($"连接字符串:{connStr}");
log.Debug($"请求URL{reqUrl}");
log.Debug($"请求JSON{requestjson}");
log.Debug($"请求超时:{reqTimeout}");
string rtn = WebRequestHelper.DoPost(reqUrl, requestjson, reqTimeout*1000);
log.Debug($"数据返回:{rtn}");
var parseJsonObj = JsonConvert.DeserializeObject<JsonStatusResponse>(rtn);
if (parseJsonObj.status == "1")
{
var parseETAJsonObj = JsonConvert.DeserializeObject<JsonETAResponse>(rtn);
//入库
using (SqlConnection dbcon = new SqlConnection(connStr))
{
dbcon.Open();
using (SqlTransaction trans = dbcon.BeginTransaction())
{
#region 运踪
foreach (var item in parseETAJsonObj.message)
{
string sql = UpdateSql;
sql = sql.Replace("[实际离港日期]", item.SJLGSJ).Replace("[实际离港日期]", item.SJLGSJ).Replace("[实际离港日期]", item.SJLGSJ).Replace("[实际离港日期]", item.SJLGSJ).Replace("[实际离港日期]", item.SJLGSJ);
sql = sql.Replace("[预计到港日期]", item.ETA).Replace("[预计到港日期]", item.ETA).Replace("[预计到港日期]", item.ETA).Replace("[预计到港日期]", item.ETA).Replace("[预计到港日期]", item.ETA);
sql = sql.Replace("[实际到港日期]", item.SJDGSJ).Replace("[实际到港日期]", item.SJDGSJ).Replace("[实际到港日期]", item.SJDGSJ).Replace("[实际到港日期]", item.SJDGSJ).Replace("[实际到港日期]", item.SJDGSJ);
sql = sql.Replace("[预计开船日期]", item.ETD).Replace("[预计开船日期]", item.ETD).Replace("[预计开船日期]", item.ETD).Replace("[预计开船日期]", item.ETD).Replace("[预计开船日期]", item.ETD).Replace("[预计开船日期]", item.ETD);
sql = sql.Replace("[船名]", item.YWCM);
sql = sql.Replace("[航次]", item.CKHC);
SqlCommand cmd = new SqlCommand(sql, dbcon, trans);
cmd.ExecuteNonQuery();
//if (!string.IsNullOrEmpty(item.SJLGSJ))
//{
// string sql ="update op_seae set ATD='"+ item.SJLGSJ + "' where VESSEL='"+ item.YWCM + "' AND VOYNO='"+ item.CKHC+ "'";
// SqlCommand cmd = new SqlCommand(sql, dbcon, trans);
// cmd.ExecuteNonQuery();
//}
}
#endregion
trans.Commit();
}
dbcon.Close();
}
}
else {
log.Debug($"返回数据为空");
}
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
}
}