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

import com.bocloud.common.model.*;
import com.bocloud.ims.entity.resource.fusionsphere.FusionSphereOsVersion;
import com.bocloud.ims.interfaces.resource.fusionsphere.FusionSphereOsVersionService;
import com.bocloud.ims.repository.resource.fusionsphere.FusionSphereOsVersionRepository;
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;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: FusionSphereOsVersionServiceImpl
 * @Description:获取操作系统
 * @author: zhenpingLi/李振平
 * @date: 2021/11/3 13:45
 */
@Service
@Slf4j
public class FusionSphereOsVersionServiceImpl implements FusionSphereOsVersionService {

    @Autowired
    private FusionSphereOsVersionRepository osVersionRepository;

    @Override
    public BocloudResult<GridBean<FusionSphereOsVersion>> 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 = osVersionRepository.count(params);
            List<FusionSphereOsVersion> list = this.osVersionRepository.list(page, rows, params, sorter);
            GridBean<FusionSphereOsVersion> gridBean = new GridBean<>(page, rows, total, list);
            return new BocloudResult<>(true, gridBean, "查询成功");
        } catch (Exception e) {
            log.error("list OsVersion error!", e);
            return new BocloudResult<>(false, "查询失败:" + e.getMessage());
        }
    }
}