<?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="com.unis.financialSupervision.modular.fsgrainoilstoragesummary.mapper.BizFsGrainOilStorageSummaryMapper">

    <select id="getPjcbgmSl" resultType="java.util.Map" parameterType="java.util.Map">
        SELECT
            a.org_info_id orgId,
            a.scale_year scaleYear,
            AVG(a.reserve_plan_quantity) pjcbgmsl
        FROM
            biz_gr_reserve_scale a -- 粮食储备-储备规模
        WHERE
            a.delete_flag = 'NOT_DELETE'
        AND a. STATUS = 2 -- 下发的储备规模
        AND a.grain_nature_id = 6877 -- 省(自治区、直辖市)级地方储备粮
        AND a.scale_year = #{year}
        AND a.org_info_id = #{orgId}

    </select>

    <select id="getPjymkcsl" resultType="java.util.Map" parameterType="java.util.Map">
        SELECT
            UnitID,
            avg(qmkc) pjymkc
        FROM
            depot_qh.data_kcgl_kcyjd_default
        WHERE
            UnitID = #{orgId}
          AND nf = #{year}

    </select>

    <select id="getZclkqslPj" resultType="java.util.Map" parameterType="java.util.Map">
        SELECT  IFNULL(avg(m1.zcsl), 0.0) as zclkqnlkslpj
             FROM province_all.biz_rp_issuance a
                 INNER JOIN depot_qh.business_rp_report c ON c.id = a.rp_report_id
                 INNER JOIN depot_qh.business_rp_inbound e ON c.id = e.rp_report_id
                 INNER JOIN depot_qh.business_rp_outbound f ON c.id = f.rp_report_id
                 INNER JOIN depot_qh.org_info g on g.org_id = e.org_id
                 INNER JOIN depot_qh.data_crkyw_ckrmdj_default m3 on m3.jhdID = a.rp_report_id
                 INNER JOIN depot_qh.data_crkyw_ckcmz_default m2 on m3.bizno = m2.bizno
                 INNER JOIN depot_qh.data_kcgl_fcbgz_default m1 on m1.DataID = m2.DataID
        where g.org_id = #{orgId}
          and CAST(c.plan_year as char) = #{year}
          And m1.rq &gt;= #{rotationStart}
          And m1.rq &lt;= #{rotationEnd}
    </select>

    <select id="getClkqslpj" resultType="java.util.Map" parameterType="java.util.Map">
        SELECT  IFNULL(avg(m1.zcsl), 0.0) as clkqslpj
        FROM province_all.biz_rp_issuance a
                 INNER JOIN depot_qh.business_rp_report c ON c.id = a.rp_report_id
                 INNER JOIN depot_qh.business_rp_inbound e ON c.id = e.rp_report_id
                 INNER JOIN depot_qh.business_rp_outbound f ON c.id = f.rp_report_id
                 INNER JOIN depot_qh.org_info g on g.org_id = e.org_id
                 INNER JOIN depot_qh.data_crkyw_ckrmdj_default m3 on m3.jhdID = a.rp_report_id
                 INNER JOIN depot_qh.data_crkyw_ckcmz_default m2 on m3.bizno = m2.bizno
                 INNER JOIN depot_qh.data_kcgl_fcbgz_default m1 on m1.DataID = m2.DataID
        where g.org_id = #{orgId}
          and CAST(c.plan_year as char) = #{year}
          And m1.rq &lt; #{rotationStart}
          And m1.rq &gt; #{rotationEnd}
    </select>

    <select id="getKcl" resultType="java.lang.String" parameterType="java.util.Map">
        select kcsl/cbgmsl*100 as kcl from(
           (SELECT
                SUM(kcsl) kcsl
            FROM
                depot_qh.data_kcgl_kcsw_default
            where UnitID = #{orgId}
           ) as kcsl,
          (
           SELECT
           sum(reserve_plan_quantity) * 1000 cbgmsl
              FROM
              biz_gr_reserve_scale
              WHERE
              delete_flag = 'NOT_DELETE'
              AND org_info_id = #{orgId}
              AND scale_year = #{year}
          ) as cbgmsl
       )
    </select>
</mapper>