PeopleSoft-BI-Publisher-打印PDF证明

安装Oracle的BI_Publisher工具

根据使用系统选择对应版本下载,路径如图:

创建XML文件

根据需要动态生成的字段,创建XML文件:

创建RTF文件

根据提供的word模板生成RFT文件:

1、点击示例XML,导入上一步创建的XML文件。

2、点击字段,在需要动态赋值的字段处插入字段(如果是多行的数据,那么添加重复组即可,对应在代码里也需要写入多行数据)。

3、点击预览PDF文件。

4、测试通过。

将RTF和XML文件上传至PS系统

新增数据源文件-XML文件,路径:

新增报告定义-RTF文件,路径:

利用代码写入动态文件

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
<*----------------------------------------打印离职证明----------------------------------------*>

Function Print2
Local string &DESCR, &year, &month, &day;
Local number &i;
Local XmlDoc &xmlDoc;
Local XmlNode &root_node, &sub_node, &text_node;

Local number &check1;
Local PSXP_RPTDEFNMANAGER:ReportDefn &oRptDefn;

rem Local File &dataFile;
rem Local string &last_name, &descr, &descr2, &SNDKP;
rem Local number &index;
Local C_PACKAGE:HtmlToExcle &htmlToExlcle = create C_PACKAGE:HtmlToExcle();

/****************************写入数据 begin**************************************/
Local Rowset &RS = GetLevel0()(1).GetRowset(Scroll.C_PRINT_DATA_VW);

rem 由于员工ID是唯一主键,所以查询出来只能有一条数据;
/* For &i = 1 To &RS.ActiveRowCount;
End-For;*/
If (&RS.GetRow(1).C_PRINT_SR_WK.C_PRINT_CH.Value = 1) Then
rem Local string &filepath = &htmlToExlcle.createFolder("xml");

/*定义路径*/
&sDirSep = "/";
REM 创建路径指定的目录和在路径中指定的任何不存在的目录;
CreateDirectory("XMLP", %FilePath_Relative);
REM 字符串/files/XMLP/唯一标识符(字符串);
&RptOutputDir = GetEnv("PS_SERVDIR") | &sDirSep | "files" | &sDirSep | "XMLP" | &sDirSep | UuidGen();
REM MessageBox(0, "", 0, 0, "" | &RptOutputDir);
CreateDirectory(&RptOutputDir, %FilePath_Absolute);

Local string &filepath = &RptOutputDir | "/" | %OperatorId | %Date | ".xml";

Local File &xmlFile = GetFile(&filepath, "W", "U", %FilePath_Absolute);
rem MessageBox(0, "", 0, 0, &filepath);
If Not &xmlFile.IsOpen Then
Error ("Can't open the file " | &xmlFile);
End-If;
&xmlFile.WriteLine("<?xml version='1.0' encoding='utf-8'?>");
&xmlFile.WriteLine("<ROOT>");

REM 获取员工性别;
Local string &CC;
SQLExec("SELECT CASE WHEN SEX='M' THEN '男' ELSE '女' END FROM PS_PERSON WHERE EMPLID=:1", &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_ID.Value, &CC);
rem &xmlFile.WriteLine("<SEX>" | &CC | "</SEX>") /*性别*/;
REM MessageBox(0, "", 0, 0, "性别:" | &CC);
If &CC = "男" Then
&xmlFile.WriteLine("<NAME>" | &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_NAME.Value | "先生</NAME>") /*员工姓名-男*/;
Else
&xmlFile.WriteLine("<NAME>" | &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_NAME.Value | "女士</NAME>") /*员工姓名-女*/;
End-If;
rem &xmlFile.WriteLine("<EMPLID>" | &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_ID.Value | "</EMPLID>") /*员工ID*/;
&xmlFile.WriteLine("<CARDID>" | &RS.GetRow(1).C_PRINT_DATA_VW.NATIONAL_ID.Value | "</CARDID>"); /*身份证ID*/

rem 获取当前部门+职务(岗位)的开始时间;
Local string &bgndate;
&bgndate = String(&RS.GetRow(1).C_PRINT_DATA_VW.DATE_CHAR1.Value);
&bgnyear = Substring(&bgndate, 1, 4);
&bgnmon = Substring(&bgndate, 6, 2);
&bgnday = Substring(&bgndate, 9, 2);
&xmlFile.WriteLine("<BGNYEAR>" | &bgnyear | "</BGNYEAR>"); /*年*/
&xmlFile.WriteLine("<BGNMON>" | &bgnmon | "</BGNMON>"); /*月*/
&xmlFile.WriteLine("<BGNDAY>" | &bgnday | "</BGNDAY>"); /*日*/

rem 获取当前部门+职务(岗位)的结束时间;
Local string &enddate;
&enddate = String(&RS.GetRow(1).C_PRINT_DATA_VW.DATE_CHAR.Value);
&endyear = Substring(&enddate, 1, 4);
&endmon = Substring(&enddate, 6, 2);
&endday = Substring(&enddate, 9, 2);
&xmlFile.WriteLine("<ENDYEAR>" | &endyear | "</ENDYEAR>"); /*年*/
&xmlFile.WriteLine("<ENDMON>" | &endmon | "</ENDMON>"); /*月*/
&xmlFile.WriteLine("<ENDDAY>" | &endday | "</ENDDAY>"); /*日*/


&xmlFile.WriteLine("<DEPT>" | &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_DT_DSCR.Value | "</DEPT>"); /*部门*/
&xmlFile.WriteLine("<POSITION>" | &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_POST.Value | "</POSITION>"); /*职务*/
rem 获取离职原因;
Local string &reason;
SQLExec("select r.descr from ps_job j,ps_ACTN_REASON_TBL r where j.action_reason = r.ACTION_REASON and j.effdt = (select max(pj.effdt) from ps_job pj where pj.emplid = j.emplid and pj.effdt < sysdate and pj.empl_rcd = '0') and j.effseq = (select max(pj1.effseq) from ps_job pj1 where pj1.emplid = j.emplid) and j.emplid = :1;", &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_ID.Value, &reason);
&xmlFile.WriteLine("<REASON>" | &reason | "</REASON>"); /*离职原因*/

&xmlFile.WriteLine("<JYXY>未签订竞业限制协议。</JYXY>"); /*未签订竞业协议*/
rem 获取竞业协议;
REM if *** = ture then
&xmlFile.WriteLine("<JYXY>"|"未签订竞业限制协议"|"</JYXY>"); /*未签订竞业协议*/
REM else
&xmlFile.WriteLine("<JYXY>"|"签订竞业限制协议(协议期限为劳动合同解除或终止之日起满XXX个月)"|"</JYXY>"); /*签订竞业协议*/
REM end-if;

&xmlFile.WriteLine("<COM>" | &RS.GetRow(1).C_PRINT_DATA_VW.COMPANYID.Value | "</COM>"); /*公司*/
rem 获取系统年月日;
Local string &sysdate;
SQLExec("SELECT TO_CHAR(SYSDATE , 'YYYY-MM-DD') FROM DUAL", &sysdate);
REM &sysdate = String(%DATE);
REM MessageBox(0, "", 0, 0, "系统时间:" | &sysdate);
&sysyear = Substring(&sysdate, 1, 4);
&sysmon = Substring(&sysdate, 6, 2);
&sysday = Substring(&sysdate, 9, 2);
&xmlFile.WriteLine("<SYSYEAR>" | &sysyear | "</SYSYEAR>"); /*年*/
&xmlFile.WriteLine("<SYSMON>" | &sysmon | "</SYSMON>"); /*月*/
&xmlFile.WriteLine("<SYSDAY>" | &sysday | "</SYSDAY>"); /*日*/
&xmlFile.WriteLine("</ROOT>");

rem C_PERS_TEMP_VW;
/****************************写入数据 end**************************************/
&xmlFile.Close();

&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn("C_EMP_I_TEMP");
&oRptDefn.Get();
rem &oRptDefn.OutDestination = %FilePath;
&oRptDefn.SetRuntimeDataXMLFile(&filepath);
rem &oRptDefn.ProcessInstance = &ProcessInstance;
&oRptDefn.ProcessReport("C_EMP_I_TEMP_1", "ZHS", %Date, "");

CommitWork();

&oRptDefn.DisplayOutput();
REM &oRptDefn.Publish("", "", "", &ProcessInstance);
try
catch Exception &Err
If Not &oRptDefn = Null Then
&oRptDefn.Close();
End-If;
WriteToLog(%ApplicationLogFence_Error, &Err.ToString());
&Err.Output();

end-try;
/**************把下载成功的数据写入到log表中********************/
SQLExec("select 1 from ps_c_print_log where c_print_id=:1", &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_ID.Value, &check1);

If &check1 = 0 Then
Local Record &REC = CreateRecord(Record.C_PRINT_LOG);
&REC.C_PRINT_ID.Value = &RS.GetRow(1).C_PRINT_DATA_VW.C_PRINT_ID.Value;
&REC.C_PRINT_FLAG.Value = "1";
&REC.Insert();
CommitWork();
End-If;
Else
Error "请勾选需要打印证明的员工";
End-If;
End-Function;