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

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 ESCC225003Executor extends BaseExecutor implements IExperimentReviewRuleExecutor {
    @Override
    public String getProcessType() {
        return ExperimentReviewProcessType.ESCC22500;
    }

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

    /**
     * 质子退火过程中的环境温度
     *
     * 可能低估或高估器件的抗辐射性能
     *
     * 退火温度偏高有利于器件的辐射感生缺陷退火，退火温度偏低不有利于器件的辐射感生缺陷退火
     *
     * 参考其他单位指定的质子测试指南
     *
     * 退火过程退火温度在10-30℃范围外，启动这条评定建议
     *
     * @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 annealTemperature = experimentAnnealProcess.getAnnealTemperature();
            Integer temp = Integer.valueOf(annealTemperature);
            if (temp < 10) {
                condition1 = true;
                break;
            }
            if (temp > 30) {
                condition2 = true;
                break;
            }
        }
        if (condition1) {
            return ExperimentReviewResultEnum.LOW;
        }
        if (condition2) {
            return ExperimentReviewResultEnum.HIGH;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}