|
|
@@ -11,6 +11,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.DictConstants;
|
|
|
import com.xunmei.common.core.constant.ErrorMsgConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
@@ -19,8 +22,11 @@ import com.xunmei.common.core.domain.registerbook.domain.CoreRegisterBookPdf;
|
|
|
import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
import com.xunmei.common.core.enums.PlanStatus;
|
|
|
import com.xunmei.common.core.enums.RegisterBookType;
|
|
|
+import com.xunmei.common.core.enums.drill.DrillPlanStatus;
|
|
|
import com.xunmei.common.core.exception.ServiceException;
|
|
|
import com.xunmei.common.core.exception.SystemException;
|
|
|
+import com.xunmei.common.core.thread.ThreadPoolConfig;
|
|
|
+import com.xunmei.common.core.util.BeanHelper;
|
|
|
import com.xunmei.common.core.utils.DateHelper;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
@@ -50,10 +56,12 @@ import com.xunmei.system.api.domain.SafeCheckTaskRegisterBookVo;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.enums.BusinessPlanType;
|
|
|
import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
|
|
|
+import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -63,12 +71,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.io.File;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static java.util.stream.Collectors.toList;
|
|
|
+
|
|
|
/**
|
|
|
* 常规安全检查计划Service业务层处理
|
|
|
*
|
|
|
@@ -109,6 +117,10 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
|
|
|
@Autowired
|
|
|
private CoreSafecheckPlanToCheckOrgTypeMapper coreSafecheckPlanToCheckOrgTypeMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
+
|
|
|
@Override
|
|
|
public TableDataInfo<CoreSafecheckPlan> selectPage(CoreSafecheckPlan coreSafecheckPlan) {
|
|
|
//未删除
|
|
|
@@ -1119,7 +1131,7 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
|
|
|
throw new ServiceException("计划不存在");
|
|
|
}
|
|
|
|
|
|
- LambdaUpdateWrapper<CoreSafecheckPlan> wrapper = new LambdaUpdateWrapper();
|
|
|
+ LambdaUpdateWrapper<CoreSafecheckPlan> wrapper = new LambdaUpdateWrapper<>();
|
|
|
wrapper.eq(CoreSafecheckPlan::getId, planId)
|
|
|
.set(CoreSafecheckPlan::getTaskHasCompleted, state);
|
|
|
|
|
|
@@ -1137,10 +1149,139 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
|
|
|
@Override
|
|
|
public void compensate(CompensateDto compensateDto) {
|
|
|
|
|
|
+ CoreSafecheckPlan safeCheckPlan = getById(compensateDto.getPlanId());
|
|
|
+
|
|
|
+ if (ObjectUtil.isNull(safeCheckPlan)) {
|
|
|
+ throw new ServiceException("计划不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.notEqual(safeCheckPlan.getPlanStatus(), PlanStatus.USING.getCode())) {
|
|
|
+ throw new ServiceException("计划尚未下发或已停用");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.equal(safeCheckPlan.getIsDeleted(), "1")) {
|
|
|
+ throw new ServiceException("计划状态异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysOrgVO> orgCacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ //推断计划 创建任务
|
|
|
+ deducePlanAndBuildTask(safeCheckPlan, compensateDto.getOrgIdList(), orgCacheList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static final Set<OrgTypeEnum> INVALID_ORG_TYPES = Sets.newHashSet(OrgTypeEnum.SHEGN_LIAN_SHE, OrgTypeEnum.BAN_SHI_CHU, OrgTypeEnum.DIQU_HANG_SHE);
|
|
|
+
|
|
|
+ private void deducePlanAndBuildTask(CoreSafecheckPlan safeCheckPlan, List<Long> orgIdList, List<SysOrgVO> orgCacheList) {
|
|
|
+ List<SysOrgVO> orgList = orgCacheList.stream().filter(org -> orgIdList.contains(org.getId())).collect(toList());
|
|
|
+ if (orgList.isEmpty()) {
|
|
|
+ throw new ServiceException("未查询到orgIdList中指定的机构信息");
|
|
|
+ }
|
|
|
+ List<Long> idList = orgList.stream().map(SysOrgVO::getId).collect(toList());
|
|
|
+ List<Integer> typeList = orgList.stream().map(SysOrgVO::getType).distinct().collect(toList());
|
|
|
+ if (typeList.size() > 1) {
|
|
|
+ throw new ServiceException("orgIdList中指定的机构信息存在多种机构类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgTypeEnum orgTypeEnum = OrgTypeEnum.getOrgTypeEnum(typeList.get(0));
|
|
|
+
|
|
|
+ // 省联社创建的计划
|
|
|
+ if (checkIsParentPlan(safeCheckPlan.getId())) {
|
|
|
+ List<CoreSafecheckPlan> allHsPlanList = getHsPlanList(safeCheckPlan);
|
|
|
+ if (ObjectUtil.isEmpty(allHsPlanList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = getHsOrg(orgCacheList, orgList, orgTypeEnum);
|
|
|
+ List<Long> hsPlanIdList = allHsPlanList.stream().map(CoreSafecheckPlan::getId).collect(toList());
|
|
|
+ List<Long> hsOrgIdList = ((List<SysOrgVO>) map.get("list")).stream().map(SysOrgVO::getId).collect(toList());
|
|
|
+ if (ObjectUtil.hasEmpty(hsPlanIdList, hsOrgIdList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<CoreSafecheckPlan> reallyPlanList = findReallyPlanIdList(hsPlanIdList, hsOrgIdList);
|
|
|
+ boolean underHsOrgType = (boolean) map.get("underHsOrgType");
|
|
|
+ create(reallyPlanList, underHsOrgType ? idList : null);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 行社自建计划
|
|
|
+ if (INVALID_ORG_TYPES.contains(orgTypeEnum)) {
|
|
|
+ throw new ServiceException("orgIdList中传递机构信息错误!与计划信息不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CoreSafecheckPlan> plans = Lists.newArrayList(safeCheckPlan);
|
|
|
+ if (OrgTypeEnum.HANG_SHE.equals(orgTypeEnum)) {
|
|
|
+ create(plans, null);
|
|
|
+ } else {
|
|
|
+ //其实这里如果真是传入了行社以下的机构,那么大概率这里的reallyPlanIdList 计划id也只会有一个元素
|
|
|
+ create(plans, idList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void create(List<CoreSafecheckPlan> planList, List<Long> idList) {
|
|
|
+ run(() -> safetyCheckJobBusiness.createTask(planList, idList), threadPoolTaskExecutor);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CoreSafecheckPlan> findReallyPlanIdList(List<Long> planIdList, List<Long> orgIdList) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<CoreSafecheckPlan> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.in(CoreSafecheckPlan::getId, planIdList);
|
|
|
+ wrapper.in(CoreSafecheckPlan::getPlanOfOrgId, orgIdList);
|
|
|
+ return baseMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkIsParentPlan(Long planId) {
|
|
|
+ LambdaQueryWrapper<CoreSafecheckPlan> countWrapper = new LambdaQueryWrapper<>();
|
|
|
+ countWrapper.eq(CoreSafecheckPlan::getParentId, planId);
|
|
|
+ Long l = baseMapper.selectCount(countWrapper);
|
|
|
+ return ObjectUtil.isNotNull(l) && l.compareTo(0L) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<CoreSafecheckPlan> getHsPlanList(CoreSafecheckPlan drillPlan) {
|
|
|
+ LambdaQueryWrapper<CoreSafecheckPlan> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CoreSafecheckPlan::getPlanStatus, DrillPlanStatus.USING.getCode());
|
|
|
+ wrapper.eq(CoreSafecheckPlan::getIsDeleted, "0");
|
|
|
+ wrapper.eq(CoreSafecheckPlan::getParentId, drillPlan.getId());
|
|
|
+ return baseMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> getHsOrg(List<SysOrgVO> orgCacheList, List<SysOrgVO> needBuildTaskOrgList, OrgTypeEnum needBuildTaskOrgTypeEnum) {
|
|
|
+ List<SysOrgVO> list = new ArrayList<>();
|
|
|
+ boolean underHsOrgType = false;
|
|
|
+ switch (needBuildTaskOrgTypeEnum) {
|
|
|
+ //如果是省联社/办事处/地区行社 那么找到下级的行社
|
|
|
+ case SHEGN_LIAN_SHE:
|
|
|
+ case BAN_SHI_CHU:
|
|
|
+ case DIQU_HANG_SHE:
|
|
|
+ for (SysOrgVO sysOrgVO : needBuildTaskOrgList) {
|
|
|
+ String path = sysOrgVO.getPath();
|
|
|
+ List<SysOrgVO> collect = orgCacheList
|
|
|
+ .stream()
|
|
|
+ .filter(org -> ObjectUtil.isAllNotEmpty(org.getPath(), org.getType()))
|
|
|
+ .filter(org -> org.getPath().contains(path))
|
|
|
+ .filter(org -> org.getType().equals(OrgTypeEnum.HANG_SHE.getCode()))
|
|
|
+ .collect(toList());
|
|
|
+ list.addAll(collect);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case HANG_SHE: //如果传进来的就是行社 那么直接返回
|
|
|
+ list = needBuildTaskOrgList;
|
|
|
+ break;
|
|
|
+ default: //如果是行社以下机构类型,那么找到上级的行社机构返回
|
|
|
+ List<Long> ids = needBuildTaskOrgList.stream().map(SysOrgVO::getId).collect(toList());
|
|
|
+ List<SysOrg> sysOrgs = orgService.selectParentHs(ids, SecurityConstants.INNER);
|
|
|
+ list = BeanHelper.copyProperties(sysOrgs, SysOrgVO.class);
|
|
|
+ underHsOrgType = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("list", list);
|
|
|
+ map.put("underHsOrgType", underHsOrgType);
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run(Runnable runnable, ThreadPoolTaskExecutor threadPoolTaskExecutor) {
|
|
|
-
|
|
|
+ CompletableFuture.runAsync(runnable, threadPoolTaskExecutor);
|
|
|
}
|
|
|
}
|