|
|
|
@ -11,6 +11,7 @@ using ZKLT.Quartz.Model;
|
|
|
|
|
using ZKLT.Hadoop.Interface;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using ZKLT.Hadoop.Model;
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
namespace ZKLT.Quartz.Job
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
@ -18,29 +19,29 @@ namespace ZKLT.Quartz.Job
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class HttpJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private IHadoopService HadoopService;
|
|
|
|
|
public HttpJob(IHadoopService _hadoopService)
|
|
|
|
|
{
|
|
|
|
|
HadoopService = _hadoopService;
|
|
|
|
|
}
|
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
|
{
|
|
|
|
|
JobDataMap dataMap = context.JobDetail.JobDataMap;
|
|
|
|
|
string taskId = dataMap.Get("TaskId").ToString();
|
|
|
|
|
Console.WriteLine(taskId);
|
|
|
|
|
|
|
|
|
|
IHadoopService _HadoopService = (IHadoopService)dataMap.Get("hadoop");
|
|
|
|
|
// 任务配置项
|
|
|
|
|
List<QZ_JobConfig> configs = (List<QZ_JobConfig>)dataMap.Get("Params");
|
|
|
|
|
|
|
|
|
|
// 任务Id
|
|
|
|
|
string taskId = dataMap.Get("TaskId").ToString();
|
|
|
|
|
// 是否开启日志
|
|
|
|
|
int isLog = (int)dataMap.Get("IsLog");
|
|
|
|
|
// 请求地址
|
|
|
|
|
string url = configs.Find(_item => _item.Key == "Url").Value;
|
|
|
|
|
HttpMethod httpMethod = configs.Find(_item => _item.Key == "Method").Value == "Get" ? HttpMethod.Get : HttpMethod.Post;
|
|
|
|
|
// 请求类型
|
|
|
|
|
HttpMethod httpMethod = configs.Find(_item => _item.Key == "Method").Value == "GET" ? HttpMethod.Get : HttpMethod.Post;
|
|
|
|
|
// 返回数据储存表
|
|
|
|
|
string bindDatabase = configs.Find(_item => _item.Key == "BindDatabse").Value;
|
|
|
|
|
|
|
|
|
|
// 返回数据集合名
|
|
|
|
|
string resultSet = configs.Find(_item => _item.Key == "ResultSet").Value;
|
|
|
|
|
using (HttpClient client = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var resultColumnConfigs = new List<QZ_JobConfig>();
|
|
|
|
|
|
|
|
|
|
HttpRequestMessage request = new HttpRequestMessage(httpMethod, url);
|
|
|
|
|
foreach (var _item in configs)
|
|
|
|
|
{
|
|
|
|
@ -57,11 +58,29 @@ namespace ZKLT.Quartz.Job
|
|
|
|
|
HttpResponseMessage response = await client.SendAsync(request);
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
var responseList = JsonConvert.DeserializeObject<List<JObject>>(responseBody);
|
|
|
|
|
var responseObject = JsonConvert.DeserializeObject<JObject>(responseBody);
|
|
|
|
|
JArray responseList = (JArray)responseObject.GetValue(resultSet);
|
|
|
|
|
// 如果设定了绑定表 插入表中
|
|
|
|
|
if (bindDatabase != null)
|
|
|
|
|
{
|
|
|
|
|
HDP_Command[] commands = makeCommand(bindDatabase, responseList, resultColumnConfigs);
|
|
|
|
|
HadoopService.PatchCommand(commands);
|
|
|
|
|
_HadoopService.PatchCommand(commands);
|
|
|
|
|
}
|
|
|
|
|
// 日志开启,插入日志
|
|
|
|
|
if (isLog == HDP_Task.LOGOPEN)
|
|
|
|
|
{
|
|
|
|
|
var data = new HDP_TaskLog()
|
|
|
|
|
{
|
|
|
|
|
Id = "TL" + DateTime.Now.ToUniversalTime(),
|
|
|
|
|
TaskId = taskId,
|
|
|
|
|
Content = responseBody
|
|
|
|
|
};
|
|
|
|
|
var logCommand = new HDP_Command()
|
|
|
|
|
{
|
|
|
|
|
TableId = HDP_TaskLog.TABLEID,
|
|
|
|
|
Data = JToken.FromObject(data)
|
|
|
|
|
};
|
|
|
|
|
_HadoopService.Insert(logCommand);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (HttpRequestException e)
|
|
|
|
@ -70,10 +89,11 @@ namespace ZKLT.Quartz.Job
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HDP_Command[] makeCommand(string bindDatabase,List<JObject> responseList,List<QZ_JobConfig> configList)
|
|
|
|
|
public HDP_Command[] makeCommand(string bindDatabase,JArray responseList,List<QZ_JobConfig> configList)
|
|
|
|
|
{
|
|
|
|
|
HDP_Command[] commands = new HDP_Command?[responseList.Count];
|
|
|
|
|
foreach (var _item in responseList)
|
|
|
|
@ -81,10 +101,14 @@ namespace ZKLT.Quartz.Job
|
|
|
|
|
var command = new HDP_Command();
|
|
|
|
|
command.TableId = bindDatabase;
|
|
|
|
|
command.Type = HDP_CommandType.INSERT;
|
|
|
|
|
var data = new JObject();
|
|
|
|
|
foreach (var _config in configList)
|
|
|
|
|
{
|
|
|
|
|
command.Data[_config.Value] = _item[_config.Key];
|
|
|
|
|
data[_config.Value] = _item[_config.Key];
|
|
|
|
|
}
|
|
|
|
|
command.Data = data;
|
|
|
|
|
int _index = responseList.IndexOf(_item);
|
|
|
|
|
commands[_index] = command;
|
|
|
|
|
}
|
|
|
|
|
return commands;
|
|
|
|
|
}
|
|
|
|
|