<?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.system.dao.RegularDao">

    <resultMap type="Regular" id="RegularResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="regular"    column="regular"    />
        <result property="validation"    column="validation"    />
        <result property="enable"    column="enable"    />
        <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="selectRegularVo">
        select id, name, regular, validation, enable, create_by, create_time, update_by, update_time from sys_regular
    </sql>

    <select id="selectRegularList" parameterType="Regular" resultMap="RegularResult">
        <include refid="selectRegularVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="regular != null  and regular != ''"> and regular like concat('%', #{regular}, '%')</if>
            <if test="validation != null  and validation != ''"> and validation like concat('%', #{validation}, '%')</if>
            <if test="enable != null "> and enable = #{enable}</if>
        </where>
    </select>

    <select id="selectRegularById" parameterType="Long" resultMap="RegularResult">
        <include refid="selectRegularVo"/>
        where id = #{id}
    </select>

    <insert id="insertRegular" parameterType="Regular" useGeneratedKeys="true" keyProperty="id">
        insert into sys_regular
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="regular != null and regular != ''">regular,</if>
            <if test="validation != null">validation,</if>
            <if test="enable != null">enable,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="regular != null and regular != ''">#{regular},</if>
            <if test="validation != null">#{validation},</if>
            <if test="enable != null">#{enable},</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>
        </trim>
    </insert>

    <update id="updateRegular" parameterType="Regular">
        update sys_regular
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="regular != null and regular != ''">regular = #{regular},</if>
            <if test="validation != null">validation = #{validation},</if>
            <if test="enable != null">enable = #{enable},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRegularById" parameterType="Long">
        delete from sys_regular where id = #{id}
    </delete>

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

</mapper>