用户等级-定时任务-每日更新

This commit is contained in:
khalil
2025-06-09 16:09:03 +08:00
parent 13317737dc
commit db9340ebd8
4 changed files with 54 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Mapper
public interface UserRechargeLevelMapper extends BaseMapper<UserRechargeLevel> {
@@ -16,4 +17,5 @@ public interface UserRechargeLevelMapper extends BaseMapper<UserRechargeLevel> {
@Param("last60TotalGold")BigDecimal last60Gold, @Param("last60RechargeGold")BigDecimal last60RechargeGold, @Param("last60GiveGold")BigDecimal last60GiveGold,
@Param("updateTime")Date updateTime);
List<Long> listUpdateUid();
}

View File

@@ -1,7 +1,5 @@
package com.accompany.payment.service;
import com.accompany.core.model.Users;
import com.accompany.core.service.user.UsersBaseService;
import com.accompany.payment.mapper.ChargeRecordMapperMgr;
import com.accompany.payment.mapper.UserRechargeLevelMapper;
import com.accompany.payment.model.UserRechargeLevel;
@@ -15,8 +13,6 @@ import java.util.Date;
@Service
public class UserRechargeLevelService extends ServiceImpl<UserRechargeLevelMapper, UserRechargeLevel> {
@Autowired
private UsersBaseService usersBaseService;
@Autowired
private UserRechargeLevelConfigService highRechargeLevelService;
@Autowired
@@ -25,10 +21,6 @@ public class UserRechargeLevelService extends ServiceImpl<UserRechargeLevelMappe
private RechargeUserService rechargeUserService;
public void statistics(Long uid, BigDecimal totalReceiveGoldNum, BigDecimal last60TotalReceiveGoldNum) {
Users u = usersBaseService.getUsersByUid(uid);
if (null == u){
return;
}
boolean isRechargeUser = rechargeUserService.isRechargeUser(uid);

View File

@@ -18,4 +18,9 @@
`update_time` = values(`update_time`)
</update>
<select id="listUpdateUid" resultType="java.lang.Long">
select uid from user_recharge_level url
where url.last_60_total_gold > 0
</select>
</mapper>

View File

@@ -0,0 +1,47 @@
package com.accompany.scheduler.task;
import com.accompany.business.mybatismapper.DiamondGiveHistoryMapper;
import com.accompany.payment.service.UserRechargeLevelService;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
@Component
public class UserRechargeLevelTask {
@Autowired
private UserRechargeLevelService service;
@Autowired
private DiamondGiveHistoryMapper diamondGiveHistoryMapper;
@Resource(name = "bizExecutor")
private ThreadPoolExecutor bizExecutor;
@Scheduled(cron = "1 0 0 * * ?")
public void updateUserRechargeLevel(){
List<Long> uidList = service.getBaseMapper().listUpdateUid();
if (CollectionUtils.isEmpty(uidList)){
return;
}
List<List<Long>> uidListList = Lists.partition(uidList, 500);
for (List<Long> uidListPartition : uidListList){
bizExecutor.execute(() -> {
for (Long uid : uidListPartition){
BigDecimal totalReceiveGoldNum = diamondGiveHistoryMapper.getUserTotalReceiveGold(uid);
BigDecimal last60TotalReceiveGoldNum = diamondGiveHistoryMapper.getUserLast60TotalReceiveGold(uid);
service.statistics(uid, totalReceiveGoldNum, last60TotalReceiveGoldNum);
}
});
}
}
}