<?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.ruoyi.system.mapper.SysReportMapper">
    
    <resultMap type="SysReport" id="SysReportResult">
        <result property="id"    column="id"    />
        <result property="planId"    column="plan_id"    />
        <result property="lane"    column="lane"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="manageUser"    column="manage_user"    />
        <result property="managePhone"    column="manage_phone"    />
        <result property="saveUser"    column="save_user"    />
        <result property="savePhone"    column="save_phone"    />
        <result property="createUser"    column="create_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isMerge"    column="is_merge"    />
        <result property="section"    column="section"    />
        <result property="direction"    column="direction"    />
        <result property="startKm"    column="start_km"    />
        <result property="startHectometer"    column="start_hectometer"    />
        <result property="endKm"    column="end_km"    />
        <result property="endHectometer"    column="end_hectometer"    />
        <result property="contentOne"    column="content_one"    />
        <result property="contentTwo"    column="content_two"    />
        <result property="auditDept"    column="audit_dept"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectSysReportVo">
        select a.id, a.plan_id, a.lane, a.start_time, a.end_time, a.manage_user, a.manage_phone, a.save_user, a.save_phone,
               a.create_user, a.create_time, a.update_user, a.update_time, a.is_merge,a.status,a.audit_dept,b.section,b.direction,b.start_km,b.start_hectometer,
               b.end_km,b.end_hectometer,b.content_one,b.content_two
        from
        sys_report a left join sys_plan b on a.plan_id = b.id
    </sql>

    <select id="selectSysReportList" parameterType="SysReport" resultMap="SysReportResult">
        <include refid="selectSysReportVo"/>
        <where>  
            <if test="planId != null "> and plan_id = #{planId}</if>
            <if test="lane != null  and lane != ''"> and lane = #{lane}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="manageUser != null  and manageUser != ''"> and manage_user = #{manageUser}</if>
            <if test="managePhone != null  and managePhone != ''"> and manage_phone = #{managePhone}</if>
            <if test="saveUser != null  and saveUser != ''"> and save_user = #{saveUser}</if>
            <if test="savePhone != null  and savePhone != ''"> and save_phone = #{savePhone}</if>
            <if test="createUser != null  and createUser != ''"> and create_user = #{createUser}</if>
            <if test="updateUser != null  and updateUser != ''"> and update_user = #{updateUser}</if>
            <if test="isMerge != null  and isMerge != ''"> and is_merge = #{isMerge}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectSysReportById" parameterType="Long" resultMap="SysReportResult">
        <include refid="selectSysReportVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSysReport" parameterType="SysReport" useGeneratedKeys="true" keyProperty="id">
        insert into sys_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planId != null">plan_id,</if>
            <if test="lane != null">lane,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="manageUser != null">manage_user,</if>
            <if test="managePhone != null">manage_phone,</if>
            <if test="saveUser != null">save_user,</if>
            <if test="savePhone != null">save_phone,</if>
            <if test="createUser != null">create_user,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateUser != null">update_user,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isMerge != null">is_merge,</if>
            <if test="status != null">status,</if>
            <if test="auditDept != null">#{audit_dept},</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="planId != null">#{planId},</if>
            <if test="lane != null">#{lane},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="manageUser != null">#{manageUser},</if>
            <if test="managePhone != null">#{managePhone},</if>
            <if test="saveUser != null">#{saveUser},</if>
            <if test="savePhone != null">#{savePhone},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isMerge != null">#{isMerge},</if>
            <if test="status != null">#{status},</if>
            <if test="auditDept != null">#{auditDept},</if>
         </trim>
    </insert>

    <update id="updateSysReport" parameterType="SysReport">
        update sys_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="lane != null">lane = #{lane},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="manageUser != null">manage_user = #{manageUser},</if>
            <if test="managePhone != null">manage_phone = #{managePhone},</if>
            <if test="saveUser != null">save_user = #{saveUser},</if>
            <if test="savePhone != null">save_phone = #{savePhone},</if>
            <if test="createUser != null">create_user = #{createUser},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateUser != null">update_user = #{updateUser},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isMerge != null">is_merge = #{isMerge},</if>
            <if test="status != null">status = #{status},</if>
            <if test="auditDept != null">audit_dept = #{auditDept},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysReportById" parameterType="Long">
        delete from sys_report where id = #{id}
    </delete>

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

<!--    <select id="selectSysReportById" parameterType="Long" resultMap="SysReportResult">-->
<!--        SELECT-->
<!--        *-->
<!--        FROM-->
<!--        v_report_plan-->
<!--        WHERE-->
<!--        `status` = 2-->
<!--        AND section = #{section}-->
<!--        AND direction = #{direction}-->
<!--        AND ( start_km * 1000+start_hectometer > #{endKm}*1000+#{endHectometer} OR end_km * 1000+end_hectometer &lt; #{startKm}*1000+#{startHectometer})-->
<!--        AND ( UNIX_TIMESTAMP( start_time ) &lt; end_time - 3600 OR UNIX_TIMESTAMP( end_time ) &lt; start_time + 3600 )-->
<!--    </select>-->

</mapper>