<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.zrzyqc.qcsb.mapper.SsDkjzMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="resultMap" type="org.jeecg.modules.zrzyqc.qcsb.entity.SsDkjz">
<!--        <id column="id" property="id"/>-->
        <result column="dkbh" property="dkbh"/>
        <result column="dlbm" property="dlbm"/>
        <result column="dlmc" property="dlmc"/>
        <result column="xjxzqhdm" property="xjxzqhdm"/>
        <result column="xjxzqhmc" property="xjxzqhmc"/>
        <result column="pjjg" property="pjjg"/>
        <result column="zgjg" property="zgjg"/>
        <result column="zdjg" property="zdjg"/>
        <result column="mj" property="mj"/>
        <result column="zjg" property="zjg"/>
    </resultMap>
    <select id="queryList" resultType="org.jeecg.modules.zrzyqc.qcsb.entity.SsDkjz">
        SELECT
            dkbh,
            dlbm,
            dlmc,
            xjxzqhmc,
            ROUND(COALESCE(pjjg, 0)::numeric, 4) AS pjjg,
            ROUND(COALESCE(zgjg, 0)::numeric, 4) AS zgjg,
            ROUND(COALESCE(zdjg, 0)::numeric, 4) AS zdjg,
            ROUND(COALESCE(SUM(mj), 0)::numeric, 4) AS mj,
            ROUND((COALESCE(SUM(mj), 0) * COALESCE(pjjg, 0))::numeric, 4) AS zjg,
            zdjg || '~' || zgjg AS jgqj,
            CASE
                WHEN zgjg IS NULL OR zgjg = 0 THEN
                    ROUND((COALESCE(SUM(mj), 0) * COALESCE(pjjg, 0))::numeric, 4)::text
                ELSE
                        ROUND((COALESCE(SUM(mj), 0) * COALESCE(zdjg, 0))::numeric, 4) || '~' || ROUND((COALESCE(SUM(mj), 0) * COALESCE(zgjg, 0))::numeric, 4)
                END AS jzfw,
            ROUND(COALESCE(SUM(pjjg * mj), 0)::numeric, 4)  AS hz
        FROM
            ss_dkjz
        WHERE
            dkbh = #{dkbh}
        GROUP BY
            dkbh, dlbm, dlmc, xjxzqhdm, xjxzqhmc, pjjg, zgjg, zdjg
    </select>
</mapper>
