package com.huatek.busi.service.impl;


import java.time.LocalDate;
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.BusiTransformerLoadDao;
import com.huatek.busi.entity.BusiTransformerLoad;
import com.huatek.busi.mapper.BusiTransformerLoadMapper;
import com.huatek.busi.service.BusiTransformerLoadService;



/**
  * @ClassName: BusiTransformerLoadServiceImpl
  * @Description: TODO.
  * @author: arno
  * @Email : arno_fu@huatek.com
  * @date: 2018-09-19 14:24:15
  * @version: 1.0
  */

@Component
@Service(interfaceClass = BusiTransformerLoadService.class)
@Transactional(rollbackFor = Exception.class)
public class BusiTransformerLoadServiceImpl implements BusiTransformerLoadService {
	@Autowired
	private BusiTransformerLoadMapper busiTransformerLoadMappder;
	@Autowired
	private BusiTransformerLoadDao busiTransformerLoadDao;

    @Override
    public void saveOrUpdateLoad(String siteId, String mainTreeId, String brandId, LocalDate loadTime,
        String loadRate) {
        BusiTransformerLoad entity = new BusiTransformerLoad();
        entity.setSiteId(siteId);
        entity.setMainTreeId(mainTreeId);
        entity.setEquipmentId(brandId);
        entity.setLoadRate(loadRate);
        entity.setLoadTime(loadTime);
        // 查找
        BusiTransformerLoad oldOne = busiTransformerLoadMappder.getLoaByEquipmentIdAndDate(siteId, brandId, loadTime);
        if(oldOne != null) {
            entity.setId(oldOne.getId());
        }
        busiTransformerLoadDao.saveOrUpdate(entity);
    }

	@Override
	public BusiTransformerLoad getLoaByEquipmentIdAndDate(String siteId, String equipmentId, LocalDate loadTime) {
		return busiTransformerLoadMappder.getLoaByEquipmentIdAndDate(siteId, equipmentId, loadTime);
	}

	@Override
	public List<BusiTransformerLoad> getLoaByEquipmentIdAndDates(String siteId, String equipmentId, LocalDate startTime,
			LocalDate endTime) {
		return busiTransformerLoadMappder.getLoaByEquipmentIdAndDates(siteId, equipmentId, startTime, endTime);
	}

    @Override
    public String getLoadRate(String mainTreeId, LocalDate loaddTime) {
         return busiTransformerLoadMappder.getLoadRate(mainTreeId, loaddTime);
    }
}