<?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.ruoyi.rocketmq.mapper.InitialSwitchPowerSupplyMapper">
    
    <resultMap type="InitialSwitchPowerSupply" id="InitialSwitchPowerSupplyResult">
        <result property="id"    column="id"    />
        <result property="pwrEntIndex"    column="pwr_ent_index"    />
        <result property="pwrName"    column="pwr_name"    />
        <result property="pwrEntityPwrState"    column="pwr_entity_pwr_state"    />
        <result property="pwrEntityPwrCurrent"    column="pwr_entity_pwr_current"    />
        <result property="pwrEntityPwrVoltage"    column="pwr_entity_pwr_voltage"    />
        <result property="clientId"    column="client_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectInitialSwitchPowerSupplyVo">
        select id, pwr_ent_index, pwr_name, pwr_entity_pwr_state, pwr_entity_pwr_current, pwr_entity_pwr_voltage, client_id, create_time, update_time, create_by, update_by from initial_switch_power_supply
    </sql>

    <select id="selectInitialSwitchPowerSupplyList" parameterType="InitialSwitchPowerSupply" resultMap="InitialSwitchPowerSupplyResult">
        <include refid="selectInitialSwitchPowerSupplyVo"/>
        <where>  
            <if test="pwrEntIndex != null  and pwrEntIndex != ''"> and pwr_ent_index = #{pwrEntIndex}</if>
            <if test="pwrName != null  and pwrName != ''"> and pwr_name like concat('%', #{pwrName}, '%')</if>
            <if test="pwrEntityPwrState != null  and pwrEntityPwrState != ''"> and pwr_entity_pwr_state = #{pwrEntityPwrState}</if>
            <if test="pwrEntityPwrCurrent != null "> and pwr_entity_pwr_current = #{pwrEntityPwrCurrent}</if>
            <if test="pwrEntityPwrVoltage != null "> and pwr_entity_pwr_voltage = #{pwrEntityPwrVoltage}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="startTime != null  and startTime != ''"> and create_time &gt;= #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and create_time &lt;= #{endTime}</if>
        </where>
    </select>
    
    <select id="selectInitialSwitchPowerSupplyById" parameterType="Long" resultMap="InitialSwitchPowerSupplyResult">
        <include refid="selectInitialSwitchPowerSupplyVo"/>
        where id = #{id}
    </select>

    <insert id="insertInitialSwitchPowerSupply" parameterType="InitialSwitchPowerSupply" useGeneratedKeys="true" keyProperty="id">
        insert IGNORE into initial_switch_power_supply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pwrEntIndex != null">pwr_ent_index,</if>
            <if test="pwrName != null">pwr_name,</if>
            <if test="pwrEntityPwrState != null">pwr_entity_pwr_state,</if>
            <if test="pwrEntityPwrCurrent != null">pwr_entity_pwr_current,</if>
            <if test="pwrEntityPwrVoltage != null">pwr_entity_pwr_voltage,</if>
            <if test="clientId != null">client_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pwrEntIndex != null">#{pwrEntIndex},</if>
            <if test="pwrName != null">#{pwrName},</if>
            <if test="pwrEntityPwrState != null">#{pwrEntityPwrState},</if>
            <if test="pwrEntityPwrCurrent != null">#{pwrEntityPwrCurrent},</if>
            <if test="pwrEntityPwrVoltage != null">#{pwrEntityPwrVoltage},</if>
            <if test="clientId != null">#{clientId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateInitialSwitchPowerSupply" parameterType="InitialSwitchPowerSupply">
        update initial_switch_power_supply
        <trim prefix="SET" suffixOverrides=",">
            <if test="pwrEntIndex != null">pwr_ent_index = #{pwrEntIndex},</if>
            <if test="pwrName != null">pwr_name = #{pwrName},</if>
            <if test="pwrEntityPwrState != null">pwr_entity_pwr_state = #{pwrEntityPwrState},</if>
            <if test="pwrEntityPwrCurrent != null">pwr_entity_pwr_current = #{pwrEntityPwrCurrent},</if>
            <if test="pwrEntityPwrVoltage != null">pwr_entity_pwr_voltage = #{pwrEntityPwrVoltage},</if>
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInitialSwitchPowerSupplyById" parameterType="Long">
        delete from initial_switch_power_supply where id = #{id}
    </delete>

    <delete id="deleteInitialSwitchPowerSupplyByIds" parameterType="String">
        delete from initial_switch_power_supply where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="insertBatchInitialSwitchPowerSupply" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        insert IGNORE into initial_switch_power_supply
        (
        pwr_ent_index,
        pwr_name,
        pwr_entity_pwr_state,
        pwr_entity_pwr_current,
        pwr_entity_pwr_voltage,
        client_id,
        create_time,
        update_time,
        create_by,
        update_by
        )
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.pwrEntIndex},
            #{item.pwrName},
            #{item.pwrEntityPwrState},
            #{item.pwrEntityPwrCurrent},
            #{item.pwrEntityPwrVoltage},
            #{item.clientId},
            #{item.createTime},
            #{item.updateTime},
            #{item.createBy},
            #{item.updateBy}
            )
        </foreach>
    </insert>
    <select id="getAllPwrName" parameterType="InitialSwitchPowerSupply" resultType="java.util.Map">
        select pwr_name pwrName from initial_switch_power_supply
        <where>
            <if test="pwrEntIndex != null  and pwrEntIndex != ''"> and pwr_ent_index = #{pwrEntIndex}</if>
            <if test="pwrName != null  and pwrName != ''"> and pwr_name like concat('%', #{pwrName}, '%')</if>
            <if test="pwrEntityPwrState != null  and pwrEntityPwrState != ''"> and pwr_entity_pwr_state = #{pwrEntityPwrState}</if>
            <if test="pwrEntityPwrCurrent != null "> and pwr_entity_pwr_current = #{pwrEntityPwrCurrent}</if>
            <if test="pwrEntityPwrVoltage != null "> and pwr_entity_pwr_voltage = #{pwrEntityPwrVoltage}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        group by pwr_name
    </select>
    <select id="getPwrMsg" parameterType="InitialSwitchPowerSupply" resultMap="InitialSwitchPowerSupplyResult">
        <include refid="selectInitialSwitchPowerSupplyVo"/>
        <where>
            <if test="pwrEntIndex != null  and pwrEntIndex != ''"> and pwr_ent_index = #{pwrEntIndex}</if>
            <if test="pwrName != null  and pwrName != ''"> and pwr_name like concat('%', #{pwrName}, '%')</if>
            <if test="pwrEntityPwrState != null  and pwrEntityPwrState != ''"> and pwr_entity_pwr_state = #{pwrEntityPwrState}</if>
            <if test="pwrEntityPwrCurrent != null "> and pwr_entity_pwr_current = #{pwrEntityPwrCurrent}</if>
            <if test="pwrEntityPwrVoltage != null "> and pwr_entity_pwr_voltage = #{pwrEntityPwrVoltage}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        order by create_time desc limit 1
    </select>
</mapper>