xiatian 2 years ago
parent
commit
2a2c280a9b

+ 1 - 1
db/init.sql

@@ -38,7 +38,7 @@ CREATE TABLE `mps_exam` (
   `updater_id` bigint DEFAULT NULL,
   `exam_status` varchar(255) COLLATE utf8_bin NOT NULL,
   `name` varchar(255) COLLATE utf8_bin NOT NULL,
-  `code` varchar(255) COLLATE utf8_bin NOT NULL,
+  `code` varchar(255) COLLATE utf8_bin DEFAULT NULL,
   `school_id` bigint NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `IDX_EXAM_01` (`school_id`,`name`),

+ 4 - 4
src/main/java/cn/com/qmth/mps/controller/UserController.java

@@ -75,13 +75,13 @@ public class UserController extends BaseController {
 		userService.toggle(ids,enable);
 	}
 	
-	@ApiOperation(value = "重置用户密码")
+	@ApiOperation(value = "重置指定用户密码")
 	@PostMapping("reset-passwd")
-	public void resetPass(@RequestParam Long schoolId,@RequestParam List<Long> ids) {
-		userService.resetPass(schoolId,ids,getAccessUser());
+	public void resetPass(@RequestParam Long userId,@RequestParam String passwd) {
+		userService.resetPass(userId,passwd,getAccessUser());
 	}
 	
-	@ApiOperation(value = "修改用户密码")
+	@ApiOperation(value = "修改当前用户密码")
 	@PostMapping("password")
 	public void updatePass(@RequestParam String password) {
 		userService.updatePass(password,getAccessUser());

+ 1 - 1
src/main/java/cn/com/qmth/mps/service/UserService.java

@@ -29,7 +29,7 @@ public interface UserService  extends IService<UserEntity> {
 
 	void updatePass(String password, User accessUser);
 
-	void resetPass(Long schoolId,List<Long> ids, User accessUser);
+	void resetPass(Long userId, String passwd, User accessUser);
 
 
 }

+ 10 - 4
src/main/java/cn/com/qmth/mps/service/impl/UserServiceImpl.java

@@ -287,13 +287,19 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 
 	@Transactional
 	@Override
-	public void resetPass(Long schoolId, List<Long> ids, User accessUser) {
-		String pw = ByteUtil.toHexAscii(SHA256.encode(defPassWd));
+	public void resetPass(Long userId, String passwd, User user) {
+		UserEntity ue = this.getById(userId);
+		if (ue == null) {
+			throw new StatusException("未找到用户信息");
+		}
+		if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(ue.getSchoolId())) {
+			throw new StatusException("非法操作");
+		}
+		String pw = ByteUtil.toHexAscii(SHA256.encode(passwd));
 		UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
 		LambdaUpdateWrapper<UserEntity> lw = wrapper.lambda();
 		lw.set(UserEntity::getPassword, pw);
-		lw.in(UserEntity::getId, ids);
-		lw.eq(UserEntity::getSchoolId, schoolId);
+		lw.eq(UserEntity::getId, userId);
 		this.update(wrapper);
 	}
 }