<?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.safeStorage.modular.ssSafeGrainStorageInspectionResult.mapper.SsSafeGrainStorageInspectionResultMapper">

    <select id="selectMyPage"
            resultType="com.unis.safeStorage.modular.ssSafeGrainStorageInspection.entity.SsSafeGrainStorageInspection">


        SELECT t1.*,t1.id ssSafeGrainStorageInspectionId
        FROM biz_ss_safe_grain_storage_inspection t1
        LEFT JOIN biz_ss_safe_grain_storage_inspection_result t2
        ON t1.id = t2.ss_safe_grain_storage_inspection_id
        LEFT JOIN depot_qh.basic_enum a3 ON (
        t2.grain_grade_id = a3.enumId
        OR t2.grain_variety_id = a3.enumId
        )
        <where>
            <if test="storehouseName != null and storehouseName != ''">
                and t2.basic_storehouse_id in (select storehouse_id from depot_qh.basic_storehouse where storehouse_name
                like CONCAT('%',
                #{storehouseName}, '%') )
            </if>
            <if test="warehouseName != null and warehouseName != ''">
                and t2.warehouse_id in (select warehouse_id from depot_qh.basic_warehouse where warehouse_name like
                CONCAT('%',
                #{warehouseName}, '%') )
            </if>
            and t1.`status` = '1'
        </where>

        GROUP BY t1.id
        order by t1.create_time desc
        limit ${(current-1)*size},${size};

    </select>


    <select id="selectMyResultPage"
            resultType="com.unis.safeStorage.modular.ssSafeGrainStorageInspectionResult.vo.SsSafeGrainStorageInspectionResultVO">

        select t1.*,t3.org_name,t4.storehouse_name
        from biz_ss_safe_grain_storage_inspection_result t1
        left join biz_ss_safe_grain_storage_inspection t2 on t1.ss_safe_grain_storage_inspection_id = t2.id
        left join depot_qh.org_info t3 on t2.org_id = t3.org_id
        left join depot_qh.basic_storehouse t4 on t1.basic_storehouse_id = t4.storehouse_id
        <where>
            t2.`status` = '1'
            <if test="storehouseName!=null and storehouseName!=''">
                and t4.storehouse_name like concat("%",#{storehouseName},"%")
            </if>
            <if test="orgName!=null and orgName!=''">
                and t3.org_name like concat("%",#{orgName},"%")
            </if>
            <if test="inspectionDate!=null and inspectionDate!=''">
                and t1.inspection_date like concat("%",#{inspectionDate},"%")
            </if>
        </where>

        order by t1.create_time desc
    </select>
</mapper>