diff --git a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java index d3f1210..f45e8cd 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/PointController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java @@ -4,36 +4,24 @@ import annotation.GlobalInterceptor; import api.PageResult; import api.Result; import com.luoo.user.dto.point.*; -import com.luoo.user.pojo.*; +import com.luoo.user.pojo.Lottery; +import com.luoo.user.pojo.LotteryRegion; +import com.luoo.user.pojo.TaskPoint; import com.luoo.user.service.DrawLotteryService; import com.luoo.user.service.LotteryService; import com.luoo.user.service.TaskPointService; import com.luoo.user.service.UserPointLogService; import com.luoo.user.vo.point.*; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; - -import java.util.List; -import javax.annotation.Nullable; -import javax.validation.constraints.NotNull; - +import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Required; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Nullable; +import javax.validation.constraints.NotNull; +import java.util.List; /** * @program: luoo_parent @@ -440,5 +428,12 @@ public class PointController { return Result.success(); } + @ApiOperation(value = "4.1. 老用户已更换头像的直接发放积分", notes = "") + @PostMapping("/avatar/old") + public Result avatarOld() { + lotteryService.avatarOld(); + return Result.success(); + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java index fd33fe6..9deff20 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserInfoDao.java @@ -57,4 +57,7 @@ public interface UserInfoDao extends JpaRepository, JpaSpecifi @Query(value = "select * from tb_user_info where nick_name like ?1 limit 50", nativeQuery = true) public List getUserInfosByNickNameLikeLimit50(String nickName); + + @Query(value = "select * from tb_user_info where avatar != 'user/avatar/default.png'", nativeQuery = true) + public List getOldUserListWhoIsAlreadyNewAvatar(); } diff --git a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java index 89a1c10..5c59ddb 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java @@ -28,27 +28,12 @@ import enums.PointEnums; import enums.UserTypeEnum; import enums.UserVipStatusEnum; import exception.BizException; - -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -56,6 +41,17 @@ import util.IdWorker; import util.JwtUtil; import util.RedisLockUtil; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; +import java.io.IOException; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + /** * @program: luoo_parent * @description: 抽奖 @@ -94,7 +90,9 @@ public class LotteryService { private final UserinfoShippingAddressService userinfoShippingAddressService; - 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) { + 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) { this.lotteryDao = lotteryDao; this.jwtUtil = jwtUtil; this.idWorker = idWorker; @@ -108,6 +106,7 @@ public class LotteryService { this.jpaQueryFactory = jpaQueryFactory; this.envConfig = envConfig; this.userinfoShippingAddressService = userinfoShippingAddressService; + this.userPointLogService = userPointLogService; } @@ -905,4 +904,13 @@ public class LotteryService { } } + @Transactional(rollbackFor = Exception.class) + public void avatarOld() { + List oldUserListWhoIsAlreadyNewAvatar = userInfoDao.getOldUserListWhoIsAlreadyNewAvatar(); + oldUserListWhoIsAlreadyNewAvatar.forEach(userInfo -> { + log.info("用户:{},积分增加:{}", userInfo.getNickName(), TaskPointIdConstants.MODIFY_AVATAR); + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.MODIFY_AVATAR, userInfo.getId()); + }); + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/service/MemberShipService.java b/luoo_user/src/main/java/com/luoo/user/service/MemberShipService.java index 2a5cfc8..512569d 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/MemberShipService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/MemberShipService.java @@ -172,34 +172,39 @@ public class MemberShipService { * @param one 会员订单表 */ private void dealUserVipCalc(MembershipOrder one) { - // 处理用户表 - UserInfo userInfo = userInfoDao.findById(one.getUserId()).get(); + try { + // 处理用户表 + UserInfo userInfo = userInfoDao.findById(one.getUserId()).get(); - if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.INITIAL.getCode())) { - // 首次开通会员 - userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.BUY_MEMBER, one.getUserId()); - } + if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.INITIAL.getCode())) { + // 首次开通会员 + userPointLogService.addByTaskDailyAndUserId(TaskPointIdConstants.BUY_MEMBER, one.getUserId()); + } - // 永久会员码 - if (Objects.equals(one.getLife(), PointEnums.MEMBERSHIP_LIFE.getCode())) { - userInfo.setVipStatus(UserVipStatusEnum.LIFE.getCode()); - } else { - // 非永久会员码 - // 计算会员到期时间 - LocalDate vipExpireTime; - if (Objects.equals(UserVipStatusEnum.ACTIVE.getCode(), userInfo.getVipStatus())) { - // 如果是当前正是会员,以到期时间为基准,再增加membershipCode的duration天 - vipExpireTime = (userInfo.getVipExpireTime() == null ? LocalDate.now() : userInfo.getVipExpireTime()).plusDays(one.getDuration()); + // 永久会员码 + if (Objects.equals(one.getLife(), PointEnums.MEMBERSHIP_LIFE.getCode())) { + userInfo.setVipStatus(UserVipStatusEnum.LIFE.getCode()); } else { - // 如果是当前不是会员,从今天开始,增加membershipCode的duration天 - userInfo.setVipStatus(UserVipStatusEnum.INITIAL.getCode()); - vipExpireTime = LocalDate.now().plusDays(one.getDuration()); + // 非永久会员码 + // 计算会员到期时间 + LocalDate vipExpireTime; + if (Objects.equals(UserVipStatusEnum.ACTIVE.getCode(), userInfo.getVipStatus())) { + // 如果是当前正是会员,以到期时间为基准,再增加membershipCode的duration天 + vipExpireTime = (userInfo.getVipExpireTime() == null ? LocalDate.now() : userInfo.getVipExpireTime()).plusDays(one.getDuration()); + } else { + // 如果是当前不是会员,从今天开始,增加membershipCode的duration天 + userInfo.setVipStatus(UserVipStatusEnum.INITIAL.getCode()); + vipExpireTime = LocalDate.now().plusDays(one.getDuration()); + } + userInfo.setVipExpireTime(vipExpireTime); + // 无论如何当即设置为会员生效状态 + userInfo.setVipStatus(UserVipStatusEnum.ACTIVE.getCode()); } - userInfo.setVipExpireTime(vipExpireTime); - // 无论如何当即设置为会员生效状态 - userInfo.setVipStatus(UserVipStatusEnum.ACTIVE.getCode()); + userInfoDao.save(userInfo); + } catch (Exception e) { + e.printStackTrace(); + log.error("会员开通失败", e); } - userInfoDao.save(userInfo); } /**