public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { JObject jobject = new JObject(); try { String pin = (String) request.getAttribute("pin"); Staff staff = StaffDao.verify(Integer.parseInt(pin)); String reason = request.getParameter("reason"); CancelReason.InsertBuilder builder = new InsertBuilder(staff.getRestaurantId(), reason); CancelReasonDao.insert(staff, builder); jobject.initTip(true, "操作成功, 已添加退菜原因信息."); } catch (BusinessException e) { e.printStackTrace(); jobject.initTip(e); } catch (Exception e) { e.printStackTrace(); jobject.initTip4Exception(e); } finally { response.getWriter().print(jobject.toString()); } return null; }
private void compareCancelReason(Staff staff, int restaurantId) throws SQLException { List<CancelReason> cancelReasons = CancelReasonDao.get(staff); for (CancelReason.DefaultCR defCR : CancelReason.DefaultCR.values()) { boolean isExist = false; for (CancelReason cr : cancelReasons) { if (cr.getReason().equals(defCR.getReason())) { isExist = true; break; } } assertTrue("lack of" + defCR.getReason(), isExist); } }