package com.yeshi.fanli.job;
|
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import com.yeshi.fanli.entity.bus.user.UserInfo;
|
import com.yeshi.fanli.entity.integral.CodePublishRecord;
|
import com.yeshi.fanli.service.inter.user.UserInfoService;
|
import com.yeshi.fanli.service.inter.user.integral.CodePublishRecordService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.TimeUtil;
|
|
/**
|
* 邀请码发布
|
*
|
* @author Administrator
|
*
|
*/
|
@Component
|
public class ShameUserInviteCodePublishJOB {
|
|
@Resource
|
private UserInfoService userInfoService;
|
|
@Resource
|
private CodePublishRecordService codePublishRecordService;
|
|
// 7点到23点每10分钟执行一次
|
@Scheduled(cron = "0 0/10 7-23 * * ? ")
|
public void publish() {
|
if (!Constant.IS_TASK)
|
return;
|
long time = System.currentTimeMillis();
|
int day = TimeUtil.getDayDifferenceCount(new Date(TimeUtil.convertToTimeTemp("2019-11-28", "yyyy-MM-dd")),
|
new Date());
|
int count = (day + 1) * 3;
|
if (count > 33)
|
count = 33;
|
List<CodePublishRecord> list = codePublishRecordService.listByMinTime(0, 200,
|
new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(time, "yyyyMMdd"), "yyyyMMddd")));
|
int shameCount = 0;
|
for (CodePublishRecord record : list) {
|
UserInfo user = userInfoService.selectByPKey(record.getUid());
|
if (user != null && user.getType() == 1)
|
shameCount++;
|
}
|
|
if (shameCount > 33) {// 不再添加
|
return;
|
}
|
int leftCount = count - shameCount;
|
if (leftCount <= 0)
|
return;
|
|
long publishLeftCount = (TimeUtil
|
.convertToTimeTemp(TimeUtil.getGernalTime(time + 1000 * 60 * 60 * 24L, "yyyyMMdd"), "yyyyMMddd") - time)
|
/ (1000 * 60 * 10L);
|
// 今天还剩下的分钟数
|
if (leftCount > count * publishLeftCount / 102) {
|
// 计算本次是否发布
|
int start = (int) (Math.random() * 1000);
|
List<UserInfo> userList = userInfoService.listByType(1, start, 1);
|
try {
|
Thread.sleep((int) (Math.random() * 1000 * 60 * 3L));
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
// 查询用户是否近3天内发布过
|
if (codePublishRecordService.listValid(userList.get(0).getId(), 0, 1).size() > 0)
|
return;
|
if (userList != null && userList.size() > 0) {
|
codePublishRecordService.publishInviteCode(userList.get(0).getId());
|
}
|
}
|
}
|
|
}
|