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 57d9014..88416d4 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 @@ -139,6 +139,7 @@ public class PointController { @ApiOperation(value = "1.6. 任务积分列表(PC)", notes = "任务积分列表") @GetMapping("/task/list/{page}/{size}") + @GlobalInterceptor(checkAdminLogin = true) public Result> getUnApproveList( @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "页码", required = true) @PathVariable Integer page, @@ -146,6 +147,20 @@ public class PointController { return Result.success(taskPointService.getTaskPointList(page, size)); } + @ApiOperation(value = "1.7. 任务积分列表(APP)", notes = "任务积分列表") + @GetMapping("/task/list/app") + @GlobalInterceptor(checkAppUserLogin = true) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "token", required = true, dataType = "String", paramType = "header"), + @ApiImplicitParam(name = "type", value = "任务类型 1-新手任务 2-日常任务", required = true, dataType = "Integer", paramType = "query") + }) + public Result> getUnApproveListApp( + @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, + @ApiParam(value = "任务类型 1-新手任务 2-日常任务", required = true) Integer type + ) { + return Result.success(taskPointService.getTaskPointListForApp(token, type)); + } + @ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用") @PostMapping("/log/earn/task/new") @GlobalInterceptor(checkAppUserLogin = true) 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 57a0de0..b929bd9 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 @@ -7,9 +7,13 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; +import java.util.List; + public interface TaskPointDao extends JpaRepository, JpaSpecificationExecutor { @Query(value = " select * from tb_task_point order by id desc", countProjection = "id", nativeQuery = true) public Page selectAll(Pageable pageable); + public List findByTypeAndValid(Integer type, Integer valid); + } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/point/TaskPointForAppDto.java b/luoo_user/src/main/java/com/luoo/user/dto/point/TaskPointForAppDto.java new file mode 100644 index 0000000..4127e7e --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/point/TaskPointForAppDto.java @@ -0,0 +1,31 @@ +package com.luoo.user.dto.point; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.Value; + +import javax.persistence.Transient; +import java.io.Serializable; + +/** + * DTO for {@link com.luoo.user.pojo.TaskPoint} + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TaskPointForAppDto implements Serializable { + @ApiModelProperty(value = "id") + private String id; + @ApiModelProperty(value = "积分") + private Integer score; + @ApiModelProperty(value = "任务类型 1-新手任务(只触发一次) 2-日常任务(每次触发)") + private Integer type; + @ApiModelProperty(value = "任务描述") + private String description; + + @Transient + @ApiModelProperty(value = "用户任务状态 1-已参加 2-未参加") + Integer userStatus; +} \ No newline at end of file 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 98dfe37..4e7d6a1 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 @@ -3,15 +3,22 @@ package com.luoo.user.service; import api.PageResult; import com.luoo.user.dao.TaskPointDao; import com.luoo.user.dto.point.TaskPointDto; +import com.luoo.user.dto.point.TaskPointForAppDto; import com.luoo.user.pojo.TaskPoint; +import com.luoo.user.pojo.UserPointLog; import dto.UserLoginDto; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import enums.PointEnums; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; 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.jpa.domain.Specification; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -38,14 +45,24 @@ public class TaskPointService { 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; } + private UserPointLogService userPointLogService; + @Autowired - private RedisTemplate redisTemplate; + private void setUserPointLogService(UserPointLogService userPointLogService) { + this.userPointLogService = userPointLogService; + } + /** * 新增配置 @@ -146,6 +163,37 @@ public class TaskPointService { return new PageResult<>(totalElements, taskPointPage.getContent()); } + /** + * APP查询积分任务清单,以及本人是否已参与 + * + * @param token token + * @param type 任务类型 + * @return 列表 + */ + public List getTaskPointListForApp(String token, Integer type) { + List taskPointList = taskPointDao.findByTypeAndValid(type, PointEnums.VALID.getCode()); + + List result = taskPointList.stream().map(taskPoint -> { + TaskPointForAppDto taskPointForAppDto = new TaskPointForAppDto(); + BeanUtils.copyProperties(taskPoint, taskPointForAppDto); + return taskPointForAppDto; + }).collect(Collectors.toList()); + // 如果是新手任务,需要判断是否已参与 + result.forEach(taskPoint -> { + if(Objects.equals(taskPoint.getType(), PointEnums.TASK_TYPE_NEW.getCode())) { + UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token); + UserPointLog checkLog = userPointLogService.getUserPointLog(userLoginDto.getUserId(), taskPoint.getId()); + if(checkLog != null) { + taskPoint.setUserStatus(PointEnums.PARTICIPATED.getCode()); + } else { + taskPoint.setUserStatus(PointEnums.NOT_PARTICIPATED.getCode()); + } + } + + }); + return result; + } + /** * 单个查询 */ 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 8e9a29e..a507ff1 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 @@ -274,4 +274,20 @@ public class UserPointLogService { }; } + /** + * 查询是否已领取过积分-此方法仅供新手任务使用 + * + * @param userId 用户id + * @param taskPointId 任务id + * @return 空 || 已领取积分的记录 + */ + public UserPointLog getUserPointLog(String userId, String taskPointId) { + List userPointLogByUserIdAndTaskPointId = userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userId, taskPointId); + if (userPointLogByUserIdAndTaskPointId.isEmpty()) { + return null; + } else { + return userPointLogByUserIdAndTaskPointId.get(0); + } + } + }