优化系统权限逻辑

This commit is contained in:
季圣华
2021-08-22 16:05:51 +08:00
parent 2a704dcdb5
commit b220608a69
7 changed files with 35 additions and 113 deletions

View File

@@ -70,6 +70,8 @@ public class DepotController {
HttpServletRequest request) throws Exception{
JSONArray arr = new JSONArray();
try {
//获取权限信息
String ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
List<Depot> dataList = depotService.findUserDepot();
//开始拼接json数据
JSONObject outer = new JSONObject();
@@ -88,17 +90,10 @@ public class DepotController {
item.put("value", depot.getId());
item.put("title", depot.getName());
item.put("attributes", depot.getName());
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(type, keyId, "[" + depot.getId().toString() + "]");
} catch (Exception e) {
logger.error(">>>>>>>>>>>>>>>>>设置用户对应的仓库:类型" + type + " KeyId为 " + keyId + " 存在异常!");
}
if (flag == true) {
Boolean flag = ubValue.contains("[" + depot.getId().toString() + "]");
if (flag) {
item.put("checked", true);
}
//结束
dataArray.add(item);
}
}

View File

@@ -156,6 +156,8 @@ public class FunctionController {
public JSONArray getFunctionList(List<Function> dataList, String type, String keyId) throws Exception {
JSONArray dataArray = new JSONArray();
//获取权限信息
String ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
if (null != dataList) {
for (Function function : dataList) {
JSONObject item = new JSONObject();
@@ -164,13 +166,8 @@ public class FunctionController {
item.put("value", function.getId());
item.put("title", function.getName());
item.put("attributes", function.getName());
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(type, keyId, "[" + function.getId().toString() + "]");
} catch (Exception e) {
logger.error(">>>>>>>>>>>>>>>>>设置角色对应的功能:类型" + type + " KeyId为 " + keyId + " 存在异常!");
}
if (flag == true) {
Boolean flag = ubValue.contains("[" + function.getId().toString() + "]");
if (flag) {
item.put("checked", true);
}
List<Function> funList = functionService.findRoleFunction(function.getNumber());

View File

@@ -40,20 +40,16 @@ public class RoleController {
HttpServletRequest request)throws Exception {
JSONArray arr = new JSONArray();
try {
//获取权限信息
String ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
List<Role> dataList = roleService.findUserRole();
if (null != dataList) {
for (Role role : dataList) {
JSONObject item = new JSONObject();
item.put("id", role.getId());
item.put("text", role.getName());
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(type, keyId, "[" + role.getId().toString() + "]");
} catch (Exception e) {
logger.error(">>>>>>>>>>>>>>>>>设置用户对应的角色:类型" + type + " KeyId为 " + keyId + " 存在异常!");
}
if (flag == true) {
Boolean flag = ubValue.contains("[" + role.getId().toString() + "]");
if (flag) {
item.put("checked", true);
}
arr.add(item);
@@ -65,8 +61,8 @@ public class RoleController {
return arr;
}
@PostMapping(value = "/list")
public List<Role> list(HttpServletRequest request)throws Exception {
return roleService.getRole();
@GetMapping(value = "/allList")
public List<Role> allList(HttpServletRequest request)throws Exception {
return roleService.allList();
}
}

View File

@@ -83,19 +83,15 @@ public class SupplierController {
try {
String type = "UserCustomer";
Long userId = userService.getUserId(request);
//获取权限信息
String ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, userId.toString());
List<Supplier> supplierList = supplierService.findBySelectCus();
JSONArray dataArray = new JSONArray();
if (null != supplierList) {
boolean customerFlag = systemConfigService.getCustomerFlag();
for (Supplier supplier : supplierList) {
JSONObject item = new JSONObject();
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(type, userId.toString(), "[" + supplier.getId().toString() + "]");
} catch (DataAccessException e) {
logger.error(">>>>>>>>>>>>>>>>>查询用户对应的客户:存在异常!");
}
Boolean flag = ubValue.contains("[" + supplier.getId().toString() + "]");
if (!customerFlag || flag) {
item.put("id", supplier.getId());
item.put("supplier", supplier.getSupplier()); //客户名称
@@ -197,6 +193,8 @@ public class SupplierController {
HttpServletRequest request) throws Exception{
JSONArray arr = new JSONArray();
try {
//获取权限信息
String ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
List<Supplier> dataList = supplierService.findUserCustomer();
//开始拼接json数据
JSONObject outer = new JSONObject();
@@ -215,17 +213,10 @@ public class SupplierController {
item.put("value", supplier.getId());
item.put("title", supplier.getSupplier());
item.put("attributes", supplier.getSupplier());
//勾选判断1
Boolean flag = false;
try {
flag = userBusinessService.checkIsUserBusinessExist(type, keyId, "[" + supplier.getId().toString() + "]");
} catch (Exception e) {
logger.error(">>>>>>>>>>>>>>>>>设置用户对应的客户:类型" + type + " KeyId为 " + keyId + " 存在异常!");
}
if (flag == true) {
Boolean flag = ubValue.contains("[" + supplier.getId().toString() + "]");
if (flag) {
item.put("checked", true);
}
//结束
dataArray.add(item);
}
}

View File

@@ -61,49 +61,6 @@ public class SystemConfigController {
@Value(value="${spring.servlet.multipart.max-request-size}")
private Long maxRequestSize;
@GetMapping(value = "/getDictItems/{dictCode}")
public BaseResponseInfo getDictItems(@PathVariable String dictCode,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
try {
Long userId = userService.getUserId(request);
JSONArray arr = new JSONArray();
if(StringUtil.isNotEmpty(dictCode)) {
if (dictCode.equals("depotDict")) {
List<Depot> dataList = depotService.findUserDepot();
//开始拼接json数据
if (null != dataList) {
boolean depotFlag = systemConfigService.getDepotFlag();
for (Depot depot : dataList) {
JSONObject item = new JSONObject();
//勾选判断1
Boolean flag = false;
String type = "UserDepot";
try {
flag = userBusinessService.checkIsUserBusinessExist(type, userId.toString(), "[" + depot.getId().toString() + "]");
} catch (DataAccessException e) {
logger.error(">>>>>>>>>>>>>>>>>查询用户对应的仓库:类型" + type + " KeyId为 " + userId + " 存在异常!");
}
if (!depotFlag || flag) {
item.put("value", depot.getId().toString());
item.put("text", depot.getName());
item.put("title", depot.getName());
arr.add(item);
}
}
}
}
}
res.code = 200;
res.data = arr;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 获取当前租户的配置信息
* @param request