<?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.montdata.mapper.BasedataMontPatDevAlmAbnMapper">

    <resultMap type="BasedataMontPatDevAlmAbn" id="BasedataMontPatDevAlmAbnResult">
        <result property="abnId" column="abn_id"/>
        <result property="eqpBookId" column="eqp_book_id"/>
        <result property="patrolDeviceCode" column="patrol_device_code"/>
        <result property="patrolDeviceName" column="patrol_device_name"/>
        <result property="time" column="time"/>
        <!--FUNC J.6.8-->
        <result property="type" column="type"/>
        <result property="typeName" column="type_name"/>
        <result property="value" column="value"/>
        <result property="valueName" column="value_name"/>
        <result property="valueUnit" column="value_unit"/>
        <result property="unit" column="unit"/>

        <result property="content" column="content"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteFlag" column="delete_flag"/>
    </resultMap>

    <sql id="selectBasedataMontPatDevAlmAbnVo">
        SELECT abn_id,
               eqp_book_id,
               patrol_device_code,
               patrol_device_name, time, '设备异常' type, '' type_name, '' `value`, '' value_name, '' value_unit, '' unit, content, create_by, create_time, update_by, update_time, delete_flag
        FROM
            basedata_mont_patdevalmabn
    </sql>

    <select id="selectBasedataMontPatDevAlmAbnList" parameterType="BasedataMontPatDevAlmAbn"
            resultMap="BasedataMontPatDevAlmAbnResult">
        <include refid="selectBasedataMontPatDevAlmAbnVo"/>
        <where>
            <if test="eqpBookId != null ">and eqp_book_id = #{eqpBookId}</if>
            <if test="patrolDeviceCode != null  and patrolDeviceCode != ''">and patrol_device_code =
                #{patrolDeviceCode}
            </if>
            <if test="patrolDeviceName != null  and patrolDeviceName != ''">and patrol_device_name like concat('%',
                #{patrolDeviceName}, '%')
            </if>
            <if test="time != null  and time != ''">and DATE_FORMAT(time,'%Y-%m-%d') = #{time}</if>
            <if test="content != null  and content != ''">and content = #{content}</if>
            <if test="deleteFlag != null  and deleteFlag != ''">and delete_flag = #{deleteFlag}</if>
        </where>
    </select>

    <select id="selectBasedataMontPatDevAlmAbnByMontPatDevAlmAbnId" parameterType="Long"
            resultMap="BasedataMontPatDevAlmAbnResult">
        <include refid="selectBasedataMontPatDevAlmAbnVo"/>
        where abn_id = #{abnId}
    </select>

    <insert id="insertBasedataMontPatDevAlmAbn" parameterType="BasedataMontPatDevAlmAbn" useGeneratedKeys="true"
            keyProperty="abnId">
        insert into basedata_mont_patdevalmabn
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="eqpBookId != null ">eqp_book_id,</if>
            <if test="patrolDeviceCode != null">patrol_device_code,</if>
            <if test="patrolDeviceName != null">patrol_device_name,</if>
            <if test="time != null">time,</if>
            <if test="content != null">content,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleteFlag != null">delete_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="eqpBookId != null ">#{eqpBookId},</if>
            <if test="patrolDeviceCode != null">#{patrolDeviceCode},</if>
            <if test="patrolDeviceName != null">#{patrolDeviceName},</if>
            <if test="time != null">#{time},</if>
            <if test="content != null">#{content},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleteFlag != null">#{deleteFlag},</if>
        </trim>
    </insert>

    <update id="updateBasedataMontPatDevAlmAbn" parameterType="BasedataMontPatDevAlmAbn">
        update basedata_mont_patdevalmabn
        <trim prefix="SET" suffixOverrides=",">
            <if test="eqpBookId != null ">eqp_book_id = #{eqpBookId},</if>
            <if test="patrolDeviceCode != null">patrol_device_code = #{patrolDeviceCode},</if>
            <if test="patrolDeviceName != null">patrol_device_name = #{patrolDeviceName},</if>
            <if test="time != null">time = #{time},</if>
            <if test="content != null">content = #{content},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleteFlag != null">delete_flag = #{deleteFlag},</if>
        </trim>
        where abn_id = #{abnId}
    </update>

    <delete id="deleteBasedataMontPatDevAlmAbnByMontPatDevAlmAbnId" parameterType="Long">
        delete
        from basedata_mont_patdevalmabn
        where abn_id = #{abnId}
    </delete>

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