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 CustomRelatedWorkflow extends BaseBean{

    @WeaReplaceAfter(value = "/htoa/api/public/browser/data/152",order = 1)
    public String replace(WeaAfterReplaceParam weaAfterReplaceParam){
        //将接口返回报文反序列化成jsonobject对象
        JSONObject jsonObject = JSONObject.parseObject(weaAfterReplaceParam.getData());
        //获取到接口报文中的sessionkey
        String sessionkey = jsonObject.getString("datas");
        try {
            DefaultWeaTable defaultWeaTable = WeaTableTools.checkTableStringConfig(sessionkey,DefaultWeaTable.class);
            //找到table中名为创建者的列，并用字段默认实现类DefaultWeaTableColumn去获取
//            DefaultWeaTableColumn requestnameColumn = defaultWeaTable.readWeaTableColumnWithColumn("requestnamenew", DefaultWeaTableColumn.class);
//            String transmethod = "com.engine.htsc.workflow.util.WorkflowUtil.getRequestNameWithRemark";
//            requestnameColumn.setTransmethod(transmethod);

            String tableString = WeaTableTools.toTableString(defaultWeaTable);
            tableString = tableString.replace("requestname,"," requestname||'('||requestmark||')' requestname,")
                    .replace("requestnamenew,","requestnamenew||'('||requestmark||')' requestnamenew,");

            writeLog("CustomRelatedWorkflow TableString2222:"+tableString);
            //将修改后的table，以sessionkey最为键值，覆盖原来缓存中的table数据
            WeaTableTools.setTableStringVal(sessionkey,tableString);
        } catch (Exception e) {
            LogTools.error("发生错误，原因为:" + e.getMessage());
        }
        //将原有接口报文返回
        return weaAfterReplaceParam.getData();
    }
}
