@@ -3,6 +3,7 @@ package cc.smtweb.system.bpm.spring; | |||
import cc.smtweb.framework.core.annotation.SwService; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.common.SwConsts; | |||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||
import cc.smtweb.framework.core.db.impl.DatabaseUtil; | |||
import cc.smtweb.framework.core.systask.TaskStartEvent; | |||
import cc.smtweb.framework.core.systask.WebStartedEvent; | |||
@@ -326,7 +326,11 @@ public class ModelFormHelper { | |||
SwMap w = new SwMap(); | |||
widget.put("w" + id, w); | |||
SwMap widgetOpts = widgetForm.getOpts(); | |||
w.put("service", widgetForm.getService()); | |||
String service = widgetForm.getService(); | |||
if (StringUtils.isEmpty(service) && widgetForm.getParent() > 0) { | |||
service = ModelFormCache.getInstance().get(widgetForm.getParent()).getService(); | |||
} | |||
w.put("service", service); | |||
if (widgetOpts != null) w.putAll(widgetOpts); | |||
w.put("define", buildEngineModel(widgetForm, params, us, false)); | |||
} | |||
@@ -18,8 +18,10 @@ public abstract class AbstractDynPageHandler extends AbstractHandler { | |||
protected long pageId; | |||
protected PageDatasets datasets; | |||
protected DynPageProvider provider = new DynPageProvider(); | |||
protected DynPageProvider provider = getProvider(); | |||
public DynPageProvider getProvider() { | |||
return new DynPageProvider(); | |||
} | |||
@Override | |||
public void init(SwMap params, UserSession us) { | |||
super.init(params, us); | |||
@@ -36,6 +36,9 @@ public class DynPageHelper { | |||
* @return | |||
*/ | |||
public static SwMap createBean(PageDataset dataSet) { | |||
if(dataSet.masterTable<=0){ | |||
return new SwMap(); | |||
} | |||
//主表 | |||
ModelTable masterTable = ModelTableCache.getInstance().get(dataSet.masterTable); | |||
EntityDao<DefaultEntity> dao = DbEngine.getInstance().findDao(masterTable.getName()); | |||
@@ -22,7 +22,7 @@ import static cc.smtweb.framework.core.common.SwConsts.TOTAL_KEY; | |||
public class DynPageListHandler extends AbstractListHandler { | |||
protected long pageId; | |||
//过滤条件 | |||
private SwMap filter; | |||
protected SwMap filter; | |||
//对应的数据集定义 | |||
protected PageDataset pageDataSet; | |||
@@ -17,7 +17,6 @@ public class DynPageLoadHandler extends AbstractDynPageHandler { | |||
//对应的数据集定义 | |||
private PageDataset pageDataSet; | |||
//列表工具类 | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageListHandler listHandler = new DynPageListHandler(pageId, filter, pageDataSet); | |||
@@ -1,9 +1,27 @@ | |||
package cc.smtweb.system.bpm.web.sys.user.menu; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
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.DynPageTreeHandler; | |||
/** | |||
* @Author: tanghp | |||
* @Date: 2022-08-01 17:47 | |||
* @Desc: | |||
*/ | |||
public class MenuHandler { | |||
static class MenuLoadHandler extends DynPageLoadHandler { | |||
@Override | |||
public DynPageTreeHandler getTreeWorker(SwMap filter, PageDataset pageDataSet) { | |||
return new MenuTreeHandler(pageId,filter,pageDataSet); | |||
} | |||
} | |||
static class MenuTreeHandler extends DynPageTreeHandler{ | |||
public MenuTreeHandler(long pageId, SwMap filter, PageDataset pageDataSet) { | |||
super(pageId, filter, pageDataSet); | |||
} | |||
} | |||
} |
@@ -0,0 +1,125 @@ | |||
package cc.smtweb.system.bpm.web.sys.user.menuPlan; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author: tanghp | |||
* @Date: 2022-08-02 13:16 | |||
* @Desc: 菜单方案content字段处理类 | |||
*/ | |||
public class MenuPlanContent { | |||
private List<MenuPlanItem> list = new ArrayList<>(); | |||
public MenuPlanContent(String content){ | |||
List<MenuPlanItem> tempList = JsonUtil.parseList(content,MenuPlanItem.class); | |||
if(tempList!=null){ | |||
list = tempList; | |||
} | |||
} | |||
// 保存节点 | |||
public void saveItem(MenuPlanItem item,long parentId){ | |||
boolean isNew = item.getId() <=0; | |||
if(isNew){ | |||
item.setId(DbEngine.getInstance().nextId()); | |||
if(parentId<=0){ | |||
list.add(item); | |||
}else { | |||
MenuPlanItem parentItem = findById(parentId); | |||
if(parentItem==null){ | |||
throw new BizException("上级节点无效"); | |||
} | |||
parentItem.getChildren().add(item); | |||
} | |||
}else { | |||
MenuPlanItem oldItem = findById(item.getId()); | |||
if(oldItem==null){ | |||
throw new BizException("未找到修改对象"); | |||
} | |||
// 判断是否修改了父节点 | |||
MenuPlanItem oldParent = findParentById(item.getId()); | |||
MenuPlanItem newParent = findById(parentId); | |||
boolean changeParent = (oldParent ==null? -1 : oldParent.getId()) != parentId; | |||
if(changeParent){ | |||
// 改了父节点 父节点的children需要移除,新的父节点需要添加 | |||
removeById(item.getId(),oldParent==null ? list: oldParent.getChildren()); | |||
addItem(item,newParent == null ? list : newParent.getChildren()); | |||
}else { | |||
// 没有改变父节点 直接拷贝值 | |||
oldItem.setLabel(item.getLabel()); | |||
oldItem.setMenu(item.getMenu()); | |||
oldItem.setIcon(item.getIcon()); | |||
oldItem.setSeq(item.getSeq()); | |||
} | |||
} | |||
} | |||
// 转换成字符串 | |||
public String toContentStr(){ | |||
return JsonUtil.encodeString(list); | |||
} | |||
// 根据id找节点 | |||
public MenuPlanItem findById(long id){ | |||
if(id<=0){ | |||
return null; | |||
} | |||
return findById(id,list); | |||
} | |||
// 根据id找父节点 | |||
public MenuPlanItem findParentById(long id){ | |||
if(id<=0){ | |||
return null; | |||
} | |||
return findParentById(id,list); | |||
} | |||
// 获取子节点 | |||
public List<MenuPlanItem> getChildren(long parentId){ | |||
if(parentId<=0){ | |||
return list; | |||
} | |||
MenuPlanItem parent = findParentById(parentId); | |||
return parent == null ? new ArrayList<>(): parent.getChildren() ; | |||
} | |||
private MenuPlanItem findById(long id,List<MenuPlanItem> itemList){ | |||
for(MenuPlanItem item: itemList){ | |||
if(item.getId() == id){ | |||
return item; | |||
} | |||
if(item.getChildren().size()>0){ | |||
return findById(id,item.getChildren()); | |||
} | |||
} | |||
return null; | |||
} | |||
private MenuPlanItem findParentById(long id,List<MenuPlanItem> itemList){ | |||
for(MenuPlanItem item: itemList){ | |||
if(item.getChildren().size()>0){ | |||
List<MenuPlanItem> children = item.getChildren(); | |||
for(MenuPlanItem i : children){ | |||
if(i.getId() == id){ | |||
return item; | |||
} | |||
if(i.getChildren().size()>0){ | |||
return findParentById(id,i.getChildren()); | |||
} | |||
} | |||
} | |||
} | |||
return null; | |||
} | |||
private void removeById(long id, List<MenuPlanItem> itemList){ | |||
if(itemList == null || itemList.size()<=0){ | |||
return; | |||
} | |||
itemList.removeIf(item -> item.getId() == id); | |||
} | |||
private void addItem(MenuPlanItem item, List<MenuPlanItem> itemList){ | |||
if(itemList == null){ | |||
return; | |||
} | |||
itemList.add(item); | |||
} | |||
} |
@@ -1,9 +1,175 @@ | |||
package cc.smtweb.system.bpm.web.sys.user.menuPlan; | |||
import cc.smtweb.framework.core.common.R; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.jdbc.AbsDbWorker; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.mvc.service.AbstractHandler; | |||
import cc.smtweb.framework.core.mvc.service.SwListData; | |||
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.DynPageListHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageProvider; | |||
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageTreeHandler; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author: tanghp | |||
* @Date: 2022-08-01 18:10 | |||
* @Desc: | |||
*/ | |||
public class MenuPlanHandler { | |||
// 菜单列表数据集 | |||
private static String DS_MENU_LIST = "menuList"; | |||
private static String DS_MENU_CARD = "menuCard"; | |||
private static String DS_MENU_TREE = "menuTree"; | |||
static class MenuCustHandler extends AbstractHandler { | |||
// 保存方案明细 | |||
public R savePlanItem(){ | |||
// 方案ID | |||
long plan_id = params.readLong("plan_id"); | |||
if(plan_id<=0){ | |||
throw new BizException("所属方案不能为空!"); | |||
} | |||
MenuPlan menuPlan = MenuPlanCache.getInstance().get(plan_id); | |||
if(menuPlan==null){ | |||
throw new BizException("所属方案不能为空!"); | |||
} | |||
long parent_id = params.readLong("parent_id",-1L); | |||
MenuPlanItem menuPlanItem = JsonUtil.parse(params, MenuPlanItem.class); | |||
// 处理content大字段 | |||
MenuPlanContent menuPlanContent = new MenuPlanContent(menuPlan.getContent()); | |||
menuPlanContent.saveItem(menuPlanItem,parent_id); | |||
menuPlan.setContent(menuPlanContent.toContentStr()); | |||
DbEngine.getInstance().doTrans(new AbsDbWorker() { | |||
@Override | |||
public void work() { | |||
DbEngine.getInstance().updateEntity(menuPlan,"smp_content"); | |||
} | |||
@Override | |||
public void doAfterDbCommit() { | |||
MenuPlanCache.getInstance().put(menuPlan); | |||
} | |||
}); | |||
return R.success(menuPlanItem); | |||
} | |||
} | |||
static class MenuLoadHandler extends DynPageLoadHandler{ | |||
@Override | |||
public DynPageProvider getProvider() { | |||
return new MenuProvider(); | |||
} | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
if(DS_MENU_LIST.equals(pageDataSet.name)){ | |||
return new MenuListHandler(pageId,filter,pageDataSet); | |||
} | |||
DynPageListHandler listHandler = new DynPageListHandler(pageId, filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
@Override | |||
public DynPageTreeHandler getTreeWorker(SwMap filter, PageDataset pageDataSet) { | |||
menuTreeHandler treeHandler = new MenuPlanHandler.menuTreeHandler(pageId,filter,pageDataSet); | |||
treeHandler.init(params, us); | |||
return treeHandler; | |||
} | |||
} | |||
static class MenuListHandler extends DynPageListHandler { | |||
public MenuListHandler(long pageId, SwMap filter, PageDataset pageDataSet) { | |||
super(pageId, filter, pageDataSet); | |||
} | |||
@Override | |||
public SwListData buildListData() { | |||
List<MenuPlanItem> children = getChildren(); | |||
List<SwMap> list = new ArrayList<>(); | |||
int total = children.size(); | |||
for(MenuPlanItem bean: children){ | |||
list.add(bean.getData()); | |||
} | |||
return SwListData.create(list,total); | |||
} | |||
@Override | |||
public R getTotal() { | |||
SwMap r = new SwMap(); | |||
List<MenuPlanItem> children = getChildren(); | |||
r.put("total", children.size()); | |||
return R.success(r); | |||
} | |||
private List<MenuPlanItem> getChildren(){ | |||
long plan_id = filter.readLong("plan_id",-1L); | |||
long parent_id = filter.readLong("parent_id",-1L); | |||
if(plan_id<=0){ | |||
return new ArrayList<>(); | |||
} | |||
MenuPlan menuPlan = MenuPlanCache.getInstance().get(plan_id); | |||
if(menuPlan==null){ | |||
return new ArrayList<>(); | |||
} | |||
MenuPlanContent menuPlanContent = new MenuPlanContent(menuPlan.getContent()); | |||
return menuPlanContent.getChildren(parent_id); | |||
} | |||
} | |||
static class MenuProvider extends DynPageProvider{ | |||
@Override | |||
public SwMap loadData(SwMap filter, PageDataset pageDataSet) { | |||
if(DS_MENU_CARD.equals(pageDataSet.name)){ | |||
long id = filter.readLong("id",1L); | |||
long plan_id = filter.readLong("plan_id",1L); | |||
MenuPlan menuPlan = MenuPlanCache.getInstance().get(plan_id); | |||
if(menuPlan==null) { | |||
return new SwMap(); | |||
} | |||
MenuPlanContent menuPlanContent = new MenuPlanContent(menuPlan.getContent()); | |||
MenuPlanItem menuPlanItem = menuPlanContent.findById(id); | |||
if(menuPlanItem == null){ | |||
return new SwMap(); | |||
} | |||
SwMap r = new SwMap(); | |||
r.putAll(menuPlanItem.getData()); | |||
return r; | |||
} | |||
return super.loadData(filter, pageDataSet); | |||
} | |||
} | |||
static class menuTreeHandler extends DynPageTreeHandler{ | |||
private MenuPlanContent menuPlanContent; | |||
public menuTreeHandler(long pageId, SwMap filter, PageDataset pageDataSet) { | |||
super(pageId, filter, pageDataSet); | |||
long plan_id = filter.readLong("plan_id",-1L); | |||
if(plan_id<=0){ | |||
menuPlanContent = new MenuPlanContent(null); | |||
} | |||
MenuPlan menuPlan = MenuPlanCache.getInstance().get(plan_id); | |||
menuPlanContent = new MenuPlanContent(menuPlan == null ? null: menuPlan.getContent()); | |||
} | |||
@Override | |||
protected List<SwMap> getChildren(long id) { | |||
List<SwMap> list = new ArrayList<>(); | |||
List<MenuPlanItem> temList = menuPlanContent.getChildren(id); | |||
temList.forEach(bean-> list.add(bean.getData())); | |||
return list; | |||
} | |||
@Override | |||
protected long getId(SwMap bean) { | |||
return bean.readLong("id"); | |||
} | |||
@Override | |||
protected String getText(SwMap bean) { | |||
return bean.readString("label"); | |||
} | |||
} | |||
} |
@@ -0,0 +1,68 @@ | |||
package cc.smtweb.system.bpm.web.sys.user.menuPlan; | |||
import cc.smtweb.framework.core.db.impl.BaseBean; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @Author: tanghp | |||
* @Date: 2022-08-02 12:52 | |||
* @Desc: | |||
*/ | |||
public class MenuPlanItem extends BaseBean { | |||
/** 主键 */ | |||
public long getId() { | |||
return getLong("id"); | |||
} | |||
/** 主键 */ | |||
public void setId(long id) { | |||
put("id", id); | |||
} | |||
/** 菜单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<MenuPlanItem> children){ | |||
put("children",children); | |||
} | |||
public List<MenuPlanItem> getChildren(){ | |||
Object obj = get("children"); | |||
return obj==null ? new ArrayList<>() : (List<MenuPlanItem>) obj; | |||
} | |||
} |
@@ -14,17 +14,21 @@ import cc.smtweb.framework.core.session.UserSession; | |||
*/ | |||
@SwService | |||
public class MenuPlanService extends DynPageService { | |||
//public final static String TYPE_DEMO = "demo"; | |||
public final static String TYPE_CUST = "cust"; | |||
@Override | |||
protected AbstractHandler createHandler(String type) { | |||
switch (type){ | |||
case TYPE_CUST: | |||
return new MenuPlanHandler.MenuCustHandler(); | |||
case TYPE_LOAD: | |||
return new MenuPlanHandler.MenuLoadHandler(); | |||
} | |||
return super.createHandler(type); | |||
} | |||
/* demo | |||
//自定义 | |||
public R demo(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_DEMO, handler -> ((DemoHandler)handler).demo()); | |||
//保存方案明细 | |||
public R savePlanItem(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_CUST, handler -> ((MenuPlanHandler.MenuCustHandler)handler).savePlanItem()); | |||
} | |||
*/ | |||
} |
@@ -16,9 +16,17 @@ window.$swEvent.setup("bpm.sys.user.menuPlan.menuPlanList", { | |||
const afterDelMenuPlan = async () => { | |||
await $api.loadOne("planList"); | |||
} | |||
// 保存菜单项 | |||
const savePlanItem = async () => { | |||
const data = $model.menuCard.data.form; | |||
const rt = await $$http.post("bpm/menuPlan/savePlanItem",data); | |||
$model.menuCard.setFormVal("id",rt.data.id); | |||
$api.loadOne("menuList"); | |||
} | |||
return { | |||
saveMenuPlan, | |||
afterDelMenuPlan, | |||
savePlanItem, | |||
} | |||
} | |||
}); |