/*
 * 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.Date;
import java.util.List;

/**
 * @author lise
 */

@Component
public class ESCC2290007Executor extends BaseExecutor implements IExperimentReviewRuleExecutor {
    @Override
    public String getProcessType() {
        return ExperimentReviewProcessType.ESCC229000;
    }

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

    /**
     * 电学测试通过后未进行24小时的室温退火
     *
     * 可能高估器件的抗辐射性能
     *
     * 退火过程中的界面态增长将可能导致元器件的后损伤
     *
     * 可参考QJ10004A-2018 、GJB-548C，分析试验流程在两个标准的适用性
     *
     * 退火过程中的没有25℃ 24小时退火的记录，启动这条评定建议
     *
     * @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<ExperimentAnnealProcess> experimentAnnealProcessList = experimentAnnealProcessService.getByExperimentId(experiment.getId());
        for (ExperimentAnnealProcess experimentAnnealProcess : experimentAnnealProcessList) {
            if (experimentAnnealProcess.getAnnealTemperature().equals("25")) {
                condition1 = true;
                continue;
            }
            Date annealStartTime = experimentAnnealProcess.getAnnealStartTime();
            Date annealEndTime = experimentAnnealProcess.getAnnealEndTime();
            long diffInMillis = annealEndTime.getTime() - annealStartTime.getTime();
            if (diffInMillis > 24 * 60 * 60 * 1000) {
                condition2 = true;
            }
        }
        if (!condition1 && condition2) {
            return ExperimentReviewResultEnum.HIGH;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}