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

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
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 GJB548C10Executor extends BaseExecutor implements IExperimentReviewRuleExecutor {
    @Override
    public String getProcessType() {
        return ExperimentReviewProcessType.GJB548C;
    }

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

    /**
     * 10
     *
     * 器件未使用最劣偏置
     *
     * 可能高估器件的抗辐射性能
     *
     * 参见附件二知识库中84条目《辐射试验》的解释
     *
     * 采用应用偏置条件
     *
     * 试验数据中偏置条件选择动态偏置，启动这条评定建议
     *
     * @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) {
            String deviationCondition = experimentAnnealProcess.getDeviationCondition();
            JSONObject jsonObject = JSON.parseObject(deviationCondition);
            if (jsonObject.containsKey("offsetCondition")) {
                String offsetCondition = jsonObject.getString("offsetCondition");
                if (StringUtils.contains(offsetCondition, "dtpz")) {
                    condition1 = true;
                    break;
                }
            }
        }
        if (condition1) {
            return ExperimentReviewResultEnum.HIGH;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}