<?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.chinamobile.epic.dao.mapper.BusinessAnalysisMapper">
<resultMap id="BaseResultMap" type="com.chinamobile.epic.dao.model.PerformanceMetricAnalysis">
<id column="dimension_id" property="dimensionId" jdbcType="CHAR"/>
<id column="indicator_key" property="indicatorKey" jdbcType="VARCHAR"/>
<id column="create_at" property="createAt" jdbcType="TIMESTAMP"/>
<result column="pool_id" property="poolId" jdbcType="CHAR"/>
<result column="value" property="value" jdbcType="DOUBLE"/>
<result column="resource_type" property="resourceType" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
pool_id, dimension_id, indicator_key, value, resource_type, create_at
</sql>
<sql id="Base_Column_List_sumValue">
pool_id, dimension_id, indicator_key, sum(value) as value, resource_type, create_at
</sql>
<sql id="Base_Column_List_avgValue">
pool_id, dimension_id, indicator_key, avg(value) as value, resource_type, create_at
</sql>
<sql id="Base_Column_List_maxValue">
pool_id, dimension_id, indicator_key, max(value) as value, resource_type, create_at
</sql>
<sql id="Aggregation_Group_By">
dimension_id, indicator_key
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="com.chinamobile.epic.dao.model.PerformanceMetricAnalysisModel">
select
<include refid="Base_Column_List"/>
from performance_metirc_business_${tableNameSuffix}
where dimension_id = #{dimensionId,jdbcType=CHAR}
and indicator_key = #{indicatorKey,jdbcType=VARCHAR}
and create_at = #{createAt,jdbcType=TIMESTAMP}
</select>
<select id="groupByDimensionIDAndIndicatorID" resultMap="BaseResultMap">
select
<if test='func=="avg"'>
<include refid="Base_Column_List_avgValue"/>
</if>
<if test='func=="sum"'>
<include refid="Base_Column_List_sumValue"/>
</if>
from ${srcTableName}
where create_at >= #{startTime,jdbcType=TIMESTAMP}
and create_at <= #{endTime,jdbcType=TIMESTAMP}
GROUP BY
<include refid="Aggregation_Group_By"/>
</select>
<!-- 这种方式可能不准确,应该使用求last的方式: 见下面-->
<!--<select id="groupCounterDataByDimensionIndicator" resultMap="BaseResultMap">-->
<!--select-->
<!--<include refid="Base_Column_List_maxValue"/>-->
<!--from ${srcTableName}-->
<!--where create_at >= #{startTime,jdbcType=TIMESTAMP}-->
<!--and create_at <= #{endTime,jdbcType=TIMESTAMP}-->
<!--<choose>-->
<!--<when test="list != null and list.size()>0">-->
<!--and indicator_key in-->
<!--<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">-->
<!--#{item,jdbcType=CHAR}-->
<!--</foreach>-->
<!--</when>-->
<!--<otherwise>-->
<!--and indicator_key in('Unknown')-->
<!--</otherwise>-->
<!--</choose>-->
<!--GROUP BY-->
<!--<include refid="Aggregation_Group_By"/>-->
<!--</select>-->
<select id="groupCounterDataByDimensionIndicator" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from
(
SELECT * FROM ${srcTableName}
WHERE create_at >= #{startTime,jdbcType=TIMESTAMP}
and create_at <= #{endTime,jdbcType=TIMESTAMP}
<choose>
<when test="list != null and list.size()>0">
and indicator_key in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item,jdbcType=CHAR}
</foreach>
</when>
<otherwise>
and indicator_key in('Unknown')
</otherwise>
</choose>
ORDER BY create_at DESC
) AS t
GROUP BY
<include refid="Aggregation_Group_By"/>
</select>
<select id="groupGaugeDataByDimensionIndicator" resultMap="BaseResultMap">
select
<include refid="Base_Column_List_avgValue"/>
from ${srcTableName}
where create_at >= #{startTime,jdbcType=TIMESTAMP}
and create_at <= #{endTime,jdbcType=TIMESTAMP}
<choose>
<when test="list != null and list.size()>0">
and indicator_key in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item,jdbcType=CHAR}
</foreach>
</when>
<otherwise>
and indicator_key in('Unknown')
</otherwise>
</choose>
GROUP BY
<include refid="Aggregation_Group_By"/>
</select>
<delete id="deleteByPrimaryKey" parameterType="com.chinamobile.epic.dao.model.PerformanceMetricAnalysisModel">
delete from performance_metirc_business_${tableNameSuffix}
where dimension_id = #{dimensionId,jdbcType=CHAR}
and indicator_key = #{indicatorKey,jdbcType=VARCHAR}
and create_at = #{createAt,jdbcType=TIMESTAMP}
</delete>
<delete id="deleteBeforeTime">
delete from performance_metirc_business_${tableNameSuffix}
where create_at <= #{createAt,jdbcType=TIMESTAMP}
</delete>
<insert id="insert" parameterType="com.chinamobile.epic.dao.model.PerformanceMetricAnalysisModel">
insert into performance_metirc_business_${tableNameSuffix} (dimension_id, indicator_key, create_at, pool_id, value, resource_type )
values (#{dimensionId,jdbcType=CHAR}, #{indicatorKey,jdbcType=VARCHAR}, #{createAt,jdbcType=TIMESTAMP},
#{poolId,jdbcType=CHAR}, #{value,jdbcType=DOUBLE}, #{resourceType,jdbcType=VARCHAR}
)
</insert>
<insert id="insertBatch">
insert into performance_metirc_business_${tableNameSuffix} (dimension_id, indicator_key, create_at, pool_id, value, resource_type )
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.dimensionId,jdbcType=CHAR}, #{item.indicatorKey,jdbcType=VARCHAR}, #{item.createAt,jdbcType=TIMESTAMP},
#{item.poolId,jdbcType=CHAR}, #{item.value,jdbcType=DOUBLE}, #{item.resourceType,jdbcType=VARCHAR} )
</foreach>
</insert>
<insert id="insertSelective" parameterType="com.chinamobile.epic.dao.model.PerformanceMetricAnalysisModel">
insert into performance_metirc_business_${tableNameSuffix}
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="poolId != null">
pool_id,
</if>
<if test="dimensionId != null">
dimension_id,
</if>
<if test="indicatorKey != null">
indicator_key,
</if>
<if test="value != null">
value,
</if>
<if test="resourceType != null">
resource_type,
</if>
<if test="createAt != null">
create_at,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="poolId != null">
#{poolId,jdbcType=CHAR},
</if>
<if test="dimensionId != null">
#{dimensionId,jdbcType=CHAR},
</if>
<if test="indicatorKey != null">
#{indicatorKey,jdbcType=VARCHAR},
</if>
<if test="value != null">
#{value,jdbcType=DOUBLE},
</if>
<if test="resourceType != null">
#{resourceType,jdbcType=VARCHAR},
</if>
<if test="createAt != null">
#{createAt,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.chinamobile.epic.dao.model.PerformanceMetricAnalysisModel">
update performance_metirc_business_${tableNameSuffix}
<set>
<if test="poolId != null">
pool_id = #{poolId,jdbcType=CHAR},
</if>
<if test="value != null">
value = #{value,jdbcType=DOUBLE},
</if>
<if test="resourceType != null">
resource_type = #{resourceType,jdbcType=VARCHAR},
</if>
</set>
where dimension_id = #{dimensionId,jdbcType=CHAR}
and indicator_key = #{indicatorKey,jdbcType=VARCHAR}
and create_at = #{createAt,jdbcType=TIMESTAMP}
</update>
<update id="updateByPrimaryKey" parameterType="com.chinamobile.epic.dao.model.PerformanceMetricAnalysisModel">
update performance_metirc_business_${tableNameSuffix}
set pool_id = #{poolId,jdbcType=CHAR},
value = #{value,jdbcType=DOUBLE},
resource_type = #{resourceType,jdbcType=VARCHAR}
where dimension_id = #{dimensionId,jdbcType=CHAR}
and indicator_key = #{indicatorKey,jdbcType=VARCHAR}
and create_at = #{createAt,jdbcType=TIMESTAMP}
</update>
</mapper>