<?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.SafeMonitorMapper">

    <resultMap type="com.tofly.water.entity.SafeMonitor" id="SafeMonitorMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="name" column="NAME" jdbcType="VARCHAR"/>
        <result property="pumpId" column="PUMP_ID" jdbcType="INTEGER"/>
        <result property="code" column="CODE" jdbcType="VARCHAR"/>
        <result property="installationPosition" column="INSTALLATION_POSITION" jdbcType="VARCHAR"/>
        <result property="managementDept" column="MANAGEMENT_DEPT" jdbcType="VARCHAR"/>
        <result property="managementLeader" column="MANAGEMENT_LEADER" jdbcType="VARCHAR"/>
        <result property="managementLeaderPhone" column="MANAGEMENT_LEADER_PHONE" jdbcType="VARCHAR"/>
        <result property="supplierSimple" column="SUPPLIER_SIMPLE" jdbcType="VARCHAR"/>
        <result property="supplierPhone" column="SUPPLIER_PHONE" jdbcType="VARCHAR"/>
        <result property="installationLeader" column="INSTALLATION_LEADER" jdbcType="VARCHAR"/>
        <result property="installationDate" column="INSTALLATION_DATE" jdbcType="TIMESTAMP"/>
        <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
        <result property="annex" column="ANNEX" 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"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_SAFE_MONITOR(NAME, PUMP_ID, CODE, INSTALLATION_POSITION, MANAGEMENT_DEPT,
        MANAGEMENT_LEADER, MANAGEMENT_LEADER_PHONE, SUPPLIER_SIMPLE, SUPPLIER_PHONE, INSTALLATION_LEADER,
        INSTALLATION_DATE, REMARK, ANNEX, SORT, DELETED, CREATED_USER, CREATED_TIME, UPDATED_USER, UPDATED_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.pumpId}, #{entity.code}, #{entity.installationPosition}, #{entity.managementDept},
            #{entity.managementLeader}, #{entity.managementLeaderPhone}, #{entity.supplierSimple},
            #{entity.supplierPhone}, #{entity.installationLeader}, #{entity.installationDate}, #{entity.remark},
            #{entity.annex}, #{entity.sort}, #{entity.deleted}, #{entity.createdUser}, #{entity.createdTime},
            #{entity.updatedUser}, #{entity.updatedTime})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_SAFE_MONITOR(NAME, PUMP_ID, CODE, INSTALLATION_POSITION, MANAGEMENT_DEPT,
        MANAGEMENT_LEADER, MANAGEMENT_LEADER_PHONE, SUPPLIER_SIMPLE, SUPPLIER_PHONE, INSTALLATION_LEADER,
        INSTALLATION_DATE, REMARK, ANNEX, SORT, DELETED, CREATED_USER, CREATED_TIME, UPDATED_USER, UPDATED_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.pumpId}, #{entity.code}, #{entity.installationPosition}, #{entity.managementDept},
            #{entity.managementLeader}, #{entity.managementLeaderPhone}, #{entity.supplierSimple},
            #{entity.supplierPhone}, #{entity.installationLeader}, #{entity.installationDate}, #{entity.remark},
            #{entity.annex}, #{entity.sort}, #{entity.deleted}, #{entity.createdUser}, #{entity.createdTime},
            #{entity.updatedUser}, #{entity.updatedTime})
        </foreach>
        on duplicate key update
        NAME = values(NAME) , PUMP_ID = values(PUMP_ID) , CODE = values(CODE) , INSTALLATION_POSITION =
        values(INSTALLATION_POSITION) , MANAGEMENT_DEPT = values(MANAGEMENT_DEPT) , MANAGEMENT_LEADER =
        values(MANAGEMENT_LEADER) , MANAGEMENT_LEADER_PHONE = values(MANAGEMENT_LEADER_PHONE) , SUPPLIER_SIMPLE =
        values(SUPPLIER_SIMPLE) , SUPPLIER_PHONE = values(SUPPLIER_PHONE) , INSTALLATION_LEADER =
        values(INSTALLATION_LEADER) , INSTALLATION_DATE = values(INSTALLATION_DATE) , REMARK = values(REMARK) , ANNEX =
        values(ANNEX) , 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>

