package cn.stylefeng.team.project.modular.maxsort.demodata;

import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.team.project.api.ViewDataAction;
import cn.stylefeng.team.project.api.pojo.BusinessSearchRequest;
import cn.stylefeng.team.project.modular.businessrender.sql.ProjectSqlExecuteApi;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

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

@Component
public class DemoViewDataAction implements ViewDataAction {

    @Resource
    private ProjectSqlExecuteApi projectSqlExecuteApi;

    @Override
    public PageResult<Map<String, Object>> getCustomViewData(BusinessSearchRequest businessSearchRequest) {

        Page<Map<String, Object>> objectPage = PageFactory.defaultPage(businessSearchRequest);
        List<Map<String, Object>> records = this.projectSqlExecuteApi.customFindPage(objectPage, "select * from example_user", new HashMap<>());

        objectPage.setRecords(records);
        return PageResultFactory.createPageResult(objectPage);
    }

    @Override
    public List<Map<String, Object>> getCustomViewTotalData(BusinessSearchRequest businessSearchRequest) {
        return this.projectSqlExecuteApi.findList("select * from example_user", new HashMap<>());
    }

}
