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

import java.time.LocalDate;
import java.util.UUID;

import com.huatek.torch.util.uuid.Uuid;
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.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.dao.TransformerEvaluationResultsDao;
import com.huatek.busi.entity.TransformerEvaluationResults;
import com.huatek.busi.mapper.TransformerEvaluationResultsMapper;
import com.huatek.busi.service.transformer.TransformerEvaluationResultsService;
import com.huatek.busi.vo.TransformerEvaluationResultsVo;

/**
  * @ClassName: TransformerEvaluationResultsServiceImpl
  * @FullClassPath: com.huatek.busi.service.impl.transformer.TransformerEvaluationResultsServiceImpl
  * @Description: 变压器评测结果服务.
  * @author: Arno
  * @date: Sep 11, 2019 5:28:39 PM
  * @version: 1.0
  */
@Component
@Service(interfaceClass = TransformerEvaluationResultsService.class)
@Transactional(rollbackFor = Exception.class)
public class TransformerEvaluationResultsServiceImpl implements TransformerEvaluationResultsService {

	@Autowired
	private TransformerEvaluationResultsDao transformerEvaluationResultsDao;

	@Autowired
	private TransformerEvaluationResultsMapper transformerEvaluationResultsMapper;

	@Override
	public void save(TransformerEvaluationResults entity){
		entity.setId(Uuid.getUUID());
		transformerEvaluationResultsDao.add(entity);
	}

	@Override
	public PageInfo<TransformerEvaluationResultsVo> page(String mainTreeId, LocalDate start, LocalDate end, Integer page, Integer limit, String type) {
		return PageHelper.startPage(page == null ? 1 :page , limit == null? 1 : limit)
		        .doSelectPageInfo(() -> transformerEvaluationResultsMapper.page(mainTreeId,start,end, type));
	}

	@Override
	public TransformerEvaluationResultsVo findLatestResult(String mainTreeId) {
		return transformerEvaluationResultsMapper.findLatestResult(mainTreeId);
	}
}
