@RequestMapping("/myList") public ModelAndView queryOrderHouseList( HttpServletRequest request, @RequestParam(value = "code", required = false) String code) { ModelAndView mv = createMAV("personal/personal"); String openid = SessionUtil.getOpenId(request, authService); log.info("openid[{}]", new Object[] {openid}); log.debug("weixinId is " + openid); List<HouseVo> resultList = orderService.queryOrderHouseList(openid); // if (resultList == null) { // // throw new BizException("请检查定位设置是否打开"); // // 返回提示页面,提示用户打开位置定位 // mv = createMAV("myrent/note"); // return mv; // } mv.addObject("resultList", resultList); mv.addObject("weixinId", openid); mv.addObject("type", "o"); return mv; }
/** * 保存预约信息 * * @param request * @param order * @param modelMap */ @RequestMapping("add_preOrder") public void addPreOrder(HttpServletRequest request, Order order, ModelMap modelMap) { // 预约者电话 String telephone = this.findStringParameterValue(request, "orderTel"); // 验证码 String verifyCode = this.findStringParameterValue(request, "verifyCode"); if (StringUtils.equals(verifyCode, (String) request.getSession().getAttribute(telephone))) { // 房屋ID String houseId = this.findStringParameterValue(request, "houseId"); // 预约者微信ID order.setWeixinId(StringUtils.defaultIfEmpty(order.getWeixinId(), "weixinId")); // 公寓房源编号 order.setHouseId(houseId); // 预约日期 String orderDate = this.findStringParameterValue(request, "orderDate"); order.setOrderDate(orderDate); // 联系电话 order.setTelephone(telephone); // 检查该微信用户是否已预约了该房源 int count = orderService.queryOrderCountByHouseIdAndWeixinIdAndOrderDate( order.getWeixinId(), houseId, orderDate); if (count == 0) { // 保存预约信息 orderService.addPreOrder(order); // 清空Session中保存的该手机号的验证码 request.getSession().removeAttribute(telephone); // 取得预约房源的信息 HouseWrapVo houseInfo = houseService.findHouseInfoByHouseId(houseId); // 房屋描述信息 StringBuilder houseDesc = new StringBuilder(); // 小区名称+楼号+房间数 houseDesc.append(houseInfo.getCommunityName()).append(" "); if (StringUtils.isNotBlank(houseInfo.getBuildingNo())) { houseDesc.append(houseInfo.getBuildingNo()).append("号楼"); } if (StringUtils.isNotBlank(houseInfo.getLayout())) { if (ERenovation.BAY.getCode().equals(houseInfo.getLayout())) { houseDesc.append("开间"); } else { houseDesc.append(houseInfo.getLayout()).append("室"); } } if (StringUtils.isNotBlank(houseInfo.getUseArea())) { houseDesc.append(" "); houseDesc.append(houseInfo.getUseArea().replaceAll("\\.\\d*$", "")).append("平米"); } if (houseInfo.getLongPrice() != null) { houseDesc.append(" "); houseDesc .append(houseInfo.getLongPrice().toPlainString().replaceAll("\\.\\d*$", "")) .append("元/月"); } // 编辑地址 String houseAddress = houseInfo.getStreet(); DateFormat dateFormat = new SimpleDateFormat(Constants.DATE_FORMAT_NO_SEPARATOR); StringBuilder orderTimeDisplayBul = new StringBuilder(); try { Date date = dateFormat.parse(orderDate); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int weedDay = calendar.get(Calendar.DAY_OF_WEEK); orderTimeDisplayBul.append( DateUtil.getFmtDate(orderDate, Constants.DATE_FORMAT_NO_SEPARATOR, "yyyy年MM月dd日")); orderTimeDisplayBul.append(" ").append(EWeekDayType.getNameByCode(weedDay)); } catch (ParseException e) { logger.error("预约日期格式解析错误", e); } String orderDateDisplay = orderTimeDisplayBul.toString(); modelMap.put("success", true); modelMap.put("description", houseDesc.toString()); modelMap.put("houseTel", houseInfo.getTelephone()); modelMap.put("houseAdd", houseAddress); modelMap.put("orderDate", orderDateDisplay); // TODO 向用户微信发送预约消息 // ServletContext sevletContext = request.getSession() // .getServletContext(); // // 获取微信access_token // String accessToken = (String) sevletContext // .getAttribute(Constants.WEIXIN_ACCESS_TOKEN); // // 尝试从application context中取得access_token信息 // Integer validSecond = (Integer) sevletContext // .getAttribute(Constants.WEIXIN_ACCESS_TOKEN_VALID_TIME); // Long accessTokenCallTime = (Long) sevletContext // .getAttribute(Constants.ACCESS_TOKEN_CALL_TIME); // // 获取access_token失败标志 // boolean getAccessTokenFailFlag = false; // // 判定application context范围内的微信access_token信息是否存在且是否有效 // if (StringUtils.isEmpty(accessToken) // || (System.currentTimeMillis() - accessTokenCallTime) <= validSecond) { // // 不存在或者已失效 // String accessTokenInfo = getAccessTokenService.getAccessToken(); // if (StringUtils.isEmpty(accessTokenInfo)) { // log.error("微信access_token获取失败!"); // getAccessTokenFailFlag = true; // } else { // int underScoreIndex = accessTokenInfo // .indexOf(GetAccessTokenService.ACCESS_TOKEN_INFO_SEPERATOR); // validSecond = Integer.valueOf(accessTokenInfo.substring(0, // underScoreIndex)); // accessToken = accessTokenInfo // .substring(underScoreIndex + 1); // accessTokenCallTime = System.currentTimeMillis(); // // // 将取得的access_token信息保存至application context范围内 // sevletContext.setAttribute(Constants.WEIXIN_ACCESS_TOKEN, // accessToken); // sevletContext.setAttribute( // Constants.WEIXIN_ACCESS_TOKEN_VALID_TIME, // validSecond); // sevletContext.setAttribute( // Constants.ACCESS_TOKEN_CALL_TIME, // accessTokenCallTime); // } // } // // if (!getAccessTokenFailFlag // && sendOrderMessageToWeixinUser(accessToken, // order.getWeixinId(), orderDateDisplay, // houseDesc.toString(), houseInfo.getTelephone())) { // log.error("预约微信发送失败![clientTel:" + telephone + ", orderTime:" // + orderDateDisplay + ", houseAddress:" + houseAddress // + ", houseTel:" + houseInfo.getTelephone() + "]"); // } if (!sendOrderMessageToCusetomerService( telephone, orderDateDisplay, houseDesc.toString(), houseInfo.getTelephone(), houseInfo.getBrandName())) { log.error( "预约邮件发送失败![clientTel:" + telephone + ", orderTime:" + orderDateDisplay + ", houseAddress:" + houseAddress + ", houseTel:" + houseInfo.getTelephone() + "]"); } } else { modelMap.put("success", false); modelMap.put("message", "已预约过在您指定的日期看该房源!"); } } else { modelMap.put("success", false); modelMap.put("message", "输入的验证码有误,请重新输入!"); } }