郑根木 pirms 2 gadiem
vecāks
revīzija
76ed686c91
11 mainītis faili ar 182 papildinājumiem un 71 dzēšanām
  1. +4
    -11
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java
  2. +106
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java
  3. +12
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/IntEnum.java
  4. +30
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/StrEnum.java
  5. +10
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java
  6. +9
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java
  7. +0
    -27
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCatalog.java
  8. +0
    -29
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelProject.java
  9. +2
    -2
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java
  10. +6
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java
  11. +3
    -2
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java

+ 4
- 11
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java Parādīt failu

@@ -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<T extends Serializable> implements ISwCache<String, T> {
//树节点按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<T extends Serializable> implements ISwCache<
//本地调用,删除一个对象时,更新列表缓存
private void doRemoveList(String regionKey, String key, T value) {
if (StringUtils.isEmpty(key)) return;
Set<T> list = mapListLocal.get(regionKey + split_char + key);
Set<T> list = mapListLocal.get(regionKey + SPLIT_CHAR + key);
if (list == null) {
return;
}
@@ -304,7 +297,7 @@ public abstract class AbstractCache<T extends Serializable> implements ISwCache<
//本地调用,更新列表缓存
private void doUpdateList(String regionKey, String key, T value) {
if (StringUtils.isEmpty(key)) return;
Set<T> list = mapListLocal.computeIfAbsent(regionKey + split_char + key, k -> new LinkedHashSet<>());
Set<T> list = mapListLocal.computeIfAbsent(regionKey + SPLIT_CHAR + key, k -> new LinkedHashSet<>());
list.add(value);
}

@@ -368,7 +361,7 @@ public abstract class AbstractCache<T extends Serializable> implements ISwCache<
}

public final Set<T> getListByKey(String rk, String key) {
return mapListLocal.get(rk + split_char + key);
return mapListLocal.get(rk + SPLIT_CHAR + key);
}

/**


+ 106
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java Parādīt failu

@@ -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<K, V extends AbstractEnum.EnumBean> {
public Map<K, V> 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<V> values() {
return mapAll.values();
}

public boolean contains(K value) {
return mapAll.containsKey(value);
}

//遍历枚举类
public void doEnum(IEnumWorker<V> worker) {
for (V bean: mapAll.values()) {
worker.work(bean);
}
}

/**
* 枚举值对象定义
*/
public static class EnumBean<T> {
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<Integer> {
public IntEnumBean(Integer value, String name) {
super(value, name);
}
}

/**
* Str、Text 枚举值对象定义
*/
public static class StrEnumBean extends EnumBean<String> {
public StrEnumBean(String value, String name) {
super(value, name);
}
}

//枚举回调类
public interface IEnumWorker<V extends EnumBean> {
public void work(V enumBean);
}
}

+ 12
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/IntEnum.java Parādīt failu

@@ -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<Integer, AbstractEnum.IntEnumBean> {
@Override
protected AbstractEnum.IntEnumBean buildBean(Integer value, String name) {
return new AbstractEnum.IntEnumBean(value, name);
}
}

+ 30
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/StrEnum.java Parādīt failu

@@ -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<String, AbstractEnum.StrEnumBean> {
@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);
}
}

+ 10
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java Parādīt failu

@@ -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";
}

+ 9
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java Parādīt failu

@@ -0,0 +1,9 @@
package cc.smtweb.framework.core.common;

/**
* Created by Akmm at 2022/3/23 9:39
* 系统的一些枚举变量
*/
public interface SwEnum {

}

+ 0
- 27
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCatalog.java Parādīt failu

@@ -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;
}

+ 0
- 29
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/db/vo/ModelProject.java Parādīt failu

@@ -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;
}

+ 2
- 2
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultListHandler.java Parādīt failu

@@ -91,7 +91,7 @@ public class DefaultListHandler<T extends DefaultEntity> 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<String> list = mapIds.computeIfAbsent(l.getLinkTable().getName(), k -> new ArrayList<>());
Collections.addAll(list, ids);
@@ -121,7 +121,7 @@ public class DefaultListHandler<T extends DefaultEntity> 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));
}
}
}


+ 6
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java Parādīt failu

@@ -41,6 +41,12 @@ public class DefaultSaveHandler<T extends DefaultEntity> 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<T>(tableName).getBean(id);
}


+ 3
- 2
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java Parādīt failu

@@ -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<T extends DefaultEntity> {
}

public Collection<T> 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<T> getChildren(long id, Comparator<T> comparator) {
Collection<T> set = cache.getListByKey(AbstractCache.KEY_PARENT_ID, String.valueOf(id));
Collection<T> set = cache.getListByKey(SwConsts.KEY_PARENT_ID, String.valueOf(id));
List<T> list = new ArrayList<>(set);
if (comparator != null)
list.sort(comparator);


Notiek ielāde…
Atcelt
Saglabāt