|
|
@@ -0,0 +1,521 @@
|
|
|
+package com.xunmei.core.safetyCheck.job;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
+import com.xunmei.common.core.utils.DateHelper;
|
|
|
+import com.xunmei.core.safetyCheck.domain.*;
|
|
|
+import com.xunmei.core.safetyCheck.domain.CoreSafecheckPlan;
|
|
|
+import com.xunmei.core.safetyCheck.dto.SafetyTaskBuildDto;
|
|
|
+import com.xunmei.core.safetyCheck.mapper.CoreSafecheckPlanMapper;
|
|
|
+import com.xunmei.core.safetyCheck.mapper.CoreSafecheckPlanToCheckOrgMapper;
|
|
|
+import com.xunmei.core.safetyCheck.mapper.CoreSafecheckPlanToExecOrgMapper;
|
|
|
+import com.xunmei.core.safetyCheck.mapper.CoreSafecheckPlanToRoleMapper;
|
|
|
+import com.xunmei.core.safetyCheck.service.ICoreSafetyTaskService;
|
|
|
+import com.xunmei.core.safetyCheck.vo.PlanTaskBuildVo;
|
|
|
+import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author jingyuanchao
|
|
|
+ * @date 2022/6/29 14:34
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class SafetyCheckJobBusiness {
|
|
|
+ @Resource
|
|
|
+ CoreSafecheckPlanMapper planMapper;
|
|
|
+ @Resource
|
|
|
+ ICoreSafetyTaskService checkTaskService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ CoreSafecheckPlanToCheckOrgMapper planToCheckOrgMapper;
|
|
|
+ @Resource
|
|
|
+ CoreSafecheckPlanToExecOrgMapper planToExecOrgMapper;
|
|
|
+ @Resource
|
|
|
+ CoreSafecheckPlanToRoleMapper planToRoleMapper;
|
|
|
+ @Autowired
|
|
|
+ private RemoteOrgService orgService;
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void createTaskForNow(Long planId, Date start, Date end, Boolean isNeedSendTodo, Integer sourceType) throws Exception {
|
|
|
+
|
|
|
+ DateTime datetime = new DateTime();
|
|
|
+ datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
|
|
+
|
|
|
+ CoreSafecheckPlan checkPlan = planMapper.selectById(planId);
|
|
|
+ Integer planCycle = Math.toIntExact(checkPlan.getPlanCycle());
|
|
|
+
|
|
|
+ if (!planCycle.equals(6)) {
|
|
|
+ DateHelper dateHelper = new DateHelper(datetime);
|
|
|
+ Map<String, Date> map = DateHelper.getStartAndEnd(dateHelper, planCycle);
|
|
|
+ start = map.get("start");
|
|
|
+ end = map.get("end");
|
|
|
+ }
|
|
|
+ createTaskForCycle(datetime, start, end, checkPlan, isNeedSendTodo, sourceType);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面调用,立即生成任务
|
|
|
+ *
|
|
|
+ * @param dateTime
|
|
|
+ * @param start
|
|
|
+ * @param end
|
|
|
+ * @param plan
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void createTaskForCycle(DateTime dateTime, Date start, Date end, CoreSafecheckPlan plan, Boolean isNeedSendTodo, Integer sourceType) throws Exception {
|
|
|
+ List<PlanTaskBuildVo> planTask = createPlanTask(plan);
|
|
|
+ //生成具体任务
|
|
|
+ buildTask(dateTime, planTask, start, end, isNeedSendTodo, sourceType);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 有周期计划生成任务
|
|
|
+ *
|
|
|
+ * @param dateTime
|
|
|
+ * @param planCycle
|
|
|
+ * @param start
|
|
|
+ * @param end
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void createTask(Date dateTime, int planCycle, Date start, Date end) throws Exception {
|
|
|
+ QueryWrapper<CoreSafecheckPlan> qw = new QueryWrapper<>();
|
|
|
+ qw.lambda().eq(CoreSafecheckPlan::getPlanCycle, planCycle);
|
|
|
+ qw.lambda().eq(CoreSafecheckPlan::getIsDeleted, 0);
|
|
|
+ qw.lambda().eq(CoreSafecheckPlan::getPlanStatus, 1);
|
|
|
+ List<CoreSafecheckPlan> plans = planMapper.selectList(qw);
|
|
|
+ List<PlanTaskBuildVo> tasks = new ArrayList<>();
|
|
|
+ for (CoreSafecheckPlan plan : plans) {
|
|
|
+ List<PlanTaskBuildVo> planTask = createPlanTask(plan);
|
|
|
+ tasks.addAll(planTask);
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成具体任务
|
|
|
+ buildTask(dateTime, tasks, start, end, true, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成每个计划的任务
|
|
|
+ *
|
|
|
+ * @param plan
|
|
|
+ */
|
|
|
+ private List<PlanTaskBuildVo> createPlanTask(CoreSafecheckPlan plan) {
|
|
|
+
|
|
|
+ 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());
|
|
|
+ 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;
|
|
|
+ if (ObjectUtil.isEmpty(execOrg)) {
|
|
|
+ //如果没有选择具体执行检查的机构,则根据执行机构类型查询
|
|
|
+ execOrgs = orgService.selectByOrgType(execOrgType, SecurityConstants.INNER);
|
|
|
+ } else {
|
|
|
+ //选择了具体执行检查的机构
|
|
|
+ List<Long> orgIds = execOrg.stream().map(CoreSafecheckPlanToExecOrg::getOrgId).collect(Collectors.toList());
|
|
|
+ execOrgs = orgService.selectOrgByIdList(orgIds, SecurityConstants.INNER);
|
|
|
+ }
|
|
|
+ execOrgs = execOrgs.stream().filter(o -> o.getIsLock() < 1).collect(Collectors.toList());
|
|
|
+
|
|
|
+// execOrgs = execOrgs.stream().filter(o -> ObjectUtil.equal(o.getIsLock(), false)).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 -> ObjectUtil.equal(o.getIsLock(), false)).collect(Collectors.toList());
|
|
|
+ checkOrgs = checkOrgs.stream().filter(o -> o.getIsLock() < 1).collect(Collectors.toList());
|
|
|
+ //构建数据
|
|
|
+ List<PlanTaskBuildVo> bs = getBuild(plan, org, checkOrgs, roles);
|
|
|
+ list.addAll(bs);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据入参来生成任务
|
|
|
+ *
|
|
|
+ * @param plan
|
|
|
+ */
|
|
|
+ private List<PlanTaskBuildVo> createPlanTask(CoreSafecheckPlan plan, SafetyTaskBuildDto safetyTaskBuildDto) {
|
|
|
+
|
|
|
+ List<PlanTaskBuildVo> list = new ArrayList<>();
|
|
|
+ Integer execOrgType = Math.toIntExact(plan.getExecOrgType());
|
|
|
+ Integer checkOrgType = Math.toIntExact(plan.getCheckOrgType());
|
|
|
+
|
|
|
+ //获取具体执行检查的机构
|
|
|
+ List<CoreSafecheckPlanToExecOrg> execOrg = null;
|
|
|
+ if (ObjectUtil.isNotEmpty(safetyTaskBuildDto.getExecOrgIdList())) {
|
|
|
+ execOrg = new ArrayList<>();
|
|
|
+ for (Long execOrgId : safetyTaskBuildDto.getExecOrgIdList()) {
|
|
|
+ CoreSafecheckPlanToExecOrg coreSafecheckPlanToExecOrg = new CoreSafecheckPlanToExecOrg();
|
|
|
+ coreSafecheckPlanToExecOrg.setOrgId(execOrgId);
|
|
|
+ coreSafecheckPlanToExecOrg.setPlanId(plan.getId());
|
|
|
+ execOrg.add(coreSafecheckPlanToExecOrg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LambdaQueryWrapper<CoreSafecheckPlanToExecOrg> eos = new LambdaQueryWrapper<>();
|
|
|
+ eos.eq(CoreSafecheckPlanToExecOrg::getPlanId, plan.getId());
|
|
|
+ execOrg = planToExecOrgMapper.selectList(eos);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取具体受检的机构
|
|
|
+ List<CoreSafecheckPlanToCheckOrg> checkOrg = null;
|
|
|
+ if (ObjectUtil.isNotEmpty(safetyTaskBuildDto.getCheckOrgIdList())) {
|
|
|
+ checkOrg = new ArrayList<>();
|
|
|
+ for (Long checkOrgId : safetyTaskBuildDto.getCheckOrgIdList()) {
|
|
|
+ CoreSafecheckPlanToCheckOrg coreSafecheckPlanToCheckOrg = new CoreSafecheckPlanToCheckOrg();
|
|
|
+ coreSafecheckPlanToCheckOrg.setOrgId(checkOrgId);
|
|
|
+ coreSafecheckPlanToCheckOrg.setPlanId(plan.getId());
|
|
|
+ checkOrg.add(coreSafecheckPlanToCheckOrg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LambdaQueryWrapper<CoreSafecheckPlanToCheckOrg> cos = new LambdaQueryWrapper<>();
|
|
|
+ cos.eq(CoreSafecheckPlanToCheckOrg::getPlanId, plan.getId());
|
|
|
+ checkOrg = planToCheckOrgMapper.selectList(cos);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取执行角色
|
|
|
+ List<CoreSafecheckPlanToRole> roles = null;
|
|
|
+ if (ObjectUtil.isNotEmpty(safetyTaskBuildDto.getRoleIdList())) {
|
|
|
+ roles = new ArrayList<>();
|
|
|
+ for (Long roleId : safetyTaskBuildDto.getRoleIdList()) {
|
|
|
+ CoreSafecheckPlanToRole coreSafecheckPlanToRole = new CoreSafecheckPlanToRole();
|
|
|
+ coreSafecheckPlanToRole.setRoleId(roleId);
|
|
|
+ coreSafecheckPlanToRole.setPlanId(plan.getId());
|
|
|
+ roles.add(coreSafecheckPlanToRole);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LambdaQueryWrapper<CoreSafecheckPlanToRole> ros = new LambdaQueryWrapper<>();
|
|
|
+ ros.eq(CoreSafecheckPlanToRole::getPlanId, plan.getId());
|
|
|
+ roles = planToRoleMapper.selectList(ros);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<SysOrg> execOrgs = null;
|
|
|
+ if (ObjectUtil.isEmpty(execOrg)) {
|
|
|
+ //如果没有选择具体执行检查的机构,则根据执行机构类型查询
|
|
|
+ execOrgs = orgService.selectByOrgType(execOrgType, SecurityConstants.INNER);
|
|
|
+ } else {
|
|
|
+ //选择了具体执行检查的机构
|
|
|
+ List<Long> orgIds = execOrg.stream().map(CoreSafecheckPlanToExecOrg::getOrgId).collect(Collectors.toList());
|
|
|
+ execOrgs = orgService.selectOrgByIdList(orgIds, SecurityConstants.INNER);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建任务所需条件
|
|
|
+ *
|
|
|
+ * @param plan
|
|
|
+ * @param check
|
|
|
+ * @param execOrgList
|
|
|
+ * @param roles
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<PlanTaskBuildVo> getBuild(CoreSafecheckPlan plan, SysOrg check, List<SysOrg> execOrgList, List<CoreSafecheckPlanToRole> roles) {
|
|
|
+
|
|
|
+ List<PlanTaskBuildVo> list = new ArrayList<>();
|
|
|
+
|
|
|
+ PlanTaskBuildVo vo = null;
|
|
|
+ for (SysOrg org : execOrgList) {
|
|
|
+ for (CoreSafecheckPlanToRole role : roles) {
|
|
|
+ vo = new PlanTaskBuildVo();
|
|
|
+ vo.setPlanId(plan.getId());
|
|
|
+ vo.setEndTime(plan.getEndDate());
|
|
|
+ vo.setStartTime(plan.getStartDate());
|
|
|
+ vo.setCheckOrg(check);
|
|
|
+ vo.setExecOrg(org);
|
|
|
+ vo.setPlanName(plan.getPlanName());
|
|
|
+ vo.setRole(role);
|
|
|
+ vo.setPlanCycle(Math.toIntExact(plan.getPlanCycle()));
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成具体任务
|
|
|
+ *
|
|
|
+ * @param datetime
|
|
|
+ * @param tasks
|
|
|
+ * @param start
|
|
|
+ * @param end
|
|
|
+ * @param isNeedSendTodo 是否需要发送待办
|
|
|
+ * @param sourceType 生成任务的数据来源 0:检查计划 ,1:登记检查结果
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private List<CoreSafetyTask> buildTask(Date datetime, List<PlanTaskBuildVo> tasks, Date start, Date end, Boolean isNeedSendTodo, Integer sourceType) throws Exception {
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ // 设置时间
|
|
|
+ c.setTime(start);
|
|
|
+ // 设置毫秒值为0
|
|
|
+ c.set(Calendar.MILLISECOND, 0);
|
|
|
+ c.set(Calendar.SECOND, 0);
|
|
|
+ start = c.getTime();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat sdfa = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ sdfa.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
|
|
+ sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
|
|
+ end = sdfa.parse(sdf.format(end) + " 23:59:59");
|
|
|
+
|
|
|
+ DateHelper dateHelper = new DateHelper(datetime);
|
|
|
+ List<CoreSafetyTask> ats = new ArrayList<>();
|
|
|
+ Map<Long, String> hashMap = new HashMap<>();
|
|
|
+ for (PlanTaskBuildVo taskPlan : tasks) {
|
|
|
+ CoreSafetyTask checkTask = new CoreSafetyTask();
|
|
|
+ checkTask.setTitle(taskPlan.getPlanName());
|
|
|
+ checkTask.setExceptionCount(0L);
|
|
|
+ checkTask.setOrgId(taskPlan.getExecOrg().getId());
|
|
|
+ checkTask.setOrgName(taskPlan.getExecOrg().getName());
|
|
|
+ checkTask.setOrgPath(taskPlan.getExecOrg().getPath());
|
|
|
+ checkTask.setCheckOrgId(taskPlan.getCheckOrg().getId());
|
|
|
+ checkTask.setCheckOrgName(taskPlan.getCheckOrg().getName());
|
|
|
+ checkTask.setStatus(1L);
|
|
|
+ checkTask.setDoneStatus(0L);
|
|
|
+ checkTask.setCheckType(0L);
|
|
|
+ checkTask.setCheckCycle(Long.valueOf(taskPlan.getPlanCycle()));
|
|
|
+ checkTask.setYmdDate(datetime);
|
|
|
+ checkTask.setYmdDay((long) dateHelper.getDay());
|
|
|
+ checkTask.setYmdMonth((long) dateHelper.getMonth());
|
|
|
+ checkTask.setYmdQuarter((long) dateHelper.getQuarter());
|
|
|
+ checkTask.setYmdWeek((long) dateHelper.getWeek());
|
|
|
+ checkTask.setYmdYear((long) dateHelper.getYear());
|
|
|
+ checkTask.setYmdHalfyear((long) dateHelper.getHalfyear());
|
|
|
+ checkTask.setSubmitBy(null);
|
|
|
+ checkTask.setSubmitTime(null);
|
|
|
+ checkTask.setPlanId(taskPlan.getPlanId());
|
|
|
+ checkTask.setPlanStartTime(start);
|
|
|
+ checkTask.setPlanEndTime(end);
|
|
|
+ checkTask.setStartTime(null);
|
|
|
+ checkTask.setEndTime(null);
|
|
|
+ checkTask.setRoleId(taskPlan.getRole().getRoleId());
|
|
|
+ checkTask.setIsQuestion(0L);
|
|
|
+ checkTask.setSourceType(Long.valueOf(sourceType));
|
|
|
+ checkTask.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ String batchId = hashMap.get(checkTask.getCheckOrgId());
|
|
|
+ if (ObjectUtil.isEmpty(batchId)) {
|
|
|
+ batchId = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ hashMap.put(checkTask.getCheckOrgId(), batchId);
|
|
|
+ }
|
|
|
+ checkTask.setBatchId(batchId);
|
|
|
+
|
|
|
+ ats.add(checkTask);
|
|
|
+ if (ats.size() == 200) {
|
|
|
+ checkTaskService.saveBatch(ats);
|
|
|
+ ats = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ats.size() > 0) {
|
|
|
+ checkTaskService.saveBatch(ats);
|
|
|
+ }
|
|
|
+// if (isNeedSendTodo) {
|
|
|
+// //发送待办
|
|
|
+// sendTodo(todoList);
|
|
|
+// }
|
|
|
+
|
|
|
+ return ats;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String getTitle(int completed, int unCompleted) {
|
|
|
+ return String.format("(已完成(%s),未完成(%s))", completed, unCompleted);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void compensationTask(SafetyTaskBuildDto safetyTaskBuildDto) throws Exception {
|
|
|
+// SCHEDULEDTASKSLOG.info("安全检查补偿任务开始,当前入参时间为:{}", DateUtil.format(safetyTaskBuildDto.getDate(), "yyyy-MM-dd"));
|
|
|
+ DateHelper dateHelper = new DateHelper(safetyTaskBuildDto.getDate());
|
|
|
+
|
|
|
+ Map<String, Date> map = null;
|
|
|
+ List<CoreSafecheckPlan> plans = null;
|
|
|
+ if (safetyTaskBuildDto.getPlanId() != null) {
|
|
|
+ plans = new ArrayList<>();
|
|
|
+ CoreSafecheckPlan coreSafecheckPlan = planMapper.selectById(safetyTaskBuildDto.getPlanId());
|
|
|
+ plans.add(coreSafecheckPlan);
|
|
|
+ map = DateHelper.getStartAndEnd(safetyTaskBuildDto.getDate(), Math.toIntExact(coreSafecheckPlan.getPlanCycle()));
|
|
|
+ } else {
|
|
|
+ LambdaUpdateWrapper<CoreSafecheckPlan> qw = new LambdaUpdateWrapper<>();
|
|
|
+ qw.eq(CoreSafecheckPlan::getPlanCycle, safetyTaskBuildDto.getPlanCycle());
|
|
|
+ qw.eq(CoreSafecheckPlan::getIsDeleted, 0);
|
|
|
+ qw.eq(CoreSafecheckPlan::getPlanStatus, 0);
|
|
|
+ plans = planMapper.selectList(qw);
|
|
|
+ map = DateHelper.getStartAndEnd(safetyTaskBuildDto.getDate(), safetyTaskBuildDto.getPlanCycle());
|
|
|
+ }
|
|
|
+ List<PlanTaskBuildVo> tasks = new ArrayList<>();
|
|
|
+ for (CoreSafecheckPlan plan : plans) {
|
|
|
+ List<PlanTaskBuildVo> planTask = createPlanTask(plan, safetyTaskBuildDto);
|
|
|
+ tasks.addAll(planTask);
|
|
|
+ }
|
|
|
+ //生成具体任务
|
|
|
+ buildTask(safetyTaskBuildDto.getDate(), tasks, map.get("start"), map.get("end"), true, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查参数
|
|
|
+ public List<String> checkParam(SafetyTaskBuildDto safetyTaskBuildDto) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ DateHelper dateHelper = new DateHelper(safetyTaskBuildDto.getDate());
|
|
|
+ Map<String, Date> map = null;
|
|
|
+ List<CoreSafecheckPlan> plans = null;
|
|
|
+ if (safetyTaskBuildDto.getPlanId() != null) {
|
|
|
+ plans = new ArrayList<>();
|
|
|
+ CoreSafecheckPlan coreSafecheckPlan = planMapper.selectById(safetyTaskBuildDto.getPlanId());
|
|
|
+ if (coreSafecheckPlan.getPlanStatus() == 1) {
|
|
|
+ list.add("当前计划:" + coreSafecheckPlan.getPlanName() + "已禁用!");
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ plans.add(coreSafecheckPlan);
|
|
|
+ map = DateHelper.getStartAndEnd(safetyTaskBuildDto.getDate(), Math.toIntExact(coreSafecheckPlan.getPlanCycle()));
|
|
|
+ } else {
|
|
|
+ LambdaUpdateWrapper<CoreSafecheckPlan> qw = new LambdaUpdateWrapper<>();
|
|
|
+ qw.eq(CoreSafecheckPlan::getPlanCycle, safetyTaskBuildDto.getPlanCycle());
|
|
|
+ qw.eq(CoreSafecheckPlan::getIsDeleted, 0);
|
|
|
+ qw.eq(CoreSafecheckPlan::getPlanStatus, 0);
|
|
|
+ plans = planMapper.selectList(qw);
|
|
|
+ map = DateHelper.getStartAndEnd(safetyTaskBuildDto.getDate(), safetyTaskBuildDto.getPlanCycle());
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isEmpty(plans)) {
|
|
|
+ list.add("计划不存在");
|
|
|
+ }
|
|
|
+ for (CoreSafecheckPlan plan : plans) {
|
|
|
+ if (ObjectUtil.notEqual(plan.getPlanCycle(), safetyTaskBuildDto.getPlanCycle())) {
|
|
|
+ list.add("计划周期与计划不匹配");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (map.keySet().size() == 0) {
|
|
|
+ list.add("计划周期不存在");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(safetyTaskBuildDto.getExecOrgIdList())) {
|
|
|
+ List<Long> execOrgIdList = safetyTaskBuildDto.getExecOrgIdList();
|
|
|
+ for (CoreSafecheckPlan plan : plans) {
|
|
|
+ List<CoreSafecheckPlanToExecOrg> coreSafecheckPlanToExecOrgs = planToExecOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToExecOrg>().eq(CoreSafecheckPlanToExecOrg::getPlanId, plan.getId()));
|
|
|
+ if (CollectionUtil.isEmpty(coreSafecheckPlanToExecOrgs)) {
|
|
|
+ //说明计划是根据机构类型配置的,获取所有的机构类型,如果参数中执行机构的机构类型存在不属于此计划的执行机构,则返回错误
|
|
|
+ List<Long> orgTypeList = orgService.selectOrgTypeByIdList(execOrgIdList, SecurityConstants.INNER);
|
|
|
+ for (Long orgType : orgTypeList) {
|
|
|
+ if (ObjectUtil.notEqual(orgType, plan.getExecOrgType())) {
|
|
|
+ list.add("参数中," + plan.getPlanName() + "计划下存在错误执行机构数据");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //获取当前计划的所有执行机构,如果参数中存在不属于此计划的执行机构,则返回错误
|
|
|
+ List<Long> collect = coreSafecheckPlanToExecOrgs.stream().map(CoreSafecheckPlanToExecOrg::getOrgId).collect(Collectors.toList());
|
|
|
+ for (Long execOrgId : execOrgIdList) {
|
|
|
+ if (!collect.contains(execOrgId)) {
|
|
|
+ list.add("参数中," + plan.getPlanName() + "计划下存在错误执行机构数据");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(safetyTaskBuildDto.getCheckOrgIdList())) {
|
|
|
+ List<Long> checkOrgIdList = safetyTaskBuildDto.getCheckOrgIdList();
|
|
|
+ for (CoreSafecheckPlan plan : plans) {
|
|
|
+ List<CoreSafecheckPlanToCheckOrg> coreSafecheckPlanToCheckOrgs = planToCheckOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrg>().eq(CoreSafecheckPlanToCheckOrg::getPlanId, plan.getId()));
|
|
|
+ if (ObjectUtil.isEmpty(coreSafecheckPlanToCheckOrgs)) {
|
|
|
+ //说明计划是根据机构类型配置的,获取所有的机构类型,如果参数中受检机构的机构类型存在不属于此计划的受检机构,则返回错误
|
|
|
+ List<Long> orgTypeList = orgService.selectOrgTypeByIdList(checkOrgIdList, SecurityConstants.INNER);
|
|
|
+ for (Long orgType : orgTypeList) {
|
|
|
+ if (ObjectUtil.notEqual(orgType, plan.getCheckOrgType())) {
|
|
|
+ list.add("参数中," + plan.getPlanName() + "计划下存在错误检查机构数据");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //获取当前计划的所有受检机构,如果参数中存在不属于此计划的受检机构,则返回错误
|
|
|
+ List<Long> collect = coreSafecheckPlanToCheckOrgs.stream().map(CoreSafecheckPlanToCheckOrg::getOrgId).collect(Collectors.toList());
|
|
|
+ for (Long checkOrgId : checkOrgIdList) {
|
|
|
+ if (!collect.contains(checkOrgId)) {
|
|
|
+ list.add("参数中," + plan.getPlanName() + "计划下存在错误检查机构数据");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(safetyTaskBuildDto.getRoleIdList())) {
|
|
|
+ List<Long> roleIdList = safetyTaskBuildDto.getRoleIdList();
|
|
|
+ for (CoreSafecheckPlan plan : plans) {
|
|
|
+ List<CoreSafecheckPlanToRole> coreSafecheckPlanToRoles = planToRoleMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToRole>().eq(CoreSafecheckPlanToRole::getPlanId, plan.getId()));
|
|
|
+ List<Long> collect = coreSafecheckPlanToRoles.stream().map(CoreSafecheckPlanToRole::getRoleId).collect(Collectors.toList());
|
|
|
+ if (!new HashSet<>(collect).containsAll(roleIdList)) {
|
|
|
+ list.add("参数中," + plan.getPlanName() + "计划下存在错误角色数据");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (DateUtil.beginOfDay(map.get("end")).isBefore(DateUtil.beginOfDay(new Date()))) {
|
|
|
+ list.add("计划周期已过");
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|