@RequestMapping("/brand/showMerchant.do")
  public Object getShopBao(
      ModelMap model, HttpServletRequest request, HttpServletResponse response) {

    super.setCookieUrl(request, response);
    String merchantID = request.getParameter("merchantId");
    Goods topGoods = null;
    Long mid = null;
    String merIds = "";
    double savePrice = 0.0;
    GoodsCatlog goodsCatlog = null;
    MerchantForm merchantForm = null;
    CashCouponForm cashcouponForOne = null;
    CashCouponForm cashcouponForFive = null;
    CashCouponForm cashcouponForTwo = null;
    List<GoodsForm> listGoodsForm = null;
    List<MerchantForm> childForm = null;
    List<CouponForm> listCouponForm = null;

    try {
      if (null == merchantID || "".equals(merchantID)) {
        request.setAttribute("ERRMSG", "没有找到相关品牌");
        return new ModelAndView("redirect:../500.html");
      }
      mid = Long.parseLong(merchantID);

      // 品牌form
      merchantForm = shopsBaoService.getShangpubaoDetailById(mid);

      String city = merchantForm.getCity();
      if (city != null && !"".equals(city)) {
        city = PinyinUtil.hanziToPinyin(city, "");
        String refer = request.getRequestURL().toString();
        String xcity = "http://" + city;
        String staticurl = propertyUtil.getProperty("STATIC_URL");
        response.addCookie(WebUtils.cookie(CityUtils.CITY_COOKIENAME, city, CityUtils.validy));
        if (!refer.startsWith(xcity)) {
          if ("true".equals(staticurl)) {
            StringBuilder sb = new StringBuilder();
            sb.append(
                "redirect:http://"
                    + city
                    + ".qianpin.com/shangpubao/"
                    + merchantForm.getId()
                    + ".html");
            String params = WebUtils.parseQueryString(request);
            if (!org.apache.commons.lang.StringUtils.isBlank(params)) {
              sb.append("?");
              String str = WebUtils.replaceParams(params, "merchantId");
              if (str != null) {
                sb.append(str);
              }
            }

            return new ModelAndView(sb.toString());
          } else {
            return new ModelAndView(
                "redirect:http://" + city + ".qianpin.com/brand/showMerchant.do?merchantId=" + mid);
          }
        }
      }

      // 查询100元现金券
      cashcouponForOne = shopsBaoService.getCashCoupon(mid, Long.valueOf("100"));
      // 查询50元现金券
      cashcouponForFive = shopsBaoService.getCashCoupon(mid, Long.valueOf("50"));
      // 查询20元现金券
      cashcouponForTwo = shopsBaoService.getCashCoupon(mid, Long.valueOf("20"));
      // 置顶的商品
      topGoods = goodsService.getGoodsByBrandId(mid);
      // 搜索置顶商品的 一级标签属性
      if (topGoods != null) {
        goodsCatlog = goodsService.searchGoodsRegionById(topGoods.getGoodsId());

        savePrice = topGoods.getSourcePrice() - topGoods.getCurrentPrice();
        String salescount = goodsService.salesCount(topGoods.getGoodsId()); // 商品的真实购买数量
        int viewSalesCount = topGoods.getVirtualCount(); // 页面显示的商品数量
        if (null != salescount && salescount.trim().length() > 0) {
          viewSalesCount = Integer.parseInt(salescount) + topGoods.getVirtualCount();
        }
        BigDecimal big = new BigDecimal(savePrice);
        big = big.setScale(1, BigDecimal.ROUND_HALF_UP);
        savePrice = big.doubleValue();
        request.setAttribute("SALES_COUNT", viewSalesCount); // 用于页面显示的商品数量
      }
      // 查询所有商品 分页显示
      childForm = shopsBaoService.getChildMerchnatById(mid);
      int size = goodsService.getGoodsCount(childForm);
      String currentPage = request.getParameter("cpage");

      if (currentPage == null || "".equals(currentPage)) {
        currentPage = "1";
      }

      Pager pager = PagerHelper.getPager(Integer.valueOf(currentPage), size, pageSize);

      if (childForm != null && childForm.size() > 0) {
        StringBuilder ids = new StringBuilder();
        for (MerchantForm mer : childForm) {
          ids.append(mer.getId());
          ids.append(",");
        }
        merIds = ids.substring(0, ids.lastIndexOf(","));
      }

      List<Long> listIds = shopsBaoService.getGoodsCountIds(merIds, pager); // 不包括下架商品、售完商品
      listGoodsForm = goodsService.getGoodsFormByChildId(listIds); // 分店商品

      // 店铺环境
      // MerchantForm merForm =
      // shopsBaoService.getMerchantDetailById(mid);
      List<String[]> environList = merchantForm.getListMerchantbaoLogo();

      // 查找优惠券
      listCouponForm = shopsBaoService.getCouponListByMerchantId(mid, 7);

      // 评价次数
      String count = merchantForm.getEvaluation_count(); // merchantService.getEvationCount(mid);

      // 平均分数
      String evaluationscore =
          merchantForm.getAvgscores(); // merchantService.getAvgEvationScores(mid);

      request.setAttribute("pager", pager);
      request.setAttribute("topGoods", topGoods);
      if (topGoods != null && topGoods.getMapRegion() != null) {
        request.setAttribute("REGION_NUMBER", topGoods.getMapRegion().size());
      }
      request.setAttribute("hundredcoupon", cashcouponForOne);
      request.setAttribute("fiftycoupon", cashcouponForFive);
      request.setAttribute("twentycoupon", cashcouponForTwo);
      request.setAttribute("listGoodsForm", listGoodsForm);
      request.setAttribute("listCouponForm", listCouponForm);
      request.setAttribute("goodsCatlog", goodsCatlog);
      request.setAttribute("savePrice", savePrice);
      request.setAttribute("merchantForm", merchantForm);
      request.setAttribute("SHOP_ENVIROMENT", environList);
      request.setAttribute("count", count);
      request.setAttribute("MERCHANT_SCORES", evaluationscore);

      // 增加日志2012-01-17
      Map<String, String> mapLog = LogAction.getLogMap(request, response);
      mapLog.put("action", "p_bdp");
      mapLog.put("brandid", merchantID);
      LogAction.printLog(mapLog);
    } catch (Exception e) {
      e.printStackTrace();
      request.setAttribute("ERRMSG", "没有找到相关品牌!");
      return new ModelAndView("redirect:../404.html");
    }
    return "/brand/shangpubao";
    // return "/brand/showBrandDetail";
  }
public class MParseBrand {

  private static final PropertyUtil propertyUtil = PropertyUtil.getInstance(Constant.WAP_PATH);
  private static String ENCODE = "ISO-8859-1";
  private static final String PATH = propertyUtil.getProperty("ONLINE_IMAGE_PATH");
  private static final String INCLUDE = "/include/";
  private static final String STUFF = ".html";

  /**
   * @param szFileName
   * @return
   */
  public static String openFile(String szFileName) {
    try {
      BufferedReader bis =
          new BufferedReader(
              new InputStreamReader(new FileInputStream(new File(szFileName)), ENCODE));
      String szContent = "";
      String szTemp;

      while ((szTemp = bis.readLine()) != null) {
        szContent += szTemp + "\n";
      }
      bis.close();
      return szContent;
    } catch (Exception e) {
      return "";
    }
  }

  /**
   * 获取滚动品牌
   *
   * @param path
   * @param city
   * @param fileName
   * @return
   */
  public static Map<String, String> getBrandInfo(String path, String city, String fileName) {
    Map<String, String> brandMap = new LinkedHashMap<String, String>();
    try {
      StringBuilder filePath = new StringBuilder();
      filePath.append(PATH);
      filePath.append(city);
      filePath.append(INCLUDE);
      filePath.append(fileName);
      filePath.append(STUFF);
      // 开始解析
      Parser parser = new Parser(filePath.toString());
      // 过滤出<a></a>标签
      NodeFilter divFilter = new NodeClassFilter(Div.class);
      NodeList classList = parser.extractAllNodesThatMatch(divFilter);
      NodeList hrefList = null;
      NodeList imgList = null;
      Node picNode = null;
      Node hrefNode = null;
      Node imgNode = null;
      String classStr = "";
      String hrefStr = "";
      String imgStr = "";
      String imgClass = "";
      for (int i = 0; i < classList.size(); i++) {
        picNode = classList.elementAt(i);
        classStr = ((Div) picNode).getAttribute("class");
        if ("business_list_pic".equalsIgnoreCase(classStr)) {
          hrefList = picNode.getChildren();
          for (int j = 0; j < hrefList.size(); j++) {
            hrefNode = hrefList.elementAt(j);
            if (hrefNode instanceof LinkTag) {
              hrefStr = ((LinkTag) hrefNode).getLink(); // 有用品牌id,获取到id
              hrefStr = MParseBrand.getBrandId(hrefStr);
              imgList = hrefNode.getChildren();
              for (int k = 0; k < imgList.size(); k++) {
                imgNode = imgList.elementAt(k);
                if (imgNode instanceof ImageTag) {
                  imgClass = ((ImageTag) imgNode).getAttribute("class");
                  if (null != imgClass) {
                    imgStr = ((ImageTag) imgNode).getAttribute("src");
                    if (null == imgStr) {
                      imgStr = ((ImageTag) imgNode).getAttribute("original");
                    }
                  }
                }
              }
              brandMap.put(hrefStr, imgStr);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return brandMap;
  }

  public static String getBrandId(String url) {
    String brandId = "";
    url = url.replaceAll(":", "").replaceAll("/", "").replaceAll(".html", "").replaceAll("\\.", "");
    Pattern p = Pattern.compile("([\\w&&[\\D]]+)([\\d]+)");
    Matcher m = p.matcher(url);
    if (m.matches()) {
      brandId = m.group(2);
    }
    return brandId;
  }

  // Unit Testing
  public static void main(String[] args) {
    Map<String, String> brandMap = MParseBrand.getBrandInfo("", "beijing", "brand_mainlist");
    for (String key : brandMap.keySet()) {
      System.out.println("key=" + key + "---value=" + brandMap.get(key));
    }
  }
}