<?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.XjInspectionRecordsMapper">

    <resultMap type="com.fastbee.xunjian.domain.XjInspectionRecords" id="XjInspectionRecordsResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="inspectionTaskId"    column="inspection_task_id"    />
        <result property="inspectionPlanId"    column="inspection_plan_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="inspectionPersonnelId"    column="inspection_personnel_id"    />
        <result property="inspectionRouteId"    column="inspection_route_id"    />
        <result property="recordStatus"    column="record_status"    />
        <result property="abnormalStatus" column="abnormal_status"/>
        <result property="latAndLong" column="lat_and_long"/>
        <result property="picture" column="picture"/>
        <result property="remarks" column="remarks"/>
        <result property="quyuma" column="quyuma"/>
        <result property="projectId" column="project_id"/>
        <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="groupId" column="group_id"/>
    </resultMap>
    <sql id="selectXjInspectionRecordsVo">
        select *
        from xj_inspection_records
    </sql>

    <select id="selectXjInspectionRecordsList"
            parameterType="com.fastbee.xunjian.domain.XjInspectionRecords"
            resultMap="XjInspectionRecordsResult">
        <include refid="selectXjInspectionRecordsVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="inspectionTaskId != null ">and inspection_task_id = #{inspectionTaskId}</if>
            <if test="inspectionPlanId != null ">and inspection_plan_id = #{inspectionPlanId}</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="inspectionPersonnelId != null ">and inspection_personnel_id = #{inspectionPersonnelId}</if>
            <if test="inspectionRouteId != null ">and inspection_route_id = #{inspectionRouteId}</if>
            <if test="recordStatus != null  and recordStatus != ''">and record_status = #{recordStatus}</if>
            <if test="abnormalStatus != null  and abnormalStatus != ''">and abnormal_status = #{abnormalStatus}</if>
            <if test="latAndLong != null  and latAndLong != ''">and lat_and_long = #{latAndLong}</if>
            <if test="picture != null  and picture != ''">and picture = #{picture}</if>
            <if test="remarks != null  and remarks != ''">and remarks = #{remarks}</if>
            <if test="quyuma != null  and quyuma != ''">and quyuma = #{quyuma}</if>
            <if test="projectId != null ">and project_id = #{projectId}</if>
            <if test="groupId != null ">and group_id = #{groupId}</if>
            <if test="params != null and params.tasksIds != null and params.tasksIds.size>0">
                and inspection_task_id in
                <foreach collection="params.tasksIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(end_time ,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(end_time ,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
            <if test="chaxunBeginTime != null and chaxunBeginTime != ''"><!-- 开始时间检索 -->
                AND date_format(end_time ,'%y%m%d%H%i%s') &gt;= date_format(#{chaxunBeginTime},'%y%m%d%H%i%s')
            </if>
            <if test="chaxunEndTime != null and chaxunEndTime != ''"><!-- 结束时间检索 -->
                AND date_format(end_time ,'%y%m%d%H%i%s') &lt;= date_format(#{chaxunEndTime},'%y%m%d%H%i%s')
            </if>
        </where>
        order by id desc
    </select>


    <select id="selectXjInspectionRecordsById" parameterType="Long" resultMap="XjInspectionRecordsResult">
        <include refid="selectXjInspectionRecordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertXjInspectionRecords" parameterType="com.fastbee.xunjian.domain.XjInspectionRecords"
            useGeneratedKeys="true" keyProperty="id">
        insert into xj_inspection_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="inspectionTaskId != null">inspection_task_id,</if>
            <if test="inspectionPlanId != null">inspection_plan_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="inspectionPersonnelId != null">inspection_personnel_id,</if>
            <if test="inspectionRouteId != null">inspection_route_id,</if>
            <if test="recordStatus != null">record_status,</if>
            <if test="abnormalStatus != null">abnormal_status,</if>
            <if test="latAndLong != null">lat_and_long,</if>
            <if test="picture != null">picture,</if>
            <if test="remarks != null">remarks,</if>
            <if test="quyuma != null">quyuma,</if>
            <if test="projectId != null">project_id,</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="groupId != null">group_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="inspectionTaskId != null">#{inspectionTaskId},</if>
            <if test="inspectionPlanId != null">#{inspectionPlanId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="inspectionPersonnelId != null">#{inspectionPersonnelId},</if>
            <if test="inspectionRouteId != null">#{inspectionRouteId},</if>
            <if test="recordStatus != null">#{recordStatus},</if>
            <if test="abnormalStatus != null">#{abnormalStatus},</if>
            <if test="latAndLong != null">#{latAndLong},</if>
            <if test="picture != null">#{picture},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="quyuma != null">#{quyuma},</if>
            <if test="projectId != null">#{projectId},</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="groupId != null">#{groupId},</if>

        </trim>
    </insert>

    <update id="updateXjInspectionRecords" parameterType="com.fastbee.xunjian.domain.XjInspectionRecords">
        update xj_inspection_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="inspectionTaskId != null">inspection_task_id = #{inspectionTaskId},</if>
            <if test="inspectionPlanId != null">inspection_plan_id = #{inspectionPlanId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="inspectionPersonnelId != null">inspection_personnel_id = #{inspectionPersonnelId},</if>
            <if test="inspectionRouteId != null">inspection_route_id = #{inspectionRouteId},</if>
            <if test="recordStatus != null">record_status = #{recordStatus},</if>
            <if test="abnormalStatus != null">abnormal_status = #{abnormalStatus},</if>
            <if test="latAndLong != null">lat_and_long = #{latAndLong},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="quyuma != null">quyuma = #{quyuma},</if>
            <if test="projectId != null">project_id = #{projectId},</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="groupId != null">group_id = #{groupId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteXjInspectionRecordsById" parameterType="Long">
        delete from xj_inspection_records where id = #{id}
    </delete>

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


</mapper>
