改!
This commit is contained in:
parent
f51a66073b
commit
5747e255e9
@ -9,6 +9,7 @@ import java.util.stream.Collectors;
|
|||||||
public class UserHS2User {
|
public class UserHS2User {
|
||||||
public static User convert(UserHS userHS) {
|
public static User convert(UserHS userHS) {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
user.setId(userHS.getId());
|
||||||
user.setAccount(userHS.getUsername());
|
user.setAccount(userHS.getUsername());
|
||||||
user.setPassword(userHS.getPassword());
|
user.setPassword(userHS.getPassword());
|
||||||
user.setName(userHS.getNickname());
|
user.setName(userHS.getNickname());
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
package org.cmh.backend.UserManagement.controller;
|
|
||||||
|
|
||||||
import org.cmh.backend.UserManagement.model.User;
|
|
||||||
import org.cmh.backend.UserManagement.service.UserServiceTemp;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.springframework.http.ResponseEntity.ok;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class UserController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserServiceTemp userService;
|
|
||||||
@CrossOrigin(origins = "http://localhost:5173")
|
|
||||||
@PostMapping("/checkLogin")
|
|
||||||
public ResponseEntity<User> login(@RequestBody Map<String,String> credentials) {
|
|
||||||
String account = credentials.get("account");
|
|
||||||
String password = credentials.get("password");
|
|
||||||
|
|
||||||
User user = userService.getUserByAccountAndPassword(account, password);
|
|
||||||
return ok(user);
|
|
||||||
|
|
||||||
}
|
|
||||||
@CrossOrigin(origins = "http://localhost:5173")
|
|
||||||
@PostMapping("/checkRegister")
|
|
||||||
public String register(@RequestBody User user) {
|
|
||||||
|
|
||||||
if(userService.registerUser(user) != null){
|
|
||||||
return "注册成功";
|
|
||||||
}else
|
|
||||||
return "注册错误";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,22 +1,22 @@
|
|||||||
package org.cmh.backend.UserManagement.controller;
|
package org.cmh.backend.UserManagement.controller;
|
||||||
|
|
||||||
import io.jsonwebtoken.JwtParser;
|
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import org.cmh.backend.OrganizationManagement.service.OrganizationService;
|
import org.cmh.backend.OrganizationManagement.service.OrganizationService;
|
||||||
import org.cmh.backend.UserManagement.adpter.User2UserHS;
|
import org.cmh.backend.UserManagement.adpter.User2UserHS;
|
||||||
import org.cmh.backend.UserManagement.adpter.UserHS2User;
|
import org.cmh.backend.UserManagement.adpter.UserHS2User;
|
||||||
import org.cmh.backend.UserManagement.service.UserManagementService;
|
|
||||||
import org.cmh.backend.UserManagement.model.User;
|
import org.cmh.backend.UserManagement.model.User;
|
||||||
|
import org.cmh.backend.UserManagement.service.UserManagementService;
|
||||||
import org.cmh.backend.Utils.JwtUtil;
|
import org.cmh.backend.Utils.JwtUtil;
|
||||||
import org.cmh.backend.Utils.JwtVerify;
|
import org.cmh.backend.Utils.JwtVerify;
|
||||||
import org.cmh.backend.authentication.dto.UserProfileResponse;
|
import org.cmh.backend.authentication.dto.UserProfileResponse;
|
||||||
import org.cmh.backend.authentication.model.UserHS;
|
import org.cmh.backend.authentication.model.UserHS;
|
||||||
|
import org.cmh.backend.authentication.repository.UserRepository;
|
||||||
import org.cmh.backend.authentication.service.UserService;
|
import org.cmh.backend.authentication.service.UserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpEntity;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -28,6 +28,8 @@ public class UserManagementController {
|
|||||||
private OrganizationService organizationService;
|
private OrganizationService organizationService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
@PostMapping("/addUser")
|
@PostMapping("/addUser")
|
||||||
public ResponseEntity<UserProfileResponse> addUser(@RequestBody User user) {
|
public ResponseEntity<UserProfileResponse> addUser(@RequestBody User user) {
|
||||||
@ -42,10 +44,10 @@ public class UserManagementController {
|
|||||||
newuser.getRole(),
|
newuser.getRole(),
|
||||||
newuser.getCreatedAt()
|
newuser.getCreatedAt()
|
||||||
);
|
);
|
||||||
if(organizationService.getByName(newuser.getDepartment()) != null){
|
if (organizationService.getByName(newuser.getDepartment()) != null) {
|
||||||
userService.addUser(newuser);
|
userService.addUser(newuser);
|
||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
}else{
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,45 +58,50 @@ public class UserManagementController {
|
|||||||
public List<User> getAll(@RequestParam String token) {
|
public List<User> getAll(@RequestParam String token) {
|
||||||
String username = JwtUtil.extractUsername(token);
|
String username = JwtUtil.extractUsername(token);
|
||||||
UserHS userHS = userService.getUserByUsername(username);
|
UserHS userHS = userService.getUserByUsername(username);
|
||||||
List<UserHS> userHSList = userService.getAllUsers();
|
if (userHS.getSuperAdmin()) {
|
||||||
//这里分权限进行不同请求
|
return UserHS2User.convertList(userService.getAllUsers());
|
||||||
//超级管理员
|
} else {
|
||||||
if(userHS.getSuperAdmin()){
|
return UserHS2User.convertList(userService.getUsersByTenant(userHS.getTenant()));
|
||||||
return UserHS2User.convertList(userHSList);
|
|
||||||
}else{
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public ResponseEntity<UserProfileResponse> update(@RequestBody User user) {
|
public ResponseEntity<UserProfileResponse> update(@RequestBody User user) {
|
||||||
UserHS newuser = User2UserHS.convert(user);
|
UserHS reqUser = User2UserHS.convert(user);
|
||||||
UserProfileResponse response = new UserProfileResponse(
|
UserHS tarUser = userService.getUserByUsername(reqUser.getUsername());
|
||||||
newuser.getUsername(),
|
if (tarUser != null) {
|
||||||
newuser.getNickname(),
|
tarUser.setNickname(reqUser.getNickname());
|
||||||
newuser.getGender(),
|
tarUser.setGender(reqUser.getGender());
|
||||||
newuser.getPhoneNumber(),
|
tarUser.setPhoneNumber(reqUser.getPhoneNumber());
|
||||||
newuser.getEmail(),
|
tarUser.setEmail(reqUser.getEmail());
|
||||||
newuser.getDepartment(),
|
tarUser.setRole(reqUser.getRole());
|
||||||
newuser.getRole(),
|
UserProfileResponse response = new UserProfileResponse(
|
||||||
newuser.getCreatedAt()
|
reqUser.getUsername(),
|
||||||
);
|
reqUser.getNickname(),
|
||||||
if(organizationService.getByName(newuser.getDepartment()) != null){
|
reqUser.getGender(),
|
||||||
userService.addUser(newuser);
|
reqUser.getPhoneNumber(),
|
||||||
|
reqUser.getEmail(),
|
||||||
|
reqUser.getDepartment(),
|
||||||
|
reqUser.getRole(),
|
||||||
|
reqUser.getCreatedAt()
|
||||||
|
);
|
||||||
|
if (organizationService.getByName(reqUser.getDepartment()) != null) {
|
||||||
|
tarUser.setDepartment(reqUser.getDepartment());
|
||||||
|
}
|
||||||
|
userRepository.save(tarUser);
|
||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
}else{
|
} else {
|
||||||
return null;
|
return new ResponseEntity<>(null, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
@Transactional
|
@Transactional
|
||||||
//不确定这里返回值应该是什么
|
|
||||||
public void delete(@RequestBody User user) {
|
public void delete(@RequestBody User user) {
|
||||||
UserHS userHS = userService.getUserByUsername(user.getName());
|
UserHS userHS = userService.getUserByUsername(user.getName());
|
||||||
if(userHS != null){
|
if (userHS != null) {
|
||||||
//根据用户名删除用户
|
//根据用户名删除用户
|
||||||
userService.deleteUser(userHS.getUsername());
|
userService.deleteUser(userHS.getUsername());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user