基于javaweb+mysql的ssm+maven酒店管理系统(java+ssm+jsp+mysql+maven)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven酒店管理系统(java+ssm+jsp+mysql+maven)
主要技术:java springmvc mybatis mysql tomcat js jauery jsp log4j等一些常见基本技术适用于Java毕设和学习使用
主要实现: 前台:登录、注册、酒店信息浏览、搜索酒店信息、查看房间、预定房间、等
后台:部门管理、房间管理、楼层管理、订单管理、入住管理、营业额报表、承担控制权限、员工管理、角色管理、预定报表等
主要功能截图如下: 前端登陆注册和一些基本信息查看等
* @return
*/
@RequestMapping("/getHotelYearCharts")
public String getHotelYearCharts(){
//创建Map集合保存数据
Map<String,Object> dataMap = new HashMap<String,Object>();
//调用统计每个年度营业总额的方法
List<Map> mapList = chartsService.getTotalPriceByYear();
//创建两个List集合,分别保存年份及对应的营业额
List<String> keyList = new ArrayList<String>();//年份
List<Double> valueList = new ArrayList<Double>();//营业额
//循环遍历每年营业额集合
for (Map map : mapList) {
keyList.add(map.get("years").toString());//年份
valueList.add(Double.valueOf(map.get("totalPrice").toString()));//金额
}
dataMap.put("keyList",keyList);
dataMap.put("valueList",valueList);
//将Map集合以JSON格式返回
return JSON.toJSONString(dataMap);
}
/**
* 统计月营业额报表
* @param year
* @return
*/
@RequestMapping("/getHotelYearOfMonthCharts")
public String getHotelYearOfMonthCharts(String year){
//调用查询每年每月营业额的方法
List<Double> list = chartsService.getTotalPriceByYearOfMonth(year);
//循环遍历数据
for (int i = 0; i < list.size(); i++) {
//判断当前月份是否有数据,如果没有数据则以0代替
if(list.get(i)==null){
list.set(i,0D);
}
}
//将集合以JSON格式返回
return JSON.toJSONString(list);
}
/**
* 统计季度营业额报表
* @param year
* @return
*/
@RequestMapping("/getHotelQuarterCharts")
public String getHotelQuarterCharts(String year){
Map<String,Object> map = new HashMap<String,Object>();
//调用根据指定的年份查询季度营业额报表的方法
List<Map> listMap = chartsService.getQuarterTotalPriceByYear(year);
return JSON.toJSONString(map);
}
}
/**
* HP - the login name of the current user.
* 20:27 - the current system time.
*/
@Controller
public class IndexController {
@Resource
private RoomTypeService roomTypeService;
@Resource
private FloorService floorService;
@Resource
private RoomService roomService;
@RequestMapping("/index.html")
public String index(Model model){
//调用查询房型列表的方法
List<RoomType> roomTypeList = roomTypeService.findRoomTypeList(null);
//调用查询所有楼层列表的方法
List<Floor> floorList = floorService.findFloorList(null);
//调用查询每个楼层的房间列表
List<Room> roomList = roomService.findRoomListByFloorId();
//将数据放到模型中
model.addAttribute("roomTypeList",roomTypeList);
model.addAttribute("floorList",floorList);
model.addAttribute("roomList",roomList);
return "forward:/home.jsp";
}
}
/**
* 分配菜单
* @param ids
* @param roleId
* @return
*/
@RequestMapping("/saveRoleMenu")
public String saveRoleMenu(String ids,Integer roleId){
Map<String,Object> map = new HashMap<String,Object>();
//调用保存角色菜单关系的方法
if(roleService.saveRoleMenu(ids,roleId)>0){
map.put(SystemConstant.MESSAGE,"菜单分配成功");
}else{
map.put(SystemConstant.MESSAGE,"菜单分配失败");
}
return JSON.toJSONString(map);
}
/**
* 查询角色列表通过员工ID
* @param id
* @return
*/
@RequestMapping("/initRoleListByEmpId")
public DataGridViewResult initRoleListByEmpId(int id){
List<Map<String, Object>> roleList = roleService.findRoleListByMap();
//调用根据员工ID查询该员工拥有的角色列表的方法
List<Integer> roleIds = roleService.findEmployeeRoleByEmployeeId(id);
//循环比较两个集合中的角色ID值是否相等,相等则选中该角色
for (Map<String, Object> map : roleList) {
//定义变量,标识是否选中
boolean flag = false;//不选中
//获取每一个角色ID
Integer rid = (Integer) map.get("id");//id是主键,以主键作为map集合中key
//内层循环遍历该员工拥有的角色列表
for (Integer roleId : roleIds) {
//判断两个集合中是否存在角色ID相同
if(rid == roleId){
flag = true;//选中该角色
break;
}
}
//将状态保存在map集合中
map.put("LAY_CHECKED",flag);//key必须是LAY_CHECKED
}
return new DataGridViewResult(Long.valueOf(roleList.size()),roleList);
}
}
/**
* 去到月营业额报表统计分析页面
* @return
*/
@RequestMapping("/toYearOfMonthCharts")
public String toYearOfMonthCharts(){
return "admin/charts/yearOfMonthCharts";
}
/**
* 去到季度营业额报表统计分析页面
* @return
*/
@RequestMapping("/toQuarterTotalPriceCharts")
public String toQuarterTotalPriceCharts(){
return "admin/charts/quarterTotalPriceCharts";
}
/**
* 去到房型预订报表统计分析页面
* @return
*/
@RequestMapping("/toRoomTypePieCharts")
public String toRoomTypePieCharts(){
return "admin/charts/roomTypePieCharts";
}
/**
* 当日开房报表
* @return
*/
@RequestMapping({"/toCurrentDateCheckinCharts"})
public String toCurrentDateCheckinCharts(){
return "admin/charts/currentDateCheckinCharts";
}
}
/**
* HP - the login name of the current user.
* 9:55 - the current system time.
*/
@RestController
@RequestMapping("/admin/menu")
public class MenuController {
@Autowired
private MenuService menuService;
/**
* 加载左边菜单选项
* @return
*/
@RequestMapping("/loadMenuList")
public String loadMenuList(HttpSession session){
//查询所有菜单列表的方法
//List<Menu> menuList = menuService.findMenuList();
//通过session获取登录用户信息
Employee employee = (Employee) session.getAttribute(SystemConstant.LOGINUSER);
//根据当前登录用户的角色id 动态显示菜单列表
map.put(SystemConstant.MESSAGE,"删除失败");
}
return JSON.toJSONString(map);
}
}
/**
* HP - the login name of the current user.
* 16:53 - the current system time.
*/
@RestController
@RequestMapping("/admin/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@RequestMapping("/login")
public String login(String userName,String password, HttpSession session){
Map<String,Object> map = new HashMap<String, Object>();
//System.out.println("controller层用户名:"+userName);
Employee employee = employeeService.Login(userName, password);
/**
* HP - the login name of the current user.
* 16:39 - the current system time.
*/
@RestController
@RequestMapping("/admin/floor")
public class FloorController {
@Autowired
private FloorService floorService;
/**
* 查询楼层列表
* @param floorVo
* @return
*/
@RequestMapping("/list")
public DataGridViewResult list(FloorVo floorVo){
//设置分页信息
PageHelper.startPage(floorVo.getPage(),floorVo.getLimit());
//查询楼层列表
List<Floor> floorList = floorService.findFloorList(floorVo);
//创建分页对象
PageInfo<Floor> pageInfo = new PageInfo<Floor>(floorList);
//返回分页信息
return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
}
/**
* 添加楼层
* @param floor
* @return
*/
@RequestMapping("/addFloor")
public String addFloor(Floor floor){
Map<String,Object> map = new HashMap<String, Object>();
if (floorService.addFloor(floor)>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"添加成功");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"添加失败");
}
return JSON.toJSONString(map);
}
/**
* HP - the login name of the current user.
* 11:06 - the current system time.
*/
@RequestMapping("/admin/room")
@RestController
public class RoomAdminController {
@Autowired
private RoomService roomService;
/**
* 查询房间列表
* @param roomVo
* @return
*/
@RequestMapping("/list")
private DataGridViewResult list(RoomVo roomVo){
//设置分页信息
PageHelper.startPage(roomVo.getPage(),roomVo.getLimit());
//查询房型列表
List<Room> roomTypeList = roomService.findRoomListByPage(roomVo);
//创建分页对象
PageInfo<Room> pageInfo = new PageInfo<Room>(roomTypeList);
//返回数据
return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
}
/**
* 添加房间
* @param room
* @return
*/
@RequestMapping("/addRoom")
public String addRoom(Room room){
Map<String,Object> map = new HashMap<String,Object>();
if(roomService.addRoom(room)>0){
map.put(SystemConstant.SUCCESS,true);//成功
map.put(SystemConstant.MESSAGE,"添加成功");
}else{
map.put(SystemConstant.SUCCESS,false);//失败
map.put(SystemConstant.MESSAGE,"添加失败");
}
* HP - the login name of the current user.
* 16:36 - the current system time.
*/
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
/**
* 注册
* @param user
* @return
*/
@RequestMapping("/register")
@ResponseBody
public String register(User user){
Map<String,Object> map = new HashMap<String,Object>();
//调用注册的方法
if(userService.addUser(user)>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"恭喜你,注册成功!");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"很遗憾,注册失败,请重新尝试!");
}
return JSON.toJSONString(map);
}
/**
* 登录
* @param
* @return
*/
@RequestMapping("/login")
@ResponseBody
public String login(String loginName, String password, HttpSession Session){
Map<String,Object> map = new HashMap<String,Object>();
//调用注册的方法
User loginUser = userService.login(loginName, password);
//登录判断
if(loginUser!=null){
//将密码清空
loginUser.setPassword(null);
List<RoomType> roomTypeList = roomTypeService.findRoomTypeList(null);
//创建查询条件类
RoomVo roomVo = new RoomVo();
roomVo.setRoomtypeid(id);//房型ID
roomVo.setStatus(3);//可预订
//查询房间列表
List<Room> roomList = roomService.findRoomListByPage(roomVo);
//将数据放到模型中
model.addAttribute("roomTypeList",roomTypeList);
model.addAttribute("roomList",roomList);
model.addAttribute("typeId",id);//将当前选中的房型ID保存到模型中,目的是在页面中回显选中的文本(改变选中的颜色)
return "hotelList";
}
}
/**
* HP - the login name of the current user.
* 16:39 - the current system time.
*/
@RestController
@RequestMapping("/admin/floor")
public class FloorController {
@Autowired
private FloorService floorService;
* 20:27 - the current system time.
*/
@Controller
public class IndexController {
@Resource
private RoomTypeService roomTypeService;
@Resource
private FloorService floorService;
@Resource
private RoomService roomService;
@RequestMapping("/index.html")
public String index(Model model){
//调用查询房型列表的方法
List<RoomType> roomTypeList = roomTypeService.findRoomTypeList(null);
//调用查询所有楼层列表的方法
List<Floor> floorList = floorService.findFloorList(null);
//调用查询每个楼层的房间列表
List<Room> roomList = roomService.findRoomListByFloorId();
//将数据放到模型中
model.addAttribute("roomTypeList",roomTypeList);
model.addAttribute("floorList",floorList);
model.addAttribute("roomList",roomList);
return "forward:/home.jsp";
}
}
@RestController
@RequestMapping("/admin/checkout")
public class CheckoutAdminController {
@Resource
private CheckoutService checkoutService;
/**
* 办理退房
model.addAttribute("roomTypeList",roomTypeList);
model.addAttribute("roomList",roomList);
return "hotelList";
}
/**
* 根据房型查询房间列表
* @param model
* @return
*/
@RequestMapping("/list/{id}")
public String list(@PathVariable Integer id,Model model){
//调用查询所有房型列表的方法
List<RoomType> roomTypeList = roomTypeService.findRoomTypeList(null);
//创建查询条件类
RoomVo roomVo = new RoomVo();
roomVo.setRoomtypeid(id);//房型ID
roomVo.setStatus(3);//可预订
//查询房间列表
List<Room> roomList = roomService.findRoomListByPage(roomVo);
//将数据放到模型中
model.addAttribute("roomTypeList",roomTypeList);
model.addAttribute("roomList",roomList);
model.addAttribute("typeId",id);//将当前选中的房型ID保存到模型中,目的是在页面中回显选中的文本(改变选中的颜色)
return "hotelList";
}
}
/**
* HP - the login name of the current user.
* 16:39 - the current system time.
*/
@RestController
@RequestMapping("/admin/floor")
}
/**
* 去到后台欢迎页
* return
*/
@RequestMapping("/welcome")
public String welcome(){
return "admin/welcome";
}
/**
* 去到首页
* @return
*/
@RequestMapping("/home.html")
public String home(){
return "admin/home";
}
/**
* 退出
* @param session
* @return
*/
@RequestMapping("/logout")
public String logout(HttpSession session){
//退出登录的方法 清空session
//方法一 session.removeAttribute(SystemConstant.LOGINUSER);
session.invalidate();
//重定向到登录页面
return "redirect:/admin/login.html";
}
/**
* 去到部门管理页面
* @return
*/
@RequestMapping("/toDeptManager")
public String toDeptManager(){
return "admin/dept/deptManager";
}
/**
Map<String,Object> map = new HashMap<String, Object>();
int addDept = deptService.addDept(dept);
if(addDept>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"添加成功");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"添加失败");
}
//map中存放的信息已json形式返回
return JSON.toJSONString(map);
}
//修改部门信息
@RequestMapping("/updateDept")
public String updateDept(Dept dept){
Map<String,Object> map = new HashMap<String, Object>();
int updateDept = deptService.updateDept(dept);
if(updateDept>0){
map.put(SystemConstant.SUCCESS,true);
map.put(SystemConstant.MESSAGE,"修改成功");
}else{
map.put(SystemConstant.SUCCESS,false);
map.put(SystemConstant.MESSAGE,"修改失败");
}
//map中存放的信息已json形式返回
return JSON.toJSONString(map);
}
//查询该部门下是否有员工
@RequestMapping("/checkDeptHasEmployee")
public String checkDeptHasEmployee(Integer id){
Map<String,Object> map = new HashMap<String, Object>();
int countById = employeeService.getEmployeeCountById(id);
if (countById>0){
//该部门下存在员工
map.put(SystemConstant.EXISI,true);//存在
map.put(SystemConstant.MESSAGE,"该部门下存在员工,不能删除");
}else{
map.put(SystemConstant.EXISI,false);//不存在
}
return JSON.toJSONString(map);
}
//删除部门信息
@RequestMapping("/deleteById")
public String deleteById(Integer id){
Map<String,Object> map = new HashMap<String, Object>();
int deleteById = deptService.deleteById(id);
if (deleteById>0){
map.put(SystemConstant.SUCCESS,true);//删除成功
//创建菜单节点对象
MenuNode menuNode = new MenuNode();
menuNode.setId(menu.getId());//菜单编号
menuNode.setPid(menu.getPid());//父级菜单编号
menuNode.setSpread(menu.getSpread());//是否展开
menuNode.setTarget(menu.getTarget());//打开方式
menuNode.setTitle(menu.getTitle());//菜单名称
menuNode.setIcon(menu.getIcon());//菜单图标
menuNode.setHref(menu.getHref());//链接地址
//添加到list集合当中
menuNodes.add(menuNode);
}
//保存HomeInfo
homeInfo.put("title","首页");
homeInfo.put("href","/admin/welcome.html");
//保存logoInfo
logoInfo.put("title","酒店管理系统");
logoInfo.put("image","/statics/layui/images/logo.png");
logoInfo.put("href","/admin/home.html");
//将menuInfo,homeInfo,logoInfo添加到map中
map.put("menuInfo", TreeUtil.toTree(menuNodes,0));
map.put("homeInfo",homeInfo);
map.put("logoInfo",logoInfo);
return JSON.toJSONString(map);
}
/**
* 加载菜单管理页面的左侧导航树
* @return
*/
@RequestMapping("/loadMenuTree")
public DataGridViewResult loadMenuTree(){
//调用查询所有菜单列表的方法
List<Menu> menuList = menuService.findMenuList();
//创建集合保存节点信息
List<TreeNode> treeNodes = new ArrayList<TreeNode>();
//循环遍历菜单列表集合
for (Menu menu : menuList) {
//判断当前菜单是否展开
Boolean spread = (menu.getSpread()==null || menu.getSpread()==1) ? true : false;
//将菜单信息保存到treeNodes集合中
treeNodes.add(new TreeNode(menu.getId(),menu.getPid(),menu.getTitle(),spread));
/**
* HP - the login name of the current user.
* 16:53 - the current system time.
*/
@RestController
@RequestMapping("/admin/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@RequestMapping("/login")
public String login(String userName,String password, HttpSession session){
Map<String,Object> map = new HashMap<String, Object>();
//System.out.println("controller层用户名:"+userName);
Employee employee = employeeService.Login(userName, password);
if (employee!=null){
//如果不为空 登录成功
map.put(SystemConstant.SUCCESS,true);
session.setAttribute(SystemConstant.LOGINUSER,employee);
}else {
map.put(SystemConstant.SUCCESS,false);
//登录失败 提示信息
map.put(SystemConstant.MESSAGE,"账号和密码错误!");
}
return JSON.toJSONString(map);
}
/**
* 查询员工列表
* @param employeeVo
* @return
*/
@RequestMapping("/list")
public DataGridViewResult list(EmployeeVo employeeVo){
//设置分页信息
PageHelper.startPage(employeeVo.getPage(),employeeVo.getLimit());
//调用查询方法
}else{
map.put(SystemConstant.SUCCESS,false);//失败
map.put(SystemConstant.MESSAGE,"删除失败");
}
return JSON.toJSONString(map);
}
}
@RestController
@RequestMapping("/admin/orders")
public class OrdersAdminController {
@Resource
private OrdersService ordersService;
/**
* 查询订单列表
* @param ordersVo
* @return
*/
@RequestMapping("/list")