<?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.models.mapper.BizSubModuleMapper">
    
    <resultMap type="BizSubModule" id="BizSubModuleResult">
        <result property="subId" column="sub_id" />
        <result property="moduleId" column="module_id" />
        <result property="subName" column="sub_name" />
        <result property="status" column="status" />
        <result property="description" column="description" />
        <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" />
    </resultMap>

    <sql id="selectBizSubModuleVo">
        select sub_id, module_id, sub_name, status, description, del_flag, create_by, create_time, update_by, update_time
        from biz_sub_module
    </sql>

    <select id="selectBizSubModuleBySubId" parameterType="Long" resultMap="BizSubModuleResult">
        <include refid="selectBizSubModuleVo"/>
        where sub_id = #{subId}
    </select>

    <select id="selectBizSubModuleList" parameterType="BizSubModule" resultMap="BizSubModuleResult">
        <include refid="selectBizSubModuleVo"/>
        <where>
            <if test="moduleId != null"> and module_id = #{moduleId}</if>
            <if test="subName != null and subName != ''"> and sub_name like concat('%', #{subName}, '%')</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
            and del_flag = '0'
        </where>
        order by create_time desc
    </select>

    <select id="selectByModuleId" parameterType="Long" resultMap="BizSubModuleResult">
        <include refid="selectBizSubModuleVo"/>
        <where>
            <if test="_parameter != null"> and module_id = #{_parameter}</if>
            and del_flag = '0'
        </where>
        order by create_time asc
    </select>

    <insert id="insertBizSubModule" parameterType="BizSubModule" useGeneratedKeys="true" keyProperty="subId">
        insert into biz_sub_module
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="moduleId != null">module_id,</if>
            <if test="subName != null">sub_name,</if>
            <if test="status != null">status,</if>
            <if test="description != null">description,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="moduleId != null">#{moduleId},</if>
            <if test="subName != null">#{subName},</if>
            <if test="status != null">#{status},</if>
            <if test="description != null">#{description},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateBizSubModule" parameterType="BizSubModule">
        update biz_sub_module
        <trim prefix="SET" suffixOverrides=",">
            <if test="moduleId != null">module_id = #{moduleId},</if>
            <if test="subName != null">sub_name = #{subName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="description != null">description = #{description},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where sub_id = #{subId}
    </update>

    <delete id="deleteBizSubModuleBySubId" parameterType="Long">
        update biz_sub_module set del_flag = '2' where sub_id = #{subId}
    </delete>

    <delete id="deleteBizSubModuleBySubIds" parameterType="String">
        update biz_sub_module set del_flag = '2' where sub_id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>


