con_doc_batch_create.lsc 9.44 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
1 2 3
<?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>
4 5
        <a:model-query fetchAll="true" model="cont.CON500.con_contract_get_guid_file_name"
                       rootPath="guid_file_name_path"/>
niminmin's avatar
niminmin committed
6
        <!--<a:model-query fetchAll="true" model="cont.CON500.con_doc_file_templet_get_atm" rootPath="file_templet_get_atm_path"/>-->
7
        <s:server-script import="contract_print_path.js"><![CDATA[
Spencer Chang's avatar
Spencer Chang committed
8
            importPackage(java.io);
9 10 11
            importPackage(Packages.hls.plugin.docx4j);
            importPackage(Packages.leaf.plugin.word2pdf);
            importPackage(Packages.org.apache.commons.io);
12

Spencer Chang's avatar
Spencer Chang committed
13 14 15 16 17 18 19 20 21 22
            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();
23
            }
24 25 26 27 28 29 30 31 32 33 34 35
                //删除文件
            function deleteFile(filePath) {
                var file = new File(filePath);
                if (file.exists()) {
                    file.delete();
                }
            }

            //生成pdf
               function wordToPdf(word_file_path,pdf_file_path) {
                // word转pdf
                var pdf_file_path_new = pdf_file_path + '.pdf';
36
                var wordToPdf = new WordToPdf($instance('uncertain.ocm.IObjectRegistry'), "jacob-1.19-x64.dll");
37 38 39 40 41
                wordToPdf.word2pdf(word_file_path, pdf_file_path_new);
                //删除word文件
               // deleteFile(word_file_path);

                return pdf_file_path_new;
42 43 44 45 46 47 48 49 50 51 52 53 54
            }
            //生成pdf openoffice
            function doc2pdf(word_file_path,pdf_file_path) {
            // word转pdf
            var pdf_file_path_new = pdf_file_path + '.pdf';
            var wordToPdf = new doc2pdf2();

            wordToPdf.doc2pdf2("C:/Program Files (x86)/OpenOffice 4",word_file_path, pdf_file_path_new);
            //删除word文件

            deleteFile(word_file_path);

            return pdf_file_path_new;
55 56
            }

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
            //生成pdf
            function AsposeWordToPDF(word_file_path,pdf_file_path) {
            // word转pdf
            var pdf_file_path_new = pdf_file_path + '.pdf';
            var wordToPdf = new AsposeUtil();

            wordToPdf.trans(word_file_path, pdf_file_path_new,"word");
            //删除word文件

            deleteFile(word_file_path);

            return pdf_file_path_new;
            }

            //按日期创建目录
72
            function getDatePath() {
73 74 75 76 77 78 79 80
            set_parameter_file_path();
            var file_path = $ctx.parameter.pdf_path; //file_path = c:/hls_test_files/content_files/
            var now = new Date()
            y = now.getFullYear()
            m = now.getMonth() + 1
            m = m < 10 ? "0" + m : m
            var datePath = file_path + y + "/" + m + "/";
            return datePath; //datePath = d:/hls_test_files/fileupload/2018/04/
81 82
            }

niminmin's avatar
niminmin committed
83
            //第一步生成合同文本
84 85 86 87 88 89 90 91 92 93 94 95
            $bm('cont.CON505.con_contract_create_content').update({
            contract_id: $ctx.parameter.contract_id,
            content_type:'NORMAL'
            });
            var datePath = getDatePath();
            FileUtils.forceMkdir(new File(datePath)); //根据日期创建目录

            var from_file_data_map=$bm('cont.CON500.con_doc_file_templet_get_atm').queryAsMap({
            contract_id:$ctx.parameter.contract_id,
            batch_flag:$ctx.parameter.batch_flag
            });
            var from_file_data = from_file_data_map.getChildren();
Spencer Chang's avatar
Spencer Chang committed
96
            for (var i = 0;i < from_file_data.length;i++) {
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
            var to_file_path = $ctx.parameter.file_path;
            var record_data = from_file_data[i];

            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+ '.' + record_data.file_type_code || 'doc';

            copyFile(from_file_path, to_file_path);


            try {
            var brwt = new BookmarksReplaceWithText($instance('leaf.database.service.IDatabaseServiceFactory'), $instance('uncertain.ocm.IObjectRegistry'), $ctx.getData());
            brwt.replaceBookmarkFromContent(to_file_path.toString(), record_data.content_id);
            } catch (e) {
            raise_app_error(e);
            }
116 117 118 119
            if (record_data.templet_code == 'FINANCE_LEASE_CONTRACT'||record_data.templet_code == 'FINANCE_LEASE_CONTRACT_A4'||record_data.templet_code == 'BUSINESS_CONTRACT'
                ||record_data.templet_code == 'BUSINESS_CONTRACT_XJ'||record_data.templet_code=='LEASE_EXCHANGE'||record_data.templet_code=='LEASE_EXCHANGE_GN'
                ||record_data.templet_code=='FINANCE_LEASE_CONTRACT_EX'||record_data.templet_code=='BUSINESS_CONTRACT_GK'||record_data.templet_code == 'REPURCHASE_DEBT_OFFSET'
                ||record_data.templet_code == 'CON_CONTRACT_LEASE_BACK'||record_data.templet_code == 'CON_CONTRACT_MORTGAGE'||record_data.templet_code == 'FINANCE_LEASE_CONTRACT_FIN'
王炜's avatar
王炜 committed
120
                ||record_data.templet_code == 'FINANCE_LEASE_CONTRACT_FIN_A4'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_TJ'||record_data.templet_code =='CON_CONTRACT_MORTGAGE_TJ'
121
                ||record_data.templet_code =='FINANCE_LEASE_CONTRACT_TJ_SURE'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_TJ_FR'
122 123 124
				||record_data.templet_code == 'FINANCE_LEASE_CONTRACT_QT'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_A4QT'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_EXQT'||record_data.templet_code =='CON_CONTRACT_LEASE_BACK_QT'
				||record_data.templet_code =='FINANCE_LEASE_CONTRACT_D_ESWJ' ||record_data.templet_code =='BUSINESS_CONTRACT_D_ESWJ_OEC'||record_data.templet_code =='BUSINESS_CONTRACT_D_ESWJ'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_FR_TJ' //update by xsh35973 添加法人铁甲保证函
				//addby xsh35973 20221017 神钢建机
gzj34291's avatar
gzj34291 committed
125 126 127 128
                ||record_data.templet_code =='FINANCE_LEASE_CONTRACT_SG'||record_data.templet_code =='FINANCE_LEASE_CON_SG'||record_data.templet_code =='BUSINESS_CONTRACT_SG'||record_data.templet_code =='CON_CONTRACT_LEASE_BACK_SG'
                //add by gzj 2022-12-23 北京卡家
                ||record_data.templet_code =='CON_COLLECTION_PAYMENT_KJ'||record_data.templet_code =='LEASE_CONTRACT_PAR_KJ_1'||record_data.templet_code =='CSH_PAYMENT_REQ_KJ'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_KJ_SURE'
                ||record_data.templet_code =='CSH_PAYMENT_REQ_KJ_1'||record_data.templet_code =='CON_CONTRACT_MORTGAGE_KJ'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_KJ_FR'||record_data.templet_code =='FINANCE_LEASE_CONTRACT_FR_KJ'
xy's avatar
xy committed
129 130 131 132
                ||record_data.templet_code =='FINANCE_LEASE_CONTRACT_KJ'||record_data.templet_code =='LEASE_CONTRACT_PAR_KJ'||record_data.templet_code =='PERSONAL_CREDIT_KJ'||record_data.templet_code =='ENTERPRISE_CREDIT_KJ'
		//add by 18938
                ||record_data.templet_code == 'BUSINESS_CONTRACT_XN' || record_data.templet_code == 'LEASE_CONTRACT_PAR_XN2'  || record_data.templet_code == 'LEASE_CONTRACT_PAR_XN' || record_data.templet_code == 'DOWN_PAYMENT_OFFSET'
                ||record_data.templet_code == 'FINANCE_LEASEBACK_CONTRACT_XN' || record_data.templet_code == 'LEASE_ORDER_XN'  || record_data.templet_code == 'LEASE_ORDER_XN2' || record_data.templet_code == 'FINANCE_LEASE_CONTRACT_XN'
陆正友's avatar
陆正友 committed
133
                ||record_data.templet_code == 'CON_CONTRACT_MORTGAGE_XN'||record_data.templet_code == 'G_LEASE_CONTRACT_PER_EX'||record_data.templet_code == 'G_LEASE_CONTRACT_PER') {
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

            // word转pdf
            var pdf_file_path=datePath+guid_file_name_tables[0].guid_file_name + 'con_' + record_data.content_id;
            var outputfilepath = wordToPdf(to_file_path,pdf_file_path);
            var outputfilename= record_data.to_file_name +'.pdf';
            var pdf_file = new File(outputfilepath);
            var file_size = 0;
            if (pdf_file.exists()) {
            file_size = pdf_file.length();
            }
            //保存文本名及路径
            $bm('cont.CON500.con_file_content_copy_update').execute({
            table_name: 'CON_CONTRACT_CONTENT',
            content_id: record_data.content_id,
            file_name: outputfilename.toString(),
            file_path: outputfilepath.toString(),
            file_size: file_size,
            file_type_code: 'pdf',
            mime_type: 'application/pdf',
            user_id: $ctx.parameter.user_id
            });
            }

            else{

            $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()
            });
            }


            }
Spencer Chang's avatar
Spencer Chang committed
169
            }
170
            ]]></s:server-script>
Spencer Chang's avatar
Spencer Chang committed
171
    </a:init-procedure>
172
</a:service>