郑永安
2023-07-24 0645153dfa233b51a749db73f9bd5a8c5127c595
src/main/java/com/gk/hotwork/Service/ServiceImpl/ElementManagementImpl.java
@@ -5,12 +5,11 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.ElementManagement;
import com.gk.hotwork.Domain.ElementTree;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Mapper.ElementManagementMapper;
import com.gk.hotwork.Mapper.SafetyInspectionItemMapper;
import com.gk.hotwork.Service.ElementManagementService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +27,9 @@
    @Autowired
    private ElementManagementMapper elementManagementMapper;
    @Autowired
    private SafetyInspectionItemMapper safetyInspectionItemMapper;
    /**
    * @Description: 分页
@@ -96,7 +98,9 @@
                elementTree.setType(Integer.valueOf(e.get("type").toString()));
                elementTree.setLabel(e.get("label").toString());
                elementTree.setValue(Long.valueOf(e.get("value").toString()));
                elementTree.setLeaf(e.get("isLeaf").toString().equals("1")?true:false);
                elementTree.setLeaf(e.get("isLeaf").toString().equals("1")?true:false);
                elementTree.setPid(Long.valueOf(e.get("pid").toString()));
                elementTree.setPoint(e.get("point") != null ? Integer.valueOf(e.get("point").toString()) : 0);
                if(elementTree.isLeaf()){
                   elementTree.setChildren(new ArrayList<ElementTree>());
                   elementTreeList.add(elementTree);
@@ -175,6 +179,36 @@
        return returnTree;
    }
    @Override
    public List<ElementManagement> getElementByParentId(Long parentId) {
        List<ElementManagement> list = elementManagementMapper.selectList(new LambdaQueryWrapper<ElementManagement>()
                .eq(ElementManagement::getValidFlag, 1)
                .eq(ElementManagement::getParentId, parentId));
        return list;
    }
    @Override
    public List<ElementTree> getElementTreeByParentId(Long parentId) {
        List<ElementTree> returnTree = new ArrayList<>();
        List<Map<String,Object>> list = elementManagementMapper.getElementTree(); //读取元素配置
        for (Map<String, Object> map : list) {
            if(map.get("value") == parentId){ //一级要素,MenuType2
                ElementTree elementTree=new ElementTree();
                elementTree.setType(Integer.valueOf(map.get("type").toString()));
                elementTree.setLabel(map.get("label").toString());
                elementTree.setValue(Long.valueOf(map.get("value").toString()));
                elementTree.setLeaf(map.get("isLeaf").toString().equals("1")?true:false);
                elementTree.setPoint(map.get("point") != null ? Integer.valueOf(map.get("point").toString()) : 0);
                elementTree.setChildren(getChindrenTree(list,Long.valueOf(map.get("value").toString())));
                returnTree.add(elementTree);
            }else{
                continue;
            }
        }
        return returnTree;
    }
    /**
     * 查询验证
     * 验证对象存在
@@ -194,9 +228,25 @@
    public void requiredVerification(ElementManagement param){
        if(StringUtils.isBlank(param.getName())) throw new BusinessException("请填写要素名称");
        if (param.getType() == null) throw new BusinessException("请选择要素类型");
        if (param.getType() == 1 && param.getParentId()==null){
            throw new BusinessException("请选择父要素");
        if (param.getType() == 1 && param.getParentId() == null){//二级要素
            throw new BusinessException("请选择一级要素");
        }
        if(param.getType() == 2){//三级要素
            if(param.getParentId() == null){
                throw new BusinessException("请选择二级要素");
            }
            List<SafetyInspectionItem> safetyInspectionItems = safetyInspectionItemMapper.selectList(new LambdaQueryWrapper<SafetyInspectionItem>()
                    .eq(SafetyInspectionItem::getValidFlag, 1)
                    .eq(SafetyInspectionItem::getElementB, param.getParentId()));
            if(safetyInspectionItems.size() > 0){
                throw new BusinessException("二级要素下存在检查内容,不可建立三级");
            }
        }
    }
    /**