<?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.zbf.system.mapper.InventoryCheckMapper">

    <resultMap type="InventoryCheck" id="InventoryCheckResult">
        <result property="id"    column="id"    />
        <result property="checkTime"    column="check_time"    />
        <result property="checkType"    column="check_type"    />
        <result property="taskNumber"    column="task_number"    />
    </resultMap>

    <sql id="selectInventoryCheckVo">
        select id, check_time, check_type, task_number from inventory_check
    </sql>

    <select id="selectInventoryCheckList" parameterType="InventoryCheck" resultMap="InventoryCheckResult">
        <include refid="selectInventoryCheckVo"/>
        <where>
            <if test="checkTime != null "> and check_time = #{checkTime}</if>
            <if test="checkType != null  and checkType != ''"> and check_type = #{checkType}</if>
            <if test="taskNumber != null  and taskNumber != ''"> and task_number = #{taskNumber}</if>
        </where>
    </select>

    <select id="selectInventoryCheckById" parameterType="Long" resultMap="InventoryCheckResult">
        <include refid="selectInventoryCheckVo"/>
        where id = #{id}
    </select>

    <insert id="insertInventoryCheck" parameterType="InventoryCheck" useGeneratedKeys="true" keyProperty="id">
        insert into inventory_check
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="checkTime != null">check_time,</if>
            <if test="checkType != null and checkType != ''">check_type,</if>
            <if test="taskNumber != null and taskNumber != ''">task_number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="checkTime != null">#{checkTime},</if>
            <if test="checkType != null and checkType != ''">#{checkType},</if>
            <if test="taskNumber != null and taskNumber != ''">#{taskNumber},</if>
        </trim>
    </insert>

    <update id="updateInventoryCheck" parameterType="InventoryCheck">
        update inventory_check
        <trim prefix="SET" suffixOverrides=",">
            <if test="checkTime != null">check_time = #{checkTime},</if>
            <if test="checkType != null and checkType != ''">check_type = #{checkType},</if>
            <if test="taskNumber != null and taskNumber != ''">task_number = #{taskNumber},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableInventoryCheckByIds" parameterType="String">
        update inventory_check set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledInventoryCheckByIds" parameterType="String">
        update inventory_check set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteInventoryCheckById" parameterType="Long">
        delete from inventory_check  where id = #{id}
    </delete>

    <delete id="deleteInventoryCheckByIds" parameterType="String">
        delete from inventory_check where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
