攒能量活动通过排行榜颁奖
程序员文章站
2022-05-02 17:44:07
...
先上代码,写个定时任务处理活动自动生成榜单,本代码解决了根据排行榜人数,和设置的一等二等三等奖人数智能匹配,包括并列情况等。适合大家参考
public void setSaveEnergyRecord() {
List<CinemaWelfare> list = cinemaWelfareMapper.getWelfareListByState();
if (list != null) {
for (CinemaWelfare cinemaWelfare : list) {
if (cinemaWelfare.getIs_draw().equals("0")) {
//福利活动ID
Integer eventId = cinemaWelfare.getCinema_welfare_id();
//攒能量结果排行榜
List<SaveEnergy> saveEnergyList = saveEnergyMapper.selectEnergyList(eventId);
logger.info("排行榜大小==============="+saveEnergyList.size());
// 奖品配置
List<AwardsConfig> awardsConfigList = awardsConfigMapper.getAwardsConfigList(eventId.toString());
logger.info("奖项配置大小=========="+awardsConfigList.size());
if (saveEnergyList.size() != 0 && awardsConfigList.size() != 0) {
Integer level_1 = 0;
Integer level_2 = 0;
Integer level_3 = 0;
for (AwardsConfig awardsConfig : awardsConfigList) {
//一等奖
if (awardsConfig.getAwards_level().equals("1")) {
level_1 = awardsConfig.getAwards_count();
for (int i = 0; i < level_1 && i < saveEnergyList.size(); i++) {
SaveEnergy saveEnergy = saveEnergyList.get(i);
Integer userId = saveEnergy.getUser_id();
Account myInfo = accountService.getAccount(userId);
insertWinningManagement(myInfo, cinemaWelfare, awardsConfig);
}
}
//二等奖
else if (awardsConfig.getAwards_level().equals("2")) {
level_2 = awardsConfig.getAwards_count();
for (int k = level_1; k < level_1 + level_2 && k < saveEnergyList.size(); k++) {
SaveEnergy saveEnergy = saveEnergyList.get(k);
Integer userId = saveEnergy.getUser_id();
Account myInfo = accountService.getAccount(userId);
insertWinningManagement(myInfo, cinemaWelfare, awardsConfig);
}
}
//三等奖
else if (awardsConfig.getAwards_level().equals("3")) {
level_3 = awardsConfig.getAwards_count();
for (int x = level_2 + level_1; x < level_1 + level_2 + level_3 && x < saveEnergyList.size(); x++) {
SaveEnergy saveEnergy = saveEnergyList.get(x);
Integer userId = saveEnergy.getUser_id();
Account myInfo = accountService.getAccount(userId);
insertWinningManagement(myInfo, cinemaWelfare, awardsConfig);
}
}
}
}
cinemaWelfareMapper.updateSaveEnergyDrawStatus(eventId);
logger.info("更新福利颁奖状态成功", cinemaWelfare.getTitle());
} else {
logger.info("该福利活动已经生成福利奖单", cinemaWelfare.getTitle());
}
}
}
}
SaveEnergy实体类包含字段
private Integer save_energy_id;
private Integer user_id;
private Integer count;
private Date create_time;
上一篇: [Python] 豆瓣自动回帖源码
推荐阅读