
package cn.orionsec.ops.handler.importer.checker;

import cn.orionsec.kit.spring.SpringHolder;
import cn.orionsec.ops.constant.ImportType;
import cn.orionsec.ops.dao.ApplicationRepositoryDAO;
import cn.orionsec.ops.entity.domain.ApplicationRepositoryDO;
import cn.orionsec.ops.entity.importer.ApplicationRepositoryImportDTO;
import cn.orionsec.ops.entity.vo.data.DataImportCheckVO;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.List;

public class AppRepositoryDataChecker extends AbstractDataChecker<ApplicationRepositoryImportDTO, ApplicationRepositoryDO> {

    private static final ApplicationRepositoryDAO applicationRepositoryDAO = SpringHolder.getBean(ApplicationRepositoryDAO.class);

    public AppRepositoryDataChecker(Workbook workbook) {
        super(ImportType.APP_REPOSITORY, workbook);
    }

    @Override
    protected DataImportCheckVO checkImportData(List<ApplicationRepositoryImportDTO> rows) {
        // 检查数据合法性
        this.validImportRows(rows);
        // 通过唯一标识查询应用
        List<ApplicationRepositoryDO> presentList = this.getImportRowsPresentValues(rows,
                ApplicationRepositoryImportDTO::getName,
                applicationRepositoryDAO, ApplicationRepositoryDO::getRepoName);
        // 检查数据是否存在
        this.checkImportRowsPresent(rows, ApplicationRepositoryImportDTO::getName,
                presentList, ApplicationRepositoryDO::getRepoName, ApplicationRepositoryDO::getId);
        // 设置导入检查数据
        return this.setImportCheckRows(rows);
    }

}
