Commit 3ea6f018 authored by 18083's avatar 18083

非银企直连附件优化

parent 240fda59
<?xml version="1.0" encoding="UTF-8"?> <?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:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure> <a:init-procedure>
<s:server-script import="con_print_path.js"><![CDATA[ <s:server-script import="contract_print_path.js"><![CDATA[
set_parameter_file_path();
]]></s:server-script>
<s:server-script><![CDATA[
importPackage(java.io); importPackage(java.io);
importPackage(Packages.hls.plugin.docx4j); importPackage(Packages.hls.plugin.docx4j);
...@@ -19,6 +16,18 @@ ...@@ -19,6 +16,18 @@
fis.close(); fis.close();
fos.close(); fos.close();
} }
//按日期创建目录
function getDatePath() {
set_parameter_file_path();
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 datePath = file_path + y + "/" + m + "/";
return datePath;
}
//获取文件长度 //获取文件长度
function get_file_length(path){ function get_file_length(path){
var file=new File(String(path)); var file=new File(String(path));
...@@ -30,6 +39,9 @@ ...@@ -30,6 +39,9 @@
} }
} }
try {
var datePath = getDatePath();
FileUtils.forceMkdir(new File(datePath)); //根据日期创建目录
//获取原文件信息 //获取原文件信息
var file_templet_get_atm_path = $bm('csh.CSH501.csh_journal_get_atm').queryAsMap({ var file_templet_get_atm_path = $bm('csh.CSH501.csh_journal_get_atm').queryAsMap({
payment_req_id: $ctx.parameter.payment_req_id, payment_req_id: $ctx.parameter.payment_req_id,
...@@ -37,7 +49,7 @@ ...@@ -37,7 +49,7 @@
}); });
var from_file_data = file_templet_get_atm_path.getChildren(); var from_file_data = file_templet_get_atm_path.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 = datePath;
var record_data = from_file_data[i]; var record_data = from_file_data[i];
var to_file_name = record_data.to_file_name; var to_file_name = record_data.to_file_name;
...@@ -63,10 +75,10 @@ ...@@ -63,10 +75,10 @@
file_type_code:file_type_code, file_type_code:file_type_code,
mime_type:mime_type, mime_type:mime_type,
}); });
} }
} catch (e) {
raise_app_error(e);
}
]]></s:server-script> ]]></s:server-script>
</a:init-procedure> </a:init-procedure>
</a:service> </a:service>
......
...@@ -814,9 +814,7 @@ ...@@ -814,9 +814,7 @@
if (!Leaf.isEmpty(temp[0])) { if (!Leaf.isEmpty(temp[0])) {
var file_name = temp[0].toUpperCase(); var file_name = temp[0].toUpperCase();
var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase(); var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
if (file_name.indexOf('.PDF') >= 0) { if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
url = url + '<a href=javascript:view_pdf(\'' + temp[1] + '\')>' + temp[0] + '</a>' + ',';
} else if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ','; url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
} else { } else {
url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ','; url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
......
...@@ -2,80 +2,160 @@ ...@@ -2,80 +2,160 @@
<a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true"> <a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure> <a:init-procedure>
<a:model-update model="hls.HLS811.hls_doc_file_templet_get_atm"/> <a:model-update model="hls.HLS811.hls_doc_file_templet_get_atm"/>
<s:server-script import="con_print_path.js"><![CDATA[ <s:server-script import="contract_print_path.js"><![CDATA[
importPackage(Packages.hls.plugin.docx4j); importPackage(java.io);
importPackage(Packages.com.hand.hls.hlcm.util); importPackage(Packages.hls.plugin.docx4j);
importPackage(java.io); importPackage(Packages.leaf.plugin.word2pdf);
importPackage(Packages.org.apache.commons.io);
function copyFile(fOld, fNew) { //删除文件
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';
var wordToPdf = new WordToPdf($instance('uncertain.ocm.IObjectRegistry'), "jacob-1.19-x64.dll");
wordToPdf.word2pdf(word_file_path, pdf_file_path_new);
//删除word文件
//deleteFile(word_file_path);
return pdf_file_path_new;
}
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 transfer(file_path, os) { function transfer(file_path, os) {
println(file_path); println(file_path);
var fis = new FileInputStream(file_path); var fis = new FileInputStream(file_path);
var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 64); var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 64);
var len = -1; var len = -1;
while ((len = fis.read(b)) != -1) { while ((len = fis.read(b)) != -1) {
os.write(b, 0, len); os.write(b, 0, len);
} }
fis.close(); fis.close();
}
function write_os_to_file(file, os) {
var fis = new FileInputStream(file);
var b = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 64);
var len = -1;
while ((len = fis.read(b)) != -1) {
os.write(b, 0, len);
} }
fis.close();
}
//按日期创建目录
function getDatePath() {
set_parameter_file_path();
var file_path = $ctx.parameter.pdf_path;
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;
}
var attachment_batch_dl = $bm('hls.HLS811.hls_doc_file_templet_get_atm'); function collection_create_content() {
var result = attachment_batch_dl.queryAsMap({ try {
document_id: $ctx.parameter.document_id, var datePath = getDatePath();
document_table: $ctx.parameter.document_table,
batch_flag: $ctx.parameter.batch_flag,
content_id: $ctx.parameter.content_id
});
var from_file_data = result.getChildren();
for (var i = 0;i < from_file_data.length;i++) {
if (!$ctx.parameter.file_path) {
set_parameter_file_path();
}
var to_file_path = $ctx.parameter.file_path;
var record_data = from_file_data[i];
var to_file_name = record_data.to_file_name; FileUtils.forceMkdir(new File(datePath)); //根据日期创建目录
var from_file_path = record_data.file_path; var attachment_batch_dl = $bm('hls.HLS811.hls_doc_file_templet_get_atm');
var guid_file_name_path = $bm('cont.CON500.con_contract_get_guid_file_name').queryAsMap(); var result = attachment_batch_dl.queryAsMap({
var guid_file_name_tables = guid_file_name_path.getChildren(); document_id: $ctx.parameter.document_id,
to_file_path = to_file_path + guid_file_name_tables[0].guid_file_name + 'doc' + record_data.content_id; document_table: $ctx.parameter.document_table,
batch_flag: $ctx.parameter.batch_flag,
content_id: $ctx.parameter.content_id
});
var from_file_data = result.getChildren();
for (var i = 0;i < from_file_data.length;i++) {
if (!$ctx.parameter.file_path) {
set_parameter_file_path();
}
var to_file_path = $ctx.parameter.file_path;
var record_data = from_file_data[i];
copyFile(from_file_path, to_file_path); var to_file_name = record_data.to_file_name;
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 = datePath + guid_file_name_tables[0].guid_file_name + 'doc' + record_data.content_id;
copyFile(from_file_path, to_file_path);
$bm('hls.HLS811.hls_file_content_copy_update').update({
table_name: 'PAYMENT_APPROVAL_PROCESS',
content_id: $ctx.parameter.journal_id,
file_name: to_file_name.toString(),
file_path: to_file_path.toString(),
source_type: $ctx.parameter.source_type
});
try {
$bm('csh.CSH501.csh_transaction_return_print').update({ try {
document_id: $ctx.parameter.document_id, $bm('csh.CSH501.csh_transaction_return_print').update({
document_table: $ctx.parameter.document_table document_id: $ctx.parameter.document_id,
}); document_table: $ctx.parameter.document_table
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.toString(), 'COMMON'); var brwt = new BookmarksReplaceWithText($instance('leaf.database.service.IDatabaseServiceFactory'), $instance('uncertain.ocm.IObjectRegistry'), $ctx.getData());
var resp = $ctx['_instance.javax.servlet.http.HttpServletResponse']; brwt.replaceBookmarkFromContent(to_file_path.toString(), record_data.content_id.toString(), 'COMMON');
} catch (e) { } catch (e) {
raise_app_error(e); raise_app_error(e);
}
// word转pdf
var pdf_file_path=to_file_path;
var outputfilepath = wordToPdf(to_file_path,pdf_file_path);
var filename_str = record_data.to_file_name;
var outputfilename= filename_str.substr(0, filename_str.length - 5) +'.pdf';
var pdf_file = new File(outputfilepath);
var file_size = 0;
if (pdf_file.exists()) {
file_size = pdf_file.length();
}
$bm('csh.CSH501.csh_journal_get_atm').execute({
table_name: 'PAYMENT_APPROVAL_PROCESS',
journal_id: $ctx.parameter.journal_id,
file_name: outputfilename.toString(),
file_path: outputfilepath.toString(),
user_id :$ctx.parameter.user_id,
file_size: file_size,
file_type_code:'pdf',
mime_type:'application/pdf',
});
} }
}
$ctx.parameter.return_status = 'S';
$ctx.parameter.return_message = '执行成功';
} catch (e) {
$ctx.success = "true";
$ctx.parameter.return_status = 'E';
$ctx.parameter.return_message = $ctx.get('/error/@message') || String(e);
raise_app_error(e);
}
var result = {
result: $ctx.parameter.return_status,
message: $ctx.parameter.return_message
};
$ctx.parameter.json = JSON.stringify(result);
}
if ($ctx.parameter.return_status != 'E' && $ctx.parameter.return_status != 'TIMEOUT') {
collection_create_content();
}
]]></s:server-script> ]]></s:server-script>
</a:init-procedure> </a:init-procedure>
<a:service-output/>
</a:service> </a:service>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true"> <a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure> <a:init-procedure>
<a:model-update model="hls.HLS811.hls_doc_file_templet_get_atm"/> <a:model-update model="hls.HLS811.hls_doc_file_templet_get_atm"/>
<s:server-script import="con_print_path.js"><![CDATA[ <s:server-script import="contract_print_path.js"><![CDATA[
importPackage(Packages.hls.plugin.docx4j); importPackage(Packages.hls.plugin.docx4j);
importPackage(java.io); importPackage(java.io);
...@@ -18,6 +18,17 @@ ...@@ -18,6 +18,17 @@
fos.close(); fos.close();
} }
//获取文件长度
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 transfer(file_path, os) { function transfer(file_path, os) {
println(file_path); println(file_path);
var fis = new FileInputStream(file_path); var fis = new FileInputStream(file_path);
...@@ -29,7 +40,21 @@ ...@@ -29,7 +40,21 @@
fis.close(); fis.close();
} }
//按日期创建目录
function getDatePath() {
set_parameter_file_path();
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 datePath = file_path + y + "/" + m + "/";
return datePath;
}
try {
var datePath = getDatePath();
FileUtils.forceMkdir(new File(datePath)); //根据日期创建目录
var attachment_batch_dl = $bm('hls.HLS811.hls_doc_file_templet_get_atm'); var attachment_batch_dl = $bm('hls.HLS811.hls_doc_file_templet_get_atm');
var result = attachment_batch_dl.queryAsMap({ var result = attachment_batch_dl.queryAsMap({
document_id: $ctx.parameter.document_id, document_id: $ctx.parameter.document_id,
...@@ -42,7 +67,7 @@ ...@@ -42,7 +67,7 @@
if (!$ctx.parameter.file_path) { if (!$ctx.parameter.file_path) {
set_parameter_file_path(); set_parameter_file_path();
} }
var to_file_path = $ctx.parameter.file_path; var to_file_path = datePath;
var record_data = from_file_data[i]; var record_data = from_file_data[i];
var to_file_name = record_data.to_file_name; var to_file_name = record_data.to_file_name;
...@@ -52,13 +77,17 @@ ...@@ -52,13 +77,17 @@
to_file_path = to_file_path + guid_file_name_tables[0].guid_file_name + 'doc' + record_data.content_id; to_file_path = to_file_path + guid_file_name_tables[0].guid_file_name + 'doc' + record_data.content_id;
copyFile(from_file_path, to_file_path); copyFile(from_file_path, to_file_path);
//生成文件的大小
$bm('hls.HLS811.hls_file_content_copy_update').update({ var file_size=get_file_length(to_file_path.toString());
table_name: 'PAYMENT_APPROVAL_PROCESS', $bm('csh.CSH501.csh_journal_get_atm').execute({
content_id: $ctx.parameter.journal_id, table_name: 'PAYMENT_APPROVAL_PROCESS',
file_name: to_file_name.toString(), journal_id: $ctx.parameter.journal_id,
file_path: to_file_path.toString(), file_name: to_file_name.toString(),
source_type: $ctx.parameter.source_type file_path: to_file_path.toString(),
user_id :$ctx.parameter.user_id,
file_size: file_size,
file_type_code:'docx',
mime_type:'application/msword',
}); });
try { try {
...@@ -70,9 +99,11 @@ ...@@ -70,9 +99,11 @@
brwt.replaceBookmarkFromContent(to_file_path.toString(), record_data.content_id.toString(), 'COMMON'); brwt.replaceBookmarkFromContent(to_file_path.toString(), record_data.content_id.toString(), 'COMMON');
} catch (e) { } catch (e) {
raise_app_error(e); raise_app_error(e);
} }
}
} } catch (e) {
raise_app_error(e);
}
]]></s:server-script> ]]></s:server-script>
</a:init-procedure> </a:init-procedure>
</a:service> </a:service>
...@@ -95,9 +95,7 @@ ...@@ -95,9 +95,7 @@
if (!Leaf.isEmpty(temp[0])) { if (!Leaf.isEmpty(temp[0])) {
var file_name = temp[0].toUpperCase(); var file_name = temp[0].toUpperCase();
var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase(); var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
if (file_name.indexOf('.PDF') >= 0) { if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
url = url + '<a href=javascript:view_pdf(\'' + temp[1] + '\')>' + temp[0] + '</a>' + ',';
} else if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ','; url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
} else { } else {
url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ','; url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
......
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