<?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.tofly.water.mapper.BasePumpDetailMapper">

    <resultMap type="com.tofly.water.entity.BasePumpDetail" id="BasePumpDetailMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="pumpId" column="PUMP_ID" jdbcType="INTEGER"/>
        <result property="pumpGroupId" column="PUMP_GROUP_ID" jdbcType="INTEGER"/>
        <result property="name" column="NAME" jdbcType="VARCHAR"/>
        <result property="model" column="MODEL" jdbcType="VARCHAR"/>
        <result property="ratedFlow" column="RATED_FLOW" jdbcType="VARCHAR"/>
        <result property="ratedHead" column="RATED_HEAD" jdbcType="VARCHAR"/>
        <result property="ratedSpeed" column="RATED_SPEED" jdbcType="VARCHAR"/>
        <result property="ratedVoltage" column="RATED_VOLTAGE" jdbcType="VARCHAR"/>
        <result property="ratedCurrent" column="RATED_CURRENT" jdbcType="VARCHAR"/>
        <result property="ratedPower" column="RATED_POWER" jdbcType="VARCHAR"/>
        <result property="ratedFrequency" column="RATED_FREQUENCY" jdbcType="VARCHAR"/>
        <result property="sort" column="SORT" jdbcType="INTEGER"/>
        <result property="deleted" column="DELETED" jdbcType="VARCHAR"/>
        <result property="createdUser" column="CREATED_USER" jdbcType="INTEGER"/>
        <result property="createdTime" column="CREATED_TIME" jdbcType="TIMESTAMP"/>
        <result property="updatedUser" column="UPDATED_USER" jdbcType="INTEGER"/>
        <result property="updatedTime" column="UPDATED_TIME" jdbcType="TIMESTAMP"/>
        <association property="createdUserName" column="CREATED_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="updatedUserName" column="UPDATED_USER"
                     select="com.tofly.baseapi.mapper.ToflyCodeCommonMapper.getUserName"/>
        <association property="pumpIdName" column="PUMP_ID"
                     select="com.tofly.water.mapper.BasePumpMapper.selectNameById"/>
        <association property="pumpGroupIdName" column="PUMP_GROUP_ID"
                     select="com.tofly.water.mapper.BasePumpGroupMapper.selectNameById"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_BASE_PUMP_DETAIL(PUMP_ID, PUMP_GROUP_ID, NAME, MODEL, RATED_FLOW, RATED_HEAD,
        RATED_SPEED, RATED_VOLTAGE, RATED_CURRENT, RATED_POWER, RATED_FREQUENCY, SORT, DELETED, CREATED_USER,
        CREATED_TIME, UPDATED_USER, UPDATED_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.pumpId}, #{entity.pumpGroupId}, #{entity.name}, #{entity.model}, #{entity.ratedFlow},
            #{entity.ratedHead}, #{entity.ratedSpeed}, #{entity.ratedVoltage}, #{entity.ratedCurrent},
            #{entity.ratedPower}, #{entity.ratedFrequency}, #{entity.sort}, #{entity.deleted}, #{entity.createdUser},
            #{entity.createdTime}, #{entity.updatedUser}, #{entity.updatedTime})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_BASE_PUMP_DETAIL(PUMP_ID, PUMP_GROUP_ID, NAME, MODEL, RATED_FLOW, RATED_HEAD,
        RATED_SPEED, RATED_VOLTAGE, RATED_CURRENT, RATED_POWER, RATED_FREQUENCY, SORT, DELETED, CREATED_USER,
        CREATED_TIME, UPDATED_USER, UPDATED_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.pumpId}, #{entity.pumpGroupId}, #{entity.name}, #{entity.model}, #{entity.ratedFlow},
            #{entity.ratedHead}, #{entity.ratedSpeed}, #{entity.ratedVoltage}, #{entity.ratedCurrent},
            #{entity.ratedPower}, #{entity.ratedFrequency}, #{entity.sort}, #{entity.deleted}, #{entity.createdUser},
            #{entity.createdTime}, #{entity.updatedUser}, #{entity.updatedTime})
        </foreach>
        on duplicate key update
        PUMP_ID = values(PUMP_ID) , PUMP_GROUP_ID = values(PUMP_GROUP_ID) , NAME = values(NAME) , MODEL = values(MODEL)
        , RATED_FLOW = values(RATED_FLOW) , RATED_HEAD = values(RATED_HEAD) , RATED_SPEED = values(RATED_SPEED) ,
        RATED_VOLTAGE = values(RATED_VOLTAGE) , RATED_CURRENT = values(RATED_CURRENT) , RATED_POWER =
        values(RATED_POWER) , RATED_FREQUENCY = values(RATED_FREQUENCY) , SORT = values(SORT) , DELETED =
        values(DELETED) , CREATED_USER = values(CREATED_USER) , CREATED_TIME = values(CREATED_TIME) , UPDATED_USER =
        values(UPDATED_USER) , UPDATED_TIME = values(UPDATED_TIME)
    </insert>

</mapper>

