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

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

    /**
     * 9
     *
     * 可以不进行0.5倍过剂量辐照，但进行了过辐照的试验
     *
     * 可能低估器件的抗辐射性能
     *
     * 增加了过辐照剂量的辐照损伤
     *
     * 可参考 QJ10004A-2018的相关规定，分析其在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<ExperimentRadiationProcess> radiationProcessList = experimentRadiationProcessService.getByExperimentId(experiment.getId());
        for (ExperimentRadiationProcess v : radiationProcessList) {
            if (StringUtils.contains(v.getComment(), "已过辐照")) {
                condition1 = true;
                break;
            }
        }
        if (StringUtils.equals(experimentReview.getNeedRadiation(), "N")) {
            condition2 = true;
        }
        if (condition1 && condition2) {
            return ExperimentReviewResultEnum.LOW;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}