<?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.xhpc.activity.mapper.XhpcActivityFormulaMapper">
    <resultMap id="BaseResultMap" type="com.xhpc.activity.domain.XhpcActivityFormulaDomain">
        <id column="activity_formula_id" jdbcType="BIGINT" property="activityFormulaId"/>
        <result column="activity_id" jdbcType="INTEGER" property="activityId"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="power_price" javaType="DECIMAL" property="powerPrice"/>
        <result column="service_price" javaType="DECIMAL" property="servicePrice"/>
        <result column="compute_formula" jdbcType="VARCHAR" property="computeFormula"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
    </resultMap>
    <sql id="Base_Column_List">
        activity_formula_id
        , activity_id, start_time, end_time, power_price, service_price, compute_formula, create_time,
    create_by, update_time, update_by
    </sql>


    <select id="selectByActivityId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from xhpc_activity_formula
        where activity_id = #{activityId}
    </select>


    <delete id="deleteByActivityId">
        delete
        from xhpc_activity_formula
        where activity_id = #{activityId}
    </delete>


    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from xhpc_activity_formula
        where activity_formula_id = #{activityFormulaId,jdbcType=BIGINT}
    </select>


    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from xhpc_activity_formula
        where activity_formula_id = #{activityFormulaId,jdbcType=BIGINT}
    </delete>


    <insert id="insert" keyColumn="activity_formula_id" keyProperty="activityFormulaId"
            parameterType="com.xhpc.activity.domain.XhpcActivityFormulaDomain" useGeneratedKeys="true">
        insert into xhpc_activity_formula (activity_id, start_time, end_time, power_price,
                                           service_price, compute_formula, create_time, create_by,
                                           update_time, update_by)
        values (#{activityId,jdbcType=INTEGER}, #{startTime}, #{endTime}, #{powerPrice},
                #{servicePrice}, upper(#{computeFormula}), sysdate(), #{createBy,jdbcType=VARCHAR},
                sysdate(), #{updateBy,jdbcType=VARCHAR})
    </insert>


    <insert id="insertBatch">
        insert into xhpc_activity_formula (activity_id, start_time, end_time, power_price,
        service_price, compute_formula, create_time, create_by,
        update_time, update_by) values
        <foreach collection="domainList" separator="," item="domain" index="index">
            (#{domain.activityId}, #{domain.startTime}, #{domain.endTime},#{domain.powerPrice},
            #{domain.servicePrice}, upper(#{domain.computeFormula}), sysdate(), #{domain.createBy},
            sysdate(), #{domain.updateBy})
        </foreach>
    </insert>


    <update id="updateByPrimaryKey" parameterType="com.xhpc.activity.domain.XhpcActivityFormulaDomain">
        update xhpc_activity_formula
        set activity_id     = #{activityId,jdbcType=INTEGER},
            start_time      = #{startTime},
            end_time        = #{endTime},
            power_price   = #{powerPrice},
            service_price   = #{servicePrice},
            compute_formula = upper(#{computeFormula}),
            update_time     = sysdate(),
            update_by       = #{updateBy,jdbcType=VARCHAR}
        where activity_formula_id = #{activityComputeId,jdbcType=BIGINT}
    </update>

</mapper>