<?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.jsowell.pile.mapper.PileModelInfoMapper">

    <resultMap type="com.jsowell.pile.domain.PileModelInfo" id="PileModelInfoResult">
        <result property="id"    column="id"    />
        <result property="modelName"    column="model_name"    />
        <result property="ratedPower"    column="rated_power"    />
        <result property="ratedCurrent"    column="rated_current"    />
        <result property="ratedVoltage"    column="rated_voltage"    />
        <result property="speedType"    column="speed_type"    />
        <result property="chargerPileType"    column="charger_pile_type"    />
        <result property="connectorNum"    column="connector_num"    />
        <result property="interfaceStandard"    column="interface_standard"    />
        <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="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectPileModelInfoVo">
        select
            <include refid="Base_Column_List"/>
        from pile_model_info
    </sql>

    <sql id="Base_Column_List">
        id, model_name,rated_power, rated_current, rated_voltage, speed_type, charger_pile_type, connector_num, interface_standard, create_by,
        create_time, update_by, update_time,  del_flag
    </sql>

    <select id="selectPileModelInfoList" parameterType="com.jsowell.pile.domain.PileModelInfo" resultMap="PileModelInfoResult">
        <include refid="selectPileModelInfoVo"/>
        <where>
            <if test="modelName != null  and modelName != ''"> and model_name like concat('%', #{modelName}, '%')</if>
            <if test="ratedPower != null  and ratedPower != ''"> and rated_power = #{ratedPower}</if>
            <if test="ratedCurrent != null  and ratedCurrent != ''"> and rated_current = #{ratedCurrent}</if>
            <if test="ratedVoltage != null  and ratedVoltage != ''"> and rated_voltage = #{ratedVoltage}</if>
            <if test="speedType != null  and speedType != ''"> and speed_type = #{speedType}</if>
            <if test="chargerPileType != null  and chargerPileType != ''"> and charger_pile_type = #{chargerPileType}</if>
            <if test="connectorNum != null "> and connector_num = #{connectorNum}</if>
            <if test="interfaceStandard != null  and interfaceStandard != ''"> and interface_standard = #{interfaceStandard}</if>
        </where>
    </select>

    <select id="selectPileModelInfoById" parameterType="Long" resultMap="PileModelInfoResult">
        <include refid="selectPileModelInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertPileModelInfo" parameterType="com.jsowell.pile.domain.PileModelInfo" useGeneratedKeys="true" keyProperty="id">
        insert into pile_model_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelName != null">model_name,</if>
            <if test="ratedPower != null">rated_power,</if>
            <if test="ratedCurrent != null">rated_current,</if>
            <if test="ratedVoltage != null">rated_voltage,</if>
            <if test="speedType != null">speed_type,</if>
            <if test="chargerPileType != null">charger_pile_type,</if>
            <if test="connectorNum != null">connector_num,</if>
            <if test="interfaceStandard != null">interface_standard,</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="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="modelName != null">#{modelName},</if>
            <if test="ratedPower != null">#{ratedPower},</if>
            <if test="ratedCurrent != null">#{ratedCurrent},</if>
            <if test="ratedVoltage != null">#{ratedVoltage},</if>
            <if test="speedType != null">#{speedType},</if>
            <if test="chargerPileType != null">#{chargerPileType},</if>
            <if test="connectorNum != null">#{connectorNum},</if>
            <if test="interfaceStandard != null">#{interfaceStandard},</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="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updatePileModelInfo" parameterType="com.jsowell.pile.domain.PileModelInfo">
        update pile_model_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="modelName != null">model_name = #{modelName},</if>
            <if test="ratedPower != null">rated_power = #{ratedPower},</if>
            <if test="ratedCurrent != null">rated_current = #{ratedCurrent},</if>
            <if test="ratedVoltage != null">rated_voltage = #{ratedVoltage},</if>
            <if test="speedType != null">speed_type = #{speedType},</if>
            <if test="chargerPileType != null">charger_pile_type = #{chargerPileType},</if>
            <if test="connectorNum != null">connector_num = #{connectorNum},</if>
            <if test="interfaceStandard != null">interface_standard = #{interfaceStandard},</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="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePileModelInfoById" parameterType="Long">
        delete from pile_model_info where id = #{id}
    </delete>

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

    <select id="getPileModelInfoByPileSnList" resultType="com.jsowell.pile.vo.web.PileModelInfoVO">
        SELECT
            t1.sn as pileSn,
            t2.id as modelId,
            t2.model_name as modelName,
            t2.rated_power as ratedPower,
            t2.rated_current as ratedCurrent,
            t2.rated_voltage as ratedVoltage,
            t2.speed_type as speedType,
            t2.charger_pile_type as chargerPileType,
            t2.connector_num as connectorNum,
            t2.interface_standard as interfaceStandard,
            t2.create_by as createBy,
            t2.create_time as createTime,
            t2.update_by as updateBy,
            t2.update_time as updateTime
        FROM
            pile_basic_info t1
        JOIN pile_model_info t2 ON t1.model_id = t2.id
        WHERE
            t1.del_flag = '0'
          and t1.sn in
        <foreach collection="pileSnList" item="pileSn" open="(" separator="," close=")">
            #{pileSn,jdbcType=VARCHAR}
        </foreach>
    </select>


</mapper>