|
@@ -16,6 +16,8 @@ import org.springblade.manager.utils.RandomNumberHolder;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
@@ -116,6 +118,126 @@ public class FormulaZhiZuo implements FormulaStrategy {
|
|
}
|
|
}
|
|
System.out.println(values);
|
|
System.out.println(values);
|
|
}
|
|
}
|
|
|
|
+ //优化之后的代码 放开注释可直接使用
|
|
|
|
+// @Override
|
|
|
|
+// public void execute(FormData cur, TableElementConverter tec) {
|
|
|
|
+// // 1. 提取关键信息,增加空指针防护
|
|
|
|
+// String relyStr = cur.getFormula().getRely();
|
|
|
|
+// if (relyStr == null || !relyStr.contains(":")) {
|
|
|
|
+// throw new IllegalArgumentException("无效的依赖格式: " + relyStr);
|
|
|
|
+// }
|
|
|
|
+// String key = relyStr.substring(relyStr.indexOf(':') + 1);
|
|
|
|
+//
|
|
|
|
+// // 2. 获取随机数映射并检查非空
|
|
|
|
+// HashMap<Long, String> randomNumberMap = RandomNumberHolder.getRandomNumber();
|
|
|
|
+// if (randomNumberMap == null || randomNumberMap.isEmpty()) {
|
|
|
|
+// throw new IllegalStateException("随机数映射为空,无法继续处理");
|
|
|
|
+// }
|
|
|
|
+// Map.Entry<Long, String> firstRandomEntry = randomNumberMap.entrySet().iterator().next();
|
|
|
|
+//
|
|
|
|
+// // 3. 查找对应的表格信息
|
|
|
|
+// Optional<TableInfo> tableInfoOpt = tec.getTableInfoList().stream()
|
|
|
|
+// .filter(tableInfo -> firstRandomEntry.getKey().toString().equals(tableInfo.getPkeyId()))
|
|
|
|
+// .findFirst();
|
|
|
|
+// if (!tableInfoOpt.isPresent()) {
|
|
|
|
+// throw new IllegalStateException("未找到对应的表格信息,pkeyId: " + firstRandomEntry.getKey());
|
|
|
|
+// }
|
|
|
|
+// TableInfo targetTableInfo = tableInfoOpt.get();
|
|
|
|
+//
|
|
|
|
+// // 4. 解析数据字符串(预编译正则提升性能)
|
|
|
|
+// String dataStr = targetTableInfo.getDataMap().get(key);
|
|
|
|
+// if (dataStr == null) {
|
|
|
|
+// throw new IllegalArgumentException("表格数据中未找到key: " + key);
|
|
|
|
+// }
|
|
|
|
+// String[] dataSegments = dataStr.split("☆");
|
|
|
|
+// Pattern pattern = Pattern.compile("_\\^_(.*?)_"); // 预编译正则表达式
|
|
|
|
+// Map<Integer, Double> keyToValueMap = new HashMap<>();
|
|
|
|
+//
|
|
|
|
+// for (String segment : dataSegments) {
|
|
|
|
+// Matcher matcher = pattern.matcher(segment);
|
|
|
|
+// if (matcher.find()) {
|
|
|
|
+// try {
|
|
|
|
+// Integer mapKey = Integer.parseInt(matcher.group(1));
|
|
|
|
+// int splitIndex = segment.indexOf("_^_");
|
|
|
|
+// if (splitIndex > 0) {
|
|
|
|
+// Double value = Double.valueOf(segment.substring(0, splitIndex));
|
|
|
|
+// keyToValueMap.put(mapKey, value);
|
|
|
|
+// }
|
|
|
|
+// } catch (NumberFormatException e) {
|
|
|
|
+// // 记录日志而非中断,提高容错性
|
|
|
|
+// System.err.println("解析数据失败,segment: " + segment + ", 错误: " + e.getMessage());
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 5. 准备目标值列表(清空原有值)
|
|
|
|
+// List<ElementData> elementDataList = cur.getValues();
|
|
|
|
+// elementDataList.forEach(e -> e.setValue(null));
|
|
|
|
+//
|
|
|
|
+// // 6. 排序并创建Y值到ElementData的映射(优化查找效率)
|
|
|
|
+// TreeMap<Integer, Double> sortedDataMap = new TreeMap<>(keyToValueMap);
|
|
|
|
+// Map<Integer, ElementData> yToElementMap = new HashMap<>();
|
|
|
|
+// for (ElementData data : elementDataList) {
|
|
|
|
+// yToElementMap.put(data.getY(), data);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 7. 处理数据(提取重复逻辑为方法)
|
|
|
|
+// if (!sortedDataMap.isEmpty()) {
|
|
|
|
+// Map.Entry<Integer, Double> firstEntry = sortedDataMap.firstEntry();
|
|
|
|
+// processDataRange(sortedDataMap, yToElementMap, firstEntry, 0, 4, 1);
|
|
|
|
+// processDataRange(sortedDataMap, yToElementMap, firstEntry, 5, 9, 5);
|
|
|
|
+// processDataRange(sortedDataMap, yToElementMap, firstEntry, 10, Integer.MAX_VALUE, 10);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// System.out.println(elementDataList);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 处理指定范围的数据
|
|
|
|
+// * @param sortedDataMap 排序后的数据映射
|
|
|
|
+// * @param yToElementMap Y值到ElementData的映射
|
|
|
|
+// * @param firstEntry 第一个数据条目
|
|
|
|
+// * @param startIndex 起始索引
|
|
|
|
+// * @param endIndex 结束索引
|
|
|
|
+// * @param offset 偏移量
|
|
|
|
+// */
|
|
|
|
+// private void processDataRange(TreeMap<Integer, Double> sortedDataMap,
|
|
|
|
+// Map<Integer, ElementData> yToElementMap,
|
|
|
|
+// Map.Entry<Integer, Double> firstEntry,
|
|
|
|
+// int startIndex,
|
|
|
|
+// int endIndex,
|
|
|
|
+// int offset) {
|
|
|
|
+// if (sortedDataMap.size() < startIndex + 1) {
|
|
|
|
+// return; // 数据量不足,直接返回
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// Integer baseKey = firstEntry.getKey() + offset;
|
|
|
|
+// Double baseValue = sortedDataMap.get(baseKey);
|
|
|
|
+// if (baseValue == null) {
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// for (int i = startIndex; i <= endIndex; i++) {
|
|
|
|
+// if (i >= sortedDataMap.size()) {
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// Integer currentKey = baseKey + (i - offset);
|
|
|
|
+// Double currentValue = sortedDataMap.get(currentKey);
|
|
|
|
+// if (currentValue == null) {
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 计算绝对值差值
|
|
|
|
+// Double diffValue = Math.abs(baseValue - currentValue);
|
|
|
|
+//
|
|
|
|
+// // 查找并设置值(O(1)复杂度)
|
|
|
|
+// ElementData targetData = yToElementMap.get(currentKey);
|
|
|
|
+// if (targetData != null) {
|
|
|
|
+// targetData.setValue(diffValue);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean accept(FormData fd) {
|
|
public boolean accept(FormData fd) {
|