con_doc_batch_create.lsc 3.03 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="cont.CON500.con_contract_get_guid_file_name" rootPath="guid_file_name_path"/>
        <a:model-query fetchAll="true" model="cont.CON500.con_doc_file_templet_get_atm" rootPath="file_templet_get_atm_path"/>
        <s:server-script><![CDATA[
            importPackage(Packages.hls.plugin.docx4j);
            importPackage(java.io);
            
            function copyFile(fOld, fNew) {
                var fis = new java.io.FileInputStream(fOld);
                var fos = new java.io.FileOutputStream(fNew);
                var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 4);
                var len = -1;
                while ((len = fis.read(b)) != -1) {
                    fos.write(b, 0, len);
                }
                fis.close();
                fos.close();
            }
            var from_file_data = $ctx.get('/model/file_templet_get_atm_path').getChildren();
            for (var i = 0;i < from_file_data.length;i++) {
                var to_file_path = $ctx.parameter.file_path;
                var record_data = from_file_data[i];
lijingjing's avatar
lijingjing committed
25

Spencer Chang's avatar
Spencer Chang committed
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 58 59
                if (record_data.file_exists_flag != 'Y') {
                    var to_file_name = record_data.to_file_name + '.' + record_data.file_type_code || 'doc';
                    var from_file_path = record_data.file_path;
                    var guid_file_name_path = $bm('cont.CON500.con_contract_get_guid_file_name').queryAsMap();
                    var guid_file_name_tables = guid_file_name_path.getChildren();
                    to_file_path = to_file_path + guid_file_name_tables[0].guid_file_name + 'con' + record_data.content_id;

                    copyFile(from_file_path, to_file_path);

                    $bm('cont.CON500.con_file_content_copy_update').update({
                        table_name: 'CON_CONTRACT_CONTENT',
                        content_id: record_data.content_id,
                        file_name: to_file_name.toString(),
                        file_path: to_file_path.toString()
                    });
            
                    try {
                        println(111);
                        var brwt = new BookmarksReplaceWithText($instance('leaf.database.service.IDatabaseServiceFactory'), $instance('uncertain.ocm.IObjectRegistry'), $ctx.getData());
                        println($ctx.getData());
                        brwt.replaceBookmarkFromContent(to_file_path.toString(), record_data.content_id);
                    } catch (e) {
                        raise_app_error(e);
                    }
                }
            }
            //remove by chenlingfeng
           // var last_check_bm = $bm('cont.CON500.con_calc_due_date_after_print');
           // last_check_bm.update({
            //    contract_id: $ctx.parameter.contract_id
           // });
        ]]></s:server-script>
    </a:init-procedure>
</a:service>