|
@@ -3,51 +3,100 @@ package cc.smtweb.system.bpm.web.design.preview; |
|
|
import cc.smtweb.framework.core.annotation.SwParam; |
|
|
import cc.smtweb.framework.core.annotation.SwParam; |
|
|
import cc.smtweb.framework.core.annotation.SwService; |
|
|
import cc.smtweb.framework.core.annotation.SwService; |
|
|
import cc.smtweb.framework.core.common.R; |
|
|
import cc.smtweb.framework.core.common.R; |
|
|
import cc.smtweb.framework.core.exception.BizException; |
|
|
|
|
|
import cc.smtweb.framework.core.exception.SwException; |
|
|
|
|
|
|
|
|
import cc.smtweb.framework.core.common.SwEnum; |
|
|
import cc.smtweb.framework.core.db.DbEngine; |
|
|
import cc.smtweb.framework.core.db.DbEngine; |
|
|
|
|
|
import cc.smtweb.framework.core.db.vo.ModelCatalog; |
|
|
|
|
|
import cc.smtweb.framework.core.exception.BizException; |
|
|
import cc.smtweb.framework.core.session.UserSession; |
|
|
import cc.smtweb.framework.core.session.UserSession; |
|
|
import cc.smtweb.framework.core.util.CommUtil; |
|
|
import cc.smtweb.framework.core.util.CommUtil; |
|
|
import cc.smtweb.system.bpm.util.TreeDataUtil; |
|
|
import cc.smtweb.system.bpm.util.TreeDataUtil; |
|
|
|
|
|
import cc.smtweb.system.bpm.web.design.db.ModelCatalogCache; |
|
|
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; |
|
|
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; |
|
|
import cc.smtweb.system.bpm.web.design.form.ModelForm; |
|
|
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.ModelFormCache; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@SwService |
|
|
@SwService |
|
|
public class PreviewMenuTreeService { |
|
|
public class PreviewMenuTreeService { |
|
|
@SwParam |
|
|
|
|
|
private DbEngine dbEngine; |
|
|
|
|
|
|
|
|
|
|
|
public R treeAll(@SwParam("module") String module, UserSession us) { |
|
|
|
|
|
String prj_id = ModelProjectCache.getInstance().getIdByModule(module); |
|
|
|
|
|
List<ModelForm> listForm; |
|
|
|
|
|
if (StringUtils.isNotEmpty(prj_id)) { |
|
|
|
|
|
listForm = new ArrayList<>(ModelFormCache.getInstance().getFormsByPrj(Long.parseLong(prj_id))); |
|
|
|
|
|
} else { |
|
|
|
|
|
listForm = new ArrayList<>(ModelFormCache.getInstance().getAll()); |
|
|
|
|
|
} |
|
|
|
|
|
listForm.sort((o1, o2) -> CommUtil.chineseCompare(o1.getTitle(), o2.getTitle())); |
|
|
|
|
|
if (listForm.isEmpty()) throw new BizException("此项目无页面设计!"); |
|
|
|
|
|
|
|
|
|
|
|
List<MenuVO> list = new ArrayList<>(listForm.size()); |
|
|
|
|
|
for (ModelForm form: listForm) { |
|
|
|
|
|
MenuVO menu = new MenuVO(); |
|
|
|
|
|
menu.setId(form.getId()); |
|
|
|
|
|
menu.setName(form.getTitle()); |
|
|
|
|
|
menu.setPath("/bpm/" + form.getId()); |
|
|
|
|
|
// menu.setParentId(-1L); |
|
|
|
|
|
list.add(menu); |
|
|
|
|
|
|
|
|
@SwParam |
|
|
|
|
|
private DbEngine dbEngine; |
|
|
|
|
|
|
|
|
|
|
|
public R treeAll(@SwParam("module") String module, UserSession us) { |
|
|
|
|
|
String prj_id = ModelProjectCache.getInstance().getIdByModule(module); |
|
|
|
|
|
|
|
|
|
|
|
List<ModelForm> listForm; |
|
|
|
|
|
if (StringUtils.isNotEmpty(prj_id)) { |
|
|
|
|
|
listForm = new ArrayList<>(ModelFormCache.getInstance().getFormsByPrj(Long.parseLong(prj_id))); |
|
|
|
|
|
} else { |
|
|
|
|
|
listForm = new ArrayList<>(ModelFormCache.getInstance().getAll()); |
|
|
|
|
|
} |
|
|
|
|
|
listForm.sort((o1, o2) -> CommUtil.chineseCompare(o1.getTitle(), o2.getTitle())); |
|
|
|
|
|
if (listForm.isEmpty()) throw new BizException("此项目无页面设计!"); |
|
|
|
|
|
|
|
|
|
|
|
List<MenuVO> list = new ArrayList<>(); |
|
|
|
|
|
Map<Long, MenuVO> map = new HashMap<>(); |
|
|
|
|
|
for (ModelForm form : listForm) { |
|
|
|
|
|
if (SwEnum.FormType.PAGE.value != form.getType()) continue; |
|
|
|
|
|
List<Long> parentLog = ModelCatalogCache.getInstance().getAllParent(form.getMcId()); |
|
|
|
|
|
for (Long parent_id : parentLog) { |
|
|
|
|
|
if (map.containsKey(parent_id)) continue; |
|
|
|
|
|
ModelCatalog catalog = ModelCatalogCache.getInstance().get(parent_id); |
|
|
|
|
|
if (catalog == null || catalog.isEmpty()) continue; |
|
|
|
|
|
MenuVO menu = setMenuParent(parent_id, map, list); |
|
|
|
|
|
if (menu == null) continue; |
|
|
|
|
|
setMenuChildren(map.get(menu.getParentId()), menu); |
|
|
|
|
|
} |
|
|
|
|
|
MenuVO menu = new MenuVO(); |
|
|
|
|
|
menu.setId(form.getId()); |
|
|
|
|
|
menu.setName(form.getTitle()); |
|
|
|
|
|
menu.setPath("/bpm/" + form.getId()); |
|
|
|
|
|
menu.setParentId(form.getMcId()); |
|
|
|
|
|
|
|
|
|
|
|
setMenuChildren(map.get(form.getMcId()), menu); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MenuVO root = new MenuVO(); |
|
|
|
|
|
root.setName("项目"); |
|
|
|
|
|
root.setPath(module); |
|
|
|
|
|
root.setId(-1L); |
|
|
|
|
|
List<MenuVO> data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler()); |
|
|
|
|
|
|
|
|
|
|
|
return R.success(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
MenuVO root = new MenuVO(); |
|
|
|
|
|
root.setName("项目"); |
|
|
|
|
|
root.setPath(module); |
|
|
|
|
|
List<MenuVO> data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler()); |
|
|
|
|
|
|
|
|
private MenuVO setMenuParent(Long parent_id, Map<Long, MenuVO> map, List<MenuVO> list) { |
|
|
|
|
|
MenuVO parent = map.get(parent_id); |
|
|
|
|
|
if (parent != null) return parent; |
|
|
|
|
|
|
|
|
return R.success(data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ModelCatalog parentBean = ModelCatalogCache.getInstance().get(parent_id); |
|
|
|
|
|
if (parentBean == null) return null; |
|
|
|
|
|
parent = map.get(parentBean.getId()); |
|
|
|
|
|
if (parent != null) return parent; |
|
|
|
|
|
parent = new MenuVO(); |
|
|
|
|
|
parent.setId(parentBean.getId()); |
|
|
|
|
|
parent.setName(parentBean.getName()); |
|
|
|
|
|
parent.setPath(""); |
|
|
|
|
|
parent.setParentId(parentBean.getParentId()); |
|
|
|
|
|
if (parentBean.getParentId() == -1) { |
|
|
|
|
|
list.add(parent); |
|
|
|
|
|
} |
|
|
|
|
|
map.put(parentBean.getId(), parent); |
|
|
|
|
|
setMenuParent(parentBean.getParentId(), map, list); |
|
|
|
|
|
return parent; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setMenuChildren(MenuVO parent, MenuVO child) { |
|
|
|
|
|
if (parent == null) return; |
|
|
|
|
|
List<MenuVO> childs = parent.getChildren(); |
|
|
|
|
|
if (childs == null) { |
|
|
|
|
|
childs = new ArrayList<>(); |
|
|
|
|
|
parent.setChildren(childs); |
|
|
|
|
|
} |
|
|
|
|
|
childs.add(child); |
|
|
|
|
|
} |
|
|
} |
|
|
} |