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

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

    @Override
    public String execute(Experiment experiment, ExperimentSampleInfo sampleInfo, ExperimentReview experimentReview) {
        experimentService.fetchExperimentDetail(experiment);
        boolean condition1 = false, condition2 = false, condition3 = false;
        List<ExperimentTestProcess> experimentTestProcessList = experimentTestProcessService.getByExperimentId(experiment.getId());

        for (ExperimentTestProcess v : experimentTestProcessList) {
            List<TestMeteringPointDTO> testMeteringPointList = v.getTestMeteringPointList();
            TestMeteringPointDTO last = CollUtil.getLast(testMeteringPointList);
            if (!StringUtils.equals(last.getResult(), "合格")) {
                condition3 = true;
                break;
            }
        }
        if (!condition3) {
            return ExperimentReviewResultEnum.NOT_PASS;
        }
        return ExperimentReviewResultEnum.ITEM_PASS;
    }
}