<?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.production.mapper.TSaiCategoryMapper">
    
    <resultMap type="TSaiCategory" id="TSaiCategoryResult">
        <result property="saiCategoryId"    column="sai_category_id"    />
        <result property="saiCategoryName"    column="sai_category_name"    />
        <result property="delFlag"    column="del_flag"    />
        <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="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectTSaiCategoryVo">
        select d.sai_category_id, d.sai_category_name, d.del_flag, d.create_by, d.create_time, d.update_by, d.update_time, d.dept_id from t_sai_category d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTSaiCategoryList" parameterType="TSaiCategory" resultMap="TSaiCategoryResult">
        <include refid="selectTSaiCategoryVo"/>
        <where>  
            <if test="saiCategoryId != null "> and sai_category_id = #{saiCategoryId}</if>
            <if test="saiCategoryName != null  and saiCategoryName != ''"> and sai_category_name like concat(concat('%', #{saiCategoryName}), '%')</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        order by d.sai_category_name asc
    </select>
    
    <select id="selectTSaiCategoryById" parameterType="Long" resultMap="TSaiCategoryResult">
        <include refid="selectTSaiCategoryVo"/>
        where sai_category_id = #{saiCategoryId}
    </select>
        
    <insert id="insertTSaiCategory" parameterType="TSaiCategory">
        <selectKey keyProperty="saiCategoryId" resultType="long" order="BEFORE">
            SELECT seq_t_sai_category.NEXTVAL as saiCategoryId FROM DUAL
        </selectKey>
        insert into t_sai_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="saiCategoryId != null">sai_category_id,</if>
            <if test="saiCategoryName != null">sai_category_name,</if>
            <if test="delFlag != null">del_flag,</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="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="saiCategoryId != null">#{saiCategoryId},</if>
            <if test="saiCategoryName != null">#{saiCategoryName},</if>
            <if test="delFlag != null">#{delFlag},</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="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTSaiCategory" parameterType="TSaiCategory">
        update t_sai_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="saiCategoryName != null">sai_category_name = #{saiCategoryName},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where sai_category_id = #{saiCategoryId}
    </update>

    <update id="deleteTSaiCategoryById" parameterType="Long">
        update t_sai_category set del_flag = 2 where sai_category_id = #{saiCategoryId}
    </update>

    <update id="deleteTSaiCategoryByIds" parameterType="String">
        update t_sai_category set del_flag = 2 where sai_category_id in
        <foreach item="saiCategoryId" collection="array" open="(" separator="," close=")">
            #{saiCategoryId}
        </foreach>
    </update>
    
</mapper>