AtsTripBillEditHandlerEx.java 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.kingdee.eas.custom.synctask.handler;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.eas.base.permission.UserInfo;
  5. import com.kingdee.eas.util.app.ContextUtil;
  6. import com.kingdee.shr.ats.web.handler.AtsTripBillEditHandler;
  7. import com.kingdee.shr.base.syssetting.context.SHRContext;
  8. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  9. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  10. import com.kingdee.shr.base.syssetting.web.dynamic.util.DynamicUtil;
  11. import com.kingdee.shr.base.syssetting.web.dynamic.util.MD5;
  12. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  13. import com.kingdee.shr.base.syssetting.web.util.UserUtil;
  14. import com.lowagie.text.pdf.PdfReader;
  15. import com.lowagie.text.pdf.PdfStamper;
  16. import org.apache.log4j.Logger;
  17. import org.springframework.ui.ModelMap;
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpServletResponse;
  20. import javax.servlet.http.HttpSession;
  21. import java.io.*;
  22. import java.text.MessageFormat;
  23. import java.util.*;
  24. /**
  25. * @author qingwu
  26. * @date 2024/11/13
  27. * @apiNote
  28. * 员工自助我要出差
  29. */
  30. public class AtsTripBillEditHandlerEx extends AtsTripBillEditHandler {
  31. Logger logger = Logger.getLogger(AtsTripBillEditHandlerEx.class);
  32. /**
  33. * @param request
  34. * @param response
  35. * @param modelMap
  36. * @throws BOSException
  37. * @throws ShrWebBizException
  38. */
  39. public void evectionTemplateAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws ShrWebBizException {
  40. logger.error("evectionTemplateAction---");
  41. try {
  42. Context ctx = SHRContext.getInstance().getContext();//上下文
  43. HttpSession session = request.getSession();
  44. String tempFilePath = UserUtil.getUserTempDirAbsolutePath(session); //存放
  45. File tempFile = new File(tempFilePath);
  46. if (!tempFile.exists()) {
  47. tempFile.mkdirs();
  48. }
  49. String path = System.getProperty("EAS_HOME") + "/server//lib/addon/customer/template/evectionTemplate.xlsx";
  50. FileInputStream fileInputStream = new FileInputStream(path);
  51. String zipName = "outA.xlsx";
  52. String zipNameHash = MD5.md5Hash(zipName);
  53. String realFileName = getEncryRealFileName(ctx,zipNameHash);
  54. String fileStr = zipNameHash;
  55. File outFile = new File(tempFilePath + "/"+realFileName);
  56. FileOutputStream fileOutputStream = new FileOutputStream(outFile);
  57. byte[] buffer = new byte[1024];
  58. int length;
  59. while ((length = fileInputStream.read(buffer)) > 0) {
  60. fileOutputStream.write(buffer, 0, length);
  61. }
  62. Map<String, String> map = new HashMap<>();
  63. Map<String, String> param = new HashMap<String, String>();
  64. param.put("method", "tmp");
  65. param.put("file", zipNameHash);
  66. //param.put("filename", fileStr+".xlsx");
  67. param.put("filename","出差行程表.xlsx");
  68. //String link = DynamicUtil.assembleUrl("/shr/downloadfile.do", param).replaceAll("\\+", "%20");
  69. String link = DynamicUtil.assembleUrl("/shr/downloadfile.do", param);
  70. map.put("msgType", "1");
  71. map.put("link", link);
  72. this.writeSuccessData(map);
  73. } catch (Exception e) {
  74. e.printStackTrace();
  75. throw new ShrWebBizException(e.getMessage());
  76. }
  77. }
  78. public static String getEncryRealFileName(Context ctx, String realFileName) {
  79. UserInfo currentUserInfo = ContextUtil.getCurrentUserInfo(ctx);
  80. return MessageFormat.format("{0}_{1}", realFileName, MD5.md5Hash(currentUserInfo.getId().toString()));
  81. }
  82. }