|
@@ -0,0 +1,255 @@
|
|
|
+package com.kingdee.eas.custom.ssPDF.handler;
|
|
|
+
|
|
|
+import com.itextpdf.text.DocumentException;
|
|
|
+import com.itextpdf.text.pdf.*;
|
|
|
+import com.kingdee.bos.BOSException;
|
|
|
+import com.kingdee.bos.Context;
|
|
|
+import com.kingdee.eas.base.permission.UserInfo;
|
|
|
+import com.kingdee.eas.custom.shengshen.utils.PDFFillInformationUtil;
|
|
|
+import com.kingdee.eas.hr.ats.AtsUtil;
|
|
|
+import com.kingdee.eas.util.app.ContextUtil;
|
|
|
+import com.kingdee.eas.util.app.DbUtil;
|
|
|
+import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
+import com.kingdee.shr.affair.web.handler.hrman.ResignBizBillHrManListHandler;
|
|
|
+
|
|
|
+import com.kingdee.shr.base.syssetting.context.SHRContext;
|
|
|
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
|
|
|
+import com.kingdee.shr.base.syssetting.web.dynamic.util.DynamicUtil;
|
|
|
+import com.kingdee.shr.base.syssetting.web.dynamic.util.MD5;
|
|
|
+import com.kingdee.shr.base.syssetting.web.util.UserUtil;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.io.*;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author cml
|
|
|
+ * @date 2024/9/10
|
|
|
+ * @apiNote
|
|
|
+ */
|
|
|
+public class ResignBizBillHrManListHandlerEx extends ResignBizBillHrManListHandler {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 离职员工生成离职PDF
|
|
|
+ * @param request templatePrint
|
|
|
+ * @param response
|
|
|
+ * @param modelMap
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public void importPDFAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws IOException, SHRWebException {
|
|
|
+ generatePDF(request,response,modelMap);
|
|
|
+ }
|
|
|
+ public void generatePDF(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ Context ctx = SHRContext.getInstance().getContext();//上下文
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
+ String tempFilePath1 = UserUtil.getUserTempDirAbsolutePath(session); //存放
|
|
|
+ File tempFile1 = new File(tempFilePath1);
|
|
|
+ if (!tempFile1.exists()) {
|
|
|
+ tempFile1.mkdirs();
|
|
|
+ }
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
+ try{
|
|
|
+ String numbers = request.getParameter("number");
|
|
|
+ String number = "";
|
|
|
+ String[] split = numbers.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ list.add(split[i]);
|
|
|
+ }
|
|
|
+ List<Set<String>> listSet = this.splitListIntoSets(list, 20); //超过 20(需要)第二页 pdf
|
|
|
+ List<File> listFile = new ArrayList<>();
|
|
|
+ for (int i = 0; i < listSet.size(); i++) {
|
|
|
+ Set<String> set = listSet.get(i);
|
|
|
+ Map<String, String> data = getSql(set, ctx, listSet.size(), i);
|
|
|
+ if (data.containsKey("msgType") && "0".equals(data.get("msgType"))){
|
|
|
+ this.writeSuccessData(data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ number = data.get("number");
|
|
|
+ PDFFillInformationUtil pdfFillInformationUtil = new PDFFillInformationUtil();
|
|
|
+ String realPath = session.getServletContext().getRealPath("/") + "addon/custom/html/DSF_Mod.pdf";
|
|
|
+ File file = new File(realPath);
|
|
|
+ byte[] pdfBytes = convertPdfToByteArray(file);
|
|
|
+ File file1 = pdfFillInformationUtil.fillInformation(pdfBytes, data, tempFilePath1, "DSF_Mod"+i+".pdf");
|
|
|
+ listFile.add(file1);
|
|
|
+ }
|
|
|
+ //压缩文件名
|
|
|
+ String zipName = "员工离职_" + time + ".zip";
|
|
|
+ String zipNameHash = MD5.md5Hash(zipName);
|
|
|
+ String realFileName = getEncryRealFileName(ctx,zipNameHash);
|
|
|
+ String fileStr = zipNameHash;
|
|
|
+ String zipPath = tempFilePath1 + File.separator + realFileName;
|
|
|
+ PDFFillInformationUtil.compress(zipPath, listFile);
|
|
|
+
|
|
|
+ Map<String, String> param = new HashMap<String, String>();
|
|
|
+ param.put("method", "tmp");
|
|
|
+ param.put("file", fileStr);
|
|
|
+ param.put("filename", zipName);
|
|
|
+ String link = DynamicUtil.assembleUrl("/shr/downloadfile.do", param).replaceAll("\\+", "%20");
|
|
|
+ map.put("msg","离职pdf导出:" + split.length + "条数据;成功:" + number + ";失败:" + (split.length - Integer.parseInt(number)));
|
|
|
+ map.put("msgType","1");
|
|
|
+ map.put("link",link);
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("msg",e.getMessage());
|
|
|
+ map.put("msgType","0");
|
|
|
+ }
|
|
|
+ this.writeSuccessData(map);
|
|
|
+ }
|
|
|
+ public static String getEncryRealFileName(Context ctx, String realFileName) {
|
|
|
+ UserInfo currentUserInfo = ContextUtil.getCurrentUserInfo(ctx);
|
|
|
+ return MessageFormat.format("{0}_{1}", realFileName, MD5.md5Hash(currentUserInfo.getId().toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ public byte[] convertPdfToByteArray(File file) throws IOException {
|
|
|
+ FileInputStream fis = new FileInputStream(file);
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = fis.read(buffer)) != -1) {
|
|
|
+ baos.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ fis.close();
|
|
|
+ baos.close();
|
|
|
+
|
|
|
+ return baos.toByteArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> getSql(Set<String> set,Context ctx,int page,int num) throws BOSException, SQLException {
|
|
|
+ StringBuilder query = new StringBuilder();
|
|
|
+ query.append("SELECT").append("\n");
|
|
|
+ query.append("res.FBIZDATE bizDate,").append("\n");
|
|
|
+ query.append("org.FNAME_l3 orgName,").append("\n");
|
|
|
+ query.append("org.FPhoneNumber as orgPhone,").append("\n");
|
|
|
+ query.append("org.FCode as orgCode,").append("\n");
|
|
|
+ query.append("person.fname_l3 personName,").append("\n");
|
|
|
+ query.append("person.CFPinyin personPY,").append("\n");
|
|
|
+ query.append("person.CFOccupationcode personOccTion,").append("\n");
|
|
|
+ query.append("pal.FCredentialsTypeNO creNumber").append("\n");
|
|
|
+// query.append("cre.fname_l3 creName,").append("\n");
|
|
|
+// query.append("cre.fname_l3 creNumber").append("\n");
|
|
|
+ query.append("FROM t_hr_personposition pp").append("\n");
|
|
|
+ query.append("left join T_BD_person person on pp.FPERSONID = person.Fid").append("\n");
|
|
|
+ query.append("left join T_Org_admin org on org.fid = pp.FCOMPANYID").append("\n");
|
|
|
+ query.append("left join T_HR_ResignBizBillEntry res on res.FPERSONID = person.fid").append("\n");
|
|
|
+ query.append("left join T_HR_personcredentialsType pal on pal.FPERSONID = person.fid").append("\n");
|
|
|
+ //query.append("left join T_HR_CredentialsType cre on cre.FID = pal.fCredentialsTypeId").append("\n");
|
|
|
+ query.append("where person.FNUMBER in(").append("\n");
|
|
|
+ query.append(AtsUtil.convertSetToString(set));
|
|
|
+ query.append(")").append("\n");
|
|
|
+ query.append("and pal.FIsSingle='1' and res.FBIZDATE is not null").append("\n");
|
|
|
+ IRowSet kyIRowSet = DbUtil.executeQuery(ctx, query.toString());
|
|
|
+ Map<String, String> map = pdfData(kyIRowSet, page, num);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按指定大小,分隔集合,将集合按规定个数分为n个部分
|
|
|
+ * @param inputList 数据
|
|
|
+ * @param setSize 分割长度
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public <T> List<Set<T>> splitListIntoSets(List<T> inputList, int setSize) {
|
|
|
+ List<Set<T>> sets = new ArrayList<>();
|
|
|
+ for (int i = 0; i < inputList.size(); i += setSize) {
|
|
|
+ int endIndex = Math.min(i + setSize, inputList.size());
|
|
|
+ List<T> sublist = inputList.subList(i, endIndex);
|
|
|
+ Set<T> set = new HashSet<>(sublist);
|
|
|
+ sets.add(set);
|
|
|
+ }
|
|
|
+ return sets;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充模板中的数据
|
|
|
+ */
|
|
|
+ public void fillData(AcroFields fields, Map<String, String> data) throws DocumentException, IOException {
|
|
|
+ System.out.println("fillDatafillData12");
|
|
|
+ Map<String, AcroFields.Item> fields1 = fields.getFields();
|
|
|
+ System.out.println(fields1.keySet());
|
|
|
+ System.out.println(data);
|
|
|
+ fields.setField("year", "2024");
|
|
|
+ //fields.setField("empName", "22334");
|
|
|
+// fields.setField("taxpayerName0", "234345");
|
|
|
+// fields.setField("page", "2");
|
|
|
+ try {
|
|
|
+ for (String key : data.keySet()) {
|
|
|
+ String value = data.get(key);
|
|
|
+ fields.setField(key, value);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充数据源
|
|
|
+ * 其中data存放的key值与pdf模板中的文本域值相对应
|
|
|
+ */
|
|
|
+ public Map<String, String> pdfData(IRowSet rowSet,int num,int page) throws SQLException {
|
|
|
+ Map<String, String> data = new HashMap<String, String>();
|
|
|
+ if (rowSet.size() == 0){
|
|
|
+ data.put("msg","所选员工未查询到离职员工或还在离职流程中");
|
|
|
+ data.put("msgType","0");
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ SimpleDateFormat outputFormatter = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
+ int index = 2;
|
|
|
+ int indexAdd = 4;
|
|
|
+ Date date = new Date();
|
|
|
+ String dateStr = outputFormatter.format(date);
|
|
|
+ String sun = dateStr.substring(0, 2);
|
|
|
+ String month = dateStr.substring(3, 5);
|
|
|
+ String year = dateStr.substring(6, 10);
|
|
|
+ while (rowSet.next()) {
|
|
|
+ Date bizDate = rowSet.getDate("bizDate");//离职日期
|
|
|
+ String orgName = rowSet.getString("orgName");//所属公司
|
|
|
+ String orgPhone = rowSet.getString("orgPhone");//联系电话
|
|
|
+ String orgCode = rowSet.getString("orgCode");//雇主税号
|
|
|
+ String creNumber = rowSet.getString("creNumber");//证件类型编码
|
|
|
+ String personName = rowSet.getString("personName");//员工姓名
|
|
|
+ String personPY = rowSet.getString("personPY") != null ? rowSet.getString("personPY") : "";//外语拼音
|
|
|
+ String personOccTion = rowSet.getString("personOccTion");//员工信息-职业税编号
|
|
|
+ String leftStr = outputFormatter.format(bizDate);
|
|
|
+ if (index == 2){//表头 取第一条数据员工数据
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField1[0]", leftStr.substring(6,10)); //第一条员工离职的离职日期年份
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField1[1]", orgCode);//雇主税号 (行政组织维护-雇主税号) 1
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField1[2]", orgName); //雇主名称(员工信息-所属公司)
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField1[3]", orgPhone);//联系电话 (行政组织维护-联系电话) 1
|
|
|
+ data.put("topmostSubform[0].Page1[0].NumericField1[0]", String.valueOf(page+1)); //当前页数
|
|
|
+ data.put("topmostSubform[0].Page1[0].NumericField1[1]", String.valueOf(num)); //总页数
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField21[1]", orgName); //
|
|
|
+ }
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField1[" + indexAdd + "]", personOccTion); //税务号码(员工信息-职业税编号)
|
|
|
+ ++indexAdd;
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField1[" + indexAdd + "]", personName + " " + personPY); // 纳税人姓名(员工姓名+外语拼音)
|
|
|
+ ++indexAdd;
|
|
|
+ if ("62".equals(creNumber) || "64".equals(creNumber)){
|
|
|
+ creNumber = 15 + "/" + creNumber;
|
|
|
+ }else {
|
|
|
+ creNumber = 20 + "/" + creNumber;
|
|
|
+ }
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField1[" + indexAdd + "]", creNumber); //证件类型及编号(员工信息-证件类型和证件编码 澳门永久或非永久身份证为15 其他的都为20)
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField" +index+ "[0]", leftStr); //离职日期(离职单-离职日期)
|
|
|
+ index++;
|
|
|
+ ++indexAdd;
|
|
|
+ }
|
|
|
+ //key要与模板中的别名一一对应
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField23[0]", year);
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField22[0]", month);
|
|
|
+ data.put("topmostSubform[0].Page1[0].TextField24[0]", sun);
|
|
|
+ data.put("number", String.valueOf(rowSet.size()));
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|