package com.huatek.busi.service.impl.transformer;

import java.time.LocalDate;
import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.dao.TransformerInfraredMonitoringStatisticsDao;
import com.huatek.busi.entity.TransformerInfraredMonitoringStatistics;
import com.huatek.busi.mapper.TransformerInfraredMonitoringStatisticsMapper;
import com.huatek.busi.service.transformer.TransformerInfraredMonitoringStatisticsService;
import com.huatek.busi.vo.InfraredTemperatureStatisticsVo;

/**
 * 变压器红外监统计 ServiceImpl
 *
 * @author anker_cheng
 * @date Oct 28, 2019 11:31:08 AM
 */
@Component
@Service(interfaceClass = TransformerInfraredMonitoringStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerInfraredMonitoringStatisticsServiceImpl
    implements TransformerInfraredMonitoringStatisticsService {

    @Autowired
    private TransformerInfraredMonitoringStatisticsMapper transformerInfraredMonitoringStatisticsMapper;
    @Autowired
    private TransformerInfraredMonitoringStatisticsDao transformerInfraredMonitoringStatisticsDao;

    @Override
    public void saveStatistics(LocalDate day, InfraredTemperatureStatisticsVo item) {
        // 删除旧数据
        transformerInfraredMonitoringStatisticsMapper.deleteItem(item.getSensorCode(), day,
            item.getCacMonitorTypeCode());
        // 保存新数据
        TransformerInfraredMonitoringStatistics entity = new TransformerInfraredMonitoringStatistics();
        entity.setSiteId(item.getSiteId());
        entity.setSensorId(item.getSensorCode());
        entity.setMainTreeId(item.getMainTreeId());
        entity.setSubTreeId(item.getSubTreeId());
        entity.setCacMonitorTypeCode(item.getCacMonitorTypeCode());
        entity.setDTime(day);
        entity.setCreateTime(LocalDateTime.now());
        entity.setAvgMaxTmp(item.getAvgMaxTmp());
        entity.setAvgMinTmp(item.getAvgMinTmp());
        entity.setAvgMinTmp(item.getAvgAvgTmp());
        transformerInfraredMonitoringStatisticsDao.saveOrUpdate(entity);
    }

}