package com.foreverwin.mesnac.meapi.service.impl;

import com.foreverwin.modular.core.util.FrontPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.foreverwin.mesnac.meapi.model.Router;
import com.foreverwin.mesnac.meapi.mapper.RouterMapper;
import com.foreverwin.mesnac.meapi.service.RouterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Leon.L
 * @since 2021-06-02
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> implements RouterService {


    @Autowired
    private RouterMapper routerMapper;

    @Override
    public IPage<Router> selectPage(FrontPage<Router> frontPage, Router router) {
        QueryWrapper<Router> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(router);
        return super.page(frontPage.getPagePlus(), queryWrapper);
    }

    @Override
    public List<Router> selectList(Router router) {
        QueryWrapper<Router> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(router);
        return super.list(queryWrapper);
    }

    @Override
    public Router getRouterBySfcBo(String sfcBo) {
        return routerMapper.selectRouterBySfcBo(sfcBo);
    }

    @Override
    public Router getCurrentRouter(String routerBo) {
        return routerMapper.selectCurrentRouter(routerBo);
    }

    @Override
    public Router getMaxRevisionRouter(String site, String router) {
        List<Router> list = routerMapper.selectRouterList4RevisionDesc(site, router);
        if (list == null || list.size() <= 0) {
            return null;
        }

        return list.get(0);
    }


}