package com.yeshi.fanli.job;
|
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Random;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import org.yeshi.utils.DateUtil;
|
|
import com.yeshi.fanli.entity.bus.user.UserRankings;
|
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.config.ConfigService;
|
import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
|
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
import com.yeshi.fanli.service.inter.user.UserRankingsService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
|
/**
|
* 淘宝商品更细
|
*
|
* @author Administrator
|
*
|
*/
|
|
@Component
|
public class UserRankingsJob {
|
|
@Resource
|
private ConfigService configService;
|
|
@Resource
|
private UserRankingsService userRankingsService;
|
|
@Resource
|
private TaoBaoOrderService taoBaoOrderService;
|
|
@Resource
|
private UserInfoExtraService userInfoExtraService;
|
|
|
// 每天00点10执行 : 更改排行榜上的奖金
|
@Scheduled(cron = "0 15 0 * * ? ")
|
public void updateReward() {
|
// if (!Constant.IS_TASK) {
|
// return;
|
// }
|
|
// 更新人数
|
int showNum = 15;
|
// 每日增幅
|
double rangeAmount = 100;
|
try {
|
List<UserRankings> listExist = null;
|
// 每月1号归0
|
int currentDate = DateUtil.getCurrentDate();
|
if (currentDate != 1)
|
listExist = userRankingsService.getRankList(0, showNum);
|
|
// 清理数据
|
userRankingsService.clearShareReward();
|
|
// 假用户数量
|
int count = (int) userRankingsService.queryCount(null, null, null);
|
// 随机显示新的人
|
Random random = new Random();
|
List<Long> listId = new ArrayList<Long>();
|
while (listId.size() < showNum) {
|
long id = random.nextInt(count);
|
if (!listId.contains(id)) {
|
listId.add(id);
|
}
|
}
|
List<UserRankings> listNew = userRankingsService.listQueryByIds(listId);
|
|
if (listExist == null || listExist.size() == 0) {
|
for (UserRankings user : listNew) {
|
// 浮动金额
|
double amount = Math.random() * rangeAmount;
|
if (amount < 0.5) {
|
amount = 0.5;
|
}
|
user.setShareReward(new BigDecimal(amount));
|
}
|
} else {
|
for (int i = 0; i < listNew.size(); i ++) {
|
UserRankings user = listNew.get(i);
|
|
// 浮动金额
|
BigDecimal shareReward = null;
|
if (i < listExist.size()) {
|
shareReward = listExist.get(i).getShareReward();
|
}
|
|
if (shareReward == null)
|
shareReward = BigDecimal.ZERO;
|
|
// 浮动金额
|
double amount = Math.random() * rangeAmount;
|
user.setShareReward(shareReward.add(BigDecimal.valueOf(amount)));
|
}
|
}
|
// 批量更新昨日数据-移除排行榜
|
userRankingsService.updateBatchSelective(listNew);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|