@Override public NoteResult addBook(String userId, String bookName) { NoteResult result = new NoteResult(); NoteResult tmp = checkExisted(userId, bookName); if (tmp.getStatus() == 0) { // result.setStatus(-1); result.setMsg("创建新的笔记本失败,是否已经存在该名字的笔记本了"); return result; } Notebook book = new Notebook(); book.setCn_notebook_id(EncodeUtil.createId()); book.setCn_user_id(userId); book.setCn_notebook_name(bookName); book.setCn_notebook_type_id(""); book.setCn_notebook_desc(""); Timestamp time = new Timestamp(System.currentTimeMillis()); book.setCn_notebook_createtime(time); int rtn = notebookDao.save(book); if (rtn == 1) { result.setStatus(0); result.setMsg("创建新的笔记本成功"); result.setData(book.getCn_notebook_id()); } else { result.setStatus(-1); result.setMsg("创建新的笔记本失败,是否已经存在该名字的笔记本了"); } return result; }
@Override @Transactional(readOnly = true) public NoteResult loadBooks(String userId) { NoteResult result = new NoteResult(); if (userId == null || "".equals(userId)) { result.setStatus(1); result.setMsg("用户Id不能为空"); return result; } /** 根据用户 Id提取笔记本 */ List<Notebook> books = notebookDao.loadBooksByUserId(userId); result.setStatus(0); result.setMsg("查询成功"); result.setData(books); return result; }
@Override @Transactional(readOnly = true) public NoteResult checkExisted(String userId, String bookName) { NoteResult result = new NoteResult(); Map<String, String> map = new HashMap<>(); map.put("userId", userId); map.put("bookName", bookName); Notebook book = notebookDao.loadBookByBookNameAndUserId(map); if (book != null) { result.setStatus(0); result.setMsg("已经存在" + bookName + "的笔记本了"); } else { result.setStatus(-1); result.setMsg("不存在" + bookName + "的笔记本"); } return result; }