<?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.threshold.mapper.BasedataThresholdModificationMapper">

    <resultMap type="BasedataThresholdModification" id="BasedataThresholdModificationResult">
        <result property="lineId" column="line_id"/>
        <result property="patrolPointId" column="patrol_point_id"/>
        <result property="algId" column="alg_id"/>
        <result property="algName" column="alg_name"/>
        <result property="algSubtypeId" column="alg_subtype_id"/>
        <result property="algSubtypeName" column="alg_subtype_name"/>
        <result property="lowerValue" column="lower_value"/>
        <result property="upperValue" column="upper_value"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectBasedataThresholdModificationVo">
        select line_id,
               patrol_point_id,
               alg_id,
               alg_name,
               alg_subtype_id,
               alg_subtype_name,
               lower_value,
               upper_value,
               create_by,
               create_time,
               update_by,
               update_time
        from basedata_threshold_modification
    </sql>

    <select id="selectBasedataThresholdModificationList" parameterType="BasedataThresholdModification"
            resultMap="BasedataThresholdModificationResult">
        <include refid="selectBasedataThresholdModificationVo"/>
        <where>
            <if test="patrolPointId != null ">and patrol_point_id = #{patrolPointId}</if>
            <if test="algId != null ">and alg_id = #{algId}</if>
            <if test="algName != null  and algName != ''">and alg_name like concat('%', #{algName}, '%')</if>

            <if test="algSubtypeIds != null and algSubtypeIds != ''">
                and alg_subtype_id in
                <foreach item="item" collection="algSubtypeIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="algSubtypeName != null  and algSubtypeName != ''">and alg_subtype_name like concat('%',
                #{algSubtypeName}, '%')
            </if>
            <if test="lowerValue != null  and lowerValue != ''">and lower_value = #{lowerValue}</if>
            <if test="upperValue != null  and upperValue != ''">and upper_value = #{upperValue}</if>
        </where>
        ORDER BY alg_subtype_name,create_time DESC
    </select>

    <select id="selectBasedataThresholdModificationByLineId" parameterType="Long"
            resultMap="BasedataThresholdModificationResult">
        <include refid="selectBasedataThresholdModificationVo"/>
        where line_id = #{lineId}
    </select>

    <insert id="insertBasedataThresholdModification" parameterType="BasedataThresholdModification"
            useGeneratedKeys="true" keyProperty="lineId">
        insert into basedata_threshold_modification
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patrolPointId != null">patrol_point_id,</if>
            <if test="algId != null">alg_id,</if>
            <if test="algName != null">alg_name,</if>
            <if test="algSubtypeId != null">alg_subtype_id,</if>
            <if test="algSubtypeName != null">alg_subtype_name,</if>
            <if test="lowerValue != null">lower_value,</if>
            <if test="upperValue != null">upper_value,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="patrolPointId != null">#{patrolPointId},</if>
            <if test="algId != null">#{algId},</if>
            <if test="algName != null">#{algName},</if>
            <if test="algSubtypeId != null">#{algSubtypeId},</if>
            <if test="algSubtypeName != null">#{algSubtypeName},</if>
            <if test="lowerValue != null">#{lowerValue},</if>
            <if test="upperValue != null">#{upperValue},</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>
        </trim>
    </insert>

    <update id="updateBasedataThresholdModification" parameterType="BasedataThresholdModification">
        update basedata_threshold_modification
        <trim prefix="SET" suffixOverrides=",">
            <if test="patrolPointId != null">patrol_point_id = #{patrolPointId},</if>
            <if test="algId != null">alg_id = #{algId},</if>
            <if test="algName != null">alg_name = #{algName},</if>
            <if test="algSubtypeId != null">alg_subtype_id = #{algSubtypeId},</if>
            <if test="algSubtypeName != null">alg_subtype_name = #{algSubtypeName},</if>
            <if test="lowerValue != null">lower_value = #{lowerValue},</if>
            <if test="upperValue != null">upper_value = #{upperValue},</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>
        </trim>
        where line_id = #{lineId}
    </update>

    <delete id="deleteBasedataThresholdModificationByLineId" parameterType="Long">
        delete
        from basedata_threshold_modification
        where line_id = #{lineId}
    </delete>

    <delete id="deleteBasedataThresholdModificationByLineIds" parameterType="String">
        delete from basedata_threshold_modification where line_id in
        <foreach item="lineId" collection="array" open="(" separator="," close=")">
            #{lineId}
        </foreach>
    </delete>
</mapper>
