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/JobYunDang/JobBooking.cs

122 lines
5.1 KiB
C#

2 years ago
using log4net;
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using YDN;
namespace JobYunDang
{
public class JobBooking : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobBooking));
public void Execute(IJobExecutionContext context)
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string reqUrl = context.JobDetail.JobDataMap.GetString("ReqUrl");
string companyCode = context.JobDetail.JobDataMap.GetString("CompanyCode");
string companySecret = context.JobDetail.JobDataMap.GetString("CompanySecret");
string querySql = context.JobDetail.JobDataMap.GetString("QuerySql");
using (SqlConnection dbcon = new SqlConnection(connStr))
{
SqlDataAdapter adapter = new SqlDataAdapter(querySql, dbcon);
DataTable table = new DataTable();
adapter.Fill(table);
if (table.Columns.Contains("mblno") && table.Columns.Contains("carrierid") && table.Columns.Contains("portloadid"))
{
if (table.Rows.Count > 0)
{
List<dynamic> listOjb = new List<dynamic>();
foreach (DataRow row in table.Rows)
{
if (row["mblno"].ToString() != "" && row["carrierid"].ToString() != "" && row["portloadid"].ToString() != "") {
var obj = new
{
referenceno = row["mblno"].ToString(),
carriercd = row["carrierid"].ToString(),
pol = row["portloadid"].ToString()
};
listOjb.Add(obj);
}
}
var map = new Dictionary<string, string>();
map.Add("data", JsonConvert.SerializeObject(listOjb));
log.Debug($"订阅数据上传数据:{JsonConvert.SerializeObject(listOjb)}");
var urlMap = new Dictionary<string, string>();
urlMap.Add("companyid", companyCode);
var html = RequestApi.HttpPost(reqUrl, companySecret, urlMap, map);
var rtn = JsonConvert.DeserializeAnonymousType(html, new
{
success = false,
result = new dynamic[]
{
new
{
referenceno="",
success=true,
message=""
}
}
});
if (rtn.success)
{
foreach (dynamic res in rtn.result)
{
if ((bool)res.success)
{
try
{
dbcon.Open();
using (var trans = dbcon.BeginTransaction())
{
SqlCommand cmd = new SqlCommand($"update op_seae set IsBookingYDW=1,YDWUpdate=GETDATE() where mblno='{res.referenceno}'", dbcon, trans);
cmd.ExecuteNonQuery();
trans.Commit();
}
dbcon.Close();
}
catch
{
log.Error($"更新op_seae状态出错{res.referenceno}");
dbcon.Close();
}
log.Debug($"成功订阅数据,主提单号:{res.referenceno}");
}
else
{
log.Debug($"订阅数据失败,主提单号:{res.referenceno} {res.message}");
}
}
}
else
{
log.Debug($"订阅数据失败");
log.Debug(html);
}
}
else
{
log.Debug($"未查询到数据SQL语句{querySql}");
}
}
else
{
log.Error($"未包含所需的列(mblno,carrierid,portloadid)SQL语句{querySql}");
}
}
}
}
}