小车车 3 місяців тому
батько
коміт
f63c2e55bb

+ 3 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/sop/vo/SopExecutionPlanRespVO.java

@@ -75,6 +75,9 @@ public class SopExecutionPlanRespVO {
     @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
+    @Schema(description = "启用计划执行(0不启用 1启用)")
+    private Integer enableExecutionPlan;
+
     @Schema(description = "预览数据")
     private List<SopPreviewDataVO> previewDataList;
 

+ 6 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/dal/mysql/sop/SopExecutionPlanMapper.java

@@ -4,8 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopExecutionPlanPageReqVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopExecutionPlanRespVO;
 import cn.iocoder.yudao.module.iscs.dal.dataobject.sop.SopExecutionPlanDO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * SOP计划执行 Mapper
@@ -30,4 +34,6 @@ public interface SopExecutionPlanMapper extends BaseMapperX<SopExecutionPlanDO>
                 .orderByDesc(SopExecutionPlanDO::getId));
     }
 
+    List<SopExecutionPlanRespVO> getList(@Param(value = "vo") SopExecutionPlanRespVO vo);
+
 }

+ 65 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/job/SopExecutionPlanJob.java

@@ -0,0 +1,65 @@
+package cn.iocoder.yudao.module.iscs.job;
+
+import cn.hutool.core.date.DateUtil;
+import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
+import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
+import cn.iocoder.yudao.module.infra.service.job.JobLogService;
+import cn.iocoder.yudao.module.iscs.controller.admin.jobticket.vo.JobTicketSaveReqVO;
+import cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopExecutionPlanRespVO;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.sop.SopDO;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.sop.SopExecutionPlanDO;
+import cn.iocoder.yudao.module.iscs.service.jobticket.JobTicketService;
+import cn.iocoder.yudao.module.iscs.service.sop.SopExecutionPlanService;
+import cn.iocoder.yudao.module.iscs.service.sop.SopService;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * SOP执行计划任务
+ *
+ * @author cgj
+ */
+@Slf4j
+@Component
+public class SopExecutionPlanJob implements JobHandler {
+
+    @Resource
+    private SopExecutionPlanService sopExecutionPlanService;
+    @Resource
+    private SopService sopService;
+    @Resource
+    private JobTicketService jobTicketService;
+
+    /**
+     * 查找需要执行的数据,生成作业
+     *
+     * @param param 参数
+     * @return
+     */
+
+    @Override
+    @TenantIgnore
+    public String execute(String param) {
+        String yyyymmdd = DateUtil.format(new Date(), "yyyy-MM-dd");
+        SopExecutionPlanRespVO sopExecutionPlanRespVO = new SopExecutionPlanRespVO();
+        sopExecutionPlanRespVO.setNextExecutDate(yyyymmdd);
+        List<SopExecutionPlanRespVO> list = sopExecutionPlanService.getList(sopExecutionPlanRespVO);
+        for (SopExecutionPlanRespVO executionPlanRespVO : list) {
+            if (executionPlanRespVO.getEnableExecutionPlan() != null && executionPlanRespVO.getEnableExecutionPlan().equals(1)) {
+                // 开始生成作业
+                JobTicketSaveReqVO jobTicketSaveReqVO = new JobTicketSaveReqVO();
+                jobTicketSaveReqVO.setSopId(executionPlanRespVO.getSopId());
+                jobTicketService.insertJobTicketBySop(jobTicketSaveReqVO);
+
+            }
+        }
+        return String.format("定时执行清理定时任务日志数量 %s 个", 1);
+    }
+
+}

+ 2 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/sop/SopExecutionPlanService.java

@@ -72,4 +72,6 @@ public interface SopExecutionPlanService extends IService<SopExecutionPlanDO> {
      */
     PageResult<SopExecutionPlanDO> getSopExecutionPlanPage(SopExecutionPlanPageReqVO pageReqVO);
 
+    List<SopExecutionPlanRespVO> getList(SopExecutionPlanRespVO vo);
+
 }

+ 5 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/sop/SopExecutionPlanServiceImpl.java

@@ -350,4 +350,9 @@ public class SopExecutionPlanServiceImpl extends ServiceImpl<SopExecutionPlanMap
         return sopExecutionPlanMapper.selectPage(pageReqVO);
     }
 
+    @Override
+    public List<SopExecutionPlanRespVO> getList(SopExecutionPlanRespVO vo) {
+        return sopExecutionPlanMapper.getList(vo);
+    }
+
 }

+ 16 - 2
yudao-module-iscs/src/main/resources/mapper/SopExecutionPlanMapper.xml

@@ -1,6 +1,6 @@
 <?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="cn.iocoder.yudao.module.iscs.dal.mysql.sopexecutionplan.SopExecutionPlanMapper">
+<mapper namespace="cn.iocoder.yudao.module.iscs.dal.mysql.sop.SopExecutionPlanMapper">
 
     <!--
         一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
@@ -9,4 +9,18 @@
         文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
      -->
 
-</mapper>
+    <select id="getList"
+            resultType="cn.iocoder.yudao.module.iscs.controller.admin.sop.vo.SopExecutionPlanRespVO">
+        SELECT
+            e.*,
+            s.enable_execution_plan
+        FROM
+            isc_sop_execution_plan e
+                LEFT JOIN isc_sop s ON s.id = e.sop_id
+        <where>
+            <if test="vo.nextExecutDate != null and vo.nextExecutDate.trim != ''">
+                e.next_execut_date #{vo.nextExecutDate}
+            </if>
+        </where>
+    </select>
+</mapper>