| | |
| | | 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.VO.SgTypeVO; |
| | | 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.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @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(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; |
| | | } |
| | | SgProjectInfoVO sgProjectInfoVO = value.get(0); |
| | | SgProjectInfoDO sgProjectInfoDO = SgProjectInfoDO.builder().id(porId).status(sgProjectInfoVO.getProjectStatus()).projectName(sgProjectInfoVO.getProjectName()).build(); |
| | | List<SgTypeVO> sgGxDOS = new ArrayList<>(); |
| | | //类型分组 |
| | | Map<String, List<SgProjectInfoVO>> GxMap = value.stream().filter(s->s.getDeviceType()!=null).collect(Collectors.groupingBy(SgProjectInfoVO::getDeviceType)); |
| | | for (Map.Entry<String, List<SgProjectInfoVO>> ty : GxMap.entrySet()) { |
| | | String type = ty.getKey(); |
| | | List<SgProjectInfoVO> gxList = ty.getValue(); |
| | | if (CollectionUtils.isEmpty(gxList)){ |
| | | continue; |
| | | } |
| | | SgTypeVO typeVO = SgTypeVO.builder().typeName(gxList.get(0).getTypeName()).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.setStatus( deList.get(0).getDeviceStatus()); |
| | | sgDeviceDO.setStepDOList(deList.stream().map(s->SgGxStepDO.builder().id(s.getReportId()).gxStepNum(s.getGxStepNum()).gxStepName(s.getGxStepName()).deviceId(s.getDId()).approvalStatus(s.getReportStatus()).build()).collect(Collectors.toList())); |
| | | deviceDOS.add(sgDeviceDO); |
| | | } |
| | | typeVO.setDeviceDOS(deviceDOS); |
| | | sgGxDOS.add(typeVO); |
| | | } |
| | | sgProjectInfoDO.setSgGxDOS(sgGxDOS); |
| | | result.add(sgProjectInfoDO); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<SgProjectInfoVO> progressList(ProjectSearchDTO searchDTO) { |
| | | List<SgProjectInfoVO> list = sgProjectInfoMapper.progressList(searchDTO); |
| | | Map<Long, List<SgProjectInfoVO>> map = list.stream().collect(Collectors.groupingBy(SgProjectInfoVO::getId)); |
| | | List<SgProjectInfoVO> result = new ArrayList<>(); |
| | | for (Map.Entry<Long, List<SgProjectInfoVO>> entry : map.entrySet()) { |
| | | SgProjectInfoVO sgProjectInfoVO = new SgProjectInfoVO(); |
| | | List<SgProjectInfoVO> deviceList = entry.getValue(); |
| | | if (CollectionUtils.isEmpty(deviceList)){ |
| | | continue; |
| | | } |
| | | sgProjectInfoVO.setId(entry.getKey()); |
| | | sgProjectInfoVO.setProjectName(deviceList.get(0).getProjectName()); |
| | | List<SgProjectInfoVO> overList = deviceList.stream().filter(s->s.getDeviceStatus()!=null).filter(s -> s.getDeviceStatus() == 2).collect(Collectors.toList()); |
| | | BigDecimal v1 =BigDecimal.ZERO; |
| | | if (CollectionUtils.isNotEmpty(overList)){ |
| | | v1 = BigDecimal.valueOf(overList.size()); |
| | | } |
| | | BigDecimal v2 = BigDecimal.valueOf(deviceList.size()); |
| | | BigDecimal percentage = v1.divide(v2,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")); |
| | | // 如果不需要保留小数位,可以设置一个scale为0 |
| | | BigDecimal percentageRounded = percentage.setScale(0, RoundingMode.HALF_UP); |
| | | sgProjectInfoVO.setProgressName(percentageRounded+"%"); |
| | | result.add(sgProjectInfoVO); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Long> projectCount(ProjectSearchDTO searchDTO) { |
| | | Map<String, Long> map = new HashMap<>(); |
| | | LambdaQueryChainWrapper<SgProjectInfoDO> wrapper = new LambdaQueryChainWrapper<>(sgProjectInfoMapper); |
| | | String projectName = searchDTO.getProjectName(); |
| | | Integer status = searchDTO.getStatus(); |
| | | if (StringUtils.isNotBlank(projectName)){ |
| | | wrapper.like(SgProjectInfoDO::getProjectName,searchDTO.getProjectName()); |
| | | } |
| | | if (status!=null){ |
| | | wrapper.eq(SgProjectInfoDO::getStatus,searchDTO.getStatus()); |
| | | } |
| | | List<SgProjectInfoDO> list = wrapper.list(); |
| | | List<SgProjectInfoDO> pending = list.stream().filter(s -> s.getStatus() == 0).collect(Collectors.toList()); |
| | | List<SgProjectInfoDO> progress = list.stream().filter(s -> s.getStatus() == 1).collect(Collectors.toList()); |
| | | List<SgProjectInfoDO> over = list.stream().filter(s -> s.getStatus() == 2).collect(Collectors.toList()); |
| | | map.put("all", (long) list.size()); |
| | | map.put("pending", (long) pending.size()); |
| | | map.put("progress", (long) progress.size()); |
| | | map.put("over", (long) over.size()); |
| | | return map; |
| | | } |
| | | } |