示例#1
0
  @RequestMapping(
      value = "oper/notice/changeStatus",
      method = {RequestMethod.GET, RequestMethod.POST})
  public String changeStatus(
      ModelMap model,
      RedirectAttributes attributes,
      @RequestParam("id") Long id,
      @RequestParam("activo") Boolean activo) {
    Notice noticeEdit = baseService.findById(Notice.class, id);
    noticeEdit.setActivo(activo);
    baseService.save(noticeEdit);

    Notice notice = new Notice();
    model.addAttribute("noticeList", baseService.findAll(Notice.class));
    model.addAttribute("notice", notice);
    model.addAttribute("districts", secopreCache.getValidDistricts());

    return SecopreConstans.MV_CAT_NOTICE_LIST;
  }
示例#2
0
  @RequestMapping(value = "oper/notice/add", method = RequestMethod.POST)
  public String add(
      @ModelAttribute("notice") Notice notice,
      @RequestParam(value = "districts", required = true, defaultValue = "") String district,
      ModelMap model) {
    try {
      if (notice.getId() == null) {
        notice.setActivo(Boolean.TRUE);
      } else {
        Notice noticeEdit = baseService.findById(Notice.class, notice.getId());
        noticeEdit.setDisplayDate(notice.getDisplayDate());
        noticeEdit.setRegisterDate(notice.getRegisterDate());
        noticeEdit.setNoticeInfo(notice.getNoticeInfo());
        noticeEdit.setId(notice.getId());
        notice = noticeEdit;
      }

      if (!district.equals("")) {
        List<District> distritList = new ArrayList<District>();
        List<String> items = Arrays.asList(district.split("\\s*,\\s*"));

        for (String distrid : items) {
          District distr = baseService.findById(District.class, Long.parseLong(distrid));
          distritList.add(distr);
          notice.setDistrs(distritList);
        }
      }

      baseService.save(notice);
    } catch (Exception e) {
      e.getStackTrace();
      e.printStackTrace();
      model.addAttribute(
          "errors", initErrors("Ocurrio un error al insertar el aviso:" + e.getMessage()));
    }
    return SecopreConstans.MV_CAT_NOTICE_LIST;
  }