<?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.DictTypeDao">

    <resultMap type="cn.gov.customs.wxjy.system.pojo.DictType" id="DictTypeResult">
        <result property="pkDictType" column="PK_DICT_TYPE"/>
        <result property="dictName" column="DICT_NAME"/>
        <result property="dictType" column="DICT_TYPE"/>
        <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 PK_DICT_TYPE, DICT_NAME, DICT_TYPE, STATUS, CREATE_USER, CREATE_TIME, UPDATE_USER, UPDATE_TIME, REMARK
        from WXJY_DICT_TYPE
    </sql>

    <select id="selectDictTypeList" parameterType="cn.gov.customs.wxjy.system.pojo.DictTypeQuery" resultMap="DictTypeResult">
        <include refid="baseVo"/>
        <where>
            <if test="dictName != null and dictName != ''">
                AND dict_name like '%' || #{dictName} || '%'
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
            <if test="dictType != null and dictType != ''">
                AND dict_type like '%' || #{dictType} || '%'
            </if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectDictTypeAll" resultMap="DictTypeResult">
        <include refid="baseVo"/>
    </select>

    <select id="selectDictTypeById" parameterType="Long" resultMap="DictTypeResult">
        <include refid="baseVo"/>
        where PK_DICT_TYPE = #{pkDictType}
    </select>

    <select id="selectDictTypeByType" parameterType="String" resultMap="DictTypeResult">
        <include refid="baseVo"/>
        where dict_type = #{dictType}
    </select>

    <select id="checkDictTypeUnique" parameterType="String" resultMap="DictTypeResult">
        <include refid="baseVo"/>
        where dict_type = #{dictType} limit 1
    </select>

    <delete id="deleteDictTypeById" parameterType="Long">
        delete from wxjy_dict_type where PK_DICT_TYPE = #{pkDictType}
    </delete>

    <delete id="deleteDictTypeByIds" parameterType="Long">
        delete from wxjy_dict_type where PK_DICT_TYPE in
        <foreach collection="array" item="pkDictType" open="(" separator="," close=")">
            #{pkDictType}
        </foreach>
    </delete>

    <update id="updateDictType" parameterType="cn.gov.customs.wxjy.system.pojo.DictType">
        update wxjy_dict_type
        <set>
            <if test="dictName != null and dictName != ''">dict_name = #{dictName},</if>
            <if test="dictType != null and dictType != ''">dict_type = #{dictType},</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 PK_DICT_TYPE = #{pkDictType}
    </update>

    <insert id="insertDictType" parameterType="cn.gov.customs.wxjy.system.pojo.DictType">
        insert into wxjy_dict_type(
        <if test="dictName != null and dictName != ''">dict_name,</if>
        <if test="dictType != null and dictType != ''">dict_type,</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="dictName != null and dictName != ''">#{dictName},</if>
        <if test="dictType != null and dictType != ''">#{dictType},</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>
</mapper>