<?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.ssSafeProductInspectionResult.mapper.SsSafeProductInspectionResultMapper">


    <select id="selectMyPage"
            resultType="com.unis.statisticalReport.info.modular.ssSafeProductInspectionResult.vo.SsSafeProductInspectionResultVO">

        SELECT ta.org_id,
        ta.org_name,
        ta.id ssSafeProductInspectionId,
        t3.storehouse_name,
        t4.warehouse_name,
        t2.inspector,
        t2.inspection_date
        FROM (SELECT t1.*, t5.org_name
        FROM biz_ss_safe_product_inspection t1
        LEFT JOIN depot_qh.org_info t5 ON t1.org_id = t5.org_id) ta
        LEFT JOIN biz_ss_safe_product_inspection_result t2 ON ta.id = t2.ss_safe_product_inspection_id
        LEFT JOIN depot_qh.basic_storehouse t3 ON t2.basic_storehouse_id = t3.storehouse_id
        LEFT JOIN depot_qh.basic_warehouse t4 ON t2.warehouse_id = t4.warehouse_id

        <where>
            ta.`status`='1'

            <if test="warehouseName!=null and warehouseName!=''">
                and t4.warehouse_name like concat("%",#{warehouseName},"%")
            </if>
            <if test="storehouseName!=null and storehouseName!=''">
                and t3.storehouse_name like concat("%",#{storehouseName},"%")
            </if>
        </where>

        order by ta.create_time desc


    </select>


</mapper>