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

    <resultMap type="com.tofly.water.entity.OperationPlan" id="OperationPlanMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="name" column="NAME" jdbcType="VARCHAR"/>
        <result property="pumpId" column="PUMP_ID" jdbcType="INTEGER"/>
        <result property="pumpGroupId" column="PUMP_GROUP_ID" jdbcType="INTEGER"/>
        <result property="code" column="CODE" jdbcType="VARCHAR"/>
        <result property="runTime" column="RUN_TIME" jdbcType="VARCHAR"/>
        <result property="waterCapacity" column="WATER_CAPACITY" jdbcType="VARCHAR"/>
        <result property="startTime" column="START_TIME" jdbcType="TIMESTAMP"/>
        <result property="endTime" column="END_TIME" jdbcType="TIMESTAMP"/>
        <result property="cumulativeFlow" column="CUMULATIVE_FLOW" jdbcType="VARCHAR"/>
        <result property="accumulatedElectricity" column="ACCUMULATED_ELECTRICITY" jdbcType="VARCHAR"/>
        <result property="powerConsumption" column="POWER_CONSUMPTION" jdbcType="VARCHAR"/>
        <result property="averageFlow" column="AVERAGE_FLOW" jdbcType="VARCHAR"/>
        <result property="powerOfWater" column="POWER_OF_WATER" jdbcType="VARCHAR"/>
        <result property="remark" column="REMARK" 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"/>
        <collection property="planPumps" column="{planId = id}" ofType="com.tofly.water.entity.PlanPump"
                    select="com.tofly.water.mapper.PlanPumpMapper.selectByOperationPlanId"></collection>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_OPERATION_PLAN(NAME, PUMP_ID, PUMP_GROUP_ID, CODE, RUN_TIME, WATER_CAPACITY, START_TIME,
        END_TIME, CUMULATIVE_FLOW, ACCUMULATED_ELECTRICITY, POWER_CONSUMPTION, AVERAGE_FLOW, POWER_OF_WATER, REMARK,
        SORT, DELETED, CREATED_USER, CREATED_TIME, UPDATED_USER, UPDATED_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.pumpId}, #{entity.pumpGroupId}, #{entity.code}, #{entity.runTime},
            #{entity.waterCapacity}, #{entity.startTime}, #{entity.endTime}, #{entity.cumulativeFlow},
            #{entity.accumulatedElectricity}, #{entity.powerConsumption}, #{entity.averageFlow}, #{entity.powerOfWater},
            #{entity.remark}, #{entity.sort}, #{entity.deleted}, #{entity.createdUser}, #{entity.createdTime},
            #{entity.updatedUser}, #{entity.updatedTime})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_OPERATION_PLAN(NAME, PUMP_ID, PUMP_GROUP_ID, CODE, RUN_TIME, WATER_CAPACITY, START_TIME,
        END_TIME, CUMULATIVE_FLOW, ACCUMULATED_ELECTRICITY, POWER_CONSUMPTION, AVERAGE_FLOW, POWER_OF_WATER, REMARK,
        SORT, DELETED, CREATED_USER, CREATED_TIME, UPDATED_USER, UPDATED_TIME)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.pumpId}, #{entity.pumpGroupId}, #{entity.code}, #{entity.runTime},
            #{entity.waterCapacity}, #{entity.startTime}, #{entity.endTime}, #{entity.cumulativeFlow},
            #{entity.accumulatedElectricity}, #{entity.powerConsumption}, #{entity.averageFlow}, #{entity.powerOfWater},
            #{entity.remark}, #{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) , PUMP_GROUP_ID = values(PUMP_GROUP_ID) , CODE = values(CODE) ,
        RUN_TIME = values(RUN_TIME) , WATER_CAPACITY = values(WATER_CAPACITY) , START_TIME = values(START_TIME) ,
        END_TIME = values(END_TIME) , CUMULATIVE_FLOW = values(CUMULATIVE_FLOW) , ACCUMULATED_ELECTRICITY =
        values(ACCUMULATED_ELECTRICITY) , POWER_CONSUMPTION = values(POWER_CONSUMPTION) , AVERAGE_FLOW =
        values(AVERAGE_FLOW) , POWER_OF_WATER = values(POWER_OF_WATER) , REMARK = values(REMARK) , 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>

