|
|
@@ -0,0 +1,298 @@
|
|
|
+package com.xunmei.core.safetyCheck.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.utils.IDHelper;
|
|
|
+import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.core.resumption.domain.AppRule;
|
|
|
+import com.xunmei.core.resumption.domain.AppRuleItem;
|
|
|
+import com.xunmei.core.resumption.domain.AppRulePoint;
|
|
|
+import com.xunmei.core.resumption.dto.ruleItem.AppRuleItemDetailDto;
|
|
|
+import com.xunmei.core.resumption.dto.ruleItem.AppRuleItemPageDto;
|
|
|
+import com.xunmei.core.resumption.dto.ruleItem.AppRulePointSelectPageDto;
|
|
|
+import com.xunmei.core.resumption.dto.rulePoint.AppRulePointDetailDto;
|
|
|
+import com.xunmei.core.resumption.dto.rulePoint.AppRulePointDto;
|
|
|
+import com.xunmei.core.resumption.vo.appRuleItem.AppRuleItemPageVo;
|
|
|
+import com.xunmei.core.resumption.vo.appRuleItem.AppRulePointSelectVo;
|
|
|
+import com.xunmei.core.resumption.vo.appRuleItem.RuleTreeItem;
|
|
|
+import com.xunmei.core.safetyCheck.domain.SafetyCheckRule;
|
|
|
+import com.xunmei.core.safetyCheck.domain.SafetyCheckRuleItem;
|
|
|
+import com.xunmei.core.safetyCheck.domain.SafetyCheckRulePoint;
|
|
|
+import com.xunmei.core.safetyCheck.dto.ruleItem.SafetyCheckRuleItemDetailDto;
|
|
|
+import com.xunmei.core.safetyCheck.dto.ruleItem.SafetyCheckRuleItemDto;
|
|
|
+import com.xunmei.core.safetyCheck.dto.ruleItem.SafetyCheckRuleItemPageDto;
|
|
|
+import com.xunmei.core.safetyCheck.dto.ruleItem.SafetyCheckRulePointSelectPageDto;
|
|
|
+import com.xunmei.core.safetyCheck.dto.rulePoint.SafetyCheckRulePointDetailDto;
|
|
|
+import com.xunmei.core.safetyCheck.dto.rulePoint.SafetyCheckRulePointDto;
|
|
|
+import com.xunmei.core.safetyCheck.mapper.SafetyCheckRuleItemMapper;
|
|
|
+import com.xunmei.core.safetyCheck.mapper.SafetyCheckRuleMapper;
|
|
|
+import com.xunmei.core.safetyCheck.mapper.SafetyCheckRulePointMapper;
|
|
|
+import com.xunmei.core.safetyCheck.service.ISafetyCheckRuleItemService;
|
|
|
+import com.xunmei.core.safetyCheck.service.ISafetyCheckRulePointService;
|
|
|
+import com.xunmei.core.safetyCheck.vo.ruleItem.SafetyCheckRuleItemPageVo;
|
|
|
+import com.xunmei.core.safetyCheck.vo.ruleItem.SafetyCheckRulePointSelectVo;
|
|
|
+import com.xunmei.system.api.Eto.OrgListByTypesConditionEto;
|
|
|
+import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author jingyuanchao
|
|
|
+ * @since 2022-04-27
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SafetyCheckRuleItemServiceImpl
|
|
|
+ extends ServiceImpl<SafetyCheckRuleItemMapper, SafetyCheckRuleItem>
|
|
|
+ implements ISafetyCheckRuleItemService {
|
|
|
+ @Resource
|
|
|
+ private SafetyCheckRuleItemMapper safetyCheckRuleItemMapper;
|
|
|
+ @Resource
|
|
|
+ private ISafetyCheckRulePointService safetyCheckRulePointService;
|
|
|
+ @Resource
|
|
|
+ private SafetyCheckRulePointMapper safetyCheckRulePointMapper;
|
|
|
+// @Resource
|
|
|
+// private SysDictDetailService sysDictDetailService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ RemoteOrgService remoteOrgService;
|
|
|
+ @Resource
|
|
|
+ private SafetyCheckRuleMapper safetyCheckRuleMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public long edit(SafetyCheckRuleItemDto ruleItemDto) {
|
|
|
+ final SafetyCheckRuleItem item = new SafetyCheckRuleItem();
|
|
|
+ BeanUtils.copyProperties(ruleItemDto, item);
|
|
|
+// if (item.getId() == null) {
|
|
|
+// item.setId(IDHelper.id());
|
|
|
+// }
|
|
|
+
|
|
|
+// Integer num = safetyCheckRuleItemMapper.checkItemNumRepeat(item.getId(), item.getRuleId(), item.getItemNum());
|
|
|
+// if (num > 0) {
|
|
|
+// throw new RuntimeException("检查项编号重复");
|
|
|
+// }
|
|
|
+
|
|
|
+ Integer itemNameNums = safetyCheckRuleItemMapper.checkItemNameRepeat(item.getId(), item.getRuleId(), item.getName());
|
|
|
+ if (itemNameNums > 0) {
|
|
|
+ throw new RuntimeException("检查项名称重复");
|
|
|
+ }
|
|
|
+
|
|
|
+ final SafetyCheckRule rule = safetyCheckRuleMapper.selectById(ruleItemDto.getRuleId());
|
|
|
+ if (rule == null) {
|
|
|
+ throw new RuntimeException("请选择具体规范新增数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ saveOrUpdate(item);
|
|
|
+ final List<SafetyCheckRulePointDto> pointDtoList = ruleItemDto.getPointDtoList();
|
|
|
+ Set<String> hashMap = new HashSet<>();
|
|
|
+ for (SafetyCheckRulePointDto appRulePointDto : pointDtoList) {
|
|
|
+ if (hashMap.contains(appRulePointDto.getName())) {
|
|
|
+ throw new RuntimeException("履职内容重复!");
|
|
|
+ }
|
|
|
+ hashMap.add(appRulePointDto.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ final List<Long> pointIds = safetyCheckRulePointMapper.selectPointIds(item.getId());
|
|
|
+ if (pointIds.size() > 0) {
|
|
|
+ List<Long> idList2 = pointDtoList.stream().map(SafetyCheckRulePointDto::getId).collect(Collectors.toList());
|
|
|
+ for (Long pointId : pointIds) {
|
|
|
+ if (!idList2.contains(pointId)) {
|
|
|
+ Integer isUsed = safetyCheckRulePointMapper.checkIsUsed(pointId);
|
|
|
+ if (isUsed == null) {
|
|
|
+ safetyCheckRulePointMapper.deleteById(pointId);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("有要点已被使用,不能删除!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (SafetyCheckRulePointDto appRulePointDto : pointDtoList) {
|
|
|
+ SafetyCheckRulePoint point = new SafetyCheckRulePoint();
|
|
|
+ BeanUtils.copyProperties(appRulePointDto, point);
|
|
|
+ point.setItemId(item.getId());
|
|
|
+ point.setRuleId(item.getRuleId());
|
|
|
+ if (point.getId() == null) {
|
|
|
+ //新增
|
|
|
+ point.setId(IDHelper.id());
|
|
|
+
|
|
|
+ safetyCheckRulePointService.save(point);
|
|
|
+ } else {
|
|
|
+ //修改
|
|
|
+ Integer isUsed = safetyCheckRulePointMapper.checkIsUsed(point.getId());
|
|
|
+ if (isUsed == null) {
|
|
|
+ safetyCheckRulePointService.updateById(point);
|
|
|
+ } else {
|
|
|
+ //将之前的记录逻辑删除,然后新增一条记录关联到检查项
|
|
|
+ safetyCheckRulePointMapper.updateDeleted(point.getId(), 1);
|
|
|
+ Long newId = IDHelper.id();
|
|
|
+ safetyCheckRulePointMapper.updatePlanItem(point.getId(), newId);
|
|
|
+ point.setId(newId);
|
|
|
+ safetyCheckRulePointMapper.insert(point);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return item.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo pageQuery(SafetyCheckRuleItemPageDto itemPageDto) {
|
|
|
+ Page<SafetyCheckRuleItemPageVo> page;
|
|
|
+
|
|
|
+ page = safetyCheckRuleItemMapper.pageQuery(itemPageDto.getPageDto(), itemPageDto);
|
|
|
+// int order = itemPageDto() * itemPageDto.getSize();
|
|
|
+ for (SafetyCheckRuleItemPageVo vo : page.getRecords()) {
|
|
|
+// vo.setOrder(++order);
|
|
|
+ final List<SafetyCheckRulePointDetailDto> pointList = safetyCheckRulePointMapper.selectDataListByItemId(vo.getId());
|
|
|
+ vo.setPointDtoList(pointList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return TableDataInfo.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SafetyCheckRuleItemDetailDto findOne(Long id) {
|
|
|
+ final SafetyCheckRuleItem appRuleItem = safetyCheckRuleItemMapper.selectById(id);
|
|
|
+ if (ObjectUtil.isNull(appRuleItem)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SafetyCheckRuleItemDetailDto appRuleItemDto = new SafetyCheckRuleItemDetailDto();
|
|
|
+ BeanUtils.copyProperties(appRuleItem, appRuleItemDto);
|
|
|
+
|
|
|
+ List<SafetyCheckRulePointDetailDto> list = safetyCheckRulePointMapper.selectDataListByItemId(id);
|
|
|
+ appRuleItemDto.setPointDtoList(list);
|
|
|
+ return appRuleItemDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean del(Long id) {
|
|
|
+ List<Long> idList = safetyCheckRulePointMapper.selectPointIds(id);
|
|
|
+ if (idList.size() > 0) {
|
|
|
+
|
|
|
+ Integer num1 = safetyCheckRulePointMapper.checkIsJoinResumptionPlan(idList);
|
|
|
+ if (ObjectUtil.isNotNull(num1)) {
|
|
|
+ throw new RuntimeException("该检查项已被检查计划或履职计划关联,请先删除检查计划或履职计划!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ safetyCheckRuleItemMapper.deleteById(id);
|
|
|
+ safetyCheckRulePointMapper.deleteByMap(MapUtil.of("item_id", id));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RuleTreeItem> getRuleTree(Long orgId) {
|
|
|
+ List<RuleTreeItem> tree = new ArrayList<>();
|
|
|
+ List<SysOrg> orgs = remoteOrgService
|
|
|
+ .listByTypes(OrgListByTypesConditionEto.builder().orgId(orgId).orgTypes(Arrays.asList("1", "2", "3", "4", "11")).build())
|
|
|
+ .getData();
|
|
|
+ if (ObjectUtil.isEmpty(orgs)) {
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+ Map<Long, SysOrg> orgMap = orgs.stream().collect(Collectors.toMap(o -> o.getId(), o -> o));
|
|
|
+ List<SysOrg> tops = orgs.stream().filter(o -> !orgMap.containsKey(o.getParentId())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isEmpty(tops)) {
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+ List<Long> orgIds = orgs.stream().map(o -> o.getId()).collect(Collectors.toList());
|
|
|
+ List<SafetyCheckRule> rules = safetyCheckRuleMapper.selectList(new LambdaQueryWrapper<SafetyCheckRule>().in(SafetyCheckRule::getOrgId, orgIds));
|
|
|
+
|
|
|
+ tree = tops.stream().map(o -> generateTree(o, orgs, rules)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return tree;
|
|
|
+ }
|
|
|
+
|
|
|
+ private RuleTreeItem generateTree(SysOrg parent, List<SysOrg> allOrg, List<SafetyCheckRule> allRule) {
|
|
|
+ RuleTreeItem item = RuleTreeItem.builder().isRule(0).id(parent.getId()).label(parent.getName()).children(new ArrayList<>()).build();
|
|
|
+ List<RuleTreeItem> ruleItems = allRule.stream().filter(r -> ObjectUtil.equal(r.getOrgId(), parent.getId()))
|
|
|
+ .map(o -> RuleTreeItem.builder().isRule(1).id(o.getId()).label(o.getName()).orgType(o.getOrgType()).build())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ item.getChildren().addAll(ruleItems);
|
|
|
+
|
|
|
+ List<SysOrg> children = allOrg.stream()
|
|
|
+ .filter(o -> ObjectUtil.equal(o.getParentId(), parent.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (SysOrg child : children) {
|
|
|
+ item.getChildren().add(generateTree(child, allOrg, allRule));
|
|
|
+ }
|
|
|
+
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取履职内容选择框的翻页列表
|
|
|
+ *
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo pointSelectionPage(SafetyCheckRulePointSelectPageDto dto) {
|
|
|
+ Page<SafetyCheckRulePointSelectVo> page = dto.getPageDto();
|
|
|
+ page = safetyCheckRulePointMapper.pointSelectionPage(page, dto);
|
|
|
+ return TableDataInfo.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public SysDictListDto dict() {
|
|
|
+// final SysDictListDto dto = new SysDictListDto();
|
|
|
+// final List<SysDictDetail> detailList = sysDictDetailService.all();
|
|
|
+// final List<SysDictDetail> checkMethodList = detailList.stream().filter(detail -> "check_method".equals(detail.getDictCode())).collect(Collectors.toList());
|
|
|
+// final List<SysDictDetail> checkTypeList = detailList.stream().filter(detail -> "check_type".equals(detail.getDictCode())).collect(Collectors.toList());
|
|
|
+// final List<SysDictDetail> rectifyTremList = detailList.stream().filter(detail -> "rectify_trem".equals(detail.getDictCode())).collect(Collectors.toList());
|
|
|
+// dto.setCheckTypeList(checkTypeList);
|
|
|
+// dto.setRectifyTremList(rectifyTremList);
|
|
|
+// dto.setCheckMethodList(checkMethodList);
|
|
|
+// return dto;
|
|
|
+// }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public List<SecBookDtInstDto> dataType() {
|
|
|
+//
|
|
|
+// return safetyCheckRuleItemMapper.selectDataTypeList();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<AreaListVo> selectCheckAreaList() {
|
|
|
+// return safetyCheckRuleItemMapper.selectCheckAreaList();
|
|
|
+// }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public JsonResponse<?> checkRepeat(AppRuleItemCheckDto checkDto) {
|
|
|
+// if (checkDto.getItemNum() != null) {
|
|
|
+// Integer num = safetyCheckRuleItemMapper.checkItemNumRepeat(checkDto.getItemId(), checkDto.getRuleId(), checkDto.getItemNum());
|
|
|
+// if (num > 0) {
|
|
|
+// return JsonResponse.fail("检查项编号重复!");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (checkDto.getPointNum() != null) {
|
|
|
+// Integer num = safetyCheckRulePointMapper.checkPointNumRepeat(checkDto.getItemId(), checkDto.getPointId(), checkDto.getPointNum());
|
|
|
+// if (num > 0) {
|
|
|
+// return JsonResponse.fail("要点编号重复!");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (!StringUtil.isNullOrEmpty(checkDto.getPointName())) {
|
|
|
+// Integer num = safetyCheckRulePointMapper.checkPointNameRepeat(checkDto.getItemId(), checkDto.getPointId(), checkDto.getPointName());
|
|
|
+// if (num > 0) {
|
|
|
+// return JsonResponse.fail("要点名称重复!");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return JsonResponse.success();
|
|
|
+// }
|
|
|
+}
|