|
@@ -7,6 +7,7 @@ import com.mixsmart.utils.FormulaUtils;
|
|
|
import com.mixsmart.utils.StringUtils;
|
|
|
import lombok.Data;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.StringPool;
|
|
|
import org.springblade.manager.dto.ElementData;
|
|
|
import org.springblade.manager.dto.FormData;
|
|
|
import org.springblade.manager.entity.Formula;
|
|
@@ -19,6 +20,7 @@ import org.springframework.web.context.WebApplicationContext;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static org.springblade.manager.formula.TurnPoint.*;
|
|
|
|
|
@@ -31,7 +33,7 @@ import static org.springblade.manager.formula.TurnPoint.*;
|
|
|
@Data
|
|
|
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
|
|
public class FormulaTurnPoint implements FormulaStrategy {
|
|
|
- public static final String TURN_REG = "(?<=T\\(com.mixsmart.utils.CustomFunction\\).TURNPOINT\\()([^)]+)(?=))";
|
|
|
+ public static final String TURN_REG = "(?<=T\\(com.mixsmart.utils.CustomFunction\\).TURNPOINT\\()([^)]+)(?=\\))";
|
|
|
private FormData cur;
|
|
|
static final List<String> KEYS;
|
|
|
private List<String> args;
|
|
@@ -44,7 +46,7 @@ public class FormulaTurnPoint implements FormulaStrategy {
|
|
|
public void execute(TableElementConverter tec) {
|
|
|
cur.setFinished(Boolean.TRUE);
|
|
|
LinkedHashMap<String, FormData> dataSourceMap = new LinkedHashMap<>();
|
|
|
- String funArgs = ReUtil.getGroup1("(?<=T\\(com.mixsmart.utils.CustomFunction\\).TURNPOINT\\()([^)]+)(?=\\))", cur.getFormula().getFormula());
|
|
|
+ String funArgs = ReUtil.getGroup1(TURN_REG, cur.getFormula().getFormula());
|
|
|
if (StringUtils.isNotEmpty(funArgs)) {
|
|
|
this.args = new ArrayList<>(Arrays.asList(funArgs.split(",")));
|
|
|
args = args.stream().map(k -> k.replaceAll("[(E\\[)'\\]]", "")).collect(Collectors.toList());
|
|
@@ -60,58 +62,99 @@ public class FormulaTurnPoint implements FormulaStrategy {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+ /*从节点参数获取G8偏差范围*/
|
|
|
String g8pcfw =Expression.parse("WP['g8pcfw']").calculate(tec.getConstantMap());
|
|
|
- CompositeDataAccess cda = new CompositeDataAccess(dataSourceMap);
|
|
|
- List<Map<String, Object>> tableData = new ArrayList<>();
|
|
|
/*用来映射元素*/
|
|
|
LinkedHashMap<String, String> configMap = new LinkedHashMap<>(KEYS.size() * 2);
|
|
|
for (int i = 0; i < KEYS.size(); i++) {
|
|
|
configMap.put(KEYS.get(i), this.args.get(i));
|
|
|
}
|
|
|
- List<Long> tableInfoIds = tec.getKeyMappers().stream().filter(k -> k.getTableName().equals(cur.getTableName())).map(KeyMapper::getPkId).distinct().collect(Collectors.toList());
|
|
|
- while (cda.hasNext()) {
|
|
|
- LinkedHashMap<String, ElementData> map = cda.next();
|
|
|
- if (!map.get(configMap.get(KEYS.get(0))).isEmpty()) {
|
|
|
- Map<String, Object> tmp = new HashMap<>(16);
|
|
|
- KEYS.forEach(k -> {
|
|
|
- ElementData ed = map.get(c(k));
|
|
|
- tmp.put(configMap.get(k), ed.stringValue());
|
|
|
- /*V判断*/
|
|
|
- if (CD.equals(k)) {
|
|
|
- Long pkeyId = tableInfoIds.get(ed.getIndex());
|
|
|
- String findStr = "OP['" + cur.getTableName() + "']['" + pkeyId + "@" + cur.getKey() + "__" + ed.getY() + "_" + ed.getX() + "']['TF']";
|
|
|
- tmp.put("vertical", StringUtils.handleNull(Expression.parse(findStr).calculate(tec.getConstantMap())));
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- tableData.add(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> g8 = (Map<String, Object>) tec.getConstantMap().computeIfAbsent("G8", k -> new HashMap<>());
|
|
|
- List<TurnPoint> result = ITurnPointCalculator.create(tableData, configMap,g8pcfw);
|
|
|
+ /*原始数据转ListMap*/
|
|
|
+ List<Map<String, Object>> tableData=listMaps( tec, dataSourceMap,configMap);
|
|
|
+ /*保存多组测量数据*/
|
|
|
+ List<List<Map<String, Object>>> total = group(tableData);
|
|
|
+ /* List<TurnPoint> result = ITurnPointCalculator.create(tableData, configMap,g8pcfw);*/
|
|
|
+ List<List<TurnPoint>> result = total.stream().map(e->ITurnPointCalculator.create(e, configMap,g8pcfw)).collect(Collectors.toList());
|
|
|
/*V判断*/
|
|
|
- forG8(result, g8,tec);
|
|
|
- List<Object> data= result.stream().map(TurnPoint::getDataMap).flatMap(m -> {
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- for (String key : configMap.keySet()) {
|
|
|
- key = key.trim();
|
|
|
- list.add(StringUtils.handleNull(m.get(key)));
|
|
|
+ forG8(result.stream().flatMap(Collection::stream).collect(Collectors.toList()), (Map<String, Object>)tec.getConstantMap().computeIfAbsent("G8", k -> new HashMap<>()),tec);
|
|
|
+ int rowSize= cur.getCoordsList().size();
|
|
|
+ List<Object> data = new ArrayList<>();
|
|
|
+ for(List<TurnPoint> turnPoints:result){
|
|
|
+ data.addAll(turnPoints2ListObj(turnPoints,configMap));
|
|
|
+ int dummyRow=rowSize-turnPoints.size()%rowSize;
|
|
|
+ if(dummyRow!=0) {
|
|
|
+ data.addAll(Collections.nCopies(configMap.size() * dummyRow, StringPool.EMPTY));
|
|
|
}
|
|
|
- return list.stream();
|
|
|
- }).collect(Collectors.toList());
|
|
|
- if (Func.isNotEmpty(data)) {
|
|
|
- AtomicInteger ai = new AtomicInteger();
|
|
|
- Map<Integer, List<Object>> dataMap = data.stream().collect(Collectors.groupingBy(e -> ai.getAndAdd(1) % configMap.size()));
|
|
|
- ai.set(0);
|
|
|
- dataSourceMap.forEach((k, v) -> {
|
|
|
- List<Object> dl = dataMap.get(ai.getAndIncrement());
|
|
|
- v.setUpdate(1);
|
|
|
- v.setFinished(Boolean.TRUE);
|
|
|
- FormulaUtils.write(v, dl, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ write(data,dataSourceMap,configMap.size());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> listMaps(TableElementConverter tec,LinkedHashMap<String, FormData> dataSourceMap,LinkedHashMap<String, String> configMap){
|
|
|
+ CompositeDataAccess cda = new CompositeDataAccess(dataSourceMap);
|
|
|
+ List<Map<String, Object>> tableData = new ArrayList<>();
|
|
|
+ List<Long> tableInfoIds = tec.getKeyMappers().stream().filter(k -> k.getTableName().equals(cur.getTableName())).map(KeyMapper::getPkId).distinct().collect(Collectors.toList());
|
|
|
+ while (cda.hasNext()) {
|
|
|
+ LinkedHashMap<String, ElementData> map = cda.next();
|
|
|
+ Map<String, Object> tmp = new HashMap<>(16);
|
|
|
+ KEYS.forEach(k -> {
|
|
|
+ ElementData ed = map.get(c(k));
|
|
|
+ tmp.put(configMap.get(k), ed.stringValue());
|
|
|
+ /*V判断*/
|
|
|
+ if (CD.equals(k)) {
|
|
|
+ Long pkeyId = tableInfoIds.get(ed.getIndex());
|
|
|
+ String findStr = "OP['" + cur.getTableName() + "']['" + pkeyId + "@" + cur.getKey() + "__" + ed.getY() + "_" + ed.getX() + "']['TF']";
|
|
|
+ tmp.put("vertical", StringUtils.handleNull(Expression.parse(findStr).calculate(tec.getConstantMap())));
|
|
|
+ }
|
|
|
+
|
|
|
});
|
|
|
+ tableData.add(tmp);
|
|
|
+ }
|
|
|
+ return tableData;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<List<Map<String,Object>>> group(List<Map<String, Object>> tableData){
|
|
|
+ List<List<Map<String, Object>>> total = new ArrayList<>();
|
|
|
+ boolean foundNonEmpty =false;
|
|
|
+ List<Map<String, Object>>tmp =new ArrayList<>();
|
|
|
+ for(Map<String,Object> e:tableData){
|
|
|
+ boolean fi=e.values().stream().anyMatch(StringUtils::isNotEmpty);
|
|
|
+ if(fi){
|
|
|
+ tmp.add(e);
|
|
|
+ foundNonEmpty =true;
|
|
|
+ }else if(foundNonEmpty){
|
|
|
+ foundNonEmpty =false;
|
|
|
+ total.add(tmp);
|
|
|
+ tmp=new ArrayList<>();
|
|
|
}
|
|
|
+ }
|
|
|
+ return total;
|
|
|
+ }
|
|
|
|
|
|
+ private List<Object> turnPoints2ListObj(List<TurnPoint> turnPoints, LinkedHashMap<String, String> configMap){
|
|
|
+ return turnPoints.stream().map(TurnPoint::getDataMap).flatMap(m -> {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (String key : configMap.keySet()) {
|
|
|
+ key = key.trim();
|
|
|
+ list.add(StringUtils.handleNull(m.get(key)));
|
|
|
+ }
|
|
|
+ return list.stream();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ /**把结果写入各个元素*/
|
|
|
+ private void write(List<Object> data,LinkedHashMap<String, FormData> dataSourceMap,int len){
|
|
|
+ if (Func.isNotEmpty(data)) {
|
|
|
+ AtomicInteger ai = new AtomicInteger();
|
|
|
+ Map<Integer, List<Object>> dataMap = data.stream().collect(Collectors.groupingBy(e -> ai.getAndAdd(1) % len));
|
|
|
+ ai.set(0);
|
|
|
+ dataSourceMap.forEach((k, v) -> {
|
|
|
+ List<Object> dl = dataMap.get(ai.getAndIncrement());
|
|
|
+ v.setUpdate(1);
|
|
|
+ v.setFinished(Boolean.TRUE);
|
|
|
+ FormulaUtils.write(v, dl, true);
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
private void forG8(List<TurnPoint> data, Map<String, Object> g8,TableElementConverter tec) {
|