@Test(expectedExceptions = {IpCommentedException.class}) @DataSet({"ViewSpaces.xls","ViewPoints.xls"}) public void testAddCommentLog() throws Throwable{ CommentLog commentLog = XlsDataSetBeanFactory.createBean(ViewSpaceServiceTest.class, "AddComment.xls", "t_comment_log", CommentLog.class); assertNotNull(commentLog); ViewSpace viewSpace = new ViewSpace(); viewSpace.setSpaceId(initSpaceId); commentLog.setViewSpace(viewSpace); commentLog.setCommentType(CommentLog.WANT_TO_GO); viewSpaceService.addCommentLog(commentLog); List<CommentLog> commentLogs = viewSpaceService.getCommentLogBySpaceId(initSpaceId); assertNotNull(commentLogs); assertEquals(1, commentLogs.size()); ViewSpace newViewSpace = viewSpaceService.getFullViewSpace(initSpaceId); assertEquals(1, newViewSpace.getWantNum()); viewSpaceService.addCommentLog(commentLog); }
public void addCommentLog(CommentLog commentLog) throws IpCommentedException{ ViewSpace vs = commentLog.getViewSpace(); vs = viewSpaceDao.load(vs.getSpaceId()); boolean commented =commentLogDao.isIpCommented(vs.getSpaceId(),commentLog.getIp()); if (commented) { throw new IpCommentedException("这个IP已经对景区进行了评论。"); } commentLog.setViewSpace(vs); switch (commentLog.getCommentType()) { case CommentLog.WANT_TO_GO: vs.setWantNum(vs.getWantNum()+1); break; case CommentLog.HAVE_BEAN_TO: vs.setBeenNum(vs.getBeenNum()+1); break; case CommentLog.DONT_WANT_TO_GO: vs.setNotwantNum(vs.getNotwantNum()+1); break; default: throw new RuntimeException("评论类型不正确。"); } commentLogDao.save(commentLog); }
ViewSpaceService { public void addCommentLog(CommentLog commentLog) throws IpCommentedException{ ViewSpace vs = commentLog.getViewSpace(); vs = viewSpaceDao.load(vs.getSpaceId()); boolean commented =commentLogDao.isIpCommented(vs.getSpaceId(),commentLog.getIp()); if (commented) { throw new IpCommentedException("这个IP已经对景区进行了评论。"); } commentLog.setViewSpace(vs); switch (commentLog.getCommentType()) { case CommentLog.WANT_TO_GO: vs.setWantNum(vs.getWantNum()+1); break; case CommentLog.HAVE_BEAN_TO: vs.setBeenNum(vs.getBeenNum()+1); break; case CommentLog.DONT_WANT_TO_GO: vs.setNotwantNum(vs.getNotwantNum()+1); break; default: throw new RuntimeException("评论类型不正确。"); } commentLogDao.save(commentLog); } }
ViewSpaceService { public void addCommentLog(CommentLog commentLog) throws IpCommentedException{ ViewSpace vs = commentLog.getViewSpace(); vs = viewSpaceDao.load(vs.getSpaceId()); boolean commented =commentLogDao.isIpCommented(vs.getSpaceId(),commentLog.getIp()); if (commented) { throw new IpCommentedException("这个IP已经对景区进行了评论。"); } commentLog.setViewSpace(vs); switch (commentLog.getCommentType()) { case CommentLog.WANT_TO_GO: vs.setWantNum(vs.getWantNum()+1); break; case CommentLog.HAVE_BEAN_TO: vs.setBeenNum(vs.getBeenNum()+1); break; case CommentLog.DONT_WANT_TO_GO: vs.setNotwantNum(vs.getNotwantNum()+1); break; default: throw new RuntimeException("评论类型不正确。"); } commentLogDao.save(commentLog); }  }
ViewSpaceService { public void addCommentLog(CommentLog commentLog) throws IpCommentedException{ ViewSpace vs = commentLog.getViewSpace(); vs = viewSpaceDao.load(vs.getSpaceId()); boolean commented =commentLogDao.isIpCommented(vs.getSpaceId(),commentLog.getIp()); if (commented) { throw new IpCommentedException("这个IP已经对景区进行了评论。"); } commentLog.setViewSpace(vs); switch (commentLog.getCommentType()) { case CommentLog.WANT_TO_GO: vs.setWantNum(vs.getWantNum()+1); break; case CommentLog.HAVE_BEAN_TO: vs.setBeenNum(vs.getBeenNum()+1); break; case CommentLog.DONT_WANT_TO_GO: vs.setNotwantNum(vs.getNotwantNum()+1); break; default: throw new RuntimeException("评论类型不正确。"); } commentLogDao.save(commentLog); }  void addViewSpace(ViewSpace viewSpace); void deleteViewSpace(int spaceId); void updateViewSpace(ViewSpace viewSpace); List<ViewSpace> queryViewSpaceByName(String name); List<ViewSpace> queryViewSpaceByUserId(int userId); List<ViewSpace> getAllViewSpaces(); ViewSpace getFullViewSpace(int spaceId); ViewSpace getViewSpace(int spaceId); void addCommentLog(CommentLog commentLog); List<CommentLog> getCommentLogBySpaceId(int spaceId); void addViewPoint(ViewPoint viewPoint); ViewPoint getFullViewPoint(int pointId); void deleteViewPoint(int pointId); void updateViewPoint(ViewPoint viewPoint); void setViewSpaceDao(ViewSpaceDao viewSpaceDao); void setViewPointDao(ViewPointDao viewPointDao); void setCommentLogDao(CommentLogDao commentLogDao); }
ViewSpaceService { public void addCommentLog(CommentLog commentLog) throws IpCommentedException{ ViewSpace vs = commentLog.getViewSpace(); vs = viewSpaceDao.load(vs.getSpaceId()); boolean commented =commentLogDao.isIpCommented(vs.getSpaceId(),commentLog.getIp()); if (commented) { throw new IpCommentedException("这个IP已经对景区进行了评论。"); } commentLog.setViewSpace(vs); switch (commentLog.getCommentType()) { case CommentLog.WANT_TO_GO: vs.setWantNum(vs.getWantNum()+1); break; case CommentLog.HAVE_BEAN_TO: vs.setBeenNum(vs.getBeenNum()+1); break; case CommentLog.DONT_WANT_TO_GO: vs.setNotwantNum(vs.getNotwantNum()+1); break; default: throw new RuntimeException("评论类型不正确。"); } commentLogDao.save(commentLog); }  void addViewSpace(ViewSpace viewSpace); void deleteViewSpace(int spaceId); void updateViewSpace(ViewSpace viewSpace); List<ViewSpace> queryViewSpaceByName(String name); List<ViewSpace> queryViewSpaceByUserId(int userId); List<ViewSpace> getAllViewSpaces(); ViewSpace getFullViewSpace(int spaceId); ViewSpace getViewSpace(int spaceId); void addCommentLog(CommentLog commentLog); List<CommentLog> getCommentLogBySpaceId(int spaceId); void addViewPoint(ViewPoint viewPoint); ViewPoint getFullViewPoint(int pointId); void deleteViewPoint(int pointId); void updateViewPoint(ViewPoint viewPoint); void setViewSpaceDao(ViewSpaceDao viewSpaceDao); void setViewPointDao(ViewPointDao viewPointDao); void setCommentLogDao(CommentLogDao commentLogDao);  }