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;


/**
 * @Author：张承志
 * @Package：com.muyu.rule.server.basic.engine.row
 * @Project：cloud-etl-rule
 * @name：数据集指定字段进行脱敏
 * @Date：2024/8/30 11:13
 */

public class ENGINE_DataSet_ytrrt_S3 extends DataEngineDataSetActuator {

    @Override
    public void run() {

        DataValueRows dataValueRows = get();
        String json = dataValueRows.getKey();
        JSONObject jsonObject = JSON.parseObject(json);
        String key = (String) jsonObject.get("key");
        String valueFie = (String) jsonObject.get("value");
        DataValue[][] dataValue = dataValueRows.getDataValue();
        for (int i = 0; i < dataValue.length; i++) {
            for (int j = 0; j < dataValue[i].length; j++) {
                if (dataValue[i][j].getKey().equals(key) ) {
                    if (dataValue[i][j].getValue()==null || dataValue[i][j].getValue().equals("")) {
                        dataValue[i][j].setValue(valueFie);
                    }
                }
            }
        }
        dataValueRows.setDataValue(dataValue);
        set(dataValueRows);
    }
}
