Merge remote-tracking branch 'origin/release-2024-04-25' into release-2024-04-25

release-2024-08-08
wangqing 4 months ago
commit f9557c52f4

@ -0,0 +1,51 @@
package constants;
/**
* @program: luoo_parent
* @description: id
* @author: yawei.huang
* @create: 2024-07-24 15:50
**/
public class TaskPointIdConstants {
// 新手欢迎奖励
public static final String NEW_USER_WELCOME_AWARD = "1";
// 修改头像
public static final String MODIFY_AVATAR = "2";
// 修改昵称
public static final String MODIFY_NICKNAME = "3";
// 完善个人信息 todo
public static final String COMPLETE_PERSONAL_INFORMATION = "4";
// 成功关注1位用户 todo
public static final String SUCCESS_FOLLOW_ONE_USER = "5";
// 首次分享期刊 todo
public static final String FIRST_SHARE_JOURNAL = "6";
// 首次收藏期刊 todo
public static final String FIRST_COLLECT_JOURNAL = "7";
// 首次购物成功 todo
public static final String FIRST_SHOPPING_SUCCESS = "8";
// 首次完成评价 todo
public static final String FIRST_COMPLETE_COMMENT = "9";
// 开通会员 todo
public static final String OPEN_MEMBER = "10";
// 以下不需要校验是否已做过
// 每日登录 todo
public static final String DAILY_LOGIN = "11";
// 每日签到 todo
public static final String DAILY_SIGN = "12";
// 分享期刊 todo
public static final String SHARE_JOURNAL = "13";
// 邀请好友 todo
public static final String INVITE_FRIEND = "14";
// 好友首次下单成功 todo
public static final String FRIEND_FIRST_ORDER_SUCCESS = "15";
// 购买天数达标 todo
public static final String BUY_DAYS_REACHED = "16";
// 积分抽奖 todo
public static final String POINT_LOTTERY = "17";
// 积分商城 todo
public static final String POINT_SHOP = "18";
}

@ -8,6 +8,12 @@ public enum PointEnums {
VALID(1, "启用"), VALID(1, "启用"),
INVALID(2, "禁用"), INVALID(2, "禁用"),
TASK_TYPE_NEW(1, "新手任务"),
TASK_TYPE_DAILY(2, "日常任务"),
TASK_POINT_TYPE_ADD(1, "增加"),
TASK_POINT_TYPE_REDUCE(2, "减少"),
; ;
private final Integer code; private final Integer code;
private final String description; private final String description;

@ -17,6 +17,7 @@ import com.luoo.user.service.*;
import com.luoo.user.util.EmojiConverterUtil; import com.luoo.user.util.EmojiConverterUtil;
import com.luoo.user.util.IpUtil; import com.luoo.user.util.IpUtil;
import constants.Constants; import constants.Constants;
import constants.TaskPointIdConstants;
import controller.BaseController; import controller.BaseController;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.*; import enums.*;
@ -84,6 +85,9 @@ public class MyController extends BaseController {
@Autowired @Autowired
private UserMessageDao userMessageDao; private UserMessageDao userMessageDao;
@Autowired
private UserPointLogService userPointLogService;
@ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息")
@GetMapping("/userInfo") @GetMapping("/userInfo")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)
@ -128,6 +132,9 @@ public class MyController extends BaseController {
} }
} }
// 修改了昵称
boolean isChangeNickName = !Objects.equals(nickName, user.getNickName());
if (!StringTools.isEmpty(nickName)) { if (!StringTools.isEmpty(nickName)) {
user.setNickName(nickName); user.setNickName(nickName);
rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId());
@ -148,6 +155,11 @@ public class MyController extends BaseController {
} }
user.setModifyTime(new Date()); user.setModifyTime(new Date());
userInfoService.update(user); userInfoService.update(user);
if(isChangeNickName) {
// 修改了昵称
userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_NICKNAME, user.getNickName());
}
return Result.success(); return Result.success();
} }
@ -182,6 +194,8 @@ public class MyController extends BaseController {
userInfoService.update(user); userInfoService.update(user);
rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId());
userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_AVATAR, userLoginDto.getUserId());
return Result.success(Constants.RESOURCE_PREFIX + user.getThumbnail()); return Result.success(Constants.RESOURCE_PREFIX + user.getThumbnail());
} }

@ -3,8 +3,11 @@ package com.luoo.user.controller;
import annotation.GlobalInterceptor; import annotation.GlobalInterceptor;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.pojo.TaskPoint; import com.luoo.user.pojo.TaskPoint;
import com.luoo.user.pojo.UserPointLog;
import com.luoo.user.service.TaskPointService; import com.luoo.user.service.TaskPointService;
import com.luoo.user.service.UserPointLogService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
@ -13,6 +16,7 @@ import io.swagger.annotations.ApiParam;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -31,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@Slf4j @Slf4j
@CrossOrigin
@RequestMapping("/point") @RequestMapping("/point")
@Api(tags = "积分模块") @Api(tags = "积分模块")
public class PointController { public class PointController {
@ -38,13 +43,16 @@ public class PointController {
@Autowired @Autowired
private TaskPointService taskPointService; private TaskPointService taskPointService;
@Autowired
private UserPointLogService userPointLogService;
@ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用") @ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用")
@PostMapping("/task/add") @PostMapping("/task/add")
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"), @ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"),
@ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header")}) @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")})
public Result<Void> add( public Result<Void> add(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody TaskPoint taskPoint) { @RequestBody TaskPoint taskPoint) {
@ -57,7 +65,7 @@ public class PointController {
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"), @ApiImplicitParam(name = "taskPoint", value = "任务积分配置", required = true, dataType = "TaskPoint", paramType = "body"),
@ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header")} @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}
) )
public Result<Void> update( public Result<Void> update(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@ -71,7 +79,7 @@ public class PointController {
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List<TaskPoint>", paramType = "body"), @ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List<TaskPoint>", paramType = "body"),
@ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header")} @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header")}
) )
public Result<Void> batchUpdate( public Result<Void> batchUpdate(
@RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "Authorization", required = true) String authorization,
@ -85,7 +93,7 @@ public class PointController {
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "任务积分配置id", required = true, dataType = "List<String>", paramType = "body"), @ApiImplicitParam(name = "ids", value = "任务积分配置id", required = true, dataType = "List<String>", paramType = "body"),
@ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query") @ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
} }
) )
@ -102,7 +110,7 @@ public class PointController {
@GlobalInterceptor(checkAdminLogin = true) @GlobalInterceptor(checkAdminLogin = true)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "任务积分配置id", required = true, dataType = "String", paramType = "body"), @ApiImplicitParam(name = "id", value = "任务积分配置id", required = true, dataType = "String", paramType = "body"),
@ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query") @ApiImplicitParam(name = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
}) })
public Result<Void> disable( public Result<Void> disable(
@ -115,12 +123,51 @@ public class PointController {
@ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表") @ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表")
@GetMapping("/task/list/{page}/{size}") @GetMapping("/task/list/{page}/{size}")
public Result<PageResult<TaskPoint>> getUnApproveList(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, public Result<PageResult<TaskPoint>> getUnApproveList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "页码", required = true) @PathVariable Integer page, @ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(taskPointService.getTaskPointList(page, size)); return Result.success(taskPointService.getTaskPointList(page, size));
} }
@ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/new")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> addLogNew(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) {
userPointLogService.addByTaskNew(taskPointId, authorization);
return Result.success();
}
@ApiOperation(value = "2.2. 用户根据新手任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/daily")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "taskPointId", value = "任务积分配置id", required = true, dataType = "String", paramType = "body")
})
public Result<Void> addLogDaily(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestBody String taskPointId) {
userPointLogService.addByTaskDaily(taskPointId, authorization);
return Result.success();
}
@ApiOperation(value = "2.3.用户积分日志列表", notes = "用户积分日志列表")
@PostMapping("/log/list/{page}/{size}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserPointLog>> getUserPointLogList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "查询对象")@RequestBody UserPointLogSearchDto userPointLogSearchDto,
@ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ApiParam(value = "每页条数", required = true) @PathVariable Integer size) {
return Result.success(userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size));
}
} }

@ -1,15 +1,15 @@
package com.luoo.user.dao; package com.luoo.user.dao;
import com.luoo.user.pojo.TaskPoint; import com.luoo.user.pojo.TaskPoint;
import java.awt.print.Pageable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
public interface TaskPointDao extends JpaRepository<TaskPoint, String>, public interface TaskPointDao extends JpaRepository<TaskPoint, String>, JpaSpecificationExecutor<TaskPoint> {
JpaSpecificationExecutor<TaskPoint> {
@Query(value = " select * from tb_task_point order by id desc", countProjection = "id", nativeQuery = true) @Query(value = " select * from tb_task_point order by id desc", countProjection = "id", nativeQuery = true)
public Page<TaskPoint> findAll(Pageable pageable); public Page<TaskPoint> selectAll(Pageable pageable);
} }

@ -0,0 +1,18 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.MembershipCode;
import com.luoo.user.pojo.UserPointLog;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
public interface UserPointLogDao extends JpaRepository<UserPointLog, String>, JpaSpecificationExecutor<UserPointLog> {
public List<UserPointLog> findUserPointLogByUserIdAndTaskPointId(String userId, String taskPointId);
@Query(value = " select * from tb_user_point_log where user_id = ?1 order by create_time desc", countProjection = "id", nativeQuery = true)
public Page<UserPointLog> getUserPointLogList(String userId, Pageable pageable);
}

@ -0,0 +1,24 @@
package com.luoo.user.dto.point;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DTO for {@link com.luoo.user.pojo.UserPointLog}
*/
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class UserPointLogSearchDto implements Serializable {
@ApiModelProperty(value = "类型 1-收入 2-支出 null-全部")
public Integer type;
public String userId;
}

@ -0,0 +1,33 @@
package com.luoo.user.listener;
import com.luoo.user.pojo.UserPointLog;
import com.luoo.user.service.UserPointLogService;
import dto.MusicPointDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @program: luoo_parent
* @description:
* @author: yawei.huang
* @create: 2024-07-24 13:05
**/
@Component
@RabbitListener(queues = "pointLog")
@Slf4j
public class PointLogListener {
@Autowired
private UserPointLogService userPointLogService;
@RabbitHandler
public void executePointLog(UserPointLog userPointLog) {
log.info("userPointLog:{}", userPointLog);
userPointLogService.add(userPointLog);
}
}

@ -12,11 +12,9 @@ import javax.persistence.Table;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
@ -25,12 +23,10 @@ import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@Getter @Data
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode
@Builder @Builder
@Entity @Entity
@DynamicInsert @DynamicInsert
@ -83,30 +79,4 @@ public class TaskPoint {
@ApiModelProperty("是否生效1-生效 2-不生效") @ApiModelProperty("是否生效1-生效 2-不生效")
private Integer valid; private Integer valid;
@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
Class<?> oEffectiveClass = o instanceof HibernateProxy
? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass()
: o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer()
.getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) {
return false;
}
TaskPoint point = (TaskPoint) o;
return getId() != null && Objects.equals(getId(), point.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer()
.getPersistentClass().hashCode() : getClass().hashCode();
}
} }

@ -202,5 +202,10 @@ public class UserInfo implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate vipExpireTime; private LocalDate vipExpireTime;
/**
*
*/
private Integer point;
} }

@ -45,6 +45,11 @@ public class UserPointLog implements Serializable {
@ApiModelProperty(value = "用户id") @ApiModelProperty(value = "用户id")
private String userId; private String userId;
@Size(max = 20)
@Column(name = "task_point_id", length = 20)
@ApiModelProperty(value = "任务积分id")
private String taskPointId;
@Size(max = 255) @Size(max = 255)
@Column(name = "description") @Column(name = "description")
@ApiModelProperty(value = "事件描述") @ApiModelProperty(value = "事件描述")

@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import util.IdWorker; import util.IdWorker;
@ -24,16 +25,23 @@ import util.JwtUtil;
@Slf4j @Slf4j
public class TaskPointService { public class TaskPointService {
// 缓存key
public static final String TASK_POINT = "TASK-POINT-";
private final TaskPointDao taskPointDao; private final TaskPointDao taskPointDao;
private final IdWorker idWorker; private final IdWorker idWorker;
private final JwtUtil jwtUtil; private final JwtUtil jwtUtil;
public TaskPointService(TaskPointDao taskPointDao, IdWorker idWorker, JwtUtil jwtUtil) { private final RedisTemplate<String, Object> redisTemplate;
public TaskPointService(TaskPointDao taskPointDao, IdWorker idWorker, JwtUtil jwtUtil,
RedisTemplate<String, Object> redisTemplate) {
this.taskPointDao = taskPointDao; this.taskPointDao = taskPointDao;
this.idWorker = idWorker; this.idWorker = idWorker;
this.jwtUtil = jwtUtil; this.jwtUtil = jwtUtil;
this.redisTemplate = redisTemplate;
} }
@ -52,6 +60,8 @@ public class TaskPointService {
taskPointDao.save(taskPoint); taskPointDao.save(taskPoint);
redisTemplate.opsForValue().set(TASK_POINT + taskPoint.getId(), taskPoint);
} }
/** /**
@ -66,6 +76,9 @@ public class TaskPointService {
taskPoint.setUpdateUser(userLoginDto.getUserId()); taskPoint.setUpdateUser(userLoginDto.getUserId());
taskPointDao.save(taskPoint); taskPointDao.save(taskPoint);
redisTemplate.delete(TASK_POINT + taskPoint.getId());
redisTemplate.opsForValue().set(TASK_POINT + taskPoint.getId(), taskPoint);
} }
/** /**
@ -96,6 +109,9 @@ public class TaskPointService {
taskPoint.setUpdateUser(userLoginDto.getUserId()); taskPoint.setUpdateUser(userLoginDto.getUserId());
taskPointDao.save(taskPoint); taskPointDao.save(taskPoint);
redisTemplate.delete(TASK_POINT + taskPoint.getId());
redisTemplate.opsForValue().set(TASK_POINT + taskPoint.getId(), taskPoint);
} }
/** /**
@ -117,8 +133,19 @@ public class TaskPointService {
*/ */
public PageResult<TaskPoint> getTaskPointList(Integer page, Integer size) { public PageResult<TaskPoint> getTaskPointList(Integer page, Integer size) {
Pageable pageable = PageRequest.of(page - 1, size); Pageable pageable = PageRequest.of(page - 1, size);
Page<TaskPoint> taskPointPage = taskPointDao.findAll(pageable); Page<TaskPoint> taskPointPage = taskPointDao.selectAll(pageable);
long totalElements = taskPointPage.getTotalElements(); long totalElements = taskPointPage.getTotalElements();
return new PageResult<>(totalElements, taskPointPage.getContent()); return new PageResult<>(totalElements, taskPointPage.getContent());
} }
/**
*
*/
public TaskPoint getTaskPoint(String id) {
TaskPoint taskPoint = (TaskPoint) redisTemplate.opsForValue().get(TASK_POINT + id);
if(taskPoint == null) {
taskPoint = taskPointDao.findById(id).get();
}
return taskPoint;
}
} }

@ -18,6 +18,7 @@ import com.luoo.user.util.NickNameUtil;
import com.luoo.user.util.NickNameUtil2; import com.luoo.user.util.NickNameUtil2;
import constants.Constants; import constants.Constants;
import constants.ErrorConstants; import constants.ErrorConstants;
import constants.TaskPointIdConstants;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.UserBankStateEnum; import enums.UserBankStateEnum;
import enums.UserRealNameStateEnum; import enums.UserRealNameStateEnum;
@ -55,34 +56,44 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
public class UserInfoService { public class UserInfoService {
@Autowired private final UserInfoDao userInfoDao;
private UserInfoDao userInfoDao;
@Autowired
private IdWorker idWorker;
@Autowired private final IdWorker idWorker;
private RedisTemplate redisTemplate;
@Autowired private final RedisTemplate redisTemplate;
private RabbitTemplate rabbitTemplate;
@Autowired private final RabbitTemplate rabbitTemplate;
private BCryptPasswordEncoder encoder;
@Autowired private final BCryptPasswordEncoder encoder;
private HttpServletRequest request;
@Autowired private final HttpServletRequest request;
private JwtUtil jwtUtil;
@Autowired private final JwtUtil jwtUtil;
private UserRealNameDao userRealNameDao;
@Autowired private final UserRealNameDao userRealNameDao;
private UserBankDao userBankDao;
@Autowired private final UserBankDao userBankDao;
private WithdrawDao withdrawDao;
private final WithdrawDao withdrawDao;
private final UserPointLogService userPointLogService;
public UserInfoService(UserInfoDao userInfoDao, IdWorker idWorker, RedisTemplate redisTemplate,
RabbitTemplate rabbitTemplate, BCryptPasswordEncoder encoder, HttpServletRequest request,
JwtUtil jwtUtil, UserRealNameDao userRealNameDao, UserBankDao userBankDao,
WithdrawDao withdrawDao, UserPointLogService userPointLogService) {
this.userInfoDao = userInfoDao;
this.idWorker = idWorker;
this.redisTemplate = redisTemplate;
this.rabbitTemplate = rabbitTemplate;
this.encoder = encoder;
this.request = request;
this.jwtUtil = jwtUtil;
this.userRealNameDao = userRealNameDao;
this.userBankDao = userBankDao;
this.withdrawDao = withdrawDao;
this.userPointLogService = userPointLogService;
}
/** /**
* token * token
@ -215,6 +226,7 @@ public class UserInfoService {
public String loginOrRegister(UserInfo loginUserInfo) { public String loginOrRegister(UserInfo loginUserInfo) {
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
boolean isNewUser = false;
if (null == userInfo) { if (null == userInfo) {
userInfo = loginUserInfo; userInfo = loginUserInfo;
userInfo.setId(String.valueOf(idWorker.nextId())); userInfo.setId(String.valueOf(idWorker.nextId()));
@ -228,6 +240,7 @@ public class UserInfoService {
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
isNewUser = true;
} else { } else {
// userInfo.setAppleId(loginUserInfo.getAppleId()); // userInfo.setAppleId(loginUserInfo.getAppleId());
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
@ -239,6 +252,12 @@ public class UserInfoService {
} }
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
if(isNewUser) {
// 只有新用户会获得积分
userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId());
}
return Constants.TOKEN_PREFIX return Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
} }
@ -246,6 +265,7 @@ public class UserInfoService {
public String appleLoginOrRegister(UserInfo loginUserInfo) { public String appleLoginOrRegister(UserInfo loginUserInfo) {
UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId()); UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId());
boolean isNewUser = false;
if (null == userInfo) { if (null == userInfo) {
// return "未注册"; // return "未注册";
userInfo = loginUserInfo; userInfo = loginUserInfo;
@ -259,6 +279,8 @@ public class UserInfoService {
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
isNewUser = true;
} else { } else {
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
@ -269,6 +291,11 @@ public class UserInfoService {
} }
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
if(isNewUser) {
// 只有新用户会获得积分
userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId());
}
return Constants.TOKEN_PREFIX return Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
} }
@ -318,6 +345,9 @@ public class UserInfoService {
public String wechatRegister(UserInfo loginUserInfo) { public String wechatRegister(UserInfo loginUserInfo) {
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
boolean isNewUser = false;
if (null == userInfo) { if (null == userInfo) {
userInfo = loginUserInfo; userInfo = loginUserInfo;
userInfo.setId(String.valueOf(idWorker.nextId())); userInfo.setId(String.valueOf(idWorker.nextId()));
@ -330,6 +360,8 @@ public class UserInfoService {
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
isNewUser = true;
} else { } else {
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
@ -342,6 +374,11 @@ public class UserInfoService {
} }
userInfo.setLastLoginTime(new Date()); userInfo.setLastLoginTime(new Date());
userInfoDao.save(userInfo); userInfoDao.save(userInfo);
if(isNewUser) {
// 只有新用户会获得积分
userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId());
}
return Constants.TOKEN_PREFIX return Constants.TOKEN_PREFIX
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
} }

@ -0,0 +1,209 @@
package com.luoo.user.service;
import api.PageResult;
import com.luoo.user.dao.TaskPointDao;
import com.luoo.user.dao.UserPointLogDao;
import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.pojo.TaskPoint;
import com.luoo.user.pojo.UserInfo;
import com.luoo.user.pojo.UserPointLog;
import dto.UserLoginDto;
import enums.PointEnums;
import java.util.ArrayList;
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.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
import util.JwtUtil;
/**
* @program: luoo_parent
* @description:
* @author: yawei.huang
* @create: 2024-07-24 08:41
**/
@Service
@Slf4j
public class UserPointLogService {
private final UserPointLogDao userPointLogDao;
private final IdWorker idWorker;
private final JwtUtil jwtUtil;
private final TaskPointDao taskPointDao;
private final RabbitTemplate rabbitTemplate;
private final UserInfoService userInfoService;
private final RedisTemplate<String, Object> redisTemplate;
private final TaskPointService taskPointService;
public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil,
TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate,
UserInfoService userInfoService, RedisTemplate<String, Object> redisTemplate,
TaskPointService taskPointService) {
this.userPointLogDao = userPointLogDao;
this.idWorker = idWorker;
this.jwtUtil = jwtUtil;
this.taskPointDao = taskPointDao;
this.rabbitTemplate = rabbitTemplate;
this.userInfoService = userInfoService;
this.redisTemplate = redisTemplate;
this.taskPointService = taskPointService;
}
/**
*
*
* @param taskPointId ID
* @param token tokenID
*/
public void addByTaskNew(String taskPointId, String token) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
// 新手任务,只触发一次
// if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(),
// taskPointId).isEmpty()) {
// return;
// }
addByTask(taskPointId, userLoginDto);
}
/**
*
* <p>
* ID tokenRabbitMQ
*
*
* @param taskPointId ID
* @param token tokenID
*/
public void addByTaskDaily(String taskPointId, String token) {
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
addByTask(taskPointId, userLoginDto);
}
private void addByTask(String taskPointId, UserLoginDto userLoginDto) {
UserPointLog userPointLog = UserPointLog.builder()
.id(String.valueOf(idWorker.nextId()))
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
.createUser(userLoginDto.getUserId())
.taskPointId(taskPointId)
.userId(userLoginDto.getUserId())
.build();
rabbitTemplate.convertAndSend("pointLog", userPointLog);
}
/**
*
* <p>
* @Transactional
*
* @param userPointLog IDID
*/
@Transactional(rollbackFor = Exception.class)
public void add(UserPointLog userPointLog) {
// 根据积分任务ID获取积分任务详情
// 保存积分记录
String taskPointId = userPointLog.getTaskPointId();
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
// 获取积分任务类型
Integer type = taskPoint.getType();
// 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分
if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) {
// 新手任务,只触发一次
if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(),
userPointLog.getTaskPointId()).isEmpty()) {
return;
}
}
userPointLog.setScore(taskPoint.getScore());
userPointLog.setDescription(taskPoint.getDescription());
// 保存用户积分记录
userPointLogDao.save(userPointLog);
// 更新用户积分,获取用户信息并累加积分得分
// 对用户进行积分计算
UserInfo userInfo = userInfoService.findById(userPointLog.getUserId());
Integer point = userInfo.getPoint();
point += userPointLog.getScore();
userInfo.setPoint(point);
// 更新用户积分信息
userInfoService.update(userInfo);
}
/**
*
*
* @param token token
* @param page
* @param size
* @return
*/
public PageResult<UserPointLog> getUserPointLogList(String token,
UserPointLogSearchDto userPointLogSearchDto, Integer page,
Integer size) {
//
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
Sort sort = new Sort(Direction.DESC, "createTime");
PageRequest pageRequest = PageRequest.of(page - 1, size, sort);
userPointLogSearchDto.setUserId(userLoginDto.getUserId());
Specification<UserPointLog> specification = buildSearchSpecification(userPointLogSearchDto);
Page<UserPointLog> userPointLogPage = userPointLogDao.findAll(specification, pageRequest);
long totalElements = userPointLogPage.getTotalElements();
return new PageResult<>(totalElements, userPointLogPage.getContent());
}
private Specification<UserPointLog> buildSearchSpecification(UserPointLogSearchDto param) {
return (Root<UserPointLog> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
List<Predicate> predicateList = new ArrayList<Predicate>();
if (param.getType() != null) {
predicateList.add(
criteriaBuilder.and(criteriaBuilder.equal(root.get("type"), param.getType())));
}
if (StringUtils.isNotBlank(param.getUserId())) {
predicateList.add(
criteriaBuilder.and(criteriaBuilder.equal(root.get("userId"), param.getUserId())));
}
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
};
}
}

@ -12,7 +12,6 @@ create table tb_membership_code
update_user varchar(20) null comment '修改人' update_user varchar(20) null comment '修改人'
) comment '会员码'; ) comment '会员码';
create table tb_user_point_log create table tb_user_point_log
( (
id varchar(20) not null comment 'id' id varchar(20) not null comment 'id'
@ -24,8 +23,12 @@ create table tb_user_point_log
create_time datetime null comment '创建时间', create_time datetime null comment '创建时间',
update_time datetime null comment '修改时间', update_time datetime null comment '修改时间',
create_user varchar(20) null comment '创建人', create_user varchar(20) null comment '创建人',
update_user varchar(20) null comment '修改人' update_user varchar(20) null comment '修改人',
) comment '积分记录表'; task_point_id varchar(20) not null comment 'tb_task_point表id'
)
comment '积分记录表';
alter table tb_user_info alter table tb_user_info
add vip_status tinyint default 0 not null comment '会员状态 0-未开通 1-生效中 2-已过期'; add vip_status tinyint default 0 not null comment '会员状态 0-未开通 1-生效中 2-已过期';
@ -111,4 +114,12 @@ INSERT INTO `tb_task_point` (`id`, `score`, `type`, `description`, `create_time`
`create_user`, `update_user`) `create_user`, `update_user`)
VALUES ('9', 9, 1, '首次完成评价', '2024-07-24 08:57:28', '2024-07-24 08:57:28', VALUES ('9', 9, 1, '首次完成评价', '2024-07-24 08:57:28', '2024-07-24 08:57:28',
'1796003413067173888', '1796003413067173888'); '1796003413067173888', '1796003413067173888');
INSERT INTO `tb_task_point` (`id`, `score`, `type`, `description`, `create_time`, `update_time`,
`create_user`, `update_user`)
VALUES ('17', -1, 2, '积分抽奖', '2024-07-24 08:57:28', '2024-07-24 08:57:28',
'1796003413067173888', '1796003413067173888');
INSERT INTO `tb_task_point` (`id`, `score`, `type`, `description`, `create_time`, `update_time`,
`create_user`, `update_user`)
VALUES ('18', -1, 2, '积分商城', '2024-07-24 08:57:28', '2024-07-24 08:57:28',
'1796003413067173888', '1796003413067173888');

@ -0,0 +1,3 @@
alter table tb_user_info
add point int default 0 not null comment '积分';
Loading…
Cancel
Save