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

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

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

    /**
     * 指令集记录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(String taskCode){
        for (Task task : this.getRequest().getTaskList()) {
            if(task.getCode().equals(taskCode)){
                return task.getParamList();
            }
        }
        return null;
    }

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

}
