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

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

    /**
     * 8
     *
     * 需要进行0.5倍过剂量辐照而未进行辐照
     *
     * 可能高估器件的抗辐射性能
     *
     * 辐射损伤冗余评估，器件在50%过辐照持续退化
     *
     * 器件传输延迟、输出驱动和最小工作电压等参数向辐射前恢复的量值均不大于按4.12.3.2加速退火试验的恢复最值，并且辐射和加速退火试验所选择的偏置应使这些参数在加速退火过程中的响应达到最坏情况
     *
     * 辐照过程中备注栏没有“已过辐照”字段；同时在评定流程中询问用户是否需要进行过辐照，用户选是，启动这条评定建议
     *
     * @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 v : radiationProcessList) {
            if (StringUtils.contains(v.getComment(), "已过辐照")) {
                condition1 = true;
                break;
            }
        }
        if (StringUtils.equals(experimentReview.getNeedRadiation(), "Y")) {
            condition2 = true;
        }
        if (!condition1 && condition2) {
            return ExperimentReviewResultEnum.HIGH;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}