<?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.shzg.project.worn.mapper.WornOutboundBillMapper">
    
    <resultMap type="WornOutboundBill" id="WornOutboundBillResult">
        <result property="id"    column="id"    />
        <result property="billNo"    column="bill_no"    />
        <result property="billType"    column="bill_type"    />
        <result property="warehouseCode"    column="warehouse_code"    />
        <result property="warehouseName"    column="warehouse_name"    />
        <result property="areaCode"    column="area_code"    />
        <result property="areaName"    column="area_name"    />
        <result property="remark"    column="remark"    />
        <result property="outboundTime"    column="outbound_time"    />
        <result property="status"    column="status"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="projectId"    column="project_id"    />
    </resultMap>

    <sql id="selectWornOutboundBillVo">
        select id, bill_no, bill_type, warehouse_code, warehouse_name, area_code, area_name, remark, outbound_time, status, is_delete, create_by, create_time, update_by, update_time, project_id from worn_outbound_bill
    </sql>

    <select id="selectWornOutboundBillList" parameterType="WornOutboundBill" resultMap="WornOutboundBillResult">
        <include refid="selectWornOutboundBillVo"/>
        <where>  
            <if test="billNo != null  and billNo != ''"> and bill_no = #{billNo}</if>
            <if test="billType != null  and billType != ''"> and bill_type = #{billType}</if>
            <if test="warehouseCode != null  and warehouseCode != ''"> and warehouse_code = #{warehouseCode}</if>
            <if test="warehouseName != null  and warehouseName != ''"> and warehouse_name like concat('%', #{warehouseName}, '%')</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="outboundTime != null "> and outbound_time = #{outboundTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
        </where>
    </select>
    
    <select id="selectWornOutboundBillById" parameterType="Long" resultMap="WornOutboundBillResult">
        <include refid="selectWornOutboundBillVo"/>
        where id = #{id}
    </select>

    <insert id="insertWornOutboundBill" parameterType="WornOutboundBill" useGeneratedKeys="true" keyProperty="id">
        insert into worn_outbound_bill
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="billNo != null and billNo != ''">bill_no,</if>
            <if test="billType != null">bill_type,</if>
            <if test="warehouseCode != null">warehouse_code,</if>
            <if test="warehouseName != null">warehouse_name,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="areaName != null">area_name,</if>
            <if test="remark != null">remark,</if>
            <if test="outboundTime != null">outbound_time,</if>
            <if test="status != null">status,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="projectId != null">project_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="billNo != null and billNo != ''">#{billNo},</if>
            <if test="billType != null">#{billType},</if>
            <if test="warehouseCode != null">#{warehouseCode},</if>
            <if test="warehouseName != null">#{warehouseName},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="remark != null">#{remark},</if>
            <if test="outboundTime != null">#{outboundTime},</if>
            <if test="status != null">#{status},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="projectId != null">#{projectId},</if>
         </trim>
    </insert>

    <update id="updateWornOutboundBill" parameterType="WornOutboundBill">
        update worn_outbound_bill
        <trim prefix="SET" suffixOverrides=",">
            <if test="billType != null">bill_type = #{billType},</if>
            <if test="warehouseCode != null">warehouse_code = #{warehouseCode},</if>
            <if test="warehouseName != null">warehouse_name = #{warehouseName},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="outboundTime != null">outbound_time = #{outboundTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
        </trim>
        where bill_no = #{billNo}
    </update>

    <delete id="deleteWornOutboundBillById" parameterType="Long">
        delete from worn_outbound_bill where id = #{id}
    </delete>

    <delete id="deleteWornOutboundBillByIds" parameterType="String">
        delete from worn_outbound_bill where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectWornOutboundBillByBillNo" parameterType="java.lang.String" resultMap="WornOutboundBillResult">
        select
            id,
            bill_no,
            bill_type,
            warehouse_code,
            warehouse_name,
            area_code,
            area_name,
            remark,
            outbound_time,
            status,
            is_delete,
            create_by,
            create_time,
            update_by,
            update_time,
            project_id
        from worn_outbound_bill
        where bill_no = #{billNo}
          and (is_delete = '0' or is_delete is null)
            limit 1
    </select>
</mapper>