package com.bocloud.ims.service.resource.fusionsphere;

import com.bocloud.common.model.*;
import com.bocloud.ims.entity.resource.fusionsphere.FusionSphereUpLinkPort;
import com.bocloud.ims.interfaces.resource.fusionsphere.FusionSphereUpLinkPortService;
import com.bocloud.ims.repository.resource.fusionsphere.FusionSphereUpLinkPortRepository;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @ClassName: FusionSphereUpLinkPortServiceImpl
 * @Description:上行链路组
 * @author: zhenpingLi/李振平
 * @date: 2021/11/2 16:31
 */
@Service
@Slf4j
public class FusionSphereUpLinkPortServiceImpl implements FusionSphereUpLinkPortService {

    @Autowired
    private FusionSphereUpLinkPortRepository upLinkPortRepository;

    @Override
    public BocloudResult<GridBean<FusionSphereUpLinkPort>> list(Pager pager, RequestContext context) {
        List<Param> params = Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>());
        Map<String, String> sorter = Optional.ofNullable(pager.getSorter()).orElse(Maps.newHashMap());
        Integer page = Optional.ofNullable(pager.getPage()).orElse(1);
        Integer rows = Optional.ofNullable(pager.getRows()).orElse(10);
        try {
            int total = upLinkPortRepository.count(params);
            List<FusionSphereUpLinkPort> list = this.upLinkPortRepository.list(page, rows, params, sorter);
            GridBean<FusionSphereUpLinkPort> gridBean = new GridBean<>(page, rows, total, list);
            return new BocloudResult<>(true, gridBean, "查询成功");
        } catch (Exception e) {
            log.error("list UpLinkPort error!", e);
            return new BocloudResult<>(false, "查询失败:" + e.getMessage());
        }
    }
}