<?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.unique.mapper.WornUniqueCodeEventMapper">
    
    <resultMap type="WornUniqueCodeEvent" id="WornUniqueCodeEventResult">
        <result property="id"    column="id"    />
        <result property="uniqueCodeId"    column="unique_code_id"    />
        <result property="eventType"    column="event_type"    />
        <result property="eventStatus"    column="event_status"    />
        <result property="eventDesc"    column="event_desc"    />
        <result property="operatorId"    column="operator_id"    />
        <result property="operatorName"    column="operator_name"    />
        <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="remark"    column="remark"    />
        <result property="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectWornUniqueCodeEventVo">
        select id, unique_code_id, event_type, event_status, event_desc, operator_id, operator_name, create_by, create_time, update_by, update_time, remark, is_delete from worn_unique_code_event
    </sql>

    <select id="selectWornUniqueCodeEventList" parameterType="WornUniqueCodeEvent" resultMap="WornUniqueCodeEventResult">
        <include refid="selectWornUniqueCodeEventVo"/>
        <where>  
            <if test="uniqueCodeId != null "> and unique_code_id = #{uniqueCodeId}</if>
            <if test="eventType != null  and eventType != ''"> and event_type = #{eventType}</if>
            <if test="eventStatus != null  and eventStatus != ''"> and event_status = #{eventStatus}</if>
            <if test="eventDesc != null  and eventDesc != ''"> and event_desc = #{eventDesc}</if>
            <if test="operatorId != null "> and operator_id = #{operatorId}</if>
            <if test="operatorName != null  and operatorName != ''"> and operator_name like concat('%', #{operatorName}, '%')</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
        </where>
    </select>
    
    <select id="selectWornUniqueCodeEventById" parameterType="Long" resultMap="WornUniqueCodeEventResult">
        <include refid="selectWornUniqueCodeEventVo"/>
        where id = #{id}
    </select>

    <insert id="insertWornUniqueCodeEvent" parameterType="WornUniqueCodeEvent" useGeneratedKeys="true" keyProperty="id">
        insert into worn_unique_code_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uniqueCodeId != null">unique_code_id,</if>
            <if test="eventType != null and eventType != ''">event_type,</if>
            <if test="eventStatus != null">event_status,</if>
            <if test="eventDesc != null">event_desc,</if>
            <if test="operatorId != null">operator_id,</if>
            <if test="operatorName != null">operator_name,</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="remark != null">remark,</if>
            <if test="isDelete != null">is_delete,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uniqueCodeId != null">#{uniqueCodeId},</if>
            <if test="eventType != null and eventType != ''">#{eventType},</if>
            <if test="eventStatus != null">#{eventStatus},</if>
            <if test="eventDesc != null">#{eventDesc},</if>
            <if test="operatorId != null">#{operatorId},</if>
            <if test="operatorName != null">#{operatorName},</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="remark != null">#{remark},</if>
            <if test="isDelete != null">#{isDelete},</if>
         </trim>
    </insert>

    <update id="updateWornUniqueCodeEvent" parameterType="WornUniqueCodeEvent">
        update worn_unique_code_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="uniqueCodeId != null">unique_code_id = #{uniqueCodeId},</if>
            <if test="eventType != null and eventType != ''">event_type = #{eventType},</if>
            <if test="eventStatus != null">event_status = #{eventStatus},</if>
            <if test="eventDesc != null">event_desc = #{eventDesc},</if>
            <if test="operatorId != null">operator_id = #{operatorId},</if>
            <if test="operatorName != null">operator_name = #{operatorName},</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="remark != null">remark = #{remark},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWornUniqueCodeEventById" parameterType="Long">
        delete from worn_unique_code_event where id = #{id}
    </delete>

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

    <select id="selectByUniqueCodeId" resultType="WornUniqueCodeMaterial">
        SELECT *
        FROM worn_unique_code_material
        WHERE unique_code_id = #{uniqueCodeId}
    </select>
</mapper>