<?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.fastbee.xunjian.mapper.XjInspectionRoutesMapper">

    <resultMap type="com.fastbee.xunjian.domain.XjInspectionRoutes" id="XjInspectionRoutesResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="dotLineType" column="dot_line_type"/>
        <result property="engineeringObjectType" column="engineering_object_type"/>
        <result property="engineeringObjectId" column="engineering_object_id"/>
        <result property="projectId" column="project_id"/>
        <result property="latAndLong" column="lat_and_long"/>
        <result property="position" column="position"/>
        <result property="range" column="range"/>
        <result property="rangeArea" column="range_area"/>
        <result property="qrCodeId" column="qr_code_id"/>
        <result property="inspectionNoteIds" column="inspection_note_ids"/>
        <result property="quyuma" column="quyuma"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="qrCodeSn" column="qr_code_sn"/>
    </resultMap>
    <sql id="selectXjInspectionRoutesVo">
        select *
        from xj_inspection_routes 
    </sql>

    <select id="selectXjInspectionRoutesList" 
            parameterType="com.fastbee.xunjian.domain.XjInspectionRoutes"
            resultMap="XjInspectionRoutesResult">
        <include refid="selectXjInspectionRoutesVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="dotLineType != null  and dotLineType != ''">and dot_line_type = #{dotLineType}</if>
            <if test="engineeringObjectType != null  and engineeringObjectType != ''">and engineering_object_type =
                #{engineeringObjectType}
            </if>
            <if test="engineeringObjectId != null ">and engineering_object_id = #{engineeringObjectId}</if>
            <if test="projectId != null ">and project_id = #{projectId}</if>
            <if test="latAndLong != null  and latAndLong != ''">and lat_and_long = #{latAndLong}</if>
            <if test="position != null  and position != ''">and position = #{position}</if>
            <if test="range != null  and range != ''">and range = #{range}</if>
            <if test="rangeArea != null  and rangeArea != ''">and range_area = #{rangeArea}</if>
            <if test="qrCodeId != null ">and qr_code_id = #{qrCodeId}</if>
            <if test="quyuma != null  and quyuma != ''">and quyuma = #{quyuma}</if>
            <if test="qrCodeSn != null  and qrCodeSn != ''">and qr_code_sn = #{qrCodeSn}</if>
            <if test="params != null and params.ids!= null and params.ids!= ''">
                AND id in
                <foreach item="id" collection="params.ids.split(',')" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
        order by id desc
    </select>

    <select id="selectXjInspectionRoutesById" parameterType="Long" resultMap="XjInspectionRoutesResult">
        <include refid="selectXjInspectionRoutesVo"/>
        where id = #{id}
    </select>
    <select id="selectXjInspectionRoutesByName"
            resultType="string" resultMap="XjInspectionRoutesResult">
        <include refid="selectXjInspectionRoutesVo"/>
        where name = #{name} limit 1
    </select>
    <select id="selectXjInspectionRoutesByQrSn"
            parameterType="string" resultMap="XjInspectionRoutesResult">
        <include refid="selectXjInspectionRoutesVo"/>
        WHERE kqc.code_sn = #{qrSn} limit 1
    </select>


    <insert id="insertXjInspectionRoutes" parameterType="com.fastbee.xunjian.domain.XjInspectionRoutes"
            useGeneratedKeys="true" keyProperty="id">
        insert into xj_inspection_routes
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="qrCodeSn != null">qr_code_sn,</if>
            <if test="dotLineType != null">dot_line_type,</if>
            <if test="engineeringObjectType != null">engineering_object_type,</if>
            <if test="engineeringObjectId != null">engineering_object_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="latAndLong != null">lat_and_long,</if>
            <if test="position != null">position,</if>
            <if test="range != null">`range`,</if>
            <if test="rangeArea != null">range_area,</if>
            <if test="qrCodeId != null">qr_code_id,</if>
            <if test="quyuma != null">quyuma,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="inspectionNoteIds != null">inspection_note_ids,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="qrCodeSn != null">#{qrCodeSn},</if>
            <if test="dotLineType != null">#{dotLineType},</if>
            <if test="engineeringObjectType != null">#{engineeringObjectType},</if>
            <if test="engineeringObjectId != null">#{engineeringObjectId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="latAndLong != null">#{latAndLong},</if>
            <if test="position != null">#{position},</if>
            <if test="range != null">#{range},</if>
            <if test="rangeArea != null">#{rangeArea},</if>
            <if test="qrCodeId != null">#{qrCodeId},</if>
            <if test="quyuma != null">#{quyuma},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="inspectionNoteIds != null">#{inspectionNoteIds},</if>
        </trim>
    </insert>
    <update id="updateXjInspectionRoutes" parameterType="com.fastbee.xunjian.domain.XjInspectionRoutes">
        update xj_inspection_routes
        <trim prefix="SET" suffixOverrides=",">
            <if test="inspectionNoteIds != null">inspection_note_ids = #{inspectionNoteIds},</if>
            <if test="name != null">name = #{name},</if>
            <if test="dotLineType != null">dot_line_type = #{dotLineType},</if>
            <if test="engineeringObjectType != null">engineering_object_type = #{engineeringObjectType},</if>
            <if test="engineeringObjectId != null">engineering_object_id = #{engineeringObjectId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="latAndLong != null">lat_and_long = #{latAndLong},</if>
            <if test="position != null">position = #{position},</if>
            <if test="range != null">`range` = #{range},</if>
            <if test="rangeArea != null">range_area = #{rangeArea},</if>
            <if test="qrCodeId != null">qr_code_id = #{qrCodeId},</if>
            <if test="quyuma != null">quyuma = #{quyuma},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="qrCodeSn != null">qr_code_sn = #{qrCodeSn},</if>
        </trim>
        where id = #{id}
    </update>
    <delete id="deleteXjInspectionRoutesById" parameterType="Long">
        delete
        from xj_inspection_routes
        where id = #{id}
    </delete>

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