<?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.huimv.admin.mapper.BillCleanMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.huimv.admin.entity.BillClean">
        <id column="id" property="id" />
        <result column="vistit_type" property="vistitType" />
        <result column="dest_name" property="destName" />
        <result column="dest_id" property="destId" />
        <result column="admission_user_name" property="admissionUserName" />
        <result column="admission_user_id" property="admissionUserId" />
        <result column="vistit_date" property="vistitDate" />
        <result column="sub_date" property="subDate" />
        <result column="farm_id" property="farmId" />
        <result column="bill_status" property="billStatus" />
        <result column="pass_date" property="passDate" />
        <result column="pass_user_name" property="passUserName" />
        <result column="pass_user_id" property="passUserId" />
        <result column="process_id" property="processId" />
        <result column="test_location" property="testLocation" />
        <result column="test_location_id" property="testLocationId" />
    </resultMap>

    <select id="listCleanAndDry" resultType="com.huimv.admin.entity.vo.CleanAndDryVo">
        SELECT id,car_num,bill_status,test_location,check_date,vistit_type,pass_date,sub_date,1 AS 'type'
        FROM `bill_clean` WHERE farm_id = #{farmId} AND vistit_type != 0 AND img_status = 1
        <if test="status != null">
            AND bill_status = #{status}
        </if>

        UNION ALL

        SELECT id,car_num,bill_status,test_location,check_date,vistit_type,pass_date,sub_date,2 AS 'type'
        FROM `bill_dry` WHERE farm_id = #{farmId} AND vistit_type != 0 AND img_status = 1
        <if test="status != null">
            AND bill_status = #{status}
        </if>
        ORDER BY sub_date DESC
    </select>

    <select id="listPersonalCleanAndDry" resultType="com.huimv.admin.entity.vo.CleanAndDryVo">
        SELECT id,car_num,bill_status,test_location,check_date,vistit_type,sub_date,pass_date,1 AS 'type'
        FROM `bill_clean` WHERE admission_user_id = #{userId} AND vistit_type = #{vistitType}

        UNION ALL

        SELECT id,car_num,bill_status,test_location,check_date,vistit_type,sub_date,pass_date,2 AS 'type'
        FROM `bill_dry` WHERE admission_user_id = #{userId} AND vistit_type = #{vistitType}
        ORDER BY sub_date DESC
    </select>

    <select id="CleanAndDry" resultType="com.huimv.admin.entity.vo.CleanAndDryVo2">
        select *,1 AS 'type' from bill_clean where farm_id=#{farmId} and vistit_type=#{type}
        and test_location_id in
        <foreach collection="locations" item="location" separator="," open="(" close=")">
            #{location}
        </foreach>
        and img_status in
        <foreach collection="status" item="statu" separator="," open="(" close=")">
            #{statu}
        </foreach>
        union all
        select *,2 AS 'type' from bill_dry where farm_id=#{farmId} and vistit_type=#{type}
        and test_location_id in
        <foreach collection="locations" item="location" separator="," open="(" close=")">
            #{location}
        </foreach>
        and img_status in
        <foreach collection="status" item="statu" separator="," open="(" close=")">
            #{statu}
        </foreach>
        ORDER BY sub_date DESC
    </select>


    <select id="CleanAndDry2" resultType="com.huimv.admin.entity.vo.CleanAndDryVo2">
        select id,vistit_type,dest_name,dest_id,admission_user_name,admission_user_id,vistit_date,sub_date,farm_id,bill_status,pass_date,pass_user_name,pass_user_id,process_id,check_date,test_location,test_location_id,phone,car_num,img_url,img_status,1 AS 'type' from bill_clean where farm_id=#{farmId} and
        vistit_type in (1,2,3,4,5,6) and img_status=1
        and bill_status in
        <foreach collection="status" item="statu" separator="," open="(" close=")">
            #{statu}
        </foreach>
        union all
        select id,vistit_type,dest_name,dest_id,admission_user_name,admission_user_id,vistit_date,sub_date,farm_id,bill_status,pass_date,pass_user_name,pass_user_id,process_id,check_date,test_location,test_location_id,phone,car_num,img_url,img_status,2 AS 'type' from bill_dry where farm_id=#{farmId} and
        vistit_type in (1,2,3,4,5,6) and img_status=1
        and bill_status in
        <foreach collection="status" item="statu" separator="," open="(" close=")">
            #{statu}
        </foreach>
        ORDER BY sub_date DESC
    </select>

    <select id="CleanList" resultType="com.huimv.admin.entity.vo.CleanAndDryVo2">
        select *,1 AS 'type' from bill_clean where farm_id=#{farmId} and vistit_type=4 and test_location_id=#{location}
        and bill_status in
        <foreach collection="status" item="statu" separator="," open="(" close=")">
            #{statu}
        </foreach>
        union all
        select *,2 AS 'type' from bill_dry where farm_id=#{farmId} and vistit_type=4 and test_location_id=#{location}
        and bill_status in
        <foreach collection="status" item="statu" separator="," open="(" close=")">
            #{statu}
        </foreach>
        ORDER BY sub_date DESC
    </select>
</mapper>
