<?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.zehong.system.mapper.TEquipmentInfoMapper">
    
    <resultMap type="TEquipmentInfo" id="TEquipmentInfoResult">
        <result property="fEquipmentId"    column="f_equipment_id"    />
        <result property="fEquipmentCode"    column="f_equipment_code"    />
        <result property="fEquipmentName"    column="f_equipment_name"    />
        <result property="fEquipmentType"    column="f_equipment_type"    />
        <result property="fEquipmentFactory"    column="f_equipment_factory"    />
        <result property="fBeyongDepartment"    column="f_beyong_department"    />
        <result property="fIp"    column="f_ip"    />
        <result property="fPort"    column="f_port"    />
        <result property="fInstallLocation"    column="f_install_location"    />
        <result property="fIsInspect"    column="f_is_inspect"    />
        <result property="fResponsiblePerson"    column="f_responsible_person"    />
        <result property="fResponsiblePersonMobile"    column="f_responsible_person_mobile"    />
        <result property="fCreateTime"    column="f_create_time"    />
        <result property="fUpdateTime"    column="f_update_time"    />
        <result property="fStatus"    column="f_status"    />
        <result property="fAlarmTime"    column="f_alarm_time"    />
        <result property="fPowerOutageIp"    column="f_power_outage_ip"    />
        <result property="fPowerOutagePort"    column="f_power_outage_port"    />
        <result property="errorReason"    column="f_error_Reason"    />
    </resultMap>

    <sql id="selectTEquipmentInfoVo">
        select f_equipment_id, f_equipment_code, f_equipment_name, f_equipment_type, f_equipment_factory,
               f_beyong_department, f_ip, f_port, f_install_location, f_is_inspect, f_responsible_person,
               f_responsible_person_mobile, f_create_time, f_update_time, f_status, f_alarm_time, f_power_outage_ip,
               f_power_outage_port,f_error_Reason from t_equipment_info
    </sql>

    <select id="selectTEquipmentInfoList" parameterType="TEquipmentInfo" resultMap="TEquipmentInfoResult">
        <include refid="selectTEquipmentInfoVo"/>
        <where>  
            <if test="fEquipmentCode != null  and fEquipmentCode != ''"> and f_equipment_code = #{fEquipmentCode}</if>
            <if test="fEquipmentName != null  and fEquipmentName != ''"> and f_equipment_name like concat('%', #{fEquipmentName}, '%')</if>
            <if test="fEquipmentType != null  and fEquipmentType != ''"> and f_equipment_type = #{fEquipmentType}</if>
            <if test="fEquipmentFactory != null  and fEquipmentFactory != ''"> and f_equipment_factory = #{fEquipmentFactory}</if>
            <if test="fBeyongDepartment != null  and fBeyongDepartment != ''"> and f_beyong_department = #{fBeyongDepartment}</if>
            <if test="fIp != null  and fIp != ''"> and f_ip = #{fIp}</if>
            <if test="fPort != null "> and f_port = #{fPort}</if>
            <if test="fInstallLocation != null  and fInstallLocation != ''"> and f_install_location = #{fInstallLocation}</if>
            <if test="fIsInspect != null  and fIsInspect != ''"> and f_is_inspect = #{fIsInspect}</if>
            <if test="fResponsiblePerson != null  and fResponsiblePerson != ''"> and f_responsible_person = #{fResponsiblePerson}</if>
            <if test="fResponsiblePersonMobile != null  and fResponsiblePersonMobile != ''"> and f_responsible_person_mobile = #{fResponsiblePersonMobile}</if>
            <if test="fCreateTime != null "> and f_create_time = #{fCreateTime}</if>
            <if test="fUpdateTime != null "> and f_update_time = #{fUpdateTime}</if>
            <if test="fStatus != null  and fStatus != ''"> and f_status = #{fStatus}</if>
            <if test="fAlarmTime != null  and fAlarmTime != ''"> and f_alarm_time = #{fAlarmTime}</if>
        </where>
    </select>

    <select id="selectTEquipmentList" parameterType="List" resultMap="TEquipmentInfoResult">
        <include refid="selectTEquipmentInfoVo"/>
        where f_equipment_type in
        <foreach item="item" collection="types" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="getAll" resultMap="TEquipmentInfoResult">
        <include refid="selectTEquipmentInfoVo"/>
    </select>

    <select id="getAllByEquipmentCodeList" parameterType="list" resultMap="TEquipmentInfoResult">
        <include refid="selectTEquipmentInfoVo"/>
        where f_equipment_code in
        <foreach item="item" collection="equipmentCodes" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="selectTEquipmentInfoById" parameterType="Long" resultMap="TEquipmentInfoResult">
        <include refid="selectTEquipmentInfoVo"/>
        where f_equipment_id = #{fEquipmentId}
    </select>
    <select id="selectTEquipmentInfoByCode" parameterType="string" resultMap="TEquipmentInfoResult">
        <include refid="selectTEquipmentInfoVo"/>
        where f_equipment_code = #{fEquipmentCode}
    </select>

    <insert id="insertBatch" parameterType="list">
        insert into t_equipment_info (f_equipment_code, f_equipment_name, f_equipment_type, f_ip, f_port,
                f_create_time, f_status, f_power_outage_ip,
               f_power_outage_port)
        values
            <foreach collection="equipmentInfos" item="item" separator=",">
                (#{item.fEquipmentCode}, #{item.fEquipmentName}, #{item.fEquipmentType}, #{item.fIp}, #{item.fPort},
                 #{item.fCreateTime}, #{item.fStatus}, #{item.fPowerOutageIp}, #{item.fPowerOutagePort}
                )
            </foreach>
    </insert>
    <insert id="insertTEquipmentInfo" parameterType="TEquipmentInfo" useGeneratedKeys="true" keyProperty="fEquipmentId">
        insert into t_equipment_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fEquipmentCode != null">f_equipment_code,</if>
            <if test="fEquipmentName != null">f_equipment_name,</if>
            <if test="fEquipmentType != null">f_equipment_type,</if>
            <if test="fEquipmentFactory != null">f_equipment_factory,</if>
            <if test="fBeyongDepartment != null">f_beyong_department,</if>
            <if test="fIp != null">f_ip,</if>
            <if test="fPort != null">f_port,</if>
            <if test="fInstallLocation != null">f_install_location,</if>
            <if test="fIsInspect != null">f_is_inspect,</if>
            <if test="fResponsiblePerson != null">f_responsible_person,</if>
            <if test="fResponsiblePersonMobile != null">f_responsible_person_mobile,</if>
            <if test="fCreateTime != null">f_create_time,</if>
            <if test="fUpdateTime != null">f_update_time,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="fAlarmTime != null">f_alarm_time,</if>
            <if test="errorReason != null">f_error_Reason,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fEquipmentCode != null">#{fEquipmentCode},</if>
            <if test="fEquipmentName != null">#{fEquipmentName},</if>
            <if test="fEquipmentType != null">#{fEquipmentType},</if>
            <if test="fEquipmentFactory != null">#{fEquipmentFactory},</if>
            <if test="fBeyongDepartment != null">#{fBeyongDepartment},</if>
            <if test="fIp != null">#{fIp},</if>
            <if test="fPort != null">#{fPort},</if>
            <if test="fInstallLocation != null">#{fInstallLocation},</if>
            <if test="fIsInspect != null">#{fIsInspect},</if>
            <if test="fResponsiblePerson != null">#{fResponsiblePerson},</if>
            <if test="fResponsiblePersonMobile != null">#{fResponsiblePersonMobile},</if>
            <if test="fCreateTime != null">#{fCreateTime},</if>
            <if test="fUpdateTime != null">#{fUpdateTime},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="fAlarmTime != null">#{fAlarmTime},</if>
            <if test="errorReason != null">#{errorReason},</if>
         </trim>
    </insert>

    <update id="updateTEquipmentInfo" parameterType="TEquipmentInfo">
        update t_equipment_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="fEquipmentCode != null">f_equipment_code = #{fEquipmentCode},</if>
            <if test="fEquipmentName != null">f_equipment_name = #{fEquipmentName},</if>
            <if test="fEquipmentType != null">f_equipment_type = #{fEquipmentType},</if>
            <if test="fEquipmentFactory != null">f_equipment_factory = #{fEquipmentFactory},</if>
            <if test="fBeyongDepartment != null">f_beyong_department = #{fBeyongDepartment},</if>
            <if test="fIp != null">f_ip = #{fIp},</if>
            <if test="fPort != null">f_port = #{fPort},</if>
            <if test="fInstallLocation != null">f_install_location = #{fInstallLocation},</if>
            <if test="fIsInspect != null">f_is_inspect = #{fIsInspect},</if>
            <if test="fResponsiblePerson != null">f_responsible_person = #{fResponsiblePerson},</if>
            <if test="fResponsiblePersonMobile != null">f_responsible_person_mobile = #{fResponsiblePersonMobile},</if>
            <if test="fCreateTime != null">f_create_time = #{fCreateTime},</if>
            <if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="fAlarmTime != null">f_alarm_time = #{fAlarmTime},</if>
            <if test="errorReason != null">f_error_Reason = #{errorReason},</if>
        </trim>
        where f_equipment_id = #{fEquipmentId}
    </update>
    <update id="batchUpdate" parameterType="list" >
        <foreach collection="equipmentInfos" item="item"  index="index" separator=";">
            update t_equipment_info
            <trim prefix="SET" suffixOverrides=",">
                <if test="item.fStatus != null">f_status = #{item.fStatus},</if>
                <if test="item.errorReason != null">f_error_Reason = #{item.errorReason},</if>
            </trim>
            where f_equipment_id = #{item.fEquipmentId}
        </foreach>
    </update>

    <delete id="deleteTEquipmentInfoById" parameterType="Long">
        delete from t_equipment_info where f_equipment_id = #{fEquipmentId}
    </delete>

    <delete id="deleteTEquipmentInfoByIds" parameterType="String">
        delete from t_equipment_info where f_equipment_id in 
        <foreach item="fEquipmentId" collection="array" open="(" separator="," close=")">
            #{fEquipmentId}
        </foreach>
    </delete>
</mapper>