java多维透视图

    boolean allColumn = pivotList.stream().allMatch(e -> "column".equals(e.getColumnType()));
        List<TableFieldInfo> fieldList = TableInfoHelper.getTableInfo(this.getEntityClass()).getFieldList();
        Map<String, String> fieldMap = fieldList.stream().collect(Collectors.toMap(TableFieldInfo::getProperty, TableFieldInfo::getColumn, (v1 ,v2) -> v2));
        Set<String> columnSet = pivotList.stream().map(e -> "case when "+fieldMap.get(e.getColumnCode())+" is null then '' else "+fieldMap.get(e.getColumnCode())+" end "+ e.getColumnCode()).collect(Collectors.toSet());
        columnSet.add("count(*) count");
        columnSet.add("sum(teu) teu");
        columnSet.add("sum(total_weight) totalWeight");
        columnSet.add("sum(net_weight) netWeight");
        String columns = String.join(",", columnSet);
        Set<String> groupSet = pivotList.stream().map(e -> fieldMap.get(e.getColumnCode())).collect(Collectors.toSet());
        String groups = String.join(",", groupSet);
        List<Map<String, Object>> list = this.getBaseMapper().deviceCntrStatistics(wrapper, deviceContainerDTO, columns, groups);
        if(CollectionUtils.isNotEmpty(list) && allColumn){
            Map<String, Object> map = Maps.newHashMap();
            map.put("count", list.stream().filter(e -> Objects.nonNull(e.get("count"))).map(e -> Long.parseLong(e.get("count").toString())).reduce(0L, Long::sum));
            map.put("teu", list.stream().filter(e -> Objects.nonNull(e.get("teu"))).map(e -> Double.parseDouble(e.get("teu").toString())).reduce(0.0, Double::sum));
            map.put("totalWeight", list.stream().filter(e -> Objects.nonNull(e.get("totalWeight"))).map(e -> new BigDecimal(e.get("totalWeight").toString())).reduce(new BigDecimal("0"), BigDecimal::add));
            map.put("netWeight", list.stream().filter(e -> Objects.nonNull(e.get("netWeight"))).map(e -> new BigDecimal(e.get("netWeight").toString())).reduce(new BigDecimal("0"), BigDecimal::add));
            list.add(map);
        }
    <select id="deviceCntrStatistics" resultType="java.util.HashMap">
        SELECT
        ${columns}
        FROM
        cntr_container a
        <where>
            <if test="dc.damageRecordList != null and dc.damageRecordList != ''">
                <if test="dc.damageRecordList == 1">
                    AND EXISTS
                </if>
                <if test="dc.damageRecordList == 0">
                    AND NOT EXISTS
                </if>
                (SELECT 1 FROM doc_cntr_damage_record  damage WHERE damage.cntr_id = a.id)
            </if>
            <if test="dc.dangerCntrList != null and dc.dangerCntrList != ''">
                <if test="dc.dangerCntrList == 1">
                    AND EXISTS
                </if>
                <if test="dc.dangerCntrList == 0">
                    AND NOT EXISTS
                </if>
                (SELECT 1 FROM doc_danger_cntr  danger WHERE danger.cntr_id = a.id)
            </if>
            <if test="dc.billNo != null and dc.billNo != ''">
                AND c.bill_no = #{dc.billNo}
            </if>
            <if test="ew!=null and ew.isEmptyOfWhere == false">
                AND ${ew.sqlSegment}
            </if>
        </where>
        group by ${groups}
    </select>
  List<Map<String, Object>> deviceCntrStatistics(@Param("ew") QueryWrapper<DeviceContainer> wrapper, @Param("dc") DeviceContainerDTO deviceContainerDTO,
                                                   @Param("columns") String columns, @Param("groups") String groups);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值