fix: 修复用户更新

This commit is contained in:
Shu Guang 2025-05-18 20:22:36 +08:00
parent de6798dd25
commit cfbea9c2aa
4 changed files with 4830 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package com.example.system.controller; package com.example.system.controller;
import com.example.system.mapper.UserMapper;
import com.example.system.model.Result; import com.example.system.model.Result;
import com.example.system.model.UserTable; import com.example.system.model.UserTable;
import com.example.system.service.UserService; import com.example.system.service.UserService;
@ -30,10 +31,12 @@ import java.util.Map;
public class UserController { public class UserController {
private final UserService userService; private final UserService userService;
private final PasswordEncoder passwordEncoder; // 注入 PasswordEncoder private final PasswordEncoder passwordEncoder; // 注入 PasswordEncoder
private final UserMapper userMapper;
public UserController(UserService userService, PasswordEncoder passwordEncoder) { public UserController(UserService userService, PasswordEncoder passwordEncoder, UserMapper userMapper) {
this.userService = userService; this.userService = userService;
this.passwordEncoder = passwordEncoder; // 注入 PasswordEncoder this.passwordEncoder = passwordEncoder; // 注入 PasswordEncoder
this.userMapper = userMapper;
} }
/** /**
@ -149,11 +152,13 @@ public class UserController {
@PutMapping("/updateOther") @PutMapping("/updateOther")
public Object updateOther(UserTable user, HttpServletRequest request) { public Object updateOther(UserTable user, HttpServletRequest request) {
String toKen =request.getHeader("Authorization"); String toKen =request.getHeader("Authorization");
System.out.println("Token: " + user);
Claims claims = JWTUtil.checkToken(toKen); Claims claims = JWTUtil.checkToken(toKen);
Integer privileges = (Integer) claims.get("userPrivileges"); Integer privileges = (Integer) claims.get("userPrivileges");
if (privileges != 0 && !userService.updateOther(user)) { if (privileges != 0 && !userService.updateOther(user)) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "用户信息更新失败"); throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "用户信息更新失败");
} }
userMapper.updateOther(user);
return Result.success("用户信息更新成功"); return Result.success("用户信息更新成功");
} }
/** /**

View File

@ -42,14 +42,15 @@ public interface UserMapper {
@Select("select user_name from user_table where user_id=#{studentId}") @Select("select user_name from user_table where user_id=#{studentId}")
String getNameById(Integer studentId); String getNameById(Integer studentId);
@Update("update user_table SET " + @Update("UPDATE user_table SET " +
"user_name=#{userName}, s_t_id=#{sTId}, user_password=#{userPassword}, " + "user_name=#{userName}, s_t_id=#{sTId}, user_password=#{userPassword}, " +
"user_privileges=#{userPrivileges}, college_id=#{collegeId}, major_table_id=#{majorTableId}," + "user_privileges=#{userPrivileges}, college_id=#{collegeId}, major_table_id=#{majorTableId}, " +
"teacher_title=#{teacherTitle},birthdate=#{birthdate},gender=#{gender}," + "teacher_title=#{teacherTitle}, birthdate=#{birthdate}, gender=#{gender}, " +
"phone=#{phone}, email=#{email}, user_password=#{userPassword}" + "phone=#{phone}, email=#{email} " +
"WHERE user_id=#{userId}") "WHERE user_id=#{userId}")
int updateOther(UserTable user); int updateOther(UserTable user);
//获取用户总数量 //获取用户总数量
@Select("SELECT COUNT(user_id) FROM user_table;") @Select("SELECT COUNT(user_id) FROM user_table;")
Object getCount(); Object getCount();

View File

@ -23,7 +23,13 @@ public class UserServiceImpl implements UserService {
@Transactional @Transactional
@Override @Override
public boolean updateOther(UserTable user) { public boolean updateOther(UserTable user) {
log.info("[updateOther] 收到UserTable: {}", user);
int tmp = userMapper.updateOther(user); int tmp = userMapper.updateOther(user);
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
log.info("[updateOther] update SQL影响行数 tmp={}", tmp); // 这样绝不会错过
if (tmp == 1) { if (tmp == 1) {
return true; return true;
} }

File diff suppressed because it is too large Load Diff