package com.bocloud.ims.service.pbm;

import com.bocloud.common.model.*;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.GridHelper;
import com.bocloud.ims.entity.resource.pbm.PbmProfile;
import com.bocloud.ims.interfaces.pbm.PbmProfileService;
import com.bocloud.ims.repository.pbm.PbmProfileRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * vcenter存储策略
 *
 * @author wangyu
 * @version 1.0
 * @since 2020年2月27日
 */
@Service("pbmProfileService")
public class PbmProfileServiceImpl implements PbmProfileService {

    private static Logger logger = LoggerFactory.getLogger(PbmProfileServiceImpl.class);
    @Autowired
    private PbmProfileRepository profileRepository;

    @Override
    public BocloudResult<GridBean<PbmProfile>> list(Pager pager, RequestContext context) {
        List<PbmProfile> list = null;
        int total = 0;
        GridBean gridBean = null;
        try {
            pager.getSorter().put("createTime", Common.ONE);
            total = profileRepository.count(pager.getParams());
            if (pager.getSimple()) {
                List<SimpleBean> beans = profileRepository.list(pager.getParams(), pager.getSorter());
                gridBean = new GridBean(1, 1, total, beans);
            } else {
                list = profileRepository.list(pager.getPage(), pager.getRows(), pager.getParams(), pager.getSorter());
                gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list);
            }
            return new BocloudResult<>(true, gridBean, "查询成功");
        } catch (Exception e) {
            logger.error("Get error message：{}", e);
            return new BocloudResult<>(false, "查询失败");
        }
    }

}
