Exemple #1
0
  @RequestMapping(value = "/createAct", method = RequestMethod.POST)
  public ModelAndView createAct(AddActForm form, Long addUid, HttpServletRequest request) {
    UserContext context = (UserContext) request.getAttribute("context");
    Act act = converAct(form, context.getUid());
    ModelMap mmap = new ModelMap();
    try {
      String logo = null;
      long actId = 0;
      if (act != null && act.getName() != null) {
        Act oldAct = actService.getActByName(act.getName());
        if (oldAct == null) {
          Act a = actService.createAct(act, form.getCatIds());
          if (addUid != null) {
            userActService.addAct(addUid, a.getId());
          }
          actId = a.getId();
          logo = a.getLogo();
          mmap.addAttribute("msg", "create is success");
        } else {
          act.setId(oldAct.getId());
          act.setActive(oldAct.getActive());
          if (CollectionUtils.isNotEmpty(form.getCatIds())) {
            act.setCategoryIds(StringUtils.join(form.getCatIds(), ","));
          }
          act.setCreateTime(oldAct.getCreateTime());
          act.setCreateUid(oldAct.getCreateUid());
          act.setPopularity(oldAct.getPopularity());
          if (act.getProvince() == null) {
            act.setProvince(0l);
          }
          if (act.getCity() == null) {
            act.setCity(0l);
          }
          actService.updateAct(act, form.getCatIds());
          if (StringUtils.isNotEmpty(oldAct.getLogo())) {
            uploadImageService.deleteImg(act.getId(), oldAct.getLogo());
          }
          actId = act.getId();
          logo = act.getLogo();
          mmap.addAttribute("msg", "replace is success");
        }
        if (logo != null
            && form.getImgFile() != null
            && form.getImgFile().getSize() > 0
            && actId > 0) {
          uploadImageService.uploadImg(actId, logo, form.getImgFile());
        }

      } else {
        mmap.addAttribute("msg", "create act name is null");
      }
    } catch (Exception e) {
      mmap.addAttribute("msg", "create act is error.");
      log.error("create act is error.", e);
    }
    return new ModelAndView("redirect:/cms/showCreateAct", mmap);
  }
Exemple #2
0
  @RequestMapping(value = "/searchAct", method = RequestMethod.GET)
  public String searchAct(Model model, String bDate, String eDate, String name, Integer pageId) {
    List<Act> acts = null;
    if (pageId == null) pageId = 1;
    Date startDate = null;
    Date endDate = null;
    try {
      if (!StringUtils.isEmpty(bDate)) {
        startDate = DateUtils.parseDate(bDate, new String[] {"yyyy-MM-dd"});
      }
      if (!StringUtils.isEmpty(eDate)) {
        endDate = DateUtils.parseDate(eDate, new String[] {"yyyy-MM-dd"});
      }
    } catch (ParseException e) {
      log.error("parse search date error.", e);
    }
    PagerManager pager =
        new PagerManager(pageId, 10, actService.searchActsCount(startDate, endDate, name));
    acts =
        actService.searchActs(
            startDate, endDate, name, pager.getFirstResult(), pager.getMaxResult());

    List<CmsActMagerView> viewList = new ArrayList<CmsActMagerView>(acts.size());
    for (Act act : acts) {
      String age = SuitAge.getByIndex(act.getSuitAge()).getType();
      String status = SuitStatus.getByIndex(act.getSuitStatus()).getType();
      String gender = SuitGender.getByIndex(act.getSuitGender()).getType();
      City city = com.juzhai.passport.InitData.CITY_MAP.get(act.getCity());
      Province pro = com.juzhai.passport.InitData.PROVINCE_MAP.get(act.getProvince());
      String proName = "";
      String cityName = "";
      if (pro != null) {
        proName = pro.getName();
      }
      if (city != null) {
        cityName = city.getName();
      }
      String address = "";
      if (act.getAddress() != null) {
        address = act.getAddress();
      }
      String logoWebPath = "";
      if (act.getLogo() != null) {
        logoWebPath = JzCoreFunction.actLogo(act.getId(), act.getLogo(), 0);
      }
      StringBuffer categorys = new StringBuffer();
      String cats = act.getCategoryIds();
      if (cats != null) {
        for (String cat : cats.split(",")) {
          Category c = InitData.CATEGORY_MAP.get(Long.valueOf(cat));
          if (c != null) {
            categorys.append(c.getName() + " ");
          }
        }
      }
      viewList.add(
          new CmsActMagerView(
              act,
              logoWebPath,
              proName,
              cityName,
              address,
              age,
              gender,
              status,
              categorys.toString()));
    }
    model.addAttribute("cmsActMagerViews", viewList);
    model.addAttribute("pager", pager);
    model.addAttribute("acts", acts);
    model.addAttribute("eDate", eDate);
    model.addAttribute("bDate", bDate);
    model.addAttribute("name", name);
    return "cms/ajax/actManager_list";
  }