基于javaweb+mysql的ssm+maven在线点餐系统(java+ssm+jsp+mysql+maven+layui)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM+Maven在线点餐系统(java+ssm+jsp+mysql+maven+layui)
一、项目简述
功能包括: 前台实现:用户浏览菜单、菜品分类筛选、查看菜单详 情、添加购物车、购物车结算、会员券、个人订单查询等 等。 后台实现:餐系管理、菜品管理、订单管理、系统管理、 酉己备员管理等。 系统分为:高或管理员、顾客、厨师、配送员等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
*/
@Override
public Map<String, Object> addNumCountOne(Long shopcartId) {
Map<String, Object> map = new HashMap<>(16);
if (shopcartMapper.addNumCountOne(shopcartId) > 0) {
map.put(SystemConstant.FLAG, true);
}else {
map.put(SystemConstant.FLAG, false);
}
return map;
}
/**
* 减少该用户某个SKU菜品的数量
* @param shopcartId
* @return
*/
@Override
public Map<String, Object> reduceNumCountOne(Long shopcartId) {
Map<String, Object> map = new HashMap<>(16);
if (shopcartMapper.reduceNumCountOne(shopcartId) > 0) {
map.put(SystemConstant.FLAG, true);
}else {
map.put(SystemConstant.FLAG, false);
}
return map;
}
/**
* 删除购物车的某一个条目
* @param shopcartId
* @return
*/
@Override
public Map<String, Object> deleteShopcart(Long shopcartId) {
Map<String, Object> map = new HashMap<>(16);
if (shopcartMapper.deleteShopcart(shopcartId) > 0) {
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "该菜品条目已成功从您的购物车中删除");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "菜品条目从购物车中删除失败");
}
return map;
}
}
*/
@Override
public LayuiTableDataResult findUserListByPage(UserVo vo) {
//设置分页信息
PageHelper.startPage(vo.getPage(), vo.getLimit());
//调用分页查询的方法
List<UserEntity> userList = userMapper.findUserListByPage(vo);
//创建分页对象,将查询到的数据放进去
PageInfo<UserEntity> pageInfo = new PageInfo<>(userList);
//返回数据
return new LayuiTableDataResult(pageInfo.getTotal(), pageInfo.getList());
}
/**
* 后台添加用户
* @param vo
* @return
*/
@Override
public Map<String, Object> addUser(UserVo vo) {
//设置默认的用户初始密码
vo.setPassword(SystemConstant.DEFAULTPASSWORD);
Map<String, Object> map = new HashMap<>(16);
//获取影响行数
Long effectRow = userMapper.addUser(vo);
//获取用户Id,这个是在xml配置文件中配置的,也是mysql的方法,将新增的Id包装回原对象中
Long userId = vo.getUserId();
//添加用户的默认角色关系
if (userId!=null && userMapper.addUserAndRole(userId, SystemConstant.DEFAULTROLEID)>=1 && effectRow>=1) {
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "添加用户成功");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "添加用户失败");
}
return map;
}
/**
* 后台修改用户信息
* 跳转到菜品SPU管理界面
* @return
*/
@RequestMapping("/foodManage.html")
public String foodManage(){
return "food/foodManage";
}
/**
* 跳转到菜品SKU管理界面
* @return
*/
@RequestMapping("/foodSkuManage.html")
public String foodSkuManage(){
return "food/foodSkuManage";
}
/**
* 跳转到优惠券类别管理界面
* @return
*/
@RequestMapping("/ticketTypeManage.html")
public String ticketTypeManage() {
return "ticket/ticketTypeManage";
}
/**
* 跳转到优惠券领取记录管理界面
* @return
*/
@RequestMapping("/ticketManage.html")
public String ticketManage(){
return "ticket/ticketManage";
}
/**
* 跳转到订单分配管理界面
* @return
*/
@RequestMapping("/orderAllocationManage.html")
public String orderAllocationManage(){
return "order/orderAllocationManage";
}
/**
* 跳转到订单配送界面
* @return
return JSON.toJSONString(map);
}
}
/**
* 系统控制器,专门用于控制页面的跳转,负责跳转后台管理页面
*/
@Controller
@RequestMapping("/backstage")
public class BackstageController {
/**
* 跳转到用户管理界面
* @return
*/
@RequestMapping("/userManage.html")
public String userManage(){
return "user/userManage";
}
/**
* 跳转到角色管理界面
* @return
*/
@RequestMapping("/roleManage.html")
public String roleManage(){
return "role/roleManage";
}
/**
* 跳转到菜单管理界面
* @return
*/
@RequestMapping("/menuManage.html")
public String menuManage(){
return "menu/menuManage";
}
/**
* 跳转到配送员管理界面
* @return
*/
@RequestMapping("/deliverManage.html")
public String deliverManage(){
return "deliver/deliverManage";
}
/**
* 跳转到菜品类别管理界面
map.put(SystemConstant.MESSAGE, "优惠券领取成功");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "优惠券领取失败");
}
return map;
}
/**
* 根据页面信息查询优惠券领取记录
* @param vo
* @return
*/
@Override
public LayuiTableDataResult findTicketListByPage(TicketVo vo) {
//查询过期的优惠券,设置其状态为过期
List<Long> ticketOutTime = ticketMapper.findTicketIdListOutTime();
for (Long ticketId : ticketOutTime) {
ticketMapper.setOutTime(ticketId);
}
PageHelper.startPage(vo.getPage(), vo.getLimit());
List<TicketEntity> ticketListByPage = ticketMapper.findTicketListByPage(vo);
PageInfo<TicketEntity> pageInfo = new PageInfo<>(ticketListByPage);
return new LayuiTableDataResult(pageInfo.getTotal(), pageInfo.getList());
}
/**
* 将某张优惠券作废
* @param ticketId
* @return
*/
@Override
public Map<String, Object> invalid(Long ticketId) {
Map<String, Object> map = new HashMap<>(16);
if (ticketMapper.invalid(ticketId) > 0) {
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "优惠券已作废");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "优惠券作废失败");
}
return map;
}
/**
* 将某张优惠券复原
* @param ticketId
* @return
*/
@Override
public Map<String, Object> restore(Long ticketId) {
Map<String, Object> map = new HashMap<>(16);
if (ticketMapper.restore(ticketId) > 0) {
* @param ticketId
* @return
*/
@Override
public Map<String, Object> invalid(Long ticketId) {
Map<String, Object> map = new HashMap<>(16);
if (ticketMapper.invalid(ticketId) > 0) {
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "优惠券已作废");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "优惠券作废失败");
}
return map;
}
/**
* 将某张优惠券复原
* @param ticketId
* @return
*/
@Override
public Map<String, Object> restore(Long ticketId) {
Map<String, Object> map = new HashMap<>(16);
if (ticketMapper.restore(ticketId) > 0) {
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "优惠券已复原");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "优惠券复原失败");
}
return map;
}
/**
* 将某张优惠券积分返还
* @param ticketId
* @param session
* @return
*/
@Override
public Map<String, Object> returnScore(Long ticketId, HttpSession session) {
UserEntity user = (UserEntity) session.getAttribute(SystemConstant.USERLOGIN);
UserEntity user = (UserEntity) session.getAttribute(SystemConstant.USERLOGIN);
//判断用户的积分够不够领取
if (user.getScore() < ticketType.getNeedScore()){
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "很抱歉,您的积分不足以兑换该优惠券");
return map;
}
//如果剩余不足返回失败
if ((ticketType.getTicketNum()-ticketType.getReceive()) <= 0) {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "很抱歉,该优惠券被抢光啦");
return map;
}
//领取成功添加优惠券领取记录,扣除用户积分,优惠券类别已领取数+1
if (ticketMapper.addTicket(ticketTypeId, ticketType.getLiveTime(), user.getUserId())>0 &&
userMapper.modifyUserScore(-ticketType.getNeedScore(), user.getUserId())>0 &&
ticketTypeMapper.addReceiveOne(ticketTypeId)>0) {
user.setScore(user.getScore()-ticketType.getNeedScore());
session.setAttribute(SystemConstant.USERLOGIN, user);
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "优惠券领取成功");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "优惠券领取失败");
}
return map;
}
/**
* 根据页面信息查询优惠券领取记录
* @param vo
* @return
*/
@Override
public LayuiTableDataResult findTicketListByPage(TicketVo vo) {
//查询过期的优惠券,设置其状态为过期
List<Long> ticketOutTime = ticketMapper.findTicketIdListOutTime();
for (Long ticketId : ticketOutTime) {
ticketMapper.setOutTime(ticketId);
}
PageHelper.startPage(vo.getPage(), vo.getLimit());
List<TicketEntity> ticketListByPage = ticketMapper.findTicketListByPage(vo);
PageInfo<TicketEntity> pageInfo = new PageInfo<>(ticketListByPage);
return new LayuiTableDataResult(pageInfo.getTotal(), pageInfo.getList());
}
/**
* 将某张优惠券作废
* @param ticketId
* @return
*/
@Override
* 根据菜品类别编号查找对应的菜品
* @param typeId
* @return
*/
@RequestMapping("/findFoodByTypeId")
public String findFoodByTypeId(Long typeId) {
Map<String, Object> foodByTypeId = foodService.findFoodByTypeId(typeId);
return JSON.toJSONString(foodByTypeId);
}
}
/**
* 评论服务层实现类
*/
@Service
@Transactional
public class CommentServiceImpl implements CommentService {
public class FoodServiceImpl implements FoodService {
@Autowired
private FoodMapper foodMapper;
@Autowired
private FoodattrMapper foodattrMapper;
@Autowired
private FoodvalueMapper foodvalueMapper;
@Autowired
private FoodSkuMapper foodSkuMapper;
@Autowired
private FoodTypeMapper foodTypeMapper;
/**
* 根据页面条件查询菜品SPU信息列表
* @param vo
* @return
*/
@Override
public LayuiTableDataResult findFoodListByPage(FoodVo vo) {
PageHelper.startPage(vo.getPage(), vo.getLimit());
List<FoodEntity> foodListByPage = foodMapper.findFoodListByPage(vo);
PageInfo<FoodEntity> pageInfo = new PageInfo<>(foodListByPage);
return new LayuiTableDataResult(pageInfo.getTotal(), pageInfo.getList());
}
/**
* 菜品图片上传
* @param foodImage
* @return
*/
@Override
public Map<String, Object> uploadFile(MultipartFile foodImage) {
//用于存储LayUI文件上传所必须的键值
Map<String, Object> map = new HashMap<>(16);
//判断一下文件是否为空
if (!foodImage.isEmpty()) {
//将文件重命名
String newFileName = FileUploadUtil.rename(foodImage);
//全部文件都放在一个文件夹下不好管理,所以以日期作为文件夹进行管理
//组装路径
String finalPath = new SimpleDateFormat("yyyyMMdd").format(new Date()) + "/" + newFileName;
//获得文件对象,参数1:文件上传的路径,参数2:文件名称(包括文件夹)
File path = new File(SystemConstant.UPLOADPATH + SystemConstant.FOODPATH, finalPath);
if (!path.getParentFile().exists()) {
//如果文件夹不存在,就创建文件夹
path.getParentFile().mkdirs();
}
try {
//将文件保存到磁盘中
foodImage.transferTo(path);
/*
* 严格按照LayUI规定传递所必须的参数
/**
* 菜品图片上传
* @param foodImage
* @return
*/
@Override
public Map<String, Object> uploadFile(MultipartFile foodImage) {
//用于存储LayUI文件上传所必须的键值
Map<String, Object> map = new HashMap<>(16);
//判断一下文件是否为空
if (!foodImage.isEmpty()) {
//将文件重命名
String newFileName = FileUploadUtil.rename(foodImage);
//全部文件都放在一个文件夹下不好管理,所以以日期作为文件夹进行管理
//组装路径
String finalPath = new SimpleDateFormat("yyyyMMdd").format(new Date()) + "/" + newFileName;
//获得文件对象,参数1:文件上传的路径,参数2:文件名称(包括文件夹)
File path = new File(SystemConstant.UPLOADPATH + SystemConstant.FOODPATH, finalPath);
if (!path.getParentFile().exists()) {
//如果文件夹不存在,就创建文件夹
path.getParentFile().mkdirs();
}
try {
//将文件保存到磁盘中
foodImage.transferTo(path);
/*
* 严格按照LayUI规定传递所必须的参数
*/
map.put("code", 0);
map.put("msg", "文件上传成功");
Map<String, Object> dataMap = new HashMap<>(16);
//图片路径
dataMap.put("src", "/meal/upload/food/" + finalPath);
//鼠标悬停时显示的文本
dataMap.put("title", newFileName);
//保存图片路径,不包括前面的文件夹,从模块文件夹起始
dataMap.put("imagePath", SystemConstant.FOODPATH + finalPath);
map.put("data", dataMap);
} catch (IOException e) {
e.printStackTrace();
}
}
return map;
}
/**
* 添加菜品SPU信息
* @param vo
* @param foodParamList
* @param session
* @return
Map<String, Object> map = new HashMap<>(16);
Long userId = ((UserEntity) session.getAttribute(SystemConstant.USERLOGIN)).getUserId();
List<TicketEntity> ticketList = ticketMapper.findByUserUnuse(userId);
if (ticketList != null) {
map.put(SystemConstant.FLAG, true);
map.put("ticketList", ticketList);
}else {
map.put(SystemConstant.FLAG, false);
}
return map;
}
/**
* 根据优惠券编号查询优惠券
* @param ticketId
* @return
*/
@Override
public Map<String, Object> findTicketById(Long ticketId) {
Map<String, Object> map = new HashMap<>(16);
TicketEntity ticket = ticketMapper.findTicketById(ticketId);
map.put("ticket", ticket);
return map;
}
}
/**
* 菜品类别服务层实现类
@Override
public Map<String, Object> addMenu(MenuVo vo) {
Map<String, Object> map = new HashMap<>(16);
if (menuMapper.addMenu(vo) >= 1){
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "【" + vo.getTitle() + "】菜单新增成功");
} else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "【" + vo.getTitle() + "】菜单新增失败");
}
return map;
}
/**
* 修改菜单
* @param vo
* @return
*/
@Override
public Map<String, Object> modifyMenu(MenuVo vo) {
Map<String, Object> map = new HashMap<>(16);
//不可以父级菜单就是本身,直接返回修改错误
if (vo.getPid().equals(vo.getId())){
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "修改菜单失败,您不可以选择本身作为父级菜单");
return map;
}
if (menuMapper.modifyMenu(vo) >= 1){
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "【" + vo.getTitle() + "】菜单信息修改成功");
} else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "【" + vo.getTitle() + "】菜单信息修改失败");
}
return map;
}
/**
* 删除菜单
* @param menuId
* @return
*/
@Override
public Map<String, Object> deleteMenu(Integer menuId) {
Map<String, Object> map = new HashMap<>(16);
if (userMapper.modifyUserScore(rewardScore, user.getUserId()) <= 0){
throw new RuntimeException();
}
//5. 清空购物车
if (shopcartMapper.clearShopcart(order.getUserId()) <= 0){
throw new RuntimeException();
}
map1.put(SystemConstant.FLAG, true);
map1.put(SystemConstant.MESSAGE, "订单已生成");
map1.put("rewardScore", rewardScore);
}catch (RuntimeException e){
e.printStackTrace();
map1.put(SystemConstant.FLAG, false);
map1.put(SystemConstant.MESSAGE, "生成订单失败");
}
return map1;
}
/**
* 查找当前登录用户的所有订单
* @param session
* @return
*/
@Override
public List<Map<String, Object>> findOrderListByUserId(HttpSession session) {
List<Map<String, Object>> orderInfoList = new ArrayList<>();
Long userId = ((UserEntity) session.getAttribute(SystemConstant.USERLOGIN)).getUserId();
List<OrderEntity> orderList = orderMapper.findOrderListByUserId(userId);
for (OrderEntity order : orderList) {
Map<String, Object> orderInfoMap = new HashMap<>(16);
orderInfoMap.put("order", order);
List<OrderDetailEntity> orderDetailList = orderDetailMapper.findOrderDetailByOrderId(order.getOrderId());
orderInfoMap.put("orderDetailList", orderDetailList);
orderInfoList.add(orderInfoMap);
}
return orderInfoList;
}
/**
* 查询所有出餐中的订单,时间升序
* @param session
* @return
*/
@Override
public Map<String, Object> findByUserUnuse(HttpSession session) {
Map<String, Object> map = new HashMap<>(16);
Long userId = ((UserEntity) session.getAttribute(SystemConstant.USERLOGIN)).getUserId();
List<TicketEntity> ticketList = ticketMapper.findByUserUnuse(userId);
if (ticketList != null) {
map.put(SystemConstant.FLAG, true);
map.put("ticketList", ticketList);
}else {
map.put(SystemConstant.FLAG, false);
}
return map;
}
/**
* 根据优惠券编号查询优惠券
* @param ticketId
* @return
*/
@Override
public Map<String, Object> findTicketById(Long ticketId) {
Map<String, Object> map = new HashMap<>(16);
TicketEntity ticket = ticketMapper.findTicketById(ticketId);
map.put("ticket", ticket);
return map;
}
}
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "菜品添加到购物车失败");
}
}else {
if (shopcartMapper.addNumCount(record.getShopcartId(), numCount) > 0) {
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "购物车中该菜品数量修改成功!");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "菜品添加到购物车失败");
}
}
return map;
}
/**
* 查找该用户下的所有购物车信息
* @param session
* @return
*/
@Override
public Map<String, Object> findAllShopcartByUserId(HttpSession session) {
Map<String, Object> map = new HashMap<>(16);
Long userId = ((UserEntity) session.getAttribute(SystemConstant.USERLOGIN)).getUserId();
List<ShopcartEntity> shopcartByUserId = shopcartMapper.findAllShopcartByUserId(userId);
map.put("shopcart", shopcartByUserId);
return map;
}
/**
* 新增该用户某个SKU菜品的数量
* @param shopcartId
* @return
*/
@Override
public Map<String, Object> addNumCountOne(Long shopcartId) {
Map<String, Object> map = new HashMap<>(16);
if (shopcartMapper.addNumCountOne(shopcartId) > 0) {
map.put(SystemConstant.FLAG, true);
}else {
map.put(SystemConstant.FLAG, false);
}
return map;
}
/**
* 减少该用户某个SKU菜品的数量
* @param shopcartId
* @return
*/
@Override
public Map<String, Object> reduceNumCountOne(Long shopcartId) {
Map<String, Object> map = new HashMap<>(16);
return "complaint/complaintManage";
}
}
/**
* 菜品类别管理控制器
*/
@RestController
@RequestMapping("/backstage/foodtype")
public class FoodTypeManageController {
@Autowired
private FoodTypeService foodTypeService;
/**
* 根据页面返回信息查找符合条件的菜品类别集合
* @param vo
* @return
*/
@RequestMapping("/list")
public String findFoodTypeListByPage(FoodTypeVo vo){
LayuiTableDataResult foodTypeListByPage = foodTypeService.findFoodTypeListByPage(vo);
return JSON.toJSONString(foodTypeListByPage);
}
/**
* 菜品类别文件上传
* @param foodtypeImage
* @return
*/
* @return
*/
@Override
public Map<String, Object> modifyRole(RoleVo vo, HttpSession session) {
Map<String, Object> map = new HashMap<>(16);
String username = ((UserEntity) session.getAttribute(SystemConstant.USERLOGIN)).getUsername();
vo.setLastModifyBy(username);
if (roleMapper.modifyRole(vo) >= 1) {
map.put(SystemConstant.FLAG, true);
map.put(SystemConstant.MESSAGE, "角色【" + vo.getRoleName() + "】信息修改成功");
}else {
map.put(SystemConstant.FLAG, false);
map.put(SystemConstant.MESSAGE, "角色【" + vo.getRoleName() + "】信息修改失败");
}
return map;
}
/**
* 初始化该角色的菜单列表
* @param roleId
* @return
*/
@Override
public LayuiTableDataResult initRoleMenu(Long roleId) {
//调用查询所有菜单列表的方法,得到菜单的list集合
List<MenuEntity> menuList = menuMapper.findMenuList();
//查找该角色具有的菜单
List<MenuEntity> menuIdListByRoleId = menuMapper.findMenuIdListByRoleId(roleId);
//创建一个初始化的树节点集合
List<TreeNode> treeNodes = new ArrayList<>();
//遍历所有的菜单列表
for (MenuEntity menu : menuList) {
//判断一下是否需要展开
Boolean spread = (menu.getSpread() == null || menu.getSpread()==1) ? true : false;
TreeNode treeNode = new TreeNode(menu.getId(), menu.getPid(), menu.getTitle(), spread);
//遍历角色拥有的菜单列表
for (MenuEntity menu1 : menuIdListByRoleId) {
//判断当角色的菜单中
if (menu.getId().equals(menu1.getId())){
//如果拥有的菜单中存在,就修改状态为选中,状态码为1
treeNode.setCheckArr("1");
}
}
//将menu对象添加到集合中去
treeNodes.add(treeNode);
}
return new LayuiTableDataResult(treeNodes);
}
/**
* 对该角色的菜单权限进行授权
* @param menuIds
* @param roleId