幸运24-后台-关注用户个人数据

This commit is contained in:
2025-09-27 20:59:03 +08:00
parent 481b034b3b
commit dc1f9ade6d
7 changed files with 151 additions and 49 deletions

View File

@@ -6,11 +6,13 @@ import com.accompany.admin.vo.luckybag.Lucky24PersonalStatVo;
import com.accompany.admin.vo.luckybag.Lucky24PlatformStatVo;
import com.accompany.admin.vo.luckybag.Lucky24RecordAdminVo;
import com.accompany.business.constant.Lucky24PoolTypeEnum;
import com.accompany.business.dto.lucky.Lucky24GiftConfig;
import com.accompany.business.model.Gift;
import com.accompany.business.model.lucky.Lucky24Pool;
import com.accompany.business.mybatismapper.lucky.Lucky24PoolMapper;
import com.accompany.business.mybatismapper.lucky.Lucky24StatMapper;
import com.accompany.business.service.gift.GiftService;
import com.accompany.business.service.gift.Lucky24GiftSendService;
import com.accompany.business.service.user.UsersService;
import com.accompany.common.result.PageResult;
import com.accompany.common.status.BusiStatus;
@@ -70,6 +72,8 @@ public class Lucky24RecordAdminService {
private Lucky24PoolMapper poolMapper;
@Autowired
private GiftService giftService;
@Autowired
private Lucky24GiftSendService lucky24GiftSendService;
private final Map<String, Function<Lucky24PersonalStat, Object>> fieldExtractors = Map.of(
"totalInput", Lucky24PersonalStat::getTotalInput,
@@ -165,25 +169,39 @@ public class Lucky24RecordAdminService {
}
@SneakyThrows
public Lucky24PersonalStatVo getPersonal(Integer partitionId, Long erbanNo, String date, String userRechargeLevel, Integer poolType,
public Lucky24PersonalStatVo getPersonal(Integer partitionId, List<Long> followUidList, Long erbanNo, String date, String userRechargeLevel, Integer poolType,
String sortCol, String sortOrder,
int pageNo, int pageSize) {
Page<Lucky24PersonalStat> page = new Page<>(pageNo, pageSize);
Long uid = null;
if (null != erbanNo){
List<Long> uidList = new ArrayList<>();
if (!CollectionUtils.isEmpty(followUidList)){
List<Users> followUsers = usersService.listUsersFromDbInUids(followUidList);
List<Long> partitionFollowUidList = followUsers.stream().filter(u->u.getPartitionId().equals(partitionId)).map(Users::getUid).toList();
if (CollectionUtils.isEmpty(partitionFollowUidList)){
return new Lucky24PersonalStatVo(new PageResult<>(page));
}
uidList.addAll(followUsers.stream().filter(u->u.getPartitionId().equals(partitionId)).map(Users::getUid).toList());
} else if (null != erbanNo){
Users u = usersService.getUserByErbanNo(erbanNo);
if (null == u || !u.getPartitionId().equals(partitionId)){
return new Lucky24PersonalStatVo(new PageResult<>(page));
}
uid = u.getUid();
uidList.add(u.getUid());
}
PartitionInfo partitionInfo = partitionInfoService.getById(partitionId);
String zonedDateStr = DateTimeUtil.getZonedTodayStr(partitionInfo.getZoneId());
if (StringUtils.hasText(date)){
List<Lucky24PersonalStat> list = zonedDateStr.equals(date)? listPersonal(partitionId, partitionInfo.getZoneId(), uid, date, userRechargeLevel, poolType):
statMapper.listPersonalStat(partitionId, uid, userRechargeLevel, poolType, date, date);
List<Lucky24PersonalStat> list = zonedDateStr.equals(date)? listPersonal(partitionId, partitionInfo.getZoneId(), uidList, date, userRechargeLevel, poolType):
statMapper.listPersonalStat(partitionId, uidList, userRechargeLevel, poolType, date, date);
if (CollectionUtils.isEmpty(list)) {
return new Lucky24PersonalStatVo(new PageResult<>(page));
@@ -228,7 +246,8 @@ public class Lucky24RecordAdminService {
return new Lucky24PersonalStatVo(totalInput, totalOutput, totalProductionRatio, new PageResult<>(page));
}
List<Long> uidList = subList.stream().map(Lucky24PersonalStat::getUid).collect(Collectors.toList());
uidList = subList.stream().map(Lucky24PersonalStat::getUid).collect(Collectors.toList());
Map<Long, Users> usersMap = usersService.getUsersMapByUids(uidList);
Map<Long, String> userRechargeLevelMap = userRechargeLevelService.mapLevelByUid(uidList);
for (Lucky24PersonalStat stat: subList) {
@@ -265,10 +284,10 @@ public class Lucky24RecordAdminService {
CountDownLatch cdl = new CountDownLatch(2);
Long finalUid = uid;
List<Long> finalUidList = uidList;
bizExecutor.execute(()->{
try {
List<Lucky24PersonalStat> list = listPersonal(partitionId, partitionInfo.getZoneId(), finalUid, zonedDateStr, userRechargeLevel, poolType);
List<Lucky24PersonalStat> list = listPersonal(partitionId, partitionInfo.getZoneId(), finalUidList, zonedDateStr, userRechargeLevel, poolType);
for (Lucky24PersonalStat stat: list) {
statMap.put(stat.getDate(), stat);
@@ -290,7 +309,7 @@ public class Lucky24RecordAdminService {
try {
String historyStartDate = dateStrList.get(0);
String historyEndDate = dateStrList.get(dateStrList.size() - 1);
List<Lucky24PersonalStat> statList = statMapper.listPersonalStat(partitionId, finalUid, userRechargeLevel, poolType, historyStartDate, historyEndDate);
List<Lucky24PersonalStat> statList = statMapper.listPersonalStat(partitionId, finalUidList, userRechargeLevel, poolType, historyStartDate, historyEndDate);
if (!CollectionUtils.isEmpty(statList)) {
for (Lucky24PersonalStat stat: statList) {
statMap.put(stat.getDate(), stat);
@@ -324,6 +343,7 @@ public class Lucky24RecordAdminService {
int endIndex = pageNo <= 0 || pageSize <= 0? dateStrList.size(): Math.min(startIndex + pageSize, dateStrList.size());
page.setTotal(dateStrList.size());
Long finalUid = uid;
List<String> subDateStrList = dateStrList.subList(startIndex, endIndex);
page.setRecords(subDateStrList.parallelStream().map(dateStr->{
Lucky24PersonalStat stat = statMap.get(dateStr);
@@ -339,7 +359,22 @@ public class Lucky24RecordAdminService {
return new Lucky24PersonalStatVo(totalInput, totalOutput, totalProductionRatio, new PageResult<>(page));
}
private List<Lucky24PersonalStat> listPersonal(int partitionId, String zonedId, Long uid, String date, String userRechargeLevel, Integer poolType) {
@SneakyThrows
public Lucky24PersonalStatVo getFollowUserPersonal(Integer partitionId, String date, String userRechargeLevel, Integer poolType,
String sortCol, String sortOrder,
int pageNo, int pageSize) {
Lucky24GiftConfig config = lucky24GiftSendService.getConfig();
List<Long> followUidList= config.getFollowUidList();
if (CollectionUtils.isEmpty(followUidList)){
return new Lucky24PersonalStatVo(new PageResult<>(new Page<>(pageNo, pageSize)));
}
List<Long> uidList = config.getFollowUidList().stream().sorted().toList();
return getPersonal(partitionId, uidList, null, date, userRechargeLevel, poolType, sortCol, sortOrder, pageNo, pageSize);
}
private List<Lucky24PersonalStat> listPersonal(int partitionId, String zonedId, List<Long> uidList, String date, String userRechargeLevel, Integer poolType) {
List<Integer> poolTypeList = null == poolType ?
Arrays.stream(Lucky24PoolTypeEnum.values()).map(Lucky24PoolTypeEnum::getType).sorted().toList(): Collections.singletonList(poolType);
@@ -351,9 +386,10 @@ public class Lucky24RecordAdminService {
Date endTime = DateTimeUtil.getEndTimeOfDay(DateTimeUtil.convertStrToDate(date, DateTimeUtil.DEFAULT_DATE_PATTERN));
ZonedDateTime zonedEndTime = endTime.toInstant().atZone(ZoneId.systemDefault());
Date systemEndTime = Date.from(zonedEndTime.withZoneSameLocal(zoneId).toInstant());
return null == poolType?
recordMapper.listPersonal(date, partitionId, poolTypeList, systemStartTime, systemEndTime, uid, userRechargeLevel):
recordMapper.listPersonalByPoolType(date, partitionId, poolTypeList, systemStartTime, systemEndTime, uid, userRechargeLevel);
recordMapper.listPersonal(date, partitionId, poolTypeList, systemStartTime, systemEndTime, uidList, userRechargeLevel):
recordMapper.listPersonalByPoolType(date, partitionId, poolTypeList, systemStartTime, systemEndTime, uidList, userRechargeLevel);
}
public Page<Lucky24RecordAdminVo> pageRecord(Long uid, String date, Integer poolType, int pageNo, int pageSize) {
@@ -465,11 +501,13 @@ public class Lucky24RecordAdminService {
Long uid = u.getUid();
String userRechargeLevel = userRechargeLevelService.getLevelByUid(uid);
List<Long> uidList = Collections.singletonList(uid);
PartitionEnum partitionEnum = PartitionEnum.getByPartitionId(u.getPartitionId());
String zonedDateStr = DateTimeUtil.getZonedTodayStr(partitionEnum.getZoneId());
if (startDate.equals(endDate)){
List<Lucky24PersonalStat> list = zonedDateStr.equals(endDate)? listPersonal(partitionEnum.getId(), partitionEnum.getZoneId(), uid, zonedDateStr, null, null):
statMapper.listPersonalStat(partitionEnum.getId(), uid, null, null, startDate, endDate);
List<Lucky24PersonalStat> list = zonedDateStr.equals(endDate)? listPersonal(partitionEnum.getId(), partitionEnum.getZoneId(), uidList, zonedDateStr, null, null):
statMapper.listPersonalStat(partitionEnum.getId(), uidList, null, null, startDate, endDate);
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
@@ -486,19 +524,11 @@ public class Lucky24RecordAdminService {
}
if (!endDate.equals(zonedDateStr)){
List<Lucky24PersonalStat> statList = statMapper.listPersonalStat(partitionEnum.getId(), uid, null, null, startDate, endDate);
List<Lucky24PersonalStat> statList = statMapper.listPersonalStat(partitionEnum.getId(), uidList, null, null, startDate, endDate);
if (CollectionUtils.isEmpty(statList)){
return Collections.emptyList();
}
// List<Lucky24OperatorPersonalStatVo> voList = new ArrayList<>(statList.stream().map(stat -> {
// BigDecimal receiverReward = BigDecimal.valueOf(stat.getTotalInput()).multiply(receiverRewardRatio);
// BigDecimal production = BigDecimal.valueOf(stat.getTotalInput()).multiply(inputRatio).subtract(BigDecimal.valueOf(stat.getTotalInput()));
// BigDecimal productionRatio = stat.getTotalOutput() > 0L ?(receiverReward.add(BigDecimal.valueOf(stat.getTotalInput())))
// .divide(BigDecimal.valueOf(stat.getTotalOutput()), 4, RoundingMode.HALF_UP): BigDecimal.ZERO;
// return new Lucky24OperatorPersonalStatVo(stat.getDate(), partitionEnum.getId(), uid, erbanNo, userRechargeLevel, stat.getTotalInput(), stat.getTotalOutput(), receiverReward.longValue(), production, productionRatio);
// }).sorted(Comparator.comparing(Lucky24OperatorPersonalStatVo::getDate).reversed()).toList());
long totalInput = statList.stream().mapToLong(Lucky24PersonalStat::getTotalInput).sum();
long totalOutput = statList.stream().mapToLong(Lucky24PersonalStat::getTotalOutput).sum();
BigDecimal receiverReward = BigDecimal.valueOf(totalInput).multiply(receiverRewardRatio);
@@ -518,7 +548,7 @@ public class Lucky24RecordAdminService {
bizExecutor.execute(()->{
try {
List<Lucky24PersonalStat> list = listPersonal(partitionEnum.getId(), partitionEnum.getZoneId(), uid, zonedDateStr, null, null);
List<Lucky24PersonalStat> list = listPersonal(partitionEnum.getId(), partitionEnum.getZoneId(), uidList, zonedDateStr, null, null);
for (Lucky24PersonalStat stat: list) {
statMap.put(stat.getDate(), stat);
}
@@ -533,7 +563,7 @@ public class Lucky24RecordAdminService {
try {
String historyStartDate = dateStrList.get(0);
String historyEndDate = dateStrList.get(dateStrList.size() - 1);
List<Lucky24PersonalStat> statList = statMapper.listPersonalStat(partitionEnum.getId(), uid, null, null, historyStartDate, historyEndDate);
List<Lucky24PersonalStat> statList = statMapper.listPersonalStat(partitionEnum.getId(), uidList, null, null, historyStartDate, historyEndDate);
if (CollectionUtils.isEmpty(statList)){
return;
}
@@ -551,20 +581,6 @@ public class Lucky24RecordAdminService {
dateStrList.add(endDate);
// List<Lucky24OperatorPersonalStatVo> voList = new ArrayList<>(dateStrList.stream().map(dateStr -> {
// Lucky24PersonalStat stat = statMap.get(dateStr);
// if (null == stat){
// return new Lucky24OperatorPersonalStatVo(dateStr, partitionEnum.getId(), uid, erbanNo, userRechargeLevel,
// BigDecimal.ZERO.longValue(), BigDecimal.ZERO.longValue(), BigDecimal.ZERO.longValue(), BigDecimal.ZERO, BigDecimal.ZERO);
// }
//
// BigDecimal receiverReward = BigDecimal.valueOf(stat.getTotalInput()).multiply(receiverRewardRatio);
// BigDecimal production = BigDecimal.valueOf(stat.getTotalInput()).multiply(inputRatio).subtract(BigDecimal.valueOf(stat.getTotalInput()));
// BigDecimal productionRatio = stat.getTotalOutput() > 0L?
// (receiverReward.add(BigDecimal.valueOf(stat.getTotalInput()))).divide(BigDecimal.valueOf(stat.getTotalOutput()), 4, RoundingMode.HALF_UP): BigDecimal.ZERO;
// return new Lucky24OperatorPersonalStatVo(stat.getDate(), partitionEnum.getId(), uid, erbanNo, userRechargeLevel, stat.getTotalInput(), stat.getTotalOutput(), receiverReward.longValue(), production, productionRatio);
// }).sorted(Comparator.comparing(Lucky24OperatorPersonalStatVo::getDate).reversed()).toList());
long totalInput = dateStrList.stream().filter(statMap::containsKey).map(statMap::get).mapToLong(Lucky24PersonalStat::getTotalInput).sum();
long totalOutput = dateStrList.stream().filter(statMap::containsKey).map(statMap::get).mapToLong(Lucky24PersonalStat::getTotalOutput).sum();
BigDecimal receiverReward = BigDecimal.valueOf(totalInput).multiply(receiverRewardRatio);

View File

@@ -0,0 +1,86 @@
package com.accompany.admin.controller.lucky;
import com.accompany.admin.controller.BaseController;
import com.accompany.admin.service.lucky.Lucky24RecordAdminService;
import com.accompany.admin.vo.luckybag.Lucky24PersonalStatVo;
import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.exception.ServiceException;
import com.accompany.sharding.vo.Lucky24PersonalStat;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@Api(tags = "幸运24")
@RestController
@RequestMapping("/admin/lucky24/followUserRecord")
public class Lucky24FollowUserRecordAdminController extends BaseController {
@Autowired
private Lucky24RecordAdminService service;
@ApiOperation("个人数据")
@ApiImplicitParams({
@ApiImplicitParam(value = "partitionId", name = "分区ID", required = true),
@ApiImplicitParam(value = "erbanNo", name = "用户ID"),
@ApiImplicitParam(value = "date", name = "开始日期", required = true),
@ApiImplicitParam(value = "userRechargeLevel", name = "用户充值等级", required = false),
@ApiImplicitParam(value = "poolType", name = "数组类型", required = true),
@ApiImplicitParam(value = "sortCol", name = "排序列", required = true),
@ApiImplicitParam(value = "sortOrder", name = "排序方式", required = true),
@ApiImplicitParam(value = "pageNo", name = "页号", required = true),
@ApiImplicitParam(value = "pageSize", name = "页长", required = true),
})
@GetMapping("/personal")
public BusiResult<Lucky24PersonalStatVo> personal(Integer partitionId, String date, Integer poolType,
String sortCol, String sortOrder,
int pageNo, int pageSize) {
if (null == partitionId || !StringUtils.hasText(date)) {
throw new ServiceException(BusiStatus.PARAMERROR);
}
Lucky24PersonalStatVo vo = service.getFollowUserPersonal(partitionId, date, null, poolType, sortCol, sortOrder, pageNo, pageSize);
return BusiResult.success(vo);
}
@SneakyThrows
@ApiOperation("导出个人数据")
@ApiImplicitParams({
@ApiImplicitParam(value = "partitionId", name = "分区ID", required = true),
@ApiImplicitParam(value = "erbanNo", name = "用户ID"),
@ApiImplicitParam(value = "date", name = "开始日期", required = true),
@ApiImplicitParam(value = "userRechargeLevel", name = "用户充值等级", required = false),
@ApiImplicitParam(value = "poolType", name = "数组类型", required = true),
@ApiImplicitParam(value = "sortCol", name = "排序列", required = true),
@ApiImplicitParam(value = "sortOrder", name = "排序方式", required = true)
})
@GetMapping("/personal/export")
public void exportPersonal(HttpServletResponse response,
Integer partitionId, String date, Integer poolType,
String sortCol, String sortOrder) {
if (null == partitionId || !StringUtils.hasText(date)) {
throw new ServiceException(BusiStatus.PARAMERROR);
}
Lucky24PersonalStatVo vo = service.getFollowUserPersonal(partitionId, date, null, poolType, sortCol, sortOrder, 1, -1);
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码
String excelName = URLEncoder.encode("幸运24关注用户个人数据", StandardCharsets.UTF_8);
response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue());
EasyExcel.write(response.getOutputStream(), Lucky24PersonalStat.class).sheet("幸运24关注用户个人数据").doWrite(vo.getDataPage().getRows());
}
}

View File

@@ -72,7 +72,7 @@ public class Lucky24RecordAdminController extends BaseController {
if (null == partitionId || (null == erbanNo && !StringUtils.hasText(date))) {
throw new ServiceException(BusiStatus.PARAMERROR);
}
Lucky24PersonalStatVo vo = service.getPersonal(partitionId, erbanNo, date, userRechargeLevel, poolType, sortCol, sortOrder, pageNo, pageSize);
Lucky24PersonalStatVo vo = service.getPersonal(partitionId, null, erbanNo, date, userRechargeLevel, poolType, sortCol, sortOrder, pageNo, pageSize);
return BusiResult.success(vo);
}
@@ -94,7 +94,7 @@ public class Lucky24RecordAdminController extends BaseController {
if (null == partitionId || (null == erbanNo && !StringUtils.hasText(date))) {
throw new ServiceException(BusiStatus.PARAMERROR);
}
Lucky24PersonalStatVo vo = service.getPersonal(partitionId, erbanNo, date, userRechargeLevel, poolType, sortCol, sortOrder, 1, -1);
Lucky24PersonalStatVo vo = service.getPersonal(partitionId, null, erbanNo, date, userRechargeLevel, poolType, sortCol, sortOrder, 1, -1);
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");

View File

@@ -37,11 +37,11 @@ public interface Lucky24RecordMapper extends BaseMapper<Lucky24Record> {
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);
@Param("uidList") List<Long> uidList, @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("uid") Long uid, @Param("userRechargeLevel") String userRechargeLevel);
@Param("uidList") List<Long> uidList, @Param("userRechargeLevel") String userRechargeLevel);
}

View File

@@ -247,8 +247,8 @@
where r.partition_id = #{partitionId}
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
and r.create_time between #{startTime} and #{endTime}
<if test="null != uid">
and r.uid = #{uid}
<if test="null != uidList and uidList.size() > 0">
and r.uid in <foreach collection="uidList" item="uid" separator="," open="(" close=")">#{uid}</foreach>
</if>
group by r.uid
</select>
@@ -274,8 +274,8 @@
where r.partition_id = #{partitionId}
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
and r.create_time between #{startTime} and #{endTime}
<if test="null != uid">
and r.uid = #{uid}
<if test="null != uidList and uidList.size() > 0">
and r.uid in <foreach collection="uidList" item="uid" separator="," open="(" close=")">#{uid}</foreach>
</if>
group by r.pool_type, r.uid
</select>

View File

@@ -16,7 +16,7 @@ public interface Lucky24StatMapper {
@Param("startDate") String startDate, @Param("endDate") String endDate);
List<Lucky24PersonalStat> listPersonalStat(@Param("partitionId") Integer partitionId,
@Param("uid") Long uid, @Param("userRechargeLevel") String userRechargeLevel, @Param("poolType") Integer poolType,
@Param("uidList") List<Long> uidList, @Param("userRechargeLevel") String userRechargeLevel, @Param("poolType") Integer poolType,
@Param("startDate") String startDate, @Param("endDate") String endDate);
}

View File

@@ -36,8 +36,8 @@
inner join user_recharge_level url on s.uid = url.uid
where s.date between #{startDate} and #{endDate}
and s.partition_id = #{partitionId}
<if test="null != uid">
and s.uid = #{uid}
<if test="null != uidList and uidList.size() > 0">
and s.uid in <foreach collection="uidList" item="uid" separator="," open="(" close=")">#{uid}</foreach>
</if>
<if test="null != poolType">
and s.pool_type = #{poolType}