郑永安
2023-07-24 0645153dfa233b51a749db73f9bd5a8c5127c595
src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyInspectionItemImpl.java
@@ -6,9 +6,11 @@
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.dto.resp.SafetyInspectionElementRespDTO;
import com.gk.hotwork.Mapper.SafetyInspectionItemDeductionMapper;
import com.gk.hotwork.Mapper.SafetyInspectionItemMapper;
import com.gk.hotwork.Service.ElementManagementService;
import com.gk.hotwork.Service.SafetyInspectionElementAService;
import com.gk.hotwork.Service.SafetyInspectionItemService;
import org.apache.commons.collections4.CollectionUtils;
import org.checkerframework.checker.units.qual.C;
@@ -20,6 +22,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service("SafetyInspectionItemService")
@Transactional
@@ -32,6 +35,9 @@
    @Autowired
    private ElementManagementService elementManagementService;
    @Autowired
    private SafetyInspectionElementAService safetyInspectionElementAService;
    /**
    * @Description: 分页
@@ -175,10 +181,69 @@
    }
    @Override
    public List<SafetyInspectionItem> infoElementA(Long id, UserInfo user) {
    public SafetyInspectionElementRespDTO infoElementA(Long id, UserInfo user) {
        //获取要素
        List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(id);
        if(CollectionUtils.isEmpty(elementTree)){
            throw new BusinessException("该要素记录不存在");
        }
        //获取要素树下面的检查项
        List<SafetyInspectionItem> list = safetyInspectionItemMapper.infoElementA(id);
        if (CollectionUtils.isNotEmpty(list)){
            for (SafetyInspectionItem safetyInspectionItem : list){
        //一级
        SafetyInspectionElementRespDTO respDTO = new SafetyInspectionElementRespDTO();
        respDTO.setElementId(elementTree.get(0).getValue());
        respDTO.setElementName(elementTree.get(0).getLabel());
        respDTO.setType(elementTree.get(0).getType());
        respDTO.setPid(elementTree.get(0).getPid());
        List<SafetyInspectionElementRespDTO> sRespList = new ArrayList<>();
        //循环孩子节点(二级)
        if(CollectionUtils.isNotEmpty(elementTree.get(0).getChildren())){
            for (ElementTree schildren : elementTree.get(0).getChildren()){
                SafetyInspectionElementRespDTO schildrenRespDTO = new SafetyInspectionElementRespDTO();
                schildrenRespDTO.setElementId(schildren.getValue());
                schildrenRespDTO.setElementName(schildren.getLabel());
                schildrenRespDTO.setType(schildren.getType());
                schildrenRespDTO.setPid(schildren.getPid());
                if(CollectionUtils.isEmpty(schildren.getChildren())){
                    List<SafetyInspectionItem> sSelectItemList = list
                            .stream()
                            .filter(item -> item.getElementB().equals(schildren.getValue()) && item.getElementC() == null)
                            .collect(Collectors.toList());
                    schildrenRespDTO.setItemList(getSafetyInspectionItem(sSelectItemList));
                }else {
                    List<SafetyInspectionElementRespDTO> tRespList = new ArrayList<>();
                    //三级
                    for (ElementTree tchildren : schildren.getChildren()){
                        SafetyInspectionElementRespDTO tchildrenRespDTO = new SafetyInspectionElementRespDTO();
                        tchildrenRespDTO.setElementId(tchildren.getValue());
                        tchildrenRespDTO.setElementName(tchildren.getLabel());
                        tchildrenRespDTO.setType(tchildren.getType());
                        tchildrenRespDTO.setPid(tchildren.getPid());
                        List<SafetyInspectionItem> tSelectItemList = list
                                .stream()
                                .filter(item -> item.getElementC() != null && item.getElementC().equals(tchildren.getValue()))
                                .collect(Collectors.toList());
                        tchildrenRespDTO.setItemList(getSafetyInspectionItem(tSelectItemList));
                        tRespList.add(tchildrenRespDTO);
                    }
                    schildrenRespDTO.setChildren(tRespList);
                }
                sRespList.add(schildrenRespDTO);
            }
        }
        respDTO.setChildren(sRespList);
        return respDTO;
    }
    private List<SafetyInspectionItem> getSafetyInspectionItem(List<SafetyInspectionItem> itemList){
        if (CollectionUtils.isNotEmpty(itemList)){
            for (SafetyInspectionItem safetyInspectionItem : itemList){
                List<SafetyInspectionItemDeduction> deductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetyInspectionItem.getId());
                if (CollectionUtils.isNotEmpty(deductionList)){
                    safetyInspectionItem.setDeductionList(deductionList);
@@ -187,7 +252,8 @@
                }
            }
        }
        return list;
        return itemList;
    }
    @Override
@@ -221,6 +287,11 @@
    public void requiredVerification(SafetyInspectionItem param){
        if (param.getElementA() == null) throw new BusinessException("请选择A级要素");
        if (param.getElementB() == null) throw new BusinessException("请选择B级要素");
        //如果有三级要素则不创建标准
        List<ElementManagement> elementList = elementManagementService.getElementByParentId(param.getElementB());
        if(elementList.size() > 0){
            throw new BusinessException("请先删除三级要素");
        }
        if(StringUtils.isBlank(param.getStandardizationRequirements())) throw new BusinessException("请填写标准化要求");
        if(StringUtils.isBlank(param.getEnterpriseStandard())) throw new BusinessException("请填写企业达标标准");
        if(StringUtils.isBlank(param.getReviewMethod())) throw new BusinessException("请填写评审方法");