/** * Make date from header. * * @param date the date * @return the long */ private long makeDateFromHeader(final Header date) { long result = System.currentTimeMillis(); if (date != null) { try { result = DateUtil.parseDate(date.getValue()).getTime(); } catch (DateParseException ex) { getLogger() .warn( "Could not parse date '" + date + "', using system current time as item creation time.", ex); } catch (NullPointerException ex) { getLogger().warn("Parsed date is null, using system current time as item creation time."); } } return result; }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // 转发处理 StringBuffer json = new StringBuffer(); String methodCall = req.getParameter("methodCall"); if (methodCall.equals("getResultDetailByBatchNo")) { // 通过原来的批量退款批次号获取退款详情 if (req.getParameter("batchNo") == null) { json.append("{success:false,msg:'参数[原批量退款批次号]不能为空'}"); } else { Map resultDetails = refundFastpayService.getResultDetailByBatchNo(req.getParameter("batchNo")); if (CollectionUtils.isEmpty(resultDetails)) { json.append( "{success:false,msg:'原批量退款批次号为:" + req.getParameter("batchNo") + "的批量退款信息不存在'}"); } else { json.append("{success:true,data:{"); json.append("batchNo:'" + resultDetails.get("batchNo") + "',"); json.append("batchNum:'" + resultDetails.get("batchNum") + "',"); json.append("batchData:'" + resultDetails.get("batchData") + "',"); json.append( "refundDate:'" + DateUtil.formatDate( (Date) resultDetails.get("refundDate"), "yyyy-MM-dd HH:mm:ss") + "',"); json.append("isSuccess:'" + resultDetails.get("isSuccess") + "',"); json.append( "successNum:'" + (resultDetails.get("successNum") != null ? resultDetails.get("successNum") : "") + "',"); json.append( "resultDetails:'" + (resultDetails.get("resultDetails") != null ? resultDetails.get("resultDetails") : "") + "',"); json.append( "relation:'" + (resultDetails.get("relation") != null ? resultDetails.get("relation") : "") + "',"); json.append( "totalRefund:'" + (resultDetails.get("totalRefund") != null ? resultDetails.get("totalRefund") : "") + "'"); json.append("},msg:'获取原批量退款批次号为:" + req.getParameter("batchNo") + "的批量退款信息成功!'}"); } } resp.setContentType("text/html;charset=utf-8"); resp.getWriter().write(json.toString()); resp.getWriter().close(); return; } else if (methodCall.equals("batchRefundImport")) { // 批量退款导入 // 解析文件 String realPath = null; String filePath = null; Result result = null; try { DiskFileItemFactory factory = new DiskFileItemFactory(); boolean isMutipart = ServletFileUpload.isMultipartContent(req); if (isMutipart) { ServletFileUpload upload = new ServletFileUpload(factory); List fileItems = upload.parseRequest(req); Iterator iterator = fileItems.iterator(); while (iterator.hasNext()) { FileItem fi = (FileItem) iterator.next(); if (!fi.isFormField()) { String fileName = fi.getName(); if (fileName == null || "".equals(fileName)) break; String suffix = fileName.substring(fileName.lastIndexOf(".")); String systemFileName = "upload-" + System.currentTimeMillis() + suffix; filePath = PropertiesUtil.getProperties("fileUploadPath", "D:/data/upload/") + systemFileName; // realPath = req.getSession().getServletContext().getRealPath("/") + filePath; realPath = filePath; try { File uploadedFile = new File(realPath); fi.write(uploadedFile); result = processRefundFastpayExcel(realPath); if (!result.isSuccess()) { // 失败 RequestDispatcher rd = req.getRequestDispatcher("/refund/result.jsp"); req.setAttribute("result", result); rd.forward(req, resp); } else { // 成功 req.getSession(true).setAttribute("result", result); resp.sendRedirect(req.getContextPath() + "/refund/success.jsp"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } catch (FileUploadException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (methodCall.equals("batchRefundApply")) { // 批量退款申请 // 解析文件 String realPath = null; String filePath = null; Result result = null; String applyUser = null; String applyRemark = null; try { DiskFileItemFactory factory = new DiskFileItemFactory(); boolean isMutipart = ServletFileUpload.isMultipartContent(req); if (isMutipart) { ServletFileUpload upload = new ServletFileUpload(factory); List fileItems = upload.parseRequest(req); Iterator iterator = fileItems.iterator(); while (iterator.hasNext()) { FileItem fi = (FileItem) iterator.next(); if (!fi.isFormField()) { String fileName = fi.getName(); if (fileName == null || "".equals(fileName)) break; String suffix = fileName.substring(fileName.lastIndexOf(".")); String systemFileName = "upload-" + System.currentTimeMillis() + suffix; filePath = PropertiesUtil.getProperties("fileUploadPath", "D:/data/upload/") + systemFileName; // realPath = req.getSession().getServletContext().getRealPath("/") + filePath; realPath = filePath; File uploadedFile = new File(realPath); fi.write(uploadedFile); } else { String name = fi.getFieldName(); String value = fi.getString(); // 在enctype="multipart/form-data") 情况下,form表单的数据通过流传递,且在Tomcat服务器下,默认使用ISO-8859-1编码 value = new String(value.getBytes("ISO-8859-1"), "UTF-8"); if (name.equals("applyUser")) { applyUser = value; } if (name.equals("applyRemark")) { applyRemark = value; } } } try { // 简单校验,提交申请applyId为null result = processRefundFastpayApplyExcel(realPath, true, null, applyUser, applyRemark); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (FileUploadException e) { result.setMsg("附件上传失败导致申请失败!"); } catch (Exception e) { result.setMsg("服务器端异常导致申请失败!"); } if (!result.isSuccess()) { // 失败 RequestDispatcher rd = req.getRequestDispatcher("/refund/result.jsp"); req.setAttribute("result", result); rd.forward(req, resp); } else { // 成功 req.getSession(true).setAttribute("result", result); resp.sendRedirect(req.getContextPath() + "/refund/success.jsp"); } } else if (methodCall.equals("searchRefundFastpayApplyList")) { // 查询申请列表 int currentPage = Integer.valueOf(req.getParameter("currentPage").toString()); int startRecord = currentPage == 1 ? 0 : ((currentPage - 1) * Integer.valueOf(req.getParameter("pageSize").toString())); int totalPage = 0; if (req.getParameter("flag").toString().equals("0")) { startRecord = 0; } Map resultDetails = refundFastpayService.searchRefundFastpayApplyList( req.getParameter("startDate").toString(), req.getParameter("endDate").toString(), Integer.valueOf(req.getParameter("applyStatus").toString()), req.getParameter("applyUser").toString(), Boolean.valueOf(req.getParameter("isSignUser")), startRecord, Integer.valueOf(req.getParameter("pageSize").toString())); for (Map map : ((List<Map>) resultDetails.get("data"))) { json.append("{'id':'"); json.append(map.get("id")).append("','applyNo':'"); json.append(map.get("applyNo")).append("','batchNo':'"); json.append(map.get("batchNo")).append("','filepath':'"); json.append(map.get("filepath")).append("','applyStatus':'"); json.append(map.get("applyStatus")).append("','applyUser':'******','applyTime':'"); json.append(map.get("applyTime")).append("','applyRemark':'"); json.append(map.get("applyRemark")).append("','auditUser':'******','auditTime':'"); json.append(map.get("auditTime")).append("','auditRemark':'"); json.append(map.get("auditRemark")).append("','importUser':'******','importTime':'"); json.append(map.get("importTime")).append("','importRemark':'"); json.append(map.get("importRemark")).append("'"); json.append("},"); } if (json.toString().endsWith(",")) { json = new StringBuffer(json.substring(0, json.length() - 1)); } totalPage = (Integer.valueOf(resultDetails.get("rowCount").toString()) == 0 ? 1 : (Integer.valueOf(resultDetails.get("rowCount").toString()) + Integer.valueOf(req.getParameter("pageSize").toString()) - 1) / Integer.valueOf(req.getParameter("pageSize").toString())); json = new StringBuffer( "{success: true,rowCount:'" + resultDetails.get("rowCount") + "',data:[" + json + "],currentPage:'" + currentPage + "',totalPage:'" + totalPage + "'}"); resp.setContentType("text/html;charset=utf-8"); resp.getWriter().write(json.toString()); resp.getWriter().close(); return; } else if (methodCall.equals("auditRefundFastpayApply")) { // 审批 Result result = null; result = refundFastpayService.auditRefundFastpay( req.getParameter("applyId"), req.getParameter("auditUser"), // new String(req.getParameter("auditRemark").getBytes("iso-8859-1"), "UTF-8"), // req.getParameter("auditRemark"), HttpUtil.ConverUnicode(req.getParameter("auditRemark")), // reuncode Integer.valueOf(req.getParameter("applyStatus").toLowerCase())); if (result.isSuccess()) { json.append("{success:true}"); } else { json.append("{success:false, msg:'" + result.getMsg() + "'}"); } resp.setContentType("text/html;charset=utf-8"); resp.getWriter().write(json.toString()); resp.getWriter().close(); return; } else if (methodCall.equals("importRefundFastpayApply")) { // 导入 Result result = null; // 简单校验,提交申请applyId为null result = processRefundFastpayApplyExcel( null, false, req.getParameter("applyId"), req.getParameter("importUser"), // req.getParameter("importRemark") HttpUtil.ConverUnicode(req.getParameter("importRemark"))); if (result.isSuccess()) { json.append("{success:true}"); } else { json.append("{success:false, msg:'" + result.getMsg() + "'}"); } resp.setContentType("text/html;charset=utf-8"); resp.getWriter().write(json.toString()); resp.getWriter().close(); return; } else if (methodCall.equals("downloadFile")) { // 下载 Map map = refundFastpayService.getApplyDetailByBatchNo(req.getParameter("applyId")); String filePath = map.get("filepath").toString(); File dbFile = new File(filePath); FileInputStream fileIn = null; fileIn = new FileInputStream(dbFile); String contentType; contentType = "application/x-xls"; resp.setContentType(contentType); resp.setHeader( "Content-Disposition", "filename=" + filePath.substring(filePath.indexOf("upload-"))); byte[] buffer = new byte[1024 * 512]; while (true) { int bytes = fileIn.read(buffer); if (bytes == -1) { break; } resp.getOutputStream().write(buffer, 0, bytes); } resp.getOutputStream().flush(); resp.getOutputStream().close(); fileIn.close(); return; } /*else if(methodCall.equals("test")){ test(); }*/ }
public RequestMeta setIfUnmodifiedSince(Date lastmod) { return setHeader(Constants.HDR_IF_UNMODIFIED_SINCE, DateUtil.formatDate(lastmod)); }
public static RIMResponse updatePhoneOptInStatus( Map<String, Object> attributes, DAOManager daoManager) { System.out.println("update phone optIn status Webservice called "); PhoneSubscriptionDAO phoneSubscriptionDAO = daoManager.getPhoneSubscriptionDAO(); RIMResponse response = new RIMResponse(); String responseId = ""; if (attributes != null && attributes.size() > 0 && attributes.containsKey(RIMConstants.RequestMapping.PHONE_NUMBER_KEY) && !attributes.get(RIMConstants.RequestMapping.PHONE_NUMBER_KEY).toString().equals("")) { String phoneNumber = ""; Scanner in = new Scanner(attributes.get(RIMConstants.RequestMapping.PHONE_NUMBER_KEY).toString()) .useDelimiter("[^0-9]+"); while (in.hasNext()) { phoneNumber += in.next(); } int numLen = phoneNumber.length(); if (numLen > 10) phoneNumber = phoneNumber.substring(numLen - 10, numLen); String phoneOptInStatus = "N"; // default if (attributes.containsKey(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY)) { if (attributes .get(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY) .toString() .equalsIgnoreCase("true")) phoneOptInStatus = "Y"; } Date timeStampFromRequest = new Date(); if (attributes.containsKey(RIMConstants.RequestMapping.TIMESTAMP_KEY)) { try { timeStampFromRequest = DateUtil.parseDate( attributes.get(RIMConstants.RequestMapping.TIMESTAMP_KEY).toString()); } catch (DateParseException e) { // System.out.println("Error occured while parsing"); } } // Lookup to module PhoneSubscription phoneSubscription = null; boolean existsInRelate = false; phoneSubscription = phoneSubscriptionDAO.getPhoneSubscription(Long.parseLong(phoneNumber)); if (phoneSubscription == null) { phoneSubscription = new PhoneSubscription(); } else { existsInRelate = true; if (phoneSubscription.getLastUpdatedTime().compareTo(timeStampFromRequest) > 0) { response.setErrorMessage("TimeStamp from request is older than what relate has."); response.setSuccess(false); return response; } } phoneSubscription.setPhoneNumber(Long.parseLong(phoneNumber)); phoneSubscription.setPhoneOptInStatus(phoneOptInStatus); phoneSubscription.setLastUpdatedTime(timeStampFromRequest); // Lookup to Relate with only Phone Only Map<String, Object> searchWithPhoneMap = new HashMap<String, Object>(); searchWithPhoneMap.put(RIMConstants.RequestMapping.PHONE_NUMBER_KEY, phoneNumber); List<Object> customerList = CustomerWebServiceManager.searchCustomers(searchWithPhoneMap, 0); if (customerList != null && customerList.size() > 0) { Iterator<Object> custIter = customerList.iterator(); while (custIter.hasNext()) { Map<String, Object> temp = (HashMap<String, Object>) custIter.next(); Map<String, Object> relateRequest = new HashMap<String, Object>(); if (temp.containsKey(RIMConstants.RequestMapping.CUSTOMER_KEY)) { relateRequest.put( RIMConstants.RequestMapping.CUSTOMER_KEY, temp.get(RIMConstants.RequestMapping.CUSTOMER_KEY).toString()); if (attributes.containsKey(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY)) relateRequest.put( RIMConstants.RequestMapping.PHONE_OPT_IN_KEY, attributes.get(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY).toString()); else relateRequest.put(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY, "false"); responseId = CustomerWebServiceManager.addOrUdateCustomer(relateRequest, 0); } } } else { Map<String, Object> relateRequest = new HashMap<String, Object>(); relateRequest.put(RIMConstants.RequestMapping.PHONE_NUMBER_KEY, phoneNumber); if (attributes.containsKey(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY)) relateRequest.put( RIMConstants.RequestMapping.PHONE_OPT_IN_KEY, attributes.get(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY).toString()); else relateRequest.put(RIMConstants.RequestMapping.PHONE_OPT_IN_KEY, "false"); responseId = CustomerWebServiceManager.addOrUdateCustomer(relateRequest, 0); } // Update Module DB if (existsInRelate) phoneSubscriptionDAO.updatePhoneSubscription(phoneSubscription); else phoneSubscriptionDAO.insertPhoneSubscription(phoneSubscription); if (responseId != null && !responseId.isEmpty()) { response.setSuccess(true); response.setErrorMessage(null); } else { response.setSuccess(false); response.setErrorMessage("Failed to Update from Module to Relate"); } } else { response.setSuccess(false); response.setErrorMessage("Request does not sufficient data"); return response; } return response; }