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.TransformerIcgeStatisticsDao;
import com.huatek.busi.entity.TransformerIcgeStatistics;
import com.huatek.busi.mapper.TransformerIcgeStatisticsMapper;
import com.huatek.busi.service.transformer.TransformerIcgeStatisticsService;
import com.huatek.busi.vo.TransformerIcgeCountVo;

/**
 * 铁芯接地日统计表 ServiceImpl
 *
 * @author anker_cheng
 * @date Jul 29, 2019 3:40:35 PM
 */
@Component
@Service(interfaceClass = TransformerIcgeStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerIcgeStatisticsServiceImpl implements TransformerIcgeStatisticsService {

    @Autowired
    private TransformerIcgeStatisticsMapper transformerIcgeStatisticsMapper;
    @Autowired
    private TransformerIcgeStatisticsDao transformerIcgeStatisticsDao;

    @Override
    public void saveTransformerIcgeStatistics(LocalDate day, TransformerIcgeCountVo item) {
        // 删除旧记录
        transformerIcgeStatisticsMapper.deleteItem(item.getSensorCode(), day);
        // 保存新记录
        TransformerIcgeStatistics entity = new TransformerIcgeStatistics();
        entity.setSiteId(item.getSiteId());
        entity.setMainEquipmentId(item.getMainEquipmentId());
        entity.setSubEquipmentId(item.getSubEquipmentId());
        entity.setDTime(day);
        entity.setType(item.getType());
        entity.setTotalCoreCurrent(item.getAvgTotalCoreCurrent());
        entity.setCreateTime(LocalDateTime.now());
        entity.setSensorCode(item.getSensorCode());
        transformerIcgeStatisticsDao.saveOrUpdate(entity);
    }

}