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
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: xuls
$Date: 2016-11-24 上午11:18:19
$Revision: 1.0
$Purpose:
-->
<a:service xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure>
<s:server-script><![CDATA[
importPackage(java.io);
var head = $bm('zx.ZX5010.hls_zx_post_head_str');
var head_result = head.queryAsMap({
post_id:$ctx.parameter.post_id
});
var head_result_childs = head_result.getChildren();
var base = $bm('zx.ZX5010.hls_zx_post_base_str');
var base_result = base.queryAsMap({
post_id:$ctx.parameter.post_id
});
var base_result_childs = base_result.getChildren();
//var fw;
//由于fw不能写入其他字符集,只能写入系统默认的字符集,所以换成用out,虽然fw比较快
var out;
try{
/*fw = new FileWriter(head_result_childs[0].file_path);
fw.write(head_result_childs[0].head_str);
fw.close(); */
outWriter = new OutputStreamWriter(new FileOutputStream(head_result_childs[0].file_path),"GBK");
buf_writer = new BufferedWriter(outWriter);
/*写入报文头*/
buf_writer.write(head_result_childs[0].head_str);
//报文头写完加入两个回车换行 其中一个回车换行符 在下面处理
buf_writer.write("\r\n");
/*写入报文记录*/
//写报文基础数据
for (var i = 0;i < base_result_childs.length;i++) {
buf_writer.write("\r\n");//写入记录之前用\r\n区分
buf_writer.write(base_result_childs[i].base_str);
var new_flag = base_result_childs[i].new_flag;
if (new_flag =='2'){
buf_writer.write(base_result_childs[i].identify_str);
}
}
buf_writer.flush();
outWriter.close();
buf_writer.close();
}catch (e) {
/* var logger = $logger("server-script");
logger.severe(e.message) */
e.printStackTrace();
}
//fw.close();
]]></s:server-script>
</a:init-procedure>
</a:service>