luowei 2 роки тому
батько
коміт
5fd3c552c6

+ 4 - 1
project_data/sql/0.0.2/quartz/quartz.sql

@@ -1,7 +1,10 @@
-delete from sys_job where job_id in(129,128,125,138);
+delete from sys_job where job_id in(129,128,125,138,168,169,170);
 INSERT INTO `sys_job`(`job_id`, `job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (129, '恶劣天气预警', 'DEFAULT', 'WeatherTask.getDataFromApi', '0 0 7,10,14,17 * * ? *', '1', '1', '0', '超级管理员', '2023-09-25 11:46:50', '', NULL);
 INSERT INTO `sys_job` VALUES (128, '履职临期提醒(除了每日的)', 'DEFAULT', 'CoreMessageSendTask.resumptionRemind', '0 0 0 * * ?', '1', '1', '0', '超级管理员', '2023-09-22 17:03:31', '', '2023-09-22 20:29:13');
 INSERT INTO `sys_job` VALUES (125, '消息发送管理(每日凌晨零点)', 'DEFAULT', 'CoreMessageSendTask.messageSendTask', '0 0 0 * * ? *', '1', '1', '0', '超级管理员', '2023-09-21 12:30:22', '超级管理员', '2023-09-22 19:04:39');
+INSERT INTO `sys_job` VALUES (168, '评价计划每季度生成', 'DEFAULT', 'CoreEvaluatePlanTask.evaluateQuarterTask', '0 0 0 1 1/3 ?', '1', '1', '0', '超级管理员', '2023-09-21 12:30:22', '超级管理员', '2023-09-22 19:04:39');
+INSERT INTO `sys_job` VALUES (169, '评价计划每月生成', 'DEFAULT', 'CoreEvaluatePlanTask.evaluateMonthTask', '0 0 0 1 1/1 ?', '1', '1', '0', '超级管理员', '2023-09-21 12:30:22', '超级管理员', '2023-09-22 19:04:39');
+INSERT INTO `sys_job` VALUES (170, '评价计划每年生成', 'DEFAULT', 'CoreEvaluatePlanTask.evaluateYearTask', '0 0 0 1 1 ? 2023/1', '1', '1', '0', '超级管理员', '2023-09-21 12:30:22', '超级管理员', '2023-09-22 19:04:39');
 
 INSERT INTO `sys_job` VALUES (138, '回归未完成的调阅任务', 'DEFAULT', 'CoreMessageSendTask.initializationAccess', '0 0 0 * * ? *', '1', '1', '0', '超级管理员', '2023-09-21 12:30:22', '超级管理员', '2023-09-22 19:04:39');
 delete from `sys_job` where job_name='生成每周安全检查任务';

+ 1 - 0
project_data/sql/0.0.2/soc/soc.sql

@@ -119,6 +119,7 @@ CREATE TABLE `core_evaluate_task` (
                                       `org_id` BIGINT DEFAULT NULL COMMENT '机构id',
                                       `status` VARCHAR ( 2 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '状态0待1中2完成',
                                       `org_name` VARCHAR ( 255 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '机构名称',
+                                      `org_path` VARCHAR ( 255 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '机构路径',
                                       `evaluate_name` VARCHAR ( 255 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '外包评价名称',
                                       `role_name` VARCHAR ( 255 ) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '角色',
                                       `create_time` DATETIME NULL DEFAULT NULL COMMENT '创建时间',

+ 21 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteCoreEvaluatePlanService.java

@@ -0,0 +1,21 @@
+package com.xunmei.system.api;
+
+import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.constant.ServiceNameConstants;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.factory.RemoteCoreEvaluatePlanFallbackFactory;
+import com.xunmei.system.api.factory.RemoteRetrievalTaskFallbackFactory;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author :LuoWei
+ * @date : 2023/10/12
+ */
+@FeignClient(contextId = "remoteCoreEvaluatePlanService", value = ServiceNameConstants.CORE_SERVICE)
+public interface RemoteCoreEvaluatePlanService {
+    @GetMapping("/evaluatePlan/generate")
+    AjaxResult generate(@RequestParam("cycle") String cycle, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+}

+ 28 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteCoreEvaluatePlanFallbackFactory.java

@@ -0,0 +1,28 @@
+package com.xunmei.system.api.factory;
+
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.RemoteCoreEvaluatePlanService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cloud.openfeign.FallbackFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author :LuoWei
+ * @date : 2023/10/12
+ */
+@Component
+public class RemoteCoreEvaluatePlanFallbackFactory implements FallbackFactory<RemoteCoreEvaluatePlanService> {
+    private static final Logger log = LoggerFactory.getLogger(RemoteCoreEvaluatePlanFallbackFactory.class);
+
+    @Override
+    public RemoteCoreEvaluatePlanService create(Throwable cause) {
+        log.error("用户角色服务调用失败:{}", cause.getMessage());
+        return new RemoteCoreEvaluatePlanService() {
+            @Override
+            public AjaxResult generate(String cycle, String source) {
+                return null;
+            }
+        };
+    }
+}

+ 19 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/evaluate/controller/CoreEvaluatePlanController.java

@@ -6,6 +6,7 @@ import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.log.annotation.Log;
 import com.xunmei.common.log.enums.BusinessType;
+import com.xunmei.common.security.annotation.InnerAuth;
 import com.xunmei.common.security.annotation.RequiresPermissions;
 import com.xunmei.core.evaluate.domain.CoreEvaluatePlan;
 import com.xunmei.core.evaluate.dto.CoreEvaluatePlanDTO;
@@ -16,6 +17,8 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.time.LocalDate;
+
 /**
  * 外包评价计划Controller
  *
@@ -67,7 +70,22 @@ public class CoreEvaluatePlanController extends BaseController {
     public AjaxResult add(@RequestBody CoreEvaluatePlanDTO coreEvaluatePlan) {
         return toAjax(coreEvaluatePlanService.insertCoreEvaluatePlan(coreEvaluatePlan));
     }
-
+    /**
+     * 每季度生成
+     * @param cycle
+     * @return
+     */
+    @InnerAuth
+    @GetMapping("/generate")
+    public AjaxResult generate(@RequestParam(value = "cycle", required = false) String cycle) {
+        try {
+            coreEvaluatePlanService.generate(cycle);
+            return AjaxResult.success("任务生成成功");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return AjaxResult.error("任务生成失败" + e.getMessage());
+        }
+    }
     /**
      * 修改外包评价计划
      */

+ 2 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/evaluate/domain/CoreEvaluateTask.java

@@ -48,7 +48,8 @@ private String evaluateBy;
     /** 机构名称 */
             @ApiModelProperty(value = "机构名称")
     private String orgName;
-
+            @ApiModelProperty(value = "机构路径")
+            private String orgPath;
     /** 外包评价名称 */
             @ApiModelProperty(value = "外包评价名称")
     private String evaluateName;

+ 6 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/evaluate/mapper/CoreEvaluatePlanMapper.java

@@ -70,4 +70,10 @@ public interface CoreEvaluatePlanMapper extends BaseMapper<CoreEvaluatePlan> {
 
     Page<CoreEvaluatePlanListVO> selectPageList(@Param("page") Page<CoreEvaluatePlanListVO> page, @Param("request") EvaluateQueryDTO request);
 
+    /**
+     * 查出已下发同一类型的计划
+     * @param cycle
+     * @return
+     */
+    List<CoreEvaluatePlan>selectPlanByCycle(String cycle);
 }

+ 12 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/evaluate/service/ICoreEvaluatePlanService.java

@@ -52,9 +52,21 @@ public interface ICoreEvaluatePlanService extends IService<CoreEvaluatePlan> {
      */
     int updateCoreEvaluatePlan(CoreEvaluatePlanDTO coreEvaluatePlanDTO);
 
+    /**
+     * 手动下发
+     * @param id
+     * @return
+     */
     int distribute(Long id);
 
     /**
+     * 定时
+     * @param cycle
+     */
+    void generate(String cycle);
+
+
+    /**
      * 批量删除外包评价计划
      *
      * @param ids 需要删除的外包评价计划主键集合

+ 70 - 20
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/evaluate/service/impl/CoreEvaluatePlanServiceImpl.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.ErrorMsgConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.utils.DateUtils;
+import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.core.evaluate.domain.*;
@@ -22,6 +23,7 @@ import com.xunmei.core.evaluate.service.ICoreEvaluateTaskService;
 import com.xunmei.core.evaluate.vo.CoreEvaluatePlanListVO;
 import com.xunmei.core.evaluate.vo.CoreEvaluatePlanVO;
 import com.xunmei.system.api.RemoteOrgService;
+import com.xunmei.system.api.RemoteRoleService;
 import com.xunmei.system.api.RemoteUserService;
 import com.xunmei.system.api.domain.SysOrg;
 import com.xunmei.system.api.domain.SysUser;
@@ -63,6 +65,8 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
     private RemoteOrgService orgService;
     @Autowired
     private ICoreEvaluateTaskService coreEvaluateTaskService;
+    @Autowired
+    private RemoteRoleService remoteRoleService;
 
     /**
      * 查询外包评价计划
@@ -108,6 +112,9 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
      */
     @Override
     public int insertCoreEvaluatePlan(CoreEvaluatePlanDTO coreEvaluatePlanDTO) {
+        if (!check(SecurityUtils.getUserId())) {
+            throw new RuntimeException("该角色没有新增权限");
+        }
         CoreEvaluatePlan coreEvaluatePlan = new CoreEvaluatePlan();
         BeanUtils.copyProperties(coreEvaluatePlanDTO, coreEvaluatePlan);
         coreEvaluatePlan.setCreateTime(DateUtils.getNowDate());
@@ -119,7 +126,7 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
         coreEvaluatePlan.setOrgPath(sysOrg.getPath());
         long planId = IdWorker.getId();
         coreEvaluatePlan.setId(planId);
-        int insert = 0;
+        int insert;
         //主体
         insert = coreEvaluatePlanMapper.insert(coreEvaluatePlan);
         //角色
@@ -139,12 +146,36 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
             coreEvaluatePlanContent.setEvaluateId(planId);
             coreEvaluatePlanContentMapper.insert(coreEvaluatePlanContent);
         });
-        if (coreEvaluatePlanDTO.getBuildTaskNow()){
+  /*      if (coreEvaluatePlanDTO.getBuildTaskNow()) {
             this.distribute(planId);
-        }
+        }*/
         return insert;
     }
 
+    private boolean check(Long userId) {
+        String s = remoteRoleService.selectRoleNameByUserId(userId, SecurityConstants.INNER);
+        boolean admin = false;
+        if (StringUtils.isNotEmpty(s)) {
+            int i = s.indexOf(",");
+            if (i >= 0) {
+                String[] split = s.split(",");
+                for (int l = 0; l < split.length; l++) {
+                    if (split[l].equals("省联社安全保卫管理人员") || split[l].equals("超级管理员")
+                            || split[l].equals("行社安全保卫管理人员")) {
+                        admin = true;
+                        break;
+                    }
+                }
+            } else if (s.equals("省联社安全保卫管理人员") || s.equals("超级管理员") || s.equals("行社安全保卫管理人员")
+            ) {
+                admin = true;
+            }
+        } else if (SecurityUtils.getUserId() == 1) {
+            admin = true;
+        }
+        return admin;
+    }
+
     /**
      * 修改外包评价计划
      *
@@ -153,6 +184,9 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
      */
     @Override
     public int updateCoreEvaluatePlan(CoreEvaluatePlanDTO coreEvaluatePlanDTO) {
+        if (!check(SecurityUtils.getUserId())) {
+            throw new RuntimeException("该角色没有修改权限");
+        }
         //删除未完成任务
         List status = new ArrayList();
         status.add("0");
@@ -189,12 +223,16 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
             coreEvaluatePlanContent.setEvaluateId(coreEvaluatePlanDTO.getId());
             coreEvaluatePlanContentMapper.insert(coreEvaluatePlanContent);
         });
+      /*  if (coreEvaluatePlanDTO.getBuildTaskNow()) {
+            this.distribute(coreEvaluatePlanDTO.getId());
+        }*/
         return i;
     }
 
     @Override
     public int distribute(Long id) {
         CoreEvaluatePlanVO coreEvaluatePlanVO = this.selectCoreEvaluatePlanById(id);
+        CoreEvaluatePlan coreEvaluatePlan = baseMapper.selectById(id);
         SysOrg org = new SysOrg();
         org.setType(Integer.valueOf(coreEvaluatePlanVO.getOrgType()));
         org.setPath(coreEvaluatePlanVO.getOrgPath());
@@ -211,7 +249,7 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
                 time = 13;
                 break;
         }
-        int i = 1;
+        int i;
         LocalDate localDate = getTime(time);
         String firstDay = DateUtils.parseDateToStr("yyyy-MM-dd 23:59:59", Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
         SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -221,27 +259,39 @@ public class CoreEvaluatePlanServiceImpl extends ServiceImpl<CoreEvaluatePlanMap
         } catch (Exception e) {
             e.getMessage();
         }
-        for (SysOrg l : list) {
-            CoreEvaluateTask coreEvaluateTask = new CoreEvaluateTask();
-            coreEvaluateTask.setPlanId(id);
-            coreEvaluateTask.setOrgId(l.getId());
-            coreEvaluateTask.setStatus("0");
-            coreEvaluateTask.setOrgName(l.getShortName());
-            coreEvaluateTask.setEvaluateName(coreEvaluatePlanVO.getEvaluateName());
-            coreEvaluateTask.setCreateTime(DateUtils.getNowDate());
-            coreEvaluateTask.setCreateBy(coreEvaluatePlanVO.getCreateBy());
-            coreEvaluateTask.setStartTime(DateUtils.getNowDate());
-            coreEvaluateTask.setEndTime(endTime);
-            i = coreEvaluateTaskService.insertCoreEvaluateTask(coreEvaluateTask);
-            if (i < 1) {
-                return i;
+        //如果立即执行
+        if (coreEvaluatePlan.getBuildTaskNow()) {
+            for (SysOrg l : list) {
+                CoreEvaluateTask coreEvaluateTask = new CoreEvaluateTask();
+                coreEvaluateTask.setPlanId(id);
+                coreEvaluateTask.setOrgId(l.getId());
+                coreEvaluateTask.setStatus("0");
+                coreEvaluateTask.setOrgName(l.getShortName());
+                coreEvaluateTask.setOrgPath(l.getPath());
+                coreEvaluateTask.setEvaluateName(coreEvaluatePlanVO.getEvaluateName());
+                coreEvaluateTask.setCreateTime(DateUtils.getNowDate());
+                coreEvaluateTask.setCreateBy(coreEvaluatePlanVO.getCreateBy());
+                coreEvaluateTask.setStartTime(DateUtils.getNowDate());
+                coreEvaluateTask.setEndTime(endTime);
+                i = coreEvaluateTaskService.insertCoreEvaluateTask(coreEvaluateTask);
+                if (i < 1) {
+                    return i;
+                }
             }
         }
-        CoreEvaluatePlan coreEvaluatePlan = baseMapper.selectById(id);
         coreEvaluatePlan.setIsDistribute("1");
-        baseMapper.updateById(coreEvaluatePlan);
+        i = baseMapper.updateById(coreEvaluatePlan);
         return i;
     }
+
+    @Override
+    public void generate(String cycle) {
+        List<CoreEvaluatePlan> coreEvaluatePlans = baseMapper.selectPlanByCycle(cycle);
+        coreEvaluatePlans.forEach(c -> {
+            distribute(c.getId());
+        });
+    }
+
     public LocalDate getTime(int time) {
         LocalDate localDate = LocalDate.now();
         LocalDate nextMonthFirstDay = localDate.plusMonths(time).withDayOfMonth(1);

+ 10 - 0
soc-modules/soc-modules-core/src/main/resources/mapper/evaluate/CoreEvaluatePlanMapper.xml

@@ -99,6 +99,16 @@
         a.id
         ORDER BY a.create_time DESC
     </select>
+    <select id="selectPlanByCycle" resultType="com.xunmei.core.evaluate.domain.CoreEvaluatePlan">
+        SELECT
+            *
+        FROM
+            core_evaluate_plan
+        WHERE
+            is_distribute = '1'
+          AND
+            evaluate_cycle = #{cycle}
+    </select>
 
     <insert id="insertCoreEvaluatePlan" parameterType="com.xunmei.core.evaluate.domain.CoreEvaluatePlan">
         insert into core_evaluate_plan

+ 54 - 0
soc-modules/soc-modules-job/src/main/java/com/xunmei/job/task/CoreEvaluatePlanTask.java

@@ -0,0 +1,54 @@
+package com.xunmei.job.task;
+
+import cn.hutool.core.lang.UUID;
+import com.alibaba.fastjson.JSON;
+import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.RemoteCoreEvaluatePlanService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+/**
+ * @author :LuoWei
+ * @date : 2023/10/12
+ */
+@Slf4j
+@Component("CoreEvaluatePlanTask")
+public class CoreEvaluatePlanTask {
+    @Resource
+    private RemoteCoreEvaluatePlanService remoteCoreEvaluatePlanService;
+
+    /**
+     * 评价每季度生成
+     */
+    public void evaluateQuarterTask() {
+        String id = UUID.fastUUID().toString();
+        log.info("开始执行每季度生成评价任务,当前任务 id:{},当前时间:{},无参数", id, new Date());
+        AjaxResult ajaxResult = remoteCoreEvaluatePlanService.generate("1", SecurityConstants.INNER);
+        log.info("每季度生成评价任务定时任务执行结束,当前任务 id:{},当前时间:{},结果:{}", id, new Date(), JSON.toJSONString(ajaxResult));
+    }
+
+    /**
+     * 评价月生成
+     */
+    public void evaluateMonthTask() {
+        String id = UUID.fastUUID().toString();
+        log.info("开始执行每月生成评价任务,当前任务 id:{},当前时间:{},无参数", id, new Date());
+        AjaxResult ajaxResult = remoteCoreEvaluatePlanService.generate("0", SecurityConstants.INNER);
+        log.info("每月生成评价任务定时任务执行结束,当前任务 id:{},当前时间:{},结果:{}", id, new Date(), JSON.toJSONString(ajaxResult));
+    }
+
+    /**
+     * 评价月生成
+     */
+    public void evaluateYearTask() {
+        String id = UUID.fastUUID().toString();
+        log.info("开始执行每月生成评价任务,当前任务 id:{},当前时间:{},无参数", id, new Date());
+        AjaxResult ajaxResult = remoteCoreEvaluatePlanService.generate("2", SecurityConstants.INNER);
+        log.info("每月生成评价任务定时任务执行结束,当前任务 id:{},当前时间:{},结果:{}", id, new Date(), JSON.toJSONString(ajaxResult));
+    }
+}

+ 3 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/domain/SysMenu.java

@@ -1,6 +1,8 @@
 package com.xunmei.system.domain;
 
 import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.xunmei.common.core.constant.Constants;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
@@ -34,7 +36,7 @@ public class SysMenu extends BaseEntity {
     /**
      * 菜单ID
      */
-
+    @JsonSerialize(using = ToStringSerializer.class)
     private Long id;
 
     /**