mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-16 16:14:19 +08:00
部门代码优化
This commit is contained in:
@@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.bus.DepartmentBus;
|
||||
import xyz.playedu.api.PlayEduBackendThreadLocal;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.event.DepartmentDestroyEvent;
|
||||
@@ -30,9 +30,6 @@ public class DepartmentController {
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
private DepartmentBus departmentBus;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@@ -56,22 +53,8 @@ public class DepartmentController {
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_STORE)
|
||||
@PostMapping("/create")
|
||||
public JsonResponse store(@RequestBody @Validated DepartmentRequest request) throws NotFoundException {
|
||||
String parentChain = "";
|
||||
if (request.getParentId() != 0) {
|
||||
parentChain = departmentBus.compParentChain(request.getParentId());
|
||||
}
|
||||
|
||||
Department department = new Department();
|
||||
department.setName(request.getName());
|
||||
department.setParentId(request.getParentId());
|
||||
department.setParentChain(parentChain);
|
||||
department.setSort(request.getSort());
|
||||
department.setCreatedAt(new Date());
|
||||
department.setUpdatedAt(new Date());
|
||||
|
||||
departmentService.save(department);
|
||||
|
||||
public JsonResponse store(@RequestBody @Validated DepartmentRequest req) throws NotFoundException {
|
||||
departmentService.create(req.getName(), req.getParentId(), req.getSort());
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@@ -84,9 +67,9 @@ public class DepartmentController {
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
public JsonResponse update(@PathVariable Integer id, @RequestBody DepartmentRequest request) throws NotFoundException {
|
||||
public JsonResponse update(@PathVariable Integer id, @RequestBody DepartmentRequest req) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
departmentService.update(department, request.getName(), request.getParentId(), request.getSort());
|
||||
departmentService.update(department, req.getName(), req.getParentId(), req.getSort());
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@@ -95,9 +78,7 @@ public class DepartmentController {
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
departmentService.deleteById(department.getId());
|
||||
|
||||
ctx.publishEvent(new DepartmentDestroyEvent(this, id, new Date()));
|
||||
|
||||
ctx.publishEvent(new DepartmentDestroyEvent(this, PlayEduBackendThreadLocal.getAdminUserID(), department.getId(), new Date()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -25,7 +24,6 @@ import xyz.playedu.api.util.RequestUtil;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/backend/v1/auth")
|
||||
public class LoginController {
|
||||
@@ -44,14 +42,14 @@ public class LoginController {
|
||||
public JsonResponse login(@RequestBody @Validated LoginRequest loginRequest) {
|
||||
AdminUser adminUser = adminUserService.findByEmail(loginRequest.email);
|
||||
if (adminUser == null) {
|
||||
return JsonResponse.error("邮箱不存在");
|
||||
return JsonResponse.error("邮箱或密码错误");
|
||||
}
|
||||
String password = HelperUtil.MD5(loginRequest.getPassword() + adminUser.getSalt()).toLowerCase();
|
||||
if (!adminUser.getPassword().equals(password)) {
|
||||
return JsonResponse.error("密码错误");
|
||||
return JsonResponse.error("邮箱或密码错误");
|
||||
}
|
||||
if (adminUser.getIsBanLogin() == 1) {
|
||||
return JsonResponse.error("当前用户禁止登录");
|
||||
return JsonResponse.error("当前用户已禁止登录");
|
||||
}
|
||||
|
||||
String url = RequestUtil.url();
|
||||
|
||||
Reference in New Issue
Block a user