|
@@ -12,6 +12,7 @@ import com.xy.entity.SysDept;
|
|
|
import com.xy.entity.SysDeptRelation;
|
|
|
import com.xy.mapper.SysDeptMapper;
|
|
|
import com.xy.service.SysDeptRelationService;
|
|
|
+import com.xy.service.SysDeptRoleService;
|
|
|
import com.xy.service.SysDeptService;
|
|
|
import com.xy.utils.R;
|
|
|
import com.xy.utils.SaTokenUtils;
|
|
@@ -37,6 +38,7 @@ import static com.xy.utils.Beans.copy;
|
|
|
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
|
|
|
|
|
|
private final SysDeptRelationService sysDeptRelationService;
|
|
|
+ private final SysDeptRoleService sysDeptRoleService;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -60,20 +62,30 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
if (count > 0) {
|
|
|
return R.fail("此部门已存在");
|
|
|
}
|
|
|
+ List<Long> roleIds = sysDeptDto.getRoleIds();
|
|
|
|
|
|
SysDept sysDept = copy(SysDept.class, sysDeptDto).saveOrUpdate(currentUser, sysDeptDto.getSysId());
|
|
|
|
|
|
if (isAdd) {
|
|
|
//新建部门关系
|
|
|
sysDeptRelationService.saveDeptRelation(sysDept);
|
|
|
+ //角色部门关系建立
|
|
|
+ if (CollUtil.isNotEmpty(roleIds)) {
|
|
|
+ sysDeptRoleService.saveDeptRole(sysDept.getId(), roleIds);
|
|
|
+ }
|
|
|
} else {
|
|
|
// 更新部门关系
|
|
|
SysDeptRelation relation = new SysDeptRelation();
|
|
|
relation.setAncestor(sysDept.getParentId());
|
|
|
relation.setDescendant(sysDept.getId());
|
|
|
sysDeptRelationService.updateDeptRelation(relation);
|
|
|
+ //角色部门关系更新
|
|
|
+ if (CollUtil.isNotEmpty(roleIds)) {
|
|
|
+ sysDeptRoleService.updateDeptRole(sysDept.getId(), roleIds);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
return R.ok(saveOrUpdate(sysDept));
|
|
|
}
|
|
|
|
|
@@ -91,6 +103,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R<Boolean> deleteById(Long id) {
|
|
|
// 级联删除部门
|
|
|
List<Long> idList = sysDeptRelationService
|
|
@@ -102,6 +115,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
}
|
|
|
// 删除部门级联关系
|
|
|
sysDeptRelationService.removeDeptRelationById(id);
|
|
|
+ //部门角色关系移除
|
|
|
+ sysDeptRoleService.removeDeptRoleById(id);
|
|
|
return R.ok(Boolean.TRUE);
|
|
|
}
|
|
|
|