From 0645153dfa233b51a749db73f9bd5a8c5127c595 Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: 星期一, 24 七月 2023 09:27:53 +0800
Subject: [PATCH] Merge branch 'master' of https://sinanoaq.cn:8888/r/hazardInvestigationSystem.git

---
 src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java |  546 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 535 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java
index 14dd1ae..d6664fa 100644
--- a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java
+++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java
@@ -1,16 +1,19 @@
 package com.gk.hotwork.Service.ServiceImpl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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.*;
 import com.gk.hotwork.Domain.Do.SafetySelfInspectionItemQualifiedCountDO;
 import com.gk.hotwork.Domain.Exception.BusinessException;
+import com.gk.hotwork.Domain.Utils.BeanUtils;
 import com.gk.hotwork.Domain.Utils.StringUtils;
+import com.gk.hotwork.Domain.Vo.UserVo;
+import com.gk.hotwork.Domain.dto.resp.SafetySelfInspectionElementRespDTO;
+import com.gk.hotwork.Domain.dto.resp.SafetySelfInspectionRespDTO;
 import com.gk.hotwork.Mapper.*;
-import com.gk.hotwork.Service.CompanyService;
-import com.gk.hotwork.Service.SafetySelfInspectionService;
-import com.gk.hotwork.Service.UserService;
+import com.gk.hotwork.Service.*;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -38,26 +41,38 @@
     private SafetyInspectionItemDeductionMapper safetyInspectionItemDeductionMapper;
     @Autowired
     private CompanyService companyService;
+    @Autowired
+    private ElementManagementService elementManagementService;
+    @Autowired
+    private SafetyInspectionElementAService safetyInspectionElementAService;
+    @Autowired
+    private UserService userService;
+    @Autowired
+    private InspectionExpertGroupService expertGroupService;
+    @Autowired
+    private InspectionExpertService expertService;
+    @Autowired
+    private InspectionHiddenDangerService dangerService;
+
     /**
      * @Description: 分页
      */
     @Override
     public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) {
         Integer type = user.getType();
-        //普通用户
+        //企业用户
         if (type.equals(3)) {
             Long companyid = user.getCompanyid();
-            filter.put("companyid",companyid);
+            filter.put("checkedCompanyId",companyid);
         }
         //监管用户
         if (type.equals(2)) {
-            Long companyid = user.getCompanyid();
             //获取企业信息
-            CompanyInfo companyInfo = companyService.getById(companyid);
-            filter.put("province",companyInfo.getProvince());
-            filter.put("city",companyInfo.getCity());
-            filter.put("area",companyInfo.getArea());
+            filter.put("province",user.getProvince());
+            filter.put("city",user.getCity());
+            filter.put("area",user.getCounty());
         }
+        filter.put("flag",0);
 
         IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter);
         List<SafetySelfInspection> records = res.getRecords();
@@ -83,6 +98,183 @@
         return res;
     }
 
+    /**
+     * @Description: 分页
+     */
+    @Override
+    public IPage<SafetySelfInspection> selectSupervisePage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) {
+        Integer type = user.getType();
+        //普通用户
+        if (type.equals(3)) {
+            Long companyid = user.getCompanyid();
+            filter.put("checkedCompanyId",companyid);
+        }
+        //监管用户
+        if (type.equals(2)) {
+            //获取企业信息
+            filter.put("province",user.getProvince());
+            filter.put("city",user.getCity());
+            filter.put("area",user.getCounty());
+        }
+        filter.put("flag",1);
+
+        IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter);
+        List<SafetySelfInspection> records = res.getRecords();
+        if (CollectionUtils.isNotEmpty(records)){
+            DecimalFormat df = new DecimalFormat("0.00%");
+            records = records.stream().map((safetySelfInspection) -> {
+                if (safetySelfInspection.getStatus() == 2) {
+                    Long id = safetySelfInspection.getId();
+                    SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id);
+                    safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem());
+                    if (countDO != null && countDO.getItemSum() != 0 && countDO.getItemSum() != null) {
+                        BigDecimal rate = new BigDecimal(countDO.getQualifiedItem())
+                                .divide(new BigDecimal(countDO.getItemSum()), 4, BigDecimal.ROUND_HALF_UP);
+                        String qualifiedRate = df.format(rate);
+                        safetySelfInspection.setQualifiedRate(qualifiedRate);
+                        safetySelfInspection.setItemSum(countDO.getItemSum());
+                    }
+                }
+                return safetySelfInspection;
+            }).collect(Collectors.toList());
+            res.setRecords(records);
+        }
+        return res;
+    }
+   /* @Override
+    public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) {
+        Integer type = user.getType();
+        //普通用户
+        if (type.equals(3)) {
+            Long companyid = user.getCompanyid();
+            filter.put("companyid",companyid);
+        }
+        //监管用户
+        if (type.equals(2)) {
+            Long companyid = user.getCompanyid();
+            //获取企业信息
+            CompanyInfo companyInfo = companyService.getById(companyid);
+            filter.put("province",companyInfo.getProvince());
+            filter.put("city",companyInfo.getCity());
+            filter.put("area",companyInfo.getArea());
+        }
+
+        IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter);
+        List<SafetySelfInspection> records = res.getRecords();
+        if (CollectionUtils.isNotEmpty(records)){
+            DecimalFormat df = new DecimalFormat("0.00%");
+            records = records.stream().map((safetySelfInspection) -> {
+                //总分
+                Integer totalScore = 0;
+                //扣分
+                Integer delScore =0;
+
+                Long id = safetySelfInspection.getId();
+                SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id);
+                safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem());
+                if (countDO != null && countDO.getItemSum() != 0 && countDO.getItemSum() != null) {
+                    BigDecimal rate = new BigDecimal(countDO.getQualifiedItem())
+                            .divide(new BigDecimal(countDO.getItemSum()), 4, BigDecimal.ROUND_HALF_UP);
+                    String qualifiedRate = df.format(rate);
+                    safetySelfInspection.setQualifiedRate(qualifiedRate);
+                    safetySelfInspection.setItemSum(countDO.getItemSum());
+                }
+                //计算总分以及得分
+                //获取要素
+                List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id);
+                //获取检查项
+                List<SafetySelfInspectionItem> safetySelfInspectionItemList = safetySelfInspectionItemMapper.getBySafetySelfInspectionId2(id);
+                //循环要素
+                for(SafetyInspectionElementA elementA : inspectionElementAList){
+                    //获取该要素的树
+                    List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA());
+                    //二级要素
+                    if (CollectionUtils.isNotEmpty(elementTree)) {
+                        List<ElementTree> elementBList = elementTree.get(0).getChildren();
+                        for(ElementTree stree : elementBList){
+                            //三级要素为空
+                            if(CollectionUtils.isEmpty(stree.getChildren())){
+                                //总分累计
+                                totalScore += stree.getPoint();
+                                //无三级要素过滤出二级要素检查内容
+                                List<SafetySelfInspectionItem> sItemList = safetySelfInspectionItemList
+                                        .stream()
+                                        .filter(item -> item.getElementC() == null && item.getElementB().equals(stree.getValue()))
+                                        .collect(Collectors.toList());
+                                //判断是否有否决项
+                                List<SafetySelfInspectionItem> rejectList = sItemList
+                                        .stream()
+                                        .filter(item -> item.getSafetyInspectionItemResult().equals(0))
+                                        .collect(Collectors.toList());
+
+                                if(rejectList.size() > 0){
+                                    delScore += stree.getPoint();
+                                }else {
+                                    //计算出不合格扣分
+                                    delScore += unqualifiedItemDelScore(sItemList);
+                                }
+
+                            } else {
+                                List<ElementTree> elementCList = stree.getChildren();
+                                for(ElementTree ttree : elementCList){
+                                    //计算总分
+                                    totalScore += ttree.getPoint();
+                                    //过滤该三级要素检查项目
+                                    List<SafetySelfInspectionItem> tItemList = safetySelfInspectionItemList
+                                            .stream()
+                                            .filter(item -> item.getElementC() != null && item.getElementC().equals(ttree.getValue()))
+                                            .collect(Collectors.toList());
+                                    //判断是否有被否决
+                                    List<SafetySelfInspectionItem> rejectList = tItemList
+                                            .stream()
+                                            .filter(item -> item.getSafetyInspectionItemResult().equals(0))
+                                            .collect(Collectors.toList());
+                                    if(rejectList.size() > 0){
+                                        delScore += ttree.getPoint();
+                                    }else {
+                                        //计算出不合格扣分
+                                        totalScore += unqualifiedItemDelScore(tItemList);
+                                    }
+                                }
+
+                            }
+                        }
+
+                    }
+
+
+                }
+                //得分
+                Integer score = totalScore - delScore;
+                safetySelfInspection.setTotalScore(totalScore.toString());
+                safetySelfInspection.setScore(score.toString());
+                return safetySelfInspection;
+            }).collect(Collectors.toList());
+            res.setRecords(records);
+        }
+        return res;
+    }*/
+    //累计过出不合格扣分
+    private Integer unqualifiedItemDelScore(List<SafetySelfInspectionItem> itemList){
+        int delScore = 0;
+        //过滤出不合格
+        List<SafetySelfInspectionItem> unqualifiedItemList = itemList
+                .stream()
+                .filter(item -> item.getSafetyInspectionItemResult().equals(1))
+                .collect(Collectors.toList());
+        for (SafetySelfInspectionItem unqualifiedItem : unqualifiedItemList){
+            List<SafetySelfInspectionItemDeduction> itemDeductionList = safetySelfInspectionItemDeductionMapper
+                    .selectList(new LambdaQueryWrapper<SafetySelfInspectionItemDeduction>()
+                            .eq(SafetySelfInspectionItemDeduction::getSafetySelfInspectionItemId, unqualifiedItem.getId())
+                            .eq(SafetySelfInspectionItemDeduction::getValidFlag,1));
+            for (SafetySelfInspectionItemDeduction itemDeduction : itemDeductionList) {
+                delScore += itemDeduction.getPoint();
+            }
+        }
+        return delScore;
+    }
+
+
 
     /**
      * @Description: 新增
@@ -95,14 +287,18 @@
         Date date = new Date();
         String username = user.getRealname();
         param.setValidFlag(Boolean.TRUE);
+        param.setFlag((byte) 0);
         param.setUpdateBy(username);
         param.setCreateBy(username);
         param.setUpdateTime(date);
         param.setCreateTime(date);
+        param.setCheckUnit(user.getCompany());
         this.save(param);
 
         if (CollectionUtils.isNotEmpty(param.getItemList())) {
             for (SafetySelfInspectionItem safetySelfInspectionItem : param.getItemList()) {
+                //默认合格
+                safetySelfInspectionItem.setSafetyInspectionItemResult(2);
                 safetySelfInspectionItem.setValidFlag(Boolean.TRUE);
                 safetySelfInspectionItem.setUpdateBy(username);
                 safetySelfInspectionItem.setCreateBy(username);
@@ -110,6 +306,93 @@
                 safetySelfInspectionItem.setCreateTime(date);
                 safetySelfInspectionItem.setSafetySelfInspectionId(param.getId());
                 safetySelfInspectionItemMapper.insert(safetySelfInspectionItem);
+            }
+        }
+        if(CollectionUtils.isNotEmpty(param.getElementAList())){
+            for (SafetyInspectionElementA inspectionElementA : param.getElementAList()) {
+                SafetyInspectionElementA safetyInspectionElementA = new SafetyInspectionElementA();
+                safetyInspectionElementA.setSafetyInspectionId(param.getId());
+                safetyInspectionElementA.setElementA(inspectionElementA.getElementA());
+                safetyInspectionElementAService.save(safetyInspectionElementA);
+            }
+        }
+
+    }
+
+    /**
+     * 监管检查-新增
+     * @param param
+     * @param user
+     */
+    @Override
+    public void addSupervise(SafetySelfInspection param, UserInfo user) {
+        requiredSuperviseVerification(param);
+
+        Date date = new Date();
+        String username = user.getRealname();
+        param.setValidFlag(Boolean.TRUE);
+        param.setFlag((byte) 1);
+        param.setInspector(user.getId());
+        param.setUpdateBy(username);
+        param.setCreateBy(username);
+        param.setUpdateTime(date);
+        param.setCreateTime(date);
+        param.setCheckUnit(user.getCompany());
+        this.save(param);
+
+        //生成专家组记录
+        InspectionExpertGroup inspectionExpertGroup = new InspectionExpertGroup();
+        inspectionExpertGroup.setInspectionName(param.getInspectionName());
+        inspectionExpertGroup.setInspectionTime(param.getInspectionTime());
+        inspectionExpertGroup.setCheckedCompanyId(param.getCheckedCompanyId());
+        inspectionExpertGroup.setCheckedCompanyName(param.getCheckedCompanyName());
+        inspectionExpertGroup.setCheckUnit(user.getCompany());
+        inspectionExpertGroup.setSelfInspectionId(param.getId());
+        inspectionExpertGroup.setValidFlag(true);
+        inspectionExpertGroup.setCreateTime(new Date());
+        List<InspectionExpert> collect = param.getExpertList().stream().filter(inspectionExpert -> inspectionExpert.getIsLeader() == true).collect(Collectors.toList());
+        if (collect.size() > 0) {
+            UserVo userVo = userService.selectUserVoById(collect.get(0).getExpertId());
+            inspectionExpertGroup.setExpertLeader(userVo.getRealname());
+        }
+        expertGroupService.save(inspectionExpertGroup);
+
+
+        if (CollectionUtils.isNotEmpty(param.getItemList())) {
+            for (SafetySelfInspectionItem safetySelfInspectionItem : param.getItemList()) {
+                //默认合格
+                safetySelfInspectionItem.setSafetyInspectionItemResult(2);
+                safetySelfInspectionItem.setValidFlag(Boolean.TRUE);
+                safetySelfInspectionItem.setUpdateBy(username);
+                safetySelfInspectionItem.setCreateBy(username);
+                safetySelfInspectionItem.setUpdateTime(date);
+                safetySelfInspectionItem.setCreateTime(date);
+                safetySelfInspectionItem.setSafetySelfInspectionId(param.getId());
+                safetySelfInspectionItemMapper.insert(safetySelfInspectionItem);
+            }
+        }
+        if(CollectionUtils.isNotEmpty(param.getElementAList())){
+            for (SafetyInspectionElementA inspectionElementA : param.getElementAList()) {
+                SafetyInspectionElementA safetyInspectionElementA = new SafetyInspectionElementA();
+                safetyInspectionElementA.setSafetyInspectionId(param.getId());
+                safetyInspectionElementA.setElementA(inspectionElementA.getElementA());
+                safetyInspectionElementAService.save(safetyInspectionElementA);
+            }
+        }
+
+        if(CollectionUtils.isNotEmpty(param.getExpertList())){
+            for (InspectionExpert inspectionExpert : param.getExpertList()) {
+                UserVo userVo = userService.selectUserVoById(inspectionExpert.getExpertId());
+                inspectionExpert.setCompanyName(userVo.getCompany());
+                inspectionExpert.setIdcard(userVo.getIdcard());
+                inspectionExpert.setName(userVo.getRealname());
+                inspectionExpert.setPhone(userVo.getUsername());
+                inspectionExpert.setType(userVo.getType());
+                inspectionExpert.setProfessionalLevel(user.getProfessionalLevel());
+                inspectionExpert.setSpecialityName(userVo.getSpecialityName());
+                inspectionExpert.setSelfInspectionId(param.getId());
+                inspectionExpert.setExpertGropId(inspectionExpertGroup.getId());
+                expertService.save(inspectionExpert);
             }
         }
     }
@@ -186,9 +469,15 @@
         delOne.setUpdateBy(user.getRealname());
         delOne.setValidFlag(Boolean.FALSE);
         this.updateById(delOne);
+        InspectionExpertGroup expertGroup = expertGroupService.getBySelfInspectionId(id);
+        if(expertGroup != null){
+            expertGroup.setValidFlag(false);
+            expertGroupService.updateById(expertGroup);
+        }
+
     }
 
-    @Override
+  /*  @Override
     public SafetySelfInspection infoOne(Long id,String unqualified, UserInfo user) {
         SafetySelfInspection safetySelfInspection=selectVerification(id);
         //组装检查项
@@ -225,12 +514,164 @@
             safetySelfInspection.setItemList(new ArrayList<>());
         }
         return safetySelfInspection;
+    }*/
+
+    @Override
+    public SafetySelfInspectionRespDTO infoOne(Long id, String unqualified, UserInfo user) {
+        SafetySelfInspection safetySelfInspection = selectVerification(id);
+        SafetySelfInspectionRespDTO safetySelfInspectionRespDTO = new SafetySelfInspectionRespDTO();
+        BeanUtils.copyProperties(safetySelfInspection,safetySelfInspectionRespDTO);
+        //获取所有检查项
+        List<SafetySelfInspectionItem> itemList= safetySelfInspectionItemMapper.getDetailBySafetySelfInspectionId(id,unqualified);
+        //获取关联要素
+        List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id);
+
+        List<SafetySelfInspectionElementRespDTO> arespDTOList = new ArrayList<>();
+        if (CollectionUtils.isNotEmpty(inspectionElementAList)) {
+            for (SafetyInspectionElementA elementA : inspectionElementAList) {
+                //获取该要素的树
+                List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA());
+                if (CollectionUtils.isNotEmpty(elementTree)) {
+                    //一级要素
+                    ElementTree otree = elementTree.get(0);
+                    SafetySelfInspectionElementRespDTO elementARespDTO = new SafetySelfInspectionElementRespDTO();
+                    elementARespDTO.setElementId(otree.getValue());
+                    elementARespDTO.setElementName(otree.getLabel());
+                    elementARespDTO.setType(otree.getType());
+
+                    List<SafetySelfInspectionElementRespDTO> brespDTOList = new ArrayList<>();
+                    //二级要素
+                    List<ElementTree> elementBList = otree.getChildren();
+                    if(CollectionUtils.isNotEmpty(elementBList)){
+                        for (ElementTree stree : elementBList) {
+                            SafetySelfInspectionElementRespDTO elementBRespDTO = new SafetySelfInspectionElementRespDTO();
+                            elementBRespDTO.setElementId(stree.getValue());
+                            elementBRespDTO.setElementName(stree.getLabel());
+                            elementBRespDTO.setType(stree.getType());
+                            elementBRespDTO.setPid(stree.getPid());
+
+                            List<SafetySelfInspectionElementRespDTO> cRespDTOList = new ArrayList<>();
+                            //三级要素
+                            List<ElementTree> elementCList = stree.getChildren();
+                            if(CollectionUtils.isEmpty(elementCList)){
+                                //扣分
+                                int delScore = 0;
+                                int totalScore = stree.getPoint();
+                                //无三级要素过滤出二级要素检查内容
+                                List<SafetySelfInspectionItem> sItemList = itemList
+                                        .stream()
+                                        .filter(item -> item.getElementC() == null && item.getElementB().equals(stree.getValue()))
+                                        .collect(Collectors.toList());
+                                //填充检查项
+                                elementBRespDTO.setItemList(assemblyDeduction(sItemList));
+
+                                //判断是否有否决项
+                                List<SafetySelfInspectionItem> rejectList = sItemList
+                                        .stream()
+                                        .filter(item -> item.getSafetyInspectionItemResult().equals(0))
+                                        .collect(Collectors.toList());
+                                if(rejectList.size() > 0){
+                                    delScore = stree.getPoint();
+                                }else {
+                                    //计算出不合格扣分
+                                    delScore += unqualifiedItemDelScore(sItemList);
+                                }
+                                //总分
+                                elementBRespDTO.setTotalScore(stree.getPoint());
+                                //得分
+                                elementBRespDTO.setScore(totalScore-delScore);
+
+
+                            }else {
+                                for(ElementTree ttree : elementCList){
+                                    SafetySelfInspectionElementRespDTO elementCRespDTO = new SafetySelfInspectionElementRespDTO();
+                                    elementCRespDTO.setElementId(ttree.getValue());
+                                    elementCRespDTO.setElementName(ttree.getLabel());
+                                    elementCRespDTO.setType(ttree.getType());
+                                    elementCRespDTO.setPid(ttree.getPid());
+
+                                    //扣分
+                                    int delScore = 0;
+                                    int totalScore = ttree.getPoint();
+
+                                    //过滤该三级要素检查项目
+                                    List<SafetySelfInspectionItem> tItemList = itemList
+                                            .stream()
+                                            .filter(item -> item.getElementC() != null && item.getElementC().equals(ttree.getValue()))
+                                            .collect(Collectors.toList());
+                                    //填充检查项
+                                    elementCRespDTO.setItemList(assemblyDeduction(tItemList));
+
+                                    //判断是否有被否决
+                                    List<SafetySelfInspectionItem> rejectList = tItemList
+                                            .stream()
+                                            .filter(item -> item.getSafetyInspectionItemResult().equals(0))
+                                            .collect(Collectors.toList());
+                                    if(rejectList.size() > 0){
+                                        delScore = ttree.getPoint();
+                                    }else {
+                                        //计算出不合格扣分
+                                        delScore = unqualifiedItemDelScore(tItemList);
+                                    }
+                                    //总分
+                                    elementCRespDTO.setTotalScore(ttree.getPoint());
+                                    //得分
+                                    elementCRespDTO.setScore(totalScore-delScore);
+                                    cRespDTOList.add(elementCRespDTO);
+                                }
+                            }
+                            elementBRespDTO.setChildren(cRespDTOList);
+                            brespDTOList.add(elementBRespDTO);
+                        }
+                    }
+                    elementARespDTO.setChildren(brespDTOList);
+                    arespDTOList.add(elementARespDTO);
+                }
+            }
+
+        }
+        safetySelfInspectionRespDTO.setElementList(arespDTOList);
+
+        return safetySelfInspectionRespDTO;
+    }
+
+
+    //组装扣分项
+    private List<SafetySelfInspectionItem> assemblyDeduction( List<SafetySelfInspectionItem> itemList){
+        for (SafetySelfInspectionItem safetySelfInspectionItem : itemList){
+            if (safetySelfInspectionItem.getSafetyInspectionItemResult().equals(2)){
+                //根据检查项id获取原始扣分项
+                List<SafetyInspectionItemDeduction> safetyInspectionItemDeductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetySelfInspectionItem.getSafetyInspectionItemId());
+                if (CollectionUtils.isNotEmpty(safetyInspectionItemDeductionList)){
+                    List<SafetySelfInspectionItemDeduction> oldSafetySelfInspectionItemDeductionList=new ArrayList<>();
+                    for (SafetyInspectionItemDeduction safetyInspectionItemDeduction : safetyInspectionItemDeductionList){
+                        SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction = new SafetySelfInspectionItemDeduction();
+                        safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetyInspectionItemDeduction.getId());
+                        safetySelfInspectionItemDeduction.setName(safetyInspectionItemDeduction.getName());
+                        safetySelfInspectionItemDeduction.setPoint(0);
+                        oldSafetySelfInspectionItemDeductionList.add(safetySelfInspectionItemDeduction);
+                    }
+                    safetySelfInspectionItem.setSelfDeductionList(oldSafetySelfInspectionItemDeductionList);
+                }else{
+                    safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>());
+                }
+            }else if (safetySelfInspectionItem.getSafetyInspectionItemResult().equals(1)){
+                //根据自查清单记录的检查项id获取其扣分项
+                List<SafetySelfInspectionItemDeduction> selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId());
+                if (CollectionUtils.isNotEmpty(selfDeductionList)){
+                    safetySelfInspectionItem.setSelfDeductionList(selfDeductionList);
+                }
+            }
+        }
+        return itemList;
     }
 
     @Override
     public SafetySelfInspectionItem itemInfoOne(Long id, UserInfo user){
         SafetySelfInspectionItem safetySelfInspectionItem = safetySelfInspectionItemMapper.getDetailById(id);
         List<SafetySelfInspectionItemDeduction> selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId());
+        List<InspectionHiddenDanger> inspectionHiddenDangerList = dangerService.getBySafetySelfInspectionItemId(id);
+
         if (CollectionUtils.isNotEmpty(selfDeductionList)){
             safetySelfInspectionItem.setSelfDeductionList(selfDeductionList);
         }else{
@@ -250,11 +691,13 @@
                 safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>());
             }
         }
+        safetySelfInspectionItem.setDangerList(inspectionHiddenDangerList);
         return safetySelfInspectionItem;
     }
 
     @Override
     public void modItemInfo(SafetySelfInspectionItem param, UserInfo user) {
+
         if (param.getSafetyInspectionItemResult()==0 && StringUtils.isBlank(param.getSafetyInspectionItemResultDesc())){
             throw new BusinessException("否决说明必填!");
         }
@@ -266,6 +709,8 @@
         if (param.getSafetyInspectionItemResult()==0 || param.getSafetyInspectionItemResult() == 2){
             //否决 合格--删除扣分记录
             safetySelfInspectionItemDeductionMapper.delBySafetySelfInspectionItemId(param.getId(),username,date);
+            //删除隐患
+            dangerService.delByInspectionItemId(param.getSafetyInspectionItemId(),user);
         }else{
             //扣分
             List<SafetySelfInspectionItemDeduction> list = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(param.getId());
@@ -289,8 +734,41 @@
                     safetySelfInspectionItemDeductionMapper.updateById(safetySelfInspectionItemDeduction);
                 }
             }
+            //隐患
+            if(CollectionUtils.isNotEmpty(param.getDangerList())){
+                List<InspectionHiddenDanger> oldDangerList = dangerService.getBySafetySelfInspectionItemId(param.getId());
+                //过滤出要删除数据
+                List<InspectionHiddenDanger> deleteOldDangerList = oldDangerList.stream().parallel().filter(a ->
+                                param.getDangerList().stream().noneMatch(b ->
+                                        a.getId().equals(b.getId())))
+                        .collect(Collectors.toList());
+                //删除
+                if (CollectionUtils.isNotEmpty(deleteOldDangerList)) {
+                    List<Long> idList = deleteOldDangerList.stream().map(InspectionHiddenDanger::getId).collect(Collectors.toList());
+                    dangerService.delByIds(idList);
+                }
+                for (InspectionHiddenDanger inspectionHiddenDanger : param.getDangerList()) {
+                    if(inspectionHiddenDanger.getId() == null){
+                        inspectionHiddenDanger.setCreateBy(user.getRealname());
+                        inspectionHiddenDanger.setCreateTime(new Date());
+                        inspectionHiddenDanger.setUpdateBy(user.getRealname());
+                        inspectionHiddenDanger.setUpdateTime(new Date());
+                        inspectionHiddenDanger.setStatus((byte)0);
+                        inspectionHiddenDanger.setValidFlag(true);
+                        inspectionHiddenDanger.setSelfInspectionId(param.getSafetySelfInspectionId());
+                        inspectionHiddenDanger.setSelfInspectionItemId(param.getId());
+                        dangerService.save(inspectionHiddenDanger);
+                    }else {
+                        inspectionHiddenDanger.setUpdateBy(user.getRealname());
+                        inspectionHiddenDanger.setUpdateTime(new Date());
+                        dangerService.updateById(inspectionHiddenDanger);
+                    }
+                }
+            }
+
         }
     }
+
 
     @Override
     public void finish(Long id, UserInfo user) {
@@ -303,6 +781,14 @@
         safetySelfInspectionMapper.updateById(safetySelfInspection);
     }
 
+    @Override
+    public void addItemExpert(List<SafetySelfInspectionItem> itemList, UserInfo user) {
+        itemList.forEach(item -> {
+            item.setUpdateBy(user.getRealname());
+            item.setUpdateTime(new Date());
+        });
+        safetySelfInspectionItemMapper.updateBatch(itemList);
+    }
 
     /**
      * 查询验证
@@ -329,5 +815,43 @@
         if (param.getCheckedCompanyId() == null){
             throw new BusinessException("请选择被检查公司");
         }
+        if(CollectionUtils.isEmpty(param.getElementAList())){
+            throw new BusinessException("请选择A检查要素");
+        }
+        for(SafetyInspectionElementA elementA : param.getElementAList()){
+            if(elementA.getElementA() == null){
+                throw new BusinessException("请选择A检查要素");
+            }
+        }
+    }
+    public void requiredSuperviseVerification(SafetySelfInspection param) {
+        if (StringUtils.isBlank(param.getInspectionName())) throw new BusinessException("请填写排查清单名称");
+        if (param.getInspectionTime() == null) throw new BusinessException("请选择排查时间");
+        if (CollectionUtils.isEmpty(param.getExpertList())) throw new BusinessException("请选择检查专家");
+        for(InspectionExpert inspectionExpert : param.getExpertList()){
+            if(inspectionExpert.getExpertId() == null){
+                throw new BusinessException("请选择检查专家");
+            }
+            if(StringUtils.isBlank(inspectionExpert.getName())){
+                throw new BusinessException("请选择检查专家名字");
+            }
+            if(inspectionExpert.getIsLeader() == null){
+                throw new BusinessException("请选择组长或者组员");
+            }
+        }
+        if (CollectionUtils.isEmpty(param.getItemList())) {
+            throw new BusinessException("请选择检查项");
+        }
+        if (param.getCheckedCompanyId() == null){
+            throw new BusinessException("请选择被检查公司");
+        }
+        if(CollectionUtils.isEmpty(param.getElementAList())){
+            throw new BusinessException("请选择A检查要素");
+        }
+        for(SafetyInspectionElementA elementA : param.getElementAList()){
+            if(elementA.getElementA() == null){
+                throw new BusinessException("请选择A检查要素");
+            }
+        }
     }
 }

--
Gitblit v1.9.2