@@ -3,6 +3,7 @@ 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 cc.smtweb.framework.core.util.PubUtil; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -32,9 +33,17 @@ public class MenuPlanContent { | |||
if(parentItem==null){ | |||
throw new BizException("上级节点无效"); | |||
} | |||
parentItem.getChildren().add(item); | |||
List<MenuPlanItem> children = parentItem.getChildren(); | |||
if(children == null){ | |||
children = new ArrayList<>(); | |||
parentItem.setChildren(children); | |||
} | |||
children.add(item); | |||
} | |||
}else { | |||
if(item.getId() == parentId) { | |||
throw new BizException("上级不允许选自己!"); | |||
} | |||
MenuPlanItem oldItem = findById(item.getId()); | |||
if(oldItem==null){ | |||
throw new BizException("未找到修改对象"); | |||
@@ -46,7 +55,16 @@ public class MenuPlanContent { | |||
if(changeParent){ | |||
// 改了父节点 父节点的children需要移除,新的父节点需要添加 | |||
removeById(item.getId(),oldParent==null ? list: oldParent.getChildren()); | |||
addItem(item,newParent == null ? list : newParent.getChildren()); | |||
if(newParent==null){ | |||
addItem(item, list); | |||
}else { | |||
List<MenuPlanItem> children = newParent.getChildren(); | |||
if(children==null){ | |||
children = new ArrayList<>(); | |||
newParent.setChildren(children); | |||
} | |||
addItem(item, children); | |||
} | |||
}else { | |||
// 没有改变父节点 直接拷贝值 | |||
oldItem.setLabel(item.getLabel()); | |||
@@ -57,6 +75,18 @@ public class MenuPlanContent { | |||
} | |||
} | |||
// 删除节点 | |||
public void delItem(long id){ | |||
MenuPlanItem parent = findParentById(id); | |||
if(parent==null){ | |||
removeById(id,list); | |||
}else { | |||
List<MenuPlanItem> children = parent.getChildren(); | |||
if(PubUtil.isNotEmpty(children)){ | |||
removeById(id,children); | |||
} | |||
} | |||
} | |||
// 转换成字符串 | |||
public String toContentStr(){ | |||
return JsonUtil.encodeString(list); | |||
@@ -80,29 +110,35 @@ public class MenuPlanContent { | |||
if(parentId<=0){ | |||
return list; | |||
} | |||
MenuPlanItem parent = findParentById(parentId); | |||
MenuPlanItem parent = findById(parentId); | |||
return parent == null ? new ArrayList<>(): parent.getChildren() ; | |||
} | |||
private MenuPlanItem findById(long id,List<MenuPlanItem> itemList){ | |||
if(PubUtil.isEmpty(itemList)){ | |||
return null; | |||
} | |||
for(MenuPlanItem item: itemList){ | |||
if(item.getId() == id){ | |||
return item; | |||
} | |||
if(item.getChildren().size()>0){ | |||
if(PubUtil.isNotEmpty(item.getChildren())){ | |||
return findById(id,item.getChildren()); | |||
} | |||
} | |||
return null; | |||
} | |||
private MenuPlanItem findParentById(long id,List<MenuPlanItem> itemList){ | |||
if(PubUtil.isEmpty(itemList)){ | |||
return null; | |||
} | |||
for(MenuPlanItem item: itemList){ | |||
if(item.getChildren().size()>0){ | |||
List<MenuPlanItem> children = item.getChildren(); | |||
List<MenuPlanItem> children = item.getChildren(); | |||
if(PubUtil.isNotEmpty(children)){ | |||
for(MenuPlanItem i : children){ | |||
if(i.getId() == id){ | |||
return item; | |||
} | |||
if(i.getChildren().size()>0){ | |||
if(PubUtil.isNotEmpty(i.getChildren())){ | |||
return findParentById(id,i.getChildren()); | |||
} | |||
} | |||
@@ -8,6 +8,7 @@ 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.framework.core.util.PubUtil; | |||
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; | |||
@@ -59,6 +60,36 @@ public class MenuPlanHandler { | |||
}); | |||
return R.success(menuPlanItem); | |||
} | |||
// 删除方案明细 | |||
public R delPlanItem(){ | |||
// 方案ID | |||
long plan_id = params.readLong("plan_id"); | |||
long id = params.readLong("id"); | |||
if(plan_id<=0 || id<=0){ | |||
throw new BizException("参数错误!"); | |||
} | |||
MenuPlan menuPlan = MenuPlanCache.getInstance().get(plan_id); | |||
if(menuPlan==null){ | |||
throw new BizException("参数错误!"); | |||
} | |||
// 处理content大字段 | |||
MenuPlanContent menuPlanContent = new MenuPlanContent(menuPlan.getContent()); | |||
menuPlanContent.delItem(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(); | |||
} | |||
} | |||
static class MenuLoadHandler extends DynPageLoadHandler{ | |||
@@ -78,10 +109,18 @@ public class MenuPlanHandler { | |||
@Override | |||
public DynPageTreeHandler getTreeWorker(SwMap filter, PageDataset pageDataSet) { | |||
menuTreeHandler treeHandler = new MenuPlanHandler.menuTreeHandler(pageId,filter,pageDataSet); | |||
MenuTreeHandler treeHandler = new MenuPlanHandler.MenuTreeHandler(pageId,filter,pageDataSet); | |||
treeHandler.init(params, us); | |||
return treeHandler; | |||
} | |||
@Override | |||
protected void afterAddBean(PageDataset dataset, SwMap bean) { | |||
super.afterAddBean(dataset, bean); | |||
if(DS_MENU_CARD.equals(dataset.name)){ | |||
bean.put("type",0); | |||
} | |||
} | |||
} | |||
static class MenuListHandler extends DynPageListHandler { | |||
public MenuListHandler(long pageId, SwMap filter, PageDataset pageDataSet) { | |||
@@ -90,11 +129,19 @@ public class MenuPlanHandler { | |||
@Override | |||
public SwListData buildListData() { | |||
long plan_id = filter.readLong("plan_id",-1L); | |||
List<MenuPlanItem> children = getChildren(); | |||
List<SwMap> list = new ArrayList<>(); | |||
int total = children.size(); | |||
for(MenuPlanItem bean: children){ | |||
list.add(bean.getData()); | |||
int total = 0; | |||
if(PubUtil.isNotEmpty(children)){ | |||
total= children.size(); | |||
for(MenuPlanItem bean: children){ | |||
SwMap map = bean.getData(); | |||
map.put("plan_id",plan_id); | |||
map.put("type",bean.getMenu()> 0 ? 1: 0); | |||
map.put("type_text",bean.getMenu()> 0 ? "菜单": "目录"); | |||
list.add(map); | |||
} | |||
} | |||
return SwListData.create(list,total); | |||
} | |||
@@ -136,14 +183,16 @@ public class MenuPlanHandler { | |||
} | |||
SwMap r = new SwMap(); | |||
r.putAll(menuPlanItem.getData()); | |||
r.put("plan_id",plan_id); | |||
r.put("type",menuPlanItem.getMenu()> 0 ? 1: 0); | |||
return r; | |||
} | |||
return super.loadData(filter, pageDataSet); | |||
} | |||
} | |||
static class menuTreeHandler extends DynPageTreeHandler{ | |||
static class MenuTreeHandler extends DynPageTreeHandler{ | |||
private MenuPlanContent menuPlanContent; | |||
public menuTreeHandler(long pageId, SwMap filter, PageDataset pageDataSet) { | |||
public MenuTreeHandler(long pageId, SwMap filter, PageDataset pageDataSet) { | |||
super(pageId, filter, pageDataSet); | |||
long plan_id = filter.readLong("plan_id",-1L); | |||
if(plan_id<=0){ | |||
@@ -155,9 +204,17 @@ public class MenuPlanHandler { | |||
@Override | |||
protected List<SwMap> getChildren(long id) { | |||
boolean exc_menu = params.readBool("exc_menu"); | |||
List<SwMap> list = new ArrayList<>(); | |||
List<MenuPlanItem> temList = menuPlanContent.getChildren(id); | |||
temList.forEach(bean-> list.add(bean.getData())); | |||
if(PubUtil.isNotEmpty(temList)){ | |||
temList.forEach(bean-> { | |||
if(exc_menu&&bean.getMenu()>0){ | |||
return; | |||
} | |||
list.add(bean.getData()); | |||
}); | |||
} | |||
return list; | |||
} | |||
@@ -49,12 +49,12 @@ public class MenuPlanItem extends BaseBean { | |||
put("icon", icon); | |||
} | |||
/** 图标 */ | |||
/** 排序码 */ | |||
public int getSeq() { | |||
return getInt("seq"); | |||
} | |||
/** 图标 */ | |||
/** 排序码 */ | |||
public void setSeq(int seq) { | |||
put("seq", seq); | |||
} | |||
@@ -63,6 +63,6 @@ public class MenuPlanItem extends BaseBean { | |||
} | |||
public List<MenuPlanItem> getChildren(){ | |||
Object obj = get("children"); | |||
return obj==null ? new ArrayList<>() : (List<MenuPlanItem>) obj; | |||
return obj==null ? null : (List<MenuPlanItem>) obj; | |||
} | |||
} |
@@ -30,5 +30,8 @@ public class MenuPlanService extends DynPageService { | |||
public R savePlanItem(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_CUST, handler -> ((MenuPlanHandler.MenuCustHandler)handler).savePlanItem()); | |||
} | |||
// 删除方案明细 | |||
public R delPlanItem(@SwBody SwMap params, UserSession us) { | |||
return pageHandler(params, us, TYPE_CUST, handler -> ((MenuPlanHandler.MenuCustHandler)handler).delPlanItem()); | |||
} | |||
} |
@@ -4,9 +4,8 @@ | |||
*/ | |||
window.$swEvent.setup("bpm.sys.user.menuPlan.menuPlanList", { | |||
setup(page){ | |||
const { $params,$refs, $widgets, $model, $utils, $tabRouter, $api } = page || {}; | |||
const { $$message, $$http } = $utils || {}; | |||
const { $refs, $model, $utils, $api } = page || {}; | |||
const { $$message, $$http, $$sys } = $utils || {}; | |||
// 保存方案 | |||
const saveMenuPlan =async () => { | |||
await $api.saveOne("planCard"); | |||
@@ -16,17 +15,44 @@ window.$swEvent.setup("bpm.sys.user.menuPlan.menuPlanList", { | |||
const afterDelMenuPlan = async () => { | |||
await $api.loadOne("planList"); | |||
} | |||
// 调用新增之前 校验是否选择了方案 | |||
const beforeAddPlanItem = () => { | |||
const row = $model.planList?.data?.selectedRow; | |||
if(!row || !row["smp_id"]){ | |||
$$sys.throwBizException("请选择菜单方案!",true); | |||
} | |||
}; | |||
// 保存菜单项 | |||
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"); | |||
const pass = await $api.checkSaveOne("menuCard"); | |||
if(pass){ | |||
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"); | |||
$refs.planTree?.refresh(); | |||
$$message.notify.success("保存成功!"); | |||
} | |||
} | |||
// 删除菜单项 | |||
const delPlanItem = async (params) => { | |||
const data = { | |||
id: params?.row?.id, | |||
plan_id: params?.row?.plan_id | |||
} | |||
$$message.confirm("确定要删除吗?",async () => { | |||
const rt = await $$http.post("bpm/menuPlan/delPlanItem",data); | |||
$refs.planTree?.refresh(); | |||
await $api.loadOne("menuList"); | |||
$$message.notify.success("删除成功!"); | |||
}); | |||
} | |||
return { | |||
saveMenuPlan, | |||
afterDelMenuPlan, | |||
beforeAddPlanItem, | |||
savePlanItem, | |||
delPlanItem, | |||
} | |||
} | |||
}); |