Pārlūkot izejas kodu

fix:修复请求参数同名导致的前端生成API失败问题,将封装的对象解包,使用多个具体的参数进行接收;

yangyi 4 mēneši atpakaļ
vecāks
revīzija
5f1eb3e76f

+ 1 - 1
src/main/java/space/anyi/petServiceManagementSystem/server/config/PasswordConfig.java

@@ -8,7 +8,7 @@ import java.security.NoSuchAlgorithmException;
 @Component
 public class PasswordConfig {
 
-    private static final String SALT = "PetService2024!@#";
+    private static final String SALT = "PetService2026!@#";
 
     public String encrypt(String password) {
         try {

+ 8 - 3
src/main/java/space/anyi/petServiceManagementSystem/server/controller/UserController.java

@@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import space.anyi.petServiceManagementSystem.server.common.PageVo;
 import space.anyi.petServiceManagementSystem.server.common.R;
-import space.anyi.petServiceManagementSystem.server.dto.room.QueryByPageParams;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserAvatarDto;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserPasswordDto;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserStatusDto;
@@ -27,8 +26,14 @@ public class UserController {
 
     @GetMapping
     @Operation(summary = "分页查询用户列表")
-    public R<PageVo<UserVo>> queryByPage(@Valid QueryByPageParams params) {
-        return R.ok(userService.queryByPage(params));
+    public R<PageVo<UserVo>> queryByPage(
+            @RequestParam(defaultValue = "1") int pageNum,
+            @RequestParam(defaultValue = "10") int pageSize,
+            @RequestParam(required = false) String username,
+            @RequestParam(required = false) String account,
+            @RequestParam(required = false) String role,
+            @RequestParam(required = false) Integer enable) {
+        return R.ok(userService.queryByPage(pageNum, pageSize, username, account, role, enable));
     }
 
     @GetMapping("/{id}")

+ 6 - 3
src/main/java/space/anyi/petServiceManagementSystem/server/controller/admin/AdminAppointmentController.java

@@ -8,7 +8,6 @@ import space.anyi.petServiceManagementSystem.server.common.PageVo;
 import space.anyi.petServiceManagementSystem.server.common.R;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.HandleCancelDto;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.ReviewDto;
-import space.anyi.petServiceManagementSystem.server.dto.room.QueryByPageParams;
 import space.anyi.petServiceManagementSystem.server.service.AppointmentService;
 import space.anyi.petServiceManagementSystem.server.vo.appointment.AppointmentVo;
 
@@ -21,8 +20,12 @@ public class AdminAppointmentController {
 
     @GetMapping
     @Operation(summary = "获取全部预约(管理员)")
-    public R<PageVo<AppointmentVo>> listAll(@Valid QueryByPageParams params) {
-        return R.ok(appointmentService.listAll(params));
+    public R<PageVo<AppointmentVo>> listAll(
+            @RequestParam(defaultValue = "1") int pageNum,
+            @RequestParam(defaultValue = "10") int pageSize,
+            @RequestParam(required = false) String status,
+            @RequestParam(required = false) String type) {
+        return R.ok(appointmentService.listAll(pageNum, pageSize, status, type));
     }
 
     @PutMapping("/{id}/review")

+ 8 - 4
src/main/java/space/anyi/petServiceManagementSystem/server/controller/admin/AdminUserController.java

@@ -1,12 +1,10 @@
 package space.anyi.petServiceManagementSystem.server.controller.admin;
 
 import io.swagger.v3.oas.annotations.Operation;
-import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import space.anyi.petServiceManagementSystem.server.common.PageVo;
 import space.anyi.petServiceManagementSystem.server.common.R;
-import space.anyi.petServiceManagementSystem.server.dto.room.QueryByPageParams;
 import space.anyi.petServiceManagementSystem.server.service.UserService;
 import space.anyi.petServiceManagementSystem.server.vo.user.AdminUserDetailVo;
 import space.anyi.petServiceManagementSystem.server.vo.user.UserVo;
@@ -20,8 +18,14 @@ public class AdminUserController {
 
     @GetMapping
     @Operation(summary = "获取注册用户列表")
-    public R<PageVo<UserVo>> list(@Valid QueryByPageParams params) {
-        return R.ok(userService.queryByPage(params));
+    public R<PageVo<UserVo>> list(
+            @RequestParam(defaultValue = "1") int pageNum,
+            @RequestParam(defaultValue = "10") int pageSize,
+            @RequestParam(required = false) String username,
+            @RequestParam(required = false) String account,
+            @RequestParam(required = false) String role,
+            @RequestParam(required = false) Integer enable) {
+        return R.ok(userService.queryByPage(pageNum, pageSize, username, account, role, enable));
     }
 
     @GetMapping("/{id}")

+ 0 - 35
src/main/java/space/anyi/petServiceManagementSystem/server/dto/room/QueryByPageParams.java

@@ -1,35 +0,0 @@
-package space.anyi.petServiceManagementSystem.server.dto.room;
-
-import jakarta.validation.constraints.Min;
-
-public class QueryByPageParams {
-    @Min(value = 1, message = "页码最小为1")
-    private int pageNum = 1;
-
-    @Min(value = 1, message = "每页条数最小为1")
-    private int pageSize = 10;
-
-    private String username;
-    private String account;
-    private String role;
-    private Integer enable;
-    private String status;
-    private String type;
-
-    public int getPageNum() { return pageNum; }
-    public void setPageNum(int pageNum) { this.pageNum = pageNum; }
-    public int getPageSize() { return pageSize; }
-    public void setPageSize(int pageSize) { this.pageSize = pageSize; }
-    public String getUsername() { return username; }
-    public void setUsername(String username) { this.username = username; }
-    public String getAccount() { return account; }
-    public void setAccount(String account) { this.account = account; }
-    public String getRole() { return role; }
-    public void setRole(String role) { this.role = role; }
-    public Integer getEnable() { return enable; }
-    public void setEnable(Integer enable) { this.enable = enable; }
-    public String getStatus() { return status; }
-    public void setStatus(String status) { this.status = status; }
-    public String getType() { return type; }
-    public void setType(String type) { this.type = type; }
-}

+ 1 - 2
src/main/java/space/anyi/petServiceManagementSystem/server/service/AppointmentService.java

@@ -4,7 +4,6 @@ import space.anyi.petServiceManagementSystem.server.common.PageVo;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.AppointmentDto;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.HandleCancelDto;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.ReviewDto;
-import space.anyi.petServiceManagementSystem.server.dto.room.QueryByPageParams;
 import space.anyi.petServiceManagementSystem.server.vo.appointment.AppointmentVo;
 
 import java.util.List;
@@ -15,7 +14,7 @@ public interface AppointmentService {
     AppointmentVo getById(Long id, Long userId);
     Boolean cancel(Long id, String reason, Long userId);
     Boolean payDeposit(Long id, Long userId);
-    PageVo<AppointmentVo> listAll(QueryByPageParams params);
+    PageVo<AppointmentVo> listAll(int pageNum, int pageSize, String status, String type);
     Boolean review(Long id, ReviewDto dto);
     Boolean handleCancel(Long id, HandleCancelDto dto);
 }

+ 1 - 2
src/main/java/space/anyi/petServiceManagementSystem/server/service/UserService.java

@@ -1,7 +1,6 @@
 package space.anyi.petServiceManagementSystem.server.service;
 
 import space.anyi.petServiceManagementSystem.server.common.PageVo;
-import space.anyi.petServiceManagementSystem.server.dto.room.QueryByPageParams;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserAvatarDto;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserPasswordDto;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserStatusDto;
@@ -12,7 +11,7 @@ import space.anyi.petServiceManagementSystem.server.vo.user.UserVo;
 import java.util.List;
 
 public interface UserService {
-    PageVo<UserVo> queryByPage(QueryByPageParams params);
+    PageVo<UserVo> queryByPage(int pageNum, int pageSize, String username, String account, String role, Integer enable);
     UserVo queryById(Long id);
     Boolean add(UserDto dto);
     Boolean edit(UserDto dto);

+ 6 - 7
src/main/java/space/anyi/petServiceManagementSystem/server/service/impl/AppointmentServiceImpl.java

@@ -8,7 +8,6 @@ import space.anyi.petServiceManagementSystem.server.common.PageVo;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.AppointmentDto;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.HandleCancelDto;
 import space.anyi.petServiceManagementSystem.server.dto.appointment.ReviewDto;
-import space.anyi.petServiceManagementSystem.server.dto.room.QueryByPageParams;
 import space.anyi.petServiceManagementSystem.server.entity.*;
 import space.anyi.petServiceManagementSystem.server.mapper.*;
 import space.anyi.petServiceManagementSystem.server.service.AppointmentService;
@@ -148,13 +147,13 @@ public class AppointmentServiceImpl implements AppointmentService {
     }
 
     @Override
-    public PageVo<AppointmentVo> listAll(QueryByPageParams params) {
-        int offset = (params.getPageNum() - 1) * params.getPageSize();
-        return PageUtil.page(params.getPageNum(), params.getPageSize(),
-                () -> appointmentMapper.selectAllByPage(offset, params.getPageSize(),
-                        params.getStatus(), params.getType()).stream()
+    public PageVo<AppointmentVo> listAll(int pageNum, int pageSize, String status, String type) {
+        int offset = (pageNum - 1) * pageSize;
+        return PageUtil.page(pageNum, pageSize,
+                () -> appointmentMapper.selectAllByPage(offset, pageSize,
+                        status, type).stream()
                         .map(this::toAppointmentVo).collect(Collectors.toList()),
-                () -> appointmentMapper.countAll(params.getStatus(), params.getType()));
+                () -> appointmentMapper.countAll(status, type));
     }
 
     @Override

+ 6 - 9
src/main/java/space/anyi/petServiceManagementSystem/server/service/impl/UserServiceImpl.java

@@ -6,7 +6,6 @@ import org.springframework.transaction.annotation.Transactional;
 import space.anyi.petServiceManagementSystem.server.common.BusinessException;
 import space.anyi.petServiceManagementSystem.server.common.PageVo;
 import space.anyi.petServiceManagementSystem.server.config.PasswordConfig;
-import space.anyi.petServiceManagementSystem.server.dto.room.QueryByPageParams;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserAvatarDto;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserPasswordDto;
 import space.anyi.petServiceManagementSystem.server.dto.user.UpdateUserStatusDto;
@@ -49,15 +48,13 @@ public class UserServiceImpl implements UserService {
     private DewormingRecordMapper dewormingRecordMapper;
 
     @Override
-    public PageVo<UserVo> queryByPage(QueryByPageParams params) {
-        int offset = (params.getPageNum() - 1) * params.getPageSize();
-        return PageUtil.page(params.getPageNum(), params.getPageSize(),
-                () -> userMapper.selectByPage(offset, params.getPageSize(),
-                        params.getUsername(), params.getAccount(),
-                        params.getRole(), params.getEnable())
+    public PageVo<UserVo> queryByPage(int pageNum, int pageSize, String username, String account, String role, Integer enable) {
+        int offset = (pageNum - 1) * pageSize;
+        return PageUtil.page(pageNum, pageSize,
+                () -> userMapper.selectByPage(offset, pageSize,
+                        username, account, role, enable)
                         .stream().map(this::toUserVo).collect(Collectors.toList()),
-                () -> userMapper.countByCondition(params.getUsername(), params.getAccount(),
-                        params.getRole(), params.getEnable()));
+                () -> userMapper.countByCondition(username, account, role, enable));
     }
 
     @Override