示例#1
0
 /**
  * 策略价格列表
  *
  * @param mapping
  * @param actionForm
  * @param request
  * @param response
  * @return
  * @throws Exception
  */
 public ActionForward tacticsPriceList(
     ActionMapping mapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   try {
     VenueUser venueUser = UserUtil.getUserFromSession(request);
     String fieldType = request.getParameter("fieldType");
     Long venueId = venueUser.getVenueInfo().getId();
     List<TacticsPrice> tacticsPriceList = tacticsManager.getTacticsPriceList(venueId, fieldType);
     request.setAttribute("priceList", tacticsPriceList);
     request.setAttribute("fieldType", fieldType);
   } catch (Exception e) {
     log.error(e.getMessage(), e);
     printErrorLabel(response);
   }
   return mapping.findForward(FORWARD_SUCCESS);
 }
示例#2
0
  /**
   * 保存策略价格
   *
   * @param mapping
   * @param actionForm
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward saveTacticsPrice(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    try {
      VenueUser venueUser = UserUtil.getUserFromSession(request);
      Long venueId = venueUser.getVenueInfo().getId();
      JSONObject jsonObject = readJson(request);

      String tacticsId = jsonObject.getString("tacticsId");
      if (StringUtils.isEmpty(tacticsId)) {
        throw new TacticsException("没有附属策略对象");
      }

      Tactics tactics = (Tactics) getBaseManager().get(Tactics.class, Long.parseLong(tacticsId));
      List<TacticsPrice> pricePojos = new ArrayList<TacticsPrice>();
      Object start = jsonObject.get("start");
      Object end = jsonObject.get("end");
      Object price = jsonObject.get("price");

      /** 一个价格 */
      if (start instanceof java.lang.String) {
        TacticsPrice basicPrice = new TacticsPrice();
        basicPrice.setTactics(tactics);
        basicPrice.setFromTime(start.toString());
        basicPrice.setToTime(end.toString());
        basicPrice.setPrice(new Integer(price.toString()));
        basicPrice.setVenueId(venueId);
        pricePojos.add(basicPrice);
      }
      /** 多个价格 */
      else {
        JSONArray starts = (JSONArray) start;
        JSONArray ends = (JSONArray) end;
        JSONArray prices = (JSONArray) price;

        for (int i = 0; i < starts.size(); i++) {
          TacticsPrice basicPrice = new TacticsPrice();
          basicPrice.setTactics(tactics);
          basicPrice.setFromTime(starts.getString(i));
          basicPrice.setToTime(ends.getString(i));
          basicPrice.setPrice(new Integer(prices.getString(i)));
          basicPrice.setVenueId(venueId);
          pricePojos.add(basicPrice);
        }
      }

      tacticsManager.savePrices(tactics.getId(), pricePojos);

      // 设置更新状态
      if (!tactics.getIsModify()) {
        tactics.setIsModify(true);
        getBaseManager().insertOrUpdate(tactics);
      }

      printSuccess(response);
      log.info("场馆ID=" + venueId + ",成功添加策略价格;策略ID=" + tactics.getId());
    } catch (TacticsException e) {
      log.error("保存策略价格时:" + e.getMessage(), e);
      printErrorInfo(e.getMessage(), response);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      printErrorLabel(response);
    }
    return null;
  }