<?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.ho.business.mapper.StationNoteAndRepairMapper">
    <insert id="addStationNote" keyProperty="id" keyColumn="id" useGeneratedKeys="true" parameterType="com.ho.business.entity.StationNotepad">
        insert into station_notepad (title,content,create_user,create_user_name,create_time,station)
        values (#{record.title},#{record.content},#{record.createUser},#{record.createUserName},#{record.createTime},#{record.station})
    </insert>

    <delete id="deleteStationNote">
        delete from station_notepad where id = #{id}
    </delete>

    <update id="updateStationNote" parameterType="com.ho.business.entity.StationNotepad">
        update station_notepad set title = #{record.title},content = #{record.content},update_user = #{record.updateUser},update_user_name=#{record.updateUserName},
                                   update_time = #{record.updateTime} where id = #{record.id}
    </update>

    <select id="selectStationNote" resultType="com.ho.business.entity.StationNotepad">
         select * from station_notepad where station = #{record.station}
            <if test="record.title != null and record.title !=''">
                and title like concat('%',#{record.title},'%')
            </if>
            <if test="record.startTime != null and record.startTime != ''">
                and create_time &gt;= #{record.startTime}
            </if>
            <if test="record.endTime != null and record.endTime != ''">
                and create_time &lt;= #{record.endTime}
            </if>
        order by create_time desc
    </select>

    <insert id="addStationRepair" keyColumn="id" keyProperty="id" useGeneratedKeys="true" parameterType="com.ho.business.entity.StationRepair">
        insert into station_repair (repair_user,repair_user_name,repair_content,repair_position,create_time,repair_time,remark,station
        ) values(#{record.repairUser},#{record.repairUserName},#{record.repairContent},#{record.repairPosition},
                 #{record.createTime},#{record.repairTime},#{record.remark},#{record.station})
    </insert>

    <update id="updateRepairFile" >
        update repair_file set repair_id = #{repairId} where id in (
            <foreach collection="repairFileList" separator="," item="item">
                #{item.id}
            </foreach>
            )
    </update>

    <update id="updateFileRepairNull">
        update repair_file set repair_id = null where repair_id =#{repairId}
    </update>

    <insert id="addRepairFile" parameterType="com.ho.business.entity.RepairFile" keyProperty="id" keyColumn="id" useGeneratedKeys="true">
        insert into repair_file (repair_id,file_name,url) values
        (#{record.repairId},#{record.fileName},#{record.url})
    </insert>

    <delete id="deleteStationRepair">
        delete from station_repair where id = #{id}
    </delete>

    <delete id="deleteRepairInfo">
        delete from repair_file where repair_id =#{id}
    </delete>

    <update id="updateStationRepair" parameterType="com.ho.business.vo.req.StationRepairReqVo">
        update station_repair set repair_content = #{record.repairContent},repair_position =#{record.repairPosition},
                                  remark = #{record.remark},repair_time =#{record.repairTime} where id =#{record.id}
    </update>

    <select id="selectStationRepair" resultType="com.ho.business.entity.StationRepair">
        select * from station_repair where station = #{record.station}
            <if test="record.repairUserName != null and record.repairUserName !=''">
                and repair_user_name like concat('%',#{record.repairUserName},'%')
            </if>
            <if test="record.repairPosition != null and record.repairPosition !=''">
                and repair_position like concat('%',#{record.repairPosition},'%')
            </if>
            <if test="record.startTime != null and record.startTime != ''">
                and repair_time &gt;= #{record.startTime}
            </if>
            <if test="record.endTime != null and record.endTime != ''">
                and repair_time &lt;= #{record.endTime}
            </if>
    </select>

    <select id="selectRepairFile" resultType="com.ho.business.entity.RepairFile">
        select * from repair_file where repair_id = #{id}
    </select>
</mapper>
