<?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.ruoyi.app.mapper.InspectionItemMapper">
    
    <resultMap type="InspectionItem" id="InspectionItemResult">
        <result property="id"    column="id"    />
        <result property="itemName"    column="item_name"    />
        <result property="remark"    column="remark"    />
        <result property="result"    column="result"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectInspectionItemVo">
        select id, item_name, remark, result, create_time, create_by, update_time, update_by, del_flag from inspection_item
    </sql>

    <select id="selectInspectionItemList" parameterType="InspectionItem" resultMap="InspectionItemResult">
        <include refid="selectInspectionItemVo"/>
        <where>
            del_flag = '0'
            <if test="itemName != null  and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
            <if test="result != null  and result != ''"> and result = #{result}</if>
        </where>
    </select>


    <select id="selectInspectionItemById" parameterType="Long" resultMap="InspectionItemResult">
        <include refid="selectInspectionItemVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="checkItemNameUnique" parameterType="String" resultMap="InspectionItemResult">
        select id, item_name from inspection_item where item_name = #{itemName} and del_flag = '0' limit 1
    </select>

    <insert id="insertInspectionItem" parameterType="InspectionItem" useGeneratedKeys="true" keyProperty="id">
        insert into inspection_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="itemName != null and itemName != ''">item_name,</if>
            <if test="remark != null">remark,</if>
            <if test="result != null">result,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            del_flag
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="itemName != null and itemName != ''">#{itemName},</if>
            <if test="remark != null">#{remark},</if>
            <if test="result != null">#{result},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            '0'
         </trim>
    </insert>

    <update id="updateInspectionItem" parameterType="InspectionItem">
        update inspection_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="itemName != null and itemName != ''">item_name = #{itemName},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="result != null">result = #{result},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInspectionItemById" parameterType="Long">
        update inspection_item set del_flag = '2' where id = #{id}
    </delete>

    <delete id="deleteInspectionItemByIds" parameterType="String">
        update inspection_item set del_flag = '2' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>