<?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.grainReserves.modular.businessGslrLossCollect.mapper.BusinessGslrLossCollectMapper">

    <select id="alarmPage"
            resultType="com.unis.grainReserves.modular.businessGslrLossCollect.vo.BusinessGslrLossCollectVO">

        SELECT t1.*,
        t2.org_name,
        t3.storehouse_name
        FROM depot_qh.business_gslr_loss_collect t1
        LEFT JOIN depot_qh.org_info t2 ON t1.org_id = t2.org_id
        left join depot_qh.basic_storehouse t3 on t1.basic_storehouse_id = t3.storehouse_id
        <where>
            t1.`status` = '1'
            AND t1.excess_loss_quantity &gt; '0'
            <if test="orgName!=null and orgName !=''">
                and t2.org_name=#{orgName}
            </if>
            <if test="storehouseName!=null and storehouseName!=''">
                and t3.storehouse_name=#{storehouseName}
            </if>
        </where>
        order by t1.createdate desc

    </select>


    <select id="alarmLineChart"
            resultType="com.unis.grainReserves.modular.businessGslrLossCollect.vo.BusinessGslrLossCollectVO">

        SELECT t1.*,
        t2.org_name,
        t3.storehouse_name,
        t4.warehouse_name
        FROM depot_qh.business_gslr_loss_collect t1
        LEFT JOIN depot_qh.org_info t2 ON t1.org_id = t2.org_id
        left join depot_qh.basic_storehouse t3 on t1.basic_storehouse_id = t3.storehouse_id
        left join depot_qh.basic_warehouse t4 on t4.warehouse_id=t1.warehouse_id
        <where>
            t1.`status` = '1'
            AND t1.excess_loss_quantity &gt; '0'
            <if test="orgName!=null and orgName !=''">
                and t2.org_name=#{orgName}
            </if>
            <if test="storehouseName!=null and storehouseName!=''">
                and t3.storehouse_name=#{storehouseName}
            </if>
            <if test="warehouseName!=null and warehouseName!=''">
                and t4.warehouse_name=#{warehouseName}
            </if>
            <if test="startTime!=null and endTime!=null">
                and t1.business_date between #{startTime} and #{endTime}
            </if>
        </where>

    </select>


    <select id="selectMyPage"
            resultType="com.unis.grainReserves.modular.businessGslrLossCollect.entity.BusinessGslrLossCollect">

        SELECT a1.*
        FROM business_gslr_loss_collect a1
        LEFT JOIN depot_qh.basic_enum a2 ON (
        a1.grain_grade_id = a2.enumId
        OR a1.grain_nature_id = a2.enumId
        OR a1.grain_variety_id = a2.enumId
        )

        <where>

            <if test="grainNatureName != null and grainNatureName != ''">
                a2.enumname like CONCAT('%', #{grainNatureName}, '%')
            </if>
            <if test="grainVarietyName != null and grainVarietyName != ''">
                and a1.grain_variety_id in (select enumId from basic_enum where enumname like CONCAT('%',
                #{grainVarietyName}, '%') )
            </if>
            <if test="orgName != null and orgName != ''">
                and a1.org_id in (SELECT org_id FROM org_info where org_name LIKE CONCAT('%', #{orgName}, '%'))
            </if>
            and a1.`status` = '1'
        </where>

        GROUP BY a1.id
        limit ${(current-1)*size},${size};
    </select>
</mapper>