| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<EchartsDto> echartsList(){ |
| | | List<EchartsDto> echartsDtoList = new ArrayList<>(); |
| | | QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return null; |
| | | return echartsDtoList; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | |
| | | Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("e.factory_org_code", factoryCode); |
| | | }else { |
| | | return null; |
| | | return echartsDtoList; |
| | | } |
| | | } |
| | | List<String> ids=this.baseMapper.queryList(queryWrapper).stream().map(EamEquipment::getId).collect(Collectors.toList()); |
| | | return this.baseMapper.echartsList(ids); |
| | | echartsDtoList= this.baseMapper.echartsList(ids); |
| | | // 直接使用for循环处理数据 |
| | | for (EchartsDto dto : echartsDtoList) { |
| | | if (dto.getTotal() != null && !"0".equals(dto.getTotal())) { |
| | | try { |
| | | int value = Integer.parseInt(dto.getValue()); |
| | | int total = Integer.parseInt(dto.getTotal()); |
| | | double percentage = (value * 100.0) / total; |
| | | DecimalFormat df = new DecimalFormat("0.00"); |
| | | dto.setPercentage(df.format(percentage) + "%"); |
| | | } catch (NumberFormatException e) { |
| | | dto.setPercentage("0.00%"); |
| | | } |
| | | } else { |
| | | dto.setPercentage("0.00%"); |
| | | } |
| | | } |
| | | return echartsDtoList; |
| | | } |
| | | |
| | | /** |