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

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;

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.TransformerEpaIncreaseStatisticsDao;
import com.huatek.busi.entity.TransformerEpaIncreaseStatistics;
import com.huatek.busi.mapper.TransformerEpaIncreaseStatisticsMapper;
import com.huatek.busi.service.transformer.TransformerEpaIncreaseStatisticsService;
import com.huatek.frame.base.util.BeanUtils;

/**
 * 变压器油色谱增长率统计 ServiceImpl
 *
 * @author anker_cheng
 * @date Jul 15, 2019 11:49:08 AM
 */
@Component
@Service(interfaceClass = TransformerEpaIncreaseStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerEpaIncreaseStatisticsServiceImpl implements TransformerEpaIncreaseStatisticsService {

    @Autowired
    private TransformerEpaIncreaseStatisticsMapper transformerEpaIncreaseStatisticsMapper;
    @Autowired
    private TransformerEpaIncreaseStatisticsDao transformerEpaIncreaseStatisticsDao;

    @Override
    public void saveTransformerEpaIncreaseStatistics(LocalDateTime beforeDate, TransformerEpaIncreaseStatistics param) {
        TransformerEpaIncreaseStatistics transformerEpaIncreaseStatistics =
            transformerEpaIncreaseStatisticsMapper.getTransformerEpaIncreaseStatistics(param);
        if (transformerEpaIncreaseStatistics == null) {
            transformerEpaIncreaseStatistics = new TransformerEpaIncreaseStatistics();
        }
        BeanUtils.copyPropertiesWithIgnoreNull(param, transformerEpaIncreaseStatistics);
        transformerEpaIncreaseStatisticsDao.saveOrUpdate(transformerEpaIncreaseStatistics);
    }

    @Override
    public Map<String, Object> getGrowthRateMap(String sensorCode, LocalDate day) {
         return transformerEpaIncreaseStatisticsMapper.getGrowthRateMap(sensorCode, day);
    }
}