Commit 25014132 by huangfusuper

【代码重构】日志操作

parent da0171a4
...@@ -22,4 +22,11 @@ public interface JobTaskRunLogService { ...@@ -22,4 +22,11 @@ public interface JobTaskRunLogService {
* @return * @return
*/ */
int saveJobTaskRunLog(JobTaskRunLog jobTaskRunLog); int saveJobTaskRunLog(JobTaskRunLog jobTaskRunLog);
/**
* 修改数据
* @param jobTaskRunLog
* @return
*/
int updateJobTaskRunLog(JobTaskRunLog jobTaskRunLog);
} }
...@@ -5,6 +5,8 @@ import com.byit.model.JobTaskRunLog; ...@@ -5,6 +5,8 @@ import com.byit.model.JobTaskRunLog;
import com.byit.service.JobTaskRunLogService; import com.byit.service.JobTaskRunLogService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/** /**
* @program: byit-myth-job->JobTaskRunLogServiceImpl * @program: byit-myth-job->JobTaskRunLogServiceImpl
...@@ -13,12 +15,18 @@ import org.springframework.stereotype.Service; ...@@ -13,12 +15,18 @@ import org.springframework.stereotype.Service;
* @date: 2019/12/20 19:43 * @date: 2019/12/20 19:43
**/ **/
@Service @Service
@Transactional(rollbackFor = Exception.class)
public class JobTaskRunLogServiceImpl implements JobTaskRunLogService { public class JobTaskRunLogServiceImpl implements JobTaskRunLogService {
private final JobTaskRunLogMapper jobTaskRunLogMapper;
@Autowired @Autowired
private JobTaskRunLogMapper jobTaskRunLogMapper; public JobTaskRunLogServiceImpl(JobTaskRunLogMapper jobTaskRunLogMapper) {
this.jobTaskRunLogMapper = jobTaskRunLogMapper;
}
@Override @Override
@Transactional(rollbackFor = Exception.class,propagation = Propagation.SUPPORTS)
public JobTaskRunLog findJobTaskRunLogById(Integer id) { public JobTaskRunLog findJobTaskRunLogById(Integer id) {
return jobTaskRunLogMapper.getById(id); return jobTaskRunLogMapper.getById(id);
} }
...@@ -27,4 +35,9 @@ public class JobTaskRunLogServiceImpl implements JobTaskRunLogService { ...@@ -27,4 +35,9 @@ public class JobTaskRunLogServiceImpl implements JobTaskRunLogService {
public int saveJobTaskRunLog(JobTaskRunLog jobTaskRunLog) { public int saveJobTaskRunLog(JobTaskRunLog jobTaskRunLog) {
return jobTaskRunLogMapper.insertSelective(jobTaskRunLog); return jobTaskRunLogMapper.insertSelective(jobTaskRunLog);
} }
@Override
public int updateJobTaskRunLog(JobTaskRunLog jobTaskRunLog) {
return jobTaskRunLogMapper.updateByIdSelective(jobTaskRunLog);
}
} }
...@@ -5,6 +5,8 @@ import com.byit.model.JobTaskSchedule; ...@@ -5,6 +5,8 @@ import com.byit.model.JobTaskSchedule;
import com.byit.service.JobTaskScheduleService; import com.byit.service.JobTaskScheduleService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
...@@ -15,16 +17,22 @@ import java.util.List; ...@@ -15,16 +17,22 @@ import java.util.List;
* @date: 2019/12/20 17:32 * @date: 2019/12/20 17:32
**/ **/
@Service @Service
@Transactional(rollbackFor = Exception.class)
public class JobTaskScheduleServiceImpl implements JobTaskScheduleService { public class JobTaskScheduleServiceImpl implements JobTaskScheduleService {
private final JobTaskScheduleMapper jobTaskScheduleMapper;
@Autowired @Autowired
private JobTaskScheduleMapper jobTaskScheduleMapper; public JobTaskScheduleServiceImpl(JobTaskScheduleMapper jobTaskScheduleMapper) {
this.jobTaskScheduleMapper = jobTaskScheduleMapper;
}
/** /**
* 查询五秒的数据 * 查询五秒的数据
* @param maxNextTime * @param maxNextTime
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class,propagation = Propagation.SUPPORTS)
@Override @Override
public List<JobTaskSchedule> findJobTaskScheduleByTriggerNextTimeLessThanEqual(long maxNextTime) { public List<JobTaskSchedule> findJobTaskScheduleByTriggerNextTimeLessThanEqual(long maxNextTime) {
return jobTaskScheduleMapper.findJobTaskScheduleByTriggerNextTimeLessThanEqual(maxNextTime); return jobTaskScheduleMapper.findJobTaskScheduleByTriggerNextTimeLessThanEqual(maxNextTime);
......
...@@ -5,6 +5,8 @@ import com.byit.model.JobTask; ...@@ -5,6 +5,8 @@ import com.byit.model.JobTask;
import com.byit.service.JobTaskService; import com.byit.service.JobTaskService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
...@@ -15,6 +17,7 @@ import java.util.List; ...@@ -15,6 +17,7 @@ import java.util.List;
* @date: 2019/12/20 15:13 * @date: 2019/12/20 15:13
**/ **/
@Service @Service
@Transactional(rollbackFor = Exception.class)
public class JobTaskServiceImpl implements JobTaskService { public class JobTaskServiceImpl implements JobTaskService {
private final JobTaskMapper jobTaskMapper; private final JobTaskMapper jobTaskMapper;
...@@ -28,6 +31,7 @@ public class JobTaskServiceImpl implements JobTaskService { ...@@ -28,6 +31,7 @@ public class JobTaskServiceImpl implements JobTaskService {
* @param maxNextTime 预读数值 * @param maxNextTime 预读数值
* @return 返回的是七秒内将要执行的数据 * @return 返回的是七秒内将要执行的数据
*/ */
@Transactional(rollbackFor = Exception.class,propagation = Propagation.SUPPORTS)
@Override @Override
public List<JobTask> findJobTaskByTriggerNextTimeLessThanEqual(long maxNextTime) { public List<JobTask> findJobTaskByTriggerNextTimeLessThanEqual(long maxNextTime) {
return jobTaskMapper.findJobTaskByTriggerNextTimeLessThanEqual(maxNextTime); return jobTaskMapper.findJobTaskByTriggerNextTimeLessThanEqual(maxNextTime);
......
...@@ -48,17 +48,18 @@ public class JavaBeanJobTask implements TimerTask { ...@@ -48,17 +48,18 @@ public class JavaBeanJobTask implements TimerTask {
adminSenPluginDto.setLogId(mythJobTaskSchedule.getLogId()); adminSenPluginDto.setLogId(mythJobTaskSchedule.getLogId());
//这里获取的是调度结果 //这里获取的是调度结果
String result = HttpUtil.post(url, JSON.toJSONString(adminSenPluginDto),10*1000); String result = HttpUtil.post(url, JSON.toJSONString(adminSenPluginDto),10*1000);
DispatchResponseDto dispatchResponseDto = JSON.parseObject(result, DispatchResponseDto.class);
//修改调度结果 //修改调度结果
saveLog(mythJobTaskSchedule, url, result); saveLog(mythJobTaskSchedule, url, result);
log.debug("---------------{}------------",result); log.debug("---------------{}------------",result);
}catch (PluginException ignored){ }catch (PluginException ignored){
saveLog(mythJobTaskSchedule, "", ignored.getMessage()); DispatchResponseDto dispatchResponseDto = DispatchResponseDto.builder().code(ignored.getIEnum( ).getCode( )).msg(ignored.getIEnum( ).getMsg( )).build( );
saveLog(mythJobTaskSchedule, "", JSON.toJSONString(dispatchResponseDto));
log.error("-------------通讯异常:{},{}",ignored.getIEnum().getCode(),ignored.getIEnum().getMsg()); log.error("-------------通讯异常:{},{}",ignored.getIEnum().getCode(),ignored.getIEnum().getMsg());
}catch (Exception e){ }catch (Exception e){
saveLog(mythJobTaskSchedule, "", "未知错误!!"); DispatchResponseDto dispatchResponseDto = DispatchResponseDto.builder().code("500").msg("未知错误").build( );
saveLog(mythJobTaskSchedule, "", JSON.toJSONString(dispatchResponseDto));
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -66,16 +67,17 @@ public class JavaBeanJobTask implements TimerTask { ...@@ -66,16 +67,17 @@ public class JavaBeanJobTask implements TimerTask {
private void saveLog(JobTaskSchedule mythJobTaskSchedule, String url, String result){ private void saveLog(JobTaskSchedule mythJobTaskSchedule, String url, String result){
DispatchResponseDto dispatchResponseDto = JSON.parseObject(result, DispatchResponseDto.class); DispatchResponseDto dispatchResponseDto = JSON.parseObject(result, DispatchResponseDto.class);
JobTaskRunLogServiceImpl mythJobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class); JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
JobTaskRunLog jobTaskRunLog = new JobTaskRunLog(); JobTaskRunLog jobTaskRunLog = new JobTaskRunLog();
jobTaskRunLog.setLogId(mythJobTaskSchedule.getLogId()); jobTaskRunLog.setLogId(mythJobTaskSchedule.getLogId());
//版本id需要查验 //版本id需要查验
//还需要携带版本的名字 //还需要携带版本的名字
jobTaskRunLog.setRunType("2"); jobTaskRunLog.setRunType("2");
jobTaskRunLog.setJobType("BEAN");
jobTaskRunLog.setLocalNodeHandlerName(mythJobTaskSchedule.getLocalNodeHandlerName()); jobTaskRunLog.setLocalNodeHandlerName(mythJobTaskSchedule.getLocalNodeHandlerName());
jobTaskRunLog.setTriggerTime(new Date()); jobTaskRunLog.setTriggerTime(new Date());
jobTaskRunLog.setTriggerCode(dispatchResponseDto.getCode()); jobTaskRunLog.setTriggerCode(dispatchResponseDto.getCode());
jobTaskRunLog.setTriggerMsg(dispatchResponseDto.getMsg()); jobTaskRunLog.setTriggerMsg(dispatchResponseDto.getMsg());
mythJobTaskRunLogService.saveJobTaskRunLog(jobTaskRunLog); jobTaskRunLogService.updateJobTaskRunLog(jobTaskRunLog);
} }
} }
...@@ -246,7 +246,7 @@ public class JobScheduleHelper{ ...@@ -246,7 +246,7 @@ public class JobScheduleHelper{
Integer logId = saveLog(mythJobTaskSchedule); Integer logId = saveLog(mythJobTaskSchedule);
mythJobTaskSchedule.setLogId(logId); mythJobTaskSchedule.setLogId(logId);
JavaBeanJobTask javaBeanJobTask = new JavaBeanJobTask(mythJobTaskSchedule); JavaBeanJobTask javaBeanJobTask = new JavaBeanJobTask(mythJobTaskSchedule);
jobTaskScheduleService.delete(mythJobTaskSchedule.getNodeId()); jobTaskScheduleService.delete(mythJobTaskSchedule.getId());
WorkRoulette.addJob(javaBeanJobTask,mythJobTaskSchedule.getTriggerNextTime()); WorkRoulette.addJob(javaBeanJobTask,mythJobTaskSchedule.getTriggerNextTime());
} }
}); });
......
...@@ -30,6 +30,6 @@ public class LogCallbackThread implements Runnable { ...@@ -30,6 +30,6 @@ public class LogCallbackThread implements Runnable {
jobTaskRunLog.setRunTime(jobRunResultDto.getEndTime()); jobTaskRunLog.setRunTime(jobRunResultDto.getEndTime());
jobTaskRunLog.setRunCode(jobRunResultDto.getReturnResult().getCode()); jobTaskRunLog.setRunCode(jobRunResultDto.getReturnResult().getCode());
jobTaskRunLog.setRunMsg(jobRunResultDto.getReturnResult().getMsg()); jobTaskRunLog.setRunMsg(jobRunResultDto.getReturnResult().getMsg());
mythJobTaskRunLogService.saveJobTaskRunLog(jobTaskRunLog); mythJobTaskRunLogService.updateJobTaskRunLog(jobTaskRunLog);
} }
} }
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
) )
</insert> </insert>
<insert id="insertSelective" parameterType="com.byit.model.JobTaskRunLog" useGeneratedKeys="true" keyProperty="id" keyColumn="log_id"> <insert id="insertSelective" parameterType="com.byit.model.JobTaskRunLog" useGeneratedKeys="true" keyProperty="logId" keyColumn="log_id">
insert into job_task_run_log insert into job_task_run_log
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="logId != null"> <if test="logId != null">
......
package com.byit.job.dto; package com.byit.job.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* @program: byit-myth-job->DispatchResponseDto * @program: byit-myth-job->DispatchResponseDto
...@@ -9,6 +12,9 @@ import lombok.Data; ...@@ -9,6 +12,9 @@ import lombok.Data;
* @date: 2019/12/23 11:12 * @date: 2019/12/23 11:12
**/ **/
@Data @Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DispatchResponseDto { public class DispatchResponseDto {
private String code; private String code;
private String msg; private String msg;
......
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