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

import java.time.LocalDateTime;
import java.util.Arrays;
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.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.dao.BusiOutlineTransformerExperimentDataDao;
import com.huatek.busi.dto.BusiOutlineTransformerExperimentDataDto;
import com.huatek.busi.entity.BusiOutlineTransformerExperimentData;
import com.huatek.busi.mapper.BusiOutlineTransformerExperimentDataMapper;
import com.huatek.busi.service.BusiOutlineTransformerExperimentDataService;
import com.huatek.busi.service.transformer.BusiTransformerExperimentService;
import com.huatek.busi.vo.BusiOutlineTransformerExperimentDataVo;
import com.huatek.frame.base.util.BeanUtils;

/**
 * 离线数据--变压器试验数据 ServiceImpl
 *
 * @author walker_wang
 * @date Jul 4, 2019 4:54:08 PM
 */
@Component
@Service(interfaceClass = BusiOutlineTransformerExperimentDataService.class)
@Transactional(rollbackFor = Exception.class)
public class BusiOutlineTransformerExperimentDataServiceImpl implements BusiOutlineTransformerExperimentDataService {

    @Autowired
    private BusiOutlineTransformerExperimentDataMapper busiOutlineTransformerExperimentDataMapper;
    @Autowired
    private BusiOutlineTransformerExperimentDataDao busiOutlineTransformerExperimentDataDao;
    
    
    @Autowired
    private BusiTransformerExperimentService busiTransformerExperimentService ;

    @Override
    public PageInfo<BusiOutlineTransformerExperimentDataVo> findBusiOutlineTransformerExperimentDataPage(BusiOutlineTransformerExperimentDataDto busiOutlineTransformerExperimentDataDto){
        return PageHelper.startPage(busiOutlineTransformerExperimentDataDto.getPage(), busiOutlineTransformerExperimentDataDto.getLimit())
            .doSelectPageInfo(() -> busiOutlineTransformerExperimentDataMapper.selectBusiOutlineTransformerExperimentDataPage(busiOutlineTransformerExperimentDataDto));
    }

    @Override
    public void addBusiOutlineTransformerExperimentData(String token,BusiOutlineTransformerExperimentDataDto busiOutlineTransformerExperimentDataDto){
        BusiOutlineTransformerExperimentData busiOutlineTransformerExperimentData = new BusiOutlineTransformerExperimentData();
        BeanUtils.copyPropertiesWithIgnoreNull(busiOutlineTransformerExperimentDataDto, busiOutlineTransformerExperimentData);
        busiOutlineTransformerExperimentData.setCreateTime(LocalDateTime.now());
        busiOutlineTransformerExperimentData.setExperimentDateTime(LocalDateTime.now());
        busiOutlineTransformerExperimentData.setStatus("A");
        int count =  busiOutlineTransformerExperimentDataDao.add(busiOutlineTransformerExperimentData);
        if(count > 0 ){
        	busiTransformerExperimentService.createBusiTransformerExperiment(busiOutlineTransformerExperimentData);
        }
    }

    @Override
    public BusiOutlineTransformerExperimentData findBusiOutlineTransformerExperimentData(String id){
        return busiOutlineTransformerExperimentDataDao.get(id);
    }

    @Override
    public int updateBusiOutlineTransformerExperimentData(String token, BusiOutlineTransformerExperimentDataDto busiOutlineTransformerExperimentDataDto){
        BusiOutlineTransformerExperimentData busiOutlineTransformerExperimentData = new BusiOutlineTransformerExperimentData();
        BeanUtils.copyPropertiesWithIgnoreNull(busiOutlineTransformerExperimentDataDto, busiOutlineTransformerExperimentData);
        int count = busiOutlineTransformerExperimentDataDao.updateLocal(busiOutlineTransformerExperimentData);
        if(count > 0 ){
        	busiTransformerExperimentService.createBusiTransformerExperiment(busiOutlineTransformerExperimentData);
        }
        return count;
    }

    @Override
    public void deleteBusiOutlineTransformerExperimentData(String [] ids){
    	List<String> asList = Arrays.asList(ids);
    	busiOutlineTransformerExperimentDataMapper.batchDel(asList);
    }

	@Override
	public BusiOutlineTransformerExperimentData findBusiOutlineDataByEquip(String equipmentId, String siteId) {
		return busiOutlineTransformerExperimentDataMapper.findBusiOutlineDataByEquip(equipmentId, siteId);
	}

}