<?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="cn.iocoder.mall.admin.dao.DataDictMapper">

    <sql id="FIELDS">
        id, enum_value, value, display_name, sort,
        memo, create_time
    </sql>

    <select id="selectByEnumValueAndValue" resultType="DataDictDO">
        SELECT
          <include refid="FIELDS"/>
        FROM data_dict
        WHERE enum_value = #{enumValue}
        AND value = #{value}
        AND deleted = 0
        LIMIT 1
    </select>

    <select id="selectByEnumValueAndValues" resultType="cn.iocoder.mall.admin.dataobject.DataDictDO">
        SELECT
        <include refid="FIELDS"/>
        FROM data_dict
        WHERE deleted = 0
        AND enum_value = #{enumValue}
        AND `value` IN
        <foreach collection="values" item="value" separator="," open="(" close=")">
            #{value}
        </foreach>
    </select>


    <select id="selectById" resultType="DataDictDO">
        SELECT
            <include refid="FIELDS"/>
        FROM data_dict
        WHERE id = #{id}
        AND deleted = 0
    </select>

    <select id="selectList" resultType="DataDictDO">
        SELECT
            <include refid="FIELDS"/>
        FROM data_dict
        WHERE deleted = 0
    </select>
    <select id="selectByEnumValue" resultType="cn.iocoder.mall.admin.dataobject.DataDictDO">
        SELECT
        <include refid="FIELDS"/>
        FROM data_dict
        WHERE deleted = 0
        AND enum_value = #{enumValue}
    </select>

    <insert id="insert" parameterType="DataDictDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO data_dict (
          id, enum_value, value, display_name, sort,
          memo, create_time, deleted
        ) VALUES (
          #{id}, #{enumValue}, #{value}, #{displayName}, #{sort},
          #{memo}, #{createTime}, #{deleted}
        )
    </insert>

    <update id="update" parameterType="DataDictDO">
        UPDATE data_dict
        <set>
            <if test="enumValue != null">
                enum_value = #{enumValue},
            </if>
            <if test="value != null">
                value = #{value},
            </if>
            <if test="displayName != null">
                display_name = #{displayName},
            </if>
            <if test="sort != null">
                sort = #{sort},
            </if>
            <if test="memo != null">
                memo = #{memo},
            </if>
            <if test="deleted != null">
                deleted = #{deleted}
            </if>
        </set>
        WHERE id = #{id}
    </update>

</mapper>