lyh
昨天 724f8ec3bbcf9da50f304f57d8bc9a60ad75ad0a
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -38,6 +38,9 @@
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;
@@ -460,6 +463,22 @@
        }
        List<String> ids=this.baseMapper.queryList(queryWrapper).stream().map(EamEquipment::getId).collect(Collectors.toList());
        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;
    }