efile_doc_import.lsc 5.46 KB
Newer Older
gzj34291's avatar
gzj34291 committed
1 2 3
<?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>
4
        <s:server-script import="token_record.js"><![CDATA[
gzj34291's avatar
gzj34291 committed
5 6
            importPackage(java.io);
            importPackage(java.util);
7 8 9 10
            importPackage(Packages.com.hand.hlcm);

            var startdate  = '2022-04-01 12:30:00';
            var enddate  = '2023-04-01 12:30:00';
gzj34291's avatar
gzj34291 committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
            try {
                var sys_url_bm = $bm('cont.CON4000.get_sys_url');
                var parameter_code = 'TOKEN_POSTURL';
                var SysposturlQuery = sys_url_bm.queryAsMap({
                    parameter_code: parameter_code
                });
                var posturl = SysposturlQuery.getChildren()[0].parameter_value;
                var parameter_code = 'TOKEN_APPID';
                var SysappidQuery = sys_url_bm.queryAsMap({
                    parameter_code: parameter_code
                });
                var token_appid = SysappidQuery.getChildren()[0].parameter_value;
                var parameter_code = 'TOKEN_APPSECRET';
                var SysappsecretQuery = sys_url_bm.queryAsMap({
                    parameter_code: parameter_code
                });
                var token_appsecret = SysappsecretQuery.getChildren()[0].parameter_value;


30 31 32 33 34
                var parameter_code = 'FILE_QUERY_URL';
                var FileQuery = sys_url_bm.queryAsMap({
                parameter_code: parameter_code
                });
                var docUrl = FileQuery.getChildren()[0].parameter_value;
gzj34291's avatar
gzj34291 committed
35 36 37 38 39
                var token_savelogs_bm = $bm('efile.EFILE1000.efile_get_token');
                //token是否在有效期内,在有效期内直接获取表中的token
                var check_token_valid_bm = $bm('efile.EFILE1000.check_token_valid');
                var checkTokenQuery = check_token_valid_bm.queryAsMap();
                var is_valid = checkTokenQuery.getChildren()[0].is_valid;
40
                println('is_valid = ' + is_valid);
gzj34291's avatar
gzj34291 committed
41 42

                if (is_valid == 'true') {
43
                     println("=======有效期内======");
gzj34291's avatar
gzj34291 committed
44 45 46 47
                     var SystokenQuery = token_savelogs_bm.queryAsMap();
                     var access_token = SystokenQuery.getChildren()[0].access_token;
                     var files = '{"startCreatedDate": ' + '"' +startdate +'"'
                     + ',"endCreatedDate":'+ '"' +enddate + '"'
48
                     +',"documentTypeCodeList": '+'["类型code3"]}';
gzj34291's avatar
gzj34291 committed
49
                     access_token_n = 'Bearer'+ access_token;
50
                     println('access_token_n = ' + access_token_n);
gzj34291's avatar
gzj34291 committed
51
                     var data_result_n = HttpPostDocQuery.httpPostDocImport(docUrl,files,access_token_n);
52 53
                     println('请求资料的结果:');
                     println('data_result_n = ' + data_result_n);
gzj34291's avatar
gzj34291 committed
54 55 56
                     var json_data = JSON.parse(data_result_n);
                     var statusCode =json_data.statusCode;
                     var message =json_data.message;
57

gzj34291's avatar
gzj34291 committed
58 59 60
                 } else {
                    println("=======有效期外======");
                    var data = httpPostGetToken(posturl, token_appid, token_appsecret);
61
                    println('data = ' + data);
gzj34291's avatar
gzj34291 committed
62 63
                    var json = JSON.parse(data);
                    var access_token = json.access_token;
64 65
                    println('access_token = ' + access_token);
                    //如果获取 access_token 成功,则 不会返回 status,即 status = undefined
gzj34291's avatar
gzj34291 committed
66
                    var status = json.status;
67
                    println('status = ' + status);
gzj34291's avatar
gzj34291 committed
68 69 70 71
                    if (access_token) {
                        token_savelogs_bm.insert({
                            'json': data,
                            'status': 'success'
72 73
                        });
                    // 这个 expires_in 是从 access_token 接口获取过来的数据  有效持续时间
gzj34291's avatar
gzj34291 committed
74 75 76 77
                        token_savelogs_bm.update({
                            'system_source': 'hlcm',
                            'expires_in': json.expires_in,
                            'access_token': access_token
78
                        });
gzj34291's avatar
gzj34291 committed
79 80 81
                    }

                    if (status) {
82
                    //这里为什么一个 传 json,一个传 data,可能是一样的
83
                        var token_savelogs_bm = $bm('efile.EFILE1000.efile_get_token');
gzj34291's avatar
gzj34291 committed
84
                        token_savelogs_bm.insert({
85
                            'json': data,
gzj34291's avatar
gzj34291 committed
86 87 88 89 90 91
                            'status': 'fail'
                        });
                    }

                     var files = '{"startCreatedDate": ' + '"' +startdate +'"'
                     + ',"endCreatedDate":'+ '"' +enddate + '"'
92
                     +',"documentTypeCodeList": '+'["类型code3"]}';
gzj34291's avatar
gzj34291 committed
93
                     access_token_n = 'Bearer'+ access_token;
94
                     println('access_token_n = ' + access_token_n);
gzj34291's avatar
gzj34291 committed
95
                     var data_result_n = HttpPostDocQuery.httpPostDocImport(docUrl,files,access_token_n);
96 97
                     println('请求资料的结果:');
                     println('data_result_n = ' + data_result_n);
gzj34291's avatar
gzj34291 committed
98 99 100 101
                     var json_data = JSON.parse(data_result_n);
                     var statusCode =json_data.statusCode;
                     var message =json_data.message;

102
                }
gzj34291's avatar
gzj34291 committed
103 104 105 106 107 108 109

            } catch (e) {
                println('e:' + e);
            }
        ]]></s:server-script>
    </a:init-procedure>
</a:service>