/** * 参与/关注某一活动,在查看活动详细页面 * * @param mapping 路径映射对象 * @param form 表单对象 * @param request 请求对象 * @param response 响应对象 * @return ActionForward * @throws Exception */ public ActionForward doJoinOrCareActivityRead( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 初始化 ErrorInformation errInfo = new ActivityErrInfo(); RequestUtils requ = RequestUtils.getInstance(request); int id = requ.getInt("id"); int joiner_id = requ.getInt("joiner_id"); int status = requ.getInt("status"); UserInfo loginUser = UserInfo.getLoginUser(request); if (loginUser == null) // 检查用户是否登录 errInfo.saveError(ActivityErrInfo.NEED_LOGIN); else { try { // 如果没有出错,先删除原有信息,再插入新信息 int det = JoinActivityDAO.deleteJoinAndCareAct(id, joiner_id); int ret = JoinActivityDAO.joinActivity(id, joiner_id, status); if (ret < 1) errInfo.saveError(ActivityErrInfo.ERR_UNKNOWN); // 因参加某一活动,用户积分加10 if (errInfo.isEmpty()) { int rt = AuthUserDAO.addScore(loginUser, Utils.SCORE_JOIN_ACTIVITY); if (rt < 1) errInfo.saveError(ActivityErrInfo.ERR_UNKNOWN); } } catch (SQLException e) { Logger.Log(Logger.LOG_ERROR, e); errInfo.saveError(ActivityErrInfo.DATABASE_ERR); } } if (!errInfo.isEmpty()) { errInfo.saveToRequest("err", request); return mapping.findForward("error"); } return new ActionForward("/activity/readact.jsp?actid=" + id, true); }
/** * 删除活动留言 * * @param mapping 路径映射对象 * @param form 表单对象 * @param request 请求对象 * @param response 响应对象 * @return ActionForward * @throws Exception */ public ActionForward doDeleteJoinMes( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 初始化 ErrorInformation errInfo = new ActivityErrInfo(); RequestUtils requ = RequestUtils.getInstance(request); int id = requ.getInt("actid"); int joiner_id = requ.getInt("joiner_id"); int status = requ.getInt("status"); String mes = requ.getString("mestime"); Timestamp mestime = Timestamp.valueOf(mes); // 获取登录用户信息 UserInfo loginUser = UserInfo.getLoginUser(request); if (loginUser == null) // 检查用户是否登录 errInfo.saveError(ActivityErrInfo.NEED_LOGIN); else { try { // 如果没有出错,则删除 int ret = JoinActivityDAO.deleteJoinMes(id, joiner_id, status, mestime); if (ret < 1) errInfo.saveError(ActivityErrInfo.ERR_UNKNOWN); // 因删除留言文章,用户积分减2 if (errInfo.isEmpty()) { int rt = AuthUserDAO.addScore(loginUser, -Utils.SCORE_MESSAGE_ACTIVITY); if (rt < 1) errInfo.saveError(ActivityErrInfo.ERR_UNKNOWN); } } catch (SQLException e) { Logger.Log(Logger.LOG_ERROR, e); errInfo.saveError(ActivityErrInfo.DATABASE_ERR); } } if (!errInfo.isEmpty()) { errInfo.saveToRequest("err", request); return mapping.findForward("error"); } return mapping.findForward("actread"); }
/** * 更新参与/关注活动状态 * * @param mapping 路径映射对象 * @param form 表单对象 * @param request 请求对象 * @param response 响应对象 * @return ActionForward * @throws Exception */ public ActionForward doUpdateActivityStatus( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 初始化信息 ErrorInformation errInfo = new ActivityErrInfo(); RequestUtils requ = RequestUtils.getInstance(request); int id = requ.getInt("id"); int joiner_id = requ.getInt("joiner_id"); int status = requ.getInt("status"); // 获取登录用户信息 UserInfo loginUser = UserInfo.getLoginUser(request); if (loginUser == null) // 检查用户是否登录 errInfo.saveError(ActivityErrInfo.NEED_LOGIN); else { try { // 如果没有出错,则更改 int ret = JoinActivityDAO.UpdateActivityStatus(id, joiner_id, status); if (ret < 1) errInfo.saveError(ActivityErrInfo.ERR_UNKNOWN); } catch (SQLException e) { Logger.Log(Logger.LOG_ERROR, e); errInfo.saveError(ActivityErrInfo.DATABASE_ERR); } } if (!errInfo.isEmpty()) { errInfo.saveToRequest("err", request); return mapping.findForward("error"); } return mapping.findForward("activity"); }
/** * 给某活动留言 * * @param mapping 路径映射对象 * @param form 表单对象 * @param request 请求对象 * @param response 响应对象 * @return ActionForward * @throws Exception */ public ActionForward doAdd( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 获取初始化信息 UserInfo loginUser = UserInfo.getLoginUser(request); ErrorInformation errInfo = new ActivityErrInfo(); RequestUtils requ = RequestUtils.getInstance(request); Timestamp now = new Timestamp(System.currentTimeMillis()); int id = requ.getInt("id"); int actid = requ.getInt("actid"); String content = requ.getString("message"); String authorname = requ.getString("authorname"); String joinerschool = requ.getString("joinerschool"); if (loginUser == null) errInfo.saveError(ActivityErrInfo.NEED_LOGIN); // 检查当前用户是否是正常用户 else if (loginUser.getUserStatus() != SysUtils.USER_STATUS_NORMAL) return mapping.findForward("profile"); // 留言内容不能为空 else if (StringUtils.isNull(content)) errInfo.saveError(ActivityErrInfo.NEEDED_FIELD_NOT_NULL); else { try { // 检查被留言的用户是否存在 if (!AuthUserDAO.isExistUser(id)) { errInfo.saveError(ActivityErrInfo.OPERATION_NOT_ALLOW); } else { // 生成留言信息对象 content = content.replaceAll(" ", " "); content = content.replaceAll("\n", "<br>"); JoinActivityInfo board = new JoinActivityInfo(); board.setActId(actid); board.setJoinerId(id); board.setJoinername(authorname); board.setJointime(now); board.setMessage(content); board.setMestime(now); board.setStatus(Utils.ACTIVITY_MESSAGE); board.setJoinerschool(joinerschool); int ret = JoinActivityDAO.insertMessage(board); if (ret != 1) errInfo.saveError(ActivityErrInfo.ERR_UNKNOWN); } // 因留言文章,用户积分加2 if (errInfo.isEmpty()) { int rt = AuthUserDAO.addScore(loginUser, Utils.SCORE_MESSAGE_ACTIVITY); if (rt < 1) errInfo.saveError(ActivityErrInfo.ERR_UNKNOWN); } } catch (SQLException e) { Logger.Log(Logger.LOG_ERROR, e); errInfo.saveError(ActivityErrInfo.DATABASE_ERR); } } if (!errInfo.isEmpty()) { errInfo.saveToRequest("err", request); return mapping.findForward("error"); } return mapping.findForward("actread"); }