Example #1
0
  public String addConfig() {
    String name = ServletActionContext.getRequest().getParameter("name");
    String open_state = ServletActionContext.getRequest().getParameter("open_state");
    String whiteList = ServletActionContext.getRequest().getParameter("whiteList");
    String showNum = ServletActionContext.getRequest().getParameter("showNum");
    String repeatNum = ServletActionContext.getRequest().getParameter("repeatNum");
    String showTimeInterval = ServletActionContext.getRequest().getParameter("showTimeInterval");
    String timeSlot = ServletActionContext.getRequest().getParameter("timeSlot");

    boolean open = "1".equals(open_state) ? true : false;
    int showN = 0;
    if (!StringTools.isEmpty(showNum)) showN = Integer.parseInt(showNum);

    int repeatN = 1;
    if (!StringTools.isEmpty(repeatNum)) repeatN = Integer.parseInt(repeatNum);

    float showTime = 0;
    if (!StringTools.isEmpty(showTimeInterval)) showTime = Float.parseFloat(showTimeInterval);
    // 媒体
    List<GMedia> medias = mediaService.findAlls(0).getList();
    String appSwitch = "";
    for (GMedia media : medias) {
      String p = ServletActionContext.getRequest().getParameter("appSwitch_" + media.getId());
      if (p != null) appSwitch = appSwitch + media.getId() + ":" + media.getPackageName() + ",";
    }
    if (appSwitch.endsWith(",")) appSwitch = appSwitch.substring(0, appSwitch.length() - 1);
    // 广告位
    List<GAdPosition> adPositions = adPositionService.findAlls().getList();
    String adPositionSwitch = "";
    for (GAdPosition adPosition : adPositions) {
      String p =
          ServletActionContext.getRequest()
              .getParameter("adPositionSwitch_" + adPosition.getType());
      if (p != null) adPositionSwitch = adPositionSwitch + adPosition.getType() + ",";
    }
    if (adPositionSwitch.endsWith(","))
      adPositionSwitch = adPositionSwitch.substring(0, adPositionSwitch.length() - 1);

    // 时间段
    if (timeSlot.endsWith(",")) timeSlot = timeSlot.substring(0, timeSlot.length() - 1);

    if (open) {
      List<GAdConfig> list = adConfigService.findAlls(0).getList();
      for (GAdConfig con : list) {
        if (con.getOpen()) {
          con.setOpen(false);
          adConfigService.update(con);
        }
      }
    }

    GAdConfig adConfig =
        new GAdConfig(
            name, open, whiteList, timeSlot, showN, repeatN, showTime, appSwitch, adPositionSwitch);
    adConfigService.add(adConfig);

    ActionContext.getContext().put("addConfig", "添加成功!");

    return list();
  }
Example #2
0
 public void findConfig() {
   String data = ServletActionContext.getRequest().getParameter("data");
   if (!StringTools.isEmpty(data)) {
     GAdConfig adConfig = adConfigService.find(Long.parseLong(data));
     print(JSONObject.fromObject(adConfig).toString());
   }
 }
Example #3
0
 public void deleteConfig() {
   String id = ServletActionContext.getRequest().getParameter("data");
   if (!StringTools.isEmpty(id)) {
     adConfigService.delete(Long.parseLong(id));
   }
 }