<?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.hchyun.generator.dao.ModuleDao">
    
    <resultMap type="Module" id="ModuleResult">
        <result property="id"    column="id"    />
        <result property="mName"    column="m_name"    />
        <result property="mDescribe"    column="m_describe"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectModuleVo">
        select id, m_name, m_describe, remark, create_time, create_by, update_time, update_by from sys_module
    </sql>

    <select id="selectModuleList" parameterType="Module" resultMap="ModuleResult">
        <include refid="selectModuleVo"/>
        <where>  
            <if test="mName != null  and mName != ''"> and m_name like concat('%', #{mName}, '%')</if>
            <if test="mDescribe != null  and mDescribe != ''"> and m_describe like concat('%', #{mDescribe}, '%')</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
    </select>
    
    <select id="selectModuleById" parameterType="Long" resultMap="ModuleResult">
        <include refid="selectModuleVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertModule" parameterType="Module" useGeneratedKeys="true" keyProperty="id">
        insert into sys_module
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mName != null and mName != ''">m_name,</if>
            <if test="mDescribe != null and mDescribe != ''">m_describe,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mName != null and mName != ''">#{mName},</if>
            <if test="mDescribe != null and mDescribe != ''">#{mDescribe},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateModule" parameterType="Module">
        update sys_module
        <trim prefix="SET" suffixOverrides=",">
            <if test="mName != null and mName != ''">m_name = #{mName},</if>
            <if test="mDescribe != null and mDescribe != ''">m_describe = #{mDescribe},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteModuleById" parameterType="Long">
        delete from sys_module where id = #{id}
    </delete>

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