<?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.dcsoft.system.mapper.SysPointMapper">

    <resultMap type="SysPoint" id="SysPointResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="spaceId"    column="space_id"    />
        <result property="remark"    column="remark"    />
        <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="sort"    column="sort"    />
        <association property="space"    column="space_id" javaType="SysSpace" resultMap="spaceResult" />

    </resultMap>

    <resultMap id="spaceResult" type="SysSpace">
        <id     property="id"    column="space_id"     />
        <result property="name"  column="spaceName"   />
    </resultMap>

    <sql id="selectSysPointVo">
        select p.id, p.name, p.space_id, p.remark, p.create_by, p.create_time, p.update_by, p.update_time,s.name spaceName,p.sort
        from sys_point p
        left join sys_space s on s.id=p.space_id
    </sql>

    <select id="selectSysPointList" parameterType="SysPoint" resultMap="SysPointResult">
        <include refid="selectSysPointVo"/>
        <where>
            <if test="name != null  and name != ''"> and p.name like concat('%', #{name}, '%')</if>
            <if test="spaceId != null "> and p.space_id = #{spaceId}</if>
        </where>
        order by p.sort
    </select>

    <select id="selectSysPointById" parameterType="Long" resultMap="SysPointResult">
        <include refid="selectSysPointVo"/>
        where p.id = #{id}
    </select>


    <insert id="insertSysPoint" parameterType="SysPoint">
        insert into sys_point
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="spaceId != null">space_id,</if>
            <if test="remark != null">remark,</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="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="spaceId != null">#{spaceId},</if>
            <if test="remark != null">#{remark},</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="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateSysPoint" parameterType="SysPoint">
        update sys_point
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="spaceId != null">space_id = #{spaceId},</if>
            <if test="remark != null">remark = #{remark},</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="sort != null">sort = #{sort},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysPointById" parameterType="Long">
        delete from sys_point where id = #{id}
    </delete>

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