<?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.configuration.mapper.TMatterFeatureMapper">

    <resultMap type="TMatterFeature" id="TMatterFeatureResult">
        <result property="id" column="id"/>
        <result property="featureName" column="feature_name"/>
        <result property="featureCode" column="feature_code"/>
        <result property="deptName" column="dept_name"/>
    </resultMap>

    <sql id="selectTMatterFeatureVo">
        select d.id, d.feature_name, d.feature_code, s.dept_name
        from t_matter_feature d
                 left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <sql id="selectTMatterFeatureVo2">
        select d.id, d.feature_name, d.feature_code, s.dept_name
        from t_matter_feature d
    </sql>

    <select id="queryByIds" resultType="java.lang.String">
        select d.feature_code
        from t_matter_feature d
        where
        d.id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>

    </select>

    <select id="selectTMatterFeatureList" parameterType="TMatterFeature" resultMap="TMatterFeatureResult">
        <include refid="selectTMatterFeatureVo"/>
        <where>
            <if test="featureName != null  and featureName != ''">and feature_name like concat(concat('%',
                #{featureName}), '%')
            </if>
            <if test="featureCode != null  and featureCode != ''">and feature_code = #{featureCode}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMatterFeatureById" parameterType="Long" resultMap="TMatterFeatureResult">
        <include refid="selectTMatterFeatureVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMatterFeature" parameterType="TMatterFeature">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_matter_feature.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_matter_feature
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="featureName != null and featureName != ''">feature_name,</if>
            <if test="featureCode != null">feature_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="featureName != null and featureName != ''">#{featureName},</if>
            <if test="featureCode != null">#{featureCode},</if>
        </trim>
    </insert>

    <update id="updateTMatterFeature" parameterType="TMatterFeature">
        update t_matter_feature
        <trim prefix="SET" suffixOverrides=",">
            <if test="featureName != null and featureName != ''">feature_name = #{featureName},</if>
            <if test="featureCode != null">feature_code = #{featureCode},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
