parent
70d6bb2fe8
commit
1122944839
@ -0,0 +1,19 @@
|
|||||||
|
package enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum PointEnums {
|
||||||
|
|
||||||
|
VALID(1, "启用"),
|
||||||
|
INVALID(2, "禁用"),
|
||||||
|
|
||||||
|
;
|
||||||
|
private final Integer code;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
PointEnums(int code, String description) {
|
||||||
|
this.code = code;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package com.luoo.user.controller;
|
||||||
|
|
||||||
|
import annotation.GlobalInterceptor;
|
||||||
|
import api.PageResult;
|
||||||
|
import api.Result;
|
||||||
|
import com.luoo.user.pojo.TaskPoint;
|
||||||
|
import com.luoo.user.service.TaskPointService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @program: luoo_parent
|
||||||
|
* @description: 积分模块
|
||||||
|
* @author: yawei.huang
|
||||||
|
* @create: 2024-07-24 10:11
|
||||||
|
**/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Slf4j
|
||||||
|
@RequestMapping("/point")
|
||||||
|
@Api(tags = "积分模块")
|
||||||
|
public class PointController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskPointService taskPointService;
|
||||||
|
|
||||||
|
|
||||||
|
@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")})
|
||||||
|
public Result<Void> add(
|
||||||
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
||||||
|
@RequestBody TaskPoint taskPoint) {
|
||||||
|
taskPointService.add(taskPoint, authorization);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "1.2.修改任务积分配置", notes = "仅限admin权限用户调用")
|
||||||
|
@PostMapping("/task/update")
|
||||||
|
@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")}
|
||||||
|
)
|
||||||
|
public Result<Void> update(
|
||||||
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
||||||
|
@RequestBody TaskPoint taskPoint) {
|
||||||
|
taskPointService.update(taskPoint, authorization);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "1.3.批量修改任务积分配置", notes = "仅限admin权限用户调用")
|
||||||
|
@PostMapping("/task/batch/update")
|
||||||
|
@GlobalInterceptor(checkAdminLogin = true)
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "taskPoints", value = "任务积分配置", required = true, dataType = "List<TaskPoint>", paramType = "body"),
|
||||||
|
@ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header")}
|
||||||
|
)
|
||||||
|
public Result<Void> batchUpdate(
|
||||||
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
||||||
|
@RequestBody List<TaskPoint> taskPoints) {
|
||||||
|
taskPointService.batchUpdate(taskPoints, authorization);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "1.4.批量禁用任务积分配置", notes = "仅限admin权限用户调用")
|
||||||
|
@PostMapping("/task/batch/disable")
|
||||||
|
@GlobalInterceptor(checkAdminLogin = true)
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@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 = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public Result<Void> batchDisable(
|
||||||
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
||||||
|
@RequestBody List<String> ids,
|
||||||
|
@RequestParam Integer valid) {
|
||||||
|
taskPointService.batchDisable(ids, authorization, valid);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "1.5.禁用任务积分配置", notes = "仅限admin权限用户调用")
|
||||||
|
@PostMapping("/task/disable")
|
||||||
|
@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 = "valid", value = "是否生效 1-生效 2-不生效", required = true, dataType = "Integer", paramType = "query")
|
||||||
|
})
|
||||||
|
public Result<Void> disable(
|
||||||
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
||||||
|
@RequestParam String id,
|
||||||
|
@RequestParam Integer valid) {
|
||||||
|
taskPointService.disable(id, authorization, valid);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "1.6. 任务积分列表", notes = "任务积分列表")
|
||||||
|
@GetMapping("/task/list/{page}/{size}")
|
||||||
|
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 size) {
|
||||||
|
return Result.success(taskPointService.getTaskPointList(page, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +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.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
public interface TaskPointDao extends JpaRepository<TaskPoint, String>,
|
||||||
|
JpaSpecificationExecutor<TaskPoint> {
|
||||||
|
|
||||||
|
@Query(value = " select * from tb_task_point order by id desc", countProjection = "id", nativeQuery = true)
|
||||||
|
public Page<TaskPoint> findAll(Pageable pageable);
|
||||||
|
}
|
@ -0,0 +1,124 @@
|
|||||||
|
package com.luoo.user.service;
|
||||||
|
|
||||||
|
import api.PageResult;
|
||||||
|
import com.luoo.user.dao.TaskPointDao;
|
||||||
|
import com.luoo.user.pojo.TaskPoint;
|
||||||
|
import dto.UserLoginDto;
|
||||||
|
import java.util.List;
|
||||||
|
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.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 09:10
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class TaskPointService {
|
||||||
|
|
||||||
|
private final TaskPointDao taskPointDao;
|
||||||
|
|
||||||
|
private final IdWorker idWorker;
|
||||||
|
|
||||||
|
private final JwtUtil jwtUtil;
|
||||||
|
|
||||||
|
public TaskPointService(TaskPointDao taskPointDao, IdWorker idWorker, JwtUtil jwtUtil) {
|
||||||
|
this.taskPointDao = taskPointDao;
|
||||||
|
this.idWorker = idWorker;
|
||||||
|
this.jwtUtil = jwtUtil;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增配置
|
||||||
|
*
|
||||||
|
* @param taskPoint 配置对象
|
||||||
|
* @param token 当前用户
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void add(TaskPoint taskPoint, String token) {
|
||||||
|
taskPoint.setId(String.valueOf(idWorker.nextId()));
|
||||||
|
|
||||||
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
||||||
|
taskPoint.setCreateUser(userLoginDto.getUserId());
|
||||||
|
|
||||||
|
taskPointDao.save(taskPoint);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改配置
|
||||||
|
*
|
||||||
|
* @param taskPoint 配置对象
|
||||||
|
* @param token 当前用户
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void update(TaskPoint taskPoint, String token) {
|
||||||
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
||||||
|
taskPoint.setUpdateUser(userLoginDto.getUserId());
|
||||||
|
|
||||||
|
taskPointDao.save(taskPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量修改
|
||||||
|
*
|
||||||
|
* @param taskPoints 配置对象
|
||||||
|
* @param token 当前用户
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void batchUpdate(List<TaskPoint> taskPoints, String token) {
|
||||||
|
for (TaskPoint taskPoint : taskPoints) {
|
||||||
|
update(taskPoint, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用、禁用配置
|
||||||
|
*
|
||||||
|
* @param id 配置id
|
||||||
|
* @param token 当前用户
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void disable(String id, String token, int valid) {
|
||||||
|
TaskPoint taskPoint = taskPointDao.findById(id).get();
|
||||||
|
taskPoint.setValid(valid);
|
||||||
|
|
||||||
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
||||||
|
taskPoint.setUpdateUser(userLoginDto.getUserId());
|
||||||
|
|
||||||
|
taskPointDao.save(taskPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量启用、禁用配置
|
||||||
|
*
|
||||||
|
* @param ids ids
|
||||||
|
* @param token 当前用户
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void batchDisable(List<String> ids, String token, int valid) {
|
||||||
|
for (String id : ids) {
|
||||||
|
disable(id, token, valid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页批量查询-目前查询全部
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public PageResult<TaskPoint> getTaskPointList(Integer page, Integer size) {
|
||||||
|
Pageable pageable = PageRequest.of(page - 1, size);
|
||||||
|
Page<TaskPoint> taskPointPage = taskPointDao.findAll(pageable);
|
||||||
|
long totalElements = taskPointPage.getTotalElements();
|
||||||
|
return new PageResult<>(totalElements, taskPointPage.getContent());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue