Compare commits
No commits in common. "c684f4d795265fe3d3b9aa46dec82bce9c7d54f5" and "8b1b593d2331196ead62d73db3d45f7a8897e662" have entirely different histories.
c684f4d795
...
8b1b593d23
|
@ -1,12 +1,11 @@
|
||||||
package com.muyu.rule.common.engine;
|
package com.muyu.rule.common.engine;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.muyu.etl.domain.DataValue;
|
import com.muyu.etl.domain.DataValue;
|
||||||
import com.muyu.rule.common.basic.abstracts.DataEngineDataSetActuator;
|
import com.muyu.rule.common.basic.abstracts.DataEngineDataSetActuator;
|
||||||
import com.muyu.rule.common.domain.DataValueRows;
|
import com.muyu.rule.common.domain.DataValueRows;
|
||||||
import com.muyu.rule.common.utils.ArrayUtil;
|
import com.muyu.rule.common.exception.DeliteException;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,18 +20,16 @@ public class ENGINE_DataSet_asdf_S1 extends DataEngineDataSetActuator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
DataValueRows dataValueRows = get();
|
DataValueRows dataValueRows = get();
|
||||||
DataValue[][] dataValue = dataValueRows.getDataValue();
|
DataValue[][] dataValues = dataValueRows.getDataValue();
|
||||||
ArrayUtil<DataValue[]> arrayUtil = new ArrayUtil<>(dataValue);
|
String key = dataValueRows.getKey();
|
||||||
while (arrayUtil.hasNext()) {
|
JSONObject jsonObject = JSON.parseObject(key);
|
||||||
DataValue[] dataStructures = arrayUtil.next();
|
String o = (String) jsonObject.get(key);
|
||||||
List<DataValue> dataStructureList = Arrays.stream(dataStructures).filter(dataStructure -> dataStructure.getKey().equals("name") && dataStructure.getValue() == null).toList();
|
if (dataValues == null || "".equals(dataValues) || "null".equals(dataValues)) {
|
||||||
if (dataStructureList.size() > 0) {
|
throw new DeliteException();
|
||||||
arrayUtil.remove();
|
}else {
|
||||||
|
System.out.println("数据检测无异常");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataValue[][] currentArray = arrayUtil.getCurrentArray();
|
|
||||||
dataValueRows.setDataValue(currentArray);
|
|
||||||
set(dataValueRows);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,6 @@ public class ENGINE_ROW_HANG_R1 extends DataEngineRowActuator {
|
||||||
DataValueRow dataValueRow = get();
|
DataValueRow dataValueRow = get();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
package com.muyu.rule.common.utils;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.muyu.etl.domain.DataValue;
|
|
||||||
import com.muyu.etl.enums.DataType;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:张承志
|
|
||||||
* @Package:com.muyu.rule.common.utils
|
|
||||||
* @Project:cloud-etl-rule
|
|
||||||
* @name: 数组压栈工具
|
|
||||||
* @Date:2024/9/10 14:46
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Log4j2
|
|
||||||
public class ArrayUtil<T> implements Iterator<T> {
|
|
||||||
|
|
||||||
|
|
||||||
private final T[] originalArray; // 原始数组
|
|
||||||
private T[] currentArray; // 当前数组,用于迭代
|
|
||||||
private int currentIndex; // 当前索引
|
|
||||||
private int lastReturnedIndex; // 上一次调用next()方法时返回的索引
|
|
||||||
private boolean canRemove = false; // 标记是否可以移除元素
|
|
||||||
|
|
||||||
public ArrayUtil(T[] array) {
|
|
||||||
this.originalArray = array;
|
|
||||||
this.currentArray = Arrays.copyOf(array, array.length);
|
|
||||||
this.currentIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return currentIndex < currentArray.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T next() {
|
|
||||||
if (!hasNext()) {
|
|
||||||
throw new IllegalStateException("No more elements");
|
|
||||||
}
|
|
||||||
lastReturnedIndex = currentIndex;
|
|
||||||
canRemove = true; // 调用next()后可以调用remove()
|
|
||||||
return currentArray[currentIndex++];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
if (!canRemove) {
|
|
||||||
throw new IllegalStateException("Cannot call remove() without calling next()");
|
|
||||||
}
|
|
||||||
// 删除元素并更新数组
|
|
||||||
System.arraycopy(currentArray, lastReturnedIndex + 1, currentArray, lastReturnedIndex, currentArray.length - lastReturnedIndex - 1);
|
|
||||||
currentArray = Arrays.copyOf(currentArray, currentArray.length - 1); // 缩小数组大小
|
|
||||||
currentIndex--; // 因为我们移除了当前元素,所以索引应该减一
|
|
||||||
canRemove = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
DataValue[] dataStructures = new DataValue[6];
|
|
||||||
dataStructures[0] = DataValue.builder().value("aaa1").key("name").type(DataType.VARCHAR).label("姓名").build();
|
|
||||||
dataStructures[1] = DataValue.builder().value("aaa2").key("name").type(DataType.VARCHAR).label("姓名").build();
|
|
||||||
dataStructures[2] = DataValue.builder().value("aaa3").key("name").type(DataType.VARCHAR).label("姓名").build();
|
|
||||||
dataStructures[3] = DataValue.builder().value("aaa4").key("name").type(DataType.VARCHAR).label("姓名").build();
|
|
||||||
dataStructures[4] = DataValue.builder().value("aaa5").key("name").type(DataType.VARCHAR).label("姓名").build();
|
|
||||||
dataStructures[5] = DataValue.builder().value("aaa6").key("name").type(DataType.VARCHAR).label("姓名").build();
|
|
||||||
|
|
||||||
ArrayUtil<DataValue> dataStructureArrayUtil = new ArrayUtil<>(dataStructures);
|
|
||||||
log.info(dataStructureArrayUtil.originalArray.length);
|
|
||||||
log.info(JSONObject.toJSONString(dataStructureArrayUtil.originalArray));
|
|
||||||
while (dataStructureArrayUtil.hasNext()){
|
|
||||||
DataValue next = dataStructureArrayUtil.next();
|
|
||||||
if (next.getValue().equals("aaa3")){
|
|
||||||
dataStructureArrayUtil.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.info(dataStructureArrayUtil.currentArray.length);
|
|
||||||
log.info(Arrays.toString(dataStructureArrayUtil.currentArray));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Binary file not shown.
Loading…
Reference in New Issue