<?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.system.mapper.UserTypeMapper">
    
    <resultMap type="UserType" id="UserTypeResult">
        <result property="typeId"    column="type_id"    />
        <result property="typeName"    column="type_name"    />
        <result property="typeValue"    column="type_value"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="deleteFlag"    column="delete_flag"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectUserTypeVo">
        select type_id, type_name, type_value, remark, create_time, delete_flag, update_time from user_type
    </sql>

    <select id="selectUserTypeList" parameterType="UserType" resultMap="UserTypeResult">
        <include refid="selectUserTypeVo"/>
        <where>  
            <if test="typeName != null  and typeName != ''"> and type_name like concat('%', #{typeName}, '%')</if>
            <if test="typeValue != null  and typeValue != ''"> and type_value = #{typeValue}</if>
            <if test="deleteFlag != null  and deleteFlag != ''"> and delete_flag = #{deleteFlag}</if>
        </where>
    </select>
    
    <select id="selectUserTypeByTypeId" parameterType="Long" resultMap="UserTypeResult">
        <include refid="selectUserTypeVo"/>
        where type_id = #{typeId}
    </select>
        
    <insert id="insertUserType" parameterType="UserType" useGeneratedKeys="true" keyProperty="typeId">
        insert into user_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">type_name,</if>
            <if test="typeValue != null and typeValue != ''">type_value,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="deleteFlag != null">delete_flag,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">#{typeName},</if>
            <if test="typeValue != null and typeValue != ''">#{typeValue},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="deleteFlag != null">#{deleteFlag},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateUserType" parameterType="UserType">
        update user_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">type_name = #{typeName},</if>
            <if test="typeValue != null and typeValue != ''">type_value = #{typeValue},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="deleteFlag != null">delete_flag = #{deleteFlag},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where type_id = #{typeId}
    </update>

    <delete id="deleteUserTypeByTypeId" parameterType="Long">
        delete from user_type where type_id = #{typeId}
    </delete>

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