功能介绍
管理员:管理员使用本系统涉到的功能主要有:书籍管理、用户管理、反馈处理。
用户进入系统前台可以实现对首页、玄幻小说、仙侠小说、都市小说、历史小说、登录、注册、后台登录等功能。
部分功能模块代码
package com.lianshuwang.controller;
import com.lianshuwang.domin.Feedback;
import com.lianshuwang.domin.User;
import com.lianshuwang.helper.doBookHelper;
import com.lianshuwang.service.BackStageService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value = "/backstage")
public class BackStageController {
private static final Log logger = LogFactory.getLog(BackStageController.class);
@Autowired
private BackStageService backStageService;
@RequestMapping(value = "/")
public String getLogin() {
return "backstage/adminLogin";
}
@RequestMapping(value = "/backlogin")
public String login(String username, String password, Model model, HttpSession session) {
boolean isLogin = backStageService.getLogin(username, password);
if (isLogin) {
session.setAttribute("status",true);
return "redirect:bookManage";
} else {
model.addAttribute("error","登陆失败,请重试!");
return "backstage/adminLogin";
}
}
@RequestMapping(value = "/backloginout")
public String loginout( Model model, HttpSession session) {
session.setAttribute("status",false);
model.addAttribute("error","成功退出!");
return "backstage/adminLogin";
}
@RequestMapping(value = "/bookManage")
public String bookManage(Model model,HttpSession session) {
if (null == session.getAttribute("status")) {
return "backstage/adminLogin";
}
List<doBookHelper> bookList;
bookList = backStageService.getUploadBooks();
model.addAttribute("bookList",bookList);
return "backstage/bookManage";
}
@RequestMapping(value = "/searchBookByDays")
public String searchBookByDays(int days, Model model,HttpSession session) {
if (null == session.getAttribute("status")) {
return "backstage/adminLogin";
}
List<doBookHelper> bookList;
bookList = backStageService.getBooksByDays(days);
model.addAttribute("bookList",bookList);
return "backstage/bookManage";
}
@RequestMapping(value = "/searchBookByTitle")
public String searchBookByTitle(String title, Model model,HttpSession session) {
if (null == session.getAttribute("status")) {
return "backstage/adminLogin";
}
List<doBookHelper> bookList;
bookList = backStageService.getBooksByTitle(title);
model.addAttribute("bookList",bookList);
return "backstage/bookManage";
}
@RequestMapping(value = "/searchBookByUser")
public String searchBookByUser(long userId, Model model,HttpSession session) {
if (null == session.getAttribute("status")) {
return "backstage/adminLogin";
}
List<doBookHelper> bookList;
bookList = backStageService.getBooksByUserId(userId);
model.addAttribute("bookList",bookList);
return "backstage/bookManage";
}
@RequestMapping(value = "/deleteBook")
@ResponseBody
public Map<String,Object> deleteBook(long bookId) {
logger.info("you are removing a book!");
Map<String,Object> resultMap = new HashMap<String,Object>();
int result = backStageService.deleteBook(bookId);
resultMap.put("result",result);
return resultMap;
}
@RequestMapping(value = "/userManage")
public String userManage(Model model,HttpSession session) {
if (null == session.getAttribute("status")) {
return "backstage/adminLogin";
}
Map<String,Object> resultMap;
resultMap = backStageService.getUserByContribution();
List<User> userList = (List<User>) resultMap.get("userList");
int totalUser = (Integer) resultMap.get("totalUser");
int weekUser = (Integer) resultMap.get("weekUser");
int monthUser = (Integer) resultMap.get("monthUser");
model.addAttribute("userList",userList);
model.addAttribute("weekUser",weekUser);
model.addAttribute("monthUser",monthUser);
model.addAttribute("totalUser",totalUser);
return "backstage/userManage";
}
@RequestMapping(value = "/deleteUser")
@ResponseBody
public Map<String,Integer> deleteUser(long userId) {
logger.info("you are removing a user!");
Map<String,Integer> resultMap = new HashMap<String,Integer>();
int result = backStageService.deleteUser(userId);
resultMap.put("result",result);
return resultMap;
}
@RequestMapping(value = "/searchUser")
public String searchUser(String user, Model model,HttpSession session) {
if (null == session.getAttribute("status")) {
return "backstage/adminLogin";
}
List<User> userList = backStageService.getUserBySearch(user);
Map<String,Object> resultMap;
resultMap = backStageService.getUserByContribution();
int totalUser = (Integer) resultMap.get("totalUser");
int weekUser = (Integer) resultMap.get("weekUser");
int monthUser = (Integer) resultMap.get("monthUser");
model.addAttribute("userList",userList);
model.addAttribute("weekUser",weekUser);
model.addAttribute("monthUser",monthUser);
model.addAttribute("totalUser",totalUser);
return "backstage/userManage";
}
@RequestMapping(value = "/feedbackManage")
public String feedbackManage(Model model,HttpSession session) {
if (null == session.getAttribute("status")) {
return "backstage/adminLogin";
}
List<Feedback> feedbackList = backStageService.getFeedback();
model.addAttribute("feedbackNum",feedbackList.size());
model.addAttribute("feedbackList",feedbackList);
return "backstage/feedbackManage";
}
@RequestMapping(value = "/setRead")
@ResponseBody
public void setFeedbackRead(int feedbackId) {
backStageService.setOneFeedbackRead(feedbackId);
}
@RequestMapping(value = "/setAllRead")
public String setAllFeedbackRead() {
backStageService.setAllFeedbackRead();
return "redirect:feedbackManage";
}
}
package com.lianshuwang.service;
import com.lianshuwang.dao.BookDao;
import com.lianshuwang.dao.FeedbackDao;
import com.lianshuwang.dao.UploadDao;
import com.lianshuwang.dao.UserDao;
import com.lianshuwang.domin.Book;
import com.lianshuwang.domin.Feedback;
import com.lianshuwang.domin.Upload;
import com.lianshuwang.domin.User;
import com.lianshuwang.helper.doBookHelper;
import com.lianshuwang.util.PropertyConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BackStageService {
@Autowired
private UploadDao uploadDao;
@Autowired
private BookDao bookDao;
@Autowired
private UserDao userDao;
@Autowired
private FeedbackDao feedbackDao;
public boolean getLogin(String username, String password) {
String default_user = (String) PropertyConfigurer.getProperty("admin_user");
String default_pass = (String) PropertyConfigurer.getProperty("admin_password");
if (default_user.equals(username) && default_pass.equals(password)) {
return true;
} else {
return false;
}
}
public List<doBookHelper> iteratorUploadList(List<Upload> uploadList) {
List<doBookHelper> doBookHelperList = new ArrayList<doBookHelper>();
Book book;
for (Upload upload : uploadList) {
doBookHelper bookHelper = new doBookHelper();
book = bookDao.queryById(upload.getUploadedBook());
bookHelper.setId(book.getId());
bookHelper.setTitle(book.getBook_title());
bookHelper.setAuthor(book.getBook_author());
bookHelper.setUploader(upload.getUploader());
bookHelper.setUploadedDate(upload.getUploadedDate());
doBookHelperList.add(bookHelper);
}
return doBookHelperList;
}
public List<doBookHelper> getUploadBooks() {
List<doBookHelper> doBookHelperList;
List<Upload> uploadList = uploadDao.queryByUploadedDate();
doBookHelperList = iteratorUploadList(uploadList);
return doBookHelperList;
}
public List<doBookHelper> getBooksByDays(int days) {
List<doBookHelper> doBookHelperList;
List<Upload> uploadList;
if (days == 30) {
uploadList = uploadDao.searchByThirtyDays();
} else if (days == 7) {
uploadList = uploadDao.searchBySevenDays();
} else {
uploadList = uploadDao.searchByToday();
}
doBookHelperList = iteratorUploadList(uploadList);
return doBookHelperList;
}
public List<doBookHelper> getBooksByTitle(String title) {
List<doBookHelper> doBookHelperList = new ArrayList<doBookHelper>();
List<Book> bookList = bookDao.searchBookByTitle(title);
for (Book book: bookList) {
doBookHelper bookHelper = new doBookHelper();
bookHelper.setId(book.getId());
bookHelper.setTitle(book.getBook_title());
bookHelper.setAuthor(book.getBook_author());
Upload upload = uploadDao.queryByBookId(book.getId());
bookHelper.setUploader(upload.getUploader());
bookHelper.setUploadedDate(upload.getUploadedDate());
doBookHelperList.add(bookHelper);
}
return doBookHelperList;
}
public List<doBookHelper> getBooksByUserId(long userId) {
List<doBookHelper> doBookHelperList = new ArrayList<doBookHelper>();
List<Upload> uploadList = uploadDao.queryByUserId(userId);
Book book;
for (Upload upload : uploadList) {
book = bookDao.queryById(upload.getUploadedBook());
doBookHelper bookHelper = new doBookHelper();
bookHelper.setId(book.getId());
bookHelper.setTitle(book.getBook_title());
bookHelper.setAuthor(book.getBook_author());
bookHelper.setUploader(upload.getUploader());
bookHelper.setUploadedDate(upload.getUploadedDate());
doBookHelperList.add(bookHelper);
}
return doBookHelperList;
}
public int deleteBook(long bookId) {
Book book;
book = bookDao.queryById(bookId);
String bookFilePath = book.getBook_file();
File file = new File(bookFilePath);
if (file.exists()) {
file.delete();
} else {
return 0;
}
String bookCoverPath = book.getBook_cover();
File cover = new File(bookCoverPath);
if (cover.exists()) {
cover.delete();
} else {
return 0;
}
int count = bookDao.deleteBook(bookId);
int count2 = uploadDao.deleteUploadRow(bookId);
if (count == 0 || count2 == 0) {
return 0;
}
return 1;
}
public Map<String,Object> getUserByContribution() {
Map<String,Object> resultMap = new HashMap<String,Object>();
List<User> userList = userDao.queryUserByContribution();
resultMap.put("userList",userList);
resultMap.put("totalUser",userDao.queryUserNumber());
resultMap.put("weekUser",userDao.queryUserNumberByWeek());
resultMap.put("monthUser",userDao.queryUserNumberByMonth());
return resultMap;
}
public int deleteUser(long userId) {
int count = userDao.deleteUser(userId);
uploadDao.deleteUploadRowByUser(userId);
if (count == 0) {
return 0;
}
return 1;
}
public List<User> getUserBySearch(String searchTxt) {
List<User> userList = new ArrayList<User>();
if (searchTxt.length() < 5 ) {
userList = userDao.queryUserByUserName(searchTxt);
} else if (isNumeric(searchTxt)) {
long userId = Long.parseLong(searchTxt);
User user1 = userDao.queryById(userId);
userList.add(user1);
List<User> userList1 = userDao.queryUserByUserName(searchTxt);
userList.addAll(userList1);
}
return userList;
}
public boolean isNumeric(String str) {
for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
public List<Feedback> getFeedback() {
List<Feedback> feedbackList = feedbackDao.queryAllNotRead();
return feedbackList;
}
public int setOneFeedbackRead(int id) {
int count = feedbackDao.setOneRead(id);
return count;
}
public int setAllFeedbackRead() {
return feedbackDao.setAllRead();
}
}
package com.lianshuwang.dao;
import com.lianshuwang.domin.Book;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created by admin on 2019/10/13.
*/
@Repository
public interface BookDao {
public Book queryById(long id);
public int queryNumberOfBooks();
public int queryNumberOfSomeTypeBooks(int largeType);
public int addBook(Book book);
public Book queryByTitle(String title);
public List<Book> getLargeTypeBooks(@Param("list") List<Integer> booTypeList,
@Param("startRow") int starRow,
@Param("pageSize") int pageSize);
public List<Book> getSmallTypeBooks(@Param("type_id") int type_id,
@Param("startRow") int starRow,
@Param("pageSize") int pageSize);
public int addDownloadTimes(long id);
public List<Book> queryByDownloadTimes();
public List<Book> searchBookByTitle(String searchTxt);
public List<Book> searchBookByAuthor(String searchTxt);
public int getTotalOfLTBooks(List<Integer> booTypeList);
public int getTotalOfSTBooks(int type_id);
public int deleteBook(long id);
}