<?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.yeejoin.equipmanage.mapper.StockBillMapper">
    <resultMap id="allBill" type="com.yeejoin.equipmanage.common.entity.vo.AllBillVO">
        <result column="id" property="id"></result>
        <result column="bill_code" property="billCode"></result>
        <result column="bill_type" property="billType"></result>
        <result column="creator_name" property="creatorName"></result>
        <result column="create_date" property="createDate"></result>
        <result column="company_name" property="companyName"></result>
        <result column="type" property="type"></result>
    </resultMap>

    <select id="selectAllBill" resultMap="allBill" parameterType="com.yeejoin.equipmanage.common.entity.dto.StockBillDTO">
select * from (
        <if test='stockBillDTO.billType=="0" or stockBillDTO.billType=="4"'>
            select id,bill_code,bill_type,creator_name,create_date,company_name,4 as type from wl_wastage_bill
            where 1=1
            <if test="stockBillDTO.billCode!=null and stockBillDTO.billCode!=''">
                and bill_code like concat('%',#{stockBillDTO.billCode},'%')
            </if>
            <if test="stockBillDTO.createDateStart!=null">
                and create_date &gt;= #{stockBillDTO.createDateStart}
            </if>
            <if test="stockBillDTO.createDateEnd!=null">
                and create_date &lt;= #{stockBillDTO.createDateEnd}
            </if>
        </if>
        <if test='stockBillDTO.billType=="0"'>
            union all
        </if>
        <if test='stockBillDTO.billType=="0" or stockBillDTO.billType=="1"'>
            select id,bill_code,bill_type,creator_name,create_date,company_name,1 as type from wl_stock_bill
            where 1=1
            <if test="stockBillDTO.billCode!=null and stockBillDTO.billCode!=''">
                and bill_code like concat('%',#{stockBillDTO.billCode},'%')
            </if>
            <if test="stockBillDTO.createDateStart!=null">
                and create_date &gt;= #{stockBillDTO.createDateStart}
            </if>
            <if test="stockBillDTO.createDateEnd!=null">
                and create_date &lt;= #{stockBillDTO.createDateEnd}
            </if>
        </if>
        <if test='stockBillDTO.billType=="0"'>
            union all
        </if>
        <if test='stockBillDTO.billType=="0" or stockBillDTO.billType=="5"'>
            select id,bill_code,bill_type,creator_name,create_date,company_name,5 as type from wl_scrap
            where 1=1
            <if test="stockBillDTO.billCode!=null and stockBillDTO.billCode!=''">
                and bill_code like concat('%',#{stockBillDTO.billCode},'%')
            </if>
            <if test="stockBillDTO.createDateStart!=null">
                and create_date &gt;= #{stockBillDTO.createDateStart}
            </if>
            <if test="stockBillDTO.createDateEnd!=null">
                and create_date &lt;= #{stockBillDTO.createDateEnd}
            </if>
        </if>
        <if test='stockBillDTO.billType=="0"'>
            union all
        </if>
        <if test='stockBillDTO.billType=="0" or stockBillDTO.billType=="2" '>
            select id,bill_code,bill_type,creator_name,create_date,company_name,2 as type from wl_repair
            where 1=1
            <if test="stockBillDTO.billCode!=null and stockBillDTO.billCode!=''">
                and bill_code like concat('%',#{stockBillDTO.billCode},'%')
            </if>
            <if test="stockBillDTO.createDateStart!=null">
                and create_date &gt;= #{stockBillDTO.createDateStart}
            </if>
            <if test="stockBillDTO.createDateEnd!=null">
                and create_date &lt;= #{stockBillDTO.createDateEnd}
            </if>
        </if>
        <if test='stockBillDTO.billType=="0"'>
            union all
        </if>
        <if test='stockBillDTO.billType=="0" or stockBillDTO.billType=="3"'>
            select id,bill_code,bill_type,creator_name,create_date,company_name,3 as type from wl_maintain
            where 1=1
            <if test="stockBillDTO.billCode!=null and stockBillDTO.billCode!=''">
                and bill_code like concat('%',#{stockBillDTO.billCode},'%')
            </if>
            <if test="stockBillDTO.createDateStart!=null">
                and create_date &gt;= #{stockBillDTO.createDateStart}
            </if>
            <if test="stockBillDTO.createDateEnd!=null">
                and create_date &lt;= #{stockBillDTO.createDateEnd}
            </if>
        </if>) as da
        order by create_date desc
    </select>
</mapper>
