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

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.dao.CwzzMonitoringStatisticsDao;
import com.huatek.busi.entity.CwzzMonitoringStatistics;
import com.huatek.busi.mapper.CwzzMonitoringStatisticsMapper;
import com.huatek.busi.service.transformer.CwzzMonitoringStatisticsService;
import com.huatek.busi.vo.CwzzTemperatureStatisticsVo;
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 = CwzzMonitoringStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class CwzzMonitoringStatisticsServiceImpl
    implements CwzzMonitoringStatisticsService {

    @Autowired
    private CwzzMonitoringStatisticsMapper cwzzMonitoringStatisticsMapper;

    @Autowired
    private CwzzMonitoringStatisticsDao cwzzMonitoringStatisticsDao;

    @Override
    public void saveStatistics(LocalDate day, CwzzTemperatureStatisticsVo item) {
        // 删除旧数据
        cwzzMonitoringStatisticsMapper.deleteItem(item.getSensorCode(), day,
            item.getCacMonitorTypeCode());
        // 保存新数据
        CwzzMonitoringStatistics entity = new CwzzMonitoringStatistics();
        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.setAvgTmp(item.getAvgTmp());
        cwzzMonitoringStatisticsDao.saveOrUpdate(entity);
    }

}