新增执行线程日志记录
parent
de0e7d69af
commit
d5f3e34a8c
|
@ -0,0 +1,72 @@
|
|||
package com.muyu.quest.domain;
|
||||
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 任务执行记录对象 task_export
|
||||
*
|
||||
* @author 2112A
|
||||
* @date 2024-09-06
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("task_export")
|
||||
public class TaskExport implements Serializable {
|
||||
|
||||
/** ID */
|
||||
@TableId( type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 任务编码 */
|
||||
@Excel(name = "任务编码")
|
||||
private String taskCode;
|
||||
/** 执行编码 */
|
||||
@Excel(name = "执行编码")
|
||||
private String exportCode;
|
||||
|
||||
/** 执行SQL */
|
||||
@Excel(name = "执行SQL")
|
||||
private String addSql;
|
||||
|
||||
/** 执行状态 */
|
||||
@Excel(name = "执行状态")
|
||||
private Integer start;
|
||||
|
||||
/** 失败原因 */
|
||||
@Excel(name = "失败原因")
|
||||
private String error;
|
||||
|
||||
public TaskExport(String taskCode,String exportCode, String addSql, Integer start, String error) {
|
||||
this.taskCode = taskCode;
|
||||
this.exportCode = exportCode;
|
||||
this.addSql = addSql;
|
||||
this.start = start;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("taskCode", getTaskCode())
|
||||
.append("addSql", getAddSql())
|
||||
.append("start", getStart())
|
||||
.append("error", getError())
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.muyu.quest.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.quest.domain.TaskExport;
|
||||
import com.muyu.quest.service.ITaskExportService;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 任务执行记录Controller
|
||||
*
|
||||
* @author 2112A
|
||||
* @date 2024-09-06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/export")
|
||||
public class TaskExportController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private ITaskExportService taskExportService;
|
||||
|
||||
/**
|
||||
* 查询任务执行记录列表
|
||||
*/
|
||||
@RequiresPermissions("quest:export:list")
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<TaskExport>> list(TaskExport taskExport)
|
||||
{
|
||||
startPage();
|
||||
List<TaskExport> list = taskExportService.selectTaskExportList(taskExport);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出任务执行记录列表
|
||||
*/
|
||||
@RequiresPermissions("quest:export:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, TaskExport taskExport)
|
||||
{
|
||||
List<TaskExport> list = taskExportService.selectTaskExportList(taskExport);
|
||||
ExcelUtil<TaskExport> util = new ExcelUtil<TaskExport>(TaskExport.class);
|
||||
util.exportExcel(response, list, "任务执行记录数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务执行记录详细信息
|
||||
*/
|
||||
@RequiresPermissions("quest:export:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result<List<TaskExport>> getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(taskExportService.selectTaskExportById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增任务执行记录
|
||||
*/
|
||||
@RequiresPermissions("quest:export:add")
|
||||
@PostMapping
|
||||
public Result<Integer> add(
|
||||
@Validated @RequestBody TaskExport taskExport)
|
||||
{
|
||||
if (taskExportService.checkIdUnique(taskExport)) {
|
||||
return error("新增 任务执行记录 '" + taskExport + "'失败,任务执行记录已存在");
|
||||
}
|
||||
return toAjax(taskExportService.save(taskExport));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改任务执行记录
|
||||
*/
|
||||
@RequiresPermissions("quest:export:edit")
|
||||
@PutMapping
|
||||
public Result<Integer> edit(
|
||||
@Validated @RequestBody TaskExport taskExport)
|
||||
{
|
||||
if (!taskExportService.checkIdUnique(taskExport)) {
|
||||
return error("修改 任务执行记录 '" + taskExport + "'失败,任务执行记录不存在");
|
||||
}
|
||||
return toAjax(taskExportService.updateById(taskExport));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务执行记录
|
||||
*/
|
||||
@RequiresPermissions("quest:export:remove")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
|
||||
{
|
||||
taskExportService.removeBatchByIds(Arrays.asList(ids));
|
||||
return success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.quest.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.muyu.quest.domain.TaskExport;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 任务执行记录Mapper接口
|
||||
*
|
||||
* @author 2112A
|
||||
* @date 2024-09-06
|
||||
*/
|
||||
@Mapper
|
||||
public interface TaskExportMapper extends BaseMapper<TaskExport>{
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.quest.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.muyu.quest.domain.TaskExport;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 任务执行记录Service接口
|
||||
*
|
||||
* @author 2112A
|
||||
* @date 2024-09-06
|
||||
*/
|
||||
public interface ITaskExportService extends IService<TaskExport> {
|
||||
/**
|
||||
* 精确查询任务执行记录
|
||||
*
|
||||
* @param id 任务执行记录主键
|
||||
* @return 任务执行记录
|
||||
*/
|
||||
public TaskExport selectTaskExportById(Long id);
|
||||
|
||||
/**
|
||||
* 查询任务执行记录列表
|
||||
*
|
||||
* @param taskExport 任务执行记录
|
||||
* @return 任务执行记录集合
|
||||
*/
|
||||
public List<TaskExport> selectTaskExportList(TaskExport taskExport);
|
||||
|
||||
/**
|
||||
* 判断 任务执行记录 id是否唯一
|
||||
* @param taskExport 任务执行记录
|
||||
* @return 结果
|
||||
*/
|
||||
Boolean checkIdUnique(TaskExport taskExport);
|
||||
|
||||
|
||||
/**
|
||||
* 条件精确查询
|
||||
*/
|
||||
TaskExport selectTaskExport(TaskExport taskExport);
|
||||
|
||||
void updateByExportCode(TaskExport entity);
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.muyu.quest.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.quest.mapper.TaskExportMapper;
|
||||
import com.muyu.quest.domain.TaskExport;
|
||||
import com.muyu.quest.service.ITaskExportService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* 任务执行记录Service业务层处理
|
||||
*
|
||||
* @author 2112A
|
||||
* @date 2024-09-06
|
||||
*/
|
||||
@Service
|
||||
public class TaskExportServiceImpl
|
||||
extends ServiceImpl<TaskExportMapper, TaskExport>
|
||||
implements ITaskExportService {
|
||||
|
||||
/**
|
||||
* 精确查询任务执行记录
|
||||
*
|
||||
* @param id 任务执行记录主键
|
||||
* @return 任务执行记录
|
||||
*/
|
||||
@Override
|
||||
public TaskExport selectTaskExportById(Long id)
|
||||
{
|
||||
LambdaQueryWrapper<TaskExport> queryWrapper = new LambdaQueryWrapper<>();
|
||||
Assert.notNull(id, "id不可为空");
|
||||
queryWrapper.eq(TaskExport::getId, id);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询任务执行记录列表
|
||||
*
|
||||
* @param taskExport 任务执行记录
|
||||
* @return 任务执行记录
|
||||
*/
|
||||
@Override
|
||||
public List<TaskExport> selectTaskExportList(TaskExport taskExport)
|
||||
{
|
||||
LambdaQueryWrapper<TaskExport> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(taskExport.getTaskCode())){
|
||||
queryWrapper.eq(TaskExport::getTaskCode, taskExport.getTaskCode());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(taskExport.getAddSql())){
|
||||
queryWrapper.eq(TaskExport::getAddSql, taskExport.getAddSql());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(taskExport.getError())){
|
||||
queryWrapper.eq(TaskExport::getError, taskExport.getError());
|
||||
}
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 唯一 判断
|
||||
* @param taskExport 任务执行记录
|
||||
* @return 任务执行记录
|
||||
*/
|
||||
@Override
|
||||
public Boolean checkIdUnique(TaskExport taskExport) {
|
||||
LambdaQueryWrapper<TaskExport> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TaskExport::getId, taskExport.getId());
|
||||
return this.count(queryWrapper) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExport selectTaskExport(TaskExport taskExport) {
|
||||
LambdaQueryWrapper<TaskExport> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(taskExport.getTaskCode())){
|
||||
queryWrapper.eq(TaskExport::getTaskCode, taskExport.getTaskCode());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(taskExport.getAddSql())){
|
||||
queryWrapper.eq(TaskExport::getAddSql, taskExport.getAddSql());
|
||||
}
|
||||
if (taskExport.getStart() != null){
|
||||
queryWrapper.eq(TaskExport::getStart, taskExport.getStart());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(taskExport.getError())){
|
||||
queryWrapper.eq(TaskExport::getError, taskExport.getError());
|
||||
}
|
||||
queryWrapper.last("limit 1");
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateByExportCode(TaskExport taskExport) {
|
||||
LambdaUpdateWrapper<TaskExport> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(TaskExport::getExportCode, taskExport.getExportCode())
|
||||
.set(TaskExport::getError, taskExport.getError())
|
||||
.set(TaskExport::getStart, taskExport.getStart());
|
||||
this.update(null, updateWrapper);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,12 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.quest.domain.*;
|
||||
import com.muyu.quest.manager.TaskManager;
|
||||
import com.muyu.quest.model.DataModel;
|
||||
import com.muyu.quest.model.DataValueModel;
|
||||
import com.muyu.quest.domain.Node;
|
||||
import com.muyu.quest.domain.NodeDisposition;
|
||||
import com.muyu.quest.domain.NodeType;
|
||||
import com.muyu.quest.exception.TaskException;
|
||||
import com.muyu.quest.remote.RemoteDataSourceService;
|
||||
import com.muyu.quest.req.NodeReq;
|
||||
|
@ -19,11 +17,11 @@ import com.muyu.quest.req.TaskReq;
|
|||
import com.muyu.quest.resp.TaskResp;
|
||||
import com.muyu.quest.service.INodeDispositionService;
|
||||
import com.muyu.quest.service.INodeService;
|
||||
import com.muyu.quest.service.ITaskExportService;
|
||||
import com.muyu.quest.utils.NodeUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.muyu.quest.mapper.TaskMapper;
|
||||
import com.muyu.quest.domain.Task;
|
||||
import com.muyu.quest.service.TaskService;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -49,6 +47,8 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
|
|||
private TaskMapper taskMapper;
|
||||
@Resource
|
||||
private RemoteDataSourceService remoteDataSourceService;
|
||||
@Resource
|
||||
private ITaskExportService taskExportService;
|
||||
|
||||
private final static TaskManager taskManager = TaskManager.getTaskManager();
|
||||
|
||||
|
@ -160,15 +160,21 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
|
|||
int index = i+1;
|
||||
// 添加进入任务队列
|
||||
taskManager.execute(() -> {
|
||||
String exportCode = UUID.randomUUID().toString().replace("-","");
|
||||
// 获取新SQL 并执行
|
||||
String sql = findSql + " LIMIT 1000 OFFSET "+(index-1)*1000;
|
||||
log.info("任务 {} 开始执行第 {} 线程,查询SQL: {}",taskCode,index, sql);
|
||||
String addSql = getAddSql(nodeMap, sql);
|
||||
log.info("任务 {} 开始执行第 {} 线程,新增SQL: {}",taskCode,index, addSql);
|
||||
TaskExport entity = new TaskExport(taskCode,exportCode, sql, 0, "");
|
||||
taskExportService.save(entity);
|
||||
Result addResult = remoteDataSourceService.addTableValue(new DataValueModel(4L, addSql));
|
||||
log.info("任务 {} 第 {} 线程执行结果 {}",taskCode,index,addResult);
|
||||
if (addResult.getCode() != 200){
|
||||
throw new TaskException(addResult.getMsg());
|
||||
entity.setError(addResult.getMsg());
|
||||
entity.setStart(2);
|
||||
}else {
|
||||
entity.setStart(1);
|
||||
}
|
||||
taskExportService.updateByExportCode(entity);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.quest.mapper.TaskExportMapper">
|
||||
|
||||
<resultMap type="TaskExport" id="TaskExportResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="taskCode" column="taskCode" />
|
||||
<result property="sql" column="sql" />
|
||||
<result property="start" column="start" />
|
||||
<result property="error" column="error" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectTaskExportVo">
|
||||
select id, taskCode, sql, start, error from task_export
|
||||
</sql>
|
||||
|
||||
<select id="selectTaskExportList" parameterType="TaskExport" resultMap="TaskExportResult">
|
||||
<include refid="selectTaskExportVo"/>
|
||||
<where>
|
||||
<if test="taskCode != null and taskCode != ''"> and taskCode = #{taskCode}</if>
|
||||
<if test="sql != null and sql != ''"> and sql = #{sql}</if>
|
||||
<if test="start != null and start != ''"> and start = #{start}</if>
|
||||
<if test="error != null and error != ''"> and error = #{error}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectTaskExportById" parameterType="Long" resultMap="TaskExportResult">
|
||||
<include refid="selectTaskExportVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertTaskExport" parameterType="TaskExport">
|
||||
insert into task_export
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="taskCode != null">taskCode,</if>
|
||||
<if test="sql != null">sql,</if>
|
||||
<if test="start != null">start,</if>
|
||||
<if test="error != null">error,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="taskCode != null">#{taskCode},</if>
|
||||
<if test="sql != null">#{sql},</if>
|
||||
<if test="start != null">#{start},</if>
|
||||
<if test="error != null">#{error},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateTaskExport" parameterType="TaskExport">
|
||||
update task_export
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="taskCode != null">taskCode = #{taskCode},</if>
|
||||
<if test="sql != null">sql = #{sql},</if>
|
||||
<if test="start != null">start = #{start},</if>
|
||||
<if test="error != null">error = #{error},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteTaskExportById" parameterType="Long">
|
||||
delete from task_export where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteTaskExportByIds" parameterType="String">
|
||||
delete from task_export where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
Loading…
Reference in New Issue