| | |
| | | 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.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; |
| | |
| | | } |
| | | 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).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<>(); |
| | | List<SgProjectInfoDO> list = new LambdaQueryChainWrapper<>(sgProjectInfoMapper).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; |
| | | } |
| | | } |