<?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.inspect.metadata.mqtt.mapper.HrMaintenanceMapper">
    <resultMap id="BaseResultMap" type="com.inspect.metadata.mqtt.domain.HrMaintenance">
        <id property="maintenanceId" column="maintenance_id"/>
        <result property="nestIds" column="nest_ids"/>
        <result property="droneIds" column="drone_ids"/>
        <result property="content" column="content"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMaintenanceVo">
        select maintenance_id,
               nest_ids,
               drone_ids,
               content,
               create_time,
               update_time
        from basedata_hr_maintenance
    </sql>

    <select id="selectMaintenanceList" parameterType="com.inspect.metadata.mqtt.domain.HrMaintenance"
            resultMap="BaseResultMap">
        <include refid="selectMaintenanceVo"/>
        <where>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                and date_format(create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                and date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectMaintenanceById" parameterType="Long" resultMap="BaseResultMap">
        <include refid="selectMaintenanceVo"/>
        where maintenance_id = #{maintenanceId}
    </select>

    <insert id="insertMaintenance" parameterType="com.inspect.metadata.mqtt.domain.HrMaintenance">
        insert into basedata_hr_maintenance (
        <if test="nestIds != null and nestIds != '' ">nest_ids,</if>
        <if test="droneIds != null and droneIds != '' ">drone_ids,</if>
        <if test="content != null and content != '' ">content,</if>
        create_time
        )values(
        <if test="nestIds != null and nestIds != '' ">#{nestIds},</if>
        <if test="droneIds != null and droneIds != '' ">#{droneIds},</if>
        <if test="content != null and content != '' ">#{content},</if>
        sysdate()
        )
    </insert>

    <update id="updateMaintenance" parameterType="com.inspect.metadata.mqtt.domain.HrMaintenance">
        update basedata_hr_maintenance
        <set>
            <if test="nestIds != null and nestIds != '' ">nest_ids = #{nestIds},</if>
            <if test="droneIds != null and droneIds != '' ">drone_ids = #{droneIds},</if>
            <if test="content != null and content != '' ">content = #{content},</if>
            update_time = sysdate()
        </set>
        where maintenance_id = #{maintenanceId}
    </update>

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