Commit e9927964 by huangfusuper

Merge remote-tracking branch 'origin/developer' into developer

parents b36ea651 4551b885
......@@ -35,4 +35,10 @@ public class ApiNodeController {
return ResponseResult.ok(jobTaskRunLogList);
}
@PostMapping("autoAddJavaTask")
public String autoAddJavaTask(String param) throws Exception {
apiNodeService.autoAddJavaTask(param);
return "SUCCESS";
}
}
......@@ -2,6 +2,7 @@ package com.byit.service;
import com.byit.model.JobTaskRunLog;
import java.text.ParseException;
import java.util.List;
/**
......@@ -21,4 +22,13 @@ public interface ApiNodeService {
* @return
*/
List<JobTaskRunLog> runHistory(String nodeId);
/**
* 功能描述 自动发布任务的接口
* @author gml
* @date 2020-04-14 10:55
* @param param
* @return void
*/
void autoAddJavaTask(String param) throws Exception;
}
package com.byit.service.impl;
import com.alibaba.fastjson.JSON;
import com.byit.dto.plugin.JavaTask;
import com.byit.dto.plugin.RunLog;
import com.byit.dto.plugin.RunNode;
import com.byit.enums.NodePropertyEnum;
import com.byit.enums.ScheduleTypeEnum;
import com.byit.job.WorkRoulette;
import com.byit.job.utils.CronExpression;
import com.byit.job.utils.PlaceholderUtils;
import com.byit.mapper.JavaTaskMapper;
import com.byit.mapper.JobTaskRunLogMapper;
import com.byit.model.JobTaskRunLog;
import com.byit.model.JobTaskRunLogWithBLOBs;
......@@ -18,9 +21,12 @@ import io.netty.util.TimerTask;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
......@@ -29,6 +35,7 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
* @author guo_m
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ApiNodeServiceImpl implements ApiNodeService {
@Resource
......@@ -37,6 +44,9 @@ public class ApiNodeServiceImpl implements ApiNodeService {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource
private JavaTaskMapper javaTaskMapper;
@Override
public String runNode(String param) {
......@@ -95,4 +105,38 @@ public class ApiNodeServiceImpl implements ApiNodeService {
return jobTaskRunLogList;
}
@Override
public void autoAddJavaTask(String param) throws Exception {
ValidationUtil.dataNotBank(param, "请求参数不允许为空!");
JavaTask javaTask = JSON.parseObject(param, JavaTask.class);
ValidationUtil.dataNotBank(javaTask.getTaskName(), "任务实现类的名称不允许为空!");
ValidationUtil.dataNotBank(javaTask.getCron(), "任务的调度时间不允许为空!");
ValidationUtil.isTrueValidation(!CronExpression.isValidExpression(javaTask.getCron()), "工作流cron表达式不符合规范!");
//自动发布taskName默认为jobName
javaTask.setJobName(javaTask.getTaskName());
//如果不为空且不为-1
if(null != javaTask.getRepeatCount() && -1 != javaTask.getRepeatCount()){
javaTask.setRemainingCount(javaTask.getRemainingCount());
}
if (null != javaTask.getAlarmlAction() && "0".equals(javaTask.getRepeatCount())){
ValidationUtil.dataNotBank(javaTask.getAlarmEmail(), "设置为告警时告警邮箱不允许为空");
}
JavaTask oldJavaTask = javaTaskMapper.findByJobName(javaTask.getJobName());
if (null != oldJavaTask){
//更新配置项
oldJavaTask.setCron(javaTask.getCron());
oldJavaTask.setRepeatCount(javaTask.getRepeatCount());
oldJavaTask.setRemainingCount(javaTask.getRemainingCount());
if (null != javaTask.getAlarmlAction() && "0".equals(javaTask.getRepeatCount())){
oldJavaTask.setAlarmlAction(javaTask.getAlarmlAction());
oldJavaTask.setAlarmEmail(javaTask.getAlarmEmail());
}
javaTaskMapper.updateByIdSelective(oldJavaTask);
}else {
javaTask.setTriggerTime(new CronExpression(javaTask.getCron()).getNextValidTimeAfter(new Date()).getTime());
javaTask.setCreateTime(new Date());
javaTaskMapper.insertSelective(javaTask);
}
}
}
......@@ -11,4 +11,5 @@ public interface JavaTaskMapper {
int updateByIdSelective(JavaTask record);
JavaTask findByJobName(String jobName);
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
<id column="id" jdbcType="INTEGER" property="id" />
<result column="job_name" jdbcType="VARCHAR" property="jobName" />
<result column="task_name" jdbcType="VARCHAR" property="taskName" />
<result column="scheduling_count" jdbcType="INTEGER" property="schedulingCount" />
<result column="repeat_count" jdbcType="INTEGER" property="repeatCount" />
<result column="param" jdbcType="VARCHAR" property="param" />
<result column="trigger_time" jdbcType="BIGINT" property="triggerTime" />
<result column="cron" jdbcType="VARCHAR" property="cron" />
......@@ -18,7 +18,7 @@
</resultMap>
<sql id="Base_Column_List">
<!-- generated @mbg.generated date: 2020-04-14 -->
id, job_name, task_name, scheduling_count, param, trigger_time, cron, remaining_count,
id, job_name, task_name, repeat_count, param, trigger_time, cron, remaining_count,
create_time, update_time, alarml_action, alarm_email
</sql>
<select id="getById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
......@@ -33,7 +33,6 @@
delete from java_task
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insertSelective" parameterType="com.byit.dto.plugin.JavaTask">
<!-- generated @mbg.generated date: 2020-04-14 -->
insert into java_task
......@@ -47,8 +46,8 @@
<if test="taskName != null">
task_name,
</if>
<if test="schedulingCount != null">
scheduling_count,
<if test="repeatCount != null">
repeat_count,
</if>
<if test="param != null">
param,
......@@ -85,8 +84,8 @@
<if test="taskName != null">
#{taskName,jdbcType=VARCHAR},
</if>
<if test="schedulingCount != null">
#{schedulingCount,jdbcType=INTEGER},
<if test="repeatCount != null">
#{repeatCount,jdbcType=INTEGER},
</if>
<if test="param != null">
#{param,jdbcType=VARCHAR},
......@@ -124,8 +123,8 @@
<if test="taskName != null">
task_name = #{taskName,jdbcType=VARCHAR},
</if>
<if test="schedulingCount != null">
scheduling_count = #{schedulingCount,jdbcType=INTEGER},
<if test="repeatCount != null">
repeat_count = #{repeatCount,jdbcType=INTEGER},
</if>
<if test="param != null">
param = #{param,jdbcType=VARCHAR},
......@@ -154,5 +153,11 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<select id="findByJobName" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from java_task
where job_name = #{jobName,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
......@@ -33,7 +33,7 @@ public class JavaTask implements Serializable {
/**
* 调度次数 -1周期性调度
*/
private Integer schedulingCount;
private Integer repeatCount;
/**
* 参数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment