yaoq преди 2 години
родител
ревизия
2804285585
променени са 17 файла, в които са добавени 706 реда и са изтрити 66 реда
  1. +13
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java
  2. +7
    -6
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java
  3. +39
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupHandler.java
  4. +7
    -5
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupService.java
  5. +99
    -21
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/Menu.java
  6. +14
    -5
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuCache.java
  7. +3
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java
  8. +6
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanCache.java
  9. +237
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java
  10. +121
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRight.java
  11. +83
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java
  12. +9
    -7
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleService.java
  13. +22
    -0
      smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/dataRightGroup/drgList.js
  14. +18
    -0
      smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/role/roleRight.js
  15. +20
    -10
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  16. +7
    -4
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwMap.java
  17. +1
    -1
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java

+ 13
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java Целия файл

@@ -3,8 +3,9 @@ package cc.smtweb.system.bpm.web.design.form;
import cc.smtweb.framework.core.annotation.SwTable;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
import cc.smtweb.system.bpm.web.design.form.define.PageDatasetField;
import cc.smtweb.system.bpm.web.design.form.define.PageDatasets;
import cc.smtweb.system.bpm.web.design.form.define.PageModel;

/**
* Created by Akmm at 2022/4/15 17:26
@@ -43,6 +44,17 @@ public class ModelForm extends DefaultEntity {
this.masterTableId = masterTableId;
}

public PageDatasetField getField(String field) {
for (PageDataset ds : getDatasets().list) {
for (PageDatasetField df : ds.fields) {
if (df.name.equals(field)) {
return df;
}
}
}
return null;
}

public PageDatasets getDatasets() {
if (datasets == null) {
synchronized (ModelForm.class) {


+ 7
- 6
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java Целия файл

@@ -86,7 +86,7 @@ public class ComboHandler {
} catch (Exception ue) {
return SwListData.create(new ArrayList(), 0);
}
return SwListData.create(list, list.size());
return SwListData.create(list, 0);
}

@Override
@@ -105,20 +105,21 @@ public class ComboHandler {

@Override
public SwListData buildListData() {
ModelForm mf = ModelFormCache.getInstance().get(params.readMap("filter").readLong("f_page"));
ModelForm mf = ModelFormCache.getInstance().get(filter.readLong("f_page"));
if (mf == null) return SwListData.create(new ArrayList(), 0);
PageDatasets pageDatasets = mf.getDatasets();
if (pageDatasets == null) return SwListData.create(new ArrayList(), 0);
Map<String, SwMap> map = new HashMap<>();
pageDatasets.list.forEach(data -> {
data.fields.forEach(field -> {
if (map.containsKey(field.name)) return;
if (map.containsKey(field.field)) return;
SwMap swMap = new SwMap();
swMap.put("f_id", field.name);
swMap.put("f_id", field.field);
swMap.put("f_name", field.label);
map.put(field.name, swMap);
map.put(field.field, swMap);
});
});
return SwListData.create(new ArrayList<SwMap>(map.values()), map.size());
return SwListData.create(new ArrayList<SwMap>(map.values()), 0);
}

@Override


+ 39
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupHandler.java Целия файл

@@ -0,0 +1,39 @@
package cc.smtweb.system.bpm.web.sys.user.dataRightGroup;

import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.util.JsonUtil;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageSaveHandler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @Author: tanghp
* @Date: 2022-08-01 17:47
* @Desc:
*/
public class DataRightGroupHandler {

static class DrgSaveHandler extends DynPageSaveHandler {

@Override
protected DefaultEntity readBeanFromPage(PageDataset pageDataSet, SwMap data) {
DataRightGroup bean = (DataRightGroup) super.readBeanFromPage(pageDataSet, data);
bean.setContent(JsonUtil.encodeString(data.readListMap("sdrg_content")));
return bean;
}
}

static class DrgLoadHandle extends DynPageLoadHandler {

@Override
protected void afterLoadBean(PageDataset dataset, SwMap bean) {
super.afterLoadBean(dataset, bean);
bean.put("sdrg_content", JsonUtil.parseList(bean.readString("sdrg_content"), Map.class));
}
}
}

+ 7
- 5
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupService.java Целия файл

@@ -1,12 +1,8 @@
package cc.smtweb.system.bpm.web.sys.user.dataRightGroup;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;

/**
* Created by 1 at 2022-08-04 17:45:35
@@ -17,6 +13,12 @@ public class DataRightGroupService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
switch (type) {
case TYPE_LOAD:
return new DataRightGroupHandler.DrgLoadHandle();
case TYPE_SAVE:
return new DataRightGroupHandler.DrgSaveHandler();
}
return super.createHandler(type);
}



+ 99
- 21
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/Menu.java Целия файл

@@ -1,8 +1,14 @@
package cc.smtweb.system.bpm.web.sys.user.menu;

import cc.smtweb.framework.core.annotation.SwTable;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.util.JsonUtil;
import cc.smtweb.framework.core.util.PubUtil;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Created by 1 at 2022-08-03 08:53:34
@@ -16,94 +22,166 @@ public class Menu extends DefaultEntity {
super(ENTITY_NAME);
}

/** 主键 */
/**
* 主键
*/
public long getId() {
return getLong("sm_id");
}

/** 主键 */
/**
* 主键
*/
public void setId(long sm_id) {
put("sm_id", sm_id);
}
/** 排序 */

/**
* 排序
*/
public int getSeq() {
return getInt("sm_seq");
}

/** 排序 */
/**
* 排序
*/
public void setSeq(int sm_seq) {
put("sm_seq", sm_seq);
}
/** 名称 */

/**
* 名称
*/
public String getName() {
return getStr("sm_name");
}

/** 名称 */
/**
* 名称
*/
public void setName(String sm_name) {
put("sm_name", sm_name);
}
/** 图标 */

/**
* 图标
*/
public String getIcon() {
return getStr("sm_icon");
}

/** 图标 */
/**
* 图标
*/
public void setIcon(String sm_icon) {
put("sm_icon", sm_icon);
}
/** 权限点 */

/**
* 权限点
*/
public String getRight() {
return getStr("sm_right");
}

/** 权限点 */
/**
* 权限点
*/
public void setRight(String sm_right) {
put("sm_right", sm_right);
}
/** 类型 */

/**
* 类型
*/
public boolean isType() {
return getBool("sm_type");
}

/** 类型 */
/**
* 类型
*/
public void set(boolean sm_type) {
setBool("sm_type", sm_type);
}
/** 请求内容 */

/**
* 请求内容
*/
public String getContent() {
return getStr("sm_content");
}

/** 请求内容 */
/**
* 请求内容
*/
public void setContent(String sm_content) {
put("sm_content", sm_content);
}
/** 所属项目 */

/**
* 所属项目
*/
public long getPrjId() {
return getLong("sm_prj_id");
}

/** 所属项目 */
/**
* 所属项目
*/
public void setPrjId(long sm_prj_id) {
put("sm_prj_id", sm_prj_id);
}
/** 所属目录 */

/**
* 所属目录
*/
public long getMcId() {
return getLong("sm_mc_id");
}

/** 所属目录 */
/**
* 所属目录
*/
public void setMcId(long sm_mc_id) {
put("sm_mc_id", sm_mc_id);
}
/** 备注 */

/**
* 备注
*/
public String getRemark() {
return getStr("sm_remark");
}

/** 备注 */
/**
* 备注
*/
public void setRemark(String sm_remark) {
put("sm_remark", sm_remark);
}


public final String getPath() {
if (PubUtil.isEmpty(getContent())) return "";
return JsonUtil.parseMap(getContent()).get("path").toString();
}

public final String getPageId() {
if (PubUtil.isEmpty(getContent())) return "";
return JsonUtil.parseMap(getContent()).get("pageId").toString();
}

public final List<String> getRightList(String type) {
List<String> set = new ArrayList<>();
if (PubUtil.isEmpty(getRight())) return set;
return (List<String>) JsonUtil.parseMap(getRight()).get(type);
}

public final Set<String> getRightSet(String type) {
List<String> list = getRightList(type);
if (list == null) return new HashSet<>();
return new HashSet<String>(list);
}
}

+ 14
- 5
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuCache.java Целия файл

@@ -3,9 +3,8 @@ package cc.smtweb.system.bpm.web.sys.user.menu;
import cc.smtweb.framework.core.annotation.SwCache;
import cc.smtweb.framework.core.cache.AbstractEntityCache;
import cc.smtweb.framework.core.cache.CacheManager;
import cc.smtweb.framework.core.util.JsonUtil;
import cc.smtweb.framework.core.util.PubUtil;

import java.util.HashSet;
import java.util.Set;

/**
@@ -35,8 +34,18 @@ public class MenuCache extends AbstractEntityCache<Menu> {
public final String getPath(long menu_id) {
Menu menu = get(menu_id);
if (menu == null) return "";
String content = menu.getContent();
if (PubUtil.isEmpty(content)) return "";
return JsonUtil.parseMap(menu.getContent()).get("path").toString();
return menu.getPath();
}

public final String getPageId(long menu_id) {
Menu menu = get(menu_id);
if (menu == null) return "";
return menu.getPageId();
}

public final Set<String> getRight(long menu_id, String type) {
Menu menu = get(menu_id);
if (menu == null) return new HashSet<>();
return menu.getRightSet(type);
}
}

+ 3
- 3
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java Целия файл

@@ -73,9 +73,9 @@ public class MenuHandler {
data.put("sm_content", JsonUtil.encodeString(sm_content));
//处理权限点
SwMap sm_right = new SwMap();
sm_right.put("data", data.readStringList("sm_right_data"));
sm_right.put("func", data.readStringList("sm_right_func"));
sm_right.put("field", data.readStringList("sm_right_field"));
sm_right.put("data", data.readStringSet("sm_right_data"));
sm_right.put("func", data.readStringSet("sm_right_func"));
sm_right.put("field", data.readStringSet("sm_right_field"));
data.put("sm_right", JsonUtil.encodeString(sm_right));
return super.readBeanFromPage(pageDataSet, data);
}


+ 6
- 3
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanCache.java Целия файл

@@ -4,9 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache;
import cc.smtweb.framework.core.cache.AbstractEntityCache;
import cc.smtweb.framework.core.cache.CacheManager;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

/**
@@ -31,4 +28,10 @@ public class MenuPlanCache extends AbstractEntityCache<MenuPlan> {
public final Set<MenuPlan> getByP(String key) {
return getListByKey(mk_p, key);
}

public final MenuPlanItem getById(long mp_id, long key) {
MenuPlan menuPlan = get(mp_id);
if (menuPlan == null) return null;
return new MenuPlanContent(menuPlan.getContent()).findById(key);
}
}

+ 237
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java Целия файл

@@ -0,0 +1,237 @@
package cc.smtweb.system.bpm.web.sys.user.role;

import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.mvc.service.SwListData;
import cc.smtweb.framework.core.util.PubUtil;
import cc.smtweb.system.bpm.web.design.form.ModelForm;
import cc.smtweb.system.bpm.web.design.form.ModelFormCache;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
import cc.smtweb.system.bpm.web.design.form.define.PageDatasetField;
import cc.smtweb.system.bpm.web.engine.dynPage.*;
import cc.smtweb.system.bpm.web.sys.user.dataRight.DataRightDefineCache;
import cc.smtweb.system.bpm.web.sys.user.dataRightGroup.DataRightGroupCache;
import cc.smtweb.system.bpm.web.sys.user.menu.Menu;
import cc.smtweb.system.bpm.web.sys.user.menu.MenuCache;
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanCache;
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanItem;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @Author: tanghp
* @Date: 2022-08-01 17:47
* @Desc:
*/
public class RoleHandler {
private final static String ROLE_FUNC = "roleFuncCombo";
private final static String ROLE_Field = "roleFieldCombo";
private final static String ROLE_DATA = "roleDataList";
private final static String RIGHT_DATA = "rightData";

static class RoleSaveHandler extends DynPageSaveHandler {

/**
* 保存指定数据集操作,入参:{pageId,dataset:"", data:{form:{},list: {total:0,rows:[]}}, filter:{}}
*/
public R saveOne() {
//数据集
String dbName = params.readString("dataset");
SwMap filter = params.readMap("filter");
//待保存数据
SwMap data = params.readMap("data");
if (data == null) throw new BizException("没有收到待保存的的数据:" + dbName + "!");
//对应的数据集定义
PageDataset pageDataSet = findDataset(dbName);
if (pageDataSet == null) throw new BizException("没有找到指定的的数据集定义:" + dbName + "!");
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("未指定角色或菜单!");
SwMap formData = data.readMap("form");

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);
}
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));
}
return super.saveOne();
}
}

static class RoleLoadHandle extends DynPageLoadHandler {

@Override
public DynPageProvider getProvider() {
return new RightDataProvider();
}

@Override
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) {
switch (pageDataSet.name) {
case ROLE_FUNC:
return new RoleFuncListHandle(pageId, filter, pageDataSet);
case ROLE_Field:
return new RoleFieldListHandle(pageId, filter, pageDataSet);
case ROLE_DATA:
return new RoleDataListHandle(pageId, filter, pageDataSet);
}
return super.getListWorker(filter, pageDataSet);
}


}

static class RightDataProvider extends DynPageProvider {
@Override
public SwMap loadData(SwMap filter, PageDataset pageDataSet) {
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 new SwMap();
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();
bean.put("func", rc.getFuncRight(item.getId()));
bean.put("read", rc.getFieldRight(item.getId(), 1));
bean.put("write", rc.getFieldRight(item.getId(), 2));
return bean;
}
return super.loadData(filter, pageDataSet);
}
}

static class RoleFieldListHandle extends DynPageListHandler {

public RoleFieldListHandle(long pageId, SwMap filter, PageDataset pageDataSet) {
super(pageId, filter, pageDataSet);
}

private String getFieldName(ModelForm mf, String field) {
PageDatasetField df = mf.getField(field);
if (df == null) return null;
return df.label;
}

@Override
public SwListData buildListData() {
List<SwMap> list = new ArrayList<>();
long role_id = filter.readLong("role_id");
long mp_id = filter.readLong("mp_id");
if (role_id <= 0 || mp_id <= 0) return SwListData.create(list, 0);
Role role = RoleCache.getInstance().get(role_id);
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), mp_id);
if (item == null) return SwListData.create(list, 0);
Menu menu = MenuCache.getInstance().get(item.getMenu());
ModelForm mf = ModelFormCache.getInstance().get(menu.getPageId());
for (String f : menu.getRightSet(SwEnum.MenuRightType.FIELD.value)) {
String name = getFieldName(mf, f);
if (name == null) continue;
SwMap row = new SwMap();
row.put("f_id", f);
row.put("f_name", name);
list.add(row);
}
return SwListData.create(list, 0);
}

@Override
public R getTotal() {
return R.success(buildListData().getTotal());
}
}

static class RoleFuncListHandle extends DynPageListHandler {

public RoleFuncListHandle(long pageId, SwMap filter, PageDataset pageDataSet) {
super(pageId, filter, pageDataSet);
}

@Override
public SwListData buildListData() {
List<SwMap> list = new ArrayList<>();
long role_id = filter.readLong("role_id");
long mp_id = filter.readLong("mp_id");
if (role_id <= 0 || mp_id <= 0) return SwListData.create(list, 0);
Role role = RoleCache.getInstance().get(role_id);
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), mp_id);
if (item == null) return SwListData.create(list, 0);
Menu menu = MenuCache.getInstance().get(item.getMenu());
for (String f : menu.getRightSet(SwEnum.MenuRightType.FUNC.value)) {
if (PubUtil.isEmpty(f)) continue;
SwMap row = new SwMap();
row.put("f_id", f);
row.put("f_name", SwEnum.MenuFuncRight.instance.getName(f));
list.add(row);
}
return SwListData.create(list, 0);
}

@Override
public R getTotal() {
return R.success(buildListData().getTotal());
}
}

static class RoleDataListHandle extends DynPageListHandler {

public RoleDataListHandle(long pageId, SwMap filter, PageDataset pageDataSet) {
super(pageId, filter, pageDataSet);
}

@Override
public SwListData buildListData() {
List<SwMap> list = new ArrayList<>();
long role_id = filter.readLong("role_id");
long mp_id = filter.readLong("mp_id");
if (role_id <= 0 || mp_id <= 0) return SwListData.create(list, 0);
Role role = RoleCache.getInstance().get(role_id);
MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), mp_id);
if (item == null) return SwListData.create(list, 0);
Menu menu = MenuCache.getInstance().get(item.getMenu());
RoleRightContent rc = new RoleRightContent(role.getPrivilege());
Map<String, Object> data = rc.getDataRight(item.getId());

for (String f : menu.getRightSet(SwEnum.MenuRightType.DATA.value)) {
if (PubUtil.isEmpty(f)) continue;
SwMap row = new SwMap();
row.put("key", f);
row.put("key_text", DataRightDefineCache.getInstance().get(f).getName());
if (data.get(f) != null && PubUtil.isNotEmpty(data.get(f).toString())) {
row.put("value", data.get(f));
row.put("value_text", DataRightGroupCache.getInstance().get(data.get(f).toString()).getName());
}
list.add(row);
}
return SwListData.create(list, 0);
}

@Override
public R getTotal() {
return R.success(buildListData().getTotal());
}
}
}

+ 121
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRight.java Целия файл

@@ -0,0 +1,121 @@
package cc.smtweb.system.bpm.web.sys.user.role;

import cc.smtweb.framework.core.db.impl.BaseBean;

import java.util.*;

/**
* @Author: tanghp
* @Date: 2022-08-02 12:52
* @Desc:
*/
public class RoleRight extends BaseBean {
/**
* 主键
*/
public long getId() {
return getLong("id");
}

/**
* 主键
*/
public void setId(long id) {
put("id", id);
}


/**
* 菜单ID
*/
public long getMenuId() {
return getLong("menuId");
}

/**
* 菜单ID
*/
public void setMenuId(long menuId) {
put("menuId", menuId);
}

/**
* 菜单权限
*/
public int getMenu() {
return getInt("menu");
}

/**
* 菜单权限
*/
public void setMenu(int menu) {
put("menu", menu);
}

/**
* 功能权限
*/
public Set<String> getRightFunc() {
return (Set<String>) get("func");
}

/**
* 功能权限
*/
public void setFunc(Set<String> func) {
put("func", func);
}

/**
* [{"key": "权限定义id","value": "权限组id"}]
* 数据权限
*/
public List<Map<String, Object>> getRightData() {
return (List<Map<String, Object>>) get("data");
}

/**
* [{"key": "权限定义id","value": "权限组id"}]
* 数据权限
*/
public void setData(List<Map<String, Object>> data) {
put("data", data);
}

/**
* "0-无/1-读/2-写"
* 字段权限 {field1:0,field2:2}
*/
public Map<String, Integer> getRightField() {
return (Map<String, Integer>) get("field");
}

/**
* "0-无/1-读/2-写"
* 字段权限 {field1:0,field2:2}
*/
public void setField(Map<String, Integer> field) {
put("field", field);
}


public void setField(Set<String> as, Set<String> ws, Set<String> rs) {
Map<String, Integer> field = new HashMap<>();
if (ws == null) ws = new HashSet<>();
if (rs == null) rs = new HashSet<>();
as.removeAll(ws);
as.removeAll(rs);
rs.removeAll(ws);
ws.forEach(k -> {
field.put(k, 2);
});
rs.forEach(k -> {
field.put(k, 1);
});
as.forEach(k -> {
field.put(k, 0);
});
setField(field);
}
}

+ 83
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java Целия файл

@@ -0,0 +1,83 @@
package cc.smtweb.system.bpm.web.sys.user.role;

import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.util.JsonUtil;
import cc.smtweb.framework.core.util.PubUtil;

import java.util.*;

/**
* @Author: tanghp
* @Date: 2022-08-02 13:16
* @Desc: 菜单方案content字段处理类
*/
public class RoleRightContent {

private Map<Long, RoleRight> map = new HashMap<>();

public RoleRightContent(String content) {
List<RoleRight> tempList = JsonUtil.parseList(content, RoleRight.class);
if (PubUtil.isNotEmpty(content) && tempList == null) {
throw new BizException("角色权限转换失败!");
}
if (PubUtil.isEmpty(tempList)) return;
tempList.forEach(bean -> {
map.put(bean.getId(), bean);
});
}

public void saveItem(SwMap map) {
RoleRight right = new RoleRight();
}

// 保存节点
public void saveItem(RoleRight item) {
map.put(item.getId(), item);
}

// 删除节点
public void delItem(long id) {
map.remove(id);
}

// 转换成字符串
public String toContentStr() {
return JsonUtil.encodeString(new ArrayList<>(map.values()));
}


public RoleRight getRoleRight(Long key) {
return map.get(key);
}

public String getFuncRight(long key) {
RoleRight right = getRoleRight(key);
if (right == null) return "";
return PubUtil.getSqlInIds(right.getRightFunc());
}

public String getFieldRight(long key, int type) {
RoleRight right = getRoleRight(key);
if (right == null) return "";
Map<String, Integer> cache = right.getRightField();
if (cache == null || cache.size() == 0) return "";
Set<String> fields = new HashSet<>();
cache.forEach((k, v) -> {
if (v == type) fields.add(k);
});
return PubUtil.getSqlInIds(fields);
}

public Map<String, Object> getDataRight(long key) {
RoleRight right = getRoleRight(key);
if (right == null) return new HashMap<>();
List<Map<String, Object>> list = right.getRightData();
if (list == null || list.size() == 0) return new HashMap<>();
Map<String, Object> cache = new HashMap<>();
list.forEach(k -> {
cache.putAll(k);
});
return cache;
}
}

+ 9
- 7
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleService.java Целия файл

@@ -1,22 +1,24 @@
package cc.smtweb.system.bpm.web.sys.user.role;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;

/**
* Created by 1 at 2022-07-28 19:15:18
* 页面【[角色列表]的服务类
* Created by 1 at 2022-08-08 10:11:53
* 页面【[角色]的服务类
*/
@SwService
public class RoleService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
switch (type) {
case TYPE_SAVE:
return new RoleHandler.RoleSaveHandler();
case TYPE_LOAD:
return new RoleHandler.RoleLoadHandle();
}
return super.createHandler(type);
}



+ 22
- 0
smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/dataRightGroup/drgList.js Целия файл

@@ -0,0 +1,22 @@
/**
* Created by 1 at 2022-08-08 16:28:04
* 注册事件类【数据权限组】,参看event.defaultEvent.js
*/
window.$swEvent.setup("bpm.sys.user.dataRightGroup.drgList", {
setup(page) {
const {$params, $refs, $widgets, $model, $utils, $tabRouter, $api} = page || {};
const {$$message, $$http} = $utils || {};

const onEditItem = () => {
$model.drgItemList.data.list.rows = $model.drgCard.getFormVal("sdrg_content");
}
// 示例
const onBeforeSave = () => {
$model.drgCard.setFormVal("sdrg_content", $model.drgItemList.data.list.rows);
};
return {
onEditItem,
onBeforeSave,
}
}
});

+ 18
- 0
smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/role/roleRight.js Целия файл

@@ -0,0 +1,18 @@
/**
* Created by 1 at 2022-08-08 16:06:22
* 注册事件类【角色权限】,参看event.defaultEvent.js
*/
window.$swEvent.setup("bpm.sys.user.role.roleRight", {
setup(page) {
const {$params, $refs, $widgets, $model, $utils, $tabRouter, $api} = page || {};
const {$$message, $$http} = $utils || {};

// 示例
const onBeforeSave = () => {
$model.rightData.setFormVal("data", $model.roleDataList.data.list.rows);
};
return {
onBeforeSave,
}
}
});

+ 20
- 10
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java Целия файл

@@ -24,6 +24,7 @@ public interface SwEnum {
this.dataType = dataType;
this.notNull = 0;
}

public FieldTypeBean(Integer value, String name, String dataType, int notNull) {
super(value, name);
this.dataType = dataType;
@@ -34,13 +35,13 @@ public interface SwEnum {
class FieldType extends AbstractEnum<Integer, FieldTypeBean> {
public static FieldType instance = new FieldType();

public static FieldTypeBean ID = instance.addEnum(1, "主键", DataType.ID.value,1);
public static FieldTypeBean CODE = instance.addEnum(2, "编码字段", DataType.CODE.value,1);
public static FieldTypeBean NAME = instance.addEnum(3, "名称字段", DataType.NAME.value,1);
public static FieldTypeBean ID = instance.addEnum(1, "主键", DataType.ID.value, 1);
public static FieldTypeBean CODE = instance.addEnum(2, "编码字段", DataType.CODE.value, 1);
public static FieldTypeBean NAME = instance.addEnum(3, "名称字段", DataType.NAME.value, 1);
public static FieldTypeBean PARENT_ID = instance.addEnum(4, "父ID", DataType.ID.value);
public static FieldTypeBean LEVEL_CODE = instance.addEnum(5, "级次码", DataType.CODE.value);
public static FieldTypeBean LEVEL = instance.addEnum(6, "级次", DataType.SHORT.value);
// public static FieldTypeBean ORDER = instance.addEnum(6, "排序字段", "");
// public static FieldTypeBean ORDER = instance.addEnum(6, "排序字段", "");
public static FieldTypeBean CREATE_USER = instance.addEnum(7, "创建人", DataType.ID.value);
public static FieldTypeBean CREATE_TIME = instance.addEnum(8, "创建时间", DataType.DATETIME.value);
public static FieldTypeBean UPDATE_USER = instance.addEnum(9, "更新人", DataType.ID.value);
@@ -56,8 +57,9 @@ public interface SwEnum {
mapAll.put(value, bean);
return bean;
}

public FieldTypeBean addEnum(Integer value, String name, String dataType, int notNull) {
final FieldTypeBean bean = new FieldTypeBean(value, name, dataType,notNull);
final FieldTypeBean bean = new FieldTypeBean(value, name, dataType, notNull);
mapAll.put(value, bean);
return bean;
}
@@ -129,11 +131,11 @@ public interface SwEnum {
public static DataTypeBean INT = instance.addEnum("int", "整型", "int", 0, "int", "Int", Types.INTEGER, "0", EditorType.NUMBER.value);
public static DataTypeBean SHORT = instance.addEnum("short", "短整型", "smallint", 0, "int", "Int", Types.SMALLINT, "0", EditorType.NUMBER.value);
public static DataTypeBean BOOL = instance.addEnum("bool", "布尔型", "tinyint", 0, "boolean", "Bool", Types.TINYINT, "0", EditorType.SWITCH.value);
public static DataTypeBean CURRENCY = instance.addEnum("currency", "金额型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.NUMBER.value);
public static DataTypeBean DATE = instance.addEnum("date", "日期型", "bigint", 0, "long","Long", Types.BIGINT, "0", EditorType.DATE.value);
public static DataTypeBean CURRENCY = instance.addEnum("currency", "金额型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.NUMBER.value);
public static DataTypeBean DATE = instance.addEnum("date", "日期型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.DATE.value);
public static DataTypeBean TIME = instance.addEnum("time", "时间型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.TIME.value);
public static DataTypeBean DATETIME = instance.addEnum("datetime", "日期时间型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.DATETIME.value);
public static DataTypeBean POS = instance.addEnum("pos", "经纬度", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.NUMBER.value);
public static DataTypeBean DATETIME = instance.addEnum("datetime", "日期时间型", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.DATETIME.value);
public static DataTypeBean POS = instance.addEnum("pos", "经纬度", "bigint", 0, "long", "Long", Types.BIGINT, "0", EditorType.NUMBER.value);

@Override
protected DataTypeBean buildBean(String value, String name) {
@@ -154,7 +156,7 @@ public interface SwEnum {

//根据数据库查询的metadata适配类型
public static DataTypeBean getBySqlType(int sqlType, int precision, int scale) {
for (DataTypeBean bean: instance.mapAll.values()) {
for (DataTypeBean bean : instance.mapAll.values()) {
if (bean.type != sqlType) continue;
if (bean.dataLength == 0 || bean.dataLength == precision) return bean;
}
@@ -304,6 +306,14 @@ public interface SwEnum {
}
}

// 权限类型
class MenuRightType extends StrEnum {
public static MenuFuncRight instance = new MenuFuncRight();
public static StrEnumBean DATA = instance.addEnum("data", "数据权限");
public static StrEnumBean FUNC = instance.addEnum("func", "功能权限");
public static StrEnumBean FIELD = instance.addEnum("field", "字段权限");
}

class MenuType extends IntEnum {
public static MenuType instance = new MenuType();
public static IntEnumBean DESIGN = instance.addEnum(0, "设计器页面");


+ 7
- 4
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwMap.java Целия файл

@@ -3,10 +3,7 @@ package cc.smtweb.framework.core.common;
import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.framework.core.util.MapUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* 通用map对象,用于无具体类型的传值
@@ -75,6 +72,12 @@ public class SwMap extends HashMap<String, Object> {
return MapUtil.readStringList(this, name);
}

public Set<String> readStringSet(String name) {
List<String> list = readStringList(name);
if (list == null) return null;
return new HashSet<String>(list);
}

public int readInt(String name) {
return MapUtil.readInt(this, name);
}


+ 1
- 1
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java Целия файл

@@ -216,7 +216,7 @@ public class MapUtil {

public static List<String> readStringList(SwMap swMap, String name) {
Object value = swMap.get(name);
if (value != null) {
if (value != null && PubUtil.isNotEmpty(value.toString())) {
return Arrays.asList(value.toString().split(","));
}
return null;


Зареждане…
Отказ
Запис