一、资源包含:
- 源代码(前后端源代码+sql脚本)
- 配套文档
- 一键启动项目
- 帮忙远程控屏调试
源代码和文档加文章下方的微信名片或者私信领取哦~
二、技术介绍
采用了目前最流行的前后端分离的开发模式,前端使用Vue 后端使用Springboot框架 数据库采用Mysql。
三、项目开发背景
用户在使用手机购买书籍的过程中可能无法确认应该购买哪类书籍,或者一类书籍中哪一本书籍质量较高,评分较好,继而帮用户做出最准确的选择,为解决这个问题开发了图书推荐系统。
项目开发的初衷提供根据用户的喜好自行推荐用户可能感兴趣的书籍、提供当前最热门的书籍推荐、并提供收藏,取消收藏等功能,用户可在查看自己收藏过的书籍。此项目的目的是为用户提供一个整合了书籍推荐、书籍详细、书籍收藏、书籍分类等完整功能的图书推荐系统。
四、项目功能结构
- 登录模块:包含用户登陆相关功能。
- 我的模块:包含当前登录信息,退出登录,查看我的收藏等功能。
- 图书推荐功能:包含首页热门图书,图书推荐,图书列表等功能。
- 图书详情模块:包含某本图书的坐着,出版社,简介等详细信息。
- 图书查找模块:根据图书名称搜索满足条件的图书。
- 图书收藏模块:包含展示用户收藏的图书,操作用户收藏的图书相关功能。
package com.pis.book.service.impl;
import com.pis.book.common.ResponseResult;
import com.pis.book.domain.*;
import com.pis.book.mapper.BooksCollectionMapper;
import com.pis.book.mapper.BooksDetailMapper;
import com.pis.book.mapper.BooksHotMapper;
import com.pis.book.service.BookService;
import com.pis.book.vo.BookDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@Service
public class BookServiceImpl implements BookService {
@Autowired
private BooksHotMapper booksHotMapper;
@Autowired
private BooksDetailMapper booksDetailMapper;
@Autowired
private BooksCollectionMapper booksCollectionMapper;
/**
* @Description 获取热门图书列表
* @return
*/
@Override
public ResponseResult getHotBooks() {
List<BookDetailVo> bookDetailVos = new ArrayList<BookDetailVo>();
List<BooksHot> booksHots = new ArrayList<BooksHot>();
List<BooksHot> bookHostsList = booksHotMapper.selectByExample(new BooksHotCondition());
int count = 4;
for(int i= 0 ; i<count ; i++)
{
int index = new Random().nextInt(bookHostsList.size());
booksHots.add(bookHostsList.get(index));
bookHostsList.remove(index);
}
for(int i = 0 ; i<booksHots.size() ; i++)
{
BooksDetail booksDetail = booksDetailMapper.selectByPrimaryKey(booksHots.get(i).getBookId());
bookDetailVos.add(assembleBookDetailVo(booksDetail));
}
return new ResponseResult("1",bookDetailVos);
}
/**
* @Descrioption:猜你喜欢
* @return
*/
@Override
public ResponseResult getGuessYouLike(String userId) {
List<BookDetailVo> bookDetailVos = new ArrayList<BookDetailVo>();
List<BooksDetail> booksDetails = new ArrayList<BooksDetail>();
if(userId == null || "".equals(userId))
{
//未登录
List<BooksDetail> booksDetailList = booksDetailMapper.selectByExample(new BooksDetailCondition());
int count = 4;
for(int i = 0 ; i<count ; i++)
{
int index = new Random().nextInt(booksDetailList.size());
booksDetails.add(booksDetailList.get(index));
booksDetailList.remove(index);
}
for(int i = 0 ; i<booksDetails.size() ; i++)
{
bookDetailVos.add(assembleBookDetailVo(booksDetails.get(i)));
}
return new ResponseResult("1",bookDetailVos);
}
else
{
//已登录
//查询此用户关注的书籍类型
BooksCollectionCondition booksCollectionCondition = new BooksCollectionCondition();
booksCollectionCondition.createCriteria().andUserIdEqualTo(userId);
List<BooksCollection> bookCollectionList = booksCollectionMapper.selectByExample(booksCollectionCondition);
if(bookCollectionList == null || bookCollectionList.size() == 0)
{
//暂时没有收藏
List<BooksDetail> booksDetailList = booksDetailMapper.selectByExample(new BooksDetailCondition());
int count = 4;
for(int i = 0 ; i<count ; i++)
{
int index = new Random().nextInt(booksDetailList.size());
booksDetails.add(booksDetailList.get(index));
booksDetailList.remove(index);
}
for(int i = 0 ; i<booksDetails.size() ; i++)
{
bookDetailVos.add(assembleBookDetailVo(booksDetails.get(i)));
}
return new ResponseResult("1",bookDetailVos);
}
else
{
//已有收藏
int index = new Random().nextInt(bookCollectionList.size());
String bookTypeId = bookCollectionList.get(index).getBookTypeId();
BooksDetailCondition booksDetailCondition = new BooksDetailCondition();
booksDetailCondition.createCriteria().andBookTypeIdEqualTo(bookTypeId);
List<BooksDetail> booksDetails1 = booksDetailMapper.selectByExample(booksDetailCondition);
for(int i = 0 ; i<booksDetails1.size() ; i++)
{
int index1 = new Random().nextInt(booksDetails1.size());
booksDetails.add(booksDetails1.get(index1));
booksDetails1.remove(booksDetails1.get(index1));
}
for(int i = 0 ; i<booksDetails.size() ; i++)
{
bookDetailVos.add(assembleBookDetailVo(booksDetails.get(i)));
}
return new ResponseResult("1",bookDetailVos);
}
}
}
/**
* @Description:根据id查询书籍详细信息
* @param bookId
* @return
*/
@Override
public ResponseResult getBookDetailById(String bookId) {
BooksDetail booksDetail = booksDetailMapper.selectByPrimaryKey(bookId);
BookDetailVo bookDetailVo = assembleBookDetailVo(booksDetail);
return new ResponseResult("1",bookDetailVo);
}
/**
* @Description:根据书籍名称查找对应的书籍
* @param bookTitle
* @return
*/
@Override
public ResponseResult searchBookDetailByTitle(String bookTitle) {
List<BookDetailVo> bookDetailVos = new ArrayList<BookDetailVo>();
List<BooksDetail> booksDetailList = booksDetailMapper.selectByBookTitle(bookTitle);
for(int i = 0 ; i<booksDetailList.size() ; i++)
{
bookDetailVos.add(assembleBookDetailVo1(booksDetailList.get(i)));
}
return new ResponseResult("1",bookDetailVos);
}
/**
* @Desciption:根据图书类型查询对应的图书
* @param typeId
* @return
*/
@Override
public ResponseResult searchDetailByType(String typeId) {
List<BookDetailVo> bookDetailVos = new ArrayList<BookDetailVo>();
BooksDetailCondition booksDetailCondition = new BooksDetailCondition();
booksDetailCondition.createCriteria().andBookTypeIdEqualTo(typeId);
List<BooksDetail> booksDetailList = booksDetailMapper.selectByExampleWithBLOBs(booksDetailCondition);
for(int i = 0 ; i<booksDetailList.size() ; i++)
{
bookDetailVos.add(assembleBookDetailVo1(booksDetailList.get(i)));
}
return new ResponseResult("1",bookDetailVos);
}
private BookDetailVo assembleBookDetailVo(BooksDetail booksDetail)
{
BookDetailVo bookDetailVo = new BookDetailVo();
bookDetailVo.setId(booksDetail.getId());
bookDetailVo.setBookAuthor(booksDetail.getBookAuthor());
bookDetailVo.setBookDetailImg(booksDetail.getBookDetailImg());
bookDetailVo.setBookIntroduction(booksDetail.getBookIntroduction());
bookDetailVo.setBookMainImg(booksDetail.getBookMainImg());
bookDetailVo.setBookPrice(booksDetail.getBookPrice());
bookDetailVo.setBookPublisher(booksDetail.getBookPublisher());
bookDetailVo.setBookTitle(booksDetail.getBookTitle());
bookDetailVo.setBookTypeId(booksDetail.getBookTypeId());
bookDetailVo.setBookTypeName(booksDetail.getBookTypeName());
return bookDetailVo;
}
private BookDetailVo assembleBookDetailVo1(BooksDetail booksDetail)
{
BookDetailVo bookDetailVo = new BookDetailVo();
bookDetailVo.setId(booksDetail.getId());
bookDetailVo.setBookAuthor(booksDetail.getBookAuthor());
bookDetailVo.setBookDetailImg(booksDetail.getBookDetailImg());
bookDetailVo.setBookIntroduction(booksDetail.getBookIntroduction().substring(0,30)+"...");
bookDetailVo.setBookMainImg(booksDetail.getBookMainImg());
bookDetailVo.setBookPrice(booksDetail.getBookPrice());
bookDetailVo.setBookPublisher(booksDetail.getBookPublisher());
bookDetailVo.setBookTitle(booksDetail.getBookTitle());
bookDetailVo.setBookTypeId(booksDetail.getBookTypeId());
bookDetailVo.setBookTypeName(booksDetail.getBookTypeName());
return bookDetailVo;
}
}