Commit 2f71211b authored by stone's avatar stone

【fix】合同文本打印修改

parent 71675f61
...@@ -8,24 +8,24 @@ ...@@ -8,24 +8,24 @@
importPackage(Packages.hls.plugin.docx4j); importPackage(Packages.hls.plugin.docx4j);
importPackage(Packages.leaf.plugin.word2pdf); importPackage(Packages.leaf.plugin.word2pdf);
importPackage(Packages.org.apache.commons.io); importPackage(Packages.org.apache.commons.io);
function copyFile(fOld, fNew) { function copyFile(fOld, fNew) {
var fis = new java.io.FileInputStream(fOld); var fis = new java.io.FileInputStream(fOld);
var fos = new java.io.FileOutputStream(fNew); var fos = new java.io.FileOutputStream(fNew);
var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 4); var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 4);
var len = -1; var len = -1;
while ((len = fis.read(b)) != -1) { while ((len = fis.read(b)) != -1) {
fos.write(b, 0, len); fos.write(b, 0, len);
} }
fis.close(); fis.close();
fos.close(); fos.close();
} }
//删除文件 //删除文件
function deleteFile(filePath) { function deleteFile(filePath) {
var file = new File(filePath); var file = new File(filePath);
if (file.exists()) { if (file.exists()) {
file.delete(); file.delete();
} }
} }
//生成pdf //生成pdf
...@@ -37,77 +37,118 @@ ...@@ -37,77 +37,118 @@
//删除word文件 //删除word文件
// deleteFile(word_file_path); // deleteFile(word_file_path);
return pdf_file_path_new; return pdf_file_path_new;
}
//生成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;
} }
//按日期创建目录 //生成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;
}
//按日期创建目录
function getDatePath() { function getDatePath() {
set_parameter_file_path(); set_parameter_file_path();
var file_path = $ctx.parameter.pdf_path; //file_path = c:/hls_test_files/content_files/ var file_path = $ctx.parameter.pdf_path; //file_path = c:/hls_test_files/content_files/
var now = new Date() var now = new Date()
y = now.getFullYear() y = now.getFullYear()
m = now.getMonth() + 1 m = now.getMonth() + 1
m = m < 10 ? "0" + m : m m = m < 10 ? "0" + m : m
var datePath = file_path + y + "/" + m + "/"; var datePath = file_path + y + "/" + m + "/";
return datePath; //datePath = d:/hls_test_files/fileupload/2018/04/ return datePath; //datePath = d:/hls_test_files/fileupload/2018/04/
} }
//第一步生成合同文本 //第一步生成合同文本
$bm('cont.CON505.con_contract_create_content').update({ $bm('cont.CON505.con_contract_create_content').update({
contract_id: $ctx.parameter.contract_id, contract_id: $ctx.parameter.contract_id,
content_type:'NORMAL' content_type:'NORMAL'
}); });
var datePath = getDatePath(); var datePath = getDatePath();
FileUtils.forceMkdir(new File(datePath)); //根据日期创建目录 FileUtils.forceMkdir(new File(datePath)); //根据日期创建目录
var from_file_data_map=$bm('cont.CON500.con_doc_file_templet_get_atm').queryAsMap({ var from_file_data_map=$bm('cont.CON500.con_doc_file_templet_get_atm').queryAsMap({
contract_id:$ctx.parameter.contract_id, contract_id:$ctx.parameter.contract_id,
batch_flag:$ctx.parameter.batch_flag batch_flag:$ctx.parameter.batch_flag
}); });
var from_file_data = from_file_data_map.getChildren(); var from_file_data = from_file_data_map.getChildren();
for (var i = 0;i < from_file_data.length;i++) { for (var i = 0;i < from_file_data.length;i++) {
var to_file_path = $ctx.parameter.file_path; var to_file_path = $ctx.parameter.file_path;
var record_data = from_file_data[i]; var record_data = from_file_data[i];
if (record_data.file_exists_flag != 'Y') { if (record_data.file_exists_flag != 'Y') {
var to_file_name = record_data.to_file_name + '.' + record_data.file_type_code || 'doc'; var to_file_name = record_data.to_file_name + '.' + record_data.file_type_code || 'doc';
var from_file_path = record_data.file_path; 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_path = $bm('cont.CON500.con_contract_get_guid_file_name').queryAsMap();
var guid_file_name_tables = guid_file_name_path.getChildren(); 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; 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); copyFile(from_file_path, to_file_path);
try { try {
var brwt = new BookmarksReplaceWithText($instance('leaf.database.service.IDatabaseServiceFactory'), $instance('uncertain.ocm.IObjectRegistry'), $ctx.getData()); 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); brwt.replaceBookmarkFromContent(to_file_path.toString(), record_data.content_id);
} catch (e) { } catch (e) {
raise_app_error(e); raise_app_error(e);
} }
// word转pdf if (record_data.templet_code == 'FINANCE_LEASE_CONTRACT'||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') {
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); // word转pdf
var outputfilename= record_data.to_file_name +'.pdf'; var pdf_file_path=datePath+guid_file_name_tables[0].guid_file_name + 'con_' + record_data.content_id;
var pdf_file = new File(outputfilepath); var outputfilepath = wordToPdf(to_file_path,pdf_file_path);
println(outputfilepath); var outputfilename= record_data.to_file_name +'.pdf';
var file_size = 0; var pdf_file = new File(outputfilepath);
if (pdf_file.exists()) { var file_size = 0;
file_size = pdf_file.length(); if (pdf_file.exists()) {
} file_size = pdf_file.length();
//保存文本名及路径 }
$bm('cont.CON500.con_file_content_copy_update').execute({ //保存文本名及路径
table_name: 'CON_CONTRACT_CONTENT', $bm('cont.CON500.con_file_content_copy_update').execute({
content_id: record_data.content_id, table_name: 'CON_CONTRACT_CONTENT',
file_name: outputfilename.toString(), content_id: record_data.content_id,
file_path: outputfilepath.toString(), file_name: outputfilename.toString(),
file_size: file_size, file_path: outputfilepath.toString(),
file_type_code: 'pdf', file_size: file_size,
mime_type: 'application/pdf', file_type_code: 'pdf',
user_id: $ctx.parameter.user_id 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()
});
}
}
} }
]]></s:server-script> ]]></s:server-script>
</a:init-procedure> </a:init-procedure>
</a:service> </a:service>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment