|
|
|
@ -0,0 +1,68 @@ |
|
|
|
package com.qniao.dam.application.task; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.qniao.dam.application.service.right.RightApplicationService; |
|
|
|
import com.qniao.dam.domain.aggregate.right.valueobj.RightAcquireRecord; |
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.MarriageInformationDao; |
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.RightAcquireRecordDao; |
|
|
|
import com.qniao.das.domian.aggregate.marriageinformation.MarriageInformation; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@Component |
|
|
|
@Slf4j |
|
|
|
public class AcquireGiftRightTask { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private MarriageInformationDao marriageInformationDao; |
|
|
|
@Resource |
|
|
|
private RightApplicationService rightApplicationService; |
|
|
|
@Resource |
|
|
|
private RightAcquireRecordDao rightAcquireRecordDao; |
|
|
|
|
|
|
|
/** |
|
|
|
* 每月给资料赠送修改头像权益 人数多不能这么领取,用户自己领取就行 |
|
|
|
*/ |
|
|
|
@Scheduled(cron = "0 * * * * *") // 每分钟的第0秒执行 |
|
|
|
public void handle() { |
|
|
|
try { |
|
|
|
log.error("赠送权益任务开始"); |
|
|
|
//一个月整前的资料赠送权益 |
|
|
|
LocalDate date = LocalDate.now().minusMonths(1); |
|
|
|
LocalDateTime startTime = date.atTime(0, 0, 0); |
|
|
|
LocalDateTime endTime = date.atTime(23, 59, 59); |
|
|
|
int count = marriageInformationDao.selectCount(new LambdaQueryWrapper<MarriageInformation>() |
|
|
|
.ge(MarriageInformation::getCreateTime, startTime) |
|
|
|
.le(MarriageInformation::getCreateTime, endTime)); |
|
|
|
if (count > 0) { |
|
|
|
int num = 100; |
|
|
|
for (int i = 0; i < count; i += num) { |
|
|
|
List<MarriageInformation> list = marriageInformationDao.selectList(new LambdaQueryWrapper<MarriageInformation>() |
|
|
|
.ge(MarriageInformation::getCreateTime, startTime) |
|
|
|
.le(MarriageInformation::getCreateTime, endTime) |
|
|
|
.last("limit " + i + "," + num)); |
|
|
|
if (CollUtil.isNotEmpty(list)) { |
|
|
|
for (MarriageInformation marriageInformation : list) { |
|
|
|
//判断资料是否领取过免费权益 |
|
|
|
if (rightAcquireRecordDao.selectCount(new LambdaQueryWrapper<RightAcquireRecord>() |
|
|
|
.ge(RightAcquireRecord::getCreateTime, startTime) |
|
|
|
.le(RightAcquireRecord::getCreateTime, endTime)) == 0) { |
|
|
|
rightApplicationService.acquireNewMIRight(marriageInformation.getUserId(), marriageInformation.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
log.error("赠送权益任务结束"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("赠送权益任务异常", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |