From 1122944839fb6913cba629be2475f88959cf962e Mon Sep 17 00:00:00 2001 From: huangyw <1207046171@qq.com> Date: Wed, 24 Jul 2024 10:46:02 +0800 Subject: [PATCH] =?UTF-8?q?release:=20=E4=BB=BB=E5=8A=A1=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/enums/PointEnums.java | 19 +++ .../luoo/user/controller/PointController.java | 126 ++++++++++++++++++ .../java/com/luoo/user/dao/TaskPointDao.java | 15 +++ .../java/com/luoo/user/pojo/TaskPoint.java | 112 ++++++++++++++++ .../luoo/user/service/TaskPointService.java | 124 +++++++++++++++++ 5 files changed, 396 insertions(+) create mode 100644 luoo_common/src/main/java/enums/PointEnums.java create mode 100644 luoo_user/src/main/java/com/luoo/user/controller/PointController.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dao/TaskPointDao.java create mode 100644 luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java create mode 100644 luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java diff --git a/luoo_common/src/main/java/enums/PointEnums.java b/luoo_common/src/main/java/enums/PointEnums.java new file mode 100644 index 0000000..d4064c2 --- /dev/null +++ b/luoo_common/src/main/java/enums/PointEnums.java @@ -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; + } +} 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 new file mode 100644 index 0000000..3adbb80 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/controller/PointController.java @@ -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 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 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", paramType = "body"), + @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header")} + ) + public Result batchUpdate( + @RequestHeader(value = "Authorization", required = true) String authorization, + @RequestBody List 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", 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 batchDisable( + @RequestHeader(value = "Authorization", required = true) String authorization, + @RequestBody List 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 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> 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)); + } + + + +} 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 new file mode 100644 index 0000000..3a8a50c --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/TaskPointDao.java @@ -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, + JpaSpecificationExecutor { + + @Query(value = " select * from tb_task_point order by id desc", countProjection = "id", nativeQuery = true) + public Page findAll(Pageable pageable); +} 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 new file mode 100644 index 0000000..c9f499b --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/TaskPoint.java @@ -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(); + } +} \ 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 new file mode 100644 index 0000000..ceb2adc --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java @@ -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 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 ids, String token, int valid) { + for (String id : ids) { + disable(id, token, valid); + } + } + + /** + * 分页批量查询-目前查询全部 + * + */ + public PageResult getTaskPointList(Integer page, Integer size) { + Pageable pageable = PageRequest.of(page - 1, size); + Page taskPointPage = taskPointDao.findAll(pageable); + long totalElements = taskPointPage.getTotalElements(); + return new PageResult<>(totalElements, taskPointPage.getContent()); + } +}