Browse Source

更新优化接口

master
zhangyeguang 1 week ago
parent
commit
a16c907d15
  1. 11
      src/main/java/com/jiagutech/controller/UserController.java
  2. 6
      src/main/java/com/jiagutech/dto/response/TaskItem.java
  3. 2
      src/main/java/com/jiagutech/entity/UserEntity.java
  4. 3
      src/main/java/com/jiagutech/record/RecordTaskHandler.java
  5. 1
      src/main/java/com/jiagutech/record/RecordTaskManager.java
  6. 4
      src/main/java/com/jiagutech/service/UserService.java
  7. 26
      src/main/java/com/jiagutech/service/UserServiceImpl.java

11
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<List<UserItem>> approvalUserList() {
return R.ok(userService.approvalUserList());
@ApiOperation(value = "用户列表")
@PostMapping(value = "/userList", consumes = "application/json")
public R<PageResult<UserItem>> approvalUserList(@RequestBody PageRequest pageRequest) {
return R.ok(userService.approvalUserList(pageRequest));
}
@ApiOperation(value = "修改用户密码/信息")

6
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;
}

2
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;

3
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;
}

1
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);
}
}

4
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<UserItem> approvalUserList();
PageResult<UserItem> approvalUserList( PageRequest pageRequest);
Boolean update(UserEntity userEntity);
}

26
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<UserEntity> 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<UserItem> approvalUserList() {
public PageResult<UserItem> approvalUserList(PageRequest pageRequest) {
QueryWrapper<UserEntity> wrapper = Wrappers.query();
wrapper.eq("status", 2);
List<UserEntity> userEntities = userMapper.selectList(wrapper);
return UserMapping.INSTANCE.convertToUserItems(userEntities);
wrapper.orderByDesc("create_time");
wrapper.eq("role", 1);
Page<UserEntity> page = new Page<>(pageRequest.getPageNum(), pageRequest.getPageSize());
Page<UserEntity> result = userMapper.selectPage(page, wrapper);
List<UserItem> 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;
}

Loading…
Cancel
Save