⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookservice.java

📁 一套网上书店系统采用JAVABEAN+SERVLET+JSP
💻 JAVA
字号:
package cn.dang.service;

import ghy_page_tools.ghy_page_tools_new;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.dang.dao.AllDAO;
import cn.dang.entity.Author;
import cn.dang.entity.Book;
import cn.dang.entity.BookType;
import cn.dang.entity.Concem;

public class BookService {
	private AllDAO allDAO = new AllDAO();
	private AuthorService authorService=new AuthorService();
	private ConcemService concemService=new ConcemService();
	private BookTypeService bookTypeService=new BookTypeService();
	// 插入书籍信息
	public void setBookInfo(ArrayList values_list) throws Throwable {
		// 生成SQL语句
		String sql="insert into books(bookname,bcid,isbn,publishtime,price,clickcount,free,description,aid,pointgrade,cover,tid) values(?,?,?,?,?,0,?,?,?,100,?,?)";
		// 调用数据层方法执行插入
		allDAO.getBookDAO().nonQueryBook(sql, values_list);

	}

	// 获得书籍ID后进行判断返回boolean
	public boolean getBookId(String bookName) throws Throwable {
		String sql = "select bid from books where bookname='" + bookName + "'";
		List list = allDAO.getBookDAO().getBookInfoOne(sql);
		if (list.size() > 0) {
			return true;
		}
		return false;
	}

	// 删除书籍信息
	public void removeBookInfo(ArrayList values_list) throws Throwable {
		String sql="delete from books where bid=?";
		allDAO.getBookDAO().nonQueryBook(sql, values_list);
	}

	// 查询出根据名字获得的书籍信息
	public Book getBookInfo(String id) throws Throwable {
		String sql = "select * from books where bid=" + id + "";
		Author author = new Author();
		BookType bt = new BookType();
		Concem cn = new Concem();
		Book book = new Book();
		book.setAuthor(author);
		book.setBookType(bt);
		book.setConcem(cn);
		// 查询书籍
		Book b = allDAO.getBookDAO().getBookInfo(sql, book);
		// 根据书籍的信息查询作者
		b.setAuthor(authorService.getAuthorInfo(b.getAuthor().getAid()));
		// 根据书籍的信息查询出版社
		b.setConcem(concemService.getConcemInfo(b.getConcem().getCid()));
		// 根据书籍的信息查询小类
		BookType bte = bookTypeService.getBookTypeInfo(b.getBookType().getId());
		
		b.setBookType(bte);
		return b;
	}

	// 更新书籍信息
	public void updateBookInfo(ArrayList values_list) throws Throwable {
		// 利用StringBuilder的append方法进行字符串连接
		String sql="update books set bookname=?,bcid=?,isbn=?,publishtime=?,price=?,free=?,description=?,aid=?,cover=?,tid=? where bid=?";
		allDAO.getBookDAO().nonQueryBook(sql, values_list);
	}
	public List<Book> getAllBookInfo(String sql) throws Throwable{
		List<Book> books=allDAO.getBookDAO().queryBooksInfo(sql);
		List<Book> books2=new ArrayList<Book>();
		for(int i=0;i<books.size();i++){
			books.get(i).setAuthor(authorService.getAuthorInfo(books.get(i).getAuthor().getAid()));
			//System.out.println(authorService.getAuthorInfo(books.get(i).getAuthor().getAid()).getAuthorName());
			System.out.println(books.get(i).getAuthor().getAid());
			books.get(i).setConcem(concemService.getConcemInfo(books.get(i).getConcem().getCid()));
			books.get(i).setBookType(bookTypeService.getBookTypeInfo(books.get(i).getBookType().getId()));
			books.get(i).setDDPrice(books.get(i).getPrice()*(books.get(i).getFree()/10));
			books.get(i).setPoint((Integer)books.get(i).getPoint()/100);
		}
		return books;
	}
	
	public HashMap list_shop(String select_string, String from_string,
			String where_string, String orderby_string, String type,
			String type_field_name, String key_name, String page,
			int page_list, boolean isMulTable) throws Throwable {

		HashMap listHm = new HashMap();

		ghy_page_tools_new pageList=null;

		pageList = new ghy_page_tools_new();
		pageList.setPage_Service(select_string, from_string,
				where_string, orderby_string, type, type_field_name, key_name,
				page, page_list, isMulTable);
		List listBooks=pageList.getRecord_list();
		for(int i=0;i<listBooks.size();i++){
			String[] s=(String[])listBooks.get(i);
			s[7]=String.valueOf((Integer.parseInt(s[7])/100));
		}
		listHm.put("listBooks",listBooks );

		listHm.put("pagebean", pageList.getPagebean());

		listHm.put("TypeList", pageList
				.getTypeList("select * from twotype"));

		System.out.println("Book_info_Service中的list_shop方法提交事务了");

		return listHm;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -