|
@@ -3,6 +3,7 @@ package com.idiot.operationbackend.controller;
|
|
|
import com.baomidou.kaptcha.Kaptcha;
|
|
|
import com.idiot.operationbackend.entity.AuthUser;
|
|
|
import com.idiot.operationbackend.service.facade.AuthUserService;
|
|
|
+import com.idiot.operationbackend.support.Constants;
|
|
|
import com.idiot.operationbackend.support.CustomException;
|
|
|
import com.idiot.operationbackend.support.JsonResult;
|
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
@@ -13,9 +14,12 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
@@ -56,9 +60,75 @@ public class AuthController {
|
|
|
if (Objects.isNull(authUser)) {
|
|
|
throw new CustomException(500,"账号或者密码错误!请检查大小写");
|
|
|
}
|
|
|
+ if (!authUser.getState()) {
|
|
|
+ throw new CustomException(500,"您的账号已经被冻结!请联系父属账号");
|
|
|
+ }
|
|
|
authUser.setPassword("");
|
|
|
String token = JwtTokenUtil.sign(authUser.getNikeName(),authUser.getId());
|
|
|
return ResponseEntity.ok().header("AUTH_TOKEN",token)
|
|
|
.body(JsonResult.success(authUser));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/subManage")
|
|
|
+ @ApiOperation(value = "子账号管理")
|
|
|
+ public ResponseEntity<JsonResult<List<AuthUser>>> subUserManage(@RequestHeader String token) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}子账号管理",userId);
|
|
|
+ List<AuthUser> authUsers = userService.querySubAuthUser(userId);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(authUsers));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/subManage/{userId}")
|
|
|
+ @ApiOperation(value = "子账号冻结/解冻")
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> manageSubUser(@PathVariable String userId,
|
|
|
+ @RequestHeader String token) {
|
|
|
+ String parentUserId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}操作子账号:{}",parentUserId,userId);
|
|
|
+ AuthUser authUser = userService.queryAuthUserByParentIdAndId(parentUserId,userId);
|
|
|
+ if (Objects.isNull(authUser)) {
|
|
|
+ throw new CustomException(500,"您的账号无权操作其他人的账号,只能管理自己的子账号");
|
|
|
+ }
|
|
|
+ boolean before = authUser.getState();
|
|
|
+ authUser.setState(!before);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(before));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/subPre")
|
|
|
+ @ApiOperation(value = "获取子账号名称前缀")
|
|
|
+ public ResponseEntity<JsonResult<String>> getSubPre(@RequestHeader String token) {
|
|
|
+ String parentUserId = JwtTokenUtil.getUserId(token);
|
|
|
+
|
|
|
+ return ResponseEntity.ok(JsonResult.success(parentUserId+"@"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/subCreate")
|
|
|
+ @ApiOperation(value = "子账号创建")
|
|
|
+ public ResponseEntity<JsonResult<Boolean>> createSubUser(@RequestBody AuthUser authUser,
|
|
|
+ @RequestHeader String token) {
|
|
|
+ String parentUserId = JwtTokenUtil.getUserId(token);
|
|
|
+ logger.info("用户:{}创建 子账号",parentUserId);
|
|
|
+ AuthUser parentUser = userService.getById(parentUserId);
|
|
|
+ if (Objects.isNull(parentUser) || !StringUtils.isEmpty(parentUser.getParentUerId())) {
|
|
|
+ throw new CustomException(500,"您的账号无权是子账号无权创建子账号");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(authUser) || StringUtils.isEmpty(authUser.getUserCode())
|
|
|
+ || StringUtils.isEmpty(authUser.getPassword())) {
|
|
|
+ throw new CustomException(500,"您创建账号信息录入不全,请您补全信息!");
|
|
|
+ }
|
|
|
+ if (! authUser.getUserCode().startsWith(parentUserId)) {
|
|
|
+ throw new CustomException(500,"您创建账号信息非法,账号开始部分不容修改!!");
|
|
|
+ }
|
|
|
+ authUser.setState(true);
|
|
|
+ authUser.setId(null);
|
|
|
+ authUser.setParentUerId(parentUserId);
|
|
|
+ authUser.setCreateTime(Constants.DATE_TIME_FORMATTER.format(LocalDateTime.now()));
|
|
|
+ boolean ifSave = userService.saveUserAndDigPassword(authUser);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(ifSave));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|