diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java index daa5ac1..6ba04c9 100644 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java @@ -1,20 +1,15 @@ package cc.smtweb.framework.core.cache; import cc.smtweb.framework.core.annotation.SwCache; -import cc.smtweb.framework.core.annotation.SwParam; -import cc.smtweb.framework.core.cache.ISwCache; import cc.smtweb.framework.core.redis.RedisBroadcastEvent; import cc.smtweb.framework.core.redis.RedisManager; import cc.smtweb.framework.core.util.CommUtil; -import cc.smtweb.framework.core.util.kryo.KryoTool; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; -import com.github.benmanes.caffeine.cache.RemovalCause; import com.github.benmanes.caffeine.cache.Scheduler; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.NonNull; -import org.springframework.beans.factory.annotation.Autowired; import java.io.Serializable; import java.util.*; @@ -30,14 +25,12 @@ import java.util.concurrent.TimeUnit; */ @Slf4j public abstract class AbstractCache implements ISwCache { - //树节点按parent的key - public static final String KEY_PARENT_ID = "pr"; protected final static int LS_NONE = 0; protected final static int LS_LOADING = 1; protected final static int LS_LOADED = 2; - private final static String split_char = "-"; + private final static String SPLIT_CHAR = "-"; //唯一标识 protected String ident; //展示名称 @@ -285,7 +278,7 @@ public abstract class AbstractCache implements ISwCache< //本地调用,删除一个对象时,更新列表缓存 private void doRemoveList(String regionKey, String key, T value) { if (StringUtils.isEmpty(key)) return; - Set list = mapListLocal.get(regionKey + split_char + key); + Set list = mapListLocal.get(regionKey + SPLIT_CHAR + key); if (list == null) { return; } @@ -304,7 +297,7 @@ public abstract class AbstractCache implements ISwCache< //本地调用,更新列表缓存 private void doUpdateList(String regionKey, String key, T value) { if (StringUtils.isEmpty(key)) return; - Set list = mapListLocal.computeIfAbsent(regionKey + split_char + key, k -> new LinkedHashSet<>()); + Set list = mapListLocal.computeIfAbsent(regionKey + SPLIT_CHAR + key, k -> new LinkedHashSet<>()); list.add(value); } @@ -368,7 +361,7 @@ public abstract class AbstractCache implements ISwCache< } public final Set getListByKey(String rk, String key) { - return mapListLocal.get(rk + split_char + key); + return mapListLocal.get(rk + SPLIT_CHAR + key); } /** diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java new file mode 100644 index 0000000..29f6bb9 --- /dev/null +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java @@ -0,0 +1,106 @@ +package cc.smtweb.framework.core.common; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Created by Akmm at 2017/5/3 17:25 + * 枚举基类 + */ +public abstract class AbstractEnum { + public Map mapAll = new LinkedHashMap<>(); + + public V addEnum(K value, String name) { + final V bean = buildBean(value, name); + mapAll.put(value, bean); + return bean; + } + + public void delEnum(K value) { + mapAll.remove(value); + } + + protected abstract V buildBean(K value, String name); + + protected Object getSqlValue(V pbs) { + return pbs.value; + } + + //根据值获取对象 + public V getByValue(K value) { + V v = mapAll.get(value); + if (v != null) return v; + return getDefault(); + } + + public V getByName(String name) { + for (V bs : mapAll.values()) { + if (bs.name.equals(name)) return bs; + } + return null; + } + + //根据value获取name + public String getName(K value) { + V bean = getByValue(value); + return bean != null ? bean.name: ""; + } + + //默认值 + public V getDefault() { + return null; + } + + //所有枚举定义 + public Collection values() { + return mapAll.values(); + } + + public boolean contains(K value) { + return mapAll.containsKey(value); + } + + //遍历枚举类 + public void doEnum(IEnumWorker worker) { + for (V bean: mapAll.values()) { + worker.work(bean); + } + } + + /** + * 枚举值对象定义 + */ + public static class EnumBean { + public T value; + public String name; + + public EnumBean(T value, String name) { + this.value = value; + this.name = name; + } + } + + /** + * Int、Text 枚举值对象定义 + */ + public static class IntEnumBean extends EnumBean { + public IntEnumBean(Integer value, String name) { + super(value, name); + } + } + + /** + * Str、Text 枚举值对象定义 + */ + public static class StrEnumBean extends EnumBean { + public StrEnumBean(String value, String name) { + super(value, name); + } + } + + //枚举回调类 + public interface IEnumWorker { + public void work(V enumBean); + } +} diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/IntEnum.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/IntEnum.java new file mode 100644 index 0000000..7cdd183 --- /dev/null +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/IntEnum.java @@ -0,0 +1,12 @@ +package cc.smtweb.framework.core.common; + +/** + * Created by Akmm at 2017/5/3 17:25 + * int、text型枚举 + */ +public class IntEnum extends AbstractEnum { + @Override + protected AbstractEnum.IntEnumBean buildBean(Integer value, String name) { + return new AbstractEnum.IntEnumBean(value, name); + } +} diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/StrEnum.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/StrEnum.java new file mode 100644 index 0000000..2ada2ae --- /dev/null +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/StrEnum.java @@ -0,0 +1,30 @@ +package cc.smtweb.framework.core.common; + +import org.apache.commons.lang3.StringUtils; + +/** + * Created by Akmm at 2017/5/3 17:25 + * int、text型枚举 + */ +public class StrEnum extends AbstractEnum { + @Override + protected Object getSqlValue(StrEnumBean pbs) { + return "'" + pbs.value + "'"; + } + + @Override + protected AbstractEnum.StrEnumBean buildBean(String value, String name) { + return new AbstractEnum.StrEnumBean(value, name); + } + + //根据value获取name + public String getNames(String value) { + if (StringUtils.isEmpty(value)) return ""; + StringBuilder sb = new StringBuilder(128); + for (String s : value.split(",")) { + String n = getName(s); + if (StringUtils.isNotEmpty(n)) sb.append(",").append(n); + } + return sb.substring(1); + } +} diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java new file mode 100644 index 0000000..cdd0f69 --- /dev/null +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java @@ -0,0 +1,10 @@ +package cc.smtweb.framework.core.common; + +/** + * Created by Akmm at 2022/3/23 9:46 + */ +public interface SwConsts { + + //树节点按parent的key + String KEY_PARENT_ID = "pr"; +} diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java new file mode 100644 index 0000000..3d54bbc --- /dev/null +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java @@ -0,0 +1,9 @@ +package cc.smtweb.framework.core.common; + +/** + * Created by Akmm at 2022/3/23 9:39 + * 系统的一些枚举变量 + */ +public interface SwEnum { + +} diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCatalog.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCatalog.java deleted file mode 100644 index c9ea0de..0000000 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCatalog.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.smtweb.framework.core.db.vo; - -import lombok.Data; - -import java.io.Serializable; - -/** - * 目录 - */ -@Data -public class ModelCatalog implements Serializable { - private long id; - private long parentId; - //项目id - private long prjId; - //目录编码及名称 - private String code; - private String name; - //创建者 - private Long createUid; - //创建时间 - private Long createTime; - //最后更新人 - private Long updateUid; - //更新时间 - private Long updateTime; -} diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelProject.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelProject.java deleted file mode 100644 index 6c6555a..0000000 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelProject.java +++ /dev/null @@ -1,29 +0,0 @@ -package cc.smtweb.framework.core.db.vo; - -import lombok.Data; - -import java.io.Serializable; - -/** - * 项目 - */ -@Data -public class ModelProject implements Serializable { - private long id; - // 项目名称 - private String name; - //依赖项目 - private String depends; - //状态:0-启用 1-停用 - private int status; - //备注 - private String desc; - //创建者 - private Long createUid; - //创建时间 - private Long createTime; - //最后更新人 - private Long updateUid; - //更新时间 - private Long updateTime; -} diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java index 95f571c..20c9350 100644 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java @@ -91,7 +91,7 @@ public class DefaultListHandler extends AbstractListHan String sn = (String) dao.readValue(b, l.getLinkNameField()); if (StringUtils.isNotEmpty(sn)) names += "," + sn; } - row.put(l.getFieldName() + "_name", names.substring(1)); + row.put(l.getFieldName() + "_text", names.substring(1)); } else { List list = mapIds.computeIfAbsent(l.getLinkTable().getName(), k -> new ArrayList<>()); Collections.addAll(list, ids); @@ -121,7 +121,7 @@ public class DefaultListHandler extends AbstractListHan String sn = mapV.get(sId); if (StringUtils.isNotEmpty(sn)) names += "," + sn; } - row.put(l.getFieldName() + "_name", names.substring(1)); + row.put(l.getFieldName() + "_text", names.substring(1)); } } } diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java index 9e58d0c..6617bc9 100644 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java @@ -41,6 +41,12 @@ public class DefaultSaveHandler extends AbstractSaveHan } @Override + protected long readId() { + ModelTable table = ModelTableCache.getInstance().getByName(tableName); + return params.readLong(table.getIdField()); + } + + @Override protected T loadComp(long id) { return new DefaultProvider(tableName).getBean(id); } diff --git a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java index 1ca0f28..27b81b4 100644 --- a/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java +++ b/smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java @@ -3,6 +3,7 @@ package cc.smtweb.framework.core.mvc.service; import cc.smtweb.framework.core.SwException; import cc.smtweb.framework.core.cache.AbstractCache; 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.db.cache.ModelTableCache; @@ -61,11 +62,11 @@ public class TreeHelper { } public Collection getChildren(long id) { - return cache.getListByKey(AbstractCache.KEY_PARENT_ID, String.valueOf(id)); + return cache.getListByKey(SwConsts.KEY_PARENT_ID, String.valueOf(id)); } public List getChildren(long id, Comparator comparator) { - Collection set = cache.getListByKey(AbstractCache.KEY_PARENT_ID, String.valueOf(id)); + Collection set = cache.getListByKey(SwConsts.KEY_PARENT_ID, String.valueOf(id)); List list = new ArrayList<>(set); if (comparator != null) list.sort(comparator);