package org.nl.acs.log.service.impl;

import cn.hutool.core.date.DateUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.opc.OpcUtl;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;

/**
 * @author loujf
 * @description 服务实现
 * @date 2022-02-25
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class DeviceExecuteLogServiceImpl implements DeviceExecuteLogService {

  @Override
  public void deviceItemValue(String device_code, String key, String value) {
    String now = DateUtil.now();
  }

  @Override
  public void deviceExecuteLog(
          String device_code, String vehicle_code, String inst_code, String message) {
    try {
      MDC.put("device_code_log", device_code);
      log.info("{},{}", device_code, message);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      MDC.remove("device_code_log");
      log.info("successNum:" + OpcUtl.successNum);
      log.info("errNum:" + OpcUtl.errNum);
    }
  }

  @Override
  public void extLog(String name, String message) {
    try {
      MDC.put(name, name);
      log.info("{}", message);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      MDC.remove(name);
    }
  }
}
