mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-21 19:32:41 +08:00
增加部门删选核查api
This commit is contained in:
parent
e16212e5ad
commit
a3bb8be72e
@ -8,11 +8,14 @@ import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.PlayEduBContext;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.event.DepartmentDestroyEvent;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.DepartmentRequest;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.util.*;
|
||||
@ -30,6 +33,12 @@ public class DepartmentController {
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@ -82,6 +91,34 @@ public class DepartmentController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_CUD)
|
||||
@GetMapping("/{id}/destroy")
|
||||
public JsonResponse preDestroy(@PathVariable Integer id) {
|
||||
List<Integer> courseIds = departmentService.getCourseIdsByDepId(id);
|
||||
List<Integer> userIds = departmentService.getUserIdsByDepId(id);
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("courses", new ArrayList<>());
|
||||
data.put("users", new ArrayList<>());
|
||||
|
||||
if (courseIds != null && courseIds.size() > 0) {
|
||||
data.put("courses", courseService.chunks(courseIds, new ArrayList<>() {{
|
||||
add("id");
|
||||
add("title");
|
||||
}}));
|
||||
}
|
||||
if (userIds != null && userIds.size() > 0) {
|
||||
data.put("users", userService.chunks(userIds, new ArrayList<>() {{
|
||||
add("id");
|
||||
add("nickname");
|
||||
add("name");
|
||||
add("avatar");
|
||||
}}));
|
||||
}
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_CUD)
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
|
@ -38,4 +38,6 @@ public interface CourseService extends IService<Course> {
|
||||
void updateClassHour(Integer courseId, Integer classHour);
|
||||
|
||||
void removeCategoryIdRelate(Integer categoryId);
|
||||
|
||||
List<Course> chunks(List<Integer> ids, List<String> fields);
|
||||
}
|
||||
|
@ -33,4 +33,8 @@ public interface DepartmentService extends IService<Department> {
|
||||
|
||||
void remoteRelateUsersByDepId(Integer depId);
|
||||
|
||||
List<Integer> getUserIdsByDepId(Integer depId);
|
||||
|
||||
List<Integer> getCourseIdsByDepId(Integer depId);
|
||||
|
||||
}
|
||||
|
@ -36,4 +36,6 @@ public interface UserService extends IService<User> {
|
||||
List<Integer> getDepIdsByUserId(Integer userId);
|
||||
|
||||
void passwordChange(User user, String oldPassword, String newPassword) throws ServiceException;
|
||||
|
||||
List<User> chunks(List<Integer> ids, List<String> fields);
|
||||
}
|
||||
|
@ -193,6 +193,11 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
||||
public void removeCategoryIdRelate(Integer categoryId) {
|
||||
courseCategoryService.removeByCategoryId(categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Course> chunks(List<Integer> ids, List<String> fields) {
|
||||
return list(query().getWrapper().in("id", ids).select(fields));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,9 +5,11 @@ 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.CourseDepartment;
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.domain.UserDepartment;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.service.CourseDepartmentService;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
import xyz.playedu.api.mapper.DepartmentMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -29,6 +31,9 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
||||
@Autowired
|
||||
private UserDepartmentService userDepartmentService;
|
||||
|
||||
@Autowired
|
||||
private CourseDepartmentService courseDepartmentService;
|
||||
|
||||
@Override
|
||||
public List<Department> listByParentId(Integer id) {
|
||||
return list(query().getWrapper().eq("parent_id", id).orderByAsc("sort"));
|
||||
@ -176,6 +181,16 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
||||
QueryWrapper<UserDepartment> wrapper = userDepartmentService.query().getWrapper().eq("dep_id", depId);
|
||||
userDepartmentService.remove(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getUserIdsByDepId(Integer depId) {
|
||||
return userDepartmentService.list(userDepartmentService.query().getWrapper().eq("dep_id", depId)).stream().map(UserDepartment::getUserId).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getCourseIdsByDepId(Integer depId) {
|
||||
return courseDepartmentService.list(courseDepartmentService.query().getWrapper().eq("dep_id", depId)).stream().map(CourseDepartment::getCourseId).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,6 +215,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
setPassword(HelperUtil.MD5(newPassword + user.getSalt()));
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> chunks(List<Integer> ids, List<String> fields) {
|
||||
return list(query().getWrapper().in("id", ids).select(fields));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user