<?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.microservices.dms.achievementLibrary.mapper.AchievementDictDataMapper">
    
    <resultMap type="AchievementDictData" id="AchievementDictDataResult">
        <result property="dictCode"    column="dict_code"    />
        <result property="dictSort"    column="dict_sort"    />
        <result property="dictLabel"    column="dict_label"    />
        <result property="dictValue"    column="dict_value"    />
        <result property="dictType"    column="dict_type"    />
        <result property="status"    column="status"    />
        <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"    />
    </resultMap>

    <sql id="selectAchievementDictDataVo">
        select dict_code, dict_sort, dict_label, dict_value, dict_type, status, create_by, create_time, update_by, update_time, remark from achievement_dict_data
    </sql>

    <select id="selectAchievementDictDataList" parameterType="AchievementDictData" resultMap="AchievementDictDataResult">
        <include refid="selectAchievementDictDataVo"/>
        <where>  
            <if test="dictSort != null "> and dict_sort = #{dictSort}</if>
            <if test="dictLabel != null  and dictLabel != ''"> and dict_label = #{dictLabel}</if>
            <if test="dictValue != null  and dictValue != ''"> and dict_value = #{dictValue}</if>
            <if test="dictType != null  and dictType != ''"> and dict_type = #{dictType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAchievementDictDataByDictCode" parameterType="Long" resultMap="AchievementDictDataResult">
        <include refid="selectAchievementDictDataVo"/>
        where dict_code = #{dictCode}
    </select>
        
    <insert id="insertAchievementDictData" parameterType="AchievementDictData" useGeneratedKeys="true" keyProperty="dictCode">
        insert into achievement_dict_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dictSort != null">dict_sort,</if>
            <if test="dictLabel != null">dict_label,</if>
            <if test="dictValue != null">dict_value,</if>
            <if test="dictType != null">dict_type,</if>
            <if test="status != null">status,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dictSort != null">#{dictSort},</if>
            <if test="dictLabel != null">#{dictLabel},</if>
            <if test="dictValue != null">#{dictValue},</if>
            <if test="dictType != null">#{dictType},</if>
            <if test="status != null">#{status},</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>
         </trim>
    </insert>

    <update id="updateAchievementDictData" parameterType="AchievementDictData">
        update achievement_dict_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="dictSort != null">dict_sort = #{dictSort},</if>
            <if test="dictLabel != null">dict_label = #{dictLabel},</if>
            <if test="dictValue != null">dict_value = #{dictValue},</if>
            <if test="dictType != null">dict_type = #{dictType},</if>
            <if test="status != null">status = #{status},</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>
        </trim>
        where dict_code = #{dictCode}
    </update>

    <delete id="deleteAchievementDictDataByDictCode" parameterType="Long">
        delete from achievement_dict_data where dict_code = #{dictCode}
    </delete>

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

    <select id="selectDictDataByType" resultType="com.microservices.dms.achievementLibrary.domain.KeyValueVo">
        select dict_code as "key",dict_label as "name" from achievement_dict_data  where dict_type = #{dictType}
    </select>

    <select id="selectDictDataByLabel" resultType="int">
        select count(1) from  achievement_dict_data  where dict_type = #{type} and dict_label = #{label}
    </select>

    <select id="getDictTypes" resultType="String">
        select distinct dict_type from achievement_dict_data
    </select>
</mapper>