|
|
@@ -1,13 +1,23 @@ |
|
|
|
package com.tuoheng.miniprogram.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
|
import com.tuoheng.common.core.utils.StringUtils; |
|
|
|
import com.tuoheng.miniprogram.dao.DeptMapper; |
|
|
|
import com.tuoheng.miniprogram.entity.Dept; |
|
|
|
import com.tuoheng.miniprogram.entity.User; |
|
|
|
import com.tuoheng.miniprogram.enums.DataPermissionEnum; |
|
|
|
import com.tuoheng.miniprogram.enums.MarkEnum; |
|
|
|
import com.tuoheng.miniprogram.enums.UserCodeEnum; |
|
|
|
import com.tuoheng.miniprogram.service.IDeptService; |
|
|
|
import com.tuoheng.miniprogram.utils.CurrentUserUtil; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.xml.crypto.Data; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@@ -45,6 +55,44 @@ public class DeptServiceImpl implements IDeptService { |
|
|
|
return JsonResult.success(list); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult list() { |
|
|
|
User user = CurrentUserUtil.getUserInfo(); |
|
|
|
String tenantId = user.getTenantId(); |
|
|
|
Integer dataPermission = user.getDataPermission(); |
|
|
|
String deptId = user.getDeptId(); |
|
|
|
if(StringUtils.isEmpty(deptId)){ |
|
|
|
return JsonResult.error("当前用户部门为空"); |
|
|
|
} |
|
|
|
List<Dept> deptList = new ArrayList<>(); |
|
|
|
if(null == dataPermission){ |
|
|
|
return JsonResult.error(DataPermissionEnum.DATA_PERMISSION_IS_NOT_EXIST.getCode(), |
|
|
|
DataPermissionEnum.DATA_PERMISSION_IS_NOT_EXIST.getDescription()); |
|
|
|
} |
|
|
|
if(DataPermissionEnum.ALL.getCode() == dataPermission){ |
|
|
|
deptList = deptMapper.selectList(Wrappers.<Dept>lambdaQuery() |
|
|
|
.eq(Dept::getMark, MarkEnum.VALID.getCode()) |
|
|
|
.eq(Dept::getTenantId, tenantId)); |
|
|
|
} |
|
|
|
if(DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == dataPermission){ |
|
|
|
//获取当前部门及其子部门 |
|
|
|
List<String> deptIdList = deptMapper.selectAllChildListById(deptId); |
|
|
|
if(CollectionUtil.isNotEmpty(deptIdList)){ |
|
|
|
for (String id : deptIdList) { |
|
|
|
Dept dept = deptMapper.selectById(id); |
|
|
|
deptList.add(dept); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(DataPermissionEnum.DEPT.getCode() == dataPermission){ |
|
|
|
//查询当前部门 |
|
|
|
Dept dept = deptMapper.selectById(deptId); |
|
|
|
deptList.add(dept); |
|
|
|
} |
|
|
|
|
|
|
|
return JsonResult.success(deptList); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 递归获取部门的子集 |