shenyijian
2024-06-17 e1cdb7930d2eb4baccff2809a420a1f0f544c934
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sg/service/impl/SgProjectInfoServiceImpl.java
@@ -1,14 +1,23 @@
package cn.gistack.sm.sg.service.impl;
import cn.gistack.sm.sg.DO.SgDeviceDO;
import cn.gistack.sm.sg.DO.SgGxDO;
import cn.gistack.sm.sg.DO.SgGxStepDO;
import cn.gistack.sm.sg.DO.SgProjectInfoDO;
import cn.gistack.sm.sg.DTO.ProjectSearchDTO;
import cn.gistack.sm.sg.VO.SgProjectInfoVO;
import cn.gistack.sm.sg.mapper.SgProjectInfoMapper;
import cn.gistack.sm.sg.service.SgProjectInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * <p>
@@ -20,10 +29,55 @@
 */
@Service
public class SgProjectInfoServiceImpl extends ServiceImpl<SgProjectInfoMapper, SgProjectInfoDO> implements SgProjectInfoService {
   @Autowired
   private SgProjectInfoMapper sgProjectInfoMapper;
   @Override
   public IPage<SgProjectInfoDO> queryPageList(IPage<SgProjectInfoDO> page, ProjectSearchDTO searchDTO) {
      List<SgProjectInfoDO> sgProjectInfoDOS = baseMapper.queryPageList(page,searchDTO);
      return page.setRecords(sgProjectInfoDOS);
   }
   @Override
   public List<SgProjectInfoDO> queryStepByProject(ProjectSearchDTO searchDTO) {
      List<SgProjectInfoVO> list = sgProjectInfoMapper.queryStepByProject( searchDTO);
      //项目分组
      Map<Long, List<SgProjectInfoVO>> projectMap = list.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getId));
      List<SgProjectInfoDO> result = new ArrayList<>();
      for (Map.Entry<Long, List<SgProjectInfoVO>> entry : projectMap.entrySet()) {
         Long porId = entry.getKey();
         List<SgProjectInfoVO> value = entry.getValue();
         if (CollectionUtils.isEmpty(value)){
            continue;
         }
         SgProjectInfoDO sgProjectInfoDO = SgProjectInfoDO.builder().id(porId).projectName(value.get(0).getProjectName()).build();
         List<SgGxDO> sgGxDOS = new ArrayList<>();
         //工序分组
         Map<Long, List<SgProjectInfoVO>> GxMap = value.stream().filter(s->s.getGxId()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getGxId));
         for (Map.Entry<Long, List<SgProjectInfoVO>> gx : GxMap.entrySet()) {
            Long gxId = gx.getKey();
            List<SgProjectInfoVO> gxList = gx.getValue();
            if (CollectionUtils.isEmpty(gxList)){
               continue;
            }
            SgGxDO gxDO = SgGxDO.builder().id(gxId).gxName(gxList.get(0).getGxName()).build();
            List<SgDeviceDO> deviceDOS = new ArrayList<>();
            //设备分组
            Map<Long, List<SgProjectInfoVO>> dMap = gxList.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getDId));
            for (Map.Entry<Long, List<SgProjectInfoVO>> device : dMap.entrySet()) {
               Long dId = device.getKey();
               List<SgProjectInfoVO> deList = device.getValue();
               SgDeviceDO sgDeviceDO = new SgDeviceDO();
               sgDeviceDO.setId(dId);
               sgDeviceDO.setDeviceName(deList.get(0).getDeviceName());
               sgDeviceDO.setStepDOList(deList.stream().map(s->SgGxStepDO.builder().gxStepName(s.getGxStepName()).approvalStatus(s.getSTATUS()).build()).collect(Collectors.toList()));
               deviceDOS.add(sgDeviceDO);
            }
            gxDO.setDeviceDOS(deviceDOS);
            sgGxDOS.add(gxDO);
         }
         sgProjectInfoDO.setSgGxDOS(sgGxDOS);
         result.add(sgProjectInfoDO);
      }
      return result;
   }
}