package com.yihu.jw.monitor.service;

import com.yihu.jw.entity.base.message.BaseMessageDO;
import com.yihu.jw.entity.base.system.BaseInterfaceDictDO;
import com.yihu.jw.entity.base.system.BaseInterfaceMonitorDO;
import com.yihu.jw.entity.base.system.BaseSourceDictDO;
import com.yihu.jw.message.dao.MessageDao;
import com.yihu.jw.monitor.dao.BaseInterfaceDictDao;
import com.yihu.jw.monitor.dao.BaseInterfaceMonitorDao;
import com.yihu.jw.monitor.dao.BaseSourceDictDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BaseInterfaceMonitorService extends BaseJpaService<BaseInterfaceMonitorDO, BaseInterfaceMonitorDao> {

    @Autowired
    private BaseInterfaceMonitorDao baseInterfaceMonitorDao;
    @Autowired
    private BaseSourceDictDao baseSourceDictDao;
    @Autowired
    private BaseInterfaceDictDao baseInterfaceDictDao;
    public void saveInterfaceMonitor(String source ,String functionName,Integer time ,String startTime,String endTime){
        BaseInterfaceMonitorDO baseInterfaceMonitorDO = new BaseInterfaceMonitorDO();
        baseInterfaceMonitorDO.setSource(source);
        BaseSourceDictDO baseSourceDictDO=baseSourceDictDao.findSourceBySource(source);
        if (null!=baseSourceDictDO){
            baseInterfaceMonitorDO.setSourceName(baseSourceDictDO.getSourceName());
        }
        BaseInterfaceDictDO baseInterfaceDictDO=baseInterfaceDictDao.findByinterfaceName(functionName);
        if (null!=baseInterfaceDictDO){
            baseInterfaceMonitorDO.setTypeName(baseInterfaceDictDO.getInterfaceTypeName());
            baseInterfaceMonitorDO.setType(Integer.valueOf(baseInterfaceDictDO.getInterfaceType()));
        }
        baseInterfaceMonitorDO.setTime(time);
        if (StringUtils.isNotBlank(startTime)){
            baseInterfaceMonitorDO.setStartTime(DateUtil.strToDate(startTime));
        }
        if (StringUtils.isNotBlank(startTime)){
            baseInterfaceMonitorDO.setEndTime(DateUtil.strToDate(endTime));
        }
        baseInterfaceMonitorDao.save(baseInterfaceMonitorDO);
    }
}
