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

    <resultMap type="com.tofly.water.entity.LaborPlan" id="LaborPlanMap">
        <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="estimateWaterCapacity" column="ESTIMATE_WATER_CAPACITY" jdbcType="VARCHAR"/>
        <result property="scene" column="SCENE" 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.selectByLaborPlanId"></collection>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_LABOR_PLAN(NAME, PUMP_ID, PUMP_GROUP_ID, CODE, RUN_TIME, ESTIMATE_WATER_CAPACITY, SCENE,
        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.estimateWaterCapacity}, #{entity.scene}, #{entity.sort}, #{entity.deleted}, #{entity.createdUser},
            #{entity.createdTime}, #{entity.updatedUser}, #{entity.updatedTime})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into TF_LABOR_PLAN(NAME, PUMP_ID, PUMP_GROUP_ID, CODE, RUN_TIME, ESTIMATE_WATER_CAPACITY, SCENE,
        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.estimateWaterCapacity}, #{entity.scene}, #{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) , ESTIMATE_WATER_CAPACITY = values(ESTIMATE_WATER_CAPACITY) , SCENE = values(SCENE)
        , 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>

