@@ -10,25 +10,25 @@ import java.util.List; | |||
import java.util.Set; | |||
/** | |||
* Created by 1 at 2022-08-03 08:53:34 | |||
* Created by 1 at 2022-08-03 18:04:34 | |||
* 实体【[菜单定义](SYS_MENU)】的缓存类 | |||
*/ | |||
@SwCache(ident = "SYS_MENU", title = "菜单定义") | |||
public class MenuCache extends AbstractEntityCache<Menu> { | |||
//缓存key:按编码 | |||
public final static String mk_code = "code"; | |||
//缓存key:按目录 | |||
public final static String mk_m = "m"; | |||
public static MenuCache getInstance() { | |||
return CacheManager.getIntance().getCache(MenuCache.class); | |||
} | |||
public MenuCache() { | |||
//缓存key:按编码 | |||
regMap(mk_code, "sm_seq"); | |||
//缓存key:按目录 | |||
regList(mk_m, "sm_mc_id"); | |||
} | |||
//缓存key:按编码 | |||
public final Menu getByCode(String key) { | |||
return getByKey(mk_code, key); | |||
//缓存key:按目录 | |||
public final Set<Menu> getByM(String key) { | |||
return getListByKey(mk_m, key); | |||
} | |||
} |
@@ -3,16 +3,21 @@ package cc.smtweb.system.bpm.web.sys.user.menu; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import cc.smtweb.framework.core.db.vo.ModelCatalog; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.system.bpm.web.design.db.ModelCatalogTreeHelper; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageSaveHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageTreeHandler; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
/** | |||
* @Author: tanghp | |||
@@ -77,10 +82,59 @@ public class MenuHandler { | |||
} | |||
static class MenuTreeHandler extends DynPageTreeHandler { | |||
private ModelCatalogTreeHelper mcTreeHelper = new ModelCatalogTreeHelper(); | |||
public MenuTreeHandler(long pageId, SwMap filter, PageDataset pageDataSet) { | |||
super(pageId, filter, pageDataSet); | |||
} | |||
@Override | |||
protected List<SwMap> getChildren(long id) { | |||
List<SwMap> list = new ArrayList<>(); | |||
long prj_id = params.readFilter().readLong("project_id"); | |||
if (prj_id <= 0) return list; | |||
Menu menu = MenuCache.getInstance().get(id); | |||
if (menu != null) return list; | |||
return buildTreeData(prj_id, id); | |||
} | |||
private List<SwMap> buildTreeData(long prj_id, long id) { | |||
List<SwMap> list = new ArrayList<>(); | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(id, prj_id, false, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (PubUtil.isNotEmpty(mcList)) { | |||
for (ModelCatalog mc : mcList) { | |||
List<SwMap> children = buildTreeData(prj_id, mc.getId()); | |||
if (PubUtil.isEmpty(children)) continue; | |||
MenuNode menuNode = new MenuNode(); | |||
menuNode.setMenu(mc.getId()); | |||
menuNode.setLabel(mc.getName()); | |||
menuNode.setChildren(children); | |||
list.add(menuNode.getData()); | |||
} | |||
return list; | |||
} | |||
Set<Menu> menus = MenuCache.getInstance().getByM(String.valueOf(id)); | |||
if (PubUtil.isEmpty(menus)) return list; | |||
for (Menu m : menus) { | |||
MenuNode menuNode = new MenuNode(); | |||
menuNode.setMenu(m.getId()); | |||
menuNode.setLabel(m.getName()); | |||
menuNode.setIcon(m.getIcon()); | |||
menuNode.setSeq(m.getSeq()); | |||
list.add(menuNode.getData()); | |||
} | |||
return list; | |||
} | |||
@Override | |||
protected long getId(SwMap bean) { | |||
return bean.readLong("menu"); | |||
} | |||
@Override | |||
protected String getText(SwMap bean) { | |||
return bean.readString("label"); | |||
} | |||
} | |||
static class MenuListHandler extends DynPageListHandler { | |||
@@ -0,0 +1,79 @@ | |||
package cc.smtweb.system.bpm.web.sys.user.menu; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author: yaoq | |||
* @Date: 2022-08-02 12:52 | |||
* @Desc: | |||
*/ | |||
public class MenuNode extends DefaultEntity { | |||
/** | |||
* 菜单ID | |||
*/ | |||
public long getMenu() { | |||
return getLong("menu"); | |||
} | |||
/** | |||
* 菜单ID | |||
*/ | |||
public void setMenu(long menu) { | |||
put("menu", menu); | |||
} | |||
/** | |||
* 标题 | |||
*/ | |||
public String getLabel() { | |||
return getStr("label"); | |||
} | |||
/** | |||
* 标题 | |||
*/ | |||
public void setLabel(String label) { | |||
put("label", label); | |||
} | |||
/** | |||
* 图标 | |||
*/ | |||
public String getIcon() { | |||
return getStr("icon"); | |||
} | |||
/** | |||
* 图标 | |||
*/ | |||
public void setIcon(String icon) { | |||
put("icon", icon); | |||
} | |||
/** | |||
* 图标 | |||
*/ | |||
public int getSeq() { | |||
return getInt("seq"); | |||
} | |||
/** | |||
* 图标 | |||
*/ | |||
public void setSeq(int seq) { | |||
put("seq", seq); | |||
} | |||
public void setChildren(List<SwMap> children) { | |||
put("children", children); | |||
} | |||
public List<SwMap> getChildren() { | |||
Object obj = get("children"); | |||
return obj == null ? new ArrayList<>() : (List<SwMap>) obj; | |||
} | |||
} |
@@ -1,11 +1,15 @@ | |||
package cc.smtweb.system.bpm.web.sys.user.menu; | |||
import cc.smtweb.framework.core.annotation.SwBody; | |||
import cc.smtweb.framework.core.annotation.SwService; | |||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||
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; | |||
/** | |||
* Created by 1 at 2022-08-01 17:46:05 | |||
* Created by 1 at 2022-08-03 17:21:52 | |||
* 页面【[菜单]的服务类 | |||
*/ | |||
@SwService | |||
@@ -23,9 +23,6 @@ window.$swEvent.setup("bpm.sys.user.menu.menuList", { | |||
if (sm_type !== 0) { | |||
return url; | |||
} | |||
if (url.startsWith("/bpm")) { | |||
return url; | |||
} | |||
return "/bpm" + url; | |||
} | |||
@@ -39,6 +39,10 @@ public class SwMap extends HashMap<String, Object> { | |||
throw new SwException("不是合法的Map对象!" + v.getClass().getName()); | |||
} | |||
public SwMap readFilter() { | |||
return readMap("filter"); | |||
} | |||
public List<Map<String, Object>> readListMap(String name) { | |||
return MapUtil.readListMap(this, name); | |||
} | |||