release: APP查询积分任务清单,以及本人是否已参与

release-2024-08-08
huangyw 4 months ago
parent a2bed1ddf6
commit bd46212a2d

@ -139,6 +139,7 @@ public class PointController {
@ApiOperation(value = "1.6. 任务积分列表(PC)", notes = "任务积分列表") @ApiOperation(value = "1.6. 任务积分列表(PC)", notes = "任务积分列表")
@GetMapping("/task/list/{page}/{size}") @GetMapping("/task/list/{page}/{size}")
@GlobalInterceptor(checkAdminLogin = true)
public Result<PageResult<TaskPoint>> getUnApproveList( public Result<PageResult<TaskPoint>> getUnApproveList(
@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, @ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "页码", required = true) @PathVariable Integer page, @ApiParam(value = "页码", required = true) @PathVariable Integer page,
@ -146,6 +147,20 @@ public class PointController {
return Result.success(taskPointService.getTaskPointList(page, size)); 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<List<TaskPointForAppDto>> 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用户调用") @ApiOperation(value = "2.1. 用户根据新手任务获取积分", notes = "仅限app用户调用")
@PostMapping("/log/earn/task/new") @PostMapping("/log/earn/task/new")
@GlobalInterceptor(checkAppUserLogin = true) @GlobalInterceptor(checkAppUserLogin = true)

@ -7,9 +7,13 @@ 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;
import java.util.List;
public interface TaskPointDao extends JpaRepository<TaskPoint, String>, JpaSpecificationExecutor<TaskPoint> { public interface TaskPointDao extends JpaRepository<TaskPoint, String>, 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> selectAll(Pageable pageable); public Page<TaskPoint> selectAll(Pageable pageable);
public List<TaskPoint> findByTypeAndValid(Integer type, Integer valid);
} }

@ -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;
}

@ -3,15 +3,22 @@ package com.luoo.user.service;
import api.PageResult; import api.PageResult;
import com.luoo.user.dao.TaskPointDao; import com.luoo.user.dao.TaskPointDao;
import com.luoo.user.dto.point.TaskPointDto; 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.TaskPoint;
import com.luoo.user.pojo.UserPointLog;
import dto.UserLoginDto; import dto.UserLoginDto;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import enums.PointEnums;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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.jpa.domain.Specification;
import org.springframework.data.redis.core.RedisTemplate; 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;
@ -38,14 +45,24 @@ public class TaskPointService {
private final JwtUtil jwtUtil; 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.taskPointDao = taskPointDao;
this.idWorker = idWorker; this.idWorker = idWorker;
this.jwtUtil = jwtUtil; this.jwtUtil = jwtUtil;
this.redisTemplate = redisTemplate;
} }
private UserPointLogService userPointLogService;
@Autowired @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()); return new PageResult<>(totalElements, taskPointPage.getContent());
} }
/**
* APP
*
* @param token token
* @param type
* @return
*/
public List<TaskPointForAppDto> getTaskPointListForApp(String token, Integer type) {
List<TaskPoint> taskPointList = taskPointDao.findByTypeAndValid(type, PointEnums.VALID.getCode());
List<TaskPointForAppDto> 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;
}
/** /**
* *
*/ */

@ -274,4 +274,20 @@ public class UserPointLogService {
}; };
} }
/**
* -使
*
* @param userId id
* @param taskPointId id
* @return ||
*/
public UserPointLog getUserPointLog(String userId, String taskPointId) {
List<UserPointLog> userPointLogByUserIdAndTaskPointId = userPointLogDao.findUserPointLogByUserIdAndTaskPointId(userId, taskPointId);
if (userPointLogByUserIdAndTaskPointId.isEmpty()) {
return null;
} else {
return userPointLogByUserIdAndTaskPointId.get(0);
}
}
} }

Loading…
Cancel
Save