|
|
@@ -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)); |
|
|
|