|
@@ -1,6 +1,8 @@
|
|
|
package org.springblade.manager.formula.impl;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.log.StaticLog;
|
|
|
import com.mixsmart.utils.StringUtils;
|
|
|
import lombok.Data;
|
|
|
import org.springblade.common.utils.BaseUtils;
|
|
@@ -10,7 +12,7 @@ import org.springblade.manager.bean.TableInfo;
|
|
|
import org.springblade.manager.dto.ElementData;
|
|
|
import org.springblade.manager.dto.FormData;
|
|
|
import org.springblade.manager.entity.Formula;
|
|
|
-import org.springblade.manager.formula.Coords;
|
|
|
+import org.springblade.manager.dto.Coords;
|
|
|
import org.springblade.manager.formula.ITableElementConverter;
|
|
|
import org.springblade.manager.formula.KeyMapper;
|
|
|
import java.util.*;
|
|
@@ -72,28 +74,66 @@ public class TableElementConverter implements ITableElementConverter {
|
|
|
dataMap.keySet().forEach(e->{
|
|
|
String[] codeAndId = e.split(StringPool.AT);
|
|
|
List<KeyMapper> kms = dataMap.get(e);
|
|
|
- List<ElementData> eds = new ArrayList<>();
|
|
|
- AtomicInteger index= new AtomicInteger(0);
|
|
|
- kms.forEach(b->{
|
|
|
- List<TableInfo> elements =this.tableInfoList.stream().filter(t-> StringUtils.isEquals(t.getPkeyId(),b.getNodeId())).collect(Collectors.toList());
|
|
|
- elements.forEach(k->{
|
|
|
- LinkedHashMap<String,String> page = k.getDataMap();
|
|
|
- String v=page.get(b.getField());
|
|
|
- if(StringUtils.isNotEmpty(v)){
|
|
|
- String[] values = v.split("☆");
|
|
|
- for(String s:values){
|
|
|
- String[] t = s.split("_\\^_");
|
|
|
- String[] c =t[1].split("_");
|
|
|
- ElementData ed = new ElementData(index.get(),0,t[0],Func.toInt(c[1]),Func.toInt(c[0]));
|
|
|
- this.elementDataMap.put(StringUtils.join(b.getCode(),ed.getGroupId(),ed.getIndex(),Func.toInt(c[1]),Func.toInt(c[0]),StringPool.AT),ed);
|
|
|
- eds.add(ed);
|
|
|
+ KeyMapper one = kms.get(0);
|
|
|
+ FormData fd=new FormData(codeAndId[0],new ArrayList<>(),formulaMap.get(codeAndId[1]),this.coordinateMap.get(one.getTableName()).get(one.getField()));
|
|
|
+ /*初始化元素数据集*/
|
|
|
+ List<ElementData> eds =fd.getValues();
|
|
|
+ String coords = this.coordinateMap.get(fd.getTableName()).get(fd.getKey());
|
|
|
+ if(Func.isNotBlank(coords)){
|
|
|
+ List<Coords> coordsList = Stream.of(coords).flatMap(s-> Arrays.stream(s.split(";"))).map(s->{String[] xy=s.split("_");return new Coords(xy[1],xy[0]);}).collect(Collectors.toList());
|
|
|
+ fd.setCoordsList(coordsList);
|
|
|
+ for(int i=0;i<kms.size();i++){
|
|
|
+ /*每一页都有自己对立的Id*/
|
|
|
+ KeyMapper km=kms.get(i);
|
|
|
+ TableInfo tableInfo =this.tableInfoList.stream().filter(t-> StringUtils.isEquals(t.getPkeyId(),km.getNodeId())).findFirst().orElseGet(TableInfo::new);
|
|
|
+ int groupId=Integer.parseInt(tableInfo.getGroupId());
|
|
|
+ LinkedHashMap<String,String> pageData = tableInfo.getDataMap();
|
|
|
+ if(Func.isNotEmpty(pageData)){
|
|
|
+ Map<String,Object> tmpMap = new HashMap<>();
|
|
|
+ String v=pageData.get(km.getField());
|
|
|
+ if(StringUtils.isNotEmpty(v)){
|
|
|
+ String[] values = v.split("☆");
|
|
|
+ for(String s:values){
|
|
|
+ String[] t = s.split("_\\^_");
|
|
|
+ String[] c =t[1].split("_");
|
|
|
+ tmpMap.put(StringUtils.join(fd.getCode(),groupId,i,Func.toInt(c[1]),Func.toInt(c[0]),StringPool.AT),t[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(Coords c:coordsList){
|
|
|
+ Object val = null;
|
|
|
+ String key =StringUtils.join(fd.getCode(),groupId,i,c.getX(),c.getY(),StringPool.AT);
|
|
|
+ if(tmpMap.containsKey(key)){
|
|
|
+ val = tmpMap.get(key);
|
|
|
+ }
|
|
|
+ eds.add(new ElementData(i,0,val,c.getX(),c.getY()));
|
|
|
}
|
|
|
}
|
|
|
- index.getAndIncrement();
|
|
|
- });
|
|
|
- });
|
|
|
- KeyMapper one = kms.get(0);
|
|
|
- this.fds.add(new FormData(codeAndId[0],eds,formulaMap.get(codeAndId[1]),this.coordinateMap.get(one.getTableName()).get(one.getField())));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ StaticLog.error("FORMULA_LOG@元素{}定位信息不存在,请检查配置",fd.getTableName()+StringPool.COLON+fd.getKey());
|
|
|
+ }
|
|
|
+// AtomicInteger index= new AtomicInteger(0);
|
|
|
+// kms.forEach(b->{
|
|
|
+// List<TableInfo> elements =this.tableInfoList.stream().filter(t-> StringUtils.isEquals(t.getPkeyId(),b.getNodeId())).collect(Collectors.toList());
|
|
|
+// //String coords = this.coordinateMap.get(fd.getTableName()).get(fd.getKey());
|
|
|
+// elements.forEach(k->{
|
|
|
+// /*把页面上所有的元素区映射对象*/
|
|
|
+// LinkedHashMap<String,String> page = k.getDataMap();
|
|
|
+// String v=page.get(b.getField());
|
|
|
+// if(StringUtils.isNotEmpty(v)){
|
|
|
+// String[] values = v.split("☆");
|
|
|
+// for(String s:values){
|
|
|
+// String[] t = s.split("_\\^_");
|
|
|
+// String[] c =t[1].split("_");
|
|
|
+// ElementData ed = new ElementData(index.get(),0,t[0],Func.toInt(c[1]),Func.toInt(c[0]));
|
|
|
+// this.elementDataMap.put(StringUtils.join(b.getCode(),ed.getGroupId(),ed.getIndex(),Func.toInt(c[1]),Func.toInt(c[0]),StringPool.AT),ed);
|
|
|
+// eds.add(ed);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// index.getAndIncrement();
|
|
|
+// });
|
|
|
+// });
|
|
|
+ this.fds.add(fd);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -102,6 +142,37 @@ public class TableElementConverter implements ITableElementConverter {
|
|
|
|
|
|
@Override
|
|
|
public void after() {
|
|
|
+ /*这个方法的核心就是把fds的数据按照既定格式(key_xxx_val_y_x)回写到tableInfo,对fds进行tableName分组,非空循环写人*/
|
|
|
+ LinkedHashMap<String,List<KeyMapper>> tabs = keyMappers.stream().collect(Collectors.groupingBy(KeyMapper::getCode,LinkedHashMap::new,Collectors.toList()));
|
|
|
+ for (FormData fd : this.fds) {
|
|
|
+ if(fd.getUpdate().equals(1)){
|
|
|
+ try {
|
|
|
+ List<ElementData> elementDataList =fd.getValues();
|
|
|
+ List<KeyMapper> kms = tabs.get(fd.getCode());
|
|
|
+ List<TableInfo> tables = new ArrayList<>();
|
|
|
+ for(TableInfo t:this.tableInfoList){
|
|
|
+ if(kms.stream().anyMatch(e->StringUtils.isEquals(e.getNodeId(),t.getPkeyId()))){
|
|
|
+ /*获取将要写入的tableInfo*/
|
|
|
+ tables.add(t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LinkedHashMap<Integer,List<ElementData>> pages = elementDataList.stream().collect(Collectors.groupingBy(ElementData::getIndex,LinkedHashMap::new,Collectors.toList()));
|
|
|
+ for(int i=0;i<pages.size();i++){
|
|
|
+ /*每一页映射一个tableInfo*/
|
|
|
+ List<ElementData> p = pages.get(i);
|
|
|
+ TableInfo info = tables.get(i);
|
|
|
+ info.getDataMap().put(fd.getKey(), recovery(p));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ StaticLog.error("元素{}回写报错",fd.getCode());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**备份*/
|
|
|
+ public void _after() {
|
|
|
/*可以优化对每一张表进行元素分类,同一张元素*/
|
|
|
/*根据数据库表分组*/
|
|
|
LinkedHashMap<String,List<KeyMapper>> tabs = keyMappers.stream().collect(Collectors.groupingBy(KeyMapper::getCode,LinkedHashMap::new,Collectors.toList()));
|
|
@@ -124,13 +195,13 @@ public class TableElementConverter implements ITableElementConverter {
|
|
|
tableMap.put(fd.getTableName(),tables);
|
|
|
}
|
|
|
groups.forEach((groupId, group) -> {
|
|
|
- group.forEach((index,page)->{
|
|
|
- if(Func.isNotEmpty(page)) {
|
|
|
- TableInfo info = tables.get(index);
|
|
|
- /*每一页对应一个info*/
|
|
|
- info.getDataMap().put(fd.getKey(), recovery(page, fd));
|
|
|
- }
|
|
|
- });
|
|
|
+ group.forEach((index,page)->{
|
|
|
+ if(Func.isNotEmpty(page)) {
|
|
|
+ TableInfo info = tables.get(index);
|
|
|
+ /*每一页对应一个info*/
|
|
|
+ info.getDataMap().put(fd.getKey(), recovery(page,fd));
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
}
|
|
@@ -139,7 +210,7 @@ public class TableElementConverter implements ITableElementConverter {
|
|
|
|
|
|
/**格式化回写内容*/
|
|
|
@Deprecated
|
|
|
- public String recovery(List<ElementData> dataList,String position){
|
|
|
+ public String recovery(List<ElementData> dataList,String position,String z){
|
|
|
List<Coords> coordsList = CoordsBuilder.getInstance().build(position);
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
List<Integer[]> total = new ArrayList<>();
|
|
@@ -183,6 +254,7 @@ public class TableElementConverter implements ITableElementConverter {
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
+ @Deprecated
|
|
|
public String recovery(List<ElementData> dataList,FormData fd){
|
|
|
String coords = this.coordinateMap.get(fd.getTableName()).get(fd.getKey());
|
|
|
StringBuilder sb = new StringBuilder();
|
|
@@ -202,6 +274,13 @@ public class TableElementConverter implements ITableElementConverter {
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
+ public String recovery(List<ElementData> dataList){
|
|
|
+ if(Func.isNotEmpty(dataList)){
|
|
|
+ return dataList.stream().filter(e->!e.isEmpty()).map(e->e.stringValue()+"_^_"+e.getY()+"_"+e.getX()).collect(Collectors.joining("☆"));
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|