package com.dev.books.controller;
import com.alibaba.fastjson.JSON;
import com.dev.books.pojo.Book;
import com.dev.books.pojo.StoreIn;
import com.dev.books.pojo.StoreOut;
import com.dev.books.pojo.User;
import com.dev.books.service.BookService;
import com.dev.books.service.StoreInService;
import com.dev.books.service.StoreOutService;
import com.dev.books.service.UserService;
import com.dev.books.util.Layui;
import com.dev.books.util.RandNum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;
@Controller
public class StoreOutController {
@Autowired
StoreOutService storeOutService;
@Autowired
StoreInService storeInService;
@Autowired
BookService bookService;
@Autowired
UserService userService;
@ResponseBody
@RequestMapping(value = "/inserTeachertReceiveBook")
public String addReceiveBook(@RequestBody Map dataMap, HttpServletRequest request) {
System.out.println(dataMap);
String book_id = dataMap.get("book_id").toString();
String book_out = dataMap.get("book_out").toString();
String storeInId = dataMap.get("id").toString();
String id = RandNum.getGUID();
/*
要先登录,才有getId
*/
HttpSession session = request.getSession(true);//新建session对象
User user = (User) session.getAttribute("user"); //将对应数据存入session中
StoreOut storeOut = new StoreOut(id,book_id,user.getId(),Integer.parseInt(book_out));
System.out.println("storeOut:"+storeOut);
/*
使用fastjson把类转换成json,有两个好处,
1.需要map类型传参数
2.fastjson能够格式化时间类型
*/
String storeInJson = JSON.toJSONString(storeOut);
Map map = JSON.parseObject(storeInJson, Map.class);
System.out.println(map);
List<StoreOut> storeOuts = storeOutService.findStooByUidAndBid(user.getId(),book_id);
if(storeOuts.size()>0){
return "cannot receve";
}else {
int n = storeOutService.addReceiveBook(map);
if (n > 0) {
StoreIn storeIn = storeInService.findStoreInById(storeInId);
int init_book_count = storeIn.getBook_count();//原来库存
int current_book_count = init_book_count-Integer.parseInt(book_out);//现在库存=原来库存-已经领走库存
storeInService.updateBookCount(current_book_count,storeInId);
return "success";
}
return "failure";
}
}
@ResponseBody
@RequestMapping(value = "/getStoreOutByUserId",produces="application/json;charset=UTF-8")
public String getStoreOutByUserId(@RequestParam("limit") String limit, @RequestParam("page") String page, HttpServletRequest request) {
List<StoreOut> list = new ArrayList<>();
String uid="";
HttpSession session = request.getSession(true);//新建session对象
User user = (User) session.getAttribute("user"); //将对应数据存入session中
User u = null;
if(user.getIdentification().equals("学生")){
u = userService.findTeacherByUserId(user.getId());
uid = u.getT_id();
}else if(user.getIdentification().equals("教师")){
uid = user.getId();
}
List<StoreOut> storeOuts = storeOutService.findStoreOutByUserId(uid);
for(int i=0;i<storeOuts.size();i++){
StoreOut s = storeOuts.get(i);
int total_add = s.getBook_out();
int total_sub = s.getBook_back();
int total = total_add - total_sub;
s.setTotal(total);
list.add(s);
}
Layui l = Layui.data(list.size(), list);
return JSON.toJSONString(l);
}
@ResponseBody
@RequestMapping(value = "/getStuStoreOutByUserId",produces="application/json;charset=UTF-8")
public String getStuStoreOutByUserId(@RequestParam("limit") String limit, @RequestParam("page") String page, HttpServletRequest request) {
List<StoreOut> list = new ArrayList<>();
HttpSession session = request.getSession(true);//新建session对象
User user = (User) session.getAttribute("user"); //将对应数据存入session中
List<StoreOut> storeOuts = storeOutService.findStoreOutByUserId(user.getId());
for(int i=0;i<storeOuts.size();i++){
StoreOut s = storeOuts.get(i);
int total_add = s.getBook_out();
int total_sub = s.getBook_back();
int total = total_add - total_sub;
s.setTotal(total);
list.add(s);
}
Layui l = Layui.data(list.size(), list);
System.out.println(list);
return JSON.toJSONString(l);
}
@ResponseBody
@RequestMapping(value = "/inserStutReceiveBook")
public String inserStutReceiveBook(@RequestBody Map dataMap, HttpServletRequest request) {
System.out.println(dataMap);
//String book_id = dataMap.get("book_id").toString();
String book_out = dataMap.get("book_out").toString();
String book_id = dataMap.get("id").toString();
String id = RandNum.getGUID();
/*
要先登录,才有getId
*/
HttpSession session = request.getSession(true);//新建session对象
User user = (User) session.getAttribute("user"); //将对应数据存入session中
StoreOut storeOut = new StoreOut(id,book_id,user.getId(),Integer.parseInt(book_out));
System.out.println("storeOut:"+storeOut);
User u = userService.findTeacherByUserId(user.getId());
/*
使用fastjson把类转换成json,有两个好处,
1.需要map类型传参数
2.fastjson能够格式化时间类型
*/
String storeInJson = JSON.toJSONString(storeOut);
Map map = JSON.parseObject(storeInJson, Map.class);
System.out.println(map);
System.out.println("book_id:"+book_id);
List<StoreOut> sto = storeOutService.findStooByUidAndBid(user.getId(),book_id);
if(sto.size()>0){
return "cannot receve";
}else{
int n = storeOutService.addReceiveBook(map);
if (n > 0) {
String tid = u.getT_id();
List<StoreOut> storeOuts = storeOutService.findStoreOutByUserId(tid);//查询教师id号
//StoreIn storeIn = storeInService.findStoreInById(storeInId);
int init_book_count = storeOuts.get(0).getBook_out();//原来教师库存
int current_book_count = init_book_count-Integer.parseInt(book_out);//现在库存=原来库存-已经领走库存
storeOutService.updateTeacherBookOut(current_book_count,book_id,tid);
//storeInService.updateBookCount(current_book_count,storeInId);
return "success";
}
return "failure";
}
}
@ResponseBody
@RequestMapping(value = "/delete_updateTeachertStore")
public String delete_updateTeachertStore(@RequestBody Map dataMap, HttpServletRequest request) {
System.out.println(dataMap);
System.out.println("----教师退书-------");
String book_id = dataMap.get("book_id").toString();
String book_num = dataMap.get("book_num").toString();
String isAll = dataMap.get("isAll").toString();
Htt
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
一、项目简述 功能包括: 管理员可以增删改查教材、教材商、入库教材、用户(用 户包括学生和教师)可以对教材商、教材进行。xcel的导入 导出操作。教U阿以领取入库的教材,可以退还教材。学 生只能在对应的教师那里领取教材,并且可以退还教材、 查询自己已经领取的教材。并且对已领教材付款等等。 二、项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
资源推荐
资源详情
资源评论
收起资源包目录
Java项目:教材管理系统(java+SSM+jsp+mysql+maven) (379个子文件)
$PRODUCT_WORKSPACE_FILE$ 1KB
StoreOutController.class 9KB
UserController.class 8KB
POIUtil.class 8KB
StoreInController.class 7KB
BookController.class 6KB
SupplierController.class 5KB
StoreOut.class 5KB
StoreIn.class 4KB
User.class 4KB
PaymentsController.class 4KB
ExcelExportMyStylerImpl.class 3KB
Payments.class 3KB
CommonController.class 3KB
UserServiceImpl.class 3KB
Book.class 2KB
StoreInServiceImpl.class 2KB
BookServiceImpl.class 2KB
StoreOutServiceImpl.class 2KB
Supplier.class 2KB
MyTool.class 2KB
SwaggerConfig.class 2KB
SupplierServiceImpl.class 2KB
ProfessionController.class 1KB
CollegeController.class 1KB
CclassController.class 1KB
GradeController.class 1KB
PaymentsServiceImpl.class 1KB
Profession.class 1KB
College.class 1KB
Cclass.class 1KB
Grade.class 1KB
UserMapper.class 1KB
UserService.class 1KB
Layui.class 948B
BookMapper.class 935B
RandNum.class 922B
StoreInMapper.class 876B
StoreOutMapper.class 860B
BookService.class 860B
ProfessionServiceImpl.class 848B
CollegeServiceImpl.class 821B
CclassServiceImpl.class 812B
GradeServiceImpl.class 803B
StoreInService.class 801B
StoreOutService.class 785B
SuppliersMapper.class 633B
SupplierService.class 556B
PaymentsMapper.class 529B
PaymentsService.class 454B
ProfessionMapper.class 335B
CollegeMapper.class 323B
CclassMapper.class 319B
GradeMapper.class 315B
ProfessionService.class 260B
CollegeService.class 248B
CclassService.class 244B
GradeService.class 240B
.classpath 1KB
org.eclipse.wst.common.component 656B
bootstrap.css 134KB
layui.css 59KB
screen.css 48KB
print.css 46KB
global.css 17KB
layer.css 14KB
xadmin.css 10KB
layui.mobile.css 10KB
laydate.css 7KB
style.css 5KB
login.css 4KB
personal.css 3KB
reset.css 1KB
code.css 1KB
font.css 505B
typography.css 452B
iconfont.eot 48KB
iconfont.eot 40KB
adminthemes-webfont.eot 6KB
59.gif 10KB
22.gif 10KB
throbber.gif 9KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
共 379 条
- 1
- 2
- 3
- 4
资源评论
- zzkj1112022-07-14资源内容详尽,对我有使用价值,谢谢资源主的分享。
beyondwild
- 粉丝: 9858
- 资源: 4910
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功