<?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.ruoyi.project.plant.mapper.TMtdConfigMapper">

    <resultMap type="TMtdConfig" id="TMtdConfigResult">
        <result property="id"    column="id"    />
        <result property="configName"    column="config_name"    />
        <result property="configKey"    column="config_key"    />
        <result property="configValue"    column="config_value"    />
        <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"    />
        <result property="configType"    column="config_type"    />
    </resultMap>

    <sql id="selectTMtdConfigVo">
        select d.id, d.config_name, d.config_key, d.config_value, d.create_by, d.create_time, d.update_by, d.update_time, d.remark, d.config_type from t_mtd_config d
    </sql>

    <select id="selectTMtdConfigList" parameterType="TMtdConfig" resultMap="TMtdConfigResult">
        <include refid="selectTMtdConfigVo"/>
        <where>
            <if test="configName != null  and configName != ''"> and config_name like concat(concat('%', #{configName}), '%')</if>
            <if test="configKey != null  and configKey != ''"> and config_key = #{configKey}</if>
            <if test="configValue != null  and configValue != ''"> and config_value = #{configValue}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
    </select>

    <select id="selectTMtdConfigById" parameterType="Long" resultMap="TMtdConfigResult">
        <include refid="selectTMtdConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMtdConfig" parameterType="TMtdConfig">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_mtd_config.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_mtd_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="configName != null">config_name,</if>
            <if test="configKey != null">config_key,</if>
            <if test="configValue != null">config_value,</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>
            <if test="configType != null">config_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="configName != null">#{configName},</if>
            <if test="configKey != null">#{configKey},</if>
            <if test="configValue != null">#{configValue},</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>
            <if test="configType != null">#{configType},</if>
         </trim>
    </insert>

    <update id="updateTMtdConfig" parameterType="TMtdConfig">
        update t_mtd_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="configName != null">config_name = #{configName},</if>
            <if test="configKey != null">config_key = #{configKey},</if>
            <if test="configValue != null">config_value = #{configValue},</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>
            <if test="configType != null">config_type = #{configType},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTMtdConfigById" parameterType="Long">
        update t_mtd_config set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTMtdConfigByIds" parameterType="String">
        update t_mtd_config set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
