release- 4.2. 重新计算积分

release-2024-04-25
huangyw 2 months ago
parent 94a9423a35
commit 9a74d8b591

@ -435,5 +435,12 @@ public class PointController {
return Result.success();
}
@ApiOperation(value = "4.2. 重新计算积分", notes = "")
@PostMapping("/recalculate")
public Result<Void> recalculate() {
lotteryService.recalculate();
return Result.success();
}
}

@ -25,4 +25,9 @@ public interface UserPointLogDao extends JpaRepository<UserPointLog, String>, Jp
public List<UserPointLog> findUserPointLogsByUserIdAndTaskPointId(String userId, String taskPointId);
public List<UserPointLog> findUserPointLogByTaskPointIdInAndUserId(List<String> taskPointIds, String userId);
@Query(value = "select distinct user_id from tb_user_point_log", nativeQuery = true)
public List<String> findAllUserId();
public List<UserPointLog> findUserPointLogByUserId(String userId);
}

@ -9,6 +9,7 @@ import com.luoo.user.dao.LotteryDao;
import com.luoo.user.dao.LotteryRegionDao;
import com.luoo.user.dao.LotteryUserDao;
import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.dao.UserPointLogDao;
import com.luoo.user.dto.point.DrawDTO;
import com.luoo.user.dto.point.LotteryParticipatedSearchDto;
import com.luoo.user.dto.point.LotterySearchDto;
@ -29,6 +30,7 @@ import enums.UserBetaEnum;
import enums.UserTypeEnum;
import enums.UserVipStatusEnum;
import exception.BizException;
import java.util.concurrent.atomic.AtomicReference;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@ -93,7 +95,10 @@ public class LotteryService {
private final UserPointLogService userPointLogService;
public LotteryService(LotteryDao lotteryDao, JwtUtil jwtUtil, IdWorker idWorker, RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao, DrawLotteryScheduler drawLotteryScheduler, JPAQueryFactory jpaQueryFactory, EnvConfig envConfig, UserinfoShippingAddressService userinfoShippingAddressService, UserPointLogService userPointLogService) {
private final UserPointLogDao userPointLogDao;
public LotteryService(LotteryDao lotteryDao, JwtUtil jwtUtil, IdWorker idWorker, RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao, DrawLotteryScheduler drawLotteryScheduler, JPAQueryFactory jpaQueryFactory, EnvConfig envConfig, UserinfoShippingAddressService userinfoShippingAddressService, UserPointLogService userPointLogService,
UserPointLogDao userPointLogDao) {
this.lotteryDao = lotteryDao;
this.jwtUtil = jwtUtil;
this.idWorker = idWorker;
@ -108,6 +113,7 @@ public class LotteryService {
this.envConfig = envConfig;
this.userinfoShippingAddressService = userinfoShippingAddressService;
this.userPointLogService = userPointLogService;
this.userPointLogDao = userPointLogDao;
}
@ -920,4 +926,27 @@ public class LotteryService {
});
}
@Transactional(rollbackFor = Exception.class)
public void recalculate() {
List<String> allUserId = userPointLogDao.findAllUserId();
allUserId.forEach(userId -> {
log.info("用户:{},积分重算开始", userId);
// 查询userId对应所有的积分记录
List<UserPointLog> userPointLogList = userPointLogDao.findUserPointLogByUserId(userId);
AtomicReference<Integer> totalScore = new AtomicReference<>(0);
userPointLogList.forEach(userPointLog -> {
if (userPointLog.getType().equals(PointEnums.TASK_POINT_TYPE_ADD.getCode())) {
totalScore.updateAndGet(v -> v + userPointLog.getScore());
} else {
totalScore.updateAndGet(v -> v - userPointLog.getScore());
}
});
UserInfo userInfo = userInfoDao.findById(userId).orElse(null);
assert userInfo != null;
userInfo.setPoint(totalScore.get());
userInfoDao.save(userInfo);
});
}
}

Loading…
Cancel
Save