lyh
14 小时以前 724f8ec3bbcf9da50f304f57d8bc9a60ad75ad0a
修改计算百分比位置
已修改2个文件
94 ■■■■ 文件已修改
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/mapper/xml/EamEquipmentMapper.xml
@@ -78,51 +78,34 @@
        ${ew.customSqlSegment}
    </select>
    <select id="echartsList" resultType="org.jeecg.modules.eam.dto.EchartsDto">
        SELECT COUNT
               ( t.technology_status ) AS "value",
               item.item_text AS "name",
               item.item_value AS "code",
               ( SELECT COUNT ( a.id ) FROM eam_equipment_extend a WHERE a.technology_status IS NOT NULL
                                                <if test="ids != null and ids != ''">
                                                    AND a.id IN
                                                    <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                                                        #{id}
                                                    </foreach>
                                                </if>
                                                                   ) AS "total",
               concat (
                       round(
                               ISNULL (
                                       COUNT ( t.id ) / ( SELECT COUNT ( a.id ) FROM eam_equipment_extend a WHERE a.technology_status IS NOT NULL
                                                    <if test="ids != null and ids != ''">
                                                        AND a.id IN
                                                        <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                                                            #{id}
                                                        </foreach>
                                                    </if>),
                                       0
                               ) * 100,
                               2
                       ),
                       '%'
               ) AS "percentage"
        FROM
            sys_dict c
                LEFT JOIN sys_dict_item item ON c.id = item.dict_id
                LEFT JOIN eam_equipment_extend t ON t.technology_status = item.item_value
                <if test="ids != null and ids != ''">
                    AND t.id IN
                    <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                        #{id}
                    </foreach>
                </if>
        WHERE
            c.dict_code = 'equipment_technology_status'
        GROUP BY
            item.item_text,
            t.technology_status,
            item.item_value
        ORDER BY
            item.item_value
        WITH TotalCount AS (
        SELECT COUNT(a.id) AS total_count
        FROM eam_equipment_extend a
        WHERE a.technology_status IS NOT NULL
        <if test="ids != null and ids != ''">
            AND a.id IN
            <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        )
        SELECT
        COUNT(t.technology_status) AS "value",
        item.item_text AS "name",
        item.item_value AS "code",
        tc.total_count AS "total"
        FROM sys_dict c
        LEFT JOIN sys_dict_item item ON c.id = item.dict_id
        LEFT JOIN eam_equipment_extend t ON t.technology_status = item.item_value
        <if test="ids != null and ids != ''">
            AND t.id IN
            <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        CROSS JOIN TotalCount tc
        WHERE c.dict_code = 'equipment_technology_status'
        GROUP BY item.item_text, item.item_value, tc.total_count
        ORDER BY item.item_value
    </select>
</mapper>
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;
    }