<?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="org.springblade.system.mapper.KyDataClassifyMapper">
    <insert id="addKyDataClassify">
        insert into record_da_ky_data_classify
            (data_type_name,remark,create_time,update_time,create_user_id,create_user_name,update_user_id,update_user_name,pid)
        values (#{dataTypeName},#{remark},#{createTime},#{updateTime},#{createUserId},#{createUserName},#{updateUserId},#{updateUserName},#{pid})
    </insert>
    <update id="updateKyDataClassify">
        update record_da_ky_data_classify
        <trim prefix="set" suffixOverrides=",">
            <if test="dataTypeName!=null">
                data_type_name =#{dataTypeName},
            </if>
            <if test="updateUserId!=null">
                update_user_id =#{updateUserId},
            </if>
            <if test="updateUserName!=null">
                update_user_name =#{updateUserName},
            </if>
            <if test="updateTime!=null">
                update_time =#{updateTime},
            </if>
            <if test="remark!=null">
                remark =#{remark},
            </if>
            <if test="pid!=null">
                pid =#{pid},
            </if>
        </trim>
        where id = #{id}
    </update>
    <delete id="delKyDataClassify">
        update record_da_ky_data_classify set del_flag = '0' where id = #{id}
    </delete>

    <select id="selectKyDataClassifyList" resultType="org.springblade.common.core.domain.entity.KyDataClassify">
        select dkdc.id as id ,dkdc.data_type_name as dataTypeName,dkdc.remark as remark,
        dkdc.update_time as updateTime, dkdc.update_user_id as createUserId,
        dkdc.update_user_name as updateUserName,dksdd.dict_label as pName,dksdd.dict_value as pid
        from record_da_ky_data_classify dkdc
        left join da_ky_sys_dict_data dksdd on dkdc.pid =dksdd.dict_value
        where del_flag='1'
        <if test="dataTypeName!=null">
            AND INSTR(data_type_name, #{dataTypeName}) > 0
        </if>
        order by dkdc.create_time desc
    </select>
    <select id="listAll" resultType="org.springblade.common.core.domain.entity.KyDataClassify">
        select id,data_type_name
        from record_da_ky_data_classify where del_flag='1' and pid  =#{pid}
        <if test="dataTypeName!=null">
            AND INSTR(data_type_name, #{dataTypeName}) > 0
        </if>
    </select>
    <select id="selectKyDataClassifyByDataTypeName" resultType="org.springblade.common.core.domain.entity.KyDataClassify">
        select id,data_type_name,remark,update_time,update_user_id,update_user_name
        from record_da_ky_data_classify where del_flag='1' and data_type_name = #{dataTypeName}
    </select>
    <select id="getParenList" resultType="org.springblade.common.core.domain.entity.KyDataClassifyVo">
        select dict_value as code,dict_label as name
        from da_ky_sys_dict_data where dict_type = 'data_class_type' and status='0'
    </select>
    <select id="getById" resultType="org.springblade.common.core.domain.entity.KyDataClassify">
        select dkdc.id as id ,dkdc.data_type_name as dataTypeName,dkdc.remark as remark,
        dkdc.update_time as updateTime, dkdc.update_user_id as createUserId,
        dkdc.update_user_name as updateUserName,dksdd.dict_label as pName,dksdd.dict_value as pid
        from record_da_ky_data_classify dkdc
        left join da_ky_sys_dict_data dksdd on dkdc.pid =dksdd.dict_value
        where del_flag='1' and dkdc.id = #{id}
    </select>
</mapper>
