后台统计-统计-公会

This commit is contained in:
khalil
2025-02-14 20:55:50 +08:00
parent 96d7e3cc75
commit 3b45f1b49a
9 changed files with 267 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
package com.accompany.business.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class WeekActiveGuildStat {
private String date;
private String endDate;
private Integer partitionId;
private Integer guildId;
@TableField(exist = false)
private String groupByKey;
private Integer activeMemberCount;
private BigDecimal guildDiamondFlow;
private BigDecimal guildGoldFlow;
private BigDecimal lastGuildDiamondFlow;
private BigDecimal lastGuildGoldFlow;
private BigDecimal guildDiamondFlowWow;
private BigDecimal guildGoldFlowWow;
}

View File

@@ -0,0 +1,58 @@
package com.accompany.business.model;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@ApiModel
@Data
public class WeekGuildStat {
@TableId
@ApiModelProperty("日期")
private String date;
@ApiModelProperty("周日")
private String endDate;
@ApiModelProperty("平台总新增")
private Integer totalNewCount;
@ApiModelProperty("英语区变动")
private Integer enNewCount;
@ApiModelProperty("英语区变动详细分类")
private String enNewCountDetail;
@ApiModelProperty("阿拉伯区变动")
private Integer arNewCount;
@ApiModelProperty("阿拉伯区变动详细分类")
private String arNewCountDetail;
@ApiModelProperty("华语区变动")
private Integer zhNewCount;
@ApiModelProperty("华语区变动详细分类")
private String zhNewCountDetail;
@ApiModelProperty("土耳其区变动")
private Integer trNewCount;
@ApiModelProperty("土耳其区变动详细分类")
private String trNewCountDetail;
@ApiModelProperty("平台总活跃")
private Integer totalActiveCount;
@ApiModelProperty("英语区活跃")
private Integer enActiveCount;
@ApiModelProperty("英语区活跃详细")
private String enActiveCountDetail;
@ApiModelProperty("阿拉伯区活跃")
private Integer arActiveCount;
@ApiModelProperty("阿拉伯区活跃详细")
private String arActiveCountDetail;
@ApiModelProperty("华语区活跃")
private Integer zhActiveCount;
@ApiModelProperty("华语区活跃详细")
private String zhActiveCountDetail;
@ApiModelProperty("土耳其区活跃")
private Integer trActiveCount;
@ApiModelProperty("土耳其区活跃详细")
private String trActiveCountDetail;
}

View File

@@ -0,0 +1,10 @@
package com.accompany.business.mybatismapper;
import com.accompany.business.dto.WeekActiveGuildStat;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WeekActiveGuildStatMapper extends BaseMapper<WeekActiveGuildStat> {
}

View File

@@ -0,0 +1,10 @@
package com.accompany.business.mybatismapper;
import com.accompany.business.model.WeekGuildStat;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WeekGuildStatMapper extends BaseMapper<WeekGuildStat> {
}

View File

@@ -0,0 +1,118 @@
package com.accompany.business.service;
import com.accompany.business.dto.WeekActiveGuildStat;
import com.accompany.business.model.WeekGuildStat;
import com.accompany.business.mybatismapper.WeekGuildStatMapper;
import com.accompany.business.mybatismapper.WeekActiveGuildStatMapper;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.enumeration.PartitionEnum;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class WeekGuildStatService {
@Autowired
private WeekNewGuildStatService weekNewGuildStatService;
@Autowired
private WeekActiveGuildMemberStatService weekActiveGuildMemberStatService;
@Autowired
private WeekGuildStatMapper guildWeekPlatformStatMapper;
@Autowired
private WeekActiveGuildStatMapper weekActiveGuildStatMapper;
public void stat(String monday) {
String sunday = DateTimeUtil.convertDate(DateTimeUtil.addDays(DateTimeUtil.convertStrToDate(monday, DateTimeUtil.DEFAULT_DATE_PATTERN), 6));
Map<String, Number> diamondCountMap = weekActiveGuildMemberStatService.getDiamondCountMap(monday).readAllMap();
Map<String, Number> goldCountMap = weekActiveGuildMemberStatService.getGoldCountMap(monday).readAllMap();
List<WeekActiveGuildStat> memberStatDtoList = goldCountMap.entrySet().stream().map(entry->{
String key = entry.getKey();
String[] keyArray = key.split("_");
WeekActiveGuildStat dto = new WeekActiveGuildStat();
dto.setDate(monday);
dto.setEndDate(sunday);
dto.setPartitionId(Integer.valueOf(keyArray[0]));
dto.setGuildId(Integer.valueOf(keyArray[1]));
dto.setGroupByKey(String.join("_", keyArray[1], keyArray[0]));
dto.setGuildDiamondFlow(diamondCountMap.containsKey(key)? new BigDecimal(diamondCountMap.get(key).toString()): BigDecimal.ZERO);
dto.setGuildGoldFlow(new BigDecimal(entry.getValue().toString()));
return dto;
}).collect(Collectors.toList());
Map<String, Integer> activeMemberCountMap = memberStatDtoList.stream().collect(Collectors.groupingBy(WeekActiveGuildStat::getGroupByKey, Collectors.summingInt(dto->1)));
Map<String, BigDecimal> diamondFlowMap = memberStatDtoList.stream().collect(Collectors.groupingBy(WeekActiveGuildStat::getGroupByKey, Collectors.reducing(BigDecimal.ZERO, WeekActiveGuildStat::getGuildDiamondFlow, BigDecimal::add)));
Map<String, BigDecimal> goldFlowMap = memberStatDtoList.stream().collect(Collectors.groupingBy(WeekActiveGuildStat::getGroupByKey, Collectors.reducing(BigDecimal.ZERO, WeekActiveGuildStat::getGuildGoldFlow, BigDecimal::add)));
List<WeekActiveGuildStat> activeGuildStatList = memberStatDtoList.stream().map(WeekActiveGuildStat::getGroupByKey)
.distinct()
.map(key->{
WeekActiveGuildStat dto = new WeekActiveGuildStat();
dto.setDate(monday);
dto.setEndDate(sunday);
String[] keyArray = key.split("_");
dto.setPartitionId(Integer.valueOf(keyArray[0]));
dto.setGuildId(Integer.valueOf(keyArray[1]));
dto.setActiveMemberCount(activeMemberCountMap.get(key));
dto.setGuildDiamondFlow(diamondFlowMap.get(key));
dto.setGuildGoldFlow(goldFlowMap.get(key));
return dto;
}).collect(Collectors.toList());
weekActiveGuildStatMapper.insert(activeGuildStatList);
WeekGuildStat stat = new WeekGuildStat();
stat.setDate(monday);
stat.setEndDate(sunday);
Map<Integer, Integer> newGuildCountMap = weekNewGuildStatService.getCountMap(monday).readAllKeySet().stream()
.map(key->key.split("_")[0]).collect(Collectors.groupingBy(Integer::parseInt, Collectors.summingInt(key->1)));
stat.setTotalNewCount((int) newGuildCountMap.values().stream().mapToLong(Integer::intValue).sum());
stat.setEnNewCount(newGuildCountMap.getOrDefault(PartitionEnum.ENGLISH.getId(), 0));
stat.setArNewCount(newGuildCountMap.getOrDefault(PartitionEnum.ARAB.getId(), 0));
stat.setZhNewCount(newGuildCountMap.getOrDefault(PartitionEnum.CHINESS.getId(), 0));
stat.setTrNewCount(newGuildCountMap.getOrDefault(PartitionEnum.TURKEY.getId(), 0));
stat.setTotalActiveCount(activeGuildStatList.size());
Map<Integer, List<WeekActiveGuildStat>> activeGuildPartitionMap = activeGuildStatList.stream().collect(Collectors.groupingBy(WeekActiveGuildStat::getPartitionId));
List<WeekActiveGuildStat> enActiveGuildList = activeGuildPartitionMap.get(PartitionEnum.ENGLISH.getId());
stat.setEnActiveCount(enActiveGuildList.size());
stat.setEnActiveCountDetail(JSON.toJSONString(enActiveGuildList));
List<WeekActiveGuildStat> arActiveGuildList = activeGuildPartitionMap.get(PartitionEnum.ARAB.getId());
stat.setArActiveCount(arActiveGuildList.size());
stat.setArActiveCountDetail(JSON.toJSONString(arActiveGuildList));
List<WeekActiveGuildStat> zhActiveGuildList = activeGuildPartitionMap.get(PartitionEnum.CHINESS.getId());
stat.setZhActiveCount(zhActiveGuildList.size());
stat.setZhActiveCountDetail(JSON.toJSONString(zhActiveGuildList));
List<WeekActiveGuildStat> trActiveGuildList = activeGuildPartitionMap.get(PartitionEnum.TURKEY.getId());
stat.setTrActiveCount(trActiveGuildList.size());
stat.setTrActiveCountDetail(JSON.toJSONString(trActiveGuildList));
guildWeekPlatformStatMapper.insert(stat);
}
}

View File

@@ -17,13 +17,13 @@ public class WeekNewGuildStatService {
public void mark(Integer partitionId, Integer guildId, Date now) {
String key = String.join("_", partitionId.toString(), guildId.toString());
RMap<String, Date> countMap = getCountMap(now);
String monday = DateTimeUtil.convertDate(DateTimeUtil.getMondayDate(now));
RMap<String, Date> countMap = getCountMap(monday);
countMap.fastPutIfAbsent(key, now);
countMap.expire(DateTimeUtil.addDays(now, 14).toInstant());
}
public RMap<String, Date> getCountMap(Date date) {
String monday = DateTimeUtil.convertDate(DateTimeUtil.getMondayDate(date));
public RMap<String, Date> getCountMap(String monday) {
return redissonClient.getMap(RedisKey.week_new_guild_count.getKey(monday));
}

View File

@@ -0,0 +1,5 @@
<?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.accompany.business.mybatismapper.WeekActiveGuildStatMapper">
</mapper>

View File

@@ -0,0 +1,5 @@
<?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.accompany.business.mybatismapper.WeekGuildStatMapper">
</mapper>

View File

@@ -0,0 +1,29 @@
package com.accompany.scheduler.task;
import com.accompany.business.service.WeekActiveGuildMemberStatService;
import com.accompany.business.service.WeekGuildStatService;
import com.accompany.business.service.WeekNewGuildStatService;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.scheduler.base.BaseTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
@Slf4j
public class GuildWeekStatTask extends BaseTask {
@Autowired
private WeekGuildStatService weekGuildStatService;
@Scheduled(cron = "1 0 0 ? * MON")
public void statWeek() {
Date yesterday = DateTimeUtil.addDays(new Date(), -1);
String yesterdayStr = DateTimeUtil.convertDate(DateTimeUtil.getMondayDate(yesterday));
weekGuildStatService.stat(yesterdayStr);
}
}