<?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.statisticalReport.info.modular.grainReserveInspection.mapper.GrainReserveInspectionMapper">
    <select id="getOrgInfoOnly" resultType="map">
        SELECT
            org_id orgId,
            org_code orgCode,
            org_name orgName
        FROM
            depot_qh.org_info
    </select>
    <select id="getStorehouse" parameterType="integer" resultType="map">
        SELECT
            storehouse_id storehouseId,
            storehouse_name storehouseName
        FROM
            depot_qh.basic_storehouse
        WHERE
            org_id = #{orgId}
    </select>
    <select id="getWarehouse" parameterType="map" resultType="map">
        SELECT
            warehouse_id warehouseId,
            warehouse_name warehouseName
        FROM
            depot_qh.basic_warehouse
        WHERE
            org_id = #{orgId}
        AND storehouse_id = #{storeHouseId}
    </select>
    <select id="getCd" parameterType="map" resultType="string">
        SELECT
	        be.enumname produceArea
        FROM
            depot_qh.data_kcgl_kcsw_default kkd
        LEFT JOIN depot_qh.basic_enum be ON kkd.gb = be.enumId
        WHERE
            kkd.UnitID = #{orgId}
        AND kkd.ch = #{storeHouseId}
        AND kkd.hwh = #{warehouseId}
    </select>
    <select id="page" parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper" resultType="com.unis.statisticalReport.info.modular.grainReserveInspection.entity.GrainReserveInspection">
        SELECT
            gri.*,
            oi.org_name orgName,
            bs.storehouse_name storehouseName,
            bw.warehouse_name warehouseName,
            be.enumname grainVarietyName
        FROM
            biz_ipad_grain_reserve_inspection gri
        LEFT JOIN depot_qh.org_info oi ON oi.org_id = gri.org_id
        LEFT JOIN depot_qh.basic_storehouse bs ON gri.basic_storehouse_id = bs.storehouse_id
        LEFT JOIN depot_qh.basic_warehouse bw ON gri.warehouse_id = bw.warehouse_id
        LEFT JOIN depot_qh.basic_enum be ON gri.grain_variety_id = be.enumId
        ${ew.customSqlSegment}
    </select>

</mapper>