基于javaweb+mysql的校园二手市场系统(java+SSM+jsp+Tomcat+mysql)

项目介绍
本系统主要实现的功能有:

前台:(1)二手物品信息查看、搜索。
(2)学生注册登录、个人信息修改。
(3)二手物品信息发布、编辑。
(4)二手物品评论、回复、举报。
(5)求购信息发布。
(6)求购信息查看。
后台:(1)管理员登录。
(2)系统管理:菜单管理、角色用户管理、权限管理、日志管理、数据库备份。
(3)业务管理:二手物品管理、求购物品管理、学生信息管理、评论管理、举报管理。

(4)站点管理:友情链接管理、站点基本信息(站点名称、logo、版权等)设置

技术栈
jsp+ssm+mysql5.7请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

	}
	@RequestMapping(value = "/user/sellerInfo", method = RequestMethod.GET)
	public String getSellerInfo(ModelMap model,
			@RequestParam(value = "orderId", required = false) Integer orderId,
			HttpSession session) {
		User sessionUser = (User) session.getAttribute("user");
		if (sessionUser == null) {
			return "redirect:/";
		}
		Order orderInfo = orderService.getOrderById(orderId);
		List<Order> orders = orderService.getOtherOrderBySellerId(
				sessionUser.getId(), orderId);
		model.addAttribute("orderInfo", orderInfo);
		model.addAttribute("orders", orders);
		System.out.println("sellerInfo.size:" + orders.size());
		return "user/sellerInfo";
	}
	@RequestMapping(value = "/user/order/delete/{orderId}", method = RequestMethod.GET)
	public ResponseEntity deleteOrderById(@PathVariable Integer orderId) {
		Boolean success;
		success = orderService.deleteOrderById(orderId) > 0;
		return ResponseEntity.ok(success);
			String fileName = goodId + randomString.getRandomString(10);
			String contentType = mainFile.getContentType();
			String imageName = contentType
					.substring(contentType.indexOf("/") + 1);
			name = fileName + "." + imageName;
			mainFile.transferTo(new File(pathRoot + name));
			String photoUrl = filePath + "/" + name;
			goodService.updateGoodPhotoUrl(photoUrl, goodId);
		}
		for (MultipartFile mf : file) {
			if (!mf.isEmpty()) {
				// 生成uuid作为文件名称
				String fileName = goodId + randomString.getRandomString(10);
				// 获得文件类型(可以判断如果不是图片,禁止上传)
				String contentType = mf.getContentType();
				// 获得文件后缀名称
				String imageName = contentType.substring(contentType
						.indexOf("/") + 1);
				name = fileName + "." + imageName;
				System.out.println("name:" + name);
				mf.transferTo(new File(pathRoot + name));
				Image image = new Image();
				image.setGoodId(goodId);
				image.setName(name);
				image.setUrl(filePath + "/" + name);
				imageService.insertImage(image);
		}
		List<Good> goods = goodService.getAllGoods(0, 5);
		if (!(goodService.updateGood(good) > 0)) {
			System.out.println("修改物品失败!");
		}
		List<Image> goodImages = imageService.getImageByGoodId(good.getId());
		model.addAttribute("goods", goods);
		model.addAttribute("good", good);
		model.addAttribute("goodImages", goodImages);
		model.addAttribute("firstTypes", firstTypes);
		return "goods/userGoodEdit";
	}
	@RequestMapping(value = "/goods/userGoodEdit/updateImage", method = RequestMethod.POST)
	public String updateImage(
			HttpSession session,
			@RequestParam(value = "goodId", required = false) Integer goodId,
			@RequestParam(value = "mainFile", required = false) MultipartFile mainFile,
			@RequestParam(value = "file", required = false) MultipartFile[] file)
			throws IOException {
		User user = (User) session.getAttribute("user");
		FileCheck fileCheck = new FileCheck();
		RandomString randomString = new RandomString();
		String filePath = "/statics/image/goods/" + user.getId() + "/" + goodId;
		String pathRoot = fileCheck.checkGoodFolderExist(filePath);
		String name;
		if (!mainFile.isEmpty()) {
			String contentType = mainFile.getContentType();
			String fileName = goodId + randomString.getRandomString(10);
			String imageName = contentType
					.substring(contentType.indexOf("/") + 1);
			name = fileName + "." + imageName;
			mainFile.transferTo(new File(pathRoot + name));
			String photoUrl = filePath + "/" + name;
			goodService.updateGoodPhotoUrl(photoUrl, goodId);
		}
		for (MultipartFile mf : file) {
			if (!mf.isEmpty()) {
				String contentType = mf.getContentType();
				Reply reply = new Reply();
				reply.setReviewId(reviewId);
				reply.setFromUser(fromUser);
				reply.setFromUserId(fromUserId);
				reply.setToUser(toUser);
				reply.setToUserId(toUserId);
				reply.setText(replyText);
				if (reviewService.insertReply(reply) == 1) {
					message = "回复成功!";
					return "redirect:/goods/goodInfo?goodId=" + goodId;
				} else {
					message = "回复失败!";
					return "redirect:/goods/goodInfo?goodId=" + goodId;
				}
			}
		} else {
			Review review = new Review();
			review.setGoodId(goodId);
			review.setFromUser(fromUser);
			review.setFromUserId(fromUserId);
		this.userService = userService;
		this.collectService = collectService;
	}
	@RequestMapping(value = "userProfile", method = RequestMethod.GET)
	public String getMyProfile(ModelMap model, HttpSession session) {
		User user = (User) session.getAttribute("user");
		if (user == null) {
			return "redirect:/";
		}
		List<Collect> collects = collectService
				.getCollectByUserId(user.getId());
		for (Collect collect : collects) {
			collect.setGood(goodService.getGoodById(collect.getGoodId()));
		}
		List<Good> goods = goodService.getGoodByUserId(user.getId());
		List<Order> orders = orderService.getOrderByCustomerId(user.getId());
		List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
		List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
		List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
		model.addAttribute("collects", collects);
		model.addAttribute("goods", goods);
		model.addAttribute("orders", orders);
			} else {
				System.out.println("文件为空!");
			}
		}
		return "redirect:/goods/goodInfo?goodId=" + goodId;
	}
	@RequestMapping(value = "/goods/userGoods", method = RequestMethod.GET)
	public String getUserGoods(ModelMap model,
			@RequestParam(value = "userId", required = false) Integer userId) {
		User user = userService.getUserById(userId);
		List<Good> userGoods = goodService.getGoodStatusByUserId(userId);
		List<Good> goods = goodService.getAllGoods(0, 4);
		model.addAttribute("user", user);
		model.addAttribute("userGoods", userGoods);
		model.addAttribute("goods", goods);
			@RequestParam(value = "photo", required = false) MultipartFile photo)
			throws IOException {
		String status;
		Boolean insertSuccess;
		User sessionUser = (User) session.getAttribute("user");
		user.setId(sessionUser.getId());
		InfoCheck infoCheck = new InfoCheck();
		if (!infoCheck.isMobile(user.getMobile())) {
			status = "请输入正确的手机号!";
		} else if (!infoCheck.isEmail(user.getEmail())) {
			status = "请输入正确的邮箱!";
		} else if (userService.getUserByMobile(user.getMobile()).getId() != user
				.getId()) {
			System.out.println(userService.getUserByMobile(user.getMobile())
					.getId() + " " + user.getId());
		}
		model.addAttribute("firstTypes", firstTypes);
		model.addAttribute("goods", goods);
		model.addAttribute("pages", Math.ceil(goodsNum / limit));
		model.addAttribute("goodsNum", goodsNum);
		model.addAttribute("offset", offset);
		model.addAttribute("limit", limit);
		return "home/homeGoods";
	}
	@RequestMapping(value = "/goods/goodInfo", method = RequestMethod.GET)
	public String getGoodInfo(ModelMap model, HttpSession httpSession,
			@RequestParam(required = false) Integer goodId) {
		Good goodInfo = goodService.getGoodById(goodId);
		if (goodInfo == null) {
			return "goods/error";
		}
		Integer collect = 1;
		User user = (User) httpSession.getAttribute("user");
		if (user == null) {
			collect = 0;
		} else {
			if (collectService.getCollect(goodId, user.getId())) {
			@RequestParam(value = "reviewText", required = false, defaultValue = "") String reviewText) {
		if (reviewText.equals("")) {
			if (replyText.equals("")) {
				message = "内容不能为空!";
				return "redirect:/goods/goodInfo?goodId=" + goodId;
			} else {
				Reply reply = new Reply();
				reply.setReviewId(reviewId);
				reply.setFromUser(fromUser);
				reply.setFromUserId(fromUserId);
				reply.setToUser(toUser);
				reply.setToUserId(toUserId);
				reply.setText(replyText);
		double goodsNum = goodService.getGoodsBySearchAndTypeCount(searchText,
				secondTypeId);
		List<FirstType> firstTypes = typeService.getAllFirstType();
		for (FirstType firstType : firstTypes) {
			firstType.setSecondType(typeService
					.getSecondTypeByFirstTypeId(firstType.getId()));
		}
		model.addAttribute("firstTypes", firstTypes);
		model.addAttribute("goods", goods);
		model.addAttribute("pages", Math.ceil(goodsNum / limit));
		model.addAttribute("goodsNum", goodsNum);
		model.addAttribute("offset", offset);
		model.addAttribute("limit", limit);
		return "home/homeGoods";
	}
	@RequestMapping(value = "/goods/goodInfo", method = RequestMethod.GET)
	public String getGoodInfo(ModelMap model, HttpSession httpSession,
			@RequestParam(required = false) Integer goodId) {
		Good goodInfo = goodService.getGoodById(goodId);

基于javaweb+mysql的ssm+maven图书租赁管理系统(java+ssm+jsp+bootstrap+echarts+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SSM+Maven图书租赁管理系统(java+ssm+jsp+bootstrap+echarts+mysql)

图书租赁管理系统

项目介绍

图书租赁管理系统,该系统分为管理员与普通读者两种角色; 管理员主要功能包括: 图书管理:添加、修改、删除; 图书分类管理:添加、修改、删除; 借阅信息:还书; 预定信息:确认借书; 归还信息; 统计管理:借书/归还、营业额、销量; 普通读者主要功能包括:预定图书、待拿图书、借阅中、归还信息等;

客户端的充值,使用的支付宝沙箱测试化境

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 8.0版本; 7.lombok插件安装:本项目需要安装lombok插件,否则运行会有异常;

技术栈

  1. 后端:Spring SpringMVC MyBatis 2. 前端:JSP+bootstrap+jQuery+echarts

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;

  2. 运行项目,输入localhost:8080/bm/

					break;
				}
			}
		} catch (UnsupportedEncodingException e) {
			logger.error("Cookie Decode Error.", e);
		}
		return retValue;
	}

	/**
	 * 得到Cookie的值,
	 * 
	 * @param request
	 * @param cookieName
	 * @return
	 */
	public static String getCookieValue(HttpServletRequest request, String cookieName, String encodeString) {
		Cookie[] cookieList = request.getCookies();
		if (cookieList == null || cookieName == null){
			return null;			
		}
		String retValue = null;
		try {
			for (int i = 0; i < cookieList.length; i++) {
				if (cookieList[i].getName().equals(cookieName)) {
					retValue = URLDecoder.decode(cookieList[i].getValue(), encodeString);
					break;
				}
			}
		} catch (UnsupportedEncodingException e) {
			logger.error("Cookie Decode Error.", e);
		}
		return retValue;
	}

	/**
	 * 设置Cookie的值 不设置生效时间默认浏览器关闭即失效,也不编码
	 */
	public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue) {
		setCookie(request, response, cookieName, cookieValue, -1,"/");
	}

	/**
	 * 设置Cookie的值 在指定时间内生效,但不编码
	 */
	public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue, int cookieMaxage) {
		setCookie(request, response, cookieName, cookieValue, cookieMaxage, false);
	}

	/**
	 * 设置Cookie的值 不设置生效时间,但编码
        //发送的邮箱内容
        String emailMsg = mailTemplate.getTemplate()
                .replace("{borrowBooksTime}",DateUtils.dateFormat("yyyy年MM月dd日",borrowBook.getBbTime()))
                .replace("{dueTime}",DateUtils.dateFormat("yyyy年MM月dd日",borrowBook.getDueTime()))
                .replace("{bookName}",borrowBook.getBName())
                .replace("{userName}",borrowBook.getRName())
                .replace("{remainingDay}",borrowBook.getRemainingDays()+"")
                .replace("{systemUrl}",aDocument);
        //发送邮箱提醒
        try {
            mailUtils.sendRemind(reader.getEmail(),emailMsg);
        } catch (MessagingException e) {    //发送邮箱还书提醒失败!
            e.printStackTrace();
            throw new LyException(ExceptionEnum.SEND_REMIND_FAIL);
        }
    }
}

@RequestMapping("reader/reserveBorrow")
@RestController
public class RReserveBorrowBooksController {

    @Autowired
    private ReserveBorrowBooksService reserveBookService;

    @Autowired
        MailTemplate mailTemplate = null;
        //实际借书天数(现在的时间-租借的时间)
        int readyDay =  DateUtils.differenceDay(new Date(),borrowBook.getBbTime());
        //最大借书天数 = 应该还书的时间-租借的时间
        int maxDay = DateUtils.differenceDay(borrowBook.getDueTime(),borrowBook.getBbTime());
        //逾期天数 = 实际借书天数 - 最大借书天数
        int overDay = readyDay - maxDay;
        //用户是否逾期
        if(overDay <=0 ){ //还未逾期
            //查询未逾期模板
            mailTemplate = templateMapper.selectByPrimaryKey(1);
            borrowBook.setRemainingDays(maxDay-readyDay);
        }else{
            mailTemplate = templateMapper.selectByPrimaryKey(2);
            borrowBook.setRemainingDays(overDay);
        }

        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
        String url = basePath;

        String aDocument = "<a href=\""+url+"\">"+url+"</a>";
        //发送的邮箱内容
        String emailMsg = mailTemplate.getTemplate()
                .replace("{borrowBooksTime}",DateUtils.dateFormat("yyyy年MM月dd日",borrowBook.getBbTime()))
                .replace("{dueTime}",DateUtils.dateFormat("yyyy年MM月dd日",borrowBook.getDueTime()))
                .replace("{bookName}",borrowBook.getBName())
                .replace("{userName}",borrowBook.getRName())
                .replace("{remainingDay}",borrowBook.getRemainingDays()+"")
                .replace("{systemUrl}",aDocument);
        //发送邮箱提醒
        try {
            mailUtils.sendRemind(reader.getEmail(),emailMsg);
        } catch (MessagingException e) {    //发送邮箱还书提醒失败!
            e.printStackTrace();
            throw new LyException(ExceptionEnum.SEND_REMIND_FAIL);
        }
    }
}

    @Autowired
    private Jedis jedis;

    @Autowired
    private BMSystemProperties bmProperties;

    @Autowired
    private MailUtils mailUtils;

    //根据id查询读者信息
    public Reader queryById(Integer rId) {
        return readerMapper.selectByPrimaryKey(rId);
    }

    //判断账户名是否存在
    public void accountNameExist(String accountName) {
        if (!CollectionUtils.isEmpty(readerMapper.select(new Reader(accountName)))) {    //账户名已存在
            throw new LyException(ExceptionEnum.READER_ACCOUNT_NAME_EXIST);
        }
    }

    //用户注册
    public void saveReader(Reader reader) {
        //根据用户的账户名获取邮箱的验证码
        String verifyCode = jedis.get(reader.getAccount());
        if (StringUtils.isBlank(verifyCode)) {    //验证码已失效,或邮箱地址错误!
            throw new LyException(ExceptionEnum.VERIFY_EXPIRY_OR_EMAIL_ERROR);
        }
        if (!reader.getVerifyCode().equals(verifyCode)) { //邮箱验证码不匹配
            throw new LyException(ExceptionEnum.VERIFY_CODE_NOT_MATCHING);
        }
        reader.builderReader();
        readerMapper.insert(reader);
    }

    //发送邮箱验证码
    public void verifyMailCode(String account, String email) {
        //获取4位数的验证码
        String verifyCode = new Random().nextInt(9999) + "";
        //将验证码根据 account存入redis中
        jedis.set(account, verifyCode);
        //设置验证码有效期
        jedis.expire(account, bmProperties.getEmailVerifyCodeMinute()*60);
        //发送邮箱验证码
        Integer validMinute = bmProperties.getEmailVerifyCodeMinute();
        String emailMsg = bmProperties.getMailReaderRegisterContentModel();
        emailMsg = emailMsg.replace("{emailVerifyCode}", verifyCode).replace("{emailVerifyCodeMinute}", validMinute + "");
        try {
            mailUtils.sendRegisterVerifyCode(email, emailMsg);
        } catch (MessagingException e) {
        return reserveBorrowBooks.getRbbId();
    }

    //读者 修改剩余天数
    @Transactional
    public void modifyRemainingDays(Integer rbbId, Integer remainingDays) {
        //预定天数不能大于 {{maxBorrowBooksDay}} 最大结束天数
        if(remainingDays >= bmProperties.getMaxBorrowBooksDay()){
            //抱歉,最大借书天数为{maxBorrowBooksDay}天!
            ExceptionEnum em = ExceptionEnum.GREATER_THAN_MAX_BORROW_BOOKS_DAY;
            em.setMsg(em.getMsg().replace("{maxBorrowBooksDay}",bmProperties.getMaxBorrowBooksDay()+""));
            throw new LyException(em);
        }
        //根据id查询 预约图书表中的数据
        ReserveBorrowBooks reserveBorrowBooks = reserveBookMapper.selectByPrimaryKey(rbbId);
        if(reserveBorrowBooks == null){ //预定记录不存在,您的书籍已经成功领取!
            log.error("预约图书表修改剩余天数,失败");
            throw new LyException(ExceptionEnum.BOOK_GET_DOWN);
        }
        //查询图书是否存在
        Books books = bookMapper.selectByPrimaryKey(reserveBorrowBooks.getBId());
        if(books == null){
            throw new LyException(ExceptionEnum.BOOK_INFO_LOSE);
        }
        //修改图书数据
        if(remainingDays > 0){
            reserveBorrowBooks.setRemainingDays(remainingDays);
            //修改预约表中的数据
          reserveBookMapper.updateByPrimaryKey(reserveBorrowBooks);
        }
    }

    //读者 删除预定
    @Transactional
    public void deleteReserve(List<Integer> rbbIds) {
        for (Integer rbbId : rbbIds) {
            //根据id查询 预约图书表中的数据
            ReserveBorrowBooks reserveBorrowBooks = reserveBookMapper.selectByPrimaryKey(rbbId);
            if(reserveBorrowBooks == null){ //图书预定不存在,您的书籍已经成功领取!
                log.error("删除预定失败!");
                throw new LyException(ExceptionEnum.BOOK_GET_DOWN);
            }
            //查询图书信息
            Books books = bookMapper.selectByPrimaryKey(reserveBorrowBooks.getBId());
            if(books == null){  //判断是否存在
                throw new LyException(ExceptionEnum.BOOK_INFO_LOSE);
            }
            //删除数据
            reserveBookMapper.deleteByPrimaryKey(rbbId);
        }
    }
}
          reserveBookMapper.updateByPrimaryKey(reserveBorrowBooks);
        }
    }

    //读者 删除预定
    @Transactional
    public void deleteReserve(List<Integer> rbbIds) {
        for (Integer rbbId : rbbIds) {
            //根据id查询 预约图书表中的数据
            ReserveBorrowBooks reserveBorrowBooks = reserveBookMapper.selectByPrimaryKey(rbbId);
            if(reserveBorrowBooks == null){ //图书预定不存在,您的书籍已经成功领取!
                log.error("删除预定失败!");
                throw new LyException(ExceptionEnum.BOOK_GET_DOWN);
            }
            //查询图书信息
            Books books = bookMapper.selectByPrimaryKey(reserveBorrowBooks.getBId());
            if(books == null){  //判断是否存在
                throw new LyException(ExceptionEnum.BOOK_INFO_LOSE);
            }
            //删除数据
            reserveBookMapper.deleteByPrimaryKey(rbbId);
        }
    }
}

/**
 * 
 * Cookie 工具类
 *
 */
public final class CookieUtils {

	protected static final Logger logger = LoggerFactory.getLogger(CookieUtils.class);

	/**
	 * 得到Cookie的值, 不编码
	 * 
	 * @param request
	 * @param cookieName
	 * @return
	 */
	public static String getCookieValue(HttpServletRequest request, String cookieName) {
	 * 设置Cookie的值,并使其在指定时间内生效
	 * 
	 * @param cookieMaxage
	 *            cookie生效的最大秒数
	 */
	private static final void doSetCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue, int cookieMaxage, boolean isEncode,String path) {
		try {
			if (cookieValue == null) {
				cookieValue = "";
			} else if (isEncode) {
				cookieValue = URLEncoder.encode(cookieValue, "utf-8");
			}
			Cookie cookie = new Cookie(cookieName, cookieValue);
			if (cookieMaxage > 0)
				cookie.setMaxAge(cookieMaxage);
			if (null != request)// 设置域名的cookie
				cookie.setDomain(getDomainName(request));
			cookie.setPath(path);
			response.addCookie(cookie);
		} catch (Exception e) {
			logger.error("Cookie Encode Error.", e);
		}
	}

	/**
	 * 设置Cookie的值,并使其在指定时间内生效
	 * 
	 * @param cookieMaxage
	 *            cookie生效的最大秒数
	 */
	private static final void doSetCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue, int cookieMaxage, String encodeString,String path) {
		try {
			if (cookieValue == null) {
				cookieValue = "";
			} else {
				cookieValue = URLEncoder.encode(cookieValue, encodeString);
			}
			Cookie cookie = new Cookie(cookieName, cookieValue);
			if (cookieMaxage > 0)
				cookie.setMaxAge(cookieMaxage);
			if (null != request)// 设置域名的cookie
        if(books.getInLibraryTotal() <= 0){ //抱歉,该图书已全部借出!
            throw new LyException(ExceptionEnum.SORRY_BOOK_BORROW_ALL);
        }
        if(books.getInLibraryTotal() <= books.getReserveNum()){ //抱歉,图书预定人数已满!  在馆数(总数-借出数) == 预定数(预定表中数量)
            throw new LyException(ExceptionEnum.RESERVE_BOOK_FULL);
        }
        //预定天数不能大于 {{maxBorrowBooksDay}} 最大结束天数
        if(rentDay >= bmProperties.getMaxBorrowBooksDay()){
            //抱歉,最大借书天数为{maxBorrowBooksDay}天!
            ExceptionEnum em = ExceptionEnum.GREATER_THAN_MAX_BORROW_BOOKS_DAY;
            em.setMsg(em.getMsg().replace("{maxBorrowBooksDay}",bmProperties.getMaxBorrowBooksDay()+""));
            throw new LyException(em);
        }
        //账户至少有 多少钱才能预定图书
        if(reader.getBalance()/100.0 < bmProperties.getBorrowBooksAccountLest()){
            //抱歉,账户余额少于{balanceLess}元不能借书,请您点击右上角头像选择充值!
            ExceptionEnum em = ExceptionEnum.ACCOUNT_BALANCE_LESS;
            em.setMsg(em.getMsg().replace("{balanceLess}",bmProperties.getBorrowBooksAccountLest()+""));
            throw new LyException(em);
        }
        //封装 预定借书表
        ReserveBorrowBooks reserveBorrowBooks = new ReserveBorrowBooks();
        reserveBorrowBooks.setRId(reader.getRId());
        reserveBorrowBooks.setBId(books.getBId());
        reserveBorrowBooks.setOrderTime(new Timestamp(new Date().getTime()));
        reserveBorrowBooks.setRemainingDays(rentDay);
        //将 该图书记录 插入 预定借阅表中
        reserveBookMapper.insert(reserveBorrowBooks);
        //返回插入的id
        return reserveBorrowBooks.getRbbId();
    }

    //读者 修改剩余天数
    @Transactional
    public void modifyRemainingDays(Integer rbbId, Integer remainingDays) {
        //预定天数不能大于 {{maxBorrowBooksDay}} 最大结束天数
        if(remainingDays >= bmProperties.getMaxBorrowBooksDay()){
            //抱歉,最大借书天数为{maxBorrowBooksDay}天!
            ExceptionEnum em = ExceptionEnum.GREATER_THAN_MAX_BORROW_BOOKS_DAY;
            em.setMsg(em.getMsg().replace("{maxBorrowBooksDay}",bmProperties.getMaxBorrowBooksDay()+""));
            throw new LyException(em);
        }
        //根据id查询 预约图书表中的数据
        ReserveBorrowBooks reserveBorrowBooks = reserveBookMapper.selectByPrimaryKey(rbbId);
        if(reserveBorrowBooks == null){ //预定记录不存在,您的书籍已经成功领取!
            log.error("预约图书表修改剩余天数,失败");
            throw new LyException(ExceptionEnum.BOOK_GET_DOWN);
    //借书 一个
    @PostMapping("/{resId}")
    public ResponseEntity<Void> saveReserve(@PathVariable("resId") Integer resId){
        reserveBookService.saveReserves(Arrays.asList(resId));
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    //借书 多个
    @PostMapping
    public ResponseEntity<Void> saveReserves(@RequestBody List<Integer> resIds){
        reserveBookService.saveReserves(resIds);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

}

@RequestMapping("reader/giveBack")
@RestController
public class RGiveBackController {

    @Autowired
    private GiveBackBookService giveBackBookService;

    @Autowired
    private BMSystemProperties bmProperties;

    //分页查询 并可以带查询参数
    @GetMapping("/{page}/{size}")
    public ResponseEntity<Page<GiveBackBooks>> giveBackBook(@PathVariable("page") Integer page,
                                                            @PathVariable("size") Integer size,
                                                            GiveBackBooks reserveGiveBack,
                                                            HttpSession session){
        Reader reader = (Reader) session.getAttribute(bmProperties.getReaderSessionName());
        reserveGiveBack.setRName(reader.getRName());
    }

    //读者修改 借阅天数
    @PutMapping("/{rbbId}/{remainingDays}")
    public ResponseEntity<Void> modifyRemainingDays(@PathVariable("rbbId") Integer rbbId,
                                                    @PathVariable("remainingDays") Integer remainingDays){
        reserveBookService.modifyRemainingDays(rbbId,remainingDays);
        return ResponseEntity.ok().build();
    }

    //读者取消预定 多个
    @DeleteMapping
    public ResponseEntity<Void> deleteReserves(@RequestBody List<Integer> rbbIds){
        reserveBookService.deleteReserve(rbbIds);
        return ResponseEntity.ok().build();
    }

    //读者删除 预定
    @DeleteMapping("/{rbbId}")
    public ResponseEntity<Void> deleteReserve(@PathVariable("rbbId") Integer rbbId){
        reserveBookService.deleteReserve(Arrays.asList(rbbId));
        return ResponseEntity.ok().build();
    }

    //读者 预定图书
    @PostMapping("/{bId}/{RentDay}")
    public ResponseEntity<Integer> reserveBooks(@PathVariable("bId") Integer bId,
                                             @PathVariable("RentDay") Integer rentDay,
                                             HttpSession session){
        return ResponseEntity.ok().body(reserveBookService.reserveBook(bId, rentDay, session));
    }

}

@RequestMapping("/manager/books")
@RestController()
public class MBookController {

			logger.error("Cookie Decode Error.", e);
		}
		return retValue;
	}

	/**
	 * 设置Cookie的值 不设置生效时间默认浏览器关闭即失效,也不编码
	 */
	public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue) {
		setCookie(request, response, cookieName, cookieValue, -1,"/");
	}

	/**
	 * 设置Cookie的值 在指定时间内生效,但不编码
	 */
	public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue, int cookieMaxage) {
		setCookie(request, response, cookieName, cookieValue, cookieMaxage, false);
	}

	/**
	 * 设置Cookie的值 不设置生效时间,但编码
	 */
	public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue, boolean isEncode) {
		setCookie(request, response, cookieName, cookieValue, -1, isEncode);
	}

	/**
	 * 设置Cookie的值 在指定时间内生效, 编码参数
	 */
	public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue, int cookieMaxage, boolean isEncode) {
		doSetCookie(request, response, cookieName, cookieValue, cookieMaxage, isEncode,"/");
	}

	/**
	 * 设置Cookie的值 在指定时间内生效, 编码参数(指定编码)
	 */
	public static void setCookie(HttpServletRequest request, HttpServletResponse response, String cookieName, String cookieValue, int cookieMaxage, String encodeString) {
		doSetCookie(request, response, cookieName, cookieValue, cookieMaxage, encodeString,"/");
	}

	/**

    @Autowired
    private ManagerMapper managerMapper;

    @Autowired
    private BMSystemProperties bmProperties;

    //用户登录
    public String login(LoginVo loginVo, HttpServletResponse response, HttpServletRequest request) {
        //判断用户的类型
        String type = loginVo.getType();
        String url;
        if(type.equals("读者")){
            url = loginReader(loginVo,response,request);
        }else{  //管理员
            url = loginManager(loginVo,request);
        }
        return url;
    }

    //用户登录
    @Transactional
    public String loginReader(LoginVo loginVo, HttpServletResponse response,HttpServletRequest request){
        //根据用户名和密码查询
        Example example = new Example(Reader.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("account",loginVo.getAccount())
                .andEqualTo("password",loginVo.getPassword());
        example.or().andEqualTo("email",loginVo.getAccount())
                .andEqualTo("password",loginVo.getPassword());
        List<Reader> readers = readerMapper.selectByExample(example);
        if(CollectionUtils.isEmpty(readers)){   //不存在该用户,账号或密码错误!
            throw new LyException(ExceptionEnum.LOGIN_ACCOUNT_OR_PASSWORD);
        }
        //获取数据库中的读者信息
        Reader reader = readers.get(0);
        //判断是否有自动登录
        if(loginVo.getAutoLogin()){ //有自动登录
            Integer day = bmProperties.getReaderAutoLoginDay()*60*24;
            String path = request.getContextPath()+"/pages/reader/";
            //根据 账户名
            Cookie cookie = new Cookie(bmProperties.getAutoCookieName(),reader.getAccount());
            //设置路径
            cookie.setPath(path);
            //bm/login/autoLogin
            //设置有效期
            cookie.setMaxAge(day);
            //设置用户端存储
            response.addCookie(cookie);
        }
        //将用户的登录信息保存到 session 中
        saveReaderToSession(request,reader);
            CookieUtils.deleteCookie(request,response, bmProperties.getAutoCookieName(),request.getContextPath()+ bmProperties.getCookiePath());   //用户端删除该cookie
            return false;
        }
        //将用户信息存入session中
        saveReaderToSession(request,readers.get(0));
        return true;
    }

    //将用户的信息保存到 session 中 并设置最后的登录时间
    private void saveReaderToSession(HttpServletRequest request,Reader reader){
        //将用户的登录信息保存到 session 中
        HttpSession session = request.getSession();
        session.setAttribute(bmProperties.getReaderSessionName(),reader);
    }
}

@Service
public class MailTemplateService {

    @Autowired
    private MailTemplateMapper templateMapper;

    @Autowired
    private BorrowBookMapper borrowBookMapper;

    @Autowired
    private ReaderMapper readerMapper;

    @Autowired
    private MailUtils mailUtils;

    @Autowired
        Reader reader = readerMapper.selectByPrimaryKey(rId);
        if(reader == null){ //用户不存在
            throw new LyException(ExceptionEnum.SERVICE_BUSY);
        }
        MailTemplate mailTemplate = null;
        //实际借书天数(现在的时间-租借的时间)
        int readyDay =  DateUtils.differenceDay(new Date(),borrowBook.getBbTime());
        //最大借书天数 = 应该还书的时间-租借的时间
        int maxDay = DateUtils.differenceDay(borrowBook.getDueTime(),borrowBook.getBbTime());
        //逾期天数 = 实际借书天数 - 最大借书天数
        int overDay = readyDay - maxDay;
        //用户是否逾期
        if(overDay <=0 ){ //还未逾期
            //查询未逾期模板
            mailTemplate = templateMapper.selectByPrimaryKey(1);
            borrowBook.setRemainingDays(maxDay-readyDay);
        }else{
            mailTemplate = templateMapper.selectByPrimaryKey(2);
            borrowBook.setRemainingDays(overDay);
        }

        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
        String url = basePath;

        String aDocument = "<a href=\""+url+"\">"+url+"</a>";
        //发送的邮箱内容
        String emailMsg = mailTemplate.getTemplate()
                .replace("{borrowBooksTime}",DateUtils.dateFormat("yyyy年MM月dd日",borrowBook.getBbTime()))
                .replace("{dueTime}",DateUtils.dateFormat("yyyy年MM月dd日",borrowBook.getDueTime()))
                .replace("{bookName}",borrowBook.getBName())
                .replace("{userName}",borrowBook.getRName())
                .replace("{remainingDay}",borrowBook.getRemainingDays()+"")
                .replace("{systemUrl}",aDocument);
        //发送邮箱提醒
        try {
            mailUtils.sendRemind(reader.getEmail(),emailMsg);
        } catch (MessagingException e) {    //发送邮箱还书提醒失败!
            e.printStackTrace();
            throw new LyException(ExceptionEnum.SEND_REMIND_FAIL);
        }
    }
}


@RequestMapping("/login")
@Controller
public class LoginController {

    @Autowired
    private LoginService loginService;

    //用户登录
    @PostMapping
    @ResponseBody
    public String login(@RequestBody LoginVo loginVo, HttpServletResponse response,
                                      HttpServletRequest request){
        String url = loginService.login(loginVo,response,request);
        return url;
    }

    //读者自动登录
    @GetMapping("/autoLogin")
    public String autoLoginReader(HttpServletResponse response,HttpServletRequest request){
        Boolean flag = loginService.autoLoginReader(response, request);
        String url = "";
        if(flag){   //登录成功
            url = "/pages/reader/bookDatalist.jsp";
        }else{  //登陆失败
            url = "/pages/login.jsp";
        }
        return "redirect:"+ url;
    }

            log.error("预约图书表修改剩余天数,失败");
            throw new LyException(ExceptionEnum.BOOK_GET_DOWN);
        }
        //查询图书是否存在
        Books books = bookMapper.selectByPrimaryKey(reserveBorrowBooks.getBId());
        if(books == null){
            throw new LyException(ExceptionEnum.BOOK_INFO_LOSE);
        }
        //修改图书数据
        if(remainingDays > 0){
            reserveBorrowBooks.setRemainingDays(remainingDays);
            //修改预约表中的数据
          reserveBookMapper.updateByPrimaryKey(reserveBorrowBooks);
        }
    }

    //读者 删除预定
    @Transactional
    public void deleteReserve(List<Integer> rbbIds) {
        for (Integer rbbId : rbbIds) {
            //根据id查询 预约图书表中的数据
            ReserveBorrowBooks reserveBorrowBooks = reserveBookMapper.selectByPrimaryKey(rbbId);
            if(reserveBorrowBooks == null){ //图书预定不存在,您的书籍已经成功领取!
                log.error("删除预定失败!");
                throw new LyException(ExceptionEnum.BOOK_GET_DOWN);
            }
            //查询图书信息
            Books books = bookMapper.selectByPrimaryKey(reserveBorrowBooks.getBId());
            if(books == null){  //判断是否存在
                throw new LyException(ExceptionEnum.BOOK_INFO_LOSE);
            }
            //删除数据
            reserveBookMapper.deleteByPrimaryKey(rbbId);
        }
    }
}

/**
 * 
    }

}

@RequestMapping("reader/giveBack")
@RestController
public class RGiveBackController {

    @Autowired
    private GiveBackBookService giveBackBookService;

    @Autowired
    private BMSystemProperties bmProperties;

    //分页查询 并可以带查询参数
    @GetMapping("/{page}/{size}")
    public ResponseEntity<Page<GiveBackBooks>> giveBackBook(@PathVariable("page") Integer page,
                                                            @PathVariable("size") Integer size,
                                                            GiveBackBooks reserveGiveBack,
                                                            HttpSession session){
        Reader reader = (Reader) session.getAttribute(bmProperties.getReaderSessionName());
        reserveGiveBack.setRName(reader.getRName());
        return ResponseEntity.ok(giveBackBookService.giveBackBook(page,size, reserveGiveBack,true));
    }

}

系统主要面向于大学校园网用户,依托校园网提供给这些用户一个发布和交流二手商品信息的平台。在大学校园里,存在着很多的二手商品,但是由于信息资源的不流通以及传统二手商品信息交流方式的笨拙,导致了很多仍然具有一定价值或者具有非常价值的二手商品的囤积,乃至被当作废弃物处理。现在通过校园网进入到本系统,可以方便快捷的发布和交流任何二手商品的信息,并且可以通过留言方式进行深一步的交流。由于每个大学的校园网都基本篇布校园的每一个地方,因此,只要宣传得当,理论上来说,每一个人都可以让他所发布的信息让全校所了解,争取到了信息资源的最大化利用。 系统完成的主要功能有:用户设置功能、发布信息功能、信息管理功能、搜索信息功能,留言功能,及系统管理功能,具体业务功能包括如下: 用户注册:学生可利用自已学号进行注册,注册实现实名制。 用户登录:只有登录用户才能进行信息发布。管理员登录后可以进行系统管理。 发布信息:普通用户和管理员登录后都可以发布信息。 修改信息:普通用户可以修改自己发布的信息,管理员可以修改所有信息。 删除信息:普通用户可以删除自己发布的信息,管理员可以删除所有信息。 浏览信息:游客、普通用户和管理员可以浏览所有发布的信息。 搜索信息:游客、普通用户和管理员可以用关键字搜索所有发布的信息。普通用户可以搜索自己发布的所有信息。 发表留言:普通用户和管理员登录后都可以对发布信息进行留言。 查看留言:游客、普通用户和管理员都可以查看发布信息的留言。 删除留言:管理员可以删除留言。 添加二手指南:管理员可以添加二手指南。 查看二手指南:游客、普通用户和管理员都可以查看二手指南。 修改二手指南:管理员可以修改二手指南。 删除二手指南:管理员可以删除二手指南。 3.1.2 系统界面要求 由于系统主要面向大学生,系统界面要求不能过古板,要能体现大学校园的自由,创新。系统界面设计应体现人性化,界面清晰简捷,操作简单流畅,提高管理效果。不需要任何专业培训,不需要配备专门的电脑操作人员,无电脑知识一样运用自如。关键在于系统的框架式设计简单明晰。 3.2 概要设计 3.2.1 系统体系结构设计 本系统是一个典型的三层应用——浏览器通过Web服务器实现对数据库的各种操作。图3-1 展示了整个系统的体系结构。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值