<?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.gov.customs.wxjy.system.dao.DictDataDao">

    <resultMap type="cn.gov.customs.wxjy.system.pojo.DictData" id="DictDataResult">
        <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="cssClass" column="CSS_CLASS"/>
        <result property="listClass" column="LIST_CLASS"/>
        <result property="isDefault" column="IS_DEFAULT"/>
        <result property="status" column="STATUS"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="updateUser" column="UPDATE_USER"/>
        <result property="updateTime" column="UPDATE_TIME"/>
        <result property="remark" column="REMARK"/>
    </resultMap>

    <sql id="baseVo">
        select DICT_CODE, DICT_SORT, DICT_LABEL, DICT_VALUE, DICT_TYPE, CSS_CLASS, LIST_CLASS, IS_DEFAULT, STATUS, CREATE_USER, CREATE_TIME, UPDATE_USER, UPDATE_TIME, REMARK
        from WXJY_DICT_DATA
    </sql>

    <select id="selectDictDataList" parameterType="cn.gov.customs.wxjy.system.pojo.DictDataQuery" resultMap="DictDataResult">
        <include refid="baseVo"/>
        <where>
            <if test="dictType != null and dictType != ''">
                AND dict_type = #{dictType}
            </if>
            <if test="dictLabel != null and dictLabel != ''">
                AND dict_label like concat('%', #{dictLabel}, '%')
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
        </where>
        order by dict_sort asc
    </select>

    <select id="selectDictDataByType" parameterType="String" resultMap="DictDataResult">
        <include refid="baseVo"/>
        where status = '0' and dict_type = #{dictType} order by dict_sort asc
    </select>

    <select id="selectDictLabel" resultType="String">
        select dict_label from wxjy_dict_data
        where dict_type = #{dictType} and dict_value = #{dictValue}
    </select>

    <select id="selectDictDataById" parameterType="Long" resultMap="DictDataResult">
        <include refid="baseVo"/>
        where dict_code = #{dictCode}
    </select>

    <select id="countDictDataByType" resultType="Integer">
        select count(1) from wxjy_dict_data where dict_type=#{dictType}
    </select>

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

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

    <update id="updateDictData" parameterType="cn.gov.customs.wxjy.system.pojo.DictData">
        update wxjy_dict_data
        <set>
            <if test="dictSort != null">dict_sort = #{dictSort},</if>
            <if test="dictLabel != null and dictLabel != ''">dict_label = #{dictLabel},</if>
            <if test="dictValue != null and dictValue != ''">dict_value = #{dictValue},</if>
            <if test="dictType != null and dictType != ''">dict_type = #{dictType},</if>
            <if test="cssClass != null">css_class = #{cssClass},</if>
            <if test="listClass != null">list_class = #{listClass},</if>
            <if test="isDefault != null and isDefault != ''">is_default = #{isDefault},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateUser != null and updateUser != ''">UPDATE_USER = #{updateUser},</if>
            update_time = sysdate()
        </set>
        where dict_code = #{dictCode}
    </update>

    <update id="updateDictDataType" parameterType="String">
        update wxjy_dict_data set dict_type = #{newDictType} where dict_type = #{oldDictType}
    </update>

    <insert id="insertDictData" parameterType="cn.gov.customs.wxjy.system.pojo.DictData">
        insert into wxjy_dict_data(
        <if test="dictSort != null">dict_sort,</if>
        <if test="dictLabel != null and dictLabel != ''">dict_label,</if>
        <if test="dictValue != null and dictValue != ''">dict_value,</if>
        <if test="dictType != null and dictType != ''">dict_type,</if>
        <if test="cssClass != null and cssClass != ''">css_class,</if>
        <if test="listClass != null and listClass != ''">list_class,</if>
        <if test="isDefault != null and isDefault != ''">is_default,</if>
        <if test="status != null">status,</if>
        <if test="remark != null and remark != ''">remark,</if>
        <if test="createUser != null and createUser != ''">CREATE_USER,</if>
        create_time
        )values(
        <if test="dictSort != null">#{dictSort},</if>
        <if test="dictLabel != null and dictLabel != ''">#{dictLabel},</if>
        <if test="dictValue != null and dictValue != ''">#{dictValue},</if>
        <if test="dictType != null and dictType != ''">#{dictType},</if>
        <if test="cssClass != null and cssClass != ''">#{cssClass},</if>
        <if test="listClass != null and listClass != ''">#{listClass},</if>
        <if test="isDefault != null and isDefault != ''">#{isDefault},</if>
        <if test="status != null">#{status},</if>
        <if test="remark != null and remark != ''">#{remark},</if>
        <if test="createUser != null and createUser != ''">#{createUser},</if>
        sysdate()
        )
    </insert>

    <select id="checkDictDataUnique" parameterType="String" resultMap="DictDataResult">
        <include refid="baseVo"/>
        where dict_type = #{dictType} and dict_value = #{dictValue} limit 1
    </select>
</mapper>