
package com.lideeyunji.core.framework.config.aspect.enhancereport.model;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lideeyunji.core.framework.config.aspect.enhance.model.BaseEnhanceContext;
import com.lideeyunji.core.framework.config.aspect.enhance.model.EnhanceResult;
import com.lideeyunji.tool.framework.yunji.model.ResultDataModel;

import java.io.*;
import java.util.List;
import java.util.Map;

/**
 * @author JX
 * @create 2024-08-12 9:14
 * @dedescription: 增强执行上下文
 */
public class EnhanceReportContext extends BaseEnhanceContext implements Serializable{
    //参数
    private EnhanceReportParam param;
    //结果
    private EnhanceResult result;


    public EnhanceReportParam getParam() {
        return param;
    }

    public void setParam(EnhanceReportParam param) {
        this.param = param;
    }

    public EnhanceResult getResult() {
        return result;
    }

    public void setResult(EnhanceResult result) {
        this.result = result;
    }

    public void setResult(ResultDataModel resultDataModel){
        this.result.setExitFlag(resultDataModel.isExitFlag());
        this.result.setRecords(resultDataModel.getRecords());
        this.result.setTotal(resultDataModel.getTotal());
    }

    //通过序列化和反序列化实现深拷贝
    @Override
    public EnhanceReportContext clone(){
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);
            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois  = new ObjectInputStream(bis);
            return (EnhanceReportContext) ois.readObject();
        } catch (IOException |ClassNotFoundException e ) {
            e.printStackTrace();
            return null;
        }
    }

    public void setParam(String reportCode,Map<String,Object> params,List<Map<String,Object>> list){
        this.param = new EnhanceReportParam(reportCode,params,list);
    }

    public void setResult(boolean exitFlag,String id,Long total,List<Map<String,Object>> records){
        this.result = new EnhanceResult(exitFlag,id,total,records);
    }

    public void  setParam(String reportCode, Map<String, Object> params, List<Map<String, Object>> list, Long dataId, Page page, List<Long> dataIdList){
        this.param = new EnhanceReportParam(reportCode,params,list,dataId,page,dataIdList);
    }
}

