mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-22 11:52:43 +08:00
部门删除event
This commit is contained in:
parent
e7d335eb88
commit
aa5d3a21d8
@ -2,11 +2,13 @@ package xyz.playedu.api.controller.backend;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import xyz.playedu.api.bus.DepartmentBus;
|
import xyz.playedu.api.bus.DepartmentBus;
|
||||||
import xyz.playedu.api.constant.BPermissionConstant;
|
import xyz.playedu.api.constant.BPermissionConstant;
|
||||||
import xyz.playedu.api.domain.Department;
|
import xyz.playedu.api.domain.Department;
|
||||||
|
import xyz.playedu.api.event.DepartmentDestroyEvent;
|
||||||
import xyz.playedu.api.exception.NotFoundException;
|
import xyz.playedu.api.exception.NotFoundException;
|
||||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||||
import xyz.playedu.api.request.backend.DepartmentRequest;
|
import xyz.playedu.api.request.backend.DepartmentRequest;
|
||||||
@ -31,6 +33,9 @@ public class DepartmentController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DepartmentBus departmentBus;
|
private DepartmentBus departmentBus;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationContext ctx;
|
||||||
|
|
||||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_INDEX)
|
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_INDEX)
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public JsonResponse index() {
|
public JsonResponse index() {
|
||||||
@ -90,6 +95,9 @@ public class DepartmentController {
|
|||||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||||
Department department = departmentService.findOrFail(id);
|
Department department = departmentService.findOrFail(id);
|
||||||
departmentService.deleteById(department.getId());
|
departmentService.deleteById(department.getId());
|
||||||
|
|
||||||
|
ctx.publishEvent(new DepartmentDestroyEvent(this, id, new Date()));
|
||||||
|
|
||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,4 +213,9 @@ public class UserController {
|
|||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/store-batch")
|
||||||
|
public JsonResponse batchStore() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package xyz.playedu.api.event;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/2/23 15:27
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DepartmentDestroyEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
private Integer depId;
|
||||||
|
private Date at;
|
||||||
|
|
||||||
|
public DepartmentDestroyEvent(Object source, Integer depId, Date date) {
|
||||||
|
super(source);
|
||||||
|
this.depId = depId;
|
||||||
|
this.at = date;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package xyz.playedu.api.listener;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import xyz.playedu.api.event.DepartmentDestroyEvent;
|
||||||
|
import xyz.playedu.api.service.UserDepartmentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/2/23 15:28
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class DepartmentDestroyListener {
|
||||||
|
@Autowired
|
||||||
|
private UserDepartmentService userDepartmentService;
|
||||||
|
|
||||||
|
@Order(1)
|
||||||
|
@EventListener
|
||||||
|
public void updateLoginInfo(DepartmentDestroyEvent event) {
|
||||||
|
userDepartmentService.removeByDepId(event.getDepId());
|
||||||
|
}
|
||||||
|
}
|
@ -11,4 +11,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
public interface UserDepartmentService extends IService<UserDepartment> {
|
public interface UserDepartmentService extends IService<UserDepartment> {
|
||||||
|
|
||||||
void removeByUserId(Integer userId);
|
void removeByUserId(Integer userId);
|
||||||
|
void removeByDepId(Integer depId);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,11 @@ public class UserDepartmentServiceImpl extends ServiceImpl<UserDepartmentMapper,
|
|||||||
public void removeByUserId(Integer userId) {
|
public void removeByUserId(Integer userId) {
|
||||||
remove(query().getWrapper().eq("user_id", userId));
|
remove(query().getWrapper().eq("user_id", userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeByDepId(Integer depId) {
|
||||||
|
remove(query().getWrapper().eq("dep_id", depId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user