Selaa lähdekoodia

数据权限

master
yaoq 2 vuotta sitten
vanhempi
commit
bae61e2ae7
3 muutettua tiedostoa jossa 46 lisäystä ja 26 poistoa
  1. +36
    -19
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java
  2. +9
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java
  3. +1
    -7
      smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/role/roleRight.js

+ 36
- 19
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java Näytä tiedosto

@@ -22,6 +22,7 @@ import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @Author: tanghp
@@ -52,26 +53,38 @@ public class RoleHandler {
if (pageDataSet.name.equals(RIGHT_DATA)) {
long role_id = filter.readLong("role_id");
long mp_id = filter.readLong("mp_id");
if (role_id <= 0 || mp_id <= 0) return R.error("未指定角色或菜单!");
if (role_id <= 0) return R.error("未指定角色!");
SwMap formData = data.readMap("form");

Set<Long> set = formData.readLongSet("menu");
if (PubUtil.isEmpty(set)) return R.error("未选择菜单!");
Role role = RoleCache.getInstance().get(role_id);
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), mp_id);
RoleRightContent rc = new RoleRightContent(role.getPrivilege());
RoleRight right = rc.getRoleRight(item.getId());
if (right == null) {
right = new RoleRight();
right.setId(item.getId());
right.setMenuId(item.getMenu());
right.setMenu(1);
for (Long menu_id : set) {
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), menu_id);
RoleRight right = rc.getRoleRight(item.getId());
if (right == null) {
right = new RoleRight();
right.setId(item.getId());
right.setMenuId(item.getMenu());
right.setMenu(1);
}
rc.saveItem(right);
}
if (mp_id > 0) {
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), mp_id);
RoleRight right = rc.getRoleRight(item.getId());
if (right == null) {
right = new RoleRight();
right.setId(item.getId());
right.setMenuId(item.getMenu());
right.setMenu(1);
}
right.setFunc(formData.readStringSet("func"));
right.setData(formData.readListMap("data"));
right.setField(MenuCache.getInstance().get(item.getMenu()).getRightSet(SwEnum.MenuRightType.FIELD.value), formData.readStringSet("write"), formData.readStringSet("read"));
rc.saveItem(right);
}
right.setFunc(formData.readStringSet("func"));
right.setData(formData.readListMap("data"));
right.setField(MenuCache.getInstance().get(item.getMenu()).getRightSet(SwEnum.MenuRightType.FIELD.value), formData.readStringSet("write"), formData.readStringSet("read"));

rc.saveItem(right);
role.setPrivilege(rc.toContentStr());

DbEngine.getInstance().findDao(Role.ENTITY_NAME).updateEntity(role);
RoleCache.getInstance().put(role);
return R.success(DynRetBean.createBean(formData));
@@ -107,14 +120,18 @@ public class RoleHandler {
@Override
public SwMap loadData(SwMap filter, PageDataset pageDataSet) {
if (pageDataSet.name.equals(RIGHT_DATA)) {
SwMap bean = new SwMap();
long role_id = filter.readLong("role_id");
long mp_id = filter.readLong("mp_id");
if (role_id <= 0 || mp_id <= 0) return new SwMap();
if (role_id <= 0) return bean;
Role role = RoleCache.getInstance().get(role_id);
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), mp_id);
if (item == null) return new SwMap();
RoleRightContent rc = new RoleRightContent(role.getPrivilege());
SwMap bean = new SwMap();
if (mp_id <= 0) {
bean.put("menu", rc.getMenuRight());
return bean;
}
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), mp_id);
if (item == null) return bean;
bean.put("func", rc.getFuncRight(item.getId()));
bean.put("read", rc.getFieldRight(item.getId(), 1));
bean.put("write", rc.getFieldRight(item.getId(), 2));


+ 9
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java Näytä tiedosto

@@ -57,6 +57,15 @@ public class RoleRightContent {
return PubUtil.getSqlInIds(right.getRightFunc());
}

public String getMenuRight() {
if (map.size() == 0) return "";
Set<String> menus = new HashSet<>();
map.values().forEach(roleRight -> {
if (roleRight.getMenu() == 1) menus.add(roleRight.getId() + "");
});
return PubUtil.getSqlInIds(menus);
}

public String getFieldRight(long key, int type) {
RoleRight right = getRoleRight(key);
if (right == null) return "";


+ 1
- 7
smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/role/roleRight.js Näytä tiedosto

@@ -11,15 +11,9 @@ window.$swEvent.setup("bpm.sys.user.role.roleRight", {
const onBeforeSave = () => {
$model.rightData.setFormVal("data", $model.roleDataList.data.list.rows);
};
const onRoleSelect = (row) => {
if (this.temp_mp_id !== row["srl_id"]) {
$model.menuData.setFormVal("mp_id", "");
}
this.temp_mp_id = row["srl_id"];
}

return {
onBeforeSave,
onRoleSelect,
}
}
});

Ladataan…
Peruuta
Tallenna