package weaver.interfaces.workflow.action.javacode;

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

    public class  Action20230906023509 extends BaseBean implements Action {

    public static final String sql = "insert into workflow_requestlog (requestid,workflowid,nodeid,logtype,operatedate,operatetime,operator,remark1,clientip,operatortype,destnodeid,receivedpersons_1,showorder,agentorbyagentid,agenttype,logid,annexdocids,requestlogid,operatordept,signdocids,signworkflowids,receivedpersons,ismobile,handwrittensign,speechattachment,receivedpersonids,\n" +
            "remarklocation,issubmitdirect,remarkquote,fulltextannotation,speechattachmente9,remark,operatorsub,operatorjob,isrobotnode,seclevel) \n" +
            " select  \n" +
            "'{?lc}',\n" +
            "'331',\n" +
            "'2181',\n" +
            "'2',\n" +
            "r.operatedate,\n" +
            "r.operatetime,\n" +
            "r.operator,\n" +
            "r.remark1,\n" +
            "r.clientip,\n" +
            "r.operatortype,   \n" +
            "'',  \n" +
            "'{?xbbmzh}',\n" +
            "r.showorder,\n" +
            "r.agentorbyagentid,\n" +
            "r.agenttype,\n" +
            "r.logid,\n" +
            "r.annexdocids,\n" +
            "r.requestlogid,\n" +
            "r.operatordept,\n" +
            "r.signdocids,\n" +
            "r.signworkflowids,  \n" +
            "'',r.ismobile,\n" +
            "r.handwrittensign,\n" +
            "r.speechattachment,\n" +
            "'',\n" +
            "r.remarklocation,\n" +
            "r.issubmitdirect,\n" +
            "r.remarkquote,\n" +
            "r.fulltextannotation,\n" +
            "r.speechattachmente9,\n" +
            "r.remark,    \n" +
            "r.operatorsub,  \n" +
            "r.operatorjob, \n" +
            "r.isrobotnode,  \n" +
            "r.seclevel   \n" +
            "from workflow_requestlog r where \n" +
            "r.requestid={?requestid}\n" +
            "and r.nodeid=2169\n" +
            "order by r.operatedate desc,r.operatetime desc limit 1";

    @Override
    public String execute(RequestInfo request) {
        // 1:Log
        writeLog("Action20230906023509 action start...");

        // 2：Exception
        // boolean error = true;
        // if (error) {
        //     request.getRequestManager().setMessageid("90001");
        //     request.getRequestManager().setMessagecontent("System Abnormal Termination Process Submission！");
        // }

        // 3：Get requestid
        String requestId = request.getRequestid();

        // 4：Get form tableName
        String tablename = request.getRequestManager().getBillTableName();

        // 5：Find form content
        RecordSet rs = new RecordSet();
        rs.execute("select * from " + tablename + " where requestid =  " + requestId);
        rs.next();
        String lc = rs.getString("lc");                                //id：Form primary key
        String xbbmzh = rs.getString("xbbmzh");                    //formData：Field name for form design
        RecordSetTrans rsTrans = new RecordSetTrans();
        String excutesql = sql.replaceAll("\\{\\?xbbmzh}",xbbmzh).replaceAll("\\{\\?lc}",lc).replaceAll("\\{\\?requestid}",requestId);
        try {
            writeLog("Action20230906023509 action rsTrans" + rsTrans);
            writeLog("Action20230906023509 action excutesql" + excutesql);
            rsTrans.executeSql(excutesql);
        } catch (Exception e) {
            e.printStackTrace();

            return Action.FAILURE_AND_CONTINUE;
        }

        return Action.SUCCESS;
    }


    public static void main(String[] args) {
        // System.out.println(sql);
        String excutesql = sql.replaceAll("\\{\\?xbbmzh}","11111").replaceAll("\\{\\?lc}","22222").replaceAll("\\{\\?requestid}","3333");
        System.out.println(excutesql);
    }
}
