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

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.Page;
import com.github.pagehelper.PageHelper;
import com.huatek.busi.entity.SubstationMicStatistics;
import com.huatek.busi.mapper.SubstationMicStatisticsMapper;
import com.huatek.busi.service.substation.SubstationMicStatisticsService;
import com.huatek.busi.dao.SubstationMicStatisticsDao;
import com.huatek.busi.dto.SubstationMicStatisticsDto;
import com.huatek.busi.vo.SubstationMicStatisticsVo;
import com.huatek.frame.base.util.BeanUtils;

/**
 * 变电站微气象日统计 ServiceImpl
 *
 * @author anker_cheng
 * @date Jul 17, 2019 10:21:43 AM
 */
@Component
@Service(interfaceClass = SubstationMicStatisticsService.class)
@Transactional(rollbackFor = Exception.class)
public class SubstationMicStatisticsServiceImpl implements SubstationMicStatisticsService {

    @Autowired
    private SubstationMicStatisticsMapper substationMicStatisticsMapper;
    @Autowired
    private SubstationMicStatisticsDao substationMicStatisticsDao;

    @Override
    public Page<SubstationMicStatisticsVo> findSubstationMicStatisticsPage(SubstationMicStatisticsDto substationMicStatisticsDto){
        if(substationMicStatisticsDto.getPage() != null && substationMicStatisticsDto.getLimit() != null){
            PageHelper.startPage(substationMicStatisticsDto.getPage(), substationMicStatisticsDto.getLimit());
        }
        Page<SubstationMicStatisticsVo> substationMicStatisticss = substationMicStatisticsMapper.selectSubstationMicStatisticsPage(substationMicStatisticsDto);
        return substationMicStatisticss;
    }

    @Override
    public int addSubstationMicStatistics(String token,SubstationMicStatisticsDto substationMicStatisticsDto){
        SubstationMicStatistics substationMicStatistics = new SubstationMicStatistics();
        BeanUtils.copyPropertiesWithIgnoreNull(substationMicStatisticsDto, substationMicStatistics);
        int count = substationMicStatisticsDao.add(substationMicStatistics);
        return count;
    }

    @Override
    public SubstationMicStatistics findSubstationMicStatistics(String id){
        return substationMicStatisticsDao.get(id);
    }

    @Override
    public int updateSubstationMicStatistics(String token, SubstationMicStatisticsDto substationMicStatisticsDto){
        SubstationMicStatistics substationMicStatistics = new SubstationMicStatistics();
        BeanUtils.copyPropertiesWithIgnoreNull(substationMicStatisticsDto, substationMicStatistics);
        int count = substationMicStatisticsDao.updateLocal(substationMicStatistics);
        return count;
    }

    @Override
    public int deleteSubstationMicStatistics(String token, SubstationMicStatisticsDto substationMicStatisticsDto){
        int count = substationMicStatisticsDao.del(substationMicStatisticsDto.getId());
        return count;
    }

}