<?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.api.manage.dao.butlerService.SysInspectionPointDao">
    <select id="list" parameterType="com.api.model.butlerService.SearchInspectionPoint" resultType="com.api.vo.butlerService.VoInspectionPoint">
        select id,code,name,type,create_date from sys_inspection_point
        <where>
            <if test="code != null and code != ''">
                and code like concat('%',#{code},'%')
            </if>
            <if test="name != null and name != ''">
                and name like concat('%',#{name},'%')
            </if>
            and is_delete = 1
        </where>
        order by create_date desc
    </select>

    <insert id="insert" parameterType="com.api.model.butlerService.SysInspectionPoint">
        insert into sys_inspection_point(
            code,
            name,
            type,
            <if test="longitude != null">
                longitude,
            </if>
            <if test="latitude != null">
                latitude,
            </if>
            create_id,
            create_date,
            is_delete
        )values (
            #{code},
            #{name},
            #{type},
            <if test="longitude != null">
                #{longitude},
            </if>
            <if test="latitude != null">
                #{latitude},
            </if>
            #{createId},
            #{createDate},
            #{isDelete}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <insert id="insertCheckItems" parameterType="com.api.model.butlerService.SysInspectionCheckItems">
        insert into sys_inspection_check_items(
            inspection_point_id,
            name
        )values (
            #{inspectionPointId},
            #{name}
        )
    </insert>

    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.vo.butlerService.VoFBIInspectionPoint">
        select id,code,name,type,longitude,latitude from sys_inspection_point where id = #{id} and is_delete = 1
    </select>

    <select id="findByIdCheckItems" parameterType="java.lang.Integer" resultType="com.api.vo.butlerService.VoFBIInspectionCheckItems">
        select id,name from sys_inspection_check_items where inspection_point_id = #{id}
    </select>

    <update id="update" parameterType="com.api.model.butlerService.SysInspectionPoint">
        update sys_inspection_point
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="longitude != null">
                longitude = #{longitude},
            </if>
            <if test="latitude != null">
                latitude = #{latitude},
            </if>
            modify_id = #{modifyId},
            modify_date = #{modifyDate}
        </set>
        where id = #{id}
    </update>

    <delete id="deleteCheckItems" parameterType="java.lang.Integer">
        delete from sys_inspection_check_items where inspection_point_id = #{id}
    </delete>

    <update id="falseDelete" parameterType="java.lang.Integer">
        update sys_inspection_point set is_delete = 0 where id = #{id}
    </update>
</mapper>