|
@@ -8,6 +8,7 @@ import com.boman.common.core.utils.number.NumberUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.common.redis.service.RedisService;
|
|
|
+import com.boman.common.security.service.TokenService;
|
|
|
import com.boman.domain.SysUser;
|
|
|
import com.boman.domain.constant.CacheConstants;
|
|
|
import com.boman.system.api.model.LoginUser;
|
|
@@ -29,6 +30,8 @@ import com.boman.system.service.ISysDeptService;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import static com.boman.common.core.utils.StringUtils.isNotEmpty;
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
|
|
|
import static com.boman.common.datascope.aspect.DataScopeAspect.DATA_SCOPE_ALL;
|
|
|
|
|
|
/**
|
|
@@ -535,4 +538,42 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
public SysDept getParentById(Long parentId) {
|
|
|
return deptMapper.getParentById(parentId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SysDept> listTowns(Long deptId) {
|
|
|
+ String token = SecurityUtils.getToken();
|
|
|
+ LoginUser loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
|
|
|
+
|
|
|
+ List<SysRole> roles = loginUser.getSysUser().getRoles();
|
|
|
+ List<String> roleKeyList = roles.stream().map(SysRole::getRoleKey).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<SysDept> townsDepts = new ArrayList<>(16);
|
|
|
+ List<SysDept> allDepts = selectDeptsList();
|
|
|
+ if (roleKeyList.contains("admin") || roleKeyList.contains("city")) {
|
|
|
+ Long deptId1;
|
|
|
+ if (null == deptId) deptId1 = 1L; // 查所有乡镇
|
|
|
+ else deptId1 = deptId; // 查乡镇下的村
|
|
|
+
|
|
|
+ for (SysDept allDept : allDepts) {
|
|
|
+ if (isEmpty(allDept.getParentId())) continue;
|
|
|
+ if (allDept.getParentId().equals(deptId1)) {
|
|
|
+ townsDepts.add(allDept);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (roleKeyList.contains("sys:town")) {
|
|
|
+ if (null == deptId) {
|
|
|
+ // 乡镇的登录进来,只能选择自己的乡镇,不可以选择其他的乡镇,因此只返回自己的乡镇
|
|
|
+ townsDepts.add(loginUser.getSysUser().getDept());
|
|
|
+ } else {
|
|
|
+ for (SysDept allDept : allDepts) {
|
|
|
+ if (isEmpty(allDept.getParentId())) continue;
|
|
|
+ if (allDept.getParentId().equals(deptId)) {
|
|
|
+ townsDepts.add(allDept);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return townsDepts;
|
|
|
+ }
|
|
|
}
|