From a16c907d151f6a0577df72563260008dd2ed24c5 Mon Sep 17 00:00:00 2001 From: zhangyeguang Date: Fri, 13 Dec 2024 10:20:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BC=98=E5=8C=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jiagutech/controller/UserController.java | 11 +++++--- .../com/jiagutech/dto/response/TaskItem.java | 6 +++++ .../java/com/jiagutech/entity/UserEntity.java | 2 +- .../jiagutech/record/RecordTaskHandler.java | 3 +++ .../jiagutech/record/RecordTaskManager.java | 1 + .../com/jiagutech/service/UserService.java | 4 ++- .../jiagutech/service/UserServiceImpl.java | 26 ++++++++++++++----- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/jiagutech/controller/UserController.java b/src/main/java/com/jiagutech/controller/UserController.java index 5199cc4..278b0fe 100644 --- a/src/main/java/com/jiagutech/controller/UserController.java +++ b/src/main/java/com/jiagutech/controller/UserController.java @@ -2,10 +2,13 @@ package com.jiagutech.controller; import cn.dev33.satoken.stp.StpUtil; import com.jiagutech.dto.common.LoginUser; +import com.jiagutech.dto.common.PageRequest; +import com.jiagutech.dto.common.PageResult; import com.jiagutech.dto.common.R; import com.jiagutech.dto.request.LoginRequest; import com.jiagutech.dto.request.UserRequest; import com.jiagutech.dto.response.LoginResponse; +import com.jiagutech.dto.response.RecordItem; import com.jiagutech.dto.response.UserItem; import com.jiagutech.entity.UserEntity; import com.jiagutech.service.UserService; @@ -71,10 +74,10 @@ public class UserController { return R.ok(LoginUtil.getLoginUser()); } - @ApiOperation(value = "待审核用户列表") - @GetMapping(value = "/userList") - public R> approvalUserList() { - return R.ok(userService.approvalUserList()); + @ApiOperation(value = "用户列表") + @PostMapping(value = "/userList", consumes = "application/json") + public R> approvalUserList(@RequestBody PageRequest pageRequest) { + return R.ok(userService.approvalUserList(pageRequest)); } @ApiOperation(value = "修改用户密码/信息") diff --git a/src/main/java/com/jiagutech/dto/response/TaskItem.java b/src/main/java/com/jiagutech/dto/response/TaskItem.java index 65a50f1..bd1ad52 100644 --- a/src/main/java/com/jiagutech/dto/response/TaskItem.java +++ b/src/main/java/com/jiagutech/dto/response/TaskItem.java @@ -1,7 +1,10 @@ package com.jiagutech.dto.response; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; +import java.time.LocalDateTime; + @Data public class TaskItem { @@ -10,4 +13,7 @@ public class TaskItem { private String taskName; private Float progress; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; } diff --git a/src/main/java/com/jiagutech/entity/UserEntity.java b/src/main/java/com/jiagutech/entity/UserEntity.java index 4e2bad4..35b7713 100644 --- a/src/main/java/com/jiagutech/entity/UserEntity.java +++ b/src/main/java/com/jiagutech/entity/UserEntity.java @@ -12,7 +12,7 @@ import java.time.LocalDateTime; @Accessors(chain = true) public class UserEntity { @TableId - private long id; + private Long id; private String phone; diff --git a/src/main/java/com/jiagutech/record/RecordTaskHandler.java b/src/main/java/com/jiagutech/record/RecordTaskHandler.java index f04ff7a..b11b152 100644 --- a/src/main/java/com/jiagutech/record/RecordTaskHandler.java +++ b/src/main/java/com/jiagutech/record/RecordTaskHandler.java @@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.net.URL; +import java.time.LocalDateTime; import java.util.concurrent.ThreadPoolExecutor; @Data @@ -80,6 +81,7 @@ public class RecordTaskHandler { .setProgress(5f) .setTaskName(request.getTaskName()) .setTaskId(taskId) + .setCreateTime(LocalDateTime.now()) .setLoginUser(LoginUtil.getLoginUser()); processTask(); } @@ -94,6 +96,7 @@ public class RecordTaskHandler { private Float conf; private Float progress; private String taskName; + private LocalDateTime createTime; private LoginUser loginUser; } diff --git a/src/main/java/com/jiagutech/record/RecordTaskManager.java b/src/main/java/com/jiagutech/record/RecordTaskManager.java index 54cc080..d2423d5 100644 --- a/src/main/java/com/jiagutech/record/RecordTaskManager.java +++ b/src/main/java/com/jiagutech/record/RecordTaskManager.java @@ -32,6 +32,7 @@ public class RecordTaskManager { taskItem.setTaskId(recordTask.getTaskId()); taskItem.setProgress(recordTask.getProgress()); taskItem.setTaskName(recordTask.getTaskName()); + taskItem.setCreateTime(recordTask.getCreateTime()); taskItems.add(taskItem); } } diff --git a/src/main/java/com/jiagutech/service/UserService.java b/src/main/java/com/jiagutech/service/UserService.java index 3bb42f2..047040b 100644 --- a/src/main/java/com/jiagutech/service/UserService.java +++ b/src/main/java/com/jiagutech/service/UserService.java @@ -1,5 +1,7 @@ package com.jiagutech.service; +import com.jiagutech.dto.common.PageRequest; +import com.jiagutech.dto.common.PageResult; import com.jiagutech.dto.request.LoginRequest; import com.jiagutech.dto.response.LoginResponse; import com.jiagutech.dto.response.UserItem; @@ -15,7 +17,7 @@ public interface UserService { void approval(Long userId); - List approvalUserList(); + PageResult approvalUserList( PageRequest pageRequest); Boolean update(UserEntity userEntity); } diff --git a/src/main/java/com/jiagutech/service/UserServiceImpl.java b/src/main/java/com/jiagutech/service/UserServiceImpl.java index f7e671d..55442eb 100644 --- a/src/main/java/com/jiagutech/service/UserServiceImpl.java +++ b/src/main/java/com/jiagutech/service/UserServiceImpl.java @@ -5,14 +5,18 @@ import cn.dev33.satoken.stp.StpUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.jiagutech.common.UserConstants; import com.jiagutech.common.exception.BizCode; import com.jiagutech.common.exception.BusinessException; import com.jiagutech.dto.common.LoginUser; +import com.jiagutech.dto.common.PageRequest; +import com.jiagutech.dto.common.PageResult; import com.jiagutech.dto.mapping.UserMapping; import com.jiagutech.dto.request.LoginRequest; import com.jiagutech.dto.request.UserRequest; import com.jiagutech.dto.response.LoginResponse; +import com.jiagutech.dto.response.RecordItem; import com.jiagutech.dto.response.UserItem; import com.jiagutech.entity.UserEntity; import com.jiagutech.mapper.UserMapper; @@ -62,8 +66,14 @@ public class UserServiceImpl implements UserService { .setRealName(user.getRealName()) .setUnitName(user.getUnitName()) .setPhone(user.getPhone()) - .setRole(0) + .setRole(1) .setPassword(BCrypt.hashpw(user.getPassword())); + QueryWrapper wrapper = Wrappers.query(); + wrapper.eq("phone", user.getPhone()); + UserEntity hasExists = userMapper.selectOne(wrapper); + if (hasExists != null) { + throw new BusinessException(BizCode.USER_PHONE_EXIST); + } userMapper.insert(userEntity); emailUtil.sendEmail(null, user.getPhone(), user.getUnitName(), user.getRealName()); @@ -77,11 +87,15 @@ public class UserServiceImpl implements UserService { } @Override - public List approvalUserList() { + public PageResult approvalUserList(PageRequest pageRequest) { QueryWrapper wrapper = Wrappers.query(); - wrapper.eq("status", 2); - List userEntities = userMapper.selectList(wrapper); - return UserMapping.INSTANCE.convertToUserItems(userEntities); + wrapper.orderByDesc("create_time"); + wrapper.eq("role", 1); + Page page = new Page<>(pageRequest.getPageNum(), pageRequest.getPageSize()); + + Page result = userMapper.selectPage(page, wrapper); + List userItems = UserMapping.INSTANCE.convertToUserItems(result.getRecords()); + return PageResult.of((int) result.getTotal(), (int) result.getSize(), (int) result.getCurrent(), userItems); } @Override @@ -92,7 +106,7 @@ public class UserServiceImpl implements UserService { int res = userMapper.updateById(userEntity); if (res > 0) { assert userEntity != null; - StpUtil.logout(); + StpUtil.logout(userEntity.getId()); } return res > 0; }