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

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.dao.TransformerWindingTemperatureStatisticsDao;
import com.huatek.busi.entity.TransformerWindingTemperatureStatistics;
import com.huatek.busi.mapper.CwzzMonitoringStatisticsMapper;
import com.huatek.busi.mapper.TransformerWindingTemperaturStatisticMapper;
import com.huatek.busi.service.transformer.RzcwMonitoringStatisticsService;
import com.huatek.busi.vo.WindingTemperatureStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

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

    @Autowired
    private TransformerWindingTemperaturStatisticMapper transformerWindingTemperaturStatisticMapper;

    @Autowired
    private TransformerWindingTemperatureStatisticsDao transformerWindingTemperatureStatisticsDao;

    @Override
    public void saveStatistics(LocalDate day, WindingTemperatureStatisticsVo item) {
        // 删除旧数据
        transformerWindingTemperaturStatisticMapper.deleteItem(item.getSensorCode(), day,
            item.getCacMonitorTypeCode());
        // 保存新数据
        TransformerWindingTemperatureStatistics entity = new TransformerWindingTemperatureStatistics();
        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());
        transformerWindingTemperatureStatisticsDao.saveOrUpdate(entity);
    }

}