package com.attjl.online_borrow.controller;
import com.attjl.online_borrow.LastTime;
import com.attjl.online_borrow.entity.Book;
import com.attjl.online_borrow.entity.Borrow;
import com.attjl.online_borrow.entity.DeliveryInfo;
import com.attjl.online_borrow.entity.User;
import com.attjl.online_borrow.repository.BookRepository;
import com.attjl.online_borrow.repository.BorrowRepository;
import com.attjl.online_borrow.repository.DeliveryInfoRepository;
import com.attjl.online_borrow.repository.UserRepository;
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 javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Controller
public class BorrowController {
@Autowired
BookRepository bookRepository;
@Autowired
UserRepository userRepository;
@Autowired
BorrowRepository borrowRepository;
@Autowired
DeliveryInfoRepository deliveryInfoRepository;
@ResponseBody
@PostMapping("/Submit_orders/submit") //下单处理 active:找到配送信息, id:为图书主键, quantity:购买数量
public String Transact(HttpSession session, @RequestParam("active")
Integer active,@RequestParam("id") Integer id,@RequestParam("quantity") Integer quantity)
{
Date date=new Date();
User user=(User)session.getAttribute("loginUser"); //获取登陆者信息,强制转换为User类型
Book book=bookRepository.findById(id);
if(book.getStock()>=quantity){
Borrow borrow=new Borrow(); //必须在此创建一个新的对象,不能引入一个borrow对象,不然插入数据会变成更新数据
borrow.setNumbering(book.getNumbering());
borrow.setQuantity(quantity);
borrow.setUsername(user.getUsername());
borrow.setType(1);
borrow.setLibraryType(1);
borrow.setSerialNumber(active);
borrow.setTime(date);
book.setStock(book.getStock()-quantity);//库存自减借阅数量
book.setBw_amount(book.getBw_amount()+quantity); //借阅量自加借阅数量
bookRepository.save(book);
borrowRepository.save(borrow);
return "订单提交成功!";
}
else
return "对不起,该书库存为"+book.getStock()+",您不能借阅"+quantity+"本";
}
@RequestMapping("/my_page")
public String showDelivering(Model model,HttpSession session){
User user=(User)session.getAttribute("loginUser");
List<Borrow> borrows= borrowRepository.findDelivering(user.getUsername(),1);
if(!borrows.isEmpty()){
List<Book> books=new ArrayList<>();
for(Borrow borrow:borrows){
books.add(bookRepository.findNumbering(borrow.getNumbering()));
}
model.addAttribute("books",books);
model.addAttribute("borrows",borrows);
return "my_page";
}
else
return "my_page";
}
@ResponseBody
@PostMapping("/cancelOrder") //取消订单
public void cancelOrder(@RequestParam("index") Integer i,HttpSession session){
User user=(User)session.getAttribute("loginUser");
Borrow borrow=borrowRepository.findDelivering(user.getUsername(),1).get(i);
borrow.setType(0);
borrowRepository.save(borrow);
}
@ResponseBody
@PostMapping("/arrived") //用户确认书本送达
public void arrived(HttpSession session,@RequestParam("index") Integer i){
User user=(User)session.getAttribute("loginUser");
Borrow borrow= borrowRepository.findDelivering(user.getUsername(),1).get(i);
borrow.setType(2); //借阅的图书进入借阅未归还状态
borrowRepository.save(borrow);
}
@ResponseBody
@PostMapping("/returnBook") //用户确认归还图书
public void returnBook(HttpSession session,@RequestParam("index") Integer i){
Date date=new Date(); //获取当前系统的时间
User user=(User)session.getAttribute("loginUser");
Borrow borrow= borrowRepository.findDelivering(user.getUsername(),2).get(i);
borrow.setType(3); //归还借阅的图书,发出还书申请后的借阅状态
borrow.setReturnTime(date);
Long allTime= borrow.getReturnTime().getTime()-borrow.getTime().getTime(); //用户总共借阅的时长
borrow.setBorrowedTime(LastTime.calculatingTime(allTime));//以天、时、分、秒的形式记录总借阅时长
borrowRepository.save(borrow);
}
@RequestMapping("/my_finished") //用户借阅未归还
public String borrowFinished(HttpSession session,Model model){
Date date=new Date(); //获取当前系统时间
User user=(User)session.getAttribute("loginUser");
List<Borrow> borrows2=borrowRepository.findDelivering(user.getUsername(),2);//借阅中未归还
List<Book> books=new ArrayList<>();
for(Borrow borrow2:borrows2){
Book book= bookRepository.findNumbering(borrow2.getNumbering()); //通过ISBN找到指定图书信息
books.add(book);
}
for(Integer i=0;i<books.size();i++){
Long millisecond= (books.get(i).getMax_day())*24*60*60*1000L; //最大借阅时间(毫秒)
Long m=millisecond-(date.getTime()-borrows2.get(i).getTime().getTime()); //计算剩余借阅时间
borrows2.get(i).setLastTime(LastTime.calculatingTime(m));//通过静态方法calculatingTime将毫秒转换为天、时、分、秒的格式
}
Double[] totalPrices=new Double[books.size()];
for(Integer i=0;i<books.size();i++){
totalPrices[i]=books.get(i).getPrice()*borrows2.get(i).getQuantity(); //计算每本书的总价
}
model.addAttribute("books",books);
model.addAttribute("borrows2",borrows2);
model.addAttribute("totalPrices",totalPrices);
return "my_finished";
}
@RequestMapping("/history") //用户历史书单
public String borrowHistory(HttpSession session,Model model){
User user=(User)session.getAttribute("loginUser");
List<Borrow> borrows3=borrowRepository.findDelivering(user.getUsername(),4);//已还的书籍
List<Book> books=new ArrayList<>();
for(Borrow borrow3:borrows3){
Book book= bookRepository.findNumbering(borrow3.getNumbering()); //通过ISBN找到指定图书信息
books.add(book);
}
Double[] totalPrices=new Double[books.size()];
for(Integer i=0;i<books.size();i++){
totalPrices[i]=books.get(i).getPrice()*borrows3.get(i).getQuantity(); //计算每本书的总价
}
model.addAttribute("books",books);
model.addAttribute("borrows3",borrows3);
model.addAttribute("totalPrices",totalPrices);
return "history";
}
@RequestMapping("/library") //图书馆用户主页
public String immediateDelivery(HttpSession session,Model model){
User user=(User)session.getAttribute("loginUser");
List<DeliveryInfo> libDeliveries=deliveryInfoRepository.findByUsername(user.getUsername());
if(!libDeliveries.isEmpty()) {
DeliveryInfo libDelivery = libDeliveries.get(0);
model.addAttribute("lib_delivery",libDelivery);//图书馆信息
}
List<Book> bks=bookRepository.findByUsername(user.getUsername());//找到指定图书馆的所有图书信息
Integer total=0;
for(Book b :bks){
total=total+b.getBw_amount(); //图书馆总借阅量
}
List<Borrow> firstBorrows=borrowRepository.findByLibraryType(1); //所有需要配送的信息
没有合适的资源?快使用搜索试试~ 我知道了~
基于springboot+JPA+MySQL的网上借阅系统前端及后台,前端.zip
共223个文件
jpg:96个
js:24个
html:23个
需积分: 5 0 下载量 193 浏览量
2023-07-30
23:10:47
上传
评论
收藏 12.76MB ZIP 举报
温馨提示
基于java、jsp、servlet、mysql、springboot等技术构建的系统,适合毕设项目、课设作业。资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。
资源推荐
资源详情
资源评论
收起资源包目录
基于springboot+JPA+MySQL的网上借阅系统前端及后台,前端.zip (223个子文件)
mvnw.cmd 6KB
HomePage.css 7KB
shop_trading.css 3KB
library.css 3KB
Categories.css 2KB
Submit_orders.css 2KB
my_page.css 2KB
lib_history.css 2KB
lib_finished.css 2KB
ReturnApplication.css 2KB
my_finished.css 2KB
my_cart.css 2KB
history.css 2KB
book_list.css 1KB
address_list.css 1KB
new_bklist.css 1KB
bookInfoChange.css 1KB
completed.css 939B
transacting.css 863B
lib_information.css 748B
password_change.css 732B
personal_inform.css 731B
lib_pwd.css 616B
ship_address.css 556B
.gitignore 303B
HomePage.html 16KB
library.html 4KB
shop_trading.html 4KB
bookInfoChange.html 4KB
book_list.html 4KB
Categories.html 3KB
my_page.html 3KB
my_cart.html 2KB
new_bklist.html 2KB
lib_history.html 2KB
lib_finished.html 2KB
ReturnApplication.html 2KB
Submit_orders.html 2KB
my_finished.html 2KB
history.html 2KB
address_list.html 2KB
ship_address.html 1KB
personal_inform.html 1KB
lib_information.html 1KB
Untitled-sousuo.html 1KB
password_change.html 1KB
lib_pwd.html 1KB
foot.html 440B
maven-wrapper.jar 47KB
BorrowController.java 18KB
BookController.java 13KB
MavenWrapperDownloader.java 5KB
UserController.java 4KB
BookRepository.java 4KB
DeliveryInfoController.java 3KB
Borrow.java 3KB
ShopCartController.java 3KB
MyMvcViewController.java 2KB
Book.java 2KB
UserTypeHandler.java 1KB
UserType2Handler.java 1KB
User.java 1KB
LoginHandler.java 1KB
DeliveryInfo.java 1KB
UserRepository.java 954B
BorrowRepository.java 815B
DeliveryInfoRepository.java 773B
ShopCart.java 712B
LastTime.java 351B
OnlineBorrowApplicationTests.java 346B
OnlineBorrowApplication.java 327B
ShopCartRepository.java 313B
book66.jpeg 406KB
book64.jpg 1.18MB
book65.jpg 1.05MB
book79.jpg 889KB
book31.jpg 852KB
1.jpg 512KB
book53.jpg 307KB
book33.jpg 305KB
book36.jpg 269KB
book76.jpg 258KB
book44.jpg 254KB
book82.jpg 233KB
book81.jpg 195KB
book34.jpg 190KB
book19.jpg 188KB
book75.jpg 185KB
book61.jpg 176KB
book56.jpg 175KB
book30.jpg 174KB
book28.jpg 162KB
book54.jpg 158KB
book49.jpg 153KB
book83.jpg 152KB
book59.jpg 143KB
book12.jpg 136KB
2.jpg 136KB
book17.jpg 135KB
book35.jpg 122KB
共 223 条
- 1
- 2
- 3
资源评论
独处东汉
- 粉丝: 741
- 资源: 820
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功