package com.gyee.wisdom.alarm.sharding.logtool;

import com.alibaba.fastjson.JSON;
import com.gyee.wisdom.alarm.sharding.entity.Alertrule2;
import com.gyee.wisdom.alarm.sharding.entity.Scadabj;
import com.gyee.wisdom.alarm.sharding.entity.Warning2;
import lombok.extern.slf4j.Slf4j;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @descrition:日志记录工具
 * @author:Wanghs
 * @date:2020-04-23
 */
@Component

public class LogService {
    Logger log = LogManager.getLogger("dataChangeLogger");
    //自定义报警--更新数据
    public void alertRuleUpdateLog(Alertrule2 oldData,Alertrule2 newData,String userName){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Date nowTime=new Date();
        log.info(format.format(nowTime)+"自定义报警数据更新-----------------------------------------------------");
        log.info("操作人："+userName);
        String oldDataString= JSON.toJSONString(oldData);
        log.info("原数据："+oldDataString);
        String newDataString=JSON.toJSONString(newData);
        log.info("新数据："+newDataString);
        log.info("-----------------------------------------------------------------------");
    }
    //自定义报警--添加数据
    public void alertRuleAddLog(Alertrule2 newData,String userName){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowTime=new Date();
        log.info(format.format(nowTime)+"自定义报警数据新增-----------------------------------------------------");
        log.info("操作人："+userName);
        String newDataString=JSON.toJSONString(newData);
        log.info("新数据："+newDataString);
        log.info("-----------------------------------------------------------------------");

    }

    //风机报警--更新数据
    public void windturbineUpdateLog(Warning2 oldData,Warning2 newData,String userName){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowTime=new Date();
        log.info(format.format(nowTime)+"风机报警数据更新-----------------------------------------------------");
        log.info("操作人："+userName);
        String oldDataString= JSON.toJSONString(oldData);
        log.info("原数据："+oldDataString);
        String newDataString=JSON.toJSONString(newData);
        log.info("新数据："+newDataString);
        log.info("---------------------------------------------------------------------");
    }
    //风机报警--添加数据
    public void windturbineAddLog(Warning2 newData, String userName){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowTime=new Date();
        log.info(format.format(nowTime)+"风机报警数据新增-----------------------------------------------------");
        log.info("操作人："+userName);
        String newDataString=JSON.toJSONString(newData);
        log.info("新数据："+newDataString);
        log.info("-----------------------------------------------------------------------");
    }
    //升压站报警--更新数据
    public void scadaUpdateLog(Scadabj oldData,Scadabj newData,String userName){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowTime=new Date();
        log.info(format.format(nowTime)+"升压站报警数据更新-----------------------------------------------------");
        log.info("操作人："+userName);
        String oldDataString= JSON.toJSONString(oldData);
        log.info("原数据："+oldDataString);
        String newDataString=JSON.toJSONString(newData);
        log.info("新数据："+newDataString);
        log.info("-----------------------------------------------------------------------");
    }
    //升压站报警--添加数据
    public void scadaAddLog(Scadabj newData, String userName){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date nowTime=new Date();
        log.info(format.format(nowTime)+"升压站报警数据新增-----------------------------------------------------");
        log.info("操作人："+userName);
        String newDataString=JSON.toJSONString(newData);
        log.info("新数据："+newDataString);
        log.info("-----------------------------------------------------------------------");
    }
}
