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

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

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.TransformerPdStatisticsDao;
import com.huatek.busi.entity.TransformerPdStatistics;
import com.huatek.busi.mapper.TransformerPdStatisticsMapper;
import com.huatek.busi.service.transformer.TransformerPdStatisticsService;
import com.huatek.busi.vo.TransformerPdCountVo;

@Component
@Service(interfaceClass = TransformerPdStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerPdStatisticsServiceImpl implements TransformerPdStatisticsService {
    @Autowired
    private TransformerPdStatisticsMapper transformerPdStatisticsMapper;
    @Autowired
    private TransformerPdStatisticsDao transformerPdStatisticsDao;

    @Override
    public TransformerPdStatistics
        findTransformerGisPdStatistics(String siteId, String mainTreeId) {
        return transformerPdStatisticsMapper.findTransformerGisPdStatistics(siteId, mainTreeId);
    }

    @Override
    public void saveTransformerPdStatistics(TransformerPdCountVo item, LocalDate day) {
        // 删除记录
        transformerPdStatisticsMapper.deleteItem(item.getMainTreeId(), day);
        // 保存新记录
        TransformerPdStatistics entity = new TransformerPdStatistics();
        entity.setSiteId(item.getSiteId());
        entity.setMainTreeId(item.getMainTreeId());
        entity.setPdType(item.getCacMonitorTypeCode());
        entity.setDTime(day);
        entity.setCount(item.getDataCount());
        entity.setCratetime(LocalDateTime.now());
        entity.setElectricQuantity(item.getCapacityTotal());
        transformerPdStatisticsDao.saveOrUpdate(entity);
    }
}