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(); }
public String list() { QueryResult<GAdConfig> qr = adConfigService.findAlls(0); String sindex = ServletActionContext.getRequest().getParameter("index"); int index = 0; if (sindex != null && !"".equals(sindex)) index = Integer.parseInt(sindex); Long num = qr.getNum(); int start = index * 20; if (start > num) { start = 0; } List<GAdConfig> list = adConfigService.findAlls(start).getList(); ActionContext.getContext().put("maxNum", num); ActionContext.getContext().put("list", list); ActionContext.getContext().put("adPositions", adPositionService.findAlls().getList()); ActionContext.getContext().put("medias", mediaService.findAlls(0).getList()); ActionContext.getContext().put("pages", "config"); return "index"; }