package cn.estsh.i3plus.pojo.model.lac;

import cn.estsh.i3plus.pojo.lac.bean.LacCommandStackRecord;
import cn.estsh.i3plus.pojo.lac.bean.LacCommandStackStepTask;
import lombok.Data;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * @Description : lac指令集model
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2019-10-29 15:29
 * @Modify:
 **/
@Data
public class LacCommandStackModel implements Serializable {

    private static final long serialVersionUID = -8453748548383071954L;
    /**
     * 指令集记录id
     */
    private Long recordId;

    /**
     * 指令集记录
     */
    private LacCommandStackRecord commandStackRecord;

    /**
     * 请求数据
     */
    private LacSuitRequest request;

    /**
     * 请求XML
     */
    private String requestXml;

    /**
     * 响应数据
     */
    private LacSuitResponse response;

    /**
     * 异常信息
     */
    private Exception exception;


    public void setException(Exception exception) {
        LoggerFactory.getLogger("YYYY").error("异常信息：{}", exception);
        this.exception = exception;
    }

    public void setCommandStackRecord(LacCommandStackRecord commandStackRecord) {
        this.commandStackRecord = commandStackRecord;
        this.recordId = commandStackRecord.getId();
    }

    public Object getTaskRequestParam(LacCommandStackStepTask stepTask) {
        for (Task task : this.getRequest().getTaskList()) {
            // 步骤代码为空时匹配所有任务参数
            if (task.getStepCode() == null && task.getCode().equals(stepTask.getTaskCodeRdd())) {
                return task.getParamList();
            } else if (task.getStepCode() != null && task.getStepCode().equals(stepTask.getStepCodeRdd())
                    && task.getCode().equals(stepTask.getTaskCodeRdd())) {
                return task.getParamList();
            }
        }
        return null;
    }

    public Long getRecordId() {
        if (recordId == null && this.commandStackRecord != null) {
            this.recordId = this.commandStackRecord.getId();
        }
        return recordId;
    }

}
