package org.nl.system.service.lucene.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.enums.LogTypeEnum;
import org.nl.system.service.lucene.LuceneExecuteLogService;
import org.nl.system.service.lucene.dto.LuceneLogDto;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;

/**
 * @author jlm
 * @description 服务实现
 * @date 2023-04-11
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {

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

    @Override
    public void deviceExecuteLog(LuceneLogDto luceneLogDto) {
        luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
        log.info("{}", JSON.toJSONString(luceneLogDto));
    }

    @Override
    public void interfaceExecuteLog(LuceneLogDto luceneLogDto) {
        luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
        log.info("{}", JSON.toJSONString(luceneLogDto));
    }

    @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);
        }
    }
}
