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

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.dao.CwzzMonitoringStatisticsDao;
import com.huatek.busi.dao.GeneratorAmplMonitoringStatisticsDao;
import com.huatek.busi.entity.CwzzMonitoringStatistics;
import com.huatek.busi.entity.GeneratorAmplMonitoringStatistics;
import com.huatek.busi.mapper.CwzzMonitoringStatisticsMapper;
import com.huatek.busi.mapper.GeneratorAmplStatisticsMapper;
import com.huatek.busi.service.generatro.GeneratorAmplStatisticsService;
import com.huatek.busi.service.transformer.CwzzMonitoringStatisticsService;
import com.huatek.busi.vo.CwzzTemperatureStatisticsVo;
import com.huatek.busi.vo.GeneratorAmplStatisticsVo;
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;

@Component
@Service(interfaceClass = GeneratorAmplStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class GeneratorAmplStatisticsServiceImpl
    implements GeneratorAmplStatisticsService {

    @Autowired
    private GeneratorAmplStatisticsMapper generatorAmplStatisticsMapper;

    @Autowired
    private GeneratorAmplMonitoringStatisticsDao generatorAmplMonitoringStatisticsDao;

    @Override
    public void saveStatistics(LocalDate day, GeneratorAmplStatisticsVo item) {
        // 删除旧数据
        generatorAmplStatisticsMapper.deleteItem(item.getSensorCode(), day);
        // 保存新数据
        GeneratorAmplMonitoringStatistics entity = new GeneratorAmplMonitoringStatistics();
        entity.setSiteId(item.getSiteId());
        entity.setSensorId(item.getSensorCode());
        entity.setMainTreeId(item.getMainTreeId());
        entity.setSubTreeId(item.getSubTreeId());
        entity.setDTime(day);
        entity.setCreateTime(LocalDateTime.now());
        entity.setTypeId(item.getTypeId());
        entity.setAmplX(item.getAmplX());
        entity.setAmplY(item.getAmplY());
        entity.setAmplZ(item.getAmplZ());
        entity.setAircapAm(item.getAircapAm());
        entity.setAircapBm(item.getAircapBm());
        entity.setAircapCm(item.getAircapCm());
        entity.setAircapDm(item.getAircapDm());
        generatorAmplMonitoringStatisticsDao.saveOrUpdate(entity);
    }

}