修改后台获取当前用户角色方法,获取用户角色及用户所属机构角色

This commit is contained in:
lhc
2021-05-18 17:51:09 +08:00
parent 5c83f37a3f
commit fd867b1a39
2 changed files with 118 additions and 6 deletions

View File

@@ -13,9 +13,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author lhc
@@ -32,6 +30,7 @@ public class RoleUserServiceImpl implements RoleUserService {
private static final String USER_ROLE_ID = "USER_ROLE_ID";
private static final String OS_REL_USER_GROUP = "OS_REL_USER_GROUP";
private static final String COMMA = ",";
private static final String GUOBO_ID= "-3858082048188003782";
final BaseMapper baseMapper;
@@ -83,7 +82,10 @@ public class RoleUserServiceImpl implements RoleUserService {
public ResultVO<Object> getUserRole(String userId) {
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).andEqual("DELETED",1).build();
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_USER_ROLE, condition);
return ResultVO.getSuccess(list);
Map<String, Object> result = new HashMap<>(2);
result.put("user", list);
result.put("org", getOrgRoleList(userId));
return ResultVO.getSuccess(result);
}
@Override
@@ -93,4 +95,31 @@ public class RoleUserServiceImpl implements RoleUserService {
return ResultVO.getSuccess(list);
}
private Set<Map<String, Object>> getOrgRoleList(String userId) {
Condition deptCondition = Condition.creatCriteria().andEqual("DEPT_ID",GUOBO_ID).andEqual("DELETED",1).build();
List<Map<String,Object>> guoboList= baseMapper.selectByCondition("OS_REL_DEPT_ROLE", deptCondition);
Set<Map<String, Object>> set = new HashSet<>(guoboList);
Condition condition = Condition.creatCriteria().andEqual("ID",userId).andEqual("DELETED",1).build();
Map<String,Object> user = baseMapper.selectOneByCondition("GB_CAS_MEMBER", condition);
String code = (String) user.get("DEPT_CODE");
if (code.length() == 4) {
getDepList(set, code);
} else {
getDepList(set, code);
getDepList(set,code.substring(0,4));
}
return set;
}
private void getDepList(Set<Map<String, Object>> set, String code) {
Condition deptCondition;
Map<String, Object> org = baseMapper.selectOneByCondition("GB_CAS_DEPT", Condition.creatCriteria().andEqual("CODE", code).andEqual("DELETED", 1).build());
if (org != null && !org.isEmpty()) {
deptCondition = Condition.creatCriteria().andEqual("DEPT_ID", org.get("ID")).andEqual("DELETED", 1).build();
List<Map<String, Object>> roleList = baseMapper.selectByCondition("OS_REL_DEPT_ROLE", deptCondition);
set.addAll(roleList);
}
}
}

View File

@@ -6,6 +6,7 @@ import com.github.pagehelper.PageInfo;
import com.hcframe.base.common.ResultVO;
import com.hcframe.base.common.ServiceException;
import com.hcframe.base.common.WebPageInfo;
import com.hcframe.base.common.utils.MyPageHelper;
import com.hcframe.base.module.data.module.BaseMapper;
import com.hcframe.base.module.data.module.BaseMapperImpl;
import com.hcframe.base.module.data.module.Condition;
@@ -52,9 +53,91 @@ public class DeptServiceImpl implements DeptService {
@Override
public ResultVO<Object> addDept(Map<String, Object> org) {
String parentCode = (String) org.get("PARENT_CODE");
org.remove("PARENT_CODE");
String code;
String path;
if ("guobo".equals(parentCode)) {
MyPageHelper.orderBy("CODE", "DESC");
List<Map<String, Object>> list = baseMapper.selectAll(GB_CAS_DEPT);
List<Map<String, Object>> pathList = new LinkedList<>();
List<Map<String, Object>> codeList = new LinkedList<>();
for (Map<String, Object> map : list) {
if (4 == map.get("CODE").toString().length()) {
codeList.add(map);
}
}
MyPageHelper.orderBy("PATH", "DESC");
list = baseMapper.selectAll(GB_CAS_DEPT);
for (Map<String, Object> map : list) {
if (12 == map.get("PATH").toString().length()) {
pathList.add(map);
}
}
code = getCode(codeList,parentCode);
path = getPath(pathList);
} else {
Condition condition = Condition.creatCriteria().andLike("CODE", parentCode + "%").build();
MyPageHelper.orderBy("CODE", "DESC");
List<Map<String, Object>> codeList = baseMapper.selectByCondition(GB_CAS_DEPT, condition);
code = getCode(codeList, parentCode);
MyPageHelper.orderBy("PATH", "DESC");
List<Map<String, Object>> pathList = baseMapper.selectByCondition(GB_CAS_DEPT, condition);
path = getPath(pathList);
}
org.put("CODE", code);
org.put("PATH", path);
MyPageHelper.start(WebPageInfo.builder().pageNum(1).pageSize(1).sortField("SORT_ID").order("DESC").build());
List<Map<String, Object>> list = baseMapper.selectAll(GB_CAS_DEPT);
org.put("SORT_ID", Integer.parseInt(String.valueOf(list.get(0).get("SORT_ID")))+1);
return ResultVO.getSuccess(tableService.saveWithDate(TABLE_INFO, org));
}
private String getCode(List<Map<String,Object>> codeList,String parentCode){
String tempCode = "";
String lastCode = (String) codeList.get(0).get("CODE");
int incrementCode = Integer.parseInt(lastCode.substring(lastCode.length() - 2)) + 1;
if ("guobo".equals(parentCode)) {
parentCode = "D";
if (incrementCode < 10) {
tempCode = tempCode + "00" + incrementCode;
} else if (incrementCode < 100) {
tempCode = tempCode + "0" + incrementCode;
} else {
tempCode = tempCode + incrementCode;
}
} else {
if (incrementCode < 10) {
tempCode = tempCode + "0" + incrementCode;
} else {
tempCode = tempCode + incrementCode;
}
}
return parentCode + tempCode;
}
private String getPath(List<Map<String,Object>> pathList) {
String tempPath = "";
String lastPath = (String) pathList.get(0).get("PATH");
String parentPath = lastPath.substring(0, lastPath.length() - 4);
int incrementPath = Integer.parseInt(lastPath.substring(lastPath.length() - 4)) + 1;
if (pathList.size() == 1) {
parentPath = lastPath;
tempPath = "0001";
} else {
if (incrementPath < 10) {
tempPath = tempPath + "000" + incrementPath;
} else if (incrementPath < 100) {
tempPath = tempPath + "00" + incrementPath;
} else if (incrementPath < 1000) {
tempPath = tempPath + "0" + incrementPath;
} else {
tempPath = tempPath + incrementPath;
}
}
return parentPath + tempPath;
}
@Override
public ResultVO<Integer> updateDept(Map<String, Object> org, Integer version) {
return tableService.updateWithDate(TABLE_INFO, org, version);
@@ -68,7 +151,6 @@ public class DeptServiceImpl implements DeptService {
.creatCriteria()
.andIn(ID, Arrays.asList(idArr))
.build();
baseMapper.deleteByCondition(OS_SYS_POSITION, condition);
tableService.delete(TABLE_INFO, ids);
return ResultVO.getSuccess();
}
@@ -90,7 +172,8 @@ public class DeptServiceImpl implements DeptService {
builder.andLike("CODE", code + "%");
}
builder.andEqual("DELETED", 1);
PageInfo<Map<String, Object>> pageInfo = baseMapper.selectByCondition(builder.build(), webPageInfo);;
PageInfo<Map<String, Object>> pageInfo = baseMapper.selectByCondition(builder.build(), webPageInfo);
;
return ResultVO.getSuccess(pageInfo);
}