|
@@ -35,6 +35,7 @@ import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
|
|
|
@Tag(name = "管理后台 - 部门")
|
|
|
@RestController
|
|
@@ -54,9 +55,11 @@ public class DeptController {
|
|
|
@PreAuthorize("@ss.hasPermission('system:dept:create')")
|
|
|
public CommonResult<Long> createDept(@Valid @RequestBody DeptSaveReqVO createReqVO) {
|
|
|
Long deptId = deptService.createDept(createReqVO);
|
|
|
+
|
|
|
if(createReqVO.getLeaderUserId() == null){
|
|
|
return success(deptId);
|
|
|
}
|
|
|
+ // 重读插入了
|
|
|
if (!createReqVO.getLeaderUserId().equals("") && !createReqVO.getLeaderUserId().isEmpty()) {
|
|
|
for (Long teacherId : createReqVO.getLeaderUserId()) {//设置负责人的工作间
|
|
|
AdminUserDO teacher = adminUserService.getUser(teacherId);
|
|
@@ -71,29 +74,36 @@ public class DeptController {
|
|
|
@Operation(summary = "更新部门")
|
|
|
@PreAuthorize("@ss.hasPermission('system:dept:update')")
|
|
|
public CommonResult<Boolean> updateDept(@Valid @RequestBody DeptSaveReqVO updateReqVO) {
|
|
|
- deptService.updateDept(updateReqVO);
|
|
|
DeptDO originDept =deptService.getDept(updateReqVO.getId());
|
|
|
+ deptService.updateDept(updateReqVO);
|
|
|
DeptSaveReqVO originNewDept = BeanUtils.toBean(originDept, DeptSaveReqVO.class);
|
|
|
- List<Long>originLeaderList =originNewDept.getLeaderUserId();
|
|
|
- if (originLeaderList!=null){
|
|
|
- for (Long teacherId : updateReqVO.getLeaderUserId()) {//负责人的工作间
|
|
|
- //给教师删除所有的dept
|
|
|
- AdminUserDO teacher = adminUserService.getUser(teacherId);
|
|
|
- //TODO设置成测绘学院(默认)
|
|
|
- teacher.setDeptId(0L);
|
|
|
- adminUserService.updateUser(BeanUtils.toBean(teacher, UserSaveReqVO.class));
|
|
|
+ List<Long> originLeaderList = originNewDept.getLeaderUserId();
|
|
|
+ List<Long> newLeaderList = updateReqVO.getLeaderUserId();
|
|
|
+
|
|
|
+ if(newLeaderList == null || newLeaderList.isEmpty()){
|
|
|
+ List<AdminUserDO> teachers = adminUserService.getUserList(newLeaderList);
|
|
|
+ for (AdminUserDO teacher : teachers) {//负责人的工作间
|
|
|
+ teacher.setDeptId(0L);
|
|
|
+ adminUserService.updateUser(BeanUtils.toBean(teacher, UserSaveReqVO.class));
|
|
|
}
|
|
|
- }
|
|
|
- if(updateReqVO.getLeaderUserId() == null){
|
|
|
return success(true);
|
|
|
}
|
|
|
- if (!updateReqVO.getLeaderUserId().equals("") && !updateReqVO.getLeaderUserId().isEmpty()) {
|
|
|
- for (Long teacherId : updateReqVO.getLeaderUserId()) {//负责人的工作间
|
|
|
- //添加
|
|
|
- AdminUserDO teacher = adminUserService.getUser(teacherId);
|
|
|
+ // 新的负责人为空时,直接清空 ,如果不为空,则与原先有三种情况,增、减、同
|
|
|
+ if (originLeaderList != null ){
|
|
|
+ for (Long teacherId : originLeaderList) {//负责人的工作间
|
|
|
+ if(!newLeaderList.contains(teacherId)){
|
|
|
+ //给教师删除所有的dept
|
|
|
+ AdminUserDO teacher = adminUserService.getUser(teacherId);
|
|
|
+ //TODO设置成测绘学院(默认)
|
|
|
+ teacher.setDeptId(0L);
|
|
|
+ adminUserService.updateUser(BeanUtils.toBean(teacher, UserSaveReqVO.class));
|
|
|
+ }
|
|
|
+ newLeaderList.remove(teacherId);
|
|
|
+ }
|
|
|
+ List<AdminUserDO> teachers = adminUserService.getUserList(newLeaderList);
|
|
|
+ for (AdminUserDO teacher : teachers) {//负责人的工作间
|
|
|
teacher.setDeptId(updateReqVO.getId());
|
|
|
adminUserService.updateUser(BeanUtils.toBean(teacher, UserSaveReqVO.class));
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
return success(true);
|