You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.9 KiB
169 lines
6.9 KiB
package com.example.demo.serviceImpl;
|
|
|
|
|
|
import com.example.demo.Util.CheckIfNullUtil;
|
|
import com.example.demo.domain.vo.Meium;
|
|
import com.example.demo.domain.vo.Statistics;
|
|
import com.example.demo.domain.vo.Statisticss;
|
|
import com.example.demo.domain.vo.SumCoin;
|
|
import com.example.demo.mapper.StatisticsMapper;
|
|
import com.example.demo.sevice.StatisticsService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.List;
|
|
|
|
@RequiredArgsConstructor
|
|
@Transactional
|
|
@Service
|
|
@CacheConfig(cacheNames = "statistics")
|
|
public class StatisticsServiceImpl implements StatisticsService {
|
|
private final StatisticsMapper statisticsMapper;
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public Statistics getStatistics() {
|
|
Statistics statistics = new Statistics();
|
|
|
|
// 全年累计数据
|
|
Statistics yearStats = CheckIfNullUtil.defaultIfNull( statisticsMapper.getTotalYearCoin(), new Statistics());
|
|
statistics.setRechargeSumCoin(yearStats.getRechargeSumCoin());
|
|
statistics.setFreeSumCoin(yearStats.getFreeSumCoin());
|
|
statistics.setTaskSumCoin(yearStats.getTaskSumCoin());
|
|
statistics.setTotalSumCoin(yearStats.getTotalSumCoin());
|
|
|
|
// 昨日新增数据
|
|
Statistics yesterdayStats = CheckIfNullUtil.defaultIfNull( statisticsMapper.getYesterdayNewCoin(), new Statistics());
|
|
statistics.setRechargeYesterdaySumCoin(yesterdayStats.getRechargeYesterdaySumCoin());
|
|
statistics.setFreeYesterdaySumCoin(yesterdayStats.getFreeYesterdaySumCoin());
|
|
statistics.setTaskYesterdaySumCoin(yesterdayStats.getTaskYesterdaySumCoin());
|
|
statistics.setTotalYesterdaySumCoin(yesterdayStats.getTotalYesterdaySumCoin());
|
|
// 年累计充值人数
|
|
statistics.setRechargeCount(statisticsMapper.getYearRechargeCount());
|
|
|
|
// 本周和上周充值人数
|
|
int thisWeekCount = statisticsMapper.getRechargeCountThisWeek();
|
|
int lastWeekCount = statisticsMapper.getRechargeCountLastWeek();
|
|
statistics.setRechargeCountThisWeek(thisWeekCount);
|
|
statistics.setRechargeCountLastWeek(lastWeekCount);
|
|
|
|
// 周同比计算
|
|
BigDecimal weekOverWeekRate = BigDecimal.ZERO;//初始化为 0 表示如果没有足够的数据(如 lastWeekCount == 0),默认周同比增长率为 0。
|
|
if (lastWeekCount > 0) {
|
|
weekOverWeekRate = BigDecimal.valueOf((double) (thisWeekCount - lastWeekCount) / lastWeekCount * 100)//将计算结果转换为 BigDecimal 类型,保证高精度。
|
|
.setScale(2, BigDecimal.ROUND_HALF_UP); // 保留两位小数
|
|
}
|
|
statistics.setWeekOverWeekRate(weekOverWeekRate);
|
|
|
|
//今日和昨日充值人数
|
|
int todayCount = statisticsMapper.getRechargeCountToday();
|
|
int yesterdayCount = statisticsMapper.getRechargeCountYesterday();
|
|
int firstYesterdayCount =statisticsMapper.getFirstRechargeCountYesterday();
|
|
statistics.setRechargeCountToday(todayCount);
|
|
statistics.setRechargeCountYesterday(yesterdayCount);
|
|
statistics.setFirstRechargeCountYesterday(firstYesterdayCount);
|
|
|
|
//日环比计算
|
|
BigDecimal dayOverDayRate = BigDecimal.ZERO;
|
|
if (yesterdayCount > 0) {
|
|
dayOverDayRate = BigDecimal.valueOf((double) (todayCount - yesterdayCount) / yesterdayCount * 100).
|
|
setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
}
|
|
statistics.setDayOverDayRate(dayOverDayRate);
|
|
|
|
return statistics;
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public Statisticss stats() {
|
|
Statisticss a = new Statisticss();
|
|
a.setCoinSystemSum(statisticsMapper.getCoinSystemSum());
|
|
a.setERPSum(statisticsMapper.getERPSum());
|
|
a.setHomilyChartSum(statisticsMapper.getHomilyChartSum());
|
|
a.setHomilyLinkSum(statisticsMapper.getHomilyLinkSum());
|
|
return a;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------------------------//
|
|
@Cacheable(key="#root.method.name")
|
|
public SumCoin getSumCoin(){
|
|
return statisticsMapper.getSumCoin();
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public SumCoin getYearConsumeCoin() {
|
|
return statisticsMapper.getYearConsumeCoin();
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public SumCoin getDayConsumeCoin() {
|
|
return statisticsMapper.getDayConsumeCoin();
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public List<SumCoin> getMediuPayCoin() {
|
|
return statisticsMapper.getMediuPayCoin();
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public List<SumCoin> getMediuConsumeCoin() {
|
|
return statisticsMapper.getMediuConsumeCoin();
|
|
}
|
|
public SumCoin getMess(Integer jwcode){
|
|
return statisticsMapper.getMess(jwcode);
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public List<SumCoin> getMediumAreaPay() {
|
|
return statisticsMapper.getMediumAreaPay();
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public List<SumCoin> getMediumAreaConsume() {
|
|
return statisticsMapper.getMediumAreaConsume();
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public List<Meium> getMee( Meium meium) {
|
|
|
|
|
|
if("充值".equals(meium.getUpdateType())){
|
|
if("免费金币".equals(meium.getType())){
|
|
return statisticsMapper.getBuyAndFree(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}else if("充值金币".equals(meium.getType())){
|
|
return statisticsMapper.getBuyAndRecharge(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}else if("任务金币".equals(meium.getType())){
|
|
return statisticsMapper.getBuyAndTask(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}else{
|
|
return statisticsMapper.getBuy(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}
|
|
|
|
}else if("消费".equals(meium.getUpdateType())){
|
|
if("免费金币".equals(meium.getType())){
|
|
return statisticsMapper.getPayAndFree(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}else if("充值金币".equals(meium.getType())){
|
|
return statisticsMapper.getPayAndRecharge(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}else if("任务金币".equals(meium.getType())){
|
|
return statisticsMapper.getPayAndTask(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}else{
|
|
return statisticsMapper.getPay(meium.getSearchStartTime(),meium.getSearchEndTime());
|
|
}
|
|
|
|
} else{ return null;}
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public List<SumCoin> getMediu() {
|
|
return statisticsMapper.getMediu();
|
|
}
|
|
|
|
|
|
}
|