<?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.hw.ems.base.mapper.BaseLineLossMapper">

    <resultMap type="BaseLineLoss" id="BaseLineLossResult">
        <result property="objid"    column="objid"    />
        <result property="lineLossId"    column="line_loss_id"    />
        <result property="lineLossName"    column="line_loss_name"    />
        <result property="monitorId"    column="monitor_id"    />
        <result property="monitorName"    column="monitor_name"    />
        <result property="monitorType"    column="monitor_type"    />
        <result property="grade"    column="grade"    />
        <result property="lineLossStatus"    column="line_loss_status"    />
        <result property="userId"    column="user_id"    />
        <result property="deptId"    column="dept_id"    />
        <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="selectBaseLineLossVo">
        select objid, line_loss_id, line_loss_name, monitor_id, monitor_name, monitor_type, grade, line_loss_status, user_id, dept_id, create_by, create_time, update_by, update_time from base_line_loss
    </sql>

    <select id="selectBaseLineLossList" parameterType="BaseLineLoss" resultMap="BaseLineLossResult">
        <include refid="selectBaseLineLossVo"/>
        <where>
            <if test="lineLossId != null  and lineLossId != ''"> and line_loss_id = #{lineLossId}</if>
            <if test="lineLossName != null  and lineLossName != ''"> and line_loss_name like concat('%', #{lineLossName}, '%')</if>
            <if test="monitorId != null  and monitorId != ''"> and monitor_id = #{monitorId}</if>
            <if test="monitorName != null  and monitorName != ''"> and monitor_name like concat('%', #{monitorName}, '%')</if>
            <if test="monitorType != null "> and monitor_type = #{monitorType}</if>
            <if test="grade != null "> and grade = #{grade}</if>
            <if test="lineLossStatus != null "> and line_loss_status = #{lineLossStatus}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>
    <select id="selectBaseLineLossListLike" parameterType="BaseLineLoss" resultMap="BaseLineLossResult">
        <include refid="selectBaseLineLossVo"/>
        <where>
            <if test="lineLossId != null  and lineLossId != ''"> and line_loss_id like concat('%',#{lineLossId},'%')</if>
            <if test="lineLossName != null  and lineLossName != ''"> and line_loss_name like concat('%', #{lineLossName}, '%')</if>
            <if test="monitorId != null  and monitorId != ''"> and monitor_id = #{monitorId}</if>
            <if test="monitorName != null  and monitorName != ''"> and monitor_name like concat('%', #{monitorName}, '%')</if>
            <if test="monitorType != null "> and monitor_type = #{monitorType}</if>
            <if test="grade != null "> and grade = #{grade}</if>
            <if test="lineLossStatus != null "> and line_loss_status = #{lineLossStatus}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>

    <select id="selectBaseLineLossByObjid" parameterType="Long" resultMap="BaseLineLossResult">
        <include refid="selectBaseLineLossVo"/>
        where objid = #{objid}
    </select>
    <select id="selectMultiplePowerSuppliesList" parameterType="BaseLineLoss" resultMap="BaseLineLossResult">
        select blm.monitor_id line_loss_id,blm2.monitor_id,blm2.monitor_name from (
        select monitor_id,count(1) num from base_line_monitor
        group by monitor_id) b
        left join base_line_monitor blm on blm.monitor_id = b.monitor_id
        left join base_line_monitor blm2 on blm2.objid = blm.parent_id
        where b.num > 1
    </select>

    <insert id="insertBaseLineLoss" parameterType="BaseLineLoss" useGeneratedKeys="true" keyProperty="objid">
        insert into base_line_loss
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lineLossId != null">line_loss_id,</if>
            <if test="lineLossName != null">line_loss_name,</if>
            <if test="monitorId != null">monitor_id,</if>
            <if test="monitorName != null">monitor_name,</if>
            <if test="monitorType != null">monitor_type,</if>
            <if test="grade != null">grade,</if>
            <if test="lineLossStatus != null">line_loss_status,</if>
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</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="lineLossId != null">#{lineLossId},</if>
            <if test="lineLossName != null">#{lineLossName},</if>
            <if test="monitorId != null">#{monitorId},</if>
            <if test="monitorName != null">#{monitorName},</if>
            <if test="monitorType != null">#{monitorType},</if>
            <if test="grade != null">#{grade},</if>
            <if test="lineLossStatus != null">#{lineLossStatus},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</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="updateBaseLineLoss" parameterType="BaseLineLoss">
        update base_line_loss
        <trim prefix="SET" suffixOverrides=",">
            <if test="lineLossId != null">line_loss_id = #{lineLossId},</if>
            <if test="lineLossName != null">line_loss_name = #{lineLossName},</if>
            <if test="monitorId != null">monitor_id = #{monitorId},</if>
            <if test="monitorName != null">monitor_name = #{monitorName},</if>
            <if test="monitorType != null">monitor_type = #{monitorType},</if>
            <if test="grade != null">grade = #{grade},</if>
            <if test="lineLossStatus != null">line_loss_status = #{lineLossStatus},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</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 objid = #{objid}
    </update>

    <delete id="deleteBaseLineLossByObjid" parameterType="Long">
        delete from base_line_loss where objid = #{objid}
    </delete>

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