package com.engine.htsc.workflow.impl;

import com.alibaba.fastjson.JSONObject;
import com.weaverboot.frame.ioc.anno.classAnno.WeaIocReplaceComponent;
import com.weaverboot.frame.ioc.anno.methodAnno.WeaReplaceAfter;
import com.weaverboot.frame.ioc.handler.replace.weaReplaceParam.impl.WeaAfterReplaceParam;
import com.weaverboot.tools.componentTools.table.WeaTableTools;
import com.weaverboot.tools.logTools.LogTools;
import com.weaverboot.weaComponent.impl.weaTable.table.impl.DefaultWeaTable;
import weaver.general.BaseBean;

/**
 * Created by K1810006 on 2020/9/28.
 */
@WeaIocReplaceComponent
public class CustomReqListResult extends BaseBean{

    @WeaReplaceAfter(value = "/htoa/api/customization/workflow/reqlist/splitPageKey",order = 1)
    public String replace(WeaAfterReplaceParam weaAfterReplaceParam){
        //将接口返回报文反序列化成jsonobject对象
        JSONObject jsonObject = JSONObject.parseObject(weaAfterReplaceParam.getData());
        //获取到接口报文中的sessionkey
        String sessionkey = jsonObject.getString("sessionkey");
        System.out.println("CustomReqListResult sessionkey====="+sessionkey);
        try {
            //因为待办事宜表格为标准表格，所以我们用defaultWeaTable来获取
            //在整个拦截过程中，WeaTableTools是一个非常关键的工具类
            //此处是根据sessionkey，反序列化表格类
            DefaultWeaTable defaultWeaTable = WeaTableTools.checkTableStringConfig(sessionkey,DefaultWeaTable.class);
            //找到table中名为创建者的列，并用字段默认实现类DefaultWeaTableColumn去获取
            //DefaultWeaTableColumn defaultWeaTableColumn = defaultWeaTable.readWeaTableColumnWithColumn("创建者", DefaultWeaTableColumn.class);
            //将此类的列名修改为操作人员
            //defaultWeaTableColumn.setText("操作人员");
            //将修改后的table，以sessionkey最为键值，覆盖原来缓存中的table数据
            System.out.println("CustomReqListResult tableString========="+WeaTableTools.toTableString(defaultWeaTable));
            WeaTableTools.setTableStringVal(sessionkey,WeaTableTools.toTableString(defaultWeaTable));
        } catch (Exception e) {
            LogTools.error("发生错误，原因为:" + e.getMessage());
        }
        //将原有接口报文返回
        return weaAfterReplaceParam.getData();
    }
}
