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.rule.common.basic.abstracts.DataEngineDataSetActuator;
import com.muyu.rule.common.domain.DataValueRows;
import com.muyu.rule.common.utils.ArrayUtil;

import java.util.Arrays;
import java.util.List;


/**
 * @Author：张承志
 * @Package：com.muyu.rule.server.basic.engine.row
 * @Project：cloud-etl-rule
 * @name：数据集根据字段去空
 * @Date：2024/8/30 11:13
 */

public class ENGINE_DataSet_asdf_S1 extends DataEngineDataSetActuator {

    @Override
    public void run() {
        DataValueRows dataValueRows = get();
        DataValue[][] dataValue = dataValueRows.getDataValue();
        String key1 = dataValueRows.getKey();
        JSONObject jsonObject = JSON.parseObject(key1);
        String key = (String)jsonObject.get("key");

        ArrayUtil<DataValue[]> arrayUtil = new ArrayUtil<>(dataValue);
        while (arrayUtil.hasNext()) {
            DataValue[] dataStructures = arrayUtil.next();
            List<DataValue> dataStructureList = Arrays.stream(dataStructures).filter(dataStructure -> dataStructure.getKey().equals(key) && dataStructure.getValue() == null).toList();
            if (dataStructureList.size() > 0) {
                arrayUtil.remove();
            }
        }
        DataValue[][] currentArray = arrayUtil.getCurrentArray();
        dataValueRows.setDataValue(currentArray);
        set(dataValueRows);
    }
}
