package org.dromara.service.impl;

import cn.hutool.core.io.file.FileReader;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Exchange;
import org.dromara.service.ITblSensorRecordService;
import org.dromara.utils.GroovyUtils;
import org.dromara.utils.ScriptCache;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.util.StrUtil;
import io.netty.util.internal.StringUtil;
import lombok.Data;
import org.apache.camel.Exchange;
import org.apache.camel.PropertyInject;
import org.apache.camel.spi.UriParam;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.util.*;

@Component("groovyMessageProcess")
@Slf4j
public class GroovyMessageProcess{

    @Autowired
    private ITblSensorRecordService sensorRecordService;
    public void runScript(String scriptid,Exchange exchange){
        exchange.getOut().setBody(GroovyUtils.runjs(ScriptCache.scriptCache.get(scriptid),Map.of("exchange",exchange,"sensorRecordService",sensorRecordService)));

    }
}


