<?xml version="1.0" encoding="UTF-8"?>
<p:procedure xmlns:s="aurora.plugin.script" xmlns:a="http://www.aurora-framework.org/application" xmlns:p="uncertain.proc">
     <s:server-script><![CDATA[
            importPackage(Packages.com.test); //鐩稿綋浜巎ava涓殑import com.esa2000.*;
            importPackage(Packages.org.springframework.context);
            importPackage(Packages.org.springframework.context.support);
            importPackage(java.io);
           try {
            importPackage(Packages.com.test); //相当于java中的import com.esa2000.*;
            importPackage(Packages.org.springframework.context);
            importPackage(Packages.org.springframework.context.support);
            importPackage(java.io);
            
            function getdate() {
                var now = new Date()
                y = now.getFullYear()
                m = now.getMonth() + 1
                d = now.getDate()
                h = now.getHours()
                mi = now.getMinutes()
                ss = now.getSeconds()
                m = m < 10 ? "0" + m : m
                d = d < 10 ? "0" + d : d
                h = h < 10 ? "0" + h : h
                mi = mi < 10 ? "0" + mi : mi
                ss = ss < 10 ? "0" + ss : ss
                return y + "" + m + "" + d + "" + h + "" + mi + "" + ss
            }
            
            var locations = ["classpath:client.xml", "classpath:context/client-demo-servlet.xml"];
            
            var ctx = new FileSystemXmlApplicationContext(locations);
            var checkRealTime = ctx.getBean("testRealTimeQuery");
            var testRealTime = ctx.getBean("testRealTime");
            var debit_number = "";
            var v_flag = "N";
            //插入接口数据
            //$bm('csh.CSH600.hls_create_ebank_data').execute();
            var bm = $bm('csh.CSH600.hls_ebank_interface_v');
            var records = bm.queryAsMap({
                trs_status: 'NEW',
                interface_id: $ctx.parameter.interface_id
            }).getChildren();
            
            for (var i = 0;i < records.length;i++) {
                
                debit_number = getdate() || "" || records[i].interface_id;
                
                if (records[i].debit_number != null) {
                    var check_result = checkRealTime.testPkiQuery("1", "10011639243", "1001163924301", records[i].debit_number);
                    //解析接口数据
                    var res = $bm('csh.CSH600.hls_check_ebank_data').execute({
                        response_xml: check_result,
                        function_name: 'NC_EMBK_CHECK_PARSE',
                        request_id: '111',
                        interface_id: records[i].interface_id
                    });
                    v_flag = $ctx.parameter.flag;
                    debit_number = records[i].debit_number;
                }
                println('--------------------------');
                var res = $bm('csh.CSH600.hls_check_ebank_data').insert({
                    interface_id: records[i].interface_id,
                    debit_number : debit_number
                });
                println($ctx.parameter.flag);
            
                //未传送执行传送
                if (v_flag == 'N') {
                    /*   var result = testRealTime.testSignSinglePKI(String InputCharset,
                     String ContractId,
                     String MemberCode,
                     String MerchantAcctId,
                     String Mechantcontractno,
                     String seqId,
                     String BankAcctName,
                     String BankAcctId,
                     String Amount,
                     String Usage,
                     String CurType,
                     String Remark) */
                    var result = testRealTime.testSignSinglePKI("1", "steven04", //
                    "10011639243", "1001163924301", records[i].protocol_number, //协议号
                    debit_number, //
                    records[i].cltnam, records[i].accnbr, records[i].trsamt, records[i].buscode, records[i].currency, records[i].trsdsp);
                    //records[i].memo, //用途代码--
                    // var result = testRealTime.testSignSinglePKI("1", "steven04","10011639243", "1001163924301", "BCOMQDSuc1", "2011080101565", "缴紫", "360502198904050392", "20", "代扣", "CNY", "");
                    //解析接口数据
                    $bm('csh.CSH600.hls_writeoff_ebank_data').update({
                        response_xml: result,
                        function_name: 'NC_EMBK_PARSE',
                        request_id: '111',
                        interface_id: records[i].interface_id
                    });
                }
            }
            //核销操作
            $bm('csh.CSH600.hls_writeoff_ebank_data').execute();
            
           } catch (e) {
                println(e.message)//for test
                $logger('csh.CSH600.hls_create_ebank_data').info('error occured :,' + e.message);
            }
        ]]></s:server-script>
</p:procedure>
