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

import cn.hutool.core.collection.CollUtil;
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.dto.TestMeteringPointDTO;
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 QJ100045Executor extends BaseExecutor implements IExperimentReviewRuleExecutor {

    @Override
    public String getProcessType() {
        return ExperimentReviewProcessType.QJ10004;
    }

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

    /**
     * 5
     *
     * 不需要进行室温退火试验，但进行了室温退火
     *
     * 可能低估器件的抗辐射性能
     *
     * 退火过程中的界面态增长将可能导致元器件的后损伤
     *
     * 可参考 ESCC229000的相关规定，分析退火时长在ESCC229000的适用性
     *
     * 最后一个剂量点测试通过，但是退火过程中有室温退火（退火温度为25℃识别为室温退火），启动这条评定建议
     *
     * @param experiment
     * @param sampleInfo
     * @param experimentReview
     * @return
     */
    @Override
    public String execute(Experiment experiment, ExperimentSampleInfo sampleInfo, ExperimentReview experimentReview) {
        experimentService.fetchExperimentDetail(experiment);
        List<ExperimentTestProcess> experimentTestProcesses = experimentTestProcessService.getByExperimentId(experiment.getId());
        boolean condition1 = false, condition2 = false;
        for (ExperimentTestProcess v : experimentTestProcesses) {
            List<TestMeteringPointDTO> testMeteringPointList = v.getTestMeteringPointList();
            TestMeteringPointDTO last = CollUtil.getLast(testMeteringPointList);
            if (StringUtils.equals(last.getResult(), "合格")) {
                condition1 = true;
                break;
            }
        }
        List<ExperimentAnnealProcess> experimentAnnealProcessList = experimentAnnealProcessService.getByExperimentId(experiment.getId());
        for (ExperimentAnnealProcess experimentAnnealProcess : experimentAnnealProcessList) {
            if (experimentAnnealProcess.getAnnealTemperature().equals("25")) {
                condition2 = true;
                break;
            }
        }
        if (condition1 && condition2) {
            return ExperimentReviewResultEnum.LOW;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}