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.SubstationMicMid;
import com.huatek.busi.mapper.SubstationMicMidMapper;
import com.huatek.busi.service.substation.SubstationMicMidService;
import com.huatek.busi.dao.SubstationMicMidDao;
import com.huatek.busi.dto.SubstationMicMidDto;
import com.huatek.busi.vo.SubstationMicMidVo;
import com.huatek.frame.base.util.BeanUtils;

/**
 * 变电站微气象中间表 ServiceImpl
 *
 * @author anker_cheng
 * @date Jul 17, 2019 10:21:44 AM
 */
@Component
@Service(interfaceClass = SubstationMicMidService.class)
@Transactional(rollbackFor = Exception.class)
public class SubstationMicMidServiceImpl implements SubstationMicMidService {

    @Autowired
    private SubstationMicMidMapper substationMicMidMapper;
    @Autowired
    private SubstationMicMidDao substationMicMidDao;

    @Override
    public Page<SubstationMicMidVo> findSubstationMicMidPage(SubstationMicMidDto substationMicMidDto){
        if(substationMicMidDto.getPage() != null && substationMicMidDto.getLimit() != null){
            PageHelper.startPage(substationMicMidDto.getPage(), substationMicMidDto.getLimit());
        }
        Page<SubstationMicMidVo> substationMicMids = substationMicMidMapper.selectSubstationMicMidPage(substationMicMidDto);
        return substationMicMids;
    }

    @Override
    public int addSubstationMicMid(String token,SubstationMicMidDto substationMicMidDto){
        SubstationMicMid substationMicMid = new SubstationMicMid();
        BeanUtils.copyPropertiesWithIgnoreNull(substationMicMidDto, substationMicMid);
        int count = substationMicMidDao.add(substationMicMid);
        return count;
    }

    @Override
    public SubstationMicMid findSubstationMicMid(String id){
        return substationMicMidDao.get(id);
    }

    @Override
    public int updateSubstationMicMid(String token, SubstationMicMidDto substationMicMidDto){
        SubstationMicMid substationMicMid = new SubstationMicMid();
        BeanUtils.copyPropertiesWithIgnoreNull(substationMicMidDto, substationMicMid);
        int count = substationMicMidDao.updateLocal(substationMicMid);
        return count;
    }

    @Override
    public int deleteSubstationMicMid(String token, SubstationMicMidDto substationMicMidDto){
        int count = substationMicMidDao.del(substationMicMidDto.getId());
        return count;
    }

}