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

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.TransformerEpaDeviationCacheDao;
import com.huatek.busi.entity.TransformerEpaData;
import com.huatek.busi.entity.TransformerEpaDeviationCache;
import com.huatek.busi.mapper.TransformerEpaDeviationCacheMapper;
import com.huatek.busi.service.transformer.TransformerEpaDeviationCacheService;

/**
 * 变压器油色偏差率暂存数据（类型编码 ：021002） ServiceImpl
 *
 * @author anker_cheng
 * @date Jul 15, 2019 11:49:08 AM
 */
@Component
@Service(interfaceClass = TransformerEpaDeviationCacheService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerEpaDeviationCacheServiceImpl implements TransformerEpaDeviationCacheService {

    @Autowired
    private TransformerEpaDeviationCacheMapper transformerEpaDeviationCacheMapper;
    @Autowired
    private TransformerEpaDeviationCacheDao transformerEpaDeviationCacheDao;

    @Override
    public synchronized void saveTransformerEpaDeviationCache(TransformerEpaDeviationCache entity,
        TransformerEpaData cacEntity) {
        entity.setEquipmentId(cacEntity.getEquipmentId());
        entity.setMainEquipmentId(cacEntity.getMainEquipmentId());
        entity.setSubEquipmentId(cacEntity.getSubEquipmentId());
        entity.setSiteId(cacEntity.getSiteId());
        entity.setMainTreeId(cacEntity.getMainTreeId());
        entity.setSubTreeId(cacEntity.getSubTreeId());
        entity.setSensorCode(cacEntity.getSensorId());
        TransformerEpaDeviationCache find = transformerEpaDeviationCacheMapper.findBySubEquipmentId(entity);
        if (find != null) {
            entity.setId(find.getId());
        }
        transformerEpaDeviationCacheDao.saveOrUpdate(entity);
    }
}