<?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.spire.mapper.SpireUserMapper">

    <resultMap type="com.tofly.spire.entity.SpireUser" id="SpireUserMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="address" column="ADDRESS" jdbcType="VARCHAR"/>
        <result property="houseNumber" column="HOUSE_NUMBER" jdbcType="VARCHAR"/>
        <result property="phone" column="PHONE" jdbcType="VARCHAR"/>
        <result property="sn" column="SN" jdbcType="VARCHAR"/>
        <result property="type" column="TYPE" jdbcType="VARCHAR"/>
        <result property="userGuid" column="USER_GUID" jdbcType="VARCHAR"/>
        <result property="userName" column="USER_NAME" jdbcType="VARCHAR"/>
        <result property="valveStatusTxt" column="VALVE_STATUS_TXT" jdbcType="VARCHAR"/>
        <result property="valveType" column="VALVE_TYPE" jdbcType="VARCHAR"/>
        <result property="uploadTime" column="UPLOAD_TIME" jdbcType="TIMESTAMP"/>
        <result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into SPIRE_USER(ADDRESS, HOUSE_NUMBER, PHONE, SN, TYPE, USER_GUID, USER_NAME, VALVE_STATUS_TXT,
        VALVE_TYPE, UPLOAD_TIME, CREATE_TIME, UPDATE_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.address}, #{entity.houseNumber}, #{entity.phone}, #{entity.sn}, #{entity.type},
            #{entity.userGuid}, #{entity.userName}, #{entity.valveStatusTxt}, #{entity.valveType}, #{entity.uploadTime},
            #{entity.createTime}, #{entity.updateTime})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into SPIRE_USER(ADDRESS, HOUSE_NUMBER, PHONE, SN, TYPE, USER_GUID, USER_NAME, VALVE_STATUS_TXT,
        VALVE_TYPE, UPLOAD_TIME, CREATE_TIME, UPDATE_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.address}, #{entity.houseNumber}, #{entity.phone}, #{entity.sn}, #{entity.type},
            #{entity.userGuid}, #{entity.userName}, #{entity.valveStatusTxt}, #{entity.valveType}, #{entity.uploadTime},
            #{entity.createTime}, #{entity.updateTime})
        </foreach>
        on duplicate key update
        ADDRESS = values(ADDRESS) , HOUSE_NUMBER = values(HOUSE_NUMBER) , PHONE = values(PHONE) , SN = values(SN) , TYPE
        = values(TYPE) , USER_GUID = values(USER_GUID) , USER_NAME = values(USER_NAME) , VALVE_STATUS_TXT =
        values(VALVE_STATUS_TXT) , VALVE_TYPE = values(VALVE_TYPE) , UPLOAD_TIME = values(UPLOAD_TIME) , CREATE_TIME =
        values(CREATE_TIME) , UPDATE_TIME = values(UPDATE_TIME)
    </insert>

</mapper>

