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>
|
* 施工项目表 服务实现类
|
* </p>
|
*
|
* @author shenyijian
|
* @since 2024-06-13 11:51:20
|
*/
|
@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;
|
}
|
}
|