Просмотр исходного кода

菜单定义、页面下拉、项目下拉、目录下拉、枚举下拉

master
yaoq 2 лет назад
Родитель
Сommit
b30f595e2a
13 измененных файлов: 639 добавлений и 178 удалений
  1. +148
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java
  2. +27
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java
  3. +31
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FieldComboService.java
  4. +27
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FormComboService.java
  5. +55
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefine.java
  6. +34
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefineCache.java
  7. +30
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightService.java
  8. +51
    -2
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java
  9. +7
    -5
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuService.java
  10. +37
    -0
      smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/menu/menuList.js
  11. +10
    -2
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  12. +6
    -2
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwMap.java
  13. +176
    -167
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java

+ 148
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java Просмотреть файл

@@ -0,0 +1,148 @@
package cc.smtweb.system.bpm.web.sys.dev;

import cc.smtweb.framework.core.common.AbstractEnum;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.mvc.service.SwListData;
import cc.smtweb.framework.core.util.PubUtil;
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.ModelFormCache;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
import cc.smtweb.system.bpm.web.design.form.define.PageDatasets;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Author: tanghp
* @Date: 2022-08-01 17:47
* @Desc:
*/
public class ComboHandler {

static class FormLoadHandler extends DynPageLoadHandler {

@Override
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) {
DynPageListHandler listHandler = new ComboHandler.FormListHandler(pageId, filter, pageDataSet);
listHandler.init(params, us);
return listHandler;
}
}

static class FieldLoadHandler extends DynPageLoadHandler {

@Override
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) {
DynPageListHandler listHandler = new ComboHandler.FieldListHandler(pageId, filter, pageDataSet);
listHandler.init(params, us);
return listHandler;
}
}

static class EnumLoadHandler extends DynPageLoadHandler {

@Override
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) {
DynPageListHandler listHandler = new ComboHandler.EnumListHandler(pageId, filter, pageDataSet);
listHandler.init(params, us);
return listHandler;
}
}


static class EnumListHandler extends DynPageListHandler {

public EnumListHandler(long pageId, SwMap filter, PageDataset pageDataSet) {
super(pageId, filter, pageDataSet);
}

@Override
public SwListData buildListData() {
String cls = params.readMap("filter").readString("cls");
if (PubUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0);
List<SwMap> list = new ArrayList<>();
try {
AbstractEnum e;
try {
e = (AbstractEnum) Class.forName(cls).getDeclaredField("inst").get(null);
} catch (Exception e1) {
e = (AbstractEnum) Class.forName(cls).getDeclaredField("instance").get(null);
}
for (Object v : e.mapAll.values()) {
AbstractEnum.EnumBean bean = (AbstractEnum.EnumBean) v;
SwMap row = new SwMap();
row.put("value", bean.value.toString());
row.put("name", bean.name);
list.add(row);
}
} catch (Exception ue) {
return SwListData.create(new ArrayList(), 0);
}
return SwListData.create(list, list.size());
}

@Override
public R getTotal() {
return R.success(buildListData().getTotal());
}

}


static class FieldListHandler extends DynPageListHandler {

public FieldListHandler(long pageId, SwMap filter, PageDataset pageDataSet) {
super(pageId, filter, pageDataSet);
}

@Override
public SwListData buildListData() {
ModelForm mf = ModelFormCache.getInstance().get(params.readMap("filter").readLong("f_page"));
if (mf == null) return SwListData.create(new ArrayList(), 0);
PageDatasets pageDatasets = mf.getDatasets();
Map<String, SwMap> map = new HashMap<>();
pageDatasets.list.forEach(data -> {
data.fields.forEach(field -> {
if (map.containsKey(field.name)) return;
SwMap swMap = new SwMap();
swMap.put("f_id", field.name);
swMap.put("f_name", field.label);
map.put(field.name, swMap);
});
});
return SwListData.create(new ArrayList<SwMap>(map.values()), map.size());
}

@Override
public R getTotal() {
return R.success(buildListData().getTotal());
}

}


static class FormListHandler extends DynPageListHandler {

public FormListHandler(long pageId, SwMap filter, PageDataset pageDataSet) {
super(pageId, filter, pageDataSet);
}

@Override
protected void afterQuery(List<SwMap> listData) {
super.afterQuery(listData);
listData.forEach(row -> {
row.put("mf_url", getPageUrl(row.readLong("mf_prj_id"), row.readString("mf_name")));
});
}
}

public static String getPageUrl(long prj_id, String mf_name) {
return "/" + ModelProjectCache.getInstance().getModule(prj_id) + "." + mf_name;
}
}

+ 27
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java Просмотреть файл

@@ -0,0 +1,27 @@
package cc.smtweb.system.bpm.web.sys.dev;

import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;

/**
* Created by 1 at 2022-08-03 16:09:30
* 页面【[枚举下拉]的服务类
*/
@SwService
public class EnumComboService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
if (TYPE_LOAD.equals(type)) return new ComboHandler.EnumLoadHandler();
return super.createHandler(type);
}

/* demo
//自定义
public R demo(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_DEMO, handler -> ((DemoHandler)handler).demo());
}
*/

}

+ 31
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FieldComboService.java Просмотреть файл

@@ -0,0 +1,31 @@
package cc.smtweb.system.bpm.web.sys.dev;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;

/**
* Created by 1 at 2022-08-03 14:48:43
* 页面【[字段下拉]的服务类
*/
@SwService
public class FieldComboService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
if (TYPE_LOAD.equals(type)) return new ComboHandler.FieldLoadHandler();
return super.createHandler(type);
}

/* demo
//自定义
public R demo(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_DEMO, handler -> ((DemoHandler)handler).demo());
}
*/

}

+ 27
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FormComboService.java Просмотреть файл

@@ -0,0 +1,27 @@
package cc.smtweb.system.bpm.web.sys.dev;

import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;

/**
* Created by 1 at 2022-08-03 10:49:51
* 页面【[页面下拉]的服务类
*/
@SwService
public class FormComboService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
if (TYPE_LOAD.equals(type)) return new ComboHandler.FormLoadHandler();
return super.createHandler(type);
}

/* demo
//自定义
public R demo(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_DEMO, handler -> ((DemoHandler)handler).demo());
}
*/

}

+ 55
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefine.java Просмотреть файл

@@ -0,0 +1,55 @@
package cc.smtweb.system.bpm.web.sys.user.dataRight;

import cc.smtweb.framework.core.annotation.SwTable;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity;

/**
* Created by 1 at 2022-08-03 16:27:55
* 实体【[数据权限定义](SYS_DATA_RIGHT_DEFINE)】的Entity类
*/
@SwTable("SYS_DATA_RIGHT_DEFINE")
public class DataRightDefine extends DefaultEntity {
public static final String ENTITY_NAME = "SYS_DATA_RIGHT_DEFINE";

public DataRightDefine() {
super(ENTITY_NAME);
}

/** 主键 */
public long getId() {
return getLong("sdrd_id");
}

/** 主键 */
public void setId(long sdrd_id) {
put("sdrd_id", sdrd_id);
}
/** 编码 */
public String getCode() {
return getStr("sdrd_code");
}

/** 编码 */
public void setCode(String sdrd_code) {
put("sdrd_code", sdrd_code);
}
/** 名称 */
public String getName() {
return getStr("sdrd_name");
}

/** 名称 */
public void setName(String sdrd_name) {
put("sdrd_name", sdrd_name);
}
/** 备注 */
public String getRemark() {
return getStr("sdrd_remark");
}

/** 备注 */
public void setRemark(String sdrd_remark) {
put("sdrd_remark", sdrd_remark);
}
}

+ 34
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefineCache.java Просмотреть файл

@@ -0,0 +1,34 @@
package cc.smtweb.system.bpm.web.sys.user.dataRight;

import cc.smtweb.framework.core.annotation.SwCache;
import cc.smtweb.framework.core.cache.AbstractEntityCache;
import cc.smtweb.framework.core.cache.CacheManager;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

/**
* Created by 1 at 2022-08-03 16:27:55
* 实体【[数据权限定义](SYS_DATA_RIGHT_DEFINE)】的缓存类
*/
@SwCache(ident = "SYS_DATA_RIGHT_DEFINE", title = "数据权限定义")
public class DataRightDefineCache extends AbstractEntityCache<DataRightDefine> {
//缓存key:按编码
public final static String mk_code = "code";

public static DataRightDefineCache getInstance() {
return CacheManager.getIntance().getCache(DataRightDefineCache.class);
}

public DataRightDefineCache() {
//缓存key:按编码
regMap(mk_code, "sdrd_code");
}

//缓存key:按编码
public final DataRightDefine getByCode(String key) {
return getByKey(mk_code, key);
}
}

+ 30
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightService.java Просмотреть файл

@@ -0,0 +1,30 @@
package cc.smtweb.system.bpm.web.sys.user.dataRight;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;

/**
* Created by 1 at 2022-08-03 16:27:55
* 页面【[数据权限]的服务类
*/
@SwService
public class DataRightService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
return super.createHandler(type);
}

/* demo
//自定义
public R demo(@SwBody SwMap params, UserSession us) {
return pageHandler(params, us, TYPE_DEMO, handler -> ((DemoHandler)handler).demo());
}
*/

}

+ 51
- 2
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java Просмотреть файл

@@ -2,12 +2,17 @@ package cc.smtweb.system.bpm.web.sys.user.menu;

import cc.smtweb.framework.core.common.SwEnum;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
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;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageSaveHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageTreeHandler;

import java.util.List;
import java.util.Map;

/**
* @Author: tanghp
@@ -18,12 +23,56 @@ public class MenuHandler {
static class MenuLoadHandler extends DynPageLoadHandler {
@Override
public DynPageTreeHandler getTreeWorker(SwMap filter, PageDataset pageDataSet) {
return new MenuTreeHandler(pageId, filter, pageDataSet);
DynPageTreeHandler treeHandler = new MenuTreeHandler(pageId, filter, pageDataSet);
treeHandler.init(params, us);
return treeHandler;
}

@Override
public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) {
return new MenuListHandler(pageId, filter, pageDataSet);
DynPageListHandler listHandler = new MenuListHandler(pageId, filter, pageDataSet);
listHandler.init(params, us);
return listHandler;
}

@Override
protected void afterLoadBean(PageDataset dataset, SwMap bean) {
super.afterLoadBean(dataset, bean);
Menu menu = new Menu();
menu.setData(bean);
if (PubUtil.isNotEmptyStr(menu.getContent())) {
Map<String, String> urlMap = JsonUtil.parseMap(menu.getContent());
bean.put("sm_page_id", urlMap.get("pageId"));
bean.put("sm_page_url", urlMap.get("path"));
}
if (PubUtil.isNotEmptyStr(menu.getRight())) {
Map<String, List<String>> rightMap = JsonUtil.parseMap(menu.getRight());
bean.put("sm_right_data", PubUtil.getSqlInIds(rightMap.get("data")));
bean.put("sm_right_func", PubUtil.getSqlInIds(rightMap.get("func")));
bean.put("sm_right_field", PubUtil.getSqlInIds(rightMap.get("field")));
}
}
}

static class MenuSaveHandler extends DynPageSaveHandler {

@Override
protected DefaultEntity readBeanFromPage(PageDataset pageDataSet, SwMap data) {
if (pageDataSet.isCurTable(Menu.ENTITY_NAME)) {
//处理请求内容
SwMap sm_content = new SwMap();
sm_content.put("pageId", data.readString("sm_page_id"));
sm_content.put("path", data.readString("sm_page_url"));
data.put("sm_content", JsonUtil.encodeString(sm_content));
//处理权限点
SwMap sm_right = new SwMap();
sm_right.put("data", data.readStringList("sm_right_data"));
sm_right.put("func", data.readStringList("sm_right_func"));
sm_right.put("field", data.readStringList("sm_right_field"));
data.put("sm_right", JsonUtil.encodeString(sm_right));
return super.readBeanFromPage(pageDataSet, data);
}
return super.readBeanFromPage(pageDataSet, data);
}
}



+ 7
- 5
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuService.java Просмотреть файл

@@ -1,12 +1,8 @@
package cc.smtweb.system.bpm.web.sys.user.menu;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;

/**
* Created by 1 at 2022-08-01 17:46:05
@@ -17,6 +13,12 @@ public class MenuService extends DynPageService {
//public final static String TYPE_DEMO = "demo";
@Override
protected AbstractHandler createHandler(String type) {
switch (type) {
case TYPE_LOAD:
return new MenuHandler.MenuLoadHandler();
case TYPE_SAVE:
return new MenuHandler.MenuSaveHandler();
}
return super.createHandler(type);
}



+ 37
- 0
smtweb-framework/bpm/src/main/resources/static/event/bpm/sys/user/menu/menuList.js Просмотреть файл

@@ -0,0 +1,37 @@
/**
* Created by 1 at 2022-08-03 10:29:14
* 注册事件类【菜单管理】,参看event.defaultEvent.js
*/
window.$swEvent.setup("bpm.sys.user.menu.menuList", {
setup(page) {
const {$params, $refs, $widgets, $model, $utils, $tabRouter, $api} = page || {};
const {$$message, $$http, $$UtilPub} = $utils || {};

// 示例
const onSelectPage = (value, row) => {
$model.menuCard.setFormVal("sm_page_id", value);
$model.menuCard.setFormVal("sm_page_url", getPath(row["mf_url"]));
};

const onUrlChange = (value) => {
$model.menuCard.setFormVal("sm_page_url", getPath(value));
};

const getPath = (url) => {
//页面类型:0-设计器页面,1-自定义页面,2-外部链接
const sm_type = $$UtilPub._toNumberEx($model.menuCard.getFormVal("sm_type"));
if (sm_type !== 0) {
return url;
}
if (url.startsWith("/bpm")) {
return url;
}
return "/bpm" + url;
}

return {
onSelectPage,
onUrlChange,
}
}
});

+ 10
- 2
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java Просмотреть файл

@@ -304,7 +304,15 @@ public interface SwEnum {

class MenuType extends IntEnum {
public static MenuType instance = new MenuType();
public static IntEnumBean PAGE = instance.addEnum(0, "功能页面");
public static IntEnumBean LINK = instance.addEnum(1, "外部链接");
public static IntEnumBean DESIGN = instance.addEnum(0, "设计器页面");
public static IntEnumBean CUSTOM = instance.addEnum(1, "自定义页面");
public static IntEnumBean LINK = instance.addEnum(2, "外部链接");
}

// 功能权限枚举
class MenuFuncRight extends StrEnum {
public static MenuFuncRight instance = new MenuFuncRight();
public static StrEnumBean READ = instance.addEnum("read", "查看");
public static StrEnumBean WRITE = instance.addEnum("write", "修改");
}
}

+ 6
- 2
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwMap.java Просмотреть файл

@@ -28,9 +28,9 @@ public class SwMap extends HashMap<String, Object> {
public SwMap readMap(String name) {
Object v = get(name);
if (v == null) return null;
if (v instanceof SwMap) return (SwMap)v;
if (v instanceof SwMap) return (SwMap) v;
if (v instanceof Map) {
Map m = (Map)v;
Map m = (Map) v;
SwMap map = new SwMap(m.size());
map.putAll(m);
put(name, map);
@@ -67,6 +67,10 @@ public class SwMap extends HashMap<String, Object> {
return MapUtil.readLongSet(this, name);
}

public List<String> readStringList(String name) {
return MapUtil.readStringList(this, name);
}

public int readInt(String name) {
return MapUtil.readInt(this, name);
}


+ 176
- 167
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java Просмотреть файл

@@ -9,213 +9,222 @@ import java.util.*;
* map工具类
*/
public class MapUtil {
private MapUtil() {}

public static String readString(Map map, String name) {
return readString(map, name, "");
}

public static String readString(Map map, String name, String defaultValue) {
Object s = map.get(name);

if (s != null) {
return s.toString();
private MapUtil() {
}

return defaultValue;
}

public static long readLong(Map map, String name) {
return readLong(map, name, 0L);
}

public static long readLong(Map map, String name, Long defaultValue) {
Object s = map.get(name);

if (s != null) {
if (s instanceof Number) {
return ((Number) s).longValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Long.parseLong(value);
}
}
public static String readString(Map map, String name) {
return readString(map, name, "");
}

return defaultValue;
}

public static Long[] readLongArray(Map map, String name) {
return readLongArray(map, name, null);
}
public static String readString(Map map, String name, String defaultValue) {
Object s = map.get(name);

public static Long[] readLongArray(Map map, String name, Long[] defaultValue) {
Object value = map.get(name);
if (s != null) {
return s.toString();
}

if (value != null) {
if (value instanceof Long[]) {
return (Long[]) value;
} else if (value instanceof Object[]) {
Object[] items = (Object[])value;
List<Long> result = new ArrayList<>(items.length);
return defaultValue;
}

for (Object item: items) {
if (item != null) {
String s = item.toString();
if (StringUtils.isNotBlank(s)) {
result.add(Long.valueOf(s));
}
}
}
public static long readLong(Map map, String name) {
return readLong(map, name, 0L);
}

if (result.size() > 0) {
return result.toArray(new Long[result.size()]);
}
} else if (value instanceof List) {
List items = (List)value;
List<Long> result = new ArrayList<>(items.size());

for (Object item: items) {
if (item != null) {
String s = item.toString();
if (StringUtils.isNotBlank(s)) {
result.add(Long.valueOf(s));
public static long readLong(Map map, String name, Long defaultValue) {
Object s = map.get(name);

if (s != null) {
if (s instanceof Number) {
return ((Number) s).longValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Long.parseLong(value);
}
}
}
}

if (result.size() > 0) {
return result.toArray(new Long[result.size()]);
}
} else if (value instanceof String) {
String[] ary = value.toString().split(",");
if (ary.length > 0) {
List<Long> result = new ArrayList<>(ary.length);

for (String item: ary) {
if (StringUtils.isNotBlank(item)) {
result.add(Long.valueOf(item));
}
}

if (result.size() > 0) {
return result.toArray(new Long[result.size()]);
}
}
}
return defaultValue;
}

return defaultValue;
}

public static int readInt(Map map, String name) {
return readInt(map, name, 0);
}

public static int readInt(Map map, String name, int defaultValue) {
Object s = map.get(name);

if (s != null) {
if (s instanceof Number) {
return ((Number) s).intValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Integer.parseInt(value);
}
}
public static Long[] readLongArray(Map map, String name) {
return readLongArray(map, name, null);
}

return defaultValue;
}
public static Long[] readLongArray(Map map, String name, Long[] defaultValue) {
Object value = map.get(name);

if (value != null) {
if (value instanceof Long[]) {
return (Long[]) value;
} else if (value instanceof Object[]) {
Object[] items = (Object[]) value;
List<Long> result = new ArrayList<>(items.length);

for (Object item : items) {
if (item != null) {
String s = item.toString();
if (StringUtils.isNotBlank(s)) {
result.add(Long.valueOf(s));
}
}
}

if (result.size() > 0) {
return result.toArray(new Long[result.size()]);
}
} else if (value instanceof List) {
List items = (List) value;
List<Long> result = new ArrayList<>(items.size());

for (Object item : items) {
if (item != null) {
String s = item.toString();
if (StringUtils.isNotBlank(s)) {
result.add(Long.valueOf(s));
}
}
}

if (result.size() > 0) {
return result.toArray(new Long[result.size()]);
}
} else if (value instanceof String) {
String[] ary = value.toString().split(",");
if (ary.length > 0) {
List<Long> result = new ArrayList<>(ary.length);

for (String item : ary) {
if (StringUtils.isNotBlank(item)) {
result.add(Long.valueOf(item));
}
}

if (result.size() > 0) {
return result.toArray(new Long[result.size()]);
}
}
}
}

public static float readFloat(Map map, String name) {
return readFloat(map, name, 0.0F);
}
return defaultValue;
}

public static float readFloat(Map map, String name, float defaultValue) {
Object s = map.get(name);
public static int readInt(Map map, String name) {
return readInt(map, name, 0);
}

if (s != null) {
if (s instanceof Number) {
return ((Number) s).floatValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Float.parseFloat(value);
public static int readInt(Map map, String name, int defaultValue) {
Object s = map.get(name);

if (s != null) {
if (s instanceof Number) {
return ((Number) s).intValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Integer.parseInt(value);
}
}
}
}

return defaultValue;
}

return defaultValue;
}
public static float readFloat(Map map, String name) {
return readFloat(map, name, 0.0F);
}

public static double readDouble(Map map, String name) {
return readDouble(map, name, 0d);
}
public static float readFloat(Map map, String name, float defaultValue) {
Object s = map.get(name);

if (s != null) {
if (s instanceof Number) {
return ((Number) s).floatValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Float.parseFloat(value);
}
}
}

public static double readDouble(Map map, String name, double defaultValue) {
Object s = map.get(name);
return defaultValue;
}

if (s != null) {
if (s instanceof Number) {
return ((Number) s).doubleValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Double.parseDouble(value);
}
}
public static double readDouble(Map map, String name) {
return readDouble(map, name, 0d);
}

return defaultValue;
}
public static double readDouble(Map map, String name, double defaultValue) {
Object s = map.get(name);

if (s != null) {
if (s instanceof Number) {
return ((Number) s).doubleValue();
} else {
String value = s.toString();
if (StringUtils.isNotBlank(value)) {
return Double.parseDouble(value);
}
}
}

public static boolean readBool(Map map, String name) {
return readBool(map, name, false);
}
return defaultValue;
}

public static boolean readBool(Map map, String name, boolean defaultValue) {
Object s = map.get(name);
public static boolean readBool(Map map, String name) {
return readBool(map, name, false);
}

if (s != null) {
if (s instanceof Boolean) {
return (Boolean) s;
} else {
String value = s.toString();
if ("true".equalsIgnoreCase(value) || "1".equals(value) || "y".equalsIgnoreCase(value)) {
return Boolean.TRUE;
public static boolean readBool(Map map, String name, boolean defaultValue) {
Object s = map.get(name);

if (s != null) {
if (s instanceof Boolean) {
return (Boolean) s;
} else {
String value = s.toString();
if ("true".equalsIgnoreCase(value) || "1".equals(value) || "y".equalsIgnoreCase(value)) {
return Boolean.TRUE;
}
}
}
}

return defaultValue;
}

return defaultValue;
}
public static Set<Long> readLongSet(SwMap swMap, String name) {
Object value = swMap.get(name);
if (value != null) {
String[] ary = value.toString().split(",");
if (ary.length > 0) {
Set<Long> result = new HashSet<>(ary.length);

public static Set<Long> readLongSet(SwMap swMap, String name) {
Object value = swMap.get(name);
if (value != null) {
String[] ary = value.toString().split(",");
if (ary.length > 0) {
Set<Long> result = new HashSet<>(ary.length);
for (String item : ary) {
if (StringUtils.isNotBlank(item)) {
result.add(Long.valueOf(item));
}
}

for (String item : ary) {
if (StringUtils.isNotBlank(item)) {
result.add(Long.valueOf(item));
}
return result;
}
}

return result;
}
return null;
}

return null;
}
public static List<String> readStringList(SwMap swMap, String name) {
Object value = swMap.get(name);
if (value != null) {
return Arrays.asList(value.toString().split(","));
}
return null;
}

public static List<Map<String, Object>> readListMap(Map map, String name) {
public static List<Map<String, Object>> readListMap(Map map, String name) {
Object v = map.get(name);
if (v == null) return null;
return (List<Map<String, Object>>)v;
return (List<Map<String, Object>>) v;
}
}

Загрузка…
Отмена
Сохранить