<?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.tongran.system.mapper.EpsTaskStatisticsMapper">

    <resultMap type="EpsTaskStatistics" id="EpsTaskStatisticsResult">
        <result property="id"    column="id"    />
        <result property="taskName"    column="task_name"    />
        <result property="businessCode"    column="business_code"    />
        <result property="businessName"    column="business_name"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="percentile95"    column="percentile_95"    />
        <result property="monthlyAvgPercentile95"    column="monthly_avg_percentile_95"    />
        <result property="resourceType"    column="resource_type"    />
        <result property="includedResources"    column="included_resources"    />
        <result property="calculationType"    column="calculation_type"    />
        <result property="calculationMode"    column="calculation_mode"    />
        <result property="taskStatus"    column="task_status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectEpsTaskStatisticsVo">
        select id, task_name, business_code, business_name, start_time, end_time, percentile_95, monthly_avg_percentile_95, resource_type, included_resources, calculation_type, calculation_mode, task_status, create_time, update_time, create_by, update_by from eps_task_statistics
    </sql>

    <select id="selectEpsTaskStatisticsList" parameterType="EpsTaskStatistics" resultMap="EpsTaskStatisticsResult">
        <include refid="selectEpsTaskStatisticsVo"/>
        <where>
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
            <if test="businessCode != null  and businessCode != ''"> and business_code = #{businessCode}</if>
            <if test="businessName != null  and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
            <if test="startTime != null  and startTime != ''"> and start_time = #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and end_time = #{endTime}</if>
            <if test="percentile95 != null "> and percentile_95 = #{percentile95}</if>
            <if test="monthlyAvgPercentile95 != null "> and monthly_avg_percentile_95 = #{monthlyAvgPercentile95}</if>
            <if test="resourceType != null  and resourceType != ''"> and resource_type = #{resourceType}</if>
            <if test="includedResources != null  and includedResources != ''"> and included_resources = #{includedResources}</if>
            <if test="calculationType != null  and calculationType != ''"> and calculation_type = #{calculationType}</if>
            <if test="calculationMode != null  and calculationMode != ''"> and calculation_mode = #{calculationMode}</if>
            <if test="taskStatus != null  and taskStatus != ''"> and task_status = #{taskStatus}</if>
        </where>
    </select>

    <select id="selectEpsTaskStatisticsById" parameterType="Long" resultMap="EpsTaskStatisticsResult">
        <include refid="selectEpsTaskStatisticsVo"/>
        where id = #{id}
    </select>

    <insert id="insertEpsTaskStatistics" parameterType="EpsTaskStatistics" useGeneratedKeys="true" keyProperty="id">
        insert into eps_task_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">task_name,</if>
            <if test="businessCode != null">business_code,</if>
            <if test="businessName != null and businessName != ''">business_name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="percentile95 != null">percentile_95,</if>
            <if test="monthlyAvgPercentile95 != null">monthly_avg_percentile_95,</if>
            <if test="resourceType != null">resource_type,</if>
            <if test="includedResources != null">included_resources,</if>
            <if test="calculationType != null">calculation_type,</if>
            <if test="calculationMode != null">calculation_mode,</if>
            <if test="taskStatus != null and taskStatus != ''">task_status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">#{taskName},</if>
            <if test="businessCode != null">#{businessCode},</if>
            <if test="businessName != null and businessName != ''">#{businessName},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="percentile95 != null">#{percentile95},</if>
            <if test="monthlyAvgPercentile95 != null">#{monthlyAvgPercentile95},</if>
            <if test="resourceType != null">#{resourceType},</if>
            <if test="includedResources != null">#{includedResources},</if>
            <if test="calculationType != null">#{calculationType},</if>
            <if test="calculationMode != null">#{calculationMode},</if>
            <if test="taskStatus != null and taskStatus != ''">#{taskStatus},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateEpsTaskStatistics" parameterType="EpsTaskStatistics">
        update eps_task_statistics
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskName != null and taskName != ''">task_name = #{taskName},</if>
            <if test="businessCode != null">business_code = #{businessCode},</if>
            <if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="percentile95 != null">percentile_95 = #{percentile95},</if>
            <if test="monthlyAvgPercentile95 != null">monthly_avg_percentile_95 = #{monthlyAvgPercentile95},</if>
            <if test="resourceType != null">resource_type = #{resourceType},</if>
            <if test="includedResources != null">included_resources = #{includedResources},</if>
            <if test="calculationType != null">calculation_type = #{calculationType},</if>
            <if test="calculationMode != null">calculation_mode = #{calculationMode},</if>
            <if test="taskStatus != null and taskStatus != ''">task_status = #{taskStatus},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEpsTaskStatisticsById" parameterType="Long">
        delete from eps_task_statistics where id = #{id}
    </delete>

    <delete id="deleteEpsTaskStatisticsByIds" parameterType="String">
        delete from eps_task_statistics where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>