| | |
| | | package com.yeshi.fanli.job;
|
| | |
|
| | | import java.lang.reflect.Type;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | 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.redpack.RedPackGiveRecord;
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.dto.user.PullNewRuleTerm;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Component
|
| | | public class RedPackJob {
|
| | |
|
| | | @Resource
|
| | | private RedPackGiveRecordService redPackGiveRecordService;
|
| | | private RedPackWinInviteService redPackWinInviteService;
|
| | | |
| | | @Resource
|
| | | private RedPackConfigService redPackConfigService;
|
| | | |
| | |
|
| | | /**
|
| | | * 每天一个小时更新退回
|
| | | * 红包每月26到账
|
| | | */
|
| | | @Scheduled(cron = "0 0 0/1 * * ? ")
|
| | | public void overdue() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | |
| | | @Scheduled(cron = "0 20 0 26 * ? ")
|
| | | public void arriveMoney() {
|
| | | try {
|
| | | for (int i = 0; i < 100; i++) {
|
| | | List<RedPackGiveRecord> overdueList = redPackGiveRecordService.overdueList(500);
|
| | | if (overdueList == null || overdueList.size() == 0) {
|
| | | String value = redPackConfigService.getValueByKey("win_redpack_term");
|
| | | if (StringUtil.isNullOrEmpty(value)) {
|
| | | return;
|
| | | }
|
| | | |
| | | Type type = new TypeToken<ArrayList<PullNewRuleTerm>>() {
|
| | | }.getType();
|
| | | List<PullNewRuleTerm> listRule = new Gson().fromJson(value, type);
|
| | | if (listRule == null || listRule.size() == 0) {
|
| | | return;
|
| | | }
|
| | | |
| | | int start = 0;
|
| | | Date date = new Date();
|
| | | while(true) {
|
| | | // 上月存在邀请的用用户id
|
| | | List<Long> list = redPackWinInviteService.listWinUid(start, 1000);
|
| | | if (list == null || list.size() == 0) {
|
| | | break;
|
| | | }
|
| | | redPackGiveRecordService.overdue(overdueList);
|
| | | |
| | | for (Long uid: list) {
|
| | | // 统计上月邀请成功数量
|
| | | long count = redPackWinInviteService.countLastMonthByUid(uid);
|
| | | if (count == 0)
|
| | | continue;
|
| | | |
| | | BigDecimal money = null;
|
| | | for (PullNewRuleTerm term: listRule) {
|
| | | if (count >= term.getMin() && (term.getMax() != null && count <= term.getMax())) {
|
| | | money = term.getMoney();
|
| | | }
|
| | | }
|
| | | |
| | | if (money == null) {
|
| | | LogHelper.test("红包奖励未匹配到规则count =" + count + " uid =" + uid);
|
| | | continue;
|
| | | }
|
| | | |
| | | try {
|
| | | redPackWinInviteService.arriveMoney(uid, money, date);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | | |
| | | }
|