package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyPlcCollectDataJobService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Map;

/**
 * 第三方PLC数据采集-采集生产数据实现
 */
@Slf4j
@Service(value = "SxThirdPartyPlcCollectProductDataService")
public class SxThirdPartyPlcCollectProductDataService implements ISxThirdPartyPlcCollectDataJobService {

    @Override
    public void doThirdPartyPlcCollectData(Map<String, Object> paramMap) {

        String[] keyArr = new ArrayList<>(paramMap.keySet()).get(0).split(MesPcnExtConstWords.COLON);

        log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE START --- PARAM:{}", keyArr[1], keyArr[0], JSONObject.toJSONString(paramMap));

        if (!SxThirdPartyPlcCollectDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectDispatchSingleton.getInstance();

        SxThirdPartyPlcCollectDispatchSingleton.execMonitor(keyArr[1], keyArr[0], paramMap, false);

        log.info("工厂{}第三方PLC数据采集 --- STRATEGY {} EXEC SERVICE END ---", keyArr[1], keyArr[0]);

    }

}
