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

    <resultMap type="TMatter" id="TMatterResult">
        <result property="id" column="id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="remarks" column="remarks"/>
        <result property="createrCode" column="creater_code"/>
        <result property="createdate" column="createdate"/>
        <result property="updaterCode" column="updater_code"/>
        <result property="updatedate" column="updatedate"/>
        <result property="matterName" column="matter_name"/>
        <result property="matterType" column="matter_type"/>
        <result property="matterFeatures" column="matter_features"/>
        <result property="matterProtects" column="matter_protects"/>
        <result property="deptName" column="dept_name"/>
    </resultMap>

    <sql id="selectTMatterVo">
        select d.id,
               d.del_flag,
               d.remarks,
               d.creater_code,
               d.createdate,
               d.updater_code,
               d.updatedate,
               d.matter_name,
               d.matter_type,
               d.matter_features,
               d.matter_protects
        from t_matter d
    </sql>

    <sql id="selectTMatterVo2">
        select d.id,
               d.del_flag,
               d.remarks,
               d.creater_code,
               d.createdate,
               d.updater_code,
               d.updatedate,
               d.matter_name,
               d.matter_type,
               d.matter_features,
               d.matter_protects
        from t_matter d

    </sql>

    <select id="selectTMatterList" parameterType="TMatter" resultMap="TMatterResult">
        <include refid="selectTMatterVo2"/>
        <where>
            <if test="remarks != null  and remarks != ''">and remarks = #{remarks}</if>
            <if test="createrCode != null  and createrCode != ''">and creater_code = #{createrCode}</if>
            <if test="createdate != null ">and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''">and updater_code = #{updaterCode}</if>
            <if test="updatedate != null ">and updatedate = #{updatedate}</if>
            <if test="matterName != null  and matterName != ''">and matter_name like concat(concat('%', #{matterName}),
                '%')
            </if>
            <if test="matterType != null ">and matter_type = #{matterType}</if>
            <if test="matterFeatures != null  and matterFeatures != ''">and matter_features = #{matterFeatures}</if>
            <if test="matterProtects != null  and matterProtects != ''">and matter_protects = #{matterProtects}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMatterById" parameterType="Long" resultMap="TMatterResult">
        <include refid="selectTMatterVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMatter" parameterType="TMatter">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_matter.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_matter
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="remarks != null">remarks,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="matterName != null and matterName != ''">matter_name,</if>
            <if test="matterType != null">matter_type,</if>
            <if test="matterFeatures != null">matter_features,</if>
            <if test="matterProtects != null">matter_protects,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="matterName != null and matterName != ''">#{matterName},</if>
            <if test="matterType != null">#{matterType},</if>
            <if test="matterFeatures != null">#{matterFeatures},</if>
            <if test="matterProtects != null">#{matterProtects},</if>
        </trim>
    </insert>

    <update id="updateTMatter" parameterType="TMatter">
        update t_matter
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="matterName != null and matterName != ''">matter_name = #{matterName},</if>
            <if test="matterType != null">matter_type = #{matterType},</if>
            <if test="matterFeatures != null">matter_features = #{matterFeatures},</if>
            <if test="matterProtects != null">matter_protects = #{matterProtects},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
