<?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.generator.mapper.SysModuleMapper">
    
    <resultMap type="SysModule" id="SysModuleResult">
        <result property="moduleId"    column="module_id"    />
        <result property="moduleName"    column="module_name"    />
        <result property="moduleAlias"    column="module_alias"    />
        <result property="moduleDesc"    column="module_desc"    />
        <result property="status"    column="status"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysModuleVo">
        select module_id, module_name, module_alias, module_desc, status, del_flag, create_by, create_time, update_by, update_time, remark from sys_module
    </sql>

    <select id="selectSysModuleList" parameterType="SysModule" resultMap="SysModuleResult">
        <include refid="selectSysModuleVo"/>
        <where>  
            <if test="moduleName != null  and moduleName != ''"> and module_name like concat('%', #{moduleName}, '%')</if>
            <if test="moduleAlias != null  and moduleAlias != ''"> and module_alias = #{moduleAlias}</if>
            <if test="moduleDesc != null  and moduleDesc != ''"> and module_desc = #{moduleDesc}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectSysModuleByModuleId" parameterType="Long" resultMap="SysModuleResult">
        <include refid="selectSysModuleVo"/>
        where module_id = #{moduleId}
    </select>

    <insert id="insertSysModule" parameterType="SysModule" useGeneratedKeys="true" keyProperty="moduleId">
        insert into sys_module
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="moduleName != null and moduleName != ''">module_name,</if>
            <if test="moduleAlias != null">module_alias,</if>
            <if test="moduleDesc != null">module_desc,</if>
            <if test="status != null">status,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="moduleName != null and moduleName != ''">#{moduleName},</if>
            <if test="moduleAlias != null">#{moduleAlias},</if>
            <if test="moduleDesc != null">#{moduleDesc},</if>
            <if test="status != null">#{status},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysModule" parameterType="SysModule">
        update sys_module
        <trim prefix="SET" suffixOverrides=",">
            <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
            <if test="moduleAlias != null">module_alias = #{moduleAlias},</if>
            <if test="moduleDesc != null">module_desc = #{moduleDesc},</if>
            <if test="status != null">status = #{status},</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="remark != null">remark = #{remark},</if>
        </trim>
        where module_id = #{moduleId}
    </update>

    <delete id="deleteSysModuleByModuleId" parameterType="Long">
        delete from sys_module where module_id = #{moduleId}
    </delete>

    <delete id="deleteSysModuleByModuleIds" parameterType="String">
        delete from sys_module where module_id in 
        <foreach item="moduleId" collection="array" open="(" separator="," close=")">
            #{moduleId}
        </foreach>
    </delete>
</mapper>