Kaynağa Gözat

调整计划

luojun 2 yıl önce
ebeveyn
işleme
fa03e7b322

+ 4 - 3
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteSafetyCheckService.java

@@ -1,5 +1,6 @@
 package com.xunmei.system.api;
 
+import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.constant.ServiceNameConstants;
 import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.web.domain.AjaxResult;
@@ -7,8 +8,7 @@ import com.xunmei.system.api.factory.RemoteEduTrainingFallbackFactory;
 import com.xunmei.system.api.factory.RemoteResumptionTaskFallbackFactory;
 import com.xunmei.system.api.factory.RemoteSafetyCheckTaskFallbackFactory;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
 
@@ -64,5 +64,6 @@ public interface RemoteSafetyCheckService {
     @GetMapping(value = "checkplan/YearTask")
     R<Boolean> yearTask();
 
-
+    @PostMapping("checkplan/rebuild")
+    AjaxResult rebuild(@RequestBody String event, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
 }

+ 6 - 0
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteSafetyCheckTaskFallbackFactory.java

@@ -1,6 +1,7 @@
 package com.xunmei.system.api.factory;
 
 import com.xunmei.common.core.domain.R;
+import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.system.api.RemoteRoleService;
 import com.xunmei.system.api.RemoteSafetyCheckService;
 import org.springframework.cloud.openfeign.FallbackFactory;
@@ -38,6 +39,11 @@ public class RemoteSafetyCheckTaskFallbackFactory implements FallbackFactory<Rem
             public R<Boolean> yearTask() {
                 return null;
             }
+
+            @Override
+            public AjaxResult rebuild(String event, String source) {
+                return null;
+            }
         };
     }
 }

+ 13 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/listener/WorkTimeChangeEventListener.java

@@ -3,6 +3,7 @@ package com.xunmei.core.listener;
 import com.xunmei.common.core.event.WorkTimeChangeEvent;
 import com.xunmei.core.edu.service.ICoreEduTrainingTaskService;
 import com.xunmei.core.resumption.task.ResumptionTaskBusiness;
+import com.xunmei.core.safetyCheck.job.SafetyCheckJobBusiness;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationListener;
@@ -20,13 +21,15 @@ public class WorkTimeChangeEventListener implements ApplicationListener<WorkTime
 
     @Autowired
     private ResumptionTaskBusiness rebuildResumptionTaskBusiness;
-
+    @Autowired
+    private SafetyCheckJobBusiness rebuildSafetyCheckTask;
     @Override
     @EventListener(WorkTimeChangeEvent.class)
     @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
     public void onApplicationEvent(WorkTimeChangeEvent event) {
 //        eduTask(event);
         resumptionTask(event);
+        safetyCheckTask(event);
     }
 
     private void eduTask(WorkTimeChangeEvent event) {
@@ -49,4 +52,13 @@ public class WorkTimeChangeEventListener implements ApplicationListener<WorkTime
             log.error(e.getMessage(), e);
         }
     }
+    private void safetyCheckTask(WorkTimeChangeEvent event) {
+        try {
+            log.info("安全检查开始处理机构作息变更");
+            rebuildSafetyCheckTask.rebuildTask(event);
+            log.info("安全检查结束处理机构作息变更");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
 }

+ 11 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/safetyCheck/controller/CoreSafecheckPlanController.java

@@ -6,8 +6,12 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 
 import cn.hutool.core.date.DateTime;
+import com.alibaba.nacos.shaded.com.google.gson.Gson;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.xunmei.common.core.event.WorkTimeChangeEvent;
 import com.xunmei.common.core.utils.DateHelper;
+import com.xunmei.common.security.annotation.InnerAuth;
+import com.xunmei.core.listener.WorkTimeChangeEventListener;
 import com.xunmei.core.resumption.dto.DistributeDto;
 import com.xunmei.core.safetyCheck.domain.CoreSafecheckPlan;
 import com.xunmei.core.safetyCheck.job.SafetyCheckJobBusiness;
@@ -45,7 +49,13 @@ public class CoreSafecheckPlanController extends BaseController {
     private ICoreSafecheckPlanService coreSafecheckPlanService;
     @Autowired
     private SafetyCheckJobBusiness jobBusiness;
-
+    @Autowired
+    WorkTimeChangeEventListener workTimeChangeEventListener;
+    @PostMapping(value = "/rebuild")
+    @InnerAuth
+    void rebuildTask(@RequestBody String event){
+        workTimeChangeEventListener.onApplicationEvent(new Gson().fromJson(event, WorkTimeChangeEvent.class));
+    }
     @ApiOperation(value = "撤回")
     @GetMapping(value = "/cheHui/{id}")
 //    @RequiresPermissions("core:plan:findById")

+ 93 - 5
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/safetyCheck/job/SafetyCheckJobBusiness.java

@@ -468,8 +468,19 @@ public class SafetyCheckJobBusiness extends TaskCreatingServiceImplBase<CoreSafe
                 hashMap.put(checkTask.getCheckOrgId(), batchId);
             }
             checkTask.setBatchId(batchId);
+            //变更,如果当前机构当前YmdDate已存在已完成或者已逾期的任务则跳过,否则删除
+            List<CoreSafetyTask> coreSafetyTasks = checkTaskService.list(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getOrgId, checkTask.getOrgId()).eq(CoreSafetyTask::getYmdDate, checkTask.getYmdDate()).in(CoreSafetyTask::getStatus, 3, 4));
+            if (coreSafetyTasks.size() > 0) {
+                //如果存在同批次的已完成或者已逾期的任务需要同步批次id
+                checkTask.setBatchId(coreSafetyTasks.get(0).getBatchId());
+            } else {
+                for (CoreSafetyTask t :
+                        coreSafetyTasks) {
+                    checkTaskService.removeById(t.getId());
+                }
+                ats.add(checkTask);
+            }
 
-            ats.add(checkTask);
             if (ats.size() == 200) {
                 checkTaskService.saveBatch(ats);
                 ats = new ArrayList<>();
@@ -638,18 +649,95 @@ public class SafetyCheckJobBusiness extends TaskCreatingServiceImplBase<CoreSafe
 //        List<Long> deleteTaskIds = new ArrayList<>();
 
         List<SysOrg> orgs = remoteOrgService.selectByOrgIdList(orgIds, SecurityConstants.INNER);
-        for (SysOrg org : orgs) {
-            if (ObjectUtil.isNull(org.getType())) {
+        for (SysOrg worg : orgs) {
+            if (ObjectUtil.isNull(worg.getType())) {
                 continue;
             }
 
-            Long orgId = org.getId();
+            Long orgId = worg.getId();
             if (!workingMap.containsKey(orgId) || !workingMap.get(orgId)) {
                 //当前作息周期已经歇业,删除未进行的任务
                 checkTaskService.deleteByOrgIdAndRange(orgId, startDate, endDate);
                 continue;
-            }else{
+            } else {
                 //开始营业,重新生成任务
+                //拿到所有检查计划
+                List<CoreSafecheckPlan> plans = planMapper.selectByPlanStatus(1);
+                Iterator<CoreSafecheckPlan> safecheckPlanIterator = plans.iterator();
+                //遍历计划
+                while (safecheckPlanIterator.hasNext()) {
+                    //拿到计划所属受检机构
+                    List<SysOrg> checkOrgList = safecheckPlanIterator.next().getCheckOrgList();
+                    //过滤掉不等于当前作息变更机构的受检机构
+                    List<SysOrg> collect = checkOrgList.stream().filter(e -> e.getId().equals(orgId)).collect(Collectors.toList());
+                    //过滤完数组长度0表示没有受检机构等于作息变更机构的数据
+                    if (collect.size() == 0) {
+                        //移除当前计划
+                        safecheckPlanIterator.remove();
+                    } else
+                    //如果存在相等的受检机构,开始重新生成任务
+                    {
+                        CoreSafecheckPlan plan = safecheckPlanIterator.next();
+                        List<PlanTaskBuildVo> list = new ArrayList<>();
+                        Integer execOrgType = Math.toIntExact(plan.getExecOrgType());
+                        Integer checkOrgType = Math.toIntExact(plan.getCheckOrgType());
+
+                        //获取具体执行检查的机构
+                        QueryWrapper<CoreSafecheckPlanToExecOrg> eos = new QueryWrapper<>();
+                        eos.lambda().eq(CoreSafecheckPlanToExecOrg::getPlanId, plan.getId());
+                        List<CoreSafecheckPlanToExecOrg> execOrg = planToExecOrgMapper.selectList(eos);
+
+                        //获取具体受检的机构
+                        QueryWrapper<CoreSafecheckPlanToCheckOrg> cos = new QueryWrapper<>();
+                        //变更点,只需要保留作息变更的受检机构
+                        cos.lambda().eq(CoreSafecheckPlanToCheckOrg::getPlanId, plan.getId()).eq(CoreSafecheckPlanToCheckOrg::getOrgId, orgId);
+                        List<CoreSafecheckPlanToCheckOrg> checkOrg = planToCheckOrgMapper.selectList(cos);
+
+                        //获取执行角色
+                        QueryWrapper<CoreSafecheckPlanToRole> ros = new QueryWrapper<>();
+                        ros.lambda().eq(CoreSafecheckPlanToRole::getPlanId, plan.getId());
+                        List<CoreSafecheckPlanToRole> roles = planToRoleMapper.selectList(ros);
+
+                        List<SysOrg> execOrgs = null;
+                        SysOrg ownOrg = orgService.selectOrgById(plan.getPlanOfOrgId(), SecurityConstants.INNER);
+                        if (ObjectUtil.isEmpty(execOrg)) {
+                            //如果没有选择具体执行检查的机构,则根据执行机构类型查询
+                            execOrgs = orgService.findByOrgTypeAndParent(execOrgType, ownOrg.getPath(), SecurityConstants.INNER);
+                        } else {
+                            //选择了具体执行检查的机构
+                            List<Long> porgIds = execOrg.stream().map(CoreSafecheckPlanToExecOrg::getOrgId).collect(Collectors.toList());
+                            execOrgs = orgService.selectOrgByIdList(porgIds, SecurityConstants.INNER);
+                            execOrgs = execOrgs.stream().filter(o -> o.getPath().startsWith(ownOrg.getPath())).collect(Collectors.toList());
+                        }
+                        execOrgs = execOrgs.stream().filter(o -> o.getIsLock() < 1).collect(Collectors.toList());
+
+                        //此处循环所有执行检查的机构
+                        for (SysOrg org : execOrgs) {
+                            List<SysOrg> checkOrgs = null;
+                            if (ObjectUtil.isEmpty(checkOrg)) {
+                                //如果没有选择具体受检的机构,则根据受检机构类型查询
+                                checkOrgs = orgService.findByOrgTypeAndParent(checkOrgType, org.getPath(), SecurityConstants.INNER);
+                            } else {
+                                //选择了具体的受检机构
+                                List<Long> ids = checkOrg.stream().map(CoreSafecheckPlanToCheckOrg::getOrgId).collect(Collectors.toList());
+                                checkOrgs = orgService.selectOrgByIdList(ids, SecurityConstants.INNER);
+                            }
+                            checkOrgs = checkOrgs.stream().filter(o -> o.getIsLock() < 1).collect(Collectors.toList());
+                            //构建数据
+                            List<PlanTaskBuildVo> bs = getBuild(plan, org, checkOrgs, roles);
+                            list.addAll(bs);
+                        }
+                        //生成具体任务
+                        try {
+                            DateTime datetime = new DateTime();
+                            datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+                            buildTask(datetime, list, startDate, endDate, false, 0);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+
 
             }
 

+ 2 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/safetyCheck/mapper/CoreSafecheckPlanMapper.java

@@ -73,4 +73,6 @@ public interface CoreSafecheckPlanMapper extends BaseMapper<CoreSafecheckPlan> {
     List<CoreSafecheckPlan> selectByRole(List<Long> roleIds,Long hangsheOrgId);
 
     List<CoreSafecheckPlan> selectChildren(@Param("check") CoreSafecheckPlan coreSafecheckPlan);
+
+    List<CoreSafecheckPlan> selectByPlanStatus(@Param("planStatus")int i);
 }

+ 58 - 0
soc-modules/soc-modules-core/src/main/resources/mapper/safetycheck/CoreSafecheckPlanMapper.xml

@@ -518,4 +518,62 @@
         GROUP BY tem.plan_of_org_id
 
     </select>
+    <select id="selectByPlanStatus" resultMap="CoreSafecheckPlanResult">
+
+        SELECT
+        c.plan_name,
+        c.plan_cycle,
+        c.exec_org_type,
+        c.check_org_type,
+        c.plan_status,
+        c.start_date,
+        c.end_date,
+        c.build_task_now,
+        c.description,
+        c.is_deleted,
+        c.create_time,
+        c.update_time,
+        c.modified_by,
+        u1.NAME AS modified_name,
+        c.source_type,
+        c.plan_create_org_id,
+        c.plan_of_org_id,
+        c.check_type,
+        c.count,
+        c.id,
+        c.parent_id,
+        c.distribute,
+        c.distribute_status,
+        c.distribute_plan_status,
+        o1.short_name AS plan_create_org_name,
+        o2.type as plan_of_org_type,
+        o2.short_name AS plan_of_org_name,
+        r.role_name,
+        r.id AS role_id,
+        o3.id AS check_org_id,
+        o3.short_name AS check_org_name,
+        o4.id AS exec_org_id,
+        o4.short_name AS exec_org_name
+        FROM
+        core_safecheck_plan c
+        LEFT JOIN sys_org o1 ON c.plan_create_org_id = o1.id
+        LEFT JOIN sys_org o2 ON c.plan_of_org_id = o2.id
+        LEFT JOIN core_safecheck_plan_to_role pr ON c.id = pr.plan_id
+        LEFT JOIN sys_role r ON r.id = pr.role_id
+        LEFT JOIN core_safecheck_plan_to_check_org co ON co.plan_id = c.id
+        LEFT JOIN sys_org o3 ON o3.id = co.org_id
+        LEFT JOIN core_safecheck_plan_to_exec_org eo ON eo.plan_id = c.id
+        LEFT JOIN sys_org o4 ON o4.id = eo.org_id
+        LEFT JOIN sys_user u1 ON u1.id = c.modified_by
+        WHERE
+        1 =1
+        and c.is_deleted=0
+        <if test="planStatus != null ">
+            and c.plan_status = #{planStatus}
+        </if>
+
+
+
+
+    </select>
 </mapper>

+ 5 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/listener/WorkTimeChangeEventListener.java

@@ -6,6 +6,7 @@ import com.xunmei.common.core.event.WorkTimeChangeEvent;
 import com.xunmei.system.api.RemoteEduTrainingService;
 import com.xunmei.system.api.RemoteResumptionTaskService;
 import com.xunmei.system.api.RemoteRetrievalTaskService;
+import com.xunmei.system.api.RemoteSafetyCheckService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationListener;
@@ -26,6 +27,9 @@ public class WorkTimeChangeEventListener implements ApplicationListener<WorkTime
     RemoteEduTrainingService eduTrainingService;
     @Autowired
     RemoteRetrievalTaskService remoteRetrievalTaskService;
+//    @Autowired
+//    RemoteSafetyCheckService remoteSafetyCheckService;
+
     @Override
     @EventListener(WorkTimeChangeEvent.class)
     @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = false)
@@ -34,6 +38,6 @@ public class WorkTimeChangeEventListener implements ApplicationListener<WorkTime
         remoteResumptionTaskService.rebuild(JSON.toJSONString(event), SecurityConstants.INNER);
         eduTrainingService.rebuild(JSON.toJSONString(event), SecurityConstants.INNER);
         remoteRetrievalTaskService.rebuild(JSON.toJSONString(event), SecurityConstants.INNER);
-
+//        remoteSafetyCheckService.rebuild(JSON.toJSONString(event), SecurityConstants.INNER);
     }
 }