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

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.RptTemperRecordChartsDao;
import com.huatek.busi.entity.RptTemperRecordCharts;
import com.huatek.busi.mapper.RptTemperRecordChartsMapper;
import com.huatek.busi.service.temperature.RptTemperRecordChartsService;
import com.huatek.busi.vo.CwgTemperatureStatisticsVo;

/**
 * ServiceImpl
 *
 * @author anker_cheng
 * @date Oct 28, 2019 4:24:47 PM
 */
@Component
@Service(interfaceClass = RptTemperRecordChartsService.class)
@Transactional(rollbackFor = Exception.class)
public class RptTemperRecordChartsServiceImpl implements RptTemperRecordChartsService {

    @Autowired
    private RptTemperRecordChartsMapper rptTemperRecordChartsMapper;
    @Autowired
    private RptTemperRecordChartsDao rptTemperRecordChartsDao;

    @Override
    public synchronized void saveRptTemperRecordCharts(LocalDate day, CwgTemperatureStatisticsVo item) {
        // 删除旧数据
        rptTemperRecordChartsMapper.deleteItem(item.getMainTreeId(), item.getSensorCode(), day);
        // 保存新数据
        RptTemperRecordCharts entity = new RptTemperRecordCharts();
        entity.setSiteId(item.getSiteId());
        entity.setMainTreeId(item.getMainTreeId());
        entity.setMainEquipmentId(item.getMainEquipmentId());
        entity.setSensorId(item.getSensorCode());
        entity.setTemper(item.getTmp());
        entity.setHzTime(day);
        entity.setCreateTime(LocalDateTime.now());
        rptTemperRecordChartsDao.saveOrUpdate(entity);
    }

}