Skip to content

Commit

Permalink
Merge pull request #42 from chenyhtech/master
Browse files Browse the repository at this point in the history
更新LibraryService   添加:查询可以借的书
  • Loading branch information
shellqiqi authored Sep 21, 2017
2 parents 95f5469 + cd7af05 commit da36cc6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/seu/dao/LibraryDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public List<Library> queryBooksByBookName(final String bookName){
Object[] params = new Object[]{bookName};
return jdbcTemplate.query(sql, params, new LibraryMapper());
}
public List<Library> queryAllBorrowedBook(){
final String sql = "SELECT * FROM Library WHERE not StudentID = ?";
Object[] params = new Object[]{ 0 };
return jdbcTemplate.query(sql, params, new LibraryMapper());
}
public List<Library> queryAll() {
final String sql = "SELECT * FROM Library";
return jdbcTemplate.query(sql, new LibraryMapper());
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/seu/service/LibraryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,33 @@ public int updateBook(Library book) {
}
}

/**
* 学生查询所有可以借的书籍
* @return 返回所有可以借的书籍
*/
public List<Library> getAllAvailableBook(){
try{
List<Library> noAvaliableBook = libraryDao.queryAllBorrowedBook();
List<Library> result = libraryDao.queryAll();
int SIZE = noAvaliableBook.size();
for( int i = 0 ; i < SIZE ;i++){
Library borrowedBook = noAvaliableBook.get(i);
for(int j = 0 ; j < result.size(); j++){
if( borrowedBook.getBookId() == result.get(j).getBookId() )
{
result.remove(j);
break;
}
}
}
//result.removeAll(noAvaliableBook);
return result;
}catch (Exception e){
e.printStackTrace();
return null;
}
}

/**
* 管理员获取所有学生所借图书全部信息
* @return 返回所有学生所借图书全部信息
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/seu/dao/LibraryDaoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public void queryBooksByStudentIdTest() throws Exception {
System.out.println(libraryDaoItem.queryBooksByStudentId(2));
}

@Test
public void queryAllBorrowedBookTest() throws Exception {
System.out.println(libraryDaoItem.queryAllBorrowedBook());
}

@Test
public void queryAllTest() throws Exception {
System.out.println(libraryDaoItem.queryAll());
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/seu/service/LibraryServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@SpringBootTest
@Import(ApplicationContextConfig.class)
public class LibraryServiceTest {

@Autowired
private LibraryService libraryService;
@Test
Expand Down Expand Up @@ -66,6 +65,11 @@ public void updateBookByBookId() throws Exception {
System.out.println(libraryService.updateBook(new Library(5,"book5",2,new Date())));
}

@Test
public void getAllAvailableBook() throws Exception {
System.out.println(libraryService.getAllAvailableBook());
}

@Test
public void getLibraryAll() throws Exception {
System.out.println(libraryService.getLibraryAll());
Expand Down

0 comments on commit da36cc6

Please sign in to comment.