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

import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.Param;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.GridHelper;
import com.bocloud.ims.entity.resource.f5.BiOutstandingIssues;
import com.bocloud.ims.interfaces.resource.f5.F5OutstandingIssuesService;
import com.bocloud.ims.repository.resource.f5.F5OutstandingIssuesRepository;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by liuyuanyuan on 2019/5/8 17:26
 */
@Service("f5OutstandingIssuesService")
public class F5OutstandingIssuesServiceImpl implements F5OutstandingIssuesService {
    private static final Logger logger = LoggerFactory.getLogger(F5OutstandingIssuesServiceImpl.class);
    @Autowired
    private F5OutstandingIssuesRepository f5OutstandingIssuesRepository;

    @Override
    public BocloudResult<GridBean<BiOutstandingIssues>> list(Pager pager) {
        GridBean gridBean = null;
        try {
            int page = pager.getPage();
            int rows = pager.getRows();
            List<Param> params = pager.getParams();
            Map<String, String> sorter = pager.getSorter();
            boolean simple = pager.getSimple();


            if (null == params) {
                params = Lists.newArrayList();
            }
            if (null == sorter) {
                sorter = Maps.newHashMap();
            }
            sorter.put("applyDate", Common.ONE);
            int total = this.f5OutstandingIssuesRepository.count(params);
            List<BiOutstandingIssues> BiOutstandingIssueses = this.f5OutstandingIssuesRepository.list(page, rows, params, sorter);
            gridBean = GridHelper.getBean(page, rows, total, BiOutstandingIssueses);
            return new BocloudResult(true, gridBean, "查询成功");
        } catch (Exception e) {
            logger.error("Query Outstanding Issues list fail:", e);
            return new BocloudResult(false, "查询失败");
        }
    }

}
