|
@@ -7,6 +7,7 @@ import cn.efunbox.manage.base.service.DepartmentService;
|
|
|
import cn.efunbox.manage.base.vo.DeptTreeVO;
|
|
|
import cn.efunbox.manage.common.result.ApiCode;
|
|
|
import cn.efunbox.manage.common.result.ApiResult;
|
|
|
+import cn.efunbox.manage.common.utils.SnowflakeIdUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -40,6 +41,10 @@ public class DepartmentServiceImpl implements DepartmentService {
|
|
|
|
|
|
@Override
|
|
|
public ApiResult save(Department department) {
|
|
|
+ if(department ==null){
|
|
|
+ return ApiResult.error(ApiCode.PARAMETER_ERROR);
|
|
|
+ }
|
|
|
+ department.setId(SnowflakeIdUtil.getSnowflakeIdUtil().nextId());
|
|
|
department = departmentRepository.save(department);
|
|
|
if(Objects.nonNull(department)){
|
|
|
return ApiResult.ok(department);
|
|
@@ -49,6 +54,9 @@ public class DepartmentServiceImpl implements DepartmentService {
|
|
|
|
|
|
@Override
|
|
|
public ApiResult update(Department department) {
|
|
|
+ if(department ==null){
|
|
|
+ return ApiResult.error(ApiCode.PARAMETER_ERROR);
|
|
|
+ }
|
|
|
department = departmentRepository.update(department);
|
|
|
if(Objects.nonNull(department)){
|
|
|
return ApiResult.ok(department);
|
|
@@ -65,6 +73,18 @@ public class DepartmentServiceImpl implements DepartmentService {
|
|
|
return ApiResult.ok(departments);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ApiResult getDeptById(Long deptId) {
|
|
|
+ if(Objects.isNull(deptId)){
|
|
|
+ return ApiResult.error(ApiCode.PARAMETER_ERROR);
|
|
|
+ }
|
|
|
+ Department department = departmentRepository.find(deptId);
|
|
|
+ if(department ==null){
|
|
|
+ return ApiResult.error(ApiCode.NOT_FOUND);
|
|
|
+ }
|
|
|
+ return ApiResult.ok(department);
|
|
|
+ }
|
|
|
+
|
|
|
private DeptTreeVO recursiveTree(Long cid) {
|
|
|
Department department = departmentRepository.find(cid);
|
|
|
DeptTreeVO node = new DeptTreeVO();
|