<file_sep>package com.hqyj.dinner.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;


/**
 * <p> 分页<p>
 *
 * @Author : long
 * @Date : 2020-10-26 14:24
 **/
@Data
public class Page {
    //页码
//    @Transient
    @TableField(exist = false)
    private Integer page;
    //每页显示的行数
//    @Transient
    @TableField(exist = false)
    private Integer rows;
}
<file_sep>package com.hqyj.dinner.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.dinner.entity.OrderDetail;
import com.hqyj.dinner.entity.Tables;
import com.hqyj.dinner.service.OrderDetailService;
import com.hqyj.dinner.service.TablesService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Controller
@RequestMapping("orderDetail")
public class OrderDetailController {
    @Resource
    OrderDetailService orderDetailService;

    @Resource
    private TablesService tablesService;

    @RequestMapping("/orderTable")
    public String orderTable() {
        return "order_manage/orderTable";
    }

    @RequestMapping("orderPage")
    public String orderPage() {
        return "order_manage/order_display";
    }

    //预定一个餐桌
    @RequestMapping("/order")
    @ResponseBody
    public HashMap<String, Object> order(Tables tables) {
        HashMap<String, Object> map = new HashMap<>();
        QueryWrapper<Tables> queryWrapper = new QueryWrapper<>();
        tables.setStatus(0);
        queryWrapper.eq("id", tables.getId());
        if (tablesService.update(tables, queryWrapper)) {
            map.put("info", "预定成功");
        } else {
            map.put("info", "预定失败");
        }
        return map;
    }

    //翻台
    @RequestMapping("/cancel")
    @ResponseBody
    public HashMap<String, Object> cancel(Tables tables) {
        HashMap<String, Object> map = new HashMap<>();
        QueryWrapper<Tables> queryWrapper = new QueryWrapper<>();
        tables.setStatus(1);
        queryWrapper.eq("id", tables.getId());
        if (tablesService.update(tables, queryWrapper)) {
            map.put("info", "翻台成功");
        } else {
            map.put("info", "翻台失败");
        }
        return map;
    }

    //订餐按钮
    @RequestMapping("/orderDinner")
    @ResponseBody
    public Map<String, Integer> orderDinner(Tables tables) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("tableId", tables.getId());
        map.put("tableStatus", tables.getStatus());
        return map;
    }

    //去到点菜页面
    @RequestMapping("/menu/{tableId}&{tableStatus}")
    public ModelAndView menu(@PathVariable("tableId") Integer tableId, @PathVariable("tableStatus") Integer tableStatus, ModelAndView mv) {
        Tables tables = new Tables();
        tables.setId(tableId);
        tables.setStatus(tableStatus);
        System.out.println(tables + "****************");
/*        HashMap<String,Object> map = new HashMap<>();
        map.put("tables",tables);*/
        mv.addObject("tables", tables);
        mv.setViewName("order_manage/menu");
        return mv;
    }

    //添加一个菜
    @RequestMapping("/addCar")
    @ResponseBody
    public HashMap<String, Object> addCar(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();

        QueryWrapper<OrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("table_id", orderDetail.getTableId());
        queryWrapper.eq("food_id", orderDetail.getFoodId());
        queryWrapper.eq("status", 0);
        if (orderDetailService.getOne(queryWrapper) != null) {
            UpdateWrapper<OrderDetail> updateWrapper = new UpdateWrapper<>();
            updateWrapper.set("food_count", orderDetail.getFoodCount());
            boolean update = orderDetailService.update(orderDetail, queryWrapper);
            if (update) {
                map.put("info", "加入成功");
            } else {
                map.put("info", "加入失败");
            }
            return map;
        }
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String orderNo = dateFormat.format(date);
        System.out.println(orderDetail.getTableId() + "++++++++++++++++++++++++++++++++++++");
        orderDetail.setStatus(0);//0是没下单
        orderDetail.setPay(0);//0没付钱
        orderDetail.setOrderNo(orderNo);

        int i = orderDetailService.add(orderDetail);
        if (i > 0) {
            map.put("info", "加入成功");
        } else {
            map.put("info", "加入失败");
        }
        return map;
    }

    //取消加入的菜
    @RequestMapping("/cancel2")
    @ResponseBody
    public HashMap<String, Object> cancel(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();
        int result = orderDetailService.delete(orderDetail);
        if (result > 0) {
            map.put("info", "取消成功");
        } else {
            map.put("info", "取消失败");
        }
        return map;
    }

    //下单
    @RequestMapping("/confirm")
    @ResponseBody
    public HashMap<String, Object> confirm(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();
        List<OrderDetail> orderDetailList = orderDetailService.select(orderDetail);
        UpdateWrapper<OrderDetail> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("status", 1);
        if (orderDetailList != null) {
            for (OrderDetail orderDetail2 : orderDetailList) {
                orderDetail2.setStatus(1);
                orderDetailService.update(updateWrapper);
            }
            map.put("data", orderDetailList);
            map.put("info", "下单成功");
            return map;
        }
        map.put("info", "下单失败！如有疑问请询问服务员！");
        return map;

    }

    //详情及结算
    @RequestMapping("/search/{tableId}")
    public ModelAndView eachTableOrder(@PathVariable("tableId") Integer tableId, ModelAndView modelAndView) {
        OrderDetail orderDetail = new OrderDetail();
        orderDetail.setTableId(tableId);
        modelAndView.addObject("orderDetail", orderDetail);
        modelAndView.setViewName("order_manage/eachTableOrder");
        return modelAndView;
    }

    //查看点的菜
    @RequestMapping("/findOrder")
    @ResponseBody
    public HashMap<String, Object> findOrder(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();
        List<OrderDetail> orderDetailList = orderDetailService.selectTableOrder(orderDetail.getTableId());
        map.put("data", orderDetailList);
        return map;
    }

    //计算价格
    @RequestMapping("/count")
    @ResponseBody
    public HashMap<String, Object> count(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();
        double pay = 0.0;
//        double pay2 = 0.0;

        List<OrderDetail> orderDetailList = orderDetailService.selectTableOrder(orderDetail.getTableId());
        for (OrderDetail detail : orderDetailList) {
            Double price = detail.getPrice();
            Integer num = detail.getFoodCount();
            pay = price * num + pay;
            //System.out.println(pay);
        }
        /*for (OrderDetail detail : orderDetailList) {
            Double price = detail.getVipPrice();
            Integer num = detail.getFoodCount();
            pay2 = price * num + pay2;
            //System.out.println(pay);
        }*/
        map.put("data", pay);
//        map.put("data2", pay2);
        return map;
    }

    //付钱
    @RequestMapping("/pay")
    @ResponseBody
    public HashMap<String, Object> pay(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();
        UpdateWrapper<OrderDetail> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("pay", 1);
        //找到对应餐桌且上了菜的
        List<OrderDetail> orderDetailList = orderDetailService.selectNotPay(orderDetail.getTableId());
        if (orderDetailList.size() != 0) {
            for (OrderDetail detail : orderDetailList) {

                orderDetailService.update(detail);
            }
            map.put("data", "支付成功");

            return map;
        }
        map.put("data", "订单尚未完成");
        return map;
    }

    //商家出菜页面
    @RequestMapping("/chucai")
    public String chucai() {
        return "order_manage/chucai";
    }

    @RequestMapping("/cai")
    @ResponseBody
    public HashMap<String, Object> cai(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();
        List<OrderDetail> orderDetailList = orderDetailService.selectNotMake(orderDetail);
        map.put("data", orderDetailList);
        return map;
    }

    @RequestMapping("/make")
    @ResponseBody
    public HashMap<String, Object> make(OrderDetail orderDetail) {
        HashMap<String, Object> map = new HashMap<>();
        //找出数据
        List<OrderDetail> one = orderDetailService.selectOntMakeFood(orderDetail);
        if (one.size() >= 1) {
            //修改数据
            int update = orderDetailService.update2(orderDetail);
            if (update > 0) {
                map.put("info", "成功");
                return map;
            }
            map.put("info", "操作失败！");
            return map;
        }
        map.put("info", "操作失败！");
        return map;
    }

    @ResponseBody
    @RequestMapping("findAllOrder")
    public HashMap<String, Object> findAllOrder(OrderDetail order) {
        HashMap<String, Object> map = new HashMap<>();
        PageHelper.startPage(order.getPage(), order.getRows());
        List<OrderDetail> orderDetails = orderDetailService.findAll();
        PageInfo<OrderDetail> pageInfo = new PageInfo<>(orderDetails);
        map.put("total", pageInfo.getTotal());
        map.put("pages", pageInfo.getPages());
        map.put("endPage", pageInfo.getNavigateLastPage());
        map.put("curPage", order.getPage());
        map.put("data", pageInfo.getList());
        return map;
    }

    @ResponseBody
    @RequestMapping("del")
    public HashMap<String, Object> del(OrderDetail order) {
        HashMap<String, Object> map = new HashMap<>();
        final boolean result = orderDetailService.removeById(order.getId());
        if (result) {
            map.put("info", "删除成功");
        } else {
            map.put("info", "删除失败");
        }
        return map;
    }
}
<file_sep>package com.hqyj.dinner.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class FoodType extends Page implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 菜系ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 菜系名称
     */
    private String typeName;

    /**
     * 状态，0：下架  1：上架
     */
    private Integer status;


}
<file_sep>package com.hqyj.dinner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hqyj.dinner.entity.OrderDetail;
import com.hqyj.dinner.mapper.OrderDetailMapper;
import com.hqyj.dinner.service.OrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {

    @Resource
    OrderDetailMapper orderDetailMapper;

    @Override
    public List<OrderDetail> findAll() {
        return orderDetailMapper.selectList(null);
    }

    @Override
    public int add(OrderDetail orderDetail) {
        return orderDetailMapper.insert(orderDetail);
    }

    @Override
    public int delete(OrderDetail orderDetail) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("food_id",orderDetail.getFoodId());
        return orderDetailMapper.delete(wrapper);
    }

    @Override
    public int update(OrderDetail orderDetail) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("status",2);
        wrapper.eq("table_id",orderDetail.getTableId());
        orderDetail.setPay(1);
        return orderDetailMapper.update(orderDetail,wrapper);
    }

    @Override
    public List<OrderDetail> select(OrderDetail orderDetail) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("table_id",orderDetail.getTableId());
        wrapper.eq("status",0);
        return orderDetailMapper.selectList(wrapper);
    }

    @Override
    public List<OrderDetail> selectTableOrder(Integer tableId) {
        QueryWrapper<OrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("table_id",tableId);
        queryWrapper.in("status",1,2);
        queryWrapper.eq("pay",0);
        return orderDetailMapper.selectList(queryWrapper);
    }

    @Override
    public List<OrderDetail> selectNotPay(Integer tableId) {
        QueryWrapper<OrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("table_id",tableId);
        queryWrapper.eq("status",2);
        queryWrapper.eq("pay",0);
        return orderDetailMapper.selectList(queryWrapper);
    }

    @Override
    public List<OrderDetail> selectNotMake(OrderDetail orderDetail) {
        QueryWrapper<OrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",1);
        queryWrapper.eq("pay",0);
        return orderDetailMapper.selectList(queryWrapper);
    }

    @Override
    public List<OrderDetail> selectOntMakeFood(OrderDetail orderDetail) {
        QueryWrapper<OrderDetail> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("food_id",orderDetail.getFoodId());
        queryWrapper.eq("status",1);
        queryWrapper.eq("pay",0);
        return orderDetailMapper.selectList(queryWrapper);
    }

    @Override
    public int update2(OrderDetail orderDetail) {
        UpdateWrapper<OrderDetail> updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",orderDetail.getId());
        updateWrapper.set("status",2);
        return orderDetailMapper.update(orderDetail,updateWrapper);
    }


}
<file_sep>package com.hqyj.dinner.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.dinner.entity.Food;
import com.hqyj.dinner.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
public interface UserMapper extends BaseMapper<User> {
    List<String> selectRole(String userName);

}
<file_sep>package com.hqyj.dinner.controller;


import com.hqyj.dinner.entity.FoodType;
import com.hqyj.dinner.service.FoodTypeService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@RestController
@RequestMapping("foodType")
public class FoodTypeController {
    @Resource
    FoodTypeService foodTypeService;
    @RequestMapping("/findAll")
    public HashMap<String,Object> findAll(){
        List<FoodType> foodTypeList = foodTypeService.findAll();
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",foodTypeList);
        return map;
    }
    @RequestMapping("/add")
    public HashMap<String,Object> add(FoodType foodType) {
        HashMap<String,Object> map = new HashMap<>();
        int result = foodTypeService.add(foodType);
        if(result>0) {
          map.put("info","新增成功");
          return map;
        }else {
            map.put("info","新增失败");
            return map;
        }
    }
    @RequestMapping("/update")
    public HashMap<String,Object> update(FoodType foodType) {
        HashMap<String, Object> map = new HashMap<>();
        int result = foodTypeService.update(foodType);
        if(result>0) {
            map.put("info","修改成功");
            return map;
        }else {
            map.put("info","修改失败");
            return map;
        }
    }
    @RequestMapping("/del")
    public HashMap<String,Object> del(FoodType foodType) {
        HashMap<String, Object> map = new HashMap<>();
        int result = foodTypeService.delete(foodType);
        if(result>0) {
            map.put("info","删除成功");
            return map;
        }else {
            map.put("info","删除失败");
            return map;
        }
    }
    @RequestMapping("/select")
    public HashMap<String,Object> select(FoodType foodType){
        HashMap<String, Object> map = new HashMap<>();
        List<FoodType> foodTypeList = foodTypeService.select(foodType);
        map.put("data",foodTypeList);
        return map;
    }

}
<file_sep>package com.hqyj.dinner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqyj.dinner.entity.FoodType;
import com.hqyj.dinner.mapper.FoodTypeMapper;
import com.hqyj.dinner.service.FoodTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Service
public class FoodTypeServiceImpl extends ServiceImpl<FoodTypeMapper, FoodType> implements FoodTypeService {

    @Resource
    FoodTypeMapper foodTypeMapper;
    @Override
    public List<FoodType> findAll() {
        return foodTypeMapper.selectList(null);
    }

    @Override
    public int add(FoodType foodType) {
        return foodTypeMapper.insert(foodType);
    }

    @Override
    public int update(FoodType foodType) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",foodType.getId());
        return foodTypeMapper.update(foodType,queryWrapper);
    }

    @Override
    public int delete(FoodType foodType) {
        QueryWrapper<FoodType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",foodType.getId());
        return foodTypeMapper.delete(queryWrapper);
    }

    @Override
    public List<FoodType> select(FoodType foodType) {
        QueryWrapper<FoodType> queryWrapper = new QueryWrapper<>();
        if(foodType.getId()!=null){
            queryWrapper.eq("id",foodType.getId());
        }
        if(foodType.getTypeName()!=null){
            queryWrapper.like("type_name",foodType.getTypeName());
        }
        return foodTypeMapper.selectList(queryWrapper);
    }
}
<file_sep>package com.hqyj.dinner.controller;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

/**
 * Program: dinner
 * Description:
 * Author: Luo
 * Date: 2020-10-23 19:49
 */
@SpringBootTest
class FoodControllerTest {

    @Autowired
    FoodController foodController;

    @Test
    void test(){
        final HashMap<String, Object> map = foodController.queryMenuFood(1, 5);
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            System.out.println(entry.getKey()+":"+entry.getValue());
        }
    }

}<file_sep>package com.hqyj.dinner.service;

import com.hqyj.dinner.entity.OrderDetail;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
public interface OrderDetailService extends IService<OrderDetail> {

    List<OrderDetail> findAll();

    int add(OrderDetail  orderDetail );

    int delete(OrderDetail  orderDetail);

    int update(OrderDetail  orderDetail);

    List<OrderDetail> select(OrderDetail  orderDetail);

    List<OrderDetail> selectTableOrder(Integer tableId);

    List<OrderDetail> selectNotPay(Integer tableId);

    List<OrderDetail> selectNotMake(OrderDetail orderDetail);

    List<OrderDetail> selectOntMakeFood(OrderDetail orderDetail);

    int update2(OrderDetail orderDetail);
}
<file_sep>package com.hqyj.dinner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hqyj.dinner.entity.Role;
import com.hqyj.dinner.entity.User;
import com.hqyj.dinner.mapper.RoleMapper;
import com.hqyj.dinner.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Role> queryAllRole() {
        return roleMapper.selectList(null);
    }

    @Override
    public int add(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int delete(Role role) {
        UpdateWrapper<Role> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",role.getId());
        wrapper.set("status",0);
        return roleMapper.update(role,wrapper);
    }

    @Override
    public List<Role> select(Role role) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        if (role.getId()!=null){
            queryWrapper.eq("id",role.getId());
        }
        if (!role.getRoleName().isEmpty()){
            queryWrapper.like("role_name",role.getRoleName());
        }
        if (role.getStatus()!=null){
            queryWrapper.eq("status",role.getStatus());
        }
        return roleMapper.selectList(queryWrapper);
    }

    @Override
    public int modify(Role role) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",role.getId());
        return roleMapper.update(role,queryWrapper);
    }
}
<file_sep>package com.hqyj.dinner.shrio;

import com.hqyj.dinner.entity.User;
import com.hqyj.dinner.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Program: dinner
 * Description: Realm授权、认证
 * Author: Luo
 * Date: 2020-10-20 00:20
 */
public class MyAuthorizingRealm extends AuthorizingRealm {

    @Autowired
    private UserService userService;

    /**
     * 授权
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        //获取当前登录的用户信息
        Subject subject = SecurityUtils.getSubject();
        String userName = (String) subject.getPrincipal();

        //根据用户名查询用户拥有的权限或者角色
        List<String> list = userService.selectRole(userName);
        //创建shiro授权对象
        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
        //给用户赋予角色
        simpleAuthorizationInfo.addRoles(list);
        return simpleAuthorizationInfo;
    }

    /**
     * 认证
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        //获取登录用户的凭证
        UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
        //获取用户名
        String userName = (String) token.getPrincipal();
        //查询数据库,获取用户对象
        User user_db = userService.selectUserByUserName(userName);
        //判断用户是否存在
        if (user_db != null) {
            //创建用户凭证 ，这个对象会把数据库查询出来的用户信息和登录的用户信息进行比对
            return new SimpleAuthenticationInfo(userName, user_db.getPwd(), new Md5Hash(userName), this.getName());
        }
        return null;
    }
}
<file_sep>package com.hqyj.dinner.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;

import java.beans.Transient;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class Food extends Page implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 菜品ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 菜品名称
     */
    private String foodName;
    /**
     * 菜品名称
     */
    @TableField(exist = false)
    private String typeName;

    /**
     * 菜系id
     */
    private Integer typeId;

    /**
     * 价格
     */
    private Double price;

    /**
     * vip价格
     */
    private Double vipPrice;

    /**
     * 菜品图片url
     */
    private String imgUrl;

    /**
     * 菜品描述
     */
    private String description;

    /**
     * 状态，0：下架，1：上架
     */
    private Integer status;

    /**
     * 备用
     */
    private String zhanWei;


}
<file_sep>package com.hqyj.dinner.util;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.stereotype.Component;

/**
 * md5 密码加密工具类
 */
@Component
public class MdFive {
    /**
     *
     * @param password 密码
     * @param saltValue 盐值
     * @return  md5加密后的密码
     */
	public String encrypt(String password,String saltValue){
	    //创建MD5算法对象
        Object salt = new Md5Hash(saltValue);
        //SimpleHash(算法名称,要加密的密码,盐值,加密次数)
        Object result = new SimpleHash("MD5", password, salt, 1024);
        return result.toString();
	}

}
<file_sep>package com.hqyj.dinner.mapper;

import com.hqyj.dinner.entity.UserRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
public interface UserRoleMapper extends BaseMapper<UserRole> {

}
<file_sep>package com.hqyj.dinner.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.dinner.entity.Tables;
import com.hqyj.dinner.entity.User;
import com.hqyj.dinner.entity.Role;
import com.hqyj.dinner.entity.User;
import com.hqyj.dinner.service.RoleService;
import com.hqyj.dinner.service.UserService;
import com.hqyj.dinner.util.MdFive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @Autowired
    MdFive mdFive;

    /**
     * 进入用户管理
     */
    @RequestMapping("/userPage")
    public String userPage() {
        return "sys_manage/user";
    }

    /**
     * 查询所有用户
     */
    @ResponseBody
    @RequestMapping("queryAllUser")
    public HashMap<String, Object> queryAllUser(User user) {
        HashMap<String, Object> map = new HashMap<>();
        //1 设置分页参数：页码和条数
        PageHelper.startPage(user.getPage(), user.getRows());
        //2 查询结果集合
        List<User> userList = userService.queryAllUser();
        // 3 创建分页对象
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        List<User> listResult = pageInfo.getList();
        map.put("total", pageInfo.getTotal());
        map.put("pages", pageInfo.getPages());
        map.put("endPage", pageInfo.getNavigateLastPage());
        map.put("curPage", user.getPage());
        map.put("data", listResult);
        return map;
    }


    @RequestMapping("/add")
    @ResponseBody
    public HashMap<String, Object> add(User user) {
        HashMap<String, Object> map = new HashMap<>();
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", user.getUserName());
        final List<User> userList = userService.list(wrapper);
        if (user.getUserName().isEmpty() || user.getPwd().isEmpty()) {
            map.put("info", "用户名和密码不能为空！");
        } else if (userList.isEmpty()) {
            user.setPwd(<PASSWORD>.<PASSWORD>(user.getPwd(), user.getUserName()));
            int result = userService.add(user);
            if (result > 0) {
                map.put("info", "新增成功");
            } else {
                map.put("info", "新增失败！");
            }
        } else {
            map.put("info", "用户已存在！");
        }
        return map;
    }

    @RequestMapping("/update")
    @ResponseBody
    public HashMap<String, Object> update(User user) {
        HashMap<String, Object> map = new HashMap<>();
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", user.getUserName());
        User user_db = userService.getOne(wrapper);
        String userPwd = user.getPwd();
        if (user.getUserName().isEmpty() || user.getPwd().isEmpty()) {
            map.put("info", "用户名和密码不能为空！");
        } else if (user_db != null) {
            if (userPwd.equals(user_db.getPwd())) {
                int result = userService.modify(user);
                if (result > 0) {
                    map.put("info", "修改成功");
                } else {
                    map.put("info", "修改失败！");
                }
            } else {
                user.setPwd(mdFive.encrypt(userPwd, user.getUserName()));
                int result = userService.modify(user);
                if (result > 0) {
                    map.put("info", "修改成功");
                } else {
                    map.put("info", "修改失败！");
                }
            }
        }else {
            user.setPwd(mdFive.encrypt(userPwd, user.getUserName()));
            int result = userService.modify(user);
            if (result > 0) {
                map.put("info", "修改成功");
            } else {
                map.put("info", "修改失败！");
            }
        }
        return map;
    }

    @RequestMapping("/del")
    @ResponseBody
    public HashMap<String, Object> del(User user) {
        HashMap<String, Object> map = new HashMap<>();
        int result = userService.delete(user);
        if (result > 0) {
            map.put("info", "删除成功");
        } else {
            map.put("info", "删除失败");
        }
        return map;
    }

    @RequestMapping("/select")
    @ResponseBody
    public HashMap<String, Object> select(User user) {
        HashMap<String, Object> map = new HashMap<>();
        if (user.getUserName().isEmpty() && user.getName().isEmpty() &&
                user.getStatus() == null && user.getRoleId() == null &&
                user.getTelNum().isEmpty()) {
            map.put("info", "请输入信息以查询");
        } else {
            //1 设置分页参数：页码和条数
            PageHelper.startPage(user.getPage(), user.getRows());
            //2 查询结果集合
            List<User> userList = userService.select(user);
            // 3 创建分页对象
            PageInfo<User> pageInfo = new PageInfo<>(userList);
            map.put("total", pageInfo.getTotal());
            map.put("pages", pageInfo.getPages());
            map.put("endPage", pageInfo.getNavigateLastPage());
            map.put("curPage", user.getPage());
            if (pageInfo.getList().isEmpty()) {
                map.put("info", "没有此条记录，请添加！");
            } else {
                map.put("data", pageInfo.getList());
                map.put("info", "查询成功");
            }
        }
        return map;
    }

    @ResponseBody
    @RequestMapping("/fpRole")
    public HashMap<String, Object> fpRole(User user) {
        HashMap<String, Object> map = new HashMap<>();
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", user.getId());
        wrapper.set("role_id", user.getRoleId());
        if (userService.update(wrapper)) {
            map.put("info", "分配成功");
        } else {
            map.put("info", "分配失败");
        }
        return map;
    }

    @RequestMapping("/backUser")
    @ResponseBody
    public HashMap<String, Object> backUser(User user) {
        HashMap<String, Object> map = new HashMap<>();
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", user.getId());
        wrapper.set("status", 1);
        if (userService.update(wrapper)) {
            map.put("info", "恢复成功");
        } else {
            map.put("info", "恢复失败！");
        }
        return map;
    }
}
<file_sep>package com.hqyj.dinner.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class OrderDetail extends Page implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 订单详情ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 订单编号
     */
    private String orderNo;

    /**
     * 所属订单ID
     */
    //private Integer orderId;

    /**
     * 菜名ID
     */
    private Integer foodId;

    /**
     * 订餐数量
     */
    private Integer foodCount;

    /**
     * 状态，0：删除，1：正常
     */
    private Integer tableId;

    private Integer status;

    private Double vipPrice;

    private Double price;

    /**
     * 备用
     */
    private Integer pay;


}
<file_sep>package com.hqyj.dinner.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.dinner.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
public interface UserService extends IService<User> {


    User selectUserByUserName(String userName);

    List<User> queryAllUser();

    int add(User user);

    int modify(User user);

    int delete(User user);

    List<User> select(User user);

    List<String> selectRole(String userName);
}
<file_sep>package com.hqyj.dinner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hqyj.dinner.entity.Food;
import com.hqyj.dinner.entity.Tables;
import com.hqyj.dinner.entity.User;
import com.hqyj.dinner.mapper.RoleMapper;
import com.hqyj.dinner.mapper.UserMapper;
import com.hqyj.dinner.mapper.UserRoleMapper;
import com.hqyj.dinner.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.dinner.util.MdFive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Luo
 * @since 2020-10-19
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public User selectUserByUserName(String userName) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name",userName);
        return userMapper.selectOne(wrapper);
    }


    @Override
    public List<User> queryAllUser() {
        return userMapper.selectList(null);
    }
//增
    @Override
    public int add(User user) {
        return userMapper.insert(user);
    }
//改
    @Override
    public int modify(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",user.getId());
        return userMapper.update(user,queryWrapper);
    }
//删
    @Override
    public int delete(User user) {
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",user.getId());
        wrapper.set("status",0);
        return userMapper.update(user,wrapper);
    }
//查
    @Override
    public List<User> select(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if (!user.getUserName().isEmpty()) {
            queryWrapper.like("user_name", user.getUserName());
        }
        if (!user.getName().isEmpty()) {
            queryWrapper.like("name", user.getName());
        }
        if (user.getStatus() != null) {
            queryWrapper.eq("status", user.getStatus());
        }
        if (user.getRoleId() != null) {
            queryWrapper.eq("role_id", user.getRoleId());
        }
        if (!user.getTelNum().isEmpty()) {
            queryWrapper.like("tel_num", user.getTelNum());
        }
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public List<String> selectRole(String userName) {
        return userMapper.selectRole(userName);
    }
}
