[幸运亨惊喜]-排行榜-结算-固化

This commit is contained in:
khalil
2024-06-27 14:36:51 +08:00
committed by liaozetao
parent 78417ac118
commit 0bf3ff7a26
7 changed files with 144 additions and 2 deletions

View File

@@ -0,0 +1,18 @@
package com.accompany.core.mybatis.typehandler;
import com.alibaba.fastjson.TypeReference;
import java.util.List;
import java.util.Map;
/**
* Created by 恒仔 on 2023/3/5.
*/
public class MapListTypeHandler extends ListTypeHandler<Map<String, Object>> {
// 将ListTypeHandler<T>T为任意对象具体为特定的对象String
@Override
protected TypeReference<List<Map<String, Object>>> specificType() {
return new TypeReference<List<Map<String, Object>>>() {
};
}
}

View File

@@ -0,0 +1,19 @@
package com.accompany.business.model.lucky;
import com.accompany.core.mybatis.typehandler.DeviceInfoListTypeHandler;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class LuckyBagWeekRankHistory {
private Byte type;
private Integer partitionId;
private String date;
@TableField(typeHandler = DeviceInfoListTypeHandler.class)
private List<Map<String, Object>> rankList;
}

View File

@@ -0,0 +1,12 @@
package com.accompany.business.mybatismapper.lucky;
import com.accompany.business.model.lucky.LuckyBagWeekRankHistory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author: liaozetao
* @date: 2024/6/24 11:50
* @description:
*/
public interface LuckyBagWeekRankHistoryMapper extends BaseMapper<LuckyBagWeekRankHistory> {
}

View File

@@ -1,19 +1,30 @@
package com.accompany.business.service.lucky.rank;
import cn.hutool.core.collection.CollectionUtil;
import com.accompany.business.model.lucky.LuckyBagWeekRankHistory;
import com.accompany.business.mybatismapper.lucky.LuckyBagWeekRankHistoryMapper;
import com.accompany.business.service.rank.RankService;
import com.accompany.business.vo.RankParentVo;
import com.accompany.business.vo.RankVo;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.base.SpringContextHolder;
import com.accompany.core.model.PartitionInfo;
import com.accompany.core.service.partition.PartitionInfoService;
import com.accompany.core.util.DoubleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class LuckyBagWeekRankService {
@Autowired
private RankService rankService;
@Autowired
private LuckyBagWeekRankHistoryMapper historyMapper;
private final double multiple = 0.1D;
@@ -43,4 +54,42 @@ public class LuckyBagWeekRankService {
}
}
public void settlement(Date date) {
if (null == date){
date = new Date();
}
Date yesterDay = DateTimeUtil.addDays(date, -1);
Date monday = DateTimeUtil.getMondayDate(date);
Date yesterMonday = DateTimeUtil.getMondayDate(yesterDay);
if (!monday.after(yesterMonday)){
return;
}
// todo 固化
saveWeekRank(yesterMonday);
// todo 发奖励
}
private void saveWeekRank(Date monday) {
String date = DateTimeUtil.convertDate(monday, DateTimeUtil.DEFAULT_DATE_PATTERN);
List<PartitionInfo> partitionInfoList = SpringContextHolder.getBean(PartitionInfoService.class).listAll();
for (PartitionInfo partitionInfo: partitionInfoList){
Set<Map<String, Object>> receiveRankSet = SpringContextHolder.getBean(LuckyBagReceiveWeekRankService.class).getRank(monday, 0L, 9L, partitionInfo.getId());
historyMapper.insert(buildLuckyBagWeekRankList(Constant.RankType.vigour, partitionInfo.getId(), date, receiveRankSet));
Set<Map<String, Object>> sendRankSet = SpringContextHolder.getBean(LuckyBagSendWeekRankService.class).getRank(monday, 0L, 9L, partitionInfo.getId());
historyMapper.insert(buildLuckyBagWeekRankList(Constant.RankType.krypton, partitionInfo.getId(), date, sendRankSet));
}
}
private LuckyBagWeekRankHistory buildLuckyBagWeekRankList(Byte type, Integer partitionId, String date, Set<Map<String, Object>> rankSet) {
LuckyBagWeekRankHistory history = new LuckyBagWeekRankHistory();
history.setType(type);
history.setPartitionId(partitionId);
history.setDate(date);
history.setRankList(new ArrayList<>(rankSet));
return history;
}
}

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.lucky.LuckyBagWeekRankHistoryMapper">
</mapper>

View File

@@ -6,17 +6,22 @@ import com.accompany.common.annotation.Authorization;
import com.accompany.common.constant.Constant;
import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.base.UidContextHolder;
import com.accompany.core.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@Api(tags = "幸运福袋榜单", value = "幸运福袋榜单")
@RestController
@RequestMapping("/luckyBagWeekRank")
@@ -27,7 +32,7 @@ public class LuckyBagWeekRankController {
@ApiOperation("获取榜单")
@ApiImplicitParams({
@ApiImplicitParam(name = "rankType", value = "类型1=2=")
@ApiImplicitParam(name = "rankType", value = "类型1=2=")
})
@Authorization
@GetMapping("/listRank")
@@ -37,8 +42,23 @@ public class LuckyBagWeekRankController {
}
Long uid = UidContextHolder.get();
RankParentVo rankParentVo = Constant.RankType.vigour == rankType?
weekRankService.listSendRank(uid) : weekRankService.listReceiveRank(uid);
weekRankService.listReceiveRank(uid) : weekRankService.listSendRank(uid);
return BusiResult.success(rankParentVo);
}
@ApiOperation("结算")
@ApiImplicitParams({
@ApiImplicitParam(name = "date", value = "日期")
})
@PostMapping("/settlement")
public BusiResult<RankParentVo> listRank(String date) {
if (StringUtils.isBlank(date)){
throw new ServiceException(BusiStatus.PARAMERROR);
}
Date d = DateTimeUtil.convertStrToDate(date, DateTimeUtil.DEFAULT_DATE_PATTERN);
weekRankService.settlement(d);
return BusiResult.success();
}
}

View File

@@ -0,0 +1,19 @@
package com.accompany.scheduler.task.luckyBag;
import com.accompany.business.service.lucky.rank.LuckyBagWeekRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class LuckyBagWeekRankTask {
@Autowired
private LuckyBagWeekRankService service;
@Scheduled(cron = "0 0 1 * * ?")
public void settlement() {
service.settlement(null);
}
}