sms_batch_send.lsc 2.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:p="uncertain.proc"
           xmlns:a="http://www.leaf-framework.org/application"
           xmlns:s="leaf.plugin.script"
           trace="true">

    <a:init-procedure>
        <s:server-script><![CDATA[
            importPackage(Packages.java.util);
            importPackage(Packages.com.hand.hls.hlcm.emay);
            importPackage(Packages.com.hand.hap.system.dto);
            //step2 发送短信
            function sendsms() {
14 15 16 17 18 19 20 21 22
                var logger = $logger("server-script");
                // 查询待发送短信表
                var contract_collection = $bm('sys.SYS420.reminder_sms_list');
                contract_collection.update();
                var sms_list_bm = $bm('sys.SYS420.reminder_sms_loop');
                println($ctx.parameter.batch_id);
                var sms_list_result = sms_list_bm.queryAsMap({
                                            "batch_id": $ctx.parameter.batch_id
                                        });
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
                var sms_list_records = sms_list_result.getChildren();
                for (var i = 0; i < sms_list_records.length; i++) {
                println(1);
                    var Phones = sms_list_records[i].phone_number;
                    var content = sms_list_records[i].text;
                    var sms_id = sms_list_records[i].sms_id;
                    try {
                        var example = new Example();
                        var result = example.setSingleSms(content, Phones);
                        var req_response = result.toString();
                    } catch (e) {
                        println("抛出异常:" + e);

                    }
                    //发送后请求更新
                    $bm('sys.SYS420.reminder_sms_loop').update({
                                                            sms_id: sms_id,
                                                            result: req_response
                    });
                }
                var sms_list_n_bm = $bm('sys.SYS420.reminder_sms_list');
                println($ctx.parameter.batch_id);
                var sms_list_n_result = sms_list_n_bm.queryAsMap({
                    "batch_id": $ctx.parameter.batch_id
                });
                logger.info('111111111111111');
                var fail_num = sms_list_n_result.getChildren()[0].num;
                logger.info(fail_num);
                logger.info(fail_num > 0);
                var sms_commit_bm = $bm('sys.SYS420.reminder_sms_commit');
                sms_commit_bm.update();
                if (fail_num > 0){
                    raise_app_error('本批发送失败的信息有' + fail_num + '条');
                }
58
            }
59 60
                sendsms();
    ]]></s:server-script>
61 62 63
    </a:init-procedure>
    <a:service-output output="/parameter"/>
</a:service>