From b37d12cefda9fe00725fc6b0a12dd20cf8208d78 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 15:11:19 +0800 Subject: [PATCH 01/10] =?UTF-8?q?release:=20=E7=94=A8=E6=88=B7=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E4=BB=BB=E5=8A=A1=E8=8E=B7=E5=8F=96=E7=A7=AF=E5=88=86?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E7=9C=8B=E7=A7=AF=E5=88=86=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/enums/PointEnums.java | 6 + .../luoo/user/controller/PointController.java | 47 +++++- .../java/com/luoo/user/dao/TaskPointDao.java | 8 +- .../com/luoo/user/dao/UserPointLogDao.java | 18 +++ .../luoo/user/listener/PointLogListener.java | 33 ++++ .../java/com/luoo/user/pojo/TaskPoint.java | 38 +---- .../java/com/luoo/user/pojo/UserInfo.java | 5 + .../java/com/luoo/user/pojo/UserPointLog.java | 5 + .../luoo/user/service/TaskPointService.java | 2 +- .../user/service/UserPointLogService.java | 144 ++++++++++++++++++ luoo_user/src/main/resources/sql/20240719.sql | 25 +-- luoo_user/src/main/resources/sql/20240724.sql | 3 + 12 files changed, 278 insertions(+), 56 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java create mode 100644 luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java create mode 100644 luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java create mode 100644 luoo_user/src/main/resources/sql/20240724.sql diff --git a/luoo_common/src/main/java/enums/PointEnums.java b/luoo_common/src/main/java/enums/PointEnums.java index d4064c2..f0722ae 100644 --- a/luoo_common/src/main/java/enums/PointEnums.java +++ b/luoo_common/src/main/java/enums/PointEnums.java @@ -8,6 +8,12 @@ public enum PointEnums { VALID(1, "启用"), 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 String description; 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 3adbb80..620adb4 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,7 +4,9 @@ import annotation.GlobalInterceptor; import api.PageResult; import api.Result; import com.luoo.user.pojo.TaskPoint; +import com.luoo.user.pojo.UserPointLog; import com.luoo.user.service.TaskPointService; +import com.luoo.user.service.UserPointLogService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -13,6 +15,7 @@ import io.swagger.annotations.ApiParam; import java.util.List; import lombok.extern.slf4j.Slf4j; 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.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -31,6 +34,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController @Slf4j +@CrossOrigin @RequestMapping("/point") @Api(tags = "积分模块") public class PointController { @@ -38,13 +42,16 @@ public class PointController { @Autowired private TaskPointService taskPointService; + @Autowired + private UserPointLogService userPointLogService; + @ApiOperation(value = "1.1.新增任务积分配置", notes = "仅限admin权限用户调用") @PostMapping("/task/add") @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @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 add( @RequestHeader(value = "Authorization", required = true) String authorization, @RequestBody TaskPoint taskPoint) { @@ -57,7 +64,7 @@ public class PointController { @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @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 update( @RequestHeader(value = "Authorization", required = true) String authorization, @@ -71,7 +78,7 @@ public class PointController { @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List", 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 batchUpdate( @RequestHeader(value = "Authorization", required = true) String authorization, @@ -85,7 +92,7 @@ public class PointController { @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "任务积分配置id", required = true, dataType = "List", 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") } ) @@ -102,7 +109,7 @@ public class PointController { @GlobalInterceptor(checkAdminLogin = true) @ApiImplicitParams({ @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") }) public Result disable( @@ -115,12 +122,40 @@ public class PointController { @ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表") @GetMapping("/task/list/{page}/{size}") - public Result> getUnApproveList(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, + public Result> getUnApproveList( + @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "页码", required = true) @PathVariable Integer page, @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { return Result.success(taskPointService.getTaskPointList(page, size)); } + @ApiOperation(value = "2.1. 用户根据任务获取积分", notes = "仅限app用户调用") + @PostMapping("/log/earn/task") + @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 addLog( + @RequestHeader(value = "Authorization", required = true) String authorization, + @RequestBody String taskPointId) { + userPointLogService.addByTask(taskPointId, authorization); + return Result.success(); + } + + @ApiOperation(value = "2.2.用户积分日志列表", notes = "用户积分日志列表") + @GetMapping("/log/list/{page}/{size}") + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), + @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "Integer", paramType = "path"), + @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "Integer", paramType = "path") + }) + public Result> getUserPointLogList( + @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, + @ApiParam(value = "页码", required = true) @PathVariable Integer page, + @ApiParam(value = "每页条数", required = true) @PathVariable Integer size) { + return Result.success(userPointLogService.getUserPointLogList(token, page, size)); + } } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/TaskPointDao.java b/luoo_user/src/main/java/com/luoo/user/dao/TaskPointDao.java index 3a8a50c..57a0de0 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/TaskPointDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/TaskPointDao.java @@ -1,15 +1,15 @@ package com.luoo.user.dao; import com.luoo.user.pojo.TaskPoint; -import java.awt.print.Pageable; 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 TaskPointDao extends JpaRepository, - JpaSpecificationExecutor { +public interface TaskPointDao extends JpaRepository, JpaSpecificationExecutor { @Query(value = " select * from tb_task_point order by id desc", countProjection = "id", nativeQuery = true) - public Page findAll(Pageable pageable); + public Page selectAll(Pageable pageable); + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java new file mode 100644 index 0000000..1aa176b --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserPointLogDao.java @@ -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, JpaSpecificationExecutor { + + public List 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 getUserPointLogList(String userId, Pageable pageable); +} diff --git a/luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java b/luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java new file mode 100644 index 0000000..856c1a1 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/listener/PointLogListener.java @@ -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); + } + +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java b/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java index c9f499b..1d4c6ff 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java @@ -12,11 +12,9 @@ import javax.persistence.Table; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; 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.format.annotation.DateTimeFormat; -@Getter -@Setter -@ToString -@RequiredArgsConstructor +@Data @NoArgsConstructor @AllArgsConstructor +@EqualsAndHashCode @Builder @Entity @DynamicInsert @@ -83,30 +79,4 @@ public class TaskPoint { @ApiModelProperty("是否生效,1-生效 2-不生效") 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(); - } } \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java index bc284e0..cf116bc 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserInfo.java @@ -202,5 +202,10 @@ public class UserInfo implements Serializable { @DateTimeFormat(pattern = "yyyy-MM-dd") private LocalDate vipExpireTime; + /** + * 积分 + */ + private Integer point; + } diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java index 99109b2..3c6fecb 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserPointLog.java @@ -45,6 +45,11 @@ public class UserPointLog implements Serializable { @ApiModelProperty(value = "用户id") private String userId; + @Size(max = 20) + @Column(name = "task_point_id", length = 20) + @ApiModelProperty(value = "任务积分id") + private String taskPointId; + @Size(max = 255) @Column(name = "description") @ApiModelProperty(value = "事件描述") diff --git a/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java b/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java index ceb2adc..21af1ab 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java @@ -117,7 +117,7 @@ public class TaskPointService { */ public PageResult getTaskPointList(Integer page, Integer size) { Pageable pageable = PageRequest.of(page - 1, size); - Page taskPointPage = taskPointDao.findAll(pageable); + Page taskPointPage = taskPointDao.selectAll(pageable); long totalElements = taskPointPage.getTotalElements(); return new PageResult<>(totalElements, taskPointPage.getContent()); } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java new file mode 100644 index 0000000..1436e2d --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -0,0 +1,144 @@ +package com.luoo.user.service; + +import api.PageResult; +import com.luoo.user.dao.TaskPointDao; +import com.luoo.user.dao.UserPointLogDao; +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.Objects; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +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; + + + public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil, + TaskPointService taskPointService, TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, + UserInfoService userInfoService) { + this.userPointLogDao = userPointLogDao; + this.idWorker = idWorker; + this.jwtUtil = jwtUtil; + this.taskPointDao = taskPointDao; + this.rabbitTemplate = rabbitTemplate; + this.userInfoService = userInfoService; + } + + /** + * 通过任务添加积分明细。 + *

+ * 此方法用于处理用户完成特定任务后增加积分的逻辑。它首先根据任务点ID获取任务点信息, 然后根据用户token获取用户信息,最后创建一个积分日志对象并将其发送到RabbitMQ, + * 以异步方式记录用户的积分变动。 + * + * @param taskPointId 任务点ID,用于查找任务点信息。 + * @param token 用户的token,用于验证用户身份并获取用户ID。 + */ + public void addByTask(String taskPointId, String token) { + + TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); + + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + + UserPointLog userPointLog = UserPointLog.builder() + .id(String.valueOf(idWorker.nextId())) + .score(taskPoint.getScore()) + .type(PointEnums.TASK_POINT_TYPE_ADD.getCode()) + .description(taskPoint.getDescription()) + .createUser(userLoginDto.getUserId()) + .taskPointId(taskPointId) + .userId(userLoginDto.getUserId()) + .build(); + + rabbitTemplate.convertAndSend("pointLog", userPointLog); + } + + /** + * 添加用户积分记录。 + *

+ * 通过@Transactional注解确保该方法操作的数据库事务一致性,任何异常都将导致事务回滚。 + * + * @param userPointLog 用户积分记录对象,包含积分任务ID、用户ID和积分得分。 + */ + @Transactional(rollbackFor = Exception.class) + public void add(UserPointLog userPointLog) { + // 根据积分任务ID获取积分任务详情 + // 保存积分记录 + String taskPointId = userPointLog.getTaskPointId(); + TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); + + // 获取积分任务类型 + Integer type = taskPoint.getType(); + + // 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分 + if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) { + // 新手任务,只触发一次 + if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userPointLog.getUserId(), + userPointLog.getTaskPointId()).isEmpty()) { + return; + } + } + + // 保存用户积分记录 + 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 getUserPointLogList(String token, Integer page, Integer size) { + Pageable pageable = PageRequest.of(page - 1, size); + + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + Page taskPointPage = userPointLogDao.getUserPointLogList(userLoginDto.getUserId(), + pageable); + long totalElements = taskPointPage.getTotalElements(); + + return new PageResult<>(totalElements, taskPointPage.getContent()); + } + +} diff --git a/luoo_user/src/main/resources/sql/20240719.sql b/luoo_user/src/main/resources/sql/20240719.sql index c509d84..01c8c97 100644 --- a/luoo_user/src/main/resources/sql/20240719.sql +++ b/luoo_user/src/main/resources/sql/20240719.sql @@ -12,20 +12,23 @@ create table tb_membership_code update_user varchar(20) null comment '修改人' ) comment '会员码'; - create table tb_user_point_log ( - id varchar(20) not null comment 'id' + id varchar(20) not null comment 'id' primary key, - score int null comment '分数', - type tinyint null comment '1- 增加 2-减少', - user_id varchar(20) null comment '所属用户', - description varchar(255) null comment '事件描述', - create_time datetime null comment '创建时间', - update_time datetime null comment '修改时间', - create_user varchar(20) null comment '创建人', - update_user varchar(20) null comment '修改人' -) comment '积分记录表'; + score int null comment '分数', + type tinyint null comment '1- 增加 2-减少', + user_id varchar(20) null comment '所属用户', + description varchar(255) null comment '事件描述', + create_time datetime null comment '创建时间', + update_time datetime null comment '修改时间', + create_user varchar(20) null comment '创建人', + update_user varchar(20) null comment '修改人', + task_point_id varchar(20) not null comment 'tb_task_point表id' +) + comment '积分记录表'; + + alter table tb_user_info add vip_status tinyint default 0 not null comment '会员状态 0-未开通 1-生效中 2-已过期'; diff --git a/luoo_user/src/main/resources/sql/20240724.sql b/luoo_user/src/main/resources/sql/20240724.sql new file mode 100644 index 0000000..1ad03fd --- /dev/null +++ b/luoo_user/src/main/resources/sql/20240724.sql @@ -0,0 +1,3 @@ +alter table tb_user_info + add point int default 0 not null comment '积分'; + From 6b2fe925923b7c97d883ca0cdc28cc4a18055fc0 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 15:17:48 +0800 Subject: [PATCH 02/10] =?UTF-8?q?release:=20=E7=94=A8=E6=88=B7=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E4=BB=BB=E5=8A=A1=E8=8E=B7=E5=8F=96=E7=A7=AF=E5=88=86?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E7=9C=8B=E7=A7=AF=E5=88=86=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/luoo/user/controller/PointController.java | 1 + luoo_user/src/main/resources/sql/20240719.sql | 8 ++++++++ 2 files changed, 9 insertions(+) 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 620adb4..072d32f 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 @@ -150,6 +150,7 @@ public class PointController { @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "Integer", paramType = "path"), @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "Integer", paramType = "path") }) + @GlobalInterceptor(checkAppUserLogin = true) public Result> getUserPointLogList( @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "页码", required = true) @PathVariable Integer page, diff --git a/luoo_user/src/main/resources/sql/20240719.sql b/luoo_user/src/main/resources/sql/20240719.sql index 01c8c97..0627155 100644 --- a/luoo_user/src/main/resources/sql/20240719.sql +++ b/luoo_user/src/main/resources/sql/20240719.sql @@ -114,4 +114,12 @@ INSERT INTO `tb_task_point` (`id`, `score`, `type`, `description`, `create_time` `create_user`, `update_user`) VALUES ('9', 9, 1, '首次完成评价', '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 ('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'); From c3e7a7aced3aa70a7e099b4cb30fa80f0bcd90be Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 15:44:45 +0800 Subject: [PATCH 03/10] =?UTF-8?q?release:=20=E6=A0=B9=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=9F=A5=E8=AF=A2=E7=A7=AF=E5=88=86=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/PointController.java | 11 ++-- .../user/dto/point/UserPointLogSearchDto.java | 24 +++++++++ .../user/service/UserPointLogService.java | 52 ++++++++++++++++--- 3 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/point/UserPointLogSearchDto.java 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 072d32f..e44e034 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 @@ -3,6 +3,7 @@ package com.luoo.user.controller; import annotation.GlobalInterceptor; import api.PageResult; import api.Result; +import com.luoo.user.dto.point.UserPointLogSearchDto; import com.luoo.user.pojo.TaskPoint; import com.luoo.user.pojo.UserPointLog; import com.luoo.user.service.TaskPointService; @@ -144,18 +145,14 @@ public class PointController { } @ApiOperation(value = "2.2.用户积分日志列表", notes = "用户积分日志列表") - @GetMapping("/log/list/{page}/{size}") - @ApiImplicitParams({ - @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), - @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "Integer", paramType = "path"), - @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "Integer", paramType = "path") - }) + @PostMapping("/log/list/{page}/{size}") @GlobalInterceptor(checkAppUserLogin = true) public Result> 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, page, size)); + return Result.success(userPointLogService.getUserPointLogList(token, userPointLogSearchDto, page, size)); } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/point/UserPointLogSearchDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/UserPointLogSearchDto.java new file mode 100644 index 0000000..5d7e5ad --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/point/UserPointLogSearchDto.java @@ -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; + +} \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index 1436e2d..991882b 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -3,18 +3,31 @@ 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 com.mysql.fabric.xmlrpc.base.Param; 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.ObjectUtils; +import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; 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; import util.IdWorker; @@ -130,15 +143,40 @@ public class UserPointLogService { * @param size 每页数量 * @return 用户积分列表 */ - public PageResult getUserPointLogList(String token, Integer page, Integer size) { - Pageable pageable = PageRequest.of(page - 1, size); - + public PageResult getUserPointLogList(String token, UserPointLogSearchDto userPointLogSearchDto, Integer page, + Integer size) { +// UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - Page taskPointPage = userPointLogDao.getUserPointLogList(userLoginDto.getUserId(), - pageable); - long totalElements = taskPointPage.getTotalElements(); - return new PageResult<>(totalElements, taskPointPage.getContent()); + Sort sort = new Sort(Direction.DESC, "createTime"); + PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + + userPointLogSearchDto.setUserId(userLoginDto.getUserId()); + Specification specification = buildSearchSpecification(userPointLogSearchDto); + Page userPointLogPage = userPointLogDao.findAll(specification, pageRequest); + + long totalElements = userPointLogPage.getTotalElements(); + return new PageResult<>(totalElements, userPointLogPage.getContent()); + + + } + + private Specification buildSearchSpecification(UserPointLogSearchDto param) { + return (Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) -> { + List predicateList = new ArrayList(); + + 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()])); + }; } } From 9c7c078432cb14ab64fe8227a0bd6bb3c111e6b0 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 15:52:12 +0800 Subject: [PATCH 04/10] =?UTF-8?q?release:=20=E6=A0=B9=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=9F=A5=E8=AF=A2=E7=A7=AF=E5=88=86=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/service/UserPointLogService.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index 991882b..686c784 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -57,7 +57,7 @@ public class UserPointLogService { public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil, - TaskPointService taskPointService, TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, + TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoService userInfoService) { this.userPointLogDao = userPointLogDao; this.idWorker = idWorker; @@ -78,10 +78,16 @@ public class UserPointLogService { */ public void addByTask(String taskPointId, String token) { - TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); - UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + // 新手任务,只触发一次 + if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(), + taskPointId).isEmpty()) { + return; + } + + TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); + UserPointLog userPointLog = UserPointLog.builder() .id(String.valueOf(idWorker.nextId())) .score(taskPoint.getScore()) @@ -143,7 +149,8 @@ public class UserPointLogService { * @param size 每页数量 * @return 用户积分列表 */ - public PageResult getUserPointLogList(String token, UserPointLogSearchDto userPointLogSearchDto, Integer page, + public PageResult getUserPointLogList(String token, + UserPointLogSearchDto userPointLogSearchDto, Integer page, Integer size) { // UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); From 0a39ea0975e72c2f3fea1684ec9f48446c039b49 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 16:04:30 +0800 Subject: [PATCH 05/10] =?UTF-8?q?release:=20=E4=BB=BB=E5=8A=A1=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=A7=AF=E5=88=86=E6=8B=86=E5=88=86=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/PointController.java | 24 ++++++++++++---- .../user/service/UserPointLogService.java | 28 +++++++++++++++---- 2 files changed, 41 insertions(+), 11 deletions(-) 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 e44e034..fd4191f 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 @@ -130,21 +130,35 @@ public class PointController { return Result.success(taskPointService.getTaskPointList(page, size)); } - @ApiOperation(value = "2.1. 用户根据任务获取积分", notes = "仅限app用户调用") - @PostMapping("/log/earn/task") + @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 addLog( + public Result addLogNew( @RequestHeader(value = "Authorization", required = true) String authorization, @RequestBody String taskPointId) { - userPointLogService.addByTask(taskPointId, authorization); + userPointLogService.addByTaskNew(taskPointId, authorization); return Result.success(); } - @ApiOperation(value = "2.2.用户积分日志列表", notes = "用户积分日志列表") + @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 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> getUserPointLogList( diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index 686c784..b6567bf 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -67,6 +67,24 @@ public class UserPointLogService { this.userInfoService = userInfoService; } + /** + * 新手任务,只触发一次 + * + * @param taskPointId 任务点ID + * @param token 用户的token,用于验证用户身份并获取用户ID。 + */ + public void addByTaskNew(String taskPointId, String token) { + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + + // 新手任务,只触发一次 + if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(), + taskPointId).isEmpty()) { + return; + } + + addByTask(taskPointId, userLoginDto); + } + /** * 通过任务添加积分明细。 *

@@ -76,16 +94,14 @@ public class UserPointLogService { * @param taskPointId 任务点ID,用于查找任务点信息。 * @param token 用户的token,用于验证用户身份并获取用户ID。 */ - public void addByTask(String taskPointId, String token) { + public void addByTaskDaily(String taskPointId, String token) { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); - // 新手任务,只触发一次 - if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(), - taskPointId).isEmpty()) { - return; - } + addByTask(taskPointId, userLoginDto); + } + private void addByTask(String taskPointId, UserLoginDto userLoginDto) { TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); UserPointLog userPointLog = UserPointLog.builder() From e8b51a5dbe0626a58196cee72e8eb3bcf64664e8 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 16:21:50 +0800 Subject: [PATCH 06/10] =?UTF-8?q?release:=20=E6=96=B0=E6=89=8B=E6=AC=A2?= =?UTF-8?q?=E8=BF=8E=E5=A5=96=E5=8A=B1=E7=A7=AF=E5=88=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/constants/TaskPointIdConstants.java | 51 ++++++++++++ .../luoo/user/service/UserInfoService.java | 77 ++++++++++++++----- 2 files changed, 108 insertions(+), 20 deletions(-) create mode 100644 luoo_common/src/main/java/constants/TaskPointIdConstants.java diff --git a/luoo_common/src/main/java/constants/TaskPointIdConstants.java b/luoo_common/src/main/java/constants/TaskPointIdConstants.java new file mode 100644 index 0000000..fdc64cf --- /dev/null +++ b/luoo_common/src/main/java/constants/TaskPointIdConstants.java @@ -0,0 +1,51 @@ +package constants; + +/** + * @program: luoo_parent + * @description: 任务积分id固定值 + * @author: yawei.huang + * @create: 2024-07-24 15:50 + **/ +public class TaskPointIdConstants { + + // 新手欢迎奖励 todo + public static final String NEW_USER_WELCOME_AWARD = "1"; + // 修改头像 todo + public static final String MODIFY_AVATAR = "2"; + // 修改昵称 todo + 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"; + + +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java index ebb64aa..462bdeb 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java @@ -18,6 +18,7 @@ import com.luoo.user.util.NickNameUtil; import com.luoo.user.util.NickNameUtil2; import constants.Constants; import constants.ErrorConstants; +import constants.TaskPointIdConstants; import dto.UserLoginDto; import enums.UserBankStateEnum; import enums.UserRealNameStateEnum; @@ -55,34 +56,44 @@ import java.util.stream.Collectors; */ @Service public class UserInfoService { - @Autowired - private UserInfoDao userInfoDao; - @Autowired - private IdWorker idWorker; + private final UserInfoDao userInfoDao; - @Autowired - private RedisTemplate redisTemplate; + private final IdWorker idWorker; - @Autowired - private RabbitTemplate rabbitTemplate; + private final RedisTemplate redisTemplate; - @Autowired - private BCryptPasswordEncoder encoder; + private final RabbitTemplate rabbitTemplate; - @Autowired - private HttpServletRequest request; + private final BCryptPasswordEncoder encoder; - @Autowired - private JwtUtil jwtUtil; + private final HttpServletRequest request; - @Autowired - private UserRealNameDao userRealNameDao; + private final JwtUtil jwtUtil; - @Autowired - private UserBankDao userBankDao; + private final UserRealNameDao userRealNameDao; - @Autowired - private WithdrawDao withdrawDao; + private final UserBankDao userBankDao; + + 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解析示例 @@ -215,6 +226,7 @@ public class UserInfoService { public String loginOrRegister(UserInfo loginUserInfo) { UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); + boolean isNewUser = false; if (null == userInfo) { userInfo = loginUserInfo; userInfo.setId(String.valueOf(idWorker.nextId())); @@ -228,6 +240,7 @@ public class UserInfoService { userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); + isNewUser = true; } else { // userInfo.setAppleId(loginUserInfo.getAppleId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); @@ -239,6 +252,12 @@ public class UserInfoService { } userInfo.setLastLoginTime(new Date()); userInfoDao.save(userInfo); + + if(isNewUser) { + // 只有新用户会获得积分 + userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId()); + } + return Constants.TOKEN_PREFIX + 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) { UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId()); + boolean isNewUser = false; if (null == userInfo) { // return "未注册"; userInfo = loginUserInfo; @@ -259,6 +279,8 @@ public class UserInfoService { userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); + + isNewUser = true; } else { userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); @@ -269,6 +291,11 @@ public class UserInfoService { } userInfo.setLastLoginTime(new Date()); userInfoDao.save(userInfo); + + if(isNewUser) { + // 只有新用户会获得积分 + userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId()); + } return Constants.TOKEN_PREFIX + 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) { UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile()); + + boolean isNewUser = false; + if (null == userInfo) { userInfo = loginUserInfo; userInfo.setId(String.valueOf(idWorker.nextId())); @@ -330,6 +360,8 @@ public class UserInfoService { userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); + + isNewUser = true; } else { userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); @@ -342,6 +374,11 @@ public class UserInfoService { } userInfo.setLastLoginTime(new Date()); userInfoDao.save(userInfo); + + if(isNewUser) { + // 只有新用户会获得积分 + userPointLogService.addByTaskNew(TaskPointIdConstants.NEW_USER_WELCOME_AWARD, userInfo.getId()); + } return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar()); } From ed2fba61cab11a246c0af11a4ecd0f243d9cf580 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 16:24:35 +0800 Subject: [PATCH 07/10] =?UTF-8?q?release:=20=E4=BF=AE=E6=94=B9=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E7=A7=AF=E5=88=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/constants/TaskPointIdConstants.java | 4 ++-- .../main/java/com/luoo/user/controller/MyController.java | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/luoo_common/src/main/java/constants/TaskPointIdConstants.java b/luoo_common/src/main/java/constants/TaskPointIdConstants.java index fdc64cf..758d7b7 100644 --- a/luoo_common/src/main/java/constants/TaskPointIdConstants.java +++ b/luoo_common/src/main/java/constants/TaskPointIdConstants.java @@ -8,9 +8,9 @@ package constants; **/ public class TaskPointIdConstants { - // 新手欢迎奖励 todo + // 新手欢迎奖励 public static final String NEW_USER_WELCOME_AWARD = "1"; - // 修改头像 todo + // 修改头像 public static final String MODIFY_AVATAR = "2"; // 修改昵称 todo public static final String MODIFY_NICKNAME = "3"; diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index cddc65f..2857323 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -17,6 +17,7 @@ import com.luoo.user.service.*; import com.luoo.user.util.EmojiConverterUtil; import com.luoo.user.util.IpUtil; import constants.Constants; +import constants.TaskPointIdConstants; import controller.BaseController; import dto.UserLoginDto; import enums.*; @@ -84,6 +85,9 @@ public class MyController extends BaseController { @Autowired private UserMessageDao userMessageDao; + @Autowired + private UserPointLogService userPointLogService; + @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") @GetMapping("/userInfo") @GlobalInterceptor(checkAppUserLogin = true) @@ -182,6 +186,8 @@ public class MyController extends BaseController { userInfoService.update(user); rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); + + userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_AVATAR, userLoginDto.getUserId()); return Result.success(Constants.RESOURCE_PREFIX + user.getThumbnail()); } From 8c5bab19e1d981954bdd858715eac8df50698b79 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 16:29:04 +0800 Subject: [PATCH 08/10] =?UTF-8?q?release:=20=E4=BF=AE=E6=94=B9=E6=98=B5?= =?UTF-8?q?=E7=A7=B0=E7=A7=AF=E5=88=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/constants/TaskPointIdConstants.java | 2 +- .../java/com/luoo/user/controller/MyController.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/luoo_common/src/main/java/constants/TaskPointIdConstants.java b/luoo_common/src/main/java/constants/TaskPointIdConstants.java index 758d7b7..b3f1a1e 100644 --- a/luoo_common/src/main/java/constants/TaskPointIdConstants.java +++ b/luoo_common/src/main/java/constants/TaskPointIdConstants.java @@ -12,7 +12,7 @@ public class TaskPointIdConstants { public static final String NEW_USER_WELCOME_AWARD = "1"; // 修改头像 public static final String MODIFY_AVATAR = "2"; - // 修改昵称 todo + // 修改昵称 public static final String MODIFY_NICKNAME = "3"; // 完善个人信息 todo public static final String COMPLETE_PERSONAL_INFORMATION = "4"; diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index 2857323..05c388c 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -132,6 +132,12 @@ public class MyController extends BaseController { } } + boolean isChangeNickName = false; + if(!Objects.equals(nickName, user.getNickName())) { + // 修改了昵称 + isChangeNickName = true; + } + if (!StringTools.isEmpty(nickName)) { user.setNickName(nickName); rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); @@ -152,6 +158,11 @@ public class MyController extends BaseController { } user.setModifyTime(new Date()); userInfoService.update(user); + + if(isChangeNickName) { + // 修改了昵称 + userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_NICKNAME, user.getNickName()); + } return Result.success(); } From 07001a12cd0bfebdd00d0c76314dc7e862562bd6 Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 16:33:14 +0800 Subject: [PATCH 09/10] =?UTF-8?q?release:=20=E4=BF=AE=E6=94=B9=E6=98=B5?= =?UTF-8?q?=E7=A7=B0=E7=A7=AF=E5=88=86=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/luoo/user/controller/MyController.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index 05c388c..dc0d3bb 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -132,11 +132,8 @@ public class MyController extends BaseController { } } - boolean isChangeNickName = false; - if(!Objects.equals(nickName, user.getNickName())) { - // 修改了昵称 - isChangeNickName = true; - } + // 修改了昵称 + boolean isChangeNickName = !Objects.equals(nickName, user.getNickName()); if (!StringTools.isEmpty(nickName)) { user.setNickName(nickName); From d4863fb7675634504b27898c587bd67af5248c3e Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 17:00:18 +0800 Subject: [PATCH 10/10] =?UTF-8?q?release:=20=E7=A7=AF=E5=88=86=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=BD=BF=E7=94=A8redis=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/service/TaskPointService.java | 29 +++++++++++++++++- .../user/service/UserPointLogService.java | 30 +++++++++++-------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java b/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java index 21af1ab..9d9d42b 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java @@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import util.IdWorker; @@ -24,16 +25,23 @@ import util.JwtUtil; @Slf4j public class TaskPointService { + // 缓存key + public static final String TASK_POINT = "TASK-POINT-"; + private final TaskPointDao taskPointDao; private final IdWorker idWorker; private final JwtUtil jwtUtil; - public TaskPointService(TaskPointDao taskPointDao, IdWorker idWorker, JwtUtil jwtUtil) { + private final RedisTemplate redisTemplate; + + public TaskPointService(TaskPointDao taskPointDao, IdWorker idWorker, JwtUtil jwtUtil, + RedisTemplate redisTemplate) { this.taskPointDao = taskPointDao; this.idWorker = idWorker; this.jwtUtil = jwtUtil; + this.redisTemplate = redisTemplate; } @@ -52,6 +60,8 @@ public class TaskPointService { taskPointDao.save(taskPoint); + redisTemplate.opsForValue().set(TASK_POINT + taskPoint.getId(), taskPoint); + } /** @@ -66,6 +76,9 @@ public class TaskPointService { taskPoint.setUpdateUser(userLoginDto.getUserId()); 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()); taskPointDao.save(taskPoint); + + redisTemplate.delete(TASK_POINT + taskPoint.getId()); + redisTemplate.opsForValue().set(TASK_POINT + taskPoint.getId(), taskPoint); } /** @@ -121,4 +137,15 @@ public class TaskPointService { long totalElements = taskPointPage.getTotalElements(); 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; + } } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index b6567bf..0934be7 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -7,7 +7,6 @@ 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 com.mysql.fabric.xmlrpc.base.Param; import dto.UserLoginDto; import enums.PointEnums; import java.util.ArrayList; @@ -18,16 +17,14 @@ 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.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.beans.factory.annotation.Autowired; 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.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import util.IdWorker; @@ -55,16 +52,23 @@ public class UserPointLogService { private final UserInfoService userInfoService; + private final RedisTemplate redisTemplate; + + private final TaskPointService taskPointService; + public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil, TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, - UserInfoService userInfoService) { + UserInfoService userInfoService, RedisTemplate 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; } /** @@ -77,10 +81,10 @@ public class UserPointLogService { UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); // 新手任务,只触发一次 - if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(), - taskPointId).isEmpty()) { - return; - } +// if (!userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userLoginDto.getUserId(), +// taskPointId).isEmpty()) { +// return; +// } addByTask(taskPointId, userLoginDto); } @@ -102,13 +106,10 @@ public class UserPointLogService { } private void addByTask(String taskPointId, UserLoginDto userLoginDto) { - TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); UserPointLog userPointLog = UserPointLog.builder() .id(String.valueOf(idWorker.nextId())) - .score(taskPoint.getScore()) .type(PointEnums.TASK_POINT_TYPE_ADD.getCode()) - .description(taskPoint.getDescription()) .createUser(userLoginDto.getUserId()) .taskPointId(taskPointId) .userId(userLoginDto.getUserId()) @@ -129,7 +130,7 @@ public class UserPointLogService { // 根据积分任务ID获取积分任务详情 // 保存积分记录 String taskPointId = userPointLog.getTaskPointId(); - TaskPoint taskPoint = taskPointDao.findById(taskPointId).get(); + TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId); // 获取积分任务类型 Integer type = taskPoint.getType(); @@ -143,6 +144,9 @@ public class UserPointLogService { } } + userPointLog.setScore(taskPoint.getScore()); + userPointLog.setDescription(taskPoint.getDescription()); + // 保存用户积分记录 userPointLogDao.save(userPointLog);