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

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

    /**
     * 12
     *
     * 辐射室温环境温度不在标准范围内
     *
     * 温度高可能高估器件的抗辐射性能；温度低可能低估器件的抗辐射性能
     *
     * 参见附件二知识库中85条目《辐射试验的辐射试验-温度》的解释
     *
     * 可参考QJ10004A-2018，分析辐射室温环境温度在QJ10004A-2018的适用性
     *
     * 辐照过程中的辐照环境温度在18-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<ExperimentRadiationProcess> radiationProcessList = experimentRadiationProcessService.getByExperimentId(experiment.getId());
        for (ExperimentRadiationProcess experimentRadiationProcess : radiationProcessList) {
            String environmentalTemperature = experimentRadiationProcess.getEnvironmentalTemperature();
            Integer temp = Integer.valueOf(environmentalTemperature);
            if (temp < 18) {
                condition1 = true;
                break;
            }
            if (temp > 30) {
                condition2 = true;
                break;
            }
        }
        if (condition1) {
            return ExperimentReviewResultEnum.LOW;
        }
        if (condition2) {
            return ExperimentReviewResultEnum.HIGH;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}