package weaver.interfaces.htsc.payment;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;


public class UpdateLogTypeAsTermination extends BaseBean implements Action {

    private BaseBean bb = new BaseBean();

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        RecordSet rst = new RecordSet();
        try{
            String tablename = requestInfo.getRequestManager().getBillTableName();
            String requestid = requestInfo.getRequestid();
            int nodeid = requestInfo.getRequestManager().getNodeid();
            bb.infoLog("params0608",requestid+"--"+nodeid);
            Map<String,String> map = new HashMap<>();
            Property[] property = requestInfo.getMainTableInfo().getProperty();
            for (int i = 0;i<property.length;i++){
                String name = property[i].getName();//主字段名称
                String value = Util.null2String(property[i].getValue());
                map.put(name,value);
            }
            String spjg = map.get("spjg");
            bb.infoLog("spjg",spjg);
            if ("1".equals(spjg)){
                bb.writeLog("开始更新requestlog表");
                new Thread(() -> {
                    try {
                        Thread.sleep(30 * 1000L);
                        //更新签字日志表
                        rs.executeQuery("select max(logid) logid from " +
                                " workflow_requestlog where requestid = ? and nodeid = ?",requestid,nodeid);
                        if (rs.next()){
                            int logid = Util.getIntValue(rs.getString(1));
                            rs.executeUpdate("update workflow_requestlog set logtype = 'k' where " +
                                    " logid = ?",logid);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }).start();

            }

        }catch (Exception e){
            e.printStackTrace();
            requestInfo.getRequestManager().setMessagecontent("更新流程终止类型失败");
        }
        return Action.SUCCESS;
    }
}
