1.获取一段时间内,每天的接口总调用量,5分钟平均调用量 <select id="queryRangeTimeAvgCount" parameterType="Map" resultMap="rangeTimeDayAvg"> <![CDATA[ SELECT day_num, MAX(totalCount) AS max_count, SUM(totalCount) AS total_count, AVG(totalCount) AS avg_count FROM (SELECT count_index, day_num, SUM(count) AS totalCount FROM api_counter WHERE day_num >= ${startDayNum} AND day_num < ${endDayNum} ]]> <if test="methodId != null">AND method_id = #{methodId}</if> <![CDATA[ GROUP BY day_num, count_index) AS result GROUP BY day_num DESC ]]> </select> 2.<!--查看每个接口某一天的调用详情 按sum降序排序--> <select id="getOverviewOneDay" parameterType="int" resultMap="apiOverviewResponse"> <![CDATA[ SELECT api_o.method_id,api_m.name,api_m.version,api_m.description,api_o.sum,api_o.day_num,api_o.status FROM api_overview api_o LEFT JOIN api_method api_m ON api_m.id =api_o.method_id WHERE day_num =#{dayNum} ORDER BY sum DESC; ]]> </select> 3.<!--分页查看每个接口某一天的调用详情 按sum降序排序--> <select id="queryPaging" parameterType="java.util.Map" resultMap="apiOverview"> <![CDATA[ SELECT api_o.method_id,api_m.name,api_m.version,api_m.description,api_o.sum,api_o.day_num,api_o.status FROM api_overview api_o LEFT JOIN api_method api_m ON api_m.id =api_o.method_id WHERE day_num =#{searchParam.dayNum} ]]> <if test="searchParam.methodId != null"> AND api_o.method_id = #{searchParam.methodId} </if> <if test="searchParam.methodName != null"> AND api_m.`name` LIKE CONCAT('%','${searchParam.methodName}','%' ) </if> <if test="searchParam.status != null"> AND api_o.status = #{searchParam.status} </if> <![CDATA[ ORDER BY ${sortRow} ${sortMethod} LIMIT ${offset}, ${pageSize}; ]]> </select>4.分组之后再分页,接口平均调用时常<select id = "queryPaging" parameterType="java.util.Map" resultMap= "statPerformance"> <![CDATA[ SELECT id,method_id,name,version,description,avg_cost_time,avg_success_rate,count_index,day_num,create_time FROM ( SELECT sp.id, sp.method_id,am.`name`,am.version, am.description,AVG(sp.cost_time) AS avg_cost_time,AVG(sp.rate) AS avg_success_rate, sp.count_index, sp.day_num,sp.create_time FROM api_method am,stat_performance sp WHERE sp.method_id = am.id AND sp.day_num = #{searchParam.dayNum} ]]> <if test="searchParam.methodId != null"> AND method_id = #{searchParam.methodId} </if> <if test="searchParam.methodName != null"> AND am.`name` LIKE CONCAT('%','${searchParam.methodName}','%' ) </if> <![CDATA[ GROUP BY sp.method_id ORDER BY ${sortRow} ${sortMethod} ) a ]]> <if test="searchParam.startSpentTime != null and searchParam.endSpentTime != null"> <![CDATA[ WHERE avg_cost_time >= #{searchParam.startSpentTime} AND avg_cost_time <= #{searchParam.endSpentTime}]]> </if> <![CDATA[ LIMIT ${offset}, ${pageSize}; ]]> </select>
mybatis一些实现总结
最新推荐文章于 2019-05-11 15:20:55 发布