mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-23 09:39:33 +08:00
user_department优化
This commit is contained in:
parent
e34fb3bad0
commit
bd8f6b1af3
@ -15,7 +15,7 @@ import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.UserImportRequest;
|
||||
import xyz.playedu.api.request.backend.UserRequest;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
import xyz.playedu.api.service.UserDepartmentService;
|
||||
import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
@ -189,7 +189,7 @@ public class UserController {
|
||||
userService.updateById(newUser);
|
||||
|
||||
//先删除关联关系
|
||||
userDepartmentService.removeByUserId(user.getId());
|
||||
userService.removeRelateDepartmentsByUserId(user.getId());
|
||||
|
||||
if (request.getDepIds() != null && request.getDepIds().length > 0) { //重新建立关系
|
||||
List<UserDepartment> userDepartments = new ArrayList<>();
|
||||
|
@ -1,26 +1,22 @@
|
||||
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;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/23 15:28
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DepartmentDestroyListener {
|
||||
@Autowired
|
||||
private UserDepartmentService userDepartmentService;
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Order(1)
|
||||
@EventListener
|
||||
public void updateLoginInfo(DepartmentDestroyEvent event) {
|
||||
userDepartmentService.removeByDepId(event.getDepId());
|
||||
departmentService.remoteRelateUsersByDepId(event.getDepId());
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.playedu.api.event.UserDestroyEvent;
|
||||
import xyz.playedu.api.service.UserDepartmentService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
@ -17,12 +17,12 @@ import xyz.playedu.api.service.UserDepartmentService;
|
||||
public class UserDestroyListener {
|
||||
|
||||
@Autowired
|
||||
private UserDepartmentService userDepartmentService;
|
||||
private UserService userService;
|
||||
|
||||
@Order(1)
|
||||
@EventListener
|
||||
public void updateLoginInfo(UserDestroyEvent event) {
|
||||
userDepartmentService.removeByUserId(event.getUserId());
|
||||
userService.removeRelateDepartmentsByUserId(event.getUserId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,4 +31,6 @@ public interface DepartmentService extends IService<Department> {
|
||||
|
||||
void create(String name, Integer parentId, Integer sort) throws NotFoundException;
|
||||
|
||||
void remoteRelateUsersByDepId(Integer depId);
|
||||
|
||||
}
|
||||
|
@ -18,4 +18,6 @@ public interface UserService extends IService<User> {
|
||||
PaginationResult<User> paginate(int page, int size, UserPaginateFilter filter);
|
||||
|
||||
List<String> existsEmailsByEmails(List<String> emails);
|
||||
|
||||
void removeRelateDepartmentsByUserId(Integer userId);
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.domain.UserDepartment;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
import xyz.playedu.api.mapper.DepartmentMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -22,6 +26,9 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
|
||||
|
||||
@Autowired
|
||||
private UserDepartmentService userDepartmentService;
|
||||
|
||||
@Override
|
||||
public List<Department> listByParentId(Integer id) {
|
||||
return list(query().getWrapper().eq("parent_id", id).orderByAsc("sort"));
|
||||
@ -163,6 +170,12 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
||||
|
||||
save(department);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remoteRelateUsersByDepId(Integer depId) {
|
||||
QueryWrapper<UserDepartment> wrapper = userDepartmentService.query().getWrapper().eq("dep_id", depId);
|
||||
userDepartmentService.remove(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.ibatis.jdbc.SQL;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.domain.UserDepartment;
|
||||
import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.mapper.UserMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -23,6 +24,10 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserDepartmentService userDepartmentService;
|
||||
|
||||
@Override
|
||||
public boolean emailIsExists(String email) {
|
||||
User user = getOne(query().getWrapper().eq("email", email));
|
||||
@ -85,6 +90,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
}
|
||||
return existsEmails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRelateDepartmentsByUserId(Integer userId) {
|
||||
QueryWrapper<UserDepartment> wrapper = userDepartmentService.query().getWrapper().eq("user_id", userId);
|
||||
userDepartmentService.remove(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
package xyz.playedu.api.service.impl.internal;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import xyz.playedu.api.domain.UserDepartment;
|
||||
import xyz.playedu.api.service.UserDepartmentService;
|
||||
import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||
import xyz.playedu.api.mapper.UserDepartmentMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -14,15 +14,6 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class UserDepartmentServiceImpl extends ServiceImpl<UserDepartmentMapper, UserDepartment>
|
||||
implements UserDepartmentService {
|
||||
@Override
|
||||
public void removeByUserId(Integer userId) {
|
||||
remove(query().getWrapper().eq("user_id", userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByDepId(Integer depId) {
|
||||
remove(query().getWrapper().eq("dep_id", depId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.playedu.api.service;
|
||||
package xyz.playedu.api.service.internal;
|
||||
|
||||
import xyz.playedu.api.domain.UserDepartment;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@ -9,7 +9,4 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @createDate 2023-02-23 15:08:38
|
||||
*/
|
||||
public interface UserDepartmentService extends IService<UserDepartment> {
|
||||
|
||||
void removeByUserId(Integer userId);
|
||||
void removeByDepId(Integer depId);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user