<?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.xunmei.system.mapper.ISysAreaMapper">

    <resultMap type="com.xunmei.system.api.domain.SysArea" id="SysAreaResult">
                <result property="id" column="id"/>
                <result property="name" column="name"/>
                <result property="createTime" column="create_time"/>
                <result property="updateBy" column="update_by"/>
                <result property="updateTime" column="update_time"/>
                <result property="updateId" column="update_id"/>
                <result property="delFlag" column="del_flag"/>
                <result property="orgType" column="org_type"/>
    </resultMap>

    <sql id="selectSysAreaVo">
        select id, name, create_time, update_by, update_time, update_id, del_flag, org_type
        from sys_area
    </sql>

    <select id="selectSysAreaList" parameterType="com.xunmei.system.api.domain.SysArea"
            resultMap="SysAreaResult">
        <include refid="selectSysAreaVo"/>
        <where>
                        <if test="name != null  and name != ''">
                            and name like concat('%', #{name}, '%')
                        </if>
                        <if test="updateId != null ">
                            and update_id = #{updateId}
                        </if>
                        <if test="orgType != null ">
                            and org_type = #{orgType}
                        </if>
        </where>
    </select>

    <select id="selectSysAreaById" parameterType="Long"
            resultMap="SysAreaResult">
            <include refid="selectSysAreaVo"/>
            where id = #{id}
    </select>

    <insert id="insertSysArea" parameterType="com.xunmei.system.api.domain.SysArea"            useGeneratedKeys="true" keyProperty="id">
        insert into sys_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="name != null">name,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
                    <if test="updateId != null">update_id,
                    </if>
                    <if test="delFlag != null">del_flag,
                    </if>
                    <if test="orgType != null">org_type,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="name != null">#{name},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
                    <if test="updateId != null">#{updateId},
                    </if>
                    <if test="delFlag != null">#{delFlag},
                    </if>
                    <if test="orgType != null">#{orgType},
                    </if>
        </trim>
    </insert>

    <update id="updateSysArea" parameterType="com.xunmei.system.api.domain.SysArea">
        update sys_area
        <trim prefix="SET" suffixOverrides=",">
                    <if test="name != null">name =
                        #{name},
                    </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="updateId != null">update_id =
                        #{updateId},
                    </if>
                    <if test="delFlag != null">del_flag =
                        #{delFlag},
                    </if>
                    <if test="orgType != null">org_type =
                        #{orgType},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysAreaById" parameterType="Long">
        delete
        from sys_area where id = #{id}
    </delete>

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