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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
Declare Function GetDirSeparator PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;
Local JavaObject &reportDefn, &reportRow; Local string &sDirSep, &strQryName, &strRptLabel, &strTreeNode, &strLevel, &strRptWidthLen, &strLabel; Local number &i, &j, &n, &rownumber, &strProcessInstance, &sheets; Local array of string &rp_title_array; Local SQL &sqlGetBenLedgerInfoDetail, &sqlGetSubDept; Local string &strSetid, &strEmplidQr, &strDeptid, &strCompany, &strHrStatus, &strEffdt, &strSubDept, &strLanguagecd, &strOprid, &strDirectlyFlag; Local string &strLister, &strRptPersonNm, &strTabulationdate, &strCompanys, &strCompanyName, &strDirectlyFlag1, &strDepartment; Local string &strDepartmentName, &strIncludesubdept, &strEmplname, &strName1, &strHrStatus11, &strHrstatus1, &strEffdt1;
REM 获取页面参数; &strSetid = C_CERT_AET.SETID.Value; &strEmplidQr = C_CERT_AET.EMPLID.Value; &strDeptid = C_CERT_AET.DEPTID.Value; &strCompany = C_CERT_AET.COMPANY.Value; &strHrStatus = C_CERT_AET.HR_STATUS.Value; &strEffdt = C_CERT_AET.C_EFFDT.Value; &strSubDept = C_CERT_AET.C_INCLUDE_SUBDEPT.Value; &strLanguagecd = C_CERT_AET.C_LANGUAGE_DESCR.Value; &strOprid = C_CERT_AET.OPRID.Value; &strProcessInstance = C_CERT_AET.PROCESS_INSTANCE.Value;
rem 拼接多语言报表表头; Local array of string &arrRptLabel;
&arrRptLabel = CreateArray("EMPLID", "NAME", "DESCR2", "DESCR1", "C_CERT_NAME", "C_CERT_UNIT", "C_CERT_GRADE", "C_BGN_DT", "C_END_DT", "DESCRLONG"); For &n = 1 To &arrRptLabel.Len SQLExec("SELECT DESCRLONG FROM PS_C_REP_AE_TBL WHERE LANGUAGE_CD = :1 AND C_REP_AE_ID=:2", &strLanguagecd, &arrRptLabel [&n], &strLabel); &strRptLabel = &strRptLabel | "," | &strLabel; End-For;
&strRptLabel = Substring(&strRptLabel, 2, Len(&strRptLabel));
rem 报表名称; SQLExec("SELECT DESCRLONG FROM PS_C_REP_AE_TBL WHERE LANGUAGE_CD = :1 AND C_REP_AE_ID=:2", &strLanguagecd, "C_CERT_AE", &strQryName); rem 字段长度; &strRptWidthLen = "4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000,4000"; REM 报表数据表头; Local string &repSql = "SELECT DESCRLONG FROM PS_C_REP_AE_TBL WHERE LANGUAGE_CD = :1 AND C_REP_AE_ID=:2";
try &reportDefn = CreateJavaObject("com.cust.common.poi.ReportDefinition"); &sDirSep = GetDirSeparator(); &reportDefn.AddSheet(&strQryName); &reportDefn.addHeader(&strQryName); &reportDefn.mergeCells(0, 0, 0, 1); rem 设置表头信息; rem 制表人; &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); SQLExec(&repSql, &strLanguagecd, "LISTER", &strLister); &reportRow.addString(&strLister | ":"); SQLExec("SELECT NAME FROM PS_PERSONAL_DATA WHERE EMPLID = :1", %EmployeeId, &strRptPersonNm); &strRptPersonNm = %OperatorId | " " | &strRptPersonNm; &reportRow.addString(&strRptPersonNm); &reportDefn.addRow(&reportRow); rem 制表日期; &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); SQLExec(&repSql, &strLanguagecd, "TABULATION_DATE", &strTabulationdate); &reportRow.addString(&strTabulationdate | ":"); &reportRow.addString(String(%Date)); &reportDefn.addRow(&reportRow); rem 公司; If All(&strCompany) Then &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); SQLExec(&repSql, &strLanguagecd, "COMPANY", &strCompanys); &reportRow.addString(&strCompanys | ":"); SQLExec("SELECT (C_UTIL_PKG.GET_DESCR_COMPANY(:1, SYSDATE,'" | &strLanguagecd | "')) COMPANY FROM DUAL;", &strCompany, &strCompanyName); &reportRow.addString(&strCompany | " " | &strCompanyName); &reportDefn.addRow(&reportRow); End-If; REM 如果部门参数为空,部门id默认根节点 10000000,默认包含子部门; If None(&strDeptid) Then &strDeptid = "10000000"; &strSubDept = "Y"; End-If; rem 部门; If All(&strDeptid) Then &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); SQLExec(&repSql, &strLanguagecd, "DEPARTMENT", &strDepartment); &reportRow.addString(&strDepartment | ":"); SQLExec("SELECT (C_UTIL_PKG.GET_DESCR_DEPT_BY_SETID('" | &strSetid | "', :1, SYSDATE, '" | &strLanguagecd | "')) DEPT FROM DUAL;", &strDeptid, &strDepartmentName); &reportRow.addString(&strDeptid | " " | &strDepartmentName); &reportDefn.addRow(&reportRow); End-If; rem 是否包含子部门; If All(&strSubDept) Then &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); SQLExec(&repSql, &strLanguagecd, "INCLUDE_SUBDEPT", &strIncludesubdept); &reportRow.addString(&strIncludesubdept | ":"); &reportRow.addString(&strSubDept); &reportDefn.addRow(&reportRow); End-If; rem 员工; If All(&strEmplidQr) Then &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); SQLExec(&repSql, &strLanguagecd, "EMPLNAME", &strEmplname); &reportRow.addString(&strEmplname | ":"); SQLExec("SELECT (C_UTIL_PKG.GET_NAME_PERSONAL_DATA(:1, '" | &strLanguagecd | "')) NAME FROM DUAL;", &strEmplidQr, &strName1); &reportRow.addString(&strEmplidQr | " " | &strName1); &reportDefn.addRow(&reportRow); End-If; rem HR状态; If All(&strHrStatus) Then &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); SQLExec(&repSql, &strLanguagecd, "HR_STATUS", &strHrStatus11); &reportRow.addString(&strHrStatus11 | ":"); SQLExec("SELECT (C_UTIL_PKG.GET_DESCR_TRANSLATE('HR_STATUS',:1, SYSDATE, '" | &strLanguagecd | "')) HR_STATUS_DESCR FROM DUAL", &strHrStatus, &strHrstatus1); &reportRow.addString(&strHrstatus1); &reportDefn.addRow(&reportRow); End-If; &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); rem 表头; &rp_title_array = CreateArrayRept("", 0); &rp_title_array = Split(&strRptLabel, ","); For &i = 1 To &rp_title_array.Len &reportRow.addHeaderCell(&rp_title_array [&i]); End-For; &reportDefn.addRow(&reportRow); rem 获取部门ID; If &strSubDept = "Y" Then Local string &strGetSubDept = ""; &strGetSubDept = &strGetSubDept | "SELECT B.TREE_NODE, LEVEL AS LV "; &strGetSubDept = &strGetSubDept | " FROM (SELECT A.SETID, A.TREE_NODE, A.PARENT_NODE_NAME "; &strGetSubDept = &strGetSubDept | " FROM PSTREENODE A "; &strGetSubDept = &strGetSubDept | " WHERE A.TREE_NAME = 'DEPT_SECURITY' "; &strGetSubDept = &strGetSubDept | " AND A.SETCNTRLVALUE = ' ' "; &strGetSubDept = &strGetSubDept | " AND A.EFFDT = (SELECT MAX(A_ED.EFFDT) "; &strGetSubDept = &strGetSubDept | " FROM PSTREENODE A_ED "; &strGetSubDept = &strGetSubDept | " WHERE A_ED.SETID = A.SETID "; &strGetSubDept = &strGetSubDept | " AND A_ED.SETCNTRLVALUE = A.SETCNTRLVALUE"; &strGetSubDept = &strGetSubDept | " AND A_ED.TREE_NAME = A.TREE_NAME "; &strGetSubDept = &strGetSubDept | " AND A_ED.EFFDT <= SYSDATE) "; &strGetSubDept = &strGetSubDept | " AND A.SETID = '" | &strSetid | "') B "; &strGetSubDept = &strGetSubDept | " START WITH B.TREE_NODE = :1 "; &strGetSubDept = &strGetSubDept | " CONNECT BY PRIOR B.TREE_NODE = B.PARENT_NODE_NAME "; &strGetSubDept = &strGetSubDept | " ORDER BY LV "; Else &strGetSubDept = &strGetSubDept | " SELECT :1,1 FROM DUAL "; End-If; rem 拼接sql; Local string &sql = ""; &sql = &sql | "SELECT J.EMPLID, "; &sql = &sql | " (C_UTIL_PKG.GET_NAME_PERSONAL_DATA(J.EMPLID,'" | &strLanguagecd | "')) NAME, "; &sql = &sql | " (C_UTIL_PKG.GET_DESCR_POSN(J.POSITION_NBR,SYSDATE,'" | &strLanguagecd | "')) POST, "; &sql = &sql | " (C_UTIL_PKG.GET_DESCR_DEPT_BY_SETID('" | &strSetid | "',J.DEPTID, SYSDATE,'" | &strLanguagecd | "')) DEPT, "; &sql = &sql | " (C_UTIL_PKG.GET_DESCR_CERT_NAME(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) C_CERT_NAME, "; &sql = &sql | " (C_UTIL_PKG.GET_DESCR_CERT_UNIT(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) C_CERT_UNIT, "; &sql = &sql | " (C_UTIL_PKG.GET_DESCR_CERT_GRADE(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) C_CERT_GRADE, "; &sql = &sql | " CE.C_BGN_DT, "; &sql = &sql | " CE.C_END_DT, "; &sql = &sql | " (C_UTIL_PKG.GET_DESCR_DESCRLONG(J.EMPLID,CE.C_SEQUENCE_NUM,'" | &strLanguagecd | "')) DESCRLONG "; &sql = &sql | " FROM PS_JOB J ,PS_C_CERT_TBL CE "; &sql = &sql | " WHERE CE.EMPLID = J.EMPLID AND J.EMPL_RCD = '0' "; &sql = &sql | " AND J.EFFDT = (SELECT MAX(JOB_ED.EFFDT) "; &sql = &sql | " FROM PS_JOB JOB_ED "; &sql = &sql | " WHERE JOB_ED.EMPLID = J.EMPLID "; &sql = &sql | " AND JOB_ED.EMPL_RCD = J.EMPL_RCD "; &sql = &sql | " AND JOB_ED.EFFDT <= SYSDATE) "; &sql = &sql | " AND J.EFFSEQ = (SELECT MAX(JOB_ES.EFFSEQ) "; &sql = &sql | " FROM PS_JOB JOB_ES "; &sql = &sql | " WHERE JOB_ES.EMPLID = J.EMPLID "; &sql = &sql | " AND JOB_ES.EMPL_RCD = J.EMPL_RCD "; &sql = &sql | " AND JOB_ES.EFFDT = J.EFFDT) "; &sql = &sql | " AND J.DEPTID = :1 "; If All(&strEmplidQr) Then &sql = &sql | " AND J.EMPLID = '" | &strEmplidQr | "' "; End-If; If All(&strCompany) Then &sql = &sql | " AND J.COMPANY = '" | &strCompany | "' "; End-If; If All(&strHrStatus) Then &sql = &sql | " AND J.HR_STATUS = '" | &strHrStatus | "' "; End-If; If All(&strSetid) Then &sql = &sql | " AND J.SETID_DEPT = '" | &strSetid | "' "; End-If; REM 安全性限制; &sql = &sql | " AND EXISTS(SELECT 'X' FROM PS_C_DEPT_SEC_VW DS WHERE DS.OPRID = '" | &strOprid | "' AND DS.DEPTID = J.DEPTID)"; &sqlGetSubDept = CreateSQL(&strGetSubDept, &strDeptid); While &sqlGetSubDept.Fetch(&strTreeNode, &strLevel); Local array of any &result = CreateArrayAny(); &sqlGetBenLedgerInfoDetail = CreateSQL(&sql, &strTreeNode); MessageBox(0, "", 0, 0, "&strTreeNode=" | &strTreeNode); REM 循环查出的结果输出的exec表; While &sqlGetBenLedgerInfoDetail.Fetch(&result); MessageBox(0, "", 0, 0, "&result[1]=" | &result [1]); If &result.Len <> 0 Then &reportRow = CreateJavaObject("com.cust.common.poi.ReportRow"); For &i = 1 To &result.Len &reportRow.addString(String(&result [&i])); End-For; &reportDefn.addRow(&reportRow); End-If; End-While; End-While; &sqlGetSubDept.Close(); &reportDefn.prepareExcel(); rem 列宽; Local array of string &arrRptWidthlen = CreateArrayRept("", 0); &arrRptWidthlen = Split(&strRptWidthLen, ","); For &j = 1 To &arrRptWidthlen.Len Local number &wt = Value(&arrRptWidthlen [&j]); &reportDefn.setColumnWidth(&j - 1, &wt); End-For; Local string &FilePath; &FilePath = %FilePath | "/" | &strQryName | "_" | &strProcessInstance | ".xlsx"; REM 先生成一个空的文件; Local File &tempfile = GetFile(&FilePath, "W", %FilePath_Absolute); &tempfile.Close(); &reportDefn.ChangeHeaderBackgroundColor(0, 0, 163, 132); &reportDefn.ChangeHeaderFontColor(0, 255, 255, 255); &reportDefn.buildExcel(&FilePath); catch Exception &e; WriteToLog(%ApplicationLogFence_Error, &e.ToString()); end-try;
|