@@ -30,7 +30,7 @@ public class CacheManager { | |||||
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2); | private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2); | ||||
public AbstractCache getCache(String ident) { | public AbstractCache getCache(String ident) { | ||||
final AbstractCache cache = cacheMap.get(ident); | |||||
final AbstractCache cache = cacheMap.get(ident.toUpperCase()); | |||||
if (cache != null && cache.isNotInited()) { | if (cache != null && cache.isNotInited()) { | ||||
cache.init(); | cache.init(); | ||||
} | } | ||||
@@ -70,6 +70,9 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
if (field.isNotNull() && StringUtils.isEmpty(bean.getStr(field.getName()))) { | if (field.isNotNull() && StringUtils.isEmpty(bean.getStr(field.getName()))) { | ||||
throw new SwException(field.getTitle() + "不能为空!"); | throw new SwException(field.getTitle() + "不能为空!"); | ||||
} | } | ||||
if (field.getFieldType() == SwEnum.FieldType.PARENT_ID.value) { | |||||
TreeHelper.getTreeHelper(tableName).checkParent(bean); | |||||
} | |||||
} | } | ||||
EntityDao dao = DbEngine.getInstance().findDao(tableName); | EntityDao dao = DbEngine.getInstance().findDao(tableName); | ||||
@@ -144,16 +147,17 @@ public class DefaultSaveHandler<T extends DefaultEntity> extends AbstractSaveHan | |||||
} else { | } else { | ||||
bean = loadComp(id); | bean = loadComp(id); | ||||
} | } | ||||
TreeHelper.getTreeHelper(tableName).checkParent(bean); | |||||
//不考虑没有级次码等情况,这个在表设计时校验 | //不考虑没有级次码等情况,这个在表设计时校验 | ||||
ModelField fieldParentCode = table.findFieldByType(SwEnum.FieldType.PARENT_ID.value); | |||||
ModelField fieldParentId = table.findFieldByType(SwEnum.FieldType.PARENT_ID.value); | |||||
bean.put(fieldParentCode.getName(), parentId); | |||||
bean.put(fieldParentId.getName(), parentId); | |||||
DbEngine.getInstance().doTrans(new AbsDbWorker() { | DbEngine.getInstance().doTrans(new AbsDbWorker() { | ||||
@Override | @Override | ||||
public void work() { | public void work() { | ||||
EntityDao dao = DbEngine.getInstance().findDao(tableName); | EntityDao dao = DbEngine.getInstance().findDao(tableName); | ||||
listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean); | listTreeBean = TreeHelper.getTreeHelper(tableName).resetTreeLevel(bean); | ||||
dao.updateEntity(bean, fieldParentCode.getName()); | |||||
dao.updateEntity(bean, fieldParentId.getName()); | |||||
} | } | ||||
@Override | @Override | ||||
@@ -88,6 +88,20 @@ public class TreeHelper<T extends DefaultEntity> { | |||||
return list; | return list; | ||||
} | } | ||||
public void checkParent(T bean) { | |||||
if (table.getType() != SwEnum.TableType.TYPE_TREE.value) return; | |||||
if (!table.isNeedCache()) throw new SwException("请定义为需要缓存!"); | |||||
long pId = getParentId(bean); | |||||
if (bean.getEntityId() == pId) throw new SwException("上级节点不能为自己!"); | |||||
if (pId <= 0) return; | |||||
T parent = cache.get(pId); | |||||
if (parent == null) return; | |||||
String plevelcode = SwConsts.SPLIT_CHAR + parent.getStr(fieldLevelCode) + SwConsts.SPLIT_CHAR; | |||||
if (plevelcode.contains(SwConsts.SPLIT_CHAR + bean.getEntityId() + SwConsts.SPLIT_CHAR)) { | |||||
throw new SwException("上级节点不能为自己的下级!"); | |||||
} | |||||
} | |||||
public List<T> resetTreeLevel(T bean) { | public List<T> resetTreeLevel(T bean) { | ||||
List<T> list = new ArrayList<>(); | List<T> list = new ArrayList<>(); | ||||
if (table.getType() != SwEnum.TableType.TYPE_TREE.value) return list; | if (table.getType() != SwEnum.TableType.TYPE_TREE.value) return list; | ||||
@@ -15,5 +15,6 @@ public class ModelTableSaveHanlder extends DefaultSaveHandler<ModelTable> { | |||||
protected void readFromPage() { | protected void readFromPage() { | ||||
super.readFromPage(); | super.readFromPage(); | ||||
bean.setContent(bean.getContent()); | bean.setContent(bean.getContent()); | ||||
bean.setName(bean.getName().toUpperCase()); | |||||
} | } | ||||
} | } |
@@ -0,0 +1,8 @@ | |||||
package cc.smtweb.system.bpm.web.engine.flow; | |||||
/** | |||||
* Created by Akmm at 2022/5/24 14:21 | |||||
* 工作流 | |||||
*/ | |||||
public class FlowService { | |||||
} |