<?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.fsunrotatedgrainstorage.mapper.BizFsUnrotatedGrainStorageMapper">

    <select id="getOrgInfo" resultType="com.unis.basic.info.modular.orgInfo.entity.OrgInfo" parameterType="java.lang.Integer">
        select * from depot_qh.org_info where parent_id != 0 and org_id not in (
            select c.org_id orgId from province_all.biz_rp_issuance a -- 轮换计划下发表
            INNER JOIN depot_qh.business_rp_report b on a.rp_report_id = b.id
            INNER JOIN depot_qh.business_rp_inbound c on c.rp_report_id = b.id
            where a.plan_year = #{orgId}
            GROUP BY orgId
            UNION
            select d.org_id orgId from province_all.biz_rp_issuance a --  轮换计划下发表
            INNER JOIN depot_qh.business_rp_report b on a.rp_report_id = b.id
            INNER JOIN depot_qh.business_rp_outbound d on d.rp_report_id = b.id
            where a.plan_year = #{orgId}
            GROUP BY orgId
        )
    </select>

    <select id="getCbgmData" parameterType="java.lang.Integer" resultType="java.util.Map">
        SELECT
          a.org_info_id orgId,
            a.scale_year scaleYear,
            a.scale_month scaleMonth,
            a.grain_variety_id pz,
            b.enumname pzmc,
            a.grain_nature_id xz,
            c.enumname xzmc,
          AVG(a.reserve_plan_quantity) cbgmsl
        FROM
            biz_gr_reserve_scale a
        LEFT JOIN depot_qh.basic_enum b ON a.grain_variety_id = b.enumId
        LEFT JOIN depot_qh.basic_enum c ON a.grain_nature_id = c.enumId
        WHERE a.delete_flag = 'NOT_DELETE' AND a. STATUS = 2 -- 下发的储备规模
        AND a.grain_nature_id = 6877 -- 省(自治区、直辖市)级地方储备粮
        AND a.scale_year =  YEAR(CURDATE())
        AND a.org_info_id = #{orgId}
        GROUP BY a.grain_variety_id
    </select>
</mapper>