From bd42a5cd7d1813168263b5711e9a0882367fb8c2 Mon Sep 17 00:00:00 2001 From: fengys Date: Sun, 24 Jun 2018 18:14:11 +0800 Subject: [PATCH] =?UTF-8?q?APP=E4=B8=8B=E8=BD=BD=E5=8F=8A=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E8=BF=87=E6=BB=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebContent/WEB-INF/web.xml | 2 +- WebContent/appDownload.jsp | 166 ++++----- .../doc/controller/DocManageController.java | 318 +++++++++--------- .../als/doc/service/DocManageService.java | 170 +++++----- 4 files changed, 328 insertions(+), 328 deletions(-) diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index f93ae00d2..d4dbc7c39 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -41,7 +41,7 @@ ExcludedURLs - ^/.*Logon.jsp,^/.*SaveGraphAjax.jsp + ^/.*Logon.jsp,^/.*SaveGraphAjax.jsp,^/.*appDownload.jsp diff --git a/WebContent/appDownload.jsp b/WebContent/appDownload.jsp index 90e234215..51895a9f8 100644 --- a/WebContent/appDownload.jsp +++ b/WebContent/appDownload.jsp @@ -1,84 +1,84 @@ -<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> - - - - - - - -App应用下载 - - - - - -<% - String devType="android"; - String userAgent = request.getHeader("user-agent"); - if(userAgent.toLowerCase().indexOf("iphone")>=0){ - devType="ios"; - } -%> - -
-
-
-
- -
- -
-
- -
-
-

微信扫描打开APP下载链接提示代码优化 -

- - - + + +<% + String devType="android"; + String userAgent = request.getHeader("user-agent"); + if(userAgent.toLowerCase().indexOf("iphone")>=0){ + devType="ios"; + } +%> + +
+
+
+
+ +
+ +
+
+ +
+
+

΢ɨAPPʾŻ +

+ + + \ No newline at end of file diff --git a/src_app_fresh/apx/com/amarsoft/als/doc/controller/DocManageController.java b/src_app_fresh/apx/com/amarsoft/als/doc/controller/DocManageController.java index 3c0fc93af..cd67a213b 100644 --- a/src_app_fresh/apx/com/amarsoft/als/doc/controller/DocManageController.java +++ b/src_app_fresh/apx/com/amarsoft/als/doc/controller/DocManageController.java @@ -1,159 +1,159 @@ -//package apx.com.amarsoft.als.doc.controller; -// -//import java.io.File; -//import java.io.FileInputStream; -//import java.io.InputStream; -//import java.util.List; -//import java.util.Map; -// -//import javax.servlet.http.HttpServletRequest; -//import javax.servlet.http.HttpServletResponse; -//import javax.ws.rs.GET; -//import javax.ws.rs.Path; -//import javax.ws.rs.core.Context; -// -//import org.apache.commons.io.FileUtils; -// -//import com.amarsoft.are.ARE; -//import com.amarsoft.are.jbo.BizObject; -//import com.amarsoft.are.jbo.JBOFactory; -//import com.amarsoft.are.jbo.JBOTransaction; -//import com.amarsoft.awe.util.Transaction; -//import com.base.constant.RestfullConstant; -//import com.base.helper.AppHelper; -//import com.base.util.DownloadAttUtil; -//import com.base.util.ReturnMapUtil; -// -//import apx.com.amarsoft.als.doc.AppAtt; -//import apx.com.amarsoft.als.doc.service.DocManageService; -// -//@Path("/files") -//public class DocManageController { -// DocManageService service = new DocManageService(); -// -// @Path("/down/docById") -// @GET -// public AppAtt attachmentDownloadById(@Context HttpServletRequest request, -// @Context HttpServletResponse response) throws Exception { -// String sId = request.getParameter("id"); -// return service.attachmentDownloadById(sId, request, response); -// } -// -// @Path("/remove/docById") -// @GET -// public Map removeDocById( -// @Context HttpServletRequest request, -// @Context HttpServletResponse response, @Context Transaction sqlca, -// JBOTransaction tx) throws Exception { -// ReturnMapUtil ReturnMapUtil = new ReturnMapUtil(tx, sqlca); -// try { -// String sId = request.getParameter("id"); -// -// if (service.removeDocById(sId, tx)) { -// ReturnMapUtil.setReturnMap(null, RestfullConstant.baseProperty -// .get("SUCCESS").toString(), "ļƳɹ!"); -// } else { -// ReturnMapUtil.setReturnMap(null, RestfullConstant.baseProperty -// .get("FAIL").toString(), "ļƳʧ!"); -// } -// return ReturnMapUtil.getReturnMap(); -// } catch (Exception e) { -// return ReturnMapUtil.rollback(e); -// } -// } -// -// @Path("/downloadPlist") -// @GET -// public void downloadPlist(@Context HttpServletResponse response, -// @Context HttpServletRequest request) throws Exception { -// String sFileName = "ios-com.ceb-fl.eleasing-app.plist"; -// String sPath = request.getSession().getServletContext().getRealPath("/") -// + "/plist/" + sFileName; -// ARE.getLog().debug("ļ" + sFileName); -// ARE.getLog().debug("·" + sPath); -// DownloadAttUtil.setCharset(response, null); -// try { -// DownloadAttUtil.downloadAppIOS(sFileName, sPath, response); -// } catch (Exception e) { -// String contextPath = request.getContextPath(); -// response.setHeader("Refresh", "1;url=" + contextPath + "/404.html"); -// ARE.getLog().error("appӦʧ", e); -// throw new Exception("------Timeout------"); -// } -// } -// -// @Path("/downloadAppById") -// @GET -// public void downloadAppApplication(@Context HttpServletRequest request, -// @Context HttpServletResponse response, @Context Transaction sqlca) -// throws Exception { -// String id = request.getParameter("id"); -// String path = ""; -// String fileName = ""; -// String sql = "SELECT O.IMAGE_PATH, O.FILE_NAME " -// + "FROM O WHERE 1=1 AND id=" + "'" + id + "'"; -// List bolist = JBOFactory.getFactory() -// .getManager("jbo.app.APP_VERSION").createQuery(sql) -// .getResultList(false); -// if (bolist != null && bolist.size() > 0) { -// BizObject bo = bolist.get(0); -// path = bo.getAttribute("IMAGE_PATH") == null ? "" : bo -// .getAttribute("IMAGE_PATH").toString().trim(); -// fileName = bo.getAttribute("FILE_NAME") == null ? "" : bo -// .getAttribute("FILE_NAME").toString().trim(); -// } -// // fileName = URLEncoder.encode(fileName, "GBK"); -// fileName = new String(fileName.getBytes(), "ISO-8859-1"); -// response.reset(); -// response.setHeader("Content-disposition", "attachment; filename=" -// + fileName); -// response.setContentType("text/html; charset=UTF-8"); -// File file = new File(path); -// response.setContentLength((int) file.length()); -// -// try (InputStream in = new FileInputStream(path)) { -// FileUtils.copyFile(new File(path), response.getOutputStream()); -// } catch (Exception e) { -// ARE.getLog().error("appӦʧ", e); -// ARE.getLog().error("------Timeout------"); -// return; -// } -// } -// -// @Path("/downloadApp") -// @GET -// public void downloadFileApp(@Context HttpServletRequest request, -// @Context HttpServletResponse response, @Context Transaction sqlca) -// throws Exception { -// String sDevType = request.getParameter("devType"); -// sDevType = request.getParameter("devType") == null ? "ios" -// : request.getParameter("devType").toString(); -// String userAgent = request.getHeader("user-agent"); -// if (null != userAgent) { -// if (userAgent.toLowerCase().indexOf("iphone") >= 0) { -// sDevType = "ios"; -// } else { -// sDevType = "android"; -// } -// } -// Map appMap = AppHelper.getNewVersionByPhoneType(sDevType); -// String sFileName = ""; -// String sPath = ""; -// if (null != appMap) { -// sFileName = appMap.get("FILE_NAME".toLowerCase()) == null ? "" : appMap.get("FILE_NAME".toLowerCase()).toString(); -// sPath = appMap.get("IMAGE_PATH".toLowerCase()) == null ? "" : appMap.get("IMAGE_PATH".toLowerCase()).toString(); -// } -// ARE.getLog().debug("ļ" + sFileName); -// ARE.getLog().debug("·" + sPath); -// DownloadAttUtil.setCharset(response, null); -// try { -// DownloadAttUtil.downloadAppAndroid(sFileName, sPath, response); -// } catch (Exception e) { -// String contextPath = request.getContextPath(); -// response.setHeader("Refresh", "1;url=" + contextPath + "/404.html"); -// ARE.getLog().error("appӦʧ", e); -// throw new Exception("------Timeout------"); -// } -// } -// -//} +package apx.com.amarsoft.als.doc.controller; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; + +import org.apache.commons.io.FileUtils; + +import com.amarsoft.are.ARE; +import com.amarsoft.are.jbo.BizObject; +import com.amarsoft.are.jbo.JBOFactory; +import com.amarsoft.are.jbo.JBOTransaction; +import com.amarsoft.awe.util.Transaction; +import com.base.constant.RestfullConstant; +import com.base.helper.AppHelper; +import com.base.util.DownloadAttUtil; +import com.base.util.ReturnMapUtil; + +import apx.com.amarsoft.als.doc.AppAtt; +import apx.com.amarsoft.als.doc.service.DocManageService; + +@Path("/files") +public class DocManageController { + DocManageService service = new DocManageService(); + + @Path("/down/docById") + @GET + public AppAtt attachmentDownloadById(@Context HttpServletRequest request, + @Context HttpServletResponse response) throws Exception { + String sId = request.getParameter("id"); + return service.attachmentDownloadById(sId, request, response); + } + +// @Path("/remove/docById") +// @GET +// public Map removeDocById( +// @Context HttpServletRequest request, +// @Context HttpServletResponse response, @Context Transaction sqlca, +// JBOTransaction tx) throws Exception { +// ReturnMapUtil ReturnMapUtil = new ReturnMapUtil(tx, sqlca); +// try { +// String sId = request.getParameter("id"); +// +// if (service.removeDocById(sId, tx)) { +// ReturnMapUtil.setReturnMap(null, RestfullConstant.baseProperty +// .get("SUCCESS").toString(), "ļƳɹ!"); +// } else { +// ReturnMapUtil.setReturnMap(null, RestfullConstant.baseProperty +// .get("FAIL").toString(), "ļƳʧ!"); +// } +// return ReturnMapUtil.getReturnMap(); +// } catch (Exception e) { +// return ReturnMapUtil.rollback(e); +// } +// } + + @Path("/downloadPlist") + @GET + public void downloadPlist(@Context HttpServletResponse response, + @Context HttpServletRequest request) throws Exception { + String sFileName = "ios-com.ceb-fl.eleasing-app.plist"; + String sPath = request.getSession().getServletContext().getRealPath("/") + + "/plist/" + sFileName; + ARE.getLog().debug("ļ" + sFileName); + ARE.getLog().debug("·" + sPath); + DownloadAttUtil.setCharset(response, null); + try { + DownloadAttUtil.downloadAppIOS(sFileName, sPath, response); + } catch (Exception e) { + String contextPath = request.getContextPath(); + response.setHeader("Refresh", "1;url=" + contextPath + "/404.html"); + ARE.getLog().error("appӦʧ", e); + throw new Exception("------Timeout------"); + } + } + + @Path("/downloadAppById") + @GET + public void downloadAppApplication(@Context HttpServletRequest request, + @Context HttpServletResponse response, @Context Transaction sqlca) + throws Exception { + String id = request.getParameter("id"); + String path = ""; + String fileName = ""; + String sql = "SELECT O.IMAGE_PATH, O.FILE_NAME " + + "FROM O WHERE 1=1 AND id=" + "'" + id + "'"; + List bolist = JBOFactory.getFactory() + .getManager("jbo.app.APP_VERSION").createQuery(sql) + .getResultList(false); + if (bolist != null && bolist.size() > 0) { + BizObject bo = bolist.get(0); + path = bo.getAttribute("IMAGE_PATH") == null ? "" : bo + .getAttribute("IMAGE_PATH").toString().trim(); + fileName = bo.getAttribute("FILE_NAME") == null ? "" : bo + .getAttribute("FILE_NAME").toString().trim(); + } + // fileName = URLEncoder.encode(fileName, "GBK"); + fileName = new String(fileName.getBytes(), "ISO-8859-1"); + response.reset(); + response.setHeader("Content-disposition", "attachment; filename=" + + fileName); + response.setContentType("text/html; charset=UTF-8"); + File file = new File(path); + response.setContentLength((int) file.length()); + + try (InputStream in = new FileInputStream(path)) { + FileUtils.copyFile(new File(path), response.getOutputStream()); + } catch (Exception e) { + ARE.getLog().error("appӦʧ", e); + ARE.getLog().error("------Timeout------"); + return; + } + } + + @Path("/downloadApp") + @GET + public void downloadFileApp(@Context HttpServletRequest request, + @Context HttpServletResponse response, @Context Transaction sqlca) + throws Exception { + String sDevType = request.getParameter("devType"); + sDevType = request.getParameter("devType") == null ? "ios" + : request.getParameter("devType").toString(); + String userAgent = request.getHeader("user-agent"); + if (null != userAgent) { + if (userAgent.toLowerCase().indexOf("iphone") >= 0) { + sDevType = "ios"; + } else { + sDevType = "android"; + } + } + Map appMap = AppHelper.getNewVersionByPhoneType(sDevType); + String sFileName = ""; + String sPath = ""; + if (null != appMap) { + sFileName = appMap.get("FILE_NAME".toLowerCase()) == null ? "" : appMap.get("FILE_NAME".toLowerCase()).toString(); + sPath = appMap.get("IMAGE_PATH".toLowerCase()) == null ? "" : appMap.get("IMAGE_PATH".toLowerCase()).toString(); + } + ARE.getLog().debug("ļ" + sFileName); + ARE.getLog().debug("·" + sPath); + DownloadAttUtil.setCharset(response, null); + try { + DownloadAttUtil.downloadAppAndroid(sFileName, sPath, response); + } catch (Exception e) { + String contextPath = request.getContextPath(); + response.setHeader("Refresh", "1;url=" + contextPath + "/404.html"); + ARE.getLog().error("appӦʧ", e); + throw new Exception("------Timeout------"); + } + } + +} diff --git a/src_app_fresh/apx/com/amarsoft/als/doc/service/DocManageService.java b/src_app_fresh/apx/com/amarsoft/als/doc/service/DocManageService.java index 2a81f303e..16ea9687b 100644 --- a/src_app_fresh/apx/com/amarsoft/als/doc/service/DocManageService.java +++ b/src_app_fresh/apx/com/amarsoft/als/doc/service/DocManageService.java @@ -1,85 +1,85 @@ -//package apx.com.amarsoft.als.doc.service; -// -//import java.util.Map; -// -//import javax.servlet.http.HttpServletRequest; -//import javax.servlet.http.HttpServletResponse; -//import javax.ws.rs.core.Context; -// -//import jbo.app.tenwa.doc.DOC_ATTRIBUTE; -//import apx.com.amarsoft.als.doc.AppAtt; -// -//import com.amarsoft.are.ARE; -//import com.amarsoft.are.jbo.BizObject; -//import com.amarsoft.are.jbo.BizObjectManager; -//import com.amarsoft.are.jbo.JBOFactory; -//import com.amarsoft.are.jbo.JBOTransaction; -//import com.base.helper.LBDocHelper; -//import com.base.util.DownloadAttUtil; -// -//public class DocManageService { -// public AppAtt attachmentDownloadById(String sId, -// @Context HttpServletRequest request, -// @Context HttpServletResponse response) throws Exception { -// DownloadAttUtil.setCharset(response, null); -// // LB_DOCATTRIBUTE >. ID -// String sDevType = request.getParameter("devType") == null ? "ios" -// : request.getParameter("devType").toString(); -// String userAgent = request.getHeader("user-agent"); -// if (null != userAgent) { -// if (userAgent.toLowerCase().indexOf("iphone") >= 0) { -// sDevType = "ios"; -// } else { -// sDevType = "android"; -// } -// } -// Map lbDocMap = LBDocHelper.getDocById2(sId); -// if (null != lbDocMap) { -// String sFileName = lbDocMap.get("FILENAME".toLowerCase()) == null ? "" -// : lbDocMap.get("FILENAME".toLowerCase()).toString(); -// String sFilePath = lbDocMap.get("FILEPATH".toLowerCase()) == null ? "" -// : lbDocMap.get("FILEPATH".toLowerCase()).toString(); -// String sFileSize = lbDocMap.get("CONTENTLENGTH".toLowerCase()) == null ? "" -// : lbDocMap.get("CONTENTLENGTH".toLowerCase()).toString(); -// -// try { -// DownloadAttUtil.downloadAtt(sFileName, sFilePath, sFileSize, -// response, request, sDevType); -// } catch (Exception e) { -// String contextPath = request.getContextPath(); -// response.setHeader("Refresh", "1;url=" + contextPath -// + "/404.html"); -// ARE.getLog().error(e); -// throw new Exception("------Timeout------"); -// } -// } else { -// String contextPath = request.getContextPath(); -// response.setHeader("Refresh", "1;url=" + contextPath + "/404.html"); -// throw new Exception("------Timeout------"); -// } -// return new AppAtt(); -// } -// -// /** -// * attachment no Ƴ -// * @param sId -// * @param tx -// * @return -// */ -// public boolean removeDocById(String sId, JBOTransaction tx) { -// try { -// BizObjectManager manage = JBOFactory -// .getBizObjectManager(DOC_ATTRIBUTE.CLASS_NAME); -// BizObject bo = manage.createQuery("attachmentno=:id").setParameter("id", sId) -// .getSingleResult(true); -// if (null == bo) -// return true; -// manage.deleteObject(bo); -// return true; -// } catch (Exception e) { -// ARE.getLog().error(e); -// return false; -// } -// } -// -//} +package apx.com.amarsoft.als.doc.service; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.Context; + +//import jbo.app.tenwa.doc.DOC_ATTRIBUTE; +import apx.com.amarsoft.als.doc.AppAtt; + +import com.amarsoft.are.ARE; +import com.amarsoft.are.jbo.BizObject; +import com.amarsoft.are.jbo.BizObjectManager; +import com.amarsoft.are.jbo.JBOFactory; +import com.amarsoft.are.jbo.JBOTransaction; +import com.base.helper.LBDocHelper; +import com.base.util.DownloadAttUtil; + +public class DocManageService { + public AppAtt attachmentDownloadById(String sId, + @Context HttpServletRequest request, + @Context HttpServletResponse response) throws Exception { + DownloadAttUtil.setCharset(response, null); + // LB_DOCATTRIBUTE >. ID + String sDevType = request.getParameter("devType") == null ? "ios" + : request.getParameter("devType").toString(); + String userAgent = request.getHeader("user-agent"); + if (null != userAgent) { + if (userAgent.toLowerCase().indexOf("iphone") >= 0) { + sDevType = "ios"; + } else { + sDevType = "android"; + } + } + Map lbDocMap = LBDocHelper.getDocById2(sId); + if (null != lbDocMap) { + String sFileName = lbDocMap.get("FILENAME".toLowerCase()) == null ? "" + : lbDocMap.get("FILENAME".toLowerCase()).toString(); + String sFilePath = lbDocMap.get("FILEPATH".toLowerCase()) == null ? "" + : lbDocMap.get("FILEPATH".toLowerCase()).toString(); + String sFileSize = lbDocMap.get("CONTENTLENGTH".toLowerCase()) == null ? "" + : lbDocMap.get("CONTENTLENGTH".toLowerCase()).toString(); + + try { + DownloadAttUtil.downloadAtt(sFileName, sFilePath, sFileSize, + response, request, sDevType); + } catch (Exception e) { + String contextPath = request.getContextPath(); + response.setHeader("Refresh", "1;url=" + contextPath + + "/404.html"); + ARE.getLog().error(e); + throw new Exception("------Timeout------"); + } + } else { + String contextPath = request.getContextPath(); + response.setHeader("Refresh", "1;url=" + contextPath + "/404.html"); + throw new Exception("------Timeout------"); + } + return new AppAtt(); + } + +// /** +// * attachment no Ƴ +// * @param sId +// * @param tx +// * @return +// */ +// public boolean removeDocById(String sId, JBOTransaction tx) { +// try { +// BizObjectManager manage = JBOFactory +// .getBizObjectManager(DOC_ATTRIBUTE.CLASS_NAME); +// BizObject bo = manage.createQuery("attachmentno=:id").setParameter("id", sId) +// .getSingleResult(true); +// if (null == bo) +// return true; +// manage.deleteObject(bo); +// return true; +// } catch (Exception e) { +// ARE.getLog().error(e); +// return false; +// } +// } + +}