<?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.HookRegisterMapper">
    
    <resultMap type="HookRegister" id="HookRegisterResult">
        <result property="id"    column="id"    />
        <result property="hookNo"    column="hook_no"    />
        <result property="epcNo"    column="epc_no"    />
        <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="selectHookRegisterVo">
        select id, hook_no,epc_no, create_time, create_by, update_time, update_by, del_flag from hook_register
    </sql>

    <select id="selectHookRegisterList" parameterType="com.ruoyi.app.domain.request.ReqHookRegister" resultMap="HookRegisterResult">
        <include refid="selectHookRegisterVo"/>
        <where>
            del_flag = '0'
            <if test="keyword != null  and keyword != ''"> and (hook_no like concat('%', #{keyword}, '%') or (epc_no like concat('%', #{keyword}, '%')))</if>
            <if test="hookNo != null  and hookNo != ''"> and hook_no like concat('%', #{hookNo}, '%')</if>
            <if test="epcNo != null  and epcNo != ''"> and epc_no like concat('%', #{epcNo}, '%')</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectHookRegisterById" parameterType="Long" resultMap="HookRegisterResult">
        <include refid="selectHookRegisterVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectHookRegisterByEpcNo" parameterType="com.ruoyi.app.domain.request.ReqHookRegister" resultMap="HookRegisterResult">
        <include refid="selectHookRegisterVo"/>
        <where>
            del_flag = '0'
            <if test="epcNo != null  and epcNo != ''"> and epc_no = #{epcNo}</if>
        </where>
        order by create_time desc limit 1
    </select>
    <select id="checkHookNoUnique" parameterType="String" resultMap="HookRegisterResult">
        select id, hook_no from hook_register where hook_no = #{hookNo} and del_flag = '0' limit 1
    </select>
    <select id="checkEpcNoUnique" parameterType="String" resultMap="HookRegisterResult">
        select id, epc_no from hook_register where epc_no = #{epcNo} and del_flag = '0' limit 1
    </select>
    <insert id="insertHookRegister" parameterType="HookRegister" useGeneratedKeys="true" keyProperty="id">
        insert into hook_register
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hookNo != null and hookNo != ''">hook_no,</if>
            <if test="epcNo != null and epcNo != ''">epc_no,</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="hookNo != null and hookNo != ''">#{hookNo},</if>
            <if test="epcNo != null and epcNo != ''">#{epcNo},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            '0'
         </trim>
    </insert>

    <update id="updateHookRegister" parameterType="HookRegister">
        update hook_register
        <trim prefix="SET" suffixOverrides=",">
            <if test="hookNo != null and hookNo != ''">hook_no = #{hookNo},</if>
            <if test="epcNo != null and epcNo != ''">epc_no = #{epcNo},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

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

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