@@ -12,6 +12,7 @@ import cc.smtweb.framework.core.mvc.service.AbstractTreeHandler; | |||
import cc.smtweb.framework.core.mvc.service.TreeHelper; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.flow.ModelProc; | |||
import cc.smtweb.system.bpm.web.design.flow.ModelProcCache; | |||
import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||
@@ -102,7 +103,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity> | |||
@Override | |||
protected List<DefaultEntity> getChildren(long id) { | |||
List<ModelCatalog> list = mcTreeHelper.getChildren(id, prj_id,exc_depend, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName())); | |||
List<ModelCatalog> list = mcTreeHelper.getChildren(id, prj_id,exc_depend, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
List<DefaultEntity> listRet; | |||
if (type != TYPE_CATALOG && exc_empty) {//排除空目录 | |||
listRet = cleanEmpty(list); | |||
@@ -166,7 +167,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity> | |||
//增加表 | |||
private void addTableChildren(List<DefaultEntity> listRet, long mcid) { | |||
Collection<ModelTable> set = ModelTableCache.getInstance().getTablesByMc(mcid, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName())); | |||
Collection<ModelTable> set = ModelTableCache.getInstance().getTablesByMc(mcid, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (set == null || set.isEmpty()) return; | |||
listRet.addAll(set); | |||
@@ -174,7 +175,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity> | |||
//增加工作流 | |||
private void addProcChildren(List<DefaultEntity> listRet, long mcid) { | |||
Collection<ModelProc> set = ModelProcCache.getInstance().getProcByMc(mcid, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName())); | |||
Collection<ModelProc> set = ModelProcCache.getInstance().getProcByMc(mcid, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (set == null || set.isEmpty()) return; | |||
listRet.addAll(set); | |||
@@ -197,7 +198,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler<DefaultEntity> | |||
private void addPageChildren(List<DefaultEntity> listRet, long mcid, int type) { | |||
List<ModelForm> set = ModelFormCache.getInstance().getFormsByMc(mcid, (o1, o2) -> { | |||
if (o1.getType() != o2.getType()) return o1.getType() - o2.getType(); | |||
return CommUtil.chineseCompare(o1.getTitle(), o2.getTitle()); | |||
return StringUtil.chineseCompare(o1.getTitle(), o2.getTitle()); | |||
}); | |||
if (set == null || set.isEmpty()) return; | |||
switch (type) { | |||
@@ -8,10 +8,7 @@ import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.mvc.variable.SwVariableFactory; | |||
import cc.smtweb.framework.core.session.UserSession; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.MapUtil; | |||
import cc.smtweb.framework.core.util.SpringUtil; | |||
import cc.smtweb.framework.core.util.*; | |||
import cc.smtweb.system.bpm.spring.BpmConfigBean; | |||
import cc.smtweb.system.bpm.util.CodeGenerator; | |||
import cc.smtweb.system.bpm.util.IdeaUtil; | |||
@@ -35,6 +32,12 @@ public class ModelFormHelper { | |||
public static final String PAGE_TYPE_CARD = "card"; | |||
//分组类别-view | |||
public static final String PAGE_TYPE_VIEW = "view"; | |||
//opts里面的配置关键字 | |||
public static final String OPT_CONFIG = "config"; | |||
public static final String OPT_MODEL = "model"; | |||
public static final String OPT_PAGE_TYPE = "pageType"; | |||
public static final String OPT_PAGE = "page"; | |||
/** | |||
@@ -46,6 +49,15 @@ public class ModelFormHelper { | |||
return ModelProjectCache.getInstance().getModule(form.getPrjId()) + "." + form.getName(); | |||
} | |||
//获取form的模型 | |||
public static String getFormModel(ModelForm form) { | |||
SwMap opts = form.getOpts(); | |||
if (opts == null) return null; | |||
SwMap config = opts.readMap(OPT_CONFIG); | |||
if (config == null) return null; | |||
return config.readString(OPT_MODEL); | |||
} | |||
/** | |||
* 从缓存获取Form对象 | |||
* | |||
@@ -122,7 +134,7 @@ public class ModelFormHelper { | |||
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)) { | |||
if (StringUtil.isStrEquals(MapUtil.readString(field, "label"), pdf.label)) { | |||
field.remove("label"); | |||
} | |||
@@ -171,10 +183,10 @@ public class ModelFormHelper { | |||
ModelField tf = table.findFieldByName(field.field); | |||
if (tf == null) continue; | |||
field.table_text = null; | |||
if (CommUtil.isStrEquals(tf.getTitle(), field.label)) field.label = null; | |||
if (CommUtil.isStrEquals(tf.getDataType(), field.dataType)) field.dataType = null; | |||
if (CommUtil.isStrEquals(tf.getRemark(), field.remark)) field.remark = null; | |||
if (CommUtil.isStrEquals(tf.getEditor(), field.editor)) field.editor = null; | |||
if (StringUtil.isStrEquals(tf.getTitle(), field.label)) field.label = null; | |||
if (StringUtil.isStrEquals(tf.getDataType(), field.dataType)) field.dataType = null; | |||
if (StringUtil.isStrEquals(tf.getRemark(), field.remark)) field.remark = null; | |||
if (StringUtil.isStrEquals(tf.getEditor(), field.editor)) field.editor = null; | |||
} | |||
} | |||
@@ -362,7 +374,7 @@ public class ModelFormHelper { | |||
} | |||
} | |||
} | |||
listRet.sort((o1, o2) -> CommUtil.chineseCompare(o1.readString("label"), o2.readString("label"))); | |||
listRet.sort((o1, o2) -> StringUtil.chineseCompare(o1.readString("label"), o2.readString("label"))); | |||
return listRet; | |||
} | |||
@@ -13,6 +13,7 @@ import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.mvc.service.DefaultSaveHandler; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.system.bpm.web.design.form.model.ModelFactory; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.ArrayList; | |||
@@ -25,7 +26,7 @@ import java.util.Set; | |||
*/ | |||
public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> { | |||
//自动生成的模块子页面,暂存,便于维护缓存 | |||
private List<ModelForm> listFormChild; | |||
private List<ModelForm> listFormChild = null; | |||
public ModelFormSaveHandler() { | |||
super(ModelForm.ENTITY_NAME); | |||
@@ -33,65 +34,19 @@ public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> { | |||
@Override | |||
protected void updateBean(EntityDao<ModelForm> dao) { | |||
updateFormChild(dao); | |||
listFormChild = new ArrayList<>(); | |||
ModelFactory.getInstance().saveForm(bean, listFormChild); | |||
dao.updateEntityEx(bean, "mf_content", "mf_dataset", "mf_tmpl"); | |||
} | |||
@Override | |||
protected void insertBean(EntityDao<ModelForm> dao) { | |||
super.insertBean(dao); | |||
updateFormChild(dao); | |||
} | |||
private void updateFormChild(EntityDao<ModelForm> dao) { | |||
SwMap opts = bean.getOpts(); | |||
if (opts != null) { | |||
opts.remove(ModelFormHelper.KEY_EVENT_PATH); | |||
bean.setOption(JsonUtil.encodeString(opts)); | |||
} | |||
if (bean.getType() == SwEnum.FormType.MODULE.value) { | |||
addChildPage(dao, opts); | |||
} | |||
} | |||
//自动增加子页面 | |||
private void addChildPage(EntityDao<ModelForm> dao, SwMap opts) { | |||
listFormChild = new ArrayList<>(); | |||
Set<ModelForm> setExists = ModelFormCache.getInstance().getListByModule(bean.getEntityId()); | |||
//维护已有的子页面 | |||
if(setExists!=null){ | |||
for (ModelForm mf: setExists) { | |||
if (!CommUtil.isStrEquals(mf.getService(), bean.getService())) { | |||
mf.setService(bean.getService()); | |||
dao.updateEntityEx(bean, "mf_content", "mf_dataset", "mf_tmpl"); | |||
listFormChild.add(mf); | |||
} | |||
} | |||
} | |||
if (opts == null) return; | |||
List<String> incPage = (List<String>) opts.get("incPage"); | |||
if (incPage == null || incPage.isEmpty()) return; | |||
//增加新的子页面 | |||
for (String type : incPage) { | |||
String name = bean.getName() + "_" + type; | |||
if (existsPage(setExists, name)) continue; | |||
ModelForm page = new ModelForm(); | |||
page.getData().putAll(bean.getData()); | |||
page.setId(DbEngine.getInstance().nextId()); | |||
page.setOption("{}"); | |||
page.setDataset(null); | |||
page.setContent(null); | |||
page.setTmpl(null); | |||
page.setType(SwEnum.FormType.PAGE.value); | |||
page.setName(name); | |||
page.setParent(bean.getId()); | |||
page.setTitle(bean.getTitle() + "_" + SwEnum.PageType.instance.getName(type)); | |||
listFormChild.add(page); | |||
dao.insertEntity(page); | |||
} | |||
ModelFactory.getInstance().saveForm(bean, listFormChild); | |||
} | |||
@Override | |||
protected void saveSuccess() { | |||
ModelFormCache.getInstance().put(bean); | |||
@@ -112,17 +67,6 @@ public class ModelFormSaveHandler extends DefaultSaveHandler<ModelForm> { | |||
} | |||
} | |||
//已经存在的,不管了 | |||
private boolean existsPage(Set<ModelForm> setExists, String name) { | |||
if (setExists == null){ | |||
return false; | |||
} | |||
for (ModelForm form : setExists) { | |||
if (name.equalsIgnoreCase(form.getName())) return true; | |||
} | |||
return false; | |||
} | |||
public R saveDataset() { | |||
long id = params.readLong("id"); | |||
String data = params.readString("data"); | |||
@@ -0,0 +1,65 @@ | |||
package cc.smtweb.system.bpm.web.design.form.model; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
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.ModelFormHelper; | |||
import java.util.List; | |||
import java.util.Set; | |||
/** | |||
* Created by Akmm at 2022-08-14 10:37 | |||
* 抽象类的页面保存,供各模板继承使用 | |||
*/ | |||
public class BaseModelWorker { | |||
public void saveForm(ModelForm bean, List<ModelForm> listFormChild) { | |||
SwMap opts = bean.getOpts(); | |||
if (opts != null) { | |||
opts.remove(ModelFormHelper.KEY_EVENT_PATH); | |||
bean.setOption(JsonUtil.encodeString(opts)); | |||
} | |||
if (bean.getType() == SwEnum.FormType.MODULE.value) { | |||
saveModule(bean, listFormChild); | |||
} else { | |||
savePage(bean); | |||
} | |||
} | |||
//保存模块 | |||
protected void saveModule(ModelForm bean, List<ModelForm> listFormChild) { | |||
} | |||
//保存页面 | |||
protected void savePage(ModelForm bean) { | |||
} | |||
//构建一个子页面 | |||
protected ModelForm createPage(ModelForm bean, String type) { | |||
ModelForm page = new ModelForm(); | |||
page.getData().putAll(bean.getData()); | |||
page.setId(DbEngine.getInstance().nextId()); | |||
page.setName(bean.getName() + StringUtil.upFirst(type)); | |||
page.setDataset(null); | |||
page.setContent(null); | |||
page.setTmpl(null); | |||
page.setType(SwEnum.FormType.PAGE.value); | |||
page.setParent(bean.getId()); | |||
page.setTitle(bean.getTitle() + SwEnum.PageType.instance.getName(type)); | |||
SwMap opts = new SwMap(); | |||
opts.putAll(bean.getOpts()); | |||
opts.put("pageType", type); | |||
page.setOption(JsonUtil.encodeString(opts)); | |||
return page; | |||
} | |||
} |
@@ -0,0 +1,51 @@ | |||
package cc.smtweb.system.bpm.web.design.form.model; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.common.SwMap; | |||
import cc.smtweb.framework.core.db.DbEngine; | |||
import cc.smtweb.framework.core.db.EntityDao; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
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.ModelFormHelper; | |||
import java.util.List; | |||
import java.util.Set; | |||
/** | |||
* Created by Akmm at 2022-08-14 12:17 | |||
*/ | |||
public class LcSinlgeWorker extends BaseModelWorker { | |||
@Override | |||
protected void saveModule(ModelForm bean, List<ModelForm> listFormChild) { | |||
EntityDao<ModelForm> dao = DbEngine.getInstance().findDao(ModelForm.class); | |||
SwMap opts = bean.getOpts(); | |||
SwMap cfg = opts.readMap(ModelFormHelper.OPT_CONFIG); | |||
SwMap cfgPage = new SwMap(); | |||
cfg.put(ModelFormHelper.OPT_PAGE, cfgPage); | |||
String formName = ModelFormHelper.getPageName(bean) + StringUtil.upFirst(SwEnum.PageType.LIST.value); | |||
cfg.put(SwEnum.PageType.LIST.value, formName); | |||
ModelForm page; | |||
if (bean.isNew()) {//新增 | |||
page = createPage(bean, SwEnum.PageType.LIST.value); | |||
listFormChild.add(page); | |||
dao.insertEntity(page); | |||
} else {//修改,先不考虑修改模型的情况 todo | |||
page = ModelFormHelper.getFromCache(formName); | |||
boolean modified = false; | |||
//服务名发生变化 | |||
if (!StringUtil.isStrEquals(page.getService(), bean.getService())) { | |||
page.setService(bean.getService()); | |||
modified = true; | |||
} | |||
if (modified) { | |||
dao.updateEntityEx(bean, "mf_content", "mf_dataset", "mf_tmpl"); | |||
listFormChild.add(page); | |||
} | |||
} | |||
} | |||
} |
@@ -1,6 +1,14 @@ | |||
package cc.smtweb.system.bpm.web.design.form.model; | |||
import cc.smtweb.framework.core.common.SwConsts; | |||
import cc.smtweb.framework.core.common.SwEnum; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.exception.SwException; | |||
import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||
import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.*; | |||
/** | |||
* Created by Akmm at 2022-08-14 10:02 | |||
@@ -8,16 +16,29 @@ import cc.smtweb.system.bpm.web.design.form.ModelForm; | |||
*/ | |||
public class ModelFactory { | |||
private static ModelFactory instance; | |||
// private static Map instance; | |||
private static Map<String, BaseModelWorker> mapWorker; | |||
static { | |||
instance = new ModelFactory(); | |||
mapWorker = new HashMap<>(); | |||
mapWorker.put(SwConsts.DEF_ROOT_ID, new BaseModelWorker()); | |||
mapWorker.put(SwEnum.ModelType.LC_SINGLE.value, new LcSinlgeWorker()); | |||
} | |||
public static ModelFactory getInstance() { | |||
return instance; | |||
} | |||
public void saveForm(ModelForm form) { | |||
private BaseModelWorker getWorker(ModelForm bean) { | |||
String model = ModelFormHelper.getFormModel(bean); | |||
if (StringUtils.isEmpty(model)) return mapWorker.get(SwConsts.DEF_ROOT_ID); | |||
BaseModelWorker worker = mapWorker.get(model); | |||
if (worker == null) throw new SwException("该模型暂无接口实现!"); | |||
return worker; | |||
} | |||
//各模型的个性化保存实现 | |||
public void saveForm(ModelForm bean, List<ModelForm> listFormChild) { | |||
BaseModelWorker worker = getWorker(bean); | |||
worker.saveForm(bean, listFormChild); | |||
} | |||
} |
@@ -8,8 +8,8 @@ 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.util.CommUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
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; | |||
@@ -41,7 +41,7 @@ public class PreviewMenuTreeService { | |||
} else { | |||
listForm = new ArrayList<>(ModelFormCache.getInstance().getAll()); | |||
} | |||
listForm.sort((o1, o2) -> CommUtil.chineseCompare(o1.getTitle(), o2.getTitle())); | |||
listForm.sort((o1, o2) -> StringUtil.chineseCompare(o1.getTitle(), o2.getTitle())); | |||
if (listForm.isEmpty()) throw new BizException("此项目无页面设计!"); | |||
List<MenuVO> list = new ArrayList<>(); | |||
@@ -15,7 +15,7 @@ import cc.smtweb.framework.core.db.vo.ModelIndex; | |||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.exception.BizException; | |||
import cc.smtweb.framework.core.mvc.service.TreeHelper; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDatasetFilter; | |||
import org.apache.commons.lang3.StringUtils; | |||
@@ -187,7 +187,7 @@ public class DynPageSaveHandler extends AbstractDynPageHandler { | |||
//长度校验 | |||
if (StringUtils.isNotEmpty(value)) { | |||
int len = SwEnum.DataType.instance.getByValue(field.getDataType()).dataLength; | |||
if (len > 0 && CommUtil.getStrLenB(value) > len) { | |||
if (len > 0 && StringUtil.getStrLenB(value) > len) { | |||
throw new BizException("字段值超长:" + field.getTitle()); | |||
} | |||
} | |||
@@ -5,9 +5,9 @@ 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.db.vo.ModelProject; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.JsonUtil; | |||
import cc.smtweb.framework.core.util.PubUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import cc.smtweb.system.bpm.web.design.db.ModelCatalogTreeHelper; | |||
import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; | |||
import cc.smtweb.system.bpm.web.design.form.define.PageDataset; | |||
@@ -116,7 +116,7 @@ public class MenuHandler { | |||
} | |||
ModelProject mp = ModelProjectCache.getInstance().get(id); | |||
if (mp != null) { | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(0, mp.getId(), true, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName())); | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(0, mp.getId(), true, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (PubUtil.isEmpty(mcList)) return; | |||
for (ModelCatalog mc : mcList) { | |||
SwMap row = new SwMap(); | |||
@@ -130,7 +130,7 @@ public class MenuHandler { | |||
} | |||
return; | |||
} | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(id, (o1, o2) -> CommUtil.chineseCompare(o1.getName(), o2.getName())); | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(id, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (PubUtil.isEmpty(mcList)) return; | |||
for (ModelCatalog mc : mcList) { | |||
SwMap row = new SwMap(); | |||
@@ -174,7 +174,7 @@ public class MenuHandler { | |||
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())); | |||
List<ModelCatalog> mcList = mcTreeHelper.getChildren(id, prj_id, false, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); | |||
if (PubUtil.isNotEmpty(mcList)) { | |||
for (ModelCatalog mc : mcList) { | |||
List<SwMap> children = buildTreeData(prj_id, mc.getId()); | |||
@@ -239,9 +239,9 @@ public interface SwEnum { | |||
*/ | |||
class PageType extends StrEnum { | |||
public static PageType instance = new PageType(); | |||
public static StrEnumBean PAGE = instance.addEnum("list", "列表"); | |||
public static StrEnumBean WIDGET = instance.addEnum("card", "编辑"); | |||
public static StrEnumBean MODULE = instance.addEnum("view", "详情"); | |||
public static StrEnumBean LIST = instance.addEnum("list", "列表"); | |||
public static StrEnumBean CARD = instance.addEnum("card", "编辑"); | |||
public static StrEnumBean VIEW = instance.addEnum("view", "详情"); | |||
} | |||
/** | |||
@@ -4,6 +4,7 @@ import cc.smtweb.framework.core.exception.SwException; | |||
import cc.smtweb.framework.core.util.MapUtil; | |||
import java.util.*; | |||
import java.util.function.Function; | |||
/** | |||
* 通用map对象,用于无具体类型的传值 | |||
@@ -36,6 +37,11 @@ public class SwMap extends HashMap<String, Object> { | |||
throw new SwException("不是合法的Map对象!" + v.getClass().getName()); | |||
} | |||
public SwMap computeMapIfAbsent(String key, Function<? super String, ?> mappingFunction) { | |||
super.computeIfAbsent(key, mappingFunction); | |||
return readMap(key); | |||
} | |||
public SwMap readFilter() { | |||
return readMap("filter"); | |||
} | |||
@@ -11,9 +11,9 @@ import cc.smtweb.framework.core.db.cache.ModelTableCache; | |||
import cc.smtweb.framework.core.db.vo.ModelField; | |||
import cc.smtweb.framework.core.db.vo.ModelLinkName; | |||
import cc.smtweb.framework.core.db.vo.ModelTable; | |||
import cc.smtweb.framework.core.util.CommUtil; | |||
import cc.smtweb.framework.core.util.DateUtil; | |||
import cc.smtweb.framework.core.util.NumberUtil; | |||
import cc.smtweb.framework.core.util.StringUtil; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.util.*; | |||
@@ -27,7 +27,7 @@ public class EntityHelper { | |||
static { | |||
mapFormatter = new HashMap<>(); | |||
mapFormatter.put(SwEnum.DataType.BOOL.value, value -> { | |||
if (CommUtil.strToBool(value)) return "是"; | |||
if (StringUtil.strToBool(value)) return "是"; | |||
return ""; | |||
}); | |||
mapFormatter.put(SwEnum.DataType.CURRENCY.value, value -> { | |||
@@ -4,12 +4,10 @@ import cc.smtweb.framework.core.db.impl.BaseBean; | |||
import cc.smtweb.framework.core.db.impl.DefaultEntity; | |||
import cc.smtweb.framework.core.util.kryo.KryoTool; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.io.Serializable; | |||
import java.lang.reflect.ParameterizedType; | |||
import java.lang.reflect.Type; | |||
import java.nio.charset.StandardCharsets; | |||
import java.text.Collator; | |||
import java.util.Collection; | |||
import java.util.HashSet; | |||
@@ -22,8 +20,6 @@ import java.util.Set; | |||
*/ | |||
@Slf4j | |||
public class CommUtil { | |||
private static Collator chineseCollator = Collator.getInstance(Locale.CHINA); | |||
/** | |||
* 找指定类的泛型类 | |||
* @param cls | |||
@@ -117,28 +113,4 @@ public class CommUtil { | |||
return s.substring(0, s.length() - 1); | |||
} | |||
//中文字符串比较 | |||
public static int chineseCompare(String s1, String s2) { | |||
return chineseCollator.compare(s1, s2); | |||
} | |||
public static int compareStr(String s1, String s2) { | |||
if (StringUtils.isEmpty(s1) && StringUtils.isEmpty(s2)) return 0; | |||
if (StringUtils.isEmpty(s1)) return -1; | |||
if (StringUtils.isEmpty(s2)) return 1; | |||
return chineseCollator.compare(s1, s2); | |||
} | |||
public static boolean isStrEquals(String s1, String s2) { | |||
return compareStr(s1, s2) == 0; | |||
} | |||
//获取字段字符串长度 | |||
public static int getStrLenB(String s) { | |||
if (StringUtils.isEmpty(s)) return 0; | |||
return s.getBytes(StandardCharsets.UTF_8).length; | |||
} | |||
public static boolean strToBool(String s) { | |||
return "true".equalsIgnoreCase(s) || "1".equals(s) || "y".equalsIgnoreCase(s); | |||
} | |||
} |
@@ -1,6 +1,9 @@ | |||
package cc.smtweb.framework.core.util; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.nio.charset.StandardCharsets; | |||
import java.text.Collator; | |||
import java.util.*; | |||
@@ -449,6 +452,27 @@ public class StringUtil { | |||
}); | |||
} | |||
public static int compareStr(String s1, String s2) { | |||
if (StringUtils.isEmpty(s1) && StringUtils.isEmpty(s2)) return 0; | |||
if (StringUtils.isEmpty(s1)) return -1; | |||
if (StringUtils.isEmpty(s2)) return 1; | |||
return chineseCollator.compare(s1, s2); | |||
} | |||
public static boolean isStrEquals(String s1, String s2) { | |||
return compareStr(s1, s2) == 0; | |||
} | |||
//获取字段字符串长度 | |||
public static int getStrLenB(String s) { | |||
if (StringUtils.isEmpty(s)) return 0; | |||
return s.getBytes(StandardCharsets.UTF_8).length; | |||
} | |||
public static boolean strToBool(String s) { | |||
return "true".equalsIgnoreCase(s) || "1".equals(s) || "y".equalsIgnoreCase(s); | |||
} | |||
/*Blob转String*/ | |||
// public static String blob2Str(Blob blob) { | |||
// if (blob == null) return ""; | |||