|
@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xy.dto.CommonIdDto;
|
|
|
import com.xy.dto.SysDeptDto;
|
|
|
import com.xy.dto.SysDeptListDto;
|
|
|
import com.xy.entity.SysDept;
|
|
@@ -27,7 +28,9 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.util.*;
|
|
@@ -95,13 +98,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return R.ok(saveOrUpdate(sysDept));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
@ApiOperation(value = "系统部门树下拉列表", notes = "系统部门树下拉列表")
|
|
|
- @GetMapping("tree/list")
|
|
|
+ @PostMapping("tree/list")
|
|
|
public R<List<Tree<Long>>> deptTreeList(@Valid @RequestBody SysDeptListDto sysDeptListDto) {
|
|
|
Long sysId = sysDeptListDto.getSysId();
|
|
|
String deptName = sysDeptListDto.getName();
|
|
@@ -114,17 +116,18 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "根据ID获取部门信息", notes = "根据ID获取部门信息")
|
|
|
- @GetMapping("{id}")
|
|
|
- public R<SysDeptVo> getById(@PathVariable("id") Long id) {
|
|
|
- SysDept sysDept = super.getById(id);
|
|
|
+ @GetMapping("getById")
|
|
|
+ public R<SysDeptVo> getById(@Valid @RequestBody CommonIdDto commonIdDto) {
|
|
|
+ SysDept sysDept = super.getById(commonIdDto.getId());
|
|
|
SysDeptVo sysRoleVo = copy(SysDeptVo.class, sysDept);
|
|
|
return R.ok(sysRoleVo);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "删除部门", notes = "删除部门")
|
|
|
- @DeleteMapping("{id}")
|
|
|
+ @PostMapping("deleteById")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public R<Boolean> deleteById(@PathVariable("id") Long id) {
|
|
|
+ public R<Boolean> deleteById(@Valid @RequestBody CommonIdDto commonIdDto) {
|
|
|
+ Long id = commonIdDto.getId();
|
|
|
// 级联删除部门
|
|
|
List<Long> idList = sysDeptRelationService
|
|
|
.list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, id)).stream()
|
|
@@ -144,13 +147,14 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "获取指定部门部门树", notes = "获取指定部门部门树")
|
|
|
- @GetMapping("deptTree/{id}")
|
|
|
- public R<List<Tree<Long>>> getDeptTreeById(@PathVariable("id") Long deptId) {
|
|
|
+ @PostMapping("getDeptTreeById")
|
|
|
+ public R<List<Tree<Long>>> getDeptTreeById(@Valid @RequestBody CommonIdDto commonIdDto) {
|
|
|
+ Long id = commonIdDto.getId();
|
|
|
List<Long> descendantIdList = sysDeptRelationService
|
|
|
- .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, deptId)).stream()
|
|
|
+ .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, id)).stream()
|
|
|
.map(SysDeptRelation::getDescendant).collect(Collectors.toList());
|
|
|
List<SysDept> deptList = baseMapper.selectBatchIds(descendantIdList);
|
|
|
- Optional<SysDept> dept = deptList.stream().filter(item -> item.getId() == deptId).findFirst();
|
|
|
+ Optional<SysDept> dept = deptList.stream().filter(item -> item.getId() == id).findFirst();
|
|
|
return R.ok(getDeptTree(deptList, dept.isPresent() ? dept.get().getParentId() : 0L));
|
|
|
}
|
|
|
|