/*
 * 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.*;
import org.jeecg.modules.database.entity.*;
import org.jeecg.modules.database.service.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lise
 * @version GJB548C1Executor.java, v 0.1 2025年06月16日 20:57 lise
 */

@Component
public class GJB548C4Executor  extends BaseExecutor  implements IExperimentReviewRuleExecutor {

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

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

    /**
     * 4
     *
     * 器件没有通过电测试，未进行室温退火
     *
     * 可能低估器件的抗辐射性能
     *
     * 室温退火过程中的氧化物陷阱电荷的退火，器件的电参数有可能恢复
     *
     * 器件功能失效；当预定应用环境辐射剂量率比试验剂量率高，且高于0.001Gy(Si)/
     * 剂量率高，且高于0.001Gy(Si)/
     *
     *
     *
     * 最后一个剂量点测试未通过，但是退火过程中没有室温退火（退火温度为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;

    }
}