增加每日池子7个

master
ck 5 years ago
parent 0a03abcabc
commit fa0bfaabae

@ -6,4 +6,5 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface AwardRuleMapper extends CommonMapper<AwardRule> { public interface AwardRuleMapper extends CommonMapper<AwardRule> {
int updateDayAwardTask();
} }

@ -1,5 +1,7 @@
package com.jingcheng.template.quartz; package com.jingcheng.template.quartz;
import com.jingcheng.template.mapper.AwardRuleMapper;
import com.jingcheng.template.service.AwardRecordService;
import com.jingcheng.template.service.UsersService; import com.jingcheng.template.service.UsersService;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -15,6 +17,8 @@ public class ScheduledTask {
@Resource @Resource
UsersService usersService; UsersService usersService;
@Resource
AwardRecordService awardRecordService;
private static final String CHANCE_TASK = "0 0 0 * * ?"; private static final String CHANCE_TASK = "0 0 0 * * ?";
/** /**
@ -24,5 +28,6 @@ public class ScheduledTask {
@Scheduled(cron = CHANCE_TASK) @Scheduled(cron = CHANCE_TASK)
public void downloadWxEmployee() { public void downloadWxEmployee() {
usersService.chancesTask(); usersService.chancesTask();
awardRecordService.refreshDayAwards();
} }
} }

@ -54,4 +54,6 @@ public interface AwardRecordService<AwardRecord> extends BaseService<AwardRecord
* @return * @return
*/ */
AjaxResult isHaveDayShare(String userId); AjaxResult isHaveDayShare(String userId);
void refreshDayAwards();
} }

@ -106,10 +106,12 @@ public class AwardRecordServiceImpl extends BaseServiceImpl<AwardRecordMapper, A
//今日抽总次数 //今日抽总次数
Integer todayCount = awardRecordMapper.selectCountByExample(awardRecordExample2); Integer todayCount = awardRecordMapper.selectCountByExample(awardRecordExample2);
Integer awardNum = awardRule.getAwardNum(); Integer awardNum = awardRule.getAwardNum();
AwardRule todayAward = awardRuleMapper.selectByPrimaryKey(2L);
Integer todayAwardNum = todayAward.getAwardNum();
if (todayAwardCount >= 1){ if (todayAwardCount >= 1){
logger.info("此用户已抽中过奖品"); logger.info("此用户已抽中过奖品");
isAward = false; isAward = false;
}else { }else if (todayAwardNum > 0){
int range = (int) (1 / awardRate); int range = (int) (1 / awardRate);
int num = 1 + (int)(Math.random()*(range - 1 + 1)); int num = 1 + (int)(Math.random()*(range - 1 + 1));
if ( 0 == isHaveBigAward){ if ( 0 == isHaveBigAward){
@ -150,6 +152,8 @@ public class AwardRecordServiceImpl extends BaseServiceImpl<AwardRecordMapper, A
awardRule.setUpdateDateTime(new Date()); awardRule.setUpdateDateTime(new Date());
}else { }else {
awardRule.setAwardNum(awardNum - 1); awardRule.setAwardNum(awardNum - 1);
todayAward.setAwardNum(todayAwardNum -1);
awardRuleMapper.updateByPrimaryKeySelective(todayAward);
} }
awardRuleMapper.updateByPrimaryKeySelective(awardRule); awardRuleMapper.updateByPrimaryKeySelective(awardRule);
}else { }else {
@ -396,4 +400,11 @@ public class AwardRecordServiceImpl extends BaseServiceImpl<AwardRecordMapper, A
} }
return ajaxResult; return ajaxResult;
} }
@Override
public void refreshDayAwards() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
logger.info(simpleDateFormat.format(new Date())+ "刷新每日中奖池");
awardRuleMapper.updateDayAwardTask();
}
} }

@ -0,0 +1,7 @@
<?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.jingcheng.template.mapper.AwardRuleMapper">
<update id="updateDayAwardTask">
update award_rule set award_num = 7 where id = 2
</update>
</mapper>
Loading…
Cancel
Save