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

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

import java.util.List;

public class CommandTemplateDataChecker extends AbstractDataChecker<CommandTemplateImportDTO, CommandTemplateDO> {

    private static final CommandTemplateDAO commandTemplateDAO = SpringHolder.getBean(CommandTemplateDAO.class);

    public CommandTemplateDataChecker(Workbook workbook) {
        super(ImportType.COMMAND_TEMPLATE, workbook);
    }

    @Override
    protected DataImportCheckVO checkImportData(List<CommandTemplateImportDTO> rows) {
        // 检查数据合法性
        this.validImportRows(rows);
        // 通过名称查询模板
        List<CommandTemplateDO> presentTemplates = this.getImportRowsPresentValues(rows,
                CommandTemplateImportDTO::getName,
                commandTemplateDAO, CommandTemplateDO::getTemplateName);
        // 检查数据是否存在
        this.checkImportRowsPresent(rows, CommandTemplateImportDTO::getName,
                presentTemplates, CommandTemplateDO::getTemplateName, CommandTemplateDO::getId);
        // 设置导入检查数据
        return this.setImportCheckRows(rows);
    }

}
