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.

70 lines
2.6 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.Linq;
using System.Text;
namespace JobReqWebData
{
public class JobSendRequest : IJob
{
private ILog log = LogManager.GetLogger(typeof(JobSendRequest));
public void Execute(IJobExecutionContext context)
{
try
{
string connStr = context.JobDetail.JobDataMap.GetString("ConnectString");
string sqlQuery = context.JobDetail.JobDataMap.GetString("QuerySql");
string reqUrl = context.JobDetail.JobDataMap.GetString("ReqUrl");
string customer = context.JobDetail.JobDataMap.GetString("Customer");
string password = context.JobDetail.JobDataMap.GetString("Password");
int reqTimeout = Convert.ToInt32(context.JobDetail.JobDataMap.GetString("RequestTimeout"));
log.Debug($"连接字符串:{connStr}");
log.Debug($"查询SQL{sqlQuery}");
log.Debug($"请求URL{reqUrl}");
log.Debug($"用户:{customer}");
log.Debug($"密码:{password}");
log.Debug($"请求超时:{reqTimeout}");
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlQuery, conn);
DataTable tQuery = new DataTable();
dataAdapter.Fill(tQuery);
if (tQuery.Rows.Count == 0)
{
log.Debug("没有要发送的数据!");
return;
}
var json = DataTableToJsonHelper.ConvertToJson(tQuery);
log.Debug($"jsonStr{json.ToString(Formatting.None)}");
JObject reqObj = new JObject();
reqObj.Add("custname", new JValue(customer));
reqObj.Add("psw", new JValue(password));
reqObj.Add("bslist", json);
log.Debug($"reqObj{reqObj.ToString(Formatting.None)}");
//发送请求数据
string rtn = WebRequestHelper.DoPost(reqUrl, reqObj.ToString(Formatting.None), reqTimeout * 1000);
var objRtn = JsonConvert.DeserializeAnonymousType(rtn, new { status = "", message = "" });
log.Debug($"爬取服务返回:{objRtn.message}(Code:{objRtn.status})");
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
}
}
}
}