/*
 * Ant Group
 * Copyright (c) 2004-2025 All Rights Reserved.
 */
package org.jeecg.modules.database.service.executor;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.database.constant.ExperimentReviewProcessType;
import org.jeecg.modules.database.constant.ExperimentReviewResultEnum;
import org.jeecg.modules.database.entity.*;
import org.jeecg.modules.database.service.IExperimentReviewRuleExecutor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lise
 */

@Component
public class GJB548C14Executor extends BaseExecutor implements IExperimentReviewRuleExecutor {
    @Override
    public String getProcessType() {
        return ExperimentReviewProcessType.GJB548C;
    }

    @Override
    public int getPriority() {
        return 14;
    }

    /**
     * 14
     *
     * 使用干冰保存器件，应通过针对性的退火表征试验
     *
     * 可能高估器件的抗辐射性能
     *
     * 氧化物陷阱电荷在干冰条件下退火减弱
     *
     * 没有给出过表征试验的结果的适用范围：试验方案按照QJ10004A-2018的相关规定进行执行
     *
     * 在退火过程的备注中，有“干冰”字段，在评定流程中询问用户是否进行了针对性的退火表征试验，用户选否，启动这条评定建议
     *
     * @param experiment
     * @param sampleInfo
     * @param experimentReview
     * @return
     */
    @Override
    public String execute(Experiment experiment, ExperimentSampleInfo sampleInfo, ExperimentReview experimentReview) {
        experimentService.fetchExperimentDetail(experiment);
        boolean condition1 = false, condition2 = false;

        List<ExperimentAnnealProcess> experimentAnnealProcessList = experimentAnnealProcessService.getByExperimentId(experiment.getId());

        for (ExperimentAnnealProcess experimentAnnealProcess : experimentAnnealProcessList) {
            String comment = experimentAnnealProcess.getComment();
            if (StringUtils.contains(comment, "干冰")) {
                condition1 = true;
                break;
            }
        }
        if (StringUtils.contains(experimentReview.getNeedAnneal(), "N")) {
            condition2 = true;
        }

        if (condition1 && condition2) {
            return ExperimentReviewResultEnum.HIGH;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}