基于javaweb的智能餐厅管理系统(java+ssm+jsp+bootstrap+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的智能餐厅管理系统(java+SSM+jsp+bootstrap+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.数据库:MySql 5.7版本; 6.是否Maven项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+bootstrap
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/DiningRoom 登录 服务员账号/密码: 20144206169/123456 厨师账号/密码:20144206170/123456 经理账号/密码:20144206171/123456 收银账号/密码:20144206172/123456
用户管理控制层:
@Controller
public class TbUserController {
@Resource
TbUserServiceImpl tbUserService;
@GetMapping(“/toLogin”)
public String toLogin(){
return “user/login”;
@PostMapping(“/register”)
public String register(String uUsername, String uPassword, String uRole,Model model){
List users = tbUserService.selectAllUser();
for (TbUser temp : users){ //验证成功,直接登录
if(uUsername.equals(temp.getUUsername())){
model.addAttribute(“msg”,“刚刚:注册失败,该用户已存在!”);
return “user/login”;
TbUser user = new TbUser();
user.setUUsername(uUsername);
user.setUPassword(uPassword);
user.setURole(uRole);
tbUserService.insertUser(user);
model.addAttribute(“msg”,“刚刚:注册成功,赶快登录进行登录吧~”);
return “user/login”;
/插入用户数据,返回字符串信息/
@ResponseBody
@RequestMapping(“/insertUserInfo”)
public String insertUserInfo(String uUsername, String uPassword, String uRole){
//查询是否存在用户名了
String msg = “未知错误!”;
List users = tbUserService.selectUserByName(uUsername);
if(users.size() == 0){
TbUser user = new TbUser();
user.setUUsername(uUsername);
user.setUPassword(uPassword);
user.setURole(uRole); //字符串转化为int
int i = tbUserService.insertUser(user);
if(i != 0){
msg = “新添用户成功!”;
}else {
msg = “该用户名已存在,插入失败!”;
return msg;
/编辑用户信息,返回字符串信息/
@ResponseBody
@RequestMapping(“/edUserInfo”)
public String edUserInfo(TbUser user){
tbUserService.updateUserByUser(user);
return “用户数据已更新!”;
/跳转用户信息页面 + 分页/
@RequestMapping(“/userInfo”) //从1开始
public String userInfo(Model model,@RequestParam(value = “pageNum”,defaultValue = “1”)Integer pageNum){
List users = tbUserService.selectAllUser();
Page page = new Page<>(pageNum,5);
tbUserService.selectPage(page);
model.addAttribute(“users”,users);
model.addAttribute(“page”,page);
return “user/userInfo”;
/删除用户/
@RequestMapping(“/deleteUser/{uId}”)
public String deleteUser(@PathVariable(“uId”)int uId, Model model){
tbUserService.deleteUserById(uId);
model.addAttribute(“msg”,“删除成功!”);
return “redirect:/userInfo”;
@GetMapping(“/myInfo”)
public String myInfo(Principal principal,Model model){
String str = principal.getName();
List list = tbUserService.selectAllUser();
for(TbUser tbUser:list) {
if(tbUser.getUUsername().equals(str)){
model.addAttribute(“Member”,tbUser.getMember());
return “user/myInfo”;
/上传头像/
@RequestMapping(“/updateMyImg”)
public String updateMyImg(@RequestParam(value = “updateHeadImg”) MultipartFile updateHeadImg,
int uId, Model model, HttpSession session){
String imgPath = FileUpload.uploadFile(updateHeadImg);
//更新操作
TbUser user = tbUserService.selectUserById(uId);
user.setUUrl(imgPath);
tbUserService.updateUserByUser(user);
user = tbUserService.selectUserById(uId);
UpdateSession.reloadUserAuthority(session,user);
return “redirect:/myInfo”;
/更新我的信息/
@RequestMapping(“/updateMyInfo”)
public String updateMyInfo(TbUser user, HttpSession session){
//更新操作
TbUser tbUser = tbUserService.selectUserById(user.getUId()); //保存新数据,避免被原数据覆盖
System.out.println("tbUser = " + tbUser);
user.setUUsername(tbUser.getUUsername());
user.setUPassword(tbUser.getPassword());
user.setUMoney(tbUser.getUMoney());
tbUserService.updateUserByUser(user);
user = tbUserService.selectUserById(user.getUId());
UpdateSession.reloadUserAuthority(session,user);
return “redirect:/myInfo”;
@RequestMapping(“/shenqinghuiyuan”)
public String shenqinghuiyuan(Integer uId, HttpSession session,Model model){
//更新操作
//保存新数据,避免被原数据覆盖
TbUser tbUser = tbUserService.selectUserById(uId);
if(tbUser.getUMoney()>200){
tbUserService.updateMeber(uId);
model.addAttribute(“Member”,2);
model.addAttribute(“error”,“申请成功,请重新登录后方可生效”);
}else{
model.addAttribute(“error”,“未满足条件”);
model.addAttribute(“Member”,1);
return “user/myInfo”;
// @GetMapping(“/outLogin”)
// public String outLogin(HttpSession session){
// session.removeAttribute(“user”);
// return “user/login”;
// }
// @PostMapping(“/login”) 添加了安全策略不在需要手动验证,只需要提供个请求路径
// public void login(String uUsername, String uPassword, Model model, HttpSession session){
// List users = tbUserService.selectAllUser();
// for (TbUser temp : users){ //验证成功,直接登录
// if(uUsername.equals(temp.getUUsername()) && uPassword.equals(temp.getUPassword())){
// session.setAttribute(“user”,temp);
// return “redirect:/”;
// }
// if(uUsername.equals(temp.getUUsername()) && !uPassword.equals(temp.getUPassword())){
// model.addAttribute(“msg”,“刚刚:密码错误,登录失败!”);
// return “user/login”;
// }
// }
// model.addAttribute(“msg”,“刚刚:该用户不存在,请重新输入!”);
// return “user/login”;
// }
订单管理控制层:
@Controller
public class OrderDetailController {
@Resource
OrderDetailServiceImpl orderDetailService;
@Resource
ShoppingCartServiceImpl shoppingCartService;
@Resource
MenuDetailServiceImpl menuDetailService;
@Resource
TbUserServiceImpl tbUserService;
//修改订单状态,从0到1,由商家更新
@ResponseBody
@RequestMapping(“/changeStatusToOne”)
public String changeStatusToOne(int odId){
OrderDetail one = orderDetailService.selectOneByOdId(odId);
one.setOdStatus(1);
orderDetailService.updateOrder(one); //更新订单
return “已接单,尽快送餐吧~”;
//修改订单状态,从1到2,由用户更新
@ResponseBody
@RequestMapping(“/changeStatusToTwo”)
public String changeStatusToTwo(int odId){
OrderDetail one = orderDetailService.selectOneByOdId(odId);
one.setOdStatus(2);
orderDetailService.updateOrder(one); //更新订单
//同时更新商家的账户
TbUser adminUser = tbUserService.selectUserById(1);
int updateMoney = one.getOdTotal()+adminUser.getUMoney();
adminUser.setUMoney(updateMoney);
tbUserService.updateUserByUser(adminUser);
return “您已确认送达,钱已入商家商户,订单已完结~”;
@RequestMapping(“/orderManage”)
public String orderManage(Model model,@RequestParam(value = “pageNum”,defaultValue = “1”)Integer pageNum){
List orders = orderDetailService.selectAll();
Collections.reverse(orders); //倒叙
Page page = new Page<>(pageNum,10);
orderDetailService.selectPage(page); //分页
int allCount = orders.size(); //总数
int pendingCount = 0; //待处理单数
int receivedCount = 0; //待已接单数
int finishCount = 0; //已完结
for (OrderDetail order : orders){
if(order.getOdStatus() == 0){
pendingCount += 1;
}else if(order.getOdStatus() == 1){
receivedCount += 1;
}else{
finishCount += 1;
TbUser adminUser = tbUserService.selectUserById(1);
model.addAttribute(“total”,adminUser.getUMoney());
model.addAttribute(“page”,page);
model.addAttribute(“orders”,orders);
model.addAttribute(“allCount”,allCount);
model.addAttribute(“pendingCount”,pendingCount);
model.addAttribute(“receivedCount”,receivedCount);
model.addAttribute(“finishCount”,finishCount);
return “menu/orderManage”;
@RequestMapping(“/myOrder”)
public String myOrder(Model model,int uId){
List myOrders = orderDetailService.selectAllOrderByUId(uId);
TbUser user = tbUserService.selectUserById(uId);
model.addAttribute(“myOrders”,myOrders);
model.addAttribute(“total”,user.getUMoney());
return “user/myOrder”;
@ResponseBody
@PostMapping(“/toOrder”)
public String toOrder(OrderDetail orderDetail){
TbUser user = tbUserService.selectUserById(orderDetail.getUId());
//查询当前用户的所以购物车
List carts = shoppingCartService.selectAllByUId(orderDetail.getUId());
//获取到具体商品
String odDetail = “【”;
int odTotal = 0;
for (ShoppingCart cart : carts){
odDetail += cart.getScName()+" × “+cart.getScAmount()+”;"; //拼接成:米饭 × 1;格式
odTotal += cart.getScPrice()*cart.getScAmount(); //数量×价格
odDetail += “】”;
//赋值
orderDetail.setOdDetail(odDetail);
if(user.getMember()==2){
orderDetail.setOdTotal((int)(odTotal * 0.88));
}else{
orderDetail.setOdTotal(odTotal);
orderDetail.setOdStatus(0);
orderDetail.setOdNo(RandomNo.getRandomNo());
//完成插入
orderDetailService.insertOrder(orderDetail);
//清空购物车 + 更新商品数据
for (ShoppingCart cart : carts){
shoppingCartService.deleteById(cart.getScId()); //删除购物车数据
MenuDetail menuDetail = menuDetailService.selectById(cart.getMdId()); //通过产品id获得产品
menuDetail.setMdAmount(menuDetail.getMdAmount()-cart.getScAmount()); //减去下单数量
menuDetailService.updateMenu(menuDetail); //更新产品数据
TbUser User= tbUserService.selectUserById(orderDetail.getUId()); //用户更新支付金额
System.out.println(odTotal+“=============”);
System.out.println(user.getMember()+“=====”+odTotal);
if(user.getMember()==1 && odTotal>200) {//当会员为1时,说明不是会员,并且支付的金额大于200
user.setMember(2);
System.out.println(“进入方法后”+user.getMember());
user.setUMoney(user.getUMoney()+odTotal);
System.out.println(user.getMember());
tbUserService.updateUserByUser(user);
List details = orderDetailService.selectAllOrderByUId(orderDetail.getUId());
for (OrderDetail detail : details){
System.out.println("detail = " + detail.getOdCreateTime());
return “下单成功~”;
购物车管理控制层:
@Controller
public class ShoppingCartController {
@Resource
ShoppingCartServiceImpl shoppingCartService;
@Resource
TbUserServiceImpl tbUserService;
/去我的购物车页面/
@RequestMapping(“/shoppingCart”)
public String shoppingCart(Model model,int uId){
//查询购物车的商品
List products = shoppingCartService.selectAllByUId(uId);
int total = 0;
for (ShoppingCart cart : products){
total += cart.getScPrice()*cart.getScAmount();
model.addAttribute(“products”,products);
model.addAttribute(“total”,total);
TbUser tbUser = tbUserService.selectUserById(uId);
if(tbUser.getMember()==2){
int youhuitotal =(int) (total* 0.88);
model.addAttribute(“youhuitotal”,youhuitotal);
model.addAttribute(“Member”,tbUser.getMember());
return “user/shoppingCart”;
@RequestMapping(“/shoppingCart-plus”)
public String shoppingCartPlus(int uId,int mdId){
//把数量+1
ShoppingCart one = shoppingCartService.selectOneByMdIdAndUId(mdId, uId);
one.setScAmount(one.getScAmount()+1);
shoppingCartService.updateProduct(one);
System.out.println(“数量+1成功”);
return “redirect:/shoppingCart?uId=”+uId;
@RequestMapping(“/shoppingCart-minus”)
public String shoppingCartMinus(int uId,int mdId){
/如果 数量== 1,直接删除/
ShoppingCart one = shoppingCartService.selectOneByMdIdAndUId(mdId, uId);
if (one.getScAmount() == 1 ) {
//删除数据
shoppingCartService.deleteById(one.getScId());
return “redirect:/shoppingCart?uId=”+uId;
}else{
//数量-1
one.setScAmount(one.getScAmount()-1);
shoppingCartService.updateProduct(one);
System.out.println(“数量-1成功”);
return “redirect:/shoppingCart?uId=”+uId;
@ResponseBody
@RequestMapping(“/addShoppingCart”)
public String addShoppingCart(ShoppingCart shoppingCart){
//插入一条数据
if (shoppingCartService.selectExist(shoppingCart.getMdId(), shoppingCart.getUId()) == 0 ) {
shoppingCartService.insertProduct(shoppingCart);
return “新加入成功!”;
}else{
/如果已经存在了,直接加一/
ShoppingCart one = shoppingCartService.selectOneByMdIdAndUId(shoppingCart.getMdId(), shoppingCart.getUId());
one.setScAmount(one.getScAmount()+1);
shoppingCartService.updateProduct(one);
return “数量加+1成功!”;