con_contract_print_pdf.lsc 8.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 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 169 170 171 172 173 174 175 176
<?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:service xmlns:ns1="leaf.application.action" 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.java.lang);
            importPackage(Packages.com.hand.kinggrid);
            importPackage(Packages.com.hand.hl);
            importPackage(Packages.leaf.plugin.word2pdf);
            importPackage(Packages.java.io);
            importPackage(java.io);
            //获取日期目录
            var datePath = getDate();
            var tranfer_dir= new File(String(datePath));
                if(!tranfer_dir.exists()){//如果文件夹不存在,创建文件夹
                       tranfer_dir.mkdirs();//创建文件夹
                                    }
            try{
                 var sys_url_bm=$bm('cont.CON4000.get_sys_url');
                 var parameter_code='HLS_SYSTEM_URL';
                 var SysurlQuery = sys_url_bm.queryAsMap({
                                        parameter_code: parameter_code
                                });

                var sys_url = SysurlQuery.getChildren()[0].parameter_value;
                var down_url =sys_url+'con/contract/conExportExcel?contractId=' +$ctx.parameter.contract_id;
                var now = new Date();
                y = now.getFullYear();
                m = now.getMonth() + 1;
                m = m < 10 ? "0" + m : m;
                d = now.getDate();
                d = d < 10 ? "0" + d : d;
                h = now.getHours();
                h = h < 10 ? "0" + h : h;
                mi = now.getMinutes();
                mi = mi < 10 ? "0" + mi : mi;
                var sys_file_path_bm=$bm('cont.CON4000.get_sys_url');
                var parameter_code='TEMPORARY_FILES';
                var SysurlQuery = sys_url_bm.queryAsMap({
                                    parameter_code: parameter_code
                                });

                var sys_file_path = SysurlQuery.getChildren()[0].parameter_value;
                var f_fileDir = sys_file_path;
                var filePath = (f_fileDir + y + "\/" + m + "\/").toString();
                //var filePath = (f_fileDir + y + "//" + m + "//").toString();
                var tranfer_dir= new File(String(filePath));
                if(!tranfer_dir.exists()){//如果文件夹不存在,创建文件夹
                       tranfer_dir.mkdirs();//创建文件夹
                                    }
                var contract_number =  $ctx.parameter.contract_number;
                var file_name =  $ctx.parameter.file_name + y + m + d + h + mi + ".xlsx";
                var f_fileName = file_name.toString();
                var result_flag=DoloadFileByUrl.downloadFile(down_url, filePath, f_fileName);

                //excel 转pdf
                var to_file_path = filePath + file_name;
                var pdf_file_path= filePath + $ctx.parameter.file_name + y + m + d + h + mi + ".pdf";
                println('to_file_path  = ' + to_file_path);
				println('pdf_file_path  = ' + pdf_file_path);
                var outputfilepath = wordToPdf(to_file_path,pdf_file_path);

                file_size=get_file_length(outputfilepath);
                pdf_path =(pdf_file_path).toString()
                println('p_file_name = '+ $ctx.parameter.file_name + y + m + d + h + mi + ".pdf");
                println('contract_id  = ' + $ctx.parameter.contract_id);
                word_to_pdf_sign($ctx.parameter.contract_id,pdf_file_path,$ctx.parameter.file_name);

                if(result_flag=true){
                   var business_daily_email=$bm('cont.CON301N.insert_into_attachment_bmp').update({
                        p_file_path     :(datePath + $ctx.parameter.file_name + y + m + d + h + mi + ".pdf").toString(),
                        p_file_name     :($ctx.parameter.file_name + y + m + d + h + mi + ".pdf").toString(),
                        p_file_size     :file_size,
                        p_user_id       :$ctx.session.user_id,
                        p_contract_id   :$ctx.parameter.contract_id,
                        p_file_type     :'PDF',
                        p_lease_type    :'01'
                });
                }

            }catch(e){
                 raise_app_error(e.message);
            }

            function get_file_length(path){
                var file=new File(String(path));
                if(file.exists() && file.isFile()){
                    length=file.length();
                    return length;
                }else{
                     return 0 ;
                }
            }


            function wordToPdf(word_file_path,pdf_file_path) {
            // excel转pdf
            //var pdf_file_path_new = pdf_file_path + '.pdf';
            var pdf_file_path_new = pdf_file_path;
            var wordToPdf = new WordToPdf($instance('uncertain.ocm.IObjectRegistry'), "jacob-1.19-x64.dll");
            wordToPdf.exceltopdf(word_file_path, pdf_file_path_new);
            //删除word文件
            //deleteFile(word_file_path);
            return pdf_file_path_new;
        }
           function getDate() {
                var file_path = $ctx.parameter.file_path;
                var now = new Date()
                y = now.getFullYear()
                m = now.getMonth() + 1
                m = m < 10 ? "0" + m : m
                var path = file_path + y + "/" + m + "/";
                return path;
            }
        function word_to_pdf_sign(content_id,pdf_file_path,file_name) {
                importPackage(Packages.com.hl.signatures);
                importPackage(Packages.java.io);
                importPackage(Packages.java.util);

                var org_flag = '';
                var qf_flag = '';
                var param = new ArrayList();
                var paramdetail;
                var attachment_update = $bm('cont.CON620.con_contract_save_pdf_atm');
                var file_name = file_name;
                    var file_path = pdf_file_path;
                    if (file_name.substring(file_name.length - 4) == '.doc') {
                        file_name = file_name.substring(0, file_name.length - 4);
                    } else if (file_name.substring(file_name.length - 5) == '.docx') {
                        file_name = file_name.substring(0, file_name.length - 5);
                    }
                    var outputfilepath = pdf_file_path;// 由于wordToPdf转换后pdf文件已经带有.pdf
                    var wordToPdf = new WordToPdf($instance('uncertain.ocm.IObjectRegistry'), "jacob-1.19-x64.dll");
                    //wordToPdf.word2pdf(file_path, outputfilepath);

                    var con_signature_info = $bm('cont.CON620.get_con_signature_info').queryAsMap();
                    var con_signature_data = con_signature_info.getChildren();
                    var con_signature_record;

                    for (var i = 0;i < con_signature_data.length;i++) {

                        con_signature_record = con_signature_data[i];

                        println(con_signature_record.signature_code);
                        if (con_signature_record.signature_code == 'gz_flag'){
                             paramdetail = '[{ "code":"' + con_signature_record.code +
                                    '", "seal_code":"' + con_signature_record.seal_code +
                                    '", "seal_width":' + con_signature_record.seal_width +
                                    ', "fontname":"' + con_signature_record.fontname +
                                    '", "fontsize":"' + con_signature_record.fontsize +
                                    '", "fontcolor":"' + con_signature_record.fontcolor +
                                    '", "pageno":"' + con_signature_record.pageno +
                                    '", "text":"' + con_signature_record.word_code + '"}]';
                        }
                        param.add(paramdetail);
                    }

                    var con_signature_info = $bm('cont.CON620.get_kinggrid_info').queryAsMap();
                    var con_kinggrid_data = con_signature_info.getChildren()[0];
                    var server_url = con_kinggrid_data.server_url;
                    var app_id = con_kinggrid_data.app_id;
                    var app_security = con_kinggrid_data.app_security;
                    var status = new com.hand.kinggrid.ContractSignaturesNew.hl_contract_signatures(outputfilepath, 1,param.toArray(),server_url,app_id,app_security,datePath);

<!--                    attachment_update.update({-->
<!--                        content_id: content_id,-->
<!--                        table_name: 'HLS_DOC_FILE_CONTENT'-->
<!--                    });-->
            }


        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter"/>
</a:service>