幸运24-统计-强制使用索引
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
package com.accompany.sharding.config;
|
||||
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.common.utils.EnvComponent;
|
||||
import com.accompany.common.utils.ResourceUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
|
||||
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
|
||||
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
|
||||
@@ -19,15 +14,10 @@ import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleC
|
||||
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
|
||||
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
|
||||
import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
@@ -42,9 +32,6 @@ import java.util.*;
|
||||
@Configuration
|
||||
public class ShardingSphereConfig {
|
||||
|
||||
@Autowired
|
||||
private EnvComponent envComponent;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("masterDataSource")
|
||||
private DataSource masterDataSource;
|
||||
|
@@ -11,21 +11,22 @@ import java.util.List;
|
||||
|
||||
public interface Lucky24RecordMapper extends BaseMapper<Lucky24Record> {
|
||||
|
||||
List<Lucky24PlatformStat> listPlatform(@Param("partitionId") Integer partitionId, @Param("startTime") Date startTime, @Param("endTime") Date endTime,
|
||||
@Param("zoneIdHour") long zoneIdHour);
|
||||
List<Lucky24PlatformStat> listPlatform(@Param("zoneDate")String zoneDate, @Param("partitionId") Integer partitionId,
|
||||
@Param("poolTypeList")List<Integer> poolTypeList,
|
||||
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
List<Lucky24PlatformStat> listPlatformByPoolType(@Param("partitionId") Integer partitionId, @Param("poolType") Integer poolType,
|
||||
List<Lucky24PlatformStat> listPlatformByPoolType(@Param("zoneDate")String zonedDate, @Param("partitionId") Integer partitionId,
|
||||
@Param("poolTypeList")List<Integer> poolTypeList,
|
||||
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
List<Lucky24PersonalStat> listPersonal(@Param("zoneDate")String zoneDate, @Param("partitionId") Integer partitionId,
|
||||
@Param("poolTypeList")List<Integer> poolTypeList,
|
||||
@Param("startTime") Date startTime, @Param("endTime") Date endTime,
|
||||
@Param("uid") Long uid, @Param("userRechargeLevel") String userRechargeLevel);
|
||||
|
||||
List<Lucky24PersonalStat> listPersonalByPoolType(@Param("zoneDate")String zoneDate, @Param("partitionId") Integer partitionId,
|
||||
@Param("poolTypeList")List<Integer> poolTypeList,
|
||||
@Param("startTime") Date startTime, @Param("endTime") Date endTime,
|
||||
@Param("zoneIdHour") long zoneIdHour);
|
||||
|
||||
List<Lucky24PersonalStat> listPersonal(@Param("partitionId") Integer partitionId,
|
||||
@Param("uid") Long uid,
|
||||
@Param("userRechargeLevel") String userRechargeLevel, @Param("startTime") Date startTime, @Param("endTime") Date endTime,
|
||||
@Param("zoneIdHour") long zoneIdHour);
|
||||
|
||||
List<Lucky24PersonalStat> listPersonalByPoolType(@Param("partitionId") Integer partitionId,
|
||||
@Param("uid") Long uid, @Param("userRechargeLevel") String userRechargeLevel, @Param("poolType") Integer poolType,
|
||||
@Param("startTime") Date startTime, @Param("endTime") Date endTime,
|
||||
@Param("zoneIdHour") long zoneIdHour);
|
||||
@Param("uid") Long uid, @Param("userRechargeLevel") String userRechargeLevel);
|
||||
|
||||
}
|
||||
|
@@ -3,100 +3,112 @@
|
||||
<mapper namespace="com.accompany.sharding.mapper.Lucky24RecordMapper">
|
||||
|
||||
<select id="listPlatform" resultType="com.accompany.sharding.vo.Lucky24PlatformStat">
|
||||
select `date`, partition_id, 0 as pool_type,
|
||||
sum(`totalInput`) `totalInput`, sum(`totalOutput`) `totalOutput`,
|
||||
sum(`totalOutput`) / sum(`totalInput`) `productionRatio`,
|
||||
count(*) `count`, count((IF(`maxOutput` > 0, 1, null))) `winCount`,
|
||||
sum(`num`) `num`, sum(`winNum`) `winNum`, sum(`winNum`) / sum(`num`) `winRate`
|
||||
select #{zoneDate} as `date`,
|
||||
#{partitionId} as partition_id,
|
||||
0 as pool_type,
|
||||
ifnull(sum(`totalInput`),0) `totalInput`,
|
||||
ifnull(sum(`totalOutput`),0) `totalOutput`,
|
||||
ifnull(sum(`totalOutput`) / sum(`totalInput`),0) `productionRatio`,
|
||||
count(*) `count`,
|
||||
count((IF(`maxOutput` > 0, 1, null))) `winCount`,
|
||||
ifnull(sum(`num`),0) `num`,
|
||||
ifnull(sum(`winNum`),0) `winNum`,
|
||||
ifnull(sum(`winNum`) / sum(`num`),0) `winRate`
|
||||
from (
|
||||
select date(date_add(r.create_time, INTERVAL #{zoneIdHour} HOUR)) `date`,
|
||||
partition_id,
|
||||
select
|
||||
sum(gift_num * gift_gold_price) `totalInput`,
|
||||
sum(win_gold_num) `totalOutput`,
|
||||
count(*) `num`,
|
||||
count((case when win_gold_num > 0 then 1 end)) `winNum`,
|
||||
max(win_gold_num) `maxOutput`
|
||||
from lucky_24_record r force index (lucky_24_record_partition_id_pool_type_create_time_uid_index)
|
||||
where r.partition_id = #{partitionId}
|
||||
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
|
||||
and r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
group by r.uid) r
|
||||
</select>
|
||||
|
||||
<select id="listPlatformByPoolType" resultType="com.accompany.sharding.vo.Lucky24PlatformStat">
|
||||
select #{zoneDate} as `date`,
|
||||
#{partitionId} as partition_id,
|
||||
pool_type,
|
||||
ifnull(sum(`totalInput`),0) `totalInput`,
|
||||
ifnull(sum(`totalOutput`),0) `totalOutput`,
|
||||
ifnull(sum(`totalOutput`) / sum(`totalInput`),0) `productionRatio`,
|
||||
count(*) `count`,
|
||||
count((IF(`maxOutput` > 0, 1, null))) `winCount`,
|
||||
ifnull(sum(`num`),0) `num`,
|
||||
ifnull(sum(`winNum`),0) `winNum`,
|
||||
ifnull(sum(`winNum`) / sum(`num`),0) `winRate`
|
||||
from (
|
||||
select
|
||||
r.pool_type,
|
||||
r.uid,
|
||||
sum(gift_num * gift_gold_price) `totalInput`,
|
||||
sum(win_gold_num) `totalOutput`,
|
||||
count(*) `num`,
|
||||
count((case when win_gold_num > 0 then 1 end)) `winNum`,
|
||||
max(win_gold_num) `maxOutput`
|
||||
from lucky_24_record r
|
||||
where r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
and r.partition_id = #{partitionId}
|
||||
group by `date`, uid) l
|
||||
group by `date`
|
||||
</select>
|
||||
|
||||
<select id="listPlatformByPoolType" resultType="com.accompany.sharding.vo.Lucky24PlatformStat">
|
||||
select `date`, partition_id, pool_type,
|
||||
sum(`totalInput`) `totalInput`, sum(`totalOutput`) `totalOutput`,
|
||||
sum(`totalOutput`) / sum(`totalInput`) `productionRatio`,
|
||||
count(*) `count`, count((IF(`maxOutput` > 0, 1, null))) `winCount`,
|
||||
sum(`num`) `num`, sum(`winNum`) `winNum`, sum(`winNum`) / sum(`num`) `winRate`
|
||||
from (
|
||||
select date(date_add(r.create_time, INTERVAL #{zoneIdHour} HOUR)) `date`,
|
||||
partition_id,
|
||||
pool_type,
|
||||
sum(gift_num * gift_gold_price) `totalInput`,
|
||||
sum(win_gold_num) `totalOutput`,
|
||||
count(*) `num`,
|
||||
count((case when win_gold_num > 0 then 1 end)) `winNum`,
|
||||
max(win_gold_num) `maxOutput`
|
||||
from lucky_24_record r
|
||||
where r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
and r.partition_id = #{partitionId}
|
||||
<if test="null != poolType">
|
||||
and r.pool_type = #{poolType}
|
||||
</if>
|
||||
group by `date`, uid, pool_type) l
|
||||
group by `date`, pool_type
|
||||
from lucky_24_record r force index (lucky_24_record_partition_id_pool_type_create_time_uid_index)
|
||||
where r.partition_id = #{partitionId}
|
||||
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
|
||||
and r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
group by r.pool_type, r.uid) r
|
||||
group by r.pool_type
|
||||
</select>
|
||||
|
||||
<select id="listPersonal" resultType="com.accompany.sharding.vo.Lucky24PersonalStat">
|
||||
select date(date_add(r.create_time, INTERVAL #{zoneIdHour} HOUR)) `date`, r.partition_id,
|
||||
r.uid, 0 as pool_type,
|
||||
sum(gift_num * gift_gold_price) `totalInput`,
|
||||
sum(win_gold_num) `totalOutput`,
|
||||
sum(gift_num * gift_gold_price) - sum(win_gold_num) `production`,
|
||||
sum(win_gold_num) / sum(gift_num * gift_gold_price) `productionRatio`,
|
||||
sum(gift_num * gift_gold_price) / count(*) `avgInput`,
|
||||
select #{zoneDate} as `date`,
|
||||
#{partitionId} as partition_id,
|
||||
0 as pool_type,
|
||||
r.uid,
|
||||
ifnull(sum(gift_num * gift_gold_price),0) `totalInput`,
|
||||
ifnull(sum(win_gold_num),0) `totalOutput`,
|
||||
ifnull(sum(gift_num * gift_gold_price) - sum(win_gold_num),0) `production`,
|
||||
ifnull(sum(win_gold_num) / sum(gift_num * gift_gold_price),0) `productionRatio`,
|
||||
ifnull(sum(gift_num * gift_gold_price) / count(*),0) `avgInput`,
|
||||
count(*) `num`,
|
||||
count((case when win_gold_num > 0 then r.uid else null end)) `winNum`,
|
||||
ifnull(count((case when win_gold_num > 0 then r.uid else null end)) / count(*),0) `winRate`
|
||||
from lucky_24_record r
|
||||
from lucky_24_record r force index (lucky_24_record_partition_id_pool_type_create_time_uid_index)
|
||||
<if test="null != userRechargeLevel and '' != userRechargeLevel">
|
||||
inner join users u on r.uid = u.uid
|
||||
inner join user_recharge_level url on u.uid = url.uid and url.level = #{userRechargeLevel}
|
||||
</if>
|
||||
where r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
<if test="null != uid">
|
||||
and r.uid = #{uid}
|
||||
</if>
|
||||
and r.partition_id = #{partitionId}
|
||||
group by `date`, r.uid
|
||||
</select>
|
||||
|
||||
<select id="listPersonalByPoolType" resultType="com.accompany.sharding.vo.Lucky24PersonalStat">
|
||||
select date(date_add(r.create_time, INTERVAL #{zoneIdHour} HOUR)) `date`, r.partition_id,
|
||||
r.uid, r.pool_type,
|
||||
sum(gift_num * gift_gold_price) `totalInput`,
|
||||
sum(win_gold_num) `totalOutput`,
|
||||
sum(gift_num * gift_gold_price) - sum(win_gold_num) `production`,
|
||||
sum(win_gold_num) / sum(gift_num * gift_gold_price) `productionRatio`,
|
||||
sum(gift_num * gift_gold_price) / count(*) `avgInput`,
|
||||
count(*) `num`,
|
||||
count((case when win_gold_num > 0 then r.uid else null end)) `winNum`,
|
||||
ifnull(count((case when win_gold_num > 0 then r.uid else null end)) / count(*),0) `winRate`
|
||||
from lucky_24_record r
|
||||
<if test="null != userRechargeLevel and '' != userRechargeLevel">
|
||||
inner join users u on r.uid = u.uid
|
||||
inner join user_recharge_level url on u.uid = url.uid and url.level = #{userRechargeLevel}
|
||||
</if>
|
||||
where r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
where r.partition_id = #{partitionId}
|
||||
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
|
||||
and r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
<if test="null != uid">
|
||||
and r.uid = #{uid}
|
||||
</if>
|
||||
<if test="null != poolType">
|
||||
and r.pool_type = #{poolType}
|
||||
group by r.uid
|
||||
</select>
|
||||
|
||||
<select id="listPersonalByPoolType" resultType="com.accompany.sharding.vo.Lucky24PersonalStat">
|
||||
select #{zoneDate} as `date`,
|
||||
#{partitionId} as partition_id,
|
||||
r.pool_type,
|
||||
r.uid,
|
||||
ifnull(sum(gift_num * gift_gold_price),0) `totalInput`,
|
||||
ifnull(sum(win_gold_num),0) `totalOutput`,
|
||||
ifnull(sum(gift_num * gift_gold_price) - sum(win_gold_num),0) `production`,
|
||||
ifnull(sum(win_gold_num) / sum(gift_num * gift_gold_price),0) `productionRatio`,
|
||||
ifnull(sum(gift_num * gift_gold_price) / count(*),0) `avgInput`,
|
||||
count(*) `num`,
|
||||
count((case when win_gold_num > 0 then r.uid else null end)) `winNum`,
|
||||
ifnull(count((case when win_gold_num > 0 then r.uid else null end)) / count(*),0) `winRate`
|
||||
from lucky_24_record r force index (lucky_24_record_partition_id_pool_type_create_time_uid_index)
|
||||
<if test="null != userRechargeLevel and '' != userRechargeLevel">
|
||||
inner join users u on r.uid = u.uid
|
||||
inner join user_recharge_level url on u.uid = url.uid and url.level = #{userRechargeLevel}
|
||||
</if>
|
||||
and r.partition_id = #{partitionId}
|
||||
group by `date`, r.uid, pool_type
|
||||
where r.partition_id = #{partitionId}
|
||||
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
|
||||
and r.create_time >= #{startTime} and r.create_time <= #{endTime}
|
||||
<if test="null != uid">
|
||||
and r.uid = #{uid}
|
||||
</if>
|
||||
group by r.pool_type, r.uid
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user