package com.bocloud.ims.service.resource;

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.GridHelper;
import com.bocloud.ims.entity.resource.ResourceAccount;
import com.bocloud.ims.interfaces.resource.ResourceAccountService;
import com.bocloud.ims.repository.resource.ResourceAccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service("resourceAccountService")
public class ResourceAccountServiceImpl implements ResourceAccountService {

    @Autowired
    private ResourceAccountRepository resourceAccountRepository;

    @Override
    public BocloudResult<GridBean<ResourceAccount>> list(Pager pager) {

        int page = pager.getPage();
        int rows = pager.getRows();
        List<Param> params = pager.getParams();
        Map<String, String> sorter = pager.getSorter();
        boolean simple = pager.getSimple();

        List<ResourceAccount> list = resourceAccountRepository.list(page, rows, params, sorter);
        int total = resourceAccountRepository.count(params);
        GridBean gridBean = GridHelper.getBean(page, rows, total, list);
        return new BocloudResult<>(true, gridBean, "Success");
    }
}
