@RequestMapping(value = "/searchActs") public String searchActs(HttpServletRequest request, Model model, SearchActForm form) { if (null != form && StringUtils.isNotEmpty(form.getStartDate()) && StringUtils.isNotEmpty(form.getEndDate())) { try { Date startDate = DateUtils.parseDate(form.getStartDate(), new String[] {"yyyy-MM-dd"}); Date endDate = DateUtils.parseDate(form.getEndDate(), new String[] {"yyyy-MM-dd"}); PagerManager pager = new PagerManager(form.getPageId(), 10, actService.countNewActs(startDate, endDate)); List<Act> actList = actService.searchNewActs( startDate, endDate, form.getOrder(), pager.getFirstResult(), pager.getMaxResult()); List<CmsActView> viewList = new ArrayList<CmsActView>(actList.size()); for (Act act : actList) { viewList.add( new CmsActView( act, actService.listSynonymActs(act.getId()), actService.isShieldAct(act.getId()))); } model.addAttribute("cmsActViewList", viewList); model.addAttribute("pager", pager); } catch (ParseException e) { log.error("parse search date error.", e); } model.addAttribute("searchActForm", form); } return "cms/act_list"; }
@RequestMapping(value = "/showSynonym", method = RequestMethod.GET) public String showSynonym(HttpServletRequest request, Model model, long actId) { Act act = actService.getActById(actId); if (null != act) { List<Act> synonymActList = actService.listSynonymActs(actId); List<String> maybeSynonymList = actService.indexSearchName(act.getName(), 10); maybeSynonymList.remove(act.getName()); model.addAttribute("maybeSynonymList", maybeSynonymList); model.addAttribute("synonymActList", synonymActList); model.addAttribute("act", act); } return "cms/synonym_list"; }
@RequestMapping(value = "/showUpdate", method = RequestMethod.GET) public String showUpdate(Model model, Long actId) { if (actId == null) actId = 0l; Act act = actService.getActById(actId); assembleCiteys(model); model.addAttribute("act", act); model.addAttribute("logoWebPath", JzCoreFunction.actLogo(act.getId(), act.getLogo(), 0)); model.addAttribute("age", SuitAge.getByIndex(act.getSuitAge())); model.addAttribute("gender", SuitGender.getByIndex(act.getSuitGender())); model.addAttribute("stauts", SuitStatus.getByIndex(act.getSuitStatus())); return "cms/updateAct"; }
@Override // @Transactional public void createActAd(String actName, long rawAdId) throws ActAdInputException { Act act = actService.getActByName(actName); if (act == null) { throw new ActAdInputException(ActAdInputException.ACT_AD_NAME_IS_NOT_EXIST); } RawAd rawAd = rawAdService.getRawAd(rawAdId); if (rawAd == null) { throw new ActAdInputException(ActAdInputException.ACT_AD_RAW_AD_ID_IS_NULL); } if (isUrlExist(rawAd.getTargetUrl(), act.getId())) { throw new ActAdInputException(ActAdInputException.ACT_AD_URL_IS_EXIST); } try { ActAd actAd = rawAdIntoActAd(rawAd); int sequence = getAdCount(act.getId()); actAd.setSequence((sequence + 1)); actAd.setActId(act.getId()); actAdMapper.insert(actAd); String actIds = rawAd.getActIds(); if (StringUtils.isEmpty(actIds)) { rawAd.setActIds(String.valueOf(act.getId())); } else { String[] ids = actIds.split(","); List<String> list = new ArrayList<String>(); for (String id : ids) { list.add(id); } list.add(String.valueOf(act.getId())); rawAd.setActIds(StringUtils.join(list, ",")); } rawAd.setStatus(1); rawAdService.updateRawAd(rawAd); } catch (Exception e) { throw new ActAdInputException(ActAdInputException.CREATE_ACT_AD_IS_ERROR); } }
private Act converAct(AddActForm form, Long uid) { if (form == null) { return null; } Act act = null; if (form.getId() != null) { act = actService.getActById(form.getId()); if (act == null) { return null; } if (form.getImgFile() != null && form.getImgFile().getSize() > 0) { UUID uuid = UUID.randomUUID(); String fileName = uuid.toString() + "." + uploadImageService.getImgType(form.getImgFile()); uploadImageService.uploadImg(form.getId(), fileName, form.getImgFile()); if (!StringUtils.isEmpty(act.getLogo())) { uploadImageService.deleteImg(form.getId(), act.getLogo()); } act.setLogo(fileName); } } else { act = new Act(); act.setCreateUid(uid); if (form.getImgFile() != null && form.getImgFile().getSize() > 0) { UUID uuid = UUID.randomUUID(); if (form.getImgFile() != null) { String fileName = uuid.toString() + "." + uploadImageService.getImgType(form.getImgFile()); act.setLogo(fileName); } } } if (!form.getCheckAddress()) { act.setAddress(form.getAddress()); act.setCity(form.getCity()); act.setProvince(form.getProvince()); } Date startTime = null; Date endTime = null; try { if (!StringUtils.isEmpty(form.getStartTime())) { startTime = DateUtils.parseDate(form.getStartTime(), new String[] {"yyyy-MM-dd"}); act.setStartTime(startTime); } if (!StringUtils.isEmpty(form.getEndTime())) { endTime = DateUtils.parseDate(form.getEndTime(), new String[] {"yyyy-MM-dd"}); act.setEndTime(endTime); } } catch (ParseException e) { log.error("parse search date error.", e); } String intro = form.getIntro(); if (intro != null) act.setIntro(subString(200, form.getIntro())); if (form.getMaxCharge() == null) { act.setMaxCharge(0); } else { act.setMaxCharge(form.getMaxCharge()); } if (form.getMinCharge() == null) { act.setMinCharge(0); } else { act.setMinCharge(form.getMinCharge()); } if (form.getMaxRoleNum() == null) { act.setMaxRoleNum(0); } else { act.setMaxRoleNum(form.getMaxRoleNum()); } if (form.getMinRoleNum() == null) { act.setMinRoleNum(0); } else { act.setMinRoleNum(form.getMinRoleNum()); } act.setName(subString(10, form.getName())); act.setCategoryIds(StringUtils.join(form.getCatIds(), ",")); if (!StringUtils.isEmpty(form.getSuiAge())) { act.setSuitAge(SuitAge.getSuitAge(form.getSuiAge())); } if (!StringUtils.isEmpty(form.getSuitGender())) { act.setSuitGender(SuitGender.getSuitGender(form.getSuitGender())); } if (!StringUtils.isEmpty(form.getSuitStatu())) { act.setSuitStatus(SuitStatus.getSuitStatus(form.getSuitStatu())); } act.setFullName(subString(30, form.getFullName())); return act; }
@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); }
@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"; }