@@ -63,8 +63,8 @@ public class CodeBuildHandler extends AbstractHandler { | |||
public R buildJsCode() { | |||
userName = String.valueOf(us.getUserId()); | |||
//页面id | |||
long pageId = params.readLong("pageId"); | |||
ModelForm form = ModelFormCache.getInstance().get(pageId); | |||
String pageId = params.readString("pageId"); | |||
ModelForm form = ModelFormHelper.getFromCache(pageId); | |||
if (form == null) throw new BizException("未找到指定的页面定义(" + pageId + ")!"); | |||
String moduleName = ModelProjectCache.getInstance().getModule(form.getPrjId()); | |||
if (StringUtils.isEmpty(moduleName)) throw new BizException("此项目未定义Module!"); | |||
@@ -1,14 +1,11 @@ | |||
package cc.smtweb.system.bpm.web.design.form; | |||
import cc.smtweb.framework.core.annotation.SwCache; | |||
import cc.smtweb.framework.core.cache.AbstractCache; | |||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||
import cc.smtweb.framework.core.cache.CacheManager; | |||
import cc.smtweb.framework.core.common.SwConsts; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.EntityDao; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; | |||
import java.util.ArrayList; | |||
import java.util.Comparator; | |||
@@ -26,17 +23,18 @@ public class ModelFormCache extends AbstractEntityCache<ModelForm> { | |||
private final static String mt = "t"; | |||
private final static String ms = "s"; | |||
private final static String mn = "mn"; | |||
public static ModelFormCache getInstance() { | |||
return CacheManager.getIntance().getCache(ModelFormCache.class); | |||
} | |||
public ModelFormCache() { | |||
regMap(mk, k-> k.getName().toUpperCase()); | |||
regMap(mn, k-> ModelProjectCache.getInstance().getModule(k.getPrjId())+"-"+k.getName().toUpperCase()); | |||
regList(mp, k-> String.valueOf(k.getPrjId())); | |||
regList(mc, k-> String.valueOf(k.getMcId())); | |||
regList(ms, k-> String.valueOf(k.getParent())); | |||
regList(mt, k-> k.getMasterTableId() + SwConsts.SPLIT_CHAR + k.getType()); | |||
regMap(mk, k -> k.getName().toUpperCase()); | |||
regMap(mn, k -> ModelFormHelper.getPageName(k).toUpperCase()); | |||
regList(mp, k -> String.valueOf(k.getPrjId())); | |||
regList(mc, k -> String.valueOf(k.getMcId())); | |||
regList(ms, k -> String.valueOf(k.getParent())); | |||
regList(mt, k -> k.getMasterTableId() + SwConsts.SPLIT_CHAR + k.getType()); | |||
// regList(mf, k-> k.get); | |||
} | |||
@@ -91,19 +89,17 @@ public class ModelFormCache extends AbstractEntityCache<ModelForm> { | |||
public String getText(long id) { | |||
ModelForm form = get(id); | |||
return form != null ? form.getTitle() : String.valueOf(id); | |||
return form != null ? form.getTitle(): String.valueOf(id); | |||
} | |||
/** | |||
* 根据末模块名称和页面名称获取 页面模型 | |||
* | |||
* @param module | |||
* @param pageName | |||
* @return ModelForm | |||
*/ | |||
public ModelForm getByName(String module,String pageName){ | |||
if(PubUtil.isEmptyStr(module)||PubUtil.isEmptyStr(pageName)){ | |||
return null; | |||
} | |||
return getByKey(mn,module+"-"+pageName.toUpperCase()); | |||
public ModelForm getByPageName(String pageName) { | |||
return getByKey(mn, pageName.toUpperCase()); | |||
} | |||
} |
@@ -1,6 +1,5 @@ | |||
package cc.smtweb.system.bpm.web.design.form; | |||
import cc.smtweb.framework.core.cache.AbstractCache; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||
@@ -37,16 +36,27 @@ public class ModelFormHelper { | |||
//分组类别-view | |||
public static final String PAGE_TYPE_VIEW = "view"; | |||
/** | |||
* 获取页面的pageName,格式:module.name | |||
* @param form | |||
* @return | |||
*/ | |||
public static String getPageName(ModelForm form) { | |||
return ModelProjectCache.getInstance().getModule(form.getPrjId()) + "." + form.getName(); | |||
} | |||
/** | |||
* 从缓存获取Form对象 | |||
* | |||
* @param formId | |||
* @return | |||
*/ | |||
public static ModelForm getFromCache(long formId) { | |||
AbstractCache<ModelForm> cache = ModelFormCache.getInstance(); | |||
public static ModelForm getFromCache(String formId) { | |||
ModelFormCache cache = ModelFormCache.getInstance(); | |||
if (cache == null) return null; | |||
return cache.get(formId); | |||
ModelForm form = cache.get(formId); | |||
return form != null ? form: cache.getByPageName(formId); | |||
} | |||
/*public static PageDatasets parsePageDataset(long formId) { | |||
@@ -103,13 +113,13 @@ public class ModelFormHelper { | |||
//没有配置db,配置有误,不处理 | |||
if (StringUtils.isEmpty(db)) throw new BizException("model未配置数据集db,无法解析!"); | |||
PageDataset pds = datasets.findById(db); | |||
String key = isField ? "fields" : "filters"; | |||
String key = isField ? "fields": "filters"; | |||
List<Map<String, Object>> fields = (List<Map<String, Object>>) model.get(key); | |||
if (fields == null || fields.isEmpty()) return; | |||
for (Map<String, Object> field : fields) { | |||
String fn = (String) field.get("field"); | |||
if (StringUtils.isEmpty(fn)) throw new BizException("model[" + db + "]." + key + "未配置字段名field,无法解析!"); | |||
BaseDatasetField pdf = isField ? pds.findFieldByName(fn) : pds.findFilterByName(fn); | |||
BaseDatasetField pdf = isField ? pds.findFieldByName(fn): pds.findFilterByName(fn); | |||
if (pdf == null) throw new BizException("model[" + db + "]." + key + "未找到定义的数据集字段(" + fn + "),无法解析!"); | |||
if (CommUtil.isStrEquals(MapUtil.readString(field, "label"), pdf.label)) { | |||
@@ -204,13 +214,13 @@ public class ModelFormHelper { | |||
//处理model的fields和filters | |||
private static void buildReqModelFields(PageDataset dataSet, Map<String, Object> model, boolean isField) { | |||
String key = isField ? "fields" : "filters"; | |||
String key = isField ? "fields": "filters"; | |||
List<Map<String, Object>> fields = (List<Map<String, Object>>) model.get(key); | |||
if (fields == null || fields.isEmpty()) return; | |||
for (Map<String, Object> field : fields) { | |||
String fn = (String) field.get("field"); | |||
if (StringUtils.isEmpty(fn)) continue; | |||
BaseDatasetField pdf = isField ? dataSet.findFieldByName(fn) : dataSet.findFilterByName(fn); | |||
BaseDatasetField pdf = isField ? dataSet.findFieldByName(fn): dataSet.findFilterByName(fn); | |||
if (pdf == null) continue; | |||
if (!field.containsKey("label")) { | |||
field.put("label", pdf.label); | |||
@@ -313,21 +323,14 @@ public class ModelFormHelper { | |||
List widgetIds = (List) option.get("widgetRef"); | |||
for (Object v : widgetIds) { | |||
long id; | |||
if (v instanceof String) { | |||
id = Long.parseLong((String) v); | |||
} else if (v instanceof Integer) { | |||
id = (Integer) v; | |||
} else if (v instanceof Long) { | |||
id = (Long) v; | |||
} else throw new BizException("不能识别的控件Id:" + v); | |||
String id = v.toString(); | |||
ModelForm widgetForm = getFromCache(id); | |||
if (widgetForm == null) throw new BizException("没有找到指定的控件定义!id=" + id); | |||
SwMap w = new SwMap(); | |||
widget.put("w" + id, w); | |||
SwMap widgetOpts = widgetForm.getOpts(); | |||
String service = widgetForm.getService(); | |||
if (StringUtils.isEmpty(service) && widgetForm.getParent() > 0) { | |||
if (StringUtils.isEmpty(service) && widgetForm.getParent() > 0L) { | |||
service = ModelFormCache.getInstance().get(widgetForm.getParent()).getService(); | |||
} | |||
w.put("service", service); | |||
@@ -502,7 +505,7 @@ public class ModelFormHelper { | |||
Set<ModelForm> set = ModelFormCache.getInstance().getListByTable(tableId, SwEnum.FormType.WIDGET.value); | |||
if (set == null || set.isEmpty()) return 0L; | |||
ModelForm form = set.iterator().next(); | |||
return (form != null) ? form.getEntityId() : 0L; | |||
return (form != null) ? form.getEntityId(): 0L; | |||
} | |||
/*//js文件的路径 | |||
@@ -26,63 +26,48 @@ public class ModelFormLoadHandler extends DefaultLoadHandler<ModelForm> { | |||
super(ModelForm.ENTITY_NAME); | |||
} | |||
@Override | |||
protected ModelForm loadComp(long id) { | |||
ModelForm bean = super.loadComp(id); | |||
SwMap opts = bean.getOpts(); | |||
if (opts != null) { | |||
ModelFormHelper.buildOptsEx(bean, opts); | |||
bean.setOption(JsonUtil.encodeString(opts)); | |||
} | |||
//去掉content和dataset | |||
bean.getData().remove("mf_content"); | |||
bean.getData().remove("mf_dataset"); | |||
protected ModelForm localLoadForm() { | |||
String id = params.readString("id"); | |||
if (StringUtils.isEmpty(id)) id = params.readString("pageId"); | |||
if (StringUtils.isEmpty(id)) id = params.readString("pageName"); | |||
ModelForm bean = ModelFormHelper.getFromCache(id); | |||
if (bean == null) throw new BizException("没有找到指定的页面定义信息!id=" + id); | |||
return bean; | |||
} | |||
@Override | |||
public R load() { | |||
return R.success(localLoadForm()); | |||
} | |||
//页面设计-加载数据集定义 | |||
public R loadDataset() { | |||
long id = params.readLong("id"); | |||
ModelForm bean = super.loadComp(id); | |||
if (bean == null) throw new BizException("没有找到指定定义信息!id=" + id); | |||
ModelForm bean = localLoadForm(); | |||
return R.success(ModelFormHelper.buildReqDataset(bean.getDatasets())); | |||
} | |||
//页面设计 - 加载页面model定义 | |||
public R loadModel() { | |||
long id = params.readLong("id"); | |||
ModelForm bean = super.loadComp(id); | |||
if (bean == null) throw new BizException("没有找到指定定义信息!id=" + id); | |||
ModelForm bean = localLoadForm(); | |||
return R.success(ModelFormHelper.buildReqModel(bean)); | |||
} | |||
//页面引擎-获取页面模型 | |||
public R loadForm() { | |||
long id = params.readLong("id"); | |||
ModelForm bean = super.loadComp(id); | |||
if (bean == null) throw new BizException("没有找到指定定义信息!id=" + id); | |||
return R.success(ModelFormHelper.buildEngineModel(bean, params, us)); | |||
} | |||
// 页面引擎-获取页面模型 | |||
public R loadForm(String module, String pageName) { | |||
ModelForm bean = ModelFormCache.getInstance().getByName(module,pageName); | |||
if (bean == null) throw new BizException("没有找到指定定义信息!module=" + module+",pageName="+pageName); | |||
ModelForm bean = localLoadForm(); | |||
return R.success(ModelFormHelper.buildEngineModel(bean, params, us)); | |||
} | |||
//获取页面使用的控件的filter信息 | |||
public R loadWidgetFilter() { | |||
long id = params.readLong("id"); | |||
ModelForm bean = super.loadComp(id); | |||
if (bean == null) throw new BizException("没有找到指定控件定义!id=" + id); | |||
ModelForm bean = localLoadForm(); | |||
return R.success(ModelFormHelper.buildWidgetFilter(bean)); | |||
} | |||
//加载页面js方法 | |||
public R loadJsFuncs() { | |||
long pageId = params.readLong("pageId"); | |||
ModelForm form = ModelFormCache.getInstance().get(pageId); | |||
if (form == null) throw new BizException("未找到指定的页面定义(" + pageId + ")!"); | |||
ModelForm form = localLoadForm(); | |||
List<String> listRet = new ArrayList<>(); | |||
R r = R.success(listRet); | |||
@@ -90,7 +75,7 @@ public class ModelFormLoadHandler extends DefaultLoadHandler<ModelForm> { | |||
if (StringUtils.isEmpty(codeJavaPath)) { | |||
return r; | |||
} | |||
String path = ModelFormHelper.getCodePath(form) + "/src/main/resources/static/event/" + ModelFormHelper.getEventPath(form).replaceAll("\\.", "/") + "/" + form.getName() + ".js"; | |||
String path = ModelFormHelper.getCodePath(form) + "/src/main/resources/static/event/" + ModelFormHelper.getEventPath(form).replaceAll("\\.", "/") + "/" + form.getName() + ".js"; | |||
String js = FileUtil.readFileStr(path); | |||
if (StringUtils.isEmpty(js)) { | |||
return r; | |||
@@ -103,7 +88,7 @@ public class ModelFormLoadHandler extends DefaultLoadHandler<ModelForm> { | |||
index = js.indexOf("{", index); | |||
js = js.substring(index + 1, js.indexOf("}", index)).trim(); | |||
String[] fs = js.split(","); | |||
for (String s: fs) { | |||
for (String s : fs) { | |||
if (StringUtils.isNotBlank(s)) { | |||
listRet.add(s.trim()); | |||
} | |||
@@ -109,15 +109,7 @@ public class ModelFormService extends AbstractCompService { | |||
public R model(@SwBody SwMap params, UserSession us) { | |||
try { | |||
ModelFormLoadHandler handler = (ModelFormLoadHandler) getHandler(params, us, TYPE_LOAD); | |||
String page = params.readString("id",""); | |||
String [] array = page.split("\\."); | |||
String module = ""; | |||
String pageName = ""; | |||
if(array.length==2){ | |||
module = array[0]; | |||
pageName = array[1]; | |||
} | |||
return handler.loadForm(module,pageName); | |||
return handler.loadForm(); | |||
} catch (Exception e) { | |||
return R.error("操作失败!", e); | |||
} | |||
@@ -34,6 +34,10 @@ public class PageDataset { | |||
public boolean lazy; | |||
//是否可编辑 | |||
public boolean canEdit; | |||
//是否虚拟数据集 | |||
public boolean virtual; | |||
//关联大字段信息 | |||
public PageDatasetLinkClob linkClob; | |||
//select的字段 | |||
public List<PageDatasetField> fields; | |||
public List<PageDatasetFilter> filters; | |||
@@ -0,0 +1,16 @@ | |||
package cc.smtweb.system.bpm.web.design.form.define; | |||
/** | |||
* Created by Akmm at 2022-08-13 14:55 | |||
* 数据集关联到大字段的设置信息 | |||
*/ | |||
public class PageDatasetLinkClob { | |||
//关联的数据集 | |||
public String linkDs; | |||
//关联的字段 | |||
public String linkField; | |||
//字段内容格式,暂时只支持JSON | |||
public String linkType; | |||
//节点 | |||
public String node; | |||
} |
@@ -0,0 +1,23 @@ | |||
package cc.smtweb.system.bpm.web.design.form.model; | |||
import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||
/** | |||
* Created by Akmm at 2022-08-14 10:02 | |||
* 不同模型,在保存时候的个性处理 | |||
*/ | |||
public class ModelFactory { | |||
private static ModelFactory instance; | |||
// private static Map instance; | |||
static { | |||
instance = new ModelFactory(); | |||
} | |||
public static ModelFactory getInstance() { | |||
return instance; | |||
} | |||
public void saveForm(ModelForm form) { | |||
} | |||
} |
@@ -14,8 +14,9 @@ import cc.smtweb.system.bpm.web.design.form.define.PageDatasets; | |||
* Created by Akmm at 2022/4/21 17:53 | |||
*/ | |||
public abstract class AbstractDynPageHandler extends AbstractHandler { | |||
//页面定义id | |||
protected long pageId; | |||
//页面定义id或页面pageName | |||
protected String pageId; | |||
protected ModelForm form; | |||
protected PageDatasets datasets; | |||
protected DynPageProvider provider = getProvider(); | |||
@@ -25,13 +26,13 @@ public abstract class AbstractDynPageHandler extends AbstractHandler { | |||
@Override | |||
public void init(SwMap params, UserSession us) { | |||
super.init(params, us); | |||
pageId = params.readLong("pageId"); | |||
ModelForm form = ModelFormHelper.getFromCache(pageId); | |||
pageId = params.readString("pageId"); | |||
form = ModelFormHelper.getFromCache(pageId); | |||
if (form == null) throw new BizException("没有找到页面定义数据(" + pageId + ")!"); | |||
datasets = form.getDatasets(); | |||
if (datasets == null || datasets.list == null) throw new BizException("没有找到页面定义的数据集数据(" + pageId + ")!"); | |||
provider.pageId = pageId; | |||
provider.pageId = form.getId(); | |||
provider.datasets = datasets; | |||
} | |||
@@ -4,6 +4,8 @@ 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.mvc.service.SwListData; | |||
import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||
import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
/** | |||
@@ -19,14 +21,14 @@ public class DynPageLoadHandler extends AbstractDynPageHandler { | |||
private PageDataset pageDataSet; | |||
//列表工具类 | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageListHandler listHandler = new DynPageListHandler(pageId, filter, pageDataSet); | |||
DynPageListHandler listHandler = new DynPageListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
//树工具类 | |||
public DynPageTreeHandler getTreeWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageTreeHandler listHandler = new DynPageTreeHandler(pageId, filter, pageDataSet); | |||
DynPageTreeHandler listHandler = new DynPageTreeHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
@@ -20,7 +20,7 @@ import cc.smtweb.system.bpm.web.engine.dynPage.DynPageHelper; | |||
public class FlowProvider extends AbstractCompProvider { | |||
//获取FlowInstance | |||
public FlowInstance findFlowInstance(long pageId, long us) { | |||
public FlowInstance findFlowInstance(String pageId, long us) { | |||
return doGetData("p_" + pageId, () -> { | |||
ModelForm form = ModelFormHelper.getFromCache(pageId); | |||
if (form == null || form.getBillType() <= 0L) return null; | |||
@@ -31,7 +31,7 @@ public class ComboHandler { | |||
@Override | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageListHandler listHandler = new ComboHandler.FormListHandler(pageId, filter, pageDataSet); | |||
DynPageListHandler listHandler = new ComboHandler.FormListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
@@ -41,7 +41,7 @@ public class ComboHandler { | |||
@Override | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageListHandler listHandler = new ComboHandler.FieldListHandler(pageId, filter, pageDataSet); | |||
DynPageListHandler listHandler = new ComboHandler.FieldListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
@@ -51,7 +51,7 @@ public class ComboHandler { | |||
@Override | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageListHandler listHandler = new ComboHandler.EnumListHandler(pageId, filter, pageDataSet); | |||
DynPageListHandler listHandler = new ComboHandler.EnumListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
@@ -29,9 +29,9 @@ public class MenuHandler { | |||
static class MenuLoadHandler extends DynPageLoadHandler { | |||
@Override | |||
public DynPageTreeHandler getTreeWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageTreeHandler treeHandler = new MenuTreeHandler(pageId, filter, pageDataSet); | |||
DynPageTreeHandler treeHandler = new MenuTreeHandler(form.getId(), filter, pageDataSet); | |||
if (pageDataSet.name.equals("mcTree")) { | |||
treeHandler = new MenuCatalogTreeHandler(pageId, filter, pageDataSet); | |||
treeHandler = new MenuCatalogTreeHandler(form.getId(), filter, pageDataSet); | |||
} | |||
treeHandler.init(params, us); | |||
return treeHandler; | |||
@@ -39,7 +39,7 @@ public class MenuHandler { | |||
@Override | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
DynPageListHandler listHandler = new MenuListHandler(pageId, filter, pageDataSet); | |||
DynPageListHandler listHandler = new MenuListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
@@ -102,16 +102,16 @@ public class MenuPlanHandler { | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
if (DS_MENU_LIST.equals(pageDataSet.name)) { | |||
return new MenuListHandler(pageId, filter, pageDataSet); | |||
return new MenuListHandler(form.getId(), filter, pageDataSet); | |||
} | |||
DynPageListHandler listHandler = new DynPageListHandler(pageId, filter, pageDataSet); | |||
DynPageListHandler listHandler = new DynPageListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||
@Override | |||
public DynPageTreeHandler getTreeWorker(SwMap filter, PageDataset pageDataSet) { | |||
MenuTreeHandler treeHandler = new MenuPlanHandler.MenuTreeHandler(pageId, filter, pageDataSet); | |||
MenuTreeHandler treeHandler = new MenuPlanHandler.MenuTreeHandler(form.getId(), filter, pageDataSet); | |||
treeHandler.init(params, us); | |||
return treeHandler; | |||
} | |||
@@ -104,11 +104,11 @@ public class RoleHandler { | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
switch (pageDataSet.name) { | |||
case ROLE_FUNC: | |||
return new RoleFuncListHandle(pageId, filter, pageDataSet); | |||
return new RoleFuncListHandle(form.getId(), filter, pageDataSet); | |||
case ROLE_Field: | |||
return new RoleFieldListHandle(pageId, filter, pageDataSet); | |||
return new RoleFieldListHandle(form.getId(), filter, pageDataSet); | |||
case ROLE_DATA: | |||
return new RoleDataListHandle(pageId, filter, pageDataSet); | |||
return new RoleDataListHandle(form.getId(), filter, pageDataSet); | |||
} | |||
return super.getListWorker(filter, pageDataSet); | |||
} | |||
@@ -166,7 +166,7 @@ public class UserHandler { | |||
@Override | |||
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { | |||
UserListHandler listHandler = new UserListHandler(pageId, filter, pageDataSet); | |||
UserListHandler listHandler = new UserListHandler(form.getId(), filter, pageDataSet); | |||
listHandler.init(params, us); | |||
return listHandler; | |||
} | |||