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.

74 lines
2.7 KiB
C#

using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Asn1.Tsp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZKLT.Hadoop.Interface;
using ZKLT.Hadoop.Model;
using ZKLT.Quartz.Interface;
using ZKLT.Quartz.Model;
namespace ZKLT.Hadoop
{
public class TaskService : ITaskService
{
private IHadoopService _HadoopService;
private IQuartzService _QuartzService;
public TaskService(IHadoopService hadoopService, IQuartzService quartzService) {
_HadoopService = hadoopService;
_QuartzService = quartzService;
}
public string Start(HDP_Task taskParams)
{
//获取计划任务信息
var taskCommand = new HDP_Command();
taskCommand.TableId = "ERP_Task";
taskCommand.Where = new JObject() { { "Id","=" } };
taskCommand.Data = new JObject() { {"Id",taskParams.Id } };
var taskInfo = _HadoopService.QuerySingle<HDP_Task>(taskCommand);
if(taskInfo.IsActive == HDP_Task.ACTIVE)
{
return $"任务已经开启,无需再次开启";
}
//获取计划任务配置
var taskConfigCommand = new HDP_Command();
taskConfigCommand.TableId = "ERP_TaskConfig";
taskConfigCommand.Where = new JObject() { { "TaskId","=" } };
taskConfigCommand.Data = new JObject() { {"TaskId",taskParams.Id} };
QZ_JobParams jobParams = new QZ_JobParams();
jobParams.TaskId = taskInfo.Id;
jobParams.CronTime = taskInfo.CronTime;
jobParams.IsLog = taskInfo.IsLog;
jobParams.Params = _HadoopService.Query<QZ_JobConfig>(taskConfigCommand).ToList();
// 调用任务管理类 开启任务管理
_QuartzService.CreateHttpJob(jobParams);
// 更新active
taskCommand.Data = new JObject() { { "Id", taskParams.Id },{ "IsActive",1} };
_HadoopService.Update(taskCommand);
return $"任务{taskParams.Id}已开启";
}
public string Close(HDP_Task taskParams)
{
QZ_JobParams jobParams = new QZ_JobParams() { TaskId=taskParams.Id};
_QuartzService.CloseJob(jobParams);
// 更新active
var taskCommand = new HDP_Command();
taskCommand.TableId = "ERP_Task";
taskCommand.Where = new JObject() { { "Id", "=" } };
taskCommand.Data = new JObject() { { "Id", taskParams.Id }, { "IsActive", 0 } };
_HadoopService.Update(taskCommand);
return $"任务{taskParams.Id}已关闭";
}
}
}