class WorkerGroupService extends BaseService {

    public Map<String,Object> queryAllGroupPaging(User loginUser, Integer pageNo, Integer pageSize, String searchVal) {

        // list from index
        Integer fromIndex = (pageNo - 1) * pageSize;
        // list to index
        Integer toIndex = (pageNo - 1) * pageSize + pageSize;

        Map<String, Object> result = new HashMap<>();
        if (checkAdmin(loginUser, result)) {
            return result;
        }

        List<WorkerGroup> workerGroups = getWorkerGroups(true);

        List<WorkerGroup> resultDataList = new ArrayList<>();

        if (CollectionUtils.isNotEmpty(workerGroups)){
            List<WorkerGroup> searchValDataList = new ArrayList<>();

            if (StringUtils.isNotEmpty(searchVal)){
                for (WorkerGroup workerGroup : workerGroups){
                    if (workerGroup.getName().contains(searchVal)){
                        searchValDataList.add(workerGroup);
                    }
                }
            }else {
                searchValDataList = workerGroups;
            }

            if (searchValDataList.size() < pageSize){
                toIndex = (pageNo - 1) * pageSize + searchValDataList.size();
            }
            resultDataList = searchValDataList.subList(fromIndex, toIndex);
        }

        PageInfo<WorkerGroup> pageInfo = new PageInfo<>(pageNo, pageSize);
        pageInfo.setTotalCount(resultDataList.size());
        pageInfo.setLists(resultDataList);

        result.put(Constants.DATA_LIST, pageInfo);
        putMsg(result, Status.SUCCESS);
        return result;
    }

}