package cn.edu.whu.boot.collection.service.impl;

import cn.edu.whu.boot.collection.mapper.SearchPageMapper;
import cn.edu.whu.boot.collection.service.ISearchPageService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class SearchPageServiceImpl implements ISearchPageService{

    @Autowired
    private SearchPageMapper searchPageMapper;

    @Override
    public Page<Map<String, Object>> getPageDataByStatus(String tableNameInDB, int status){
        if(status == 0){
            return searchPageMapper.getUncheckedPageData(tableNameInDB);
        }
        else{
            return searchPageMapper.getPageDataByStatus(tableNameInDB, status);
        }
    }

    @Override
    public Page<Map<String, Object>> getPageDataByWorkerAndStatus(String tableNameInDB, Integer workerId, int status) {
        // TODO 统一使用 getPageDataByStatusAndWorker
        if(status == 0){
            return searchPageMapper.getUncheckedPageDataByWorker(tableNameInDB, workerId);
        }
        else{
            return searchPageMapper.getPageDataByStatusAndWorker(tableNameInDB, status, workerId);
        }
    }

    @Override
    public Page<Map<String, Object>> getPageDataByFuzzySearch(String tableNameInDB, String fieldNameInDB, String searchKey){
        return searchPageMapper.getPageDataByFuzzySearch(tableNameInDB, fieldNameInDB, searchKey);
    }
    @Override
    public Page<Map<String, Object>> getPageDataByWorkerNoStatus(String tableNameInDb) {
        return searchPageMapper.getPageDataByWorkerNoStatus(tableNameInDb);
    }

}
