release: 任务积分配置

release-2024-08-08
huangyw 4 months ago
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,112 @@
package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import java.time.Instant;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
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;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "tb_task_point")
@EntityListeners(AuditingEntityListener.class)
public class TaskPoint {
@Id
@Size(max = 20)
@Column(name = "id", nullable = false, length = 20)
@ApiModelProperty(value = "主键")
private String id;
@Column(name = "score")
@ApiModelProperty(value = "积分")
private Integer score;
@Column(name = "type")
@ApiModelProperty(value = "任务类型 1-新手任务(只触发一次) 2-日常任务(每次触发)")
private Integer type;
@Size(max = 255)
@Column(name = "description")
@ApiModelProperty(value = "任务描述")
private String description;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间")
@CreatedDate
private Instant createTime;
@ApiModelProperty("修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@LastModifiedDate
private Instant updateTime;
@Size(max = 20)
@Column(name = "create_user", length = 20)
@ApiModelProperty(value = "创建人")
private String createUser;
@Size(max = 20)
@Column(name = "update_user", length = 20)
@ApiModelProperty(value = "更新人")
private String updateUser;
@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();
}
}

@ -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…
Cancel
Save