package com.kcim.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kcim.common.util.UserContext;
import com.kcim.dao.mapper.KpiComputeImportMapper;
import com.kcim.dao.model.KpiComputeImport;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @program: performance
 * @description: 公用导入记录数据库交互
 * @author: Wang.YS
 * @create: 2023-07-20 10:13
 **/
@Repository
public class KpiComputeImportRepository extends ServiceImpl<KpiComputeImportMapper, KpiComputeImport> {

    public List<KpiComputeImport> getList(String computeDate) {
        LambdaQueryWrapper<KpiComputeImport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(KpiComputeImport::getComputeDate,computeDate);
        queryWrapper.eq(KpiComputeImport::getHospId, UserContext.getCurrentLoginHospId());
        return this.list(queryWrapper);
    }

    public Page<KpiComputeImport> getPage(Integer current, Integer pageSize, String computeDate, String tableName) {
        Page<KpiComputeImport> computeImportPage = new Page<>(current,pageSize);
        LambdaQueryWrapper<KpiComputeImport> queryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(computeDate)){
            queryWrapper.eq(KpiComputeImport::getComputeDate,computeDate);
        }
        if(!StringUtils.isEmpty(tableName)){
            queryWrapper.eq(KpiComputeImport::getTableName,tableName);
        }
        queryWrapper.eq(KpiComputeImport::getHospId, UserContext.getCurrentLoginHospId());
        return this.page(computeImportPage, queryWrapper);


    }
}
