基于javaweb+mysql的ssm酒店预定管理系统(前台、后台)(java+java+jsp+ssm+javabean+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
(1)用户在线浏览客房,管理自己的个人信息,预订客房。
(2)管理员对酒店的客房信息、活动信息进行管理,同时对客房评论进行管理。
前台
后台:
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) MySQL EasyUI JavaScript
基于javaweb+mysql的SSM酒店预定管理系统(前台、后台)(java+java+jsp+ssm+javabean+mysql)
@RequestMapping("/admin/room_type")
@Controller
public class RoomTypeController {
@Autowired
private RoomTypeService roomTypeService;
/**
* 房间类型管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("room_type/list");
return model;
}
/**
* 房间类型信息添加操作
* @param roomType
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(RoomType roomType){
Map<String, String> ret = new HashMap<String, String>();
if(roomType == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的房间类型信息!");
return ret;
}
if(StringUtils.isEmpty(roomType.getName())){
ret.put("type", "error");
ret.put("msg", "房间类型名称不能为空!");
return ret;
}
roomType.setAvilableNum(roomType.getRoomNum());//默认房间数等于可用房间数
roomType.setBookNum(0);//设置预定数0
roomType.setLivedNum(0);//设置已入住数0
if(roomTypeService.add(roomType) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "添加成功!");
/**
* 菜单管理控制器
*
*/
@RequestMapping("/admin/menu")
@Controller
public class MenuController {
@Autowired
private MenuService menuService;
/**
* 菜单管理列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.addObject("topList", menuService.findTopList());
model.setViewName("menu/list");
return model;
}
/**
* 获取菜单列表
* @param page
* @param name
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getMenuList(Page page,
@RequestParam(name="name",required=false,defaultValue="") String name
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
queryMap.put("name", name);
List<Menu> findList = menuService.findList(queryMap);
ret.put("rows", findList);
ret.put("total", menuService.getTotal(queryMap));
return ret;
}
/**
* 获取指定目录下的系统icon集合
* @param request
* @return
*/
@RequestMapping(value="/get_icons",method=RequestMethod.POST)
@ResponseBody
if(checkinService.edit(checkin) <= 0){
ret.put("type", "error");
ret.put("msg", "编辑失败,请联系管理员!");
return ret;
}
//编辑成功之后:1:判断房型是否发生变化,2:判断房间是否发生变化,3:判断是否是从预定订单来的信息
//首先判断是否是从预定来的入住信息
RoomType oldRoomType = roomTypeService.find(existCheckin.getRoomTypeId());
RoomType newRoomType = roomTypeService.find(checkin.getRoomTypeId());
//房型入住数不收预定订单的影响
if(oldRoomType.getId().longValue() != newRoomType.getId().longValue()){
//说明房型发生了变化,原来的房型入住数恢复,新的房型入住数增加
oldRoomType.setLivedNum(oldRoomType.getLivedNum() - 1);
newRoomType.setLivedNum(newRoomType.getLivedNum() + 1);
if(bookOrderId == null){
oldRoomType.setAvilableNum(oldRoomType.getAvilableNum() + 1);
newRoomType.setAvilableNum(newRoomType.getAvilableNum() - 1);
}
}
/**
if(bookOrderId == null){
//表示不是从预定订单来的,此时需判断原来的入住信息是否来源于预定
if(existCheckin.getBookOrderId() == null){
oldRoomType.setAvilableNum(oldRoomType.getAvilableNum() + 1);
newRoomType.setAvilableNum(newRoomType.getAvilableNum() - 1);
}
if(existCheckin.getBookOrderId() != null){
//表示原来的入住信息来源于预定,但是新的入住信息不是来源于预定,需恢复原来的预定状态
BookOrder oldBookOrder = bookOrderService.find(existCheckin.getBookOrderId());
oldBookOrder.setStatus(0);
bookOrderService.edit(oldBookOrder);
oldRoomType.setBookNum(oldRoomType.getBookNum() + 1);
}
}
//表示此时的订单是来源于预定
if(bookOrderId != null){
//表示是从预定订单来的,此时需判断原来的入住信息是否来源于预定
if(existCheckin.getBookOrderId() != null){
//表示原来的入住信息来源于预定,但是新的入住信息不是来源于预定,需恢复原来的预定状态
BookOrder oldBookOrder = bookOrderService.find(existCheckin.getBookOrderId());
if(bookOrderId.longValue() != oldBookOrder.getId().longValue()){
/**
* 预定订单管理后台控制器
*
*/
@RequestMapping("/admin/book_order")
@Controller
public class BookOrderController {
@Autowired
private AccountService accountService;
@Autowired
private RoomTypeService roomTypeService;
@Autowired
private BookOrderService bookOrderService;
/**
* 预定订单管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.addObject("roomTypeList", roomTypeService.findAll());
model.addObject("accountList", accountService.findAll());
model.setViewName("book_order/list");
return model;
}
/**
* 预定订单信息添加操作
* @param bookOrder
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(BookOrder bookOrder){
Map<String, String> ret = new HashMap<String, String>();
if(bookOrder == null){
ret.put("type", "error");
return ret;
}
if(StringUtils.isEmpty(checkin.getName())){
ret.put("type", "error");
ret.put("msg", "入住联系人名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(checkin.getMobile())){
ret.put("type", "error");
ret.put("msg", "入住联系人手机号不能为空!");
return ret;
}
if(StringUtils.isEmpty(checkin.getIdCard())){
ret.put("type", "error");
ret.put("msg", "联系人身份证号不能为空!");
return ret;
}
if(StringUtils.isEmpty(checkin.getArriveDate())){
ret.put("type", "error");
ret.put("msg", "到达时间不能为空!");
return ret;
}
if(StringUtils.isEmpty(checkin.getLeaveDate())){
ret.put("type", "error");
ret.put("msg", "离店时间不能为空!");
return ret;
}
Checkin existCheckin = checkinService.find(checkin.getId());
if(existCheckin == null){
ret.put("type", "error");
ret.put("msg", "请选择正确的入住信息进行编辑!");
return ret;
}
if(checkinService.edit(checkin) <= 0){
ret.put("type", "error");
ret.put("msg", "编辑失败,请联系管理员!");
return ret;
}
//编辑成功之后:1:判断房型是否发生变化,2:判断房间是否发生变化,3:判断是否是从预定订单来的信息
//首先判断是否是从预定来的入住信息
RoomType oldRoomType = roomTypeService.find(existCheckin.getRoomTypeId());
RoomType newRoomType = roomTypeService.find(checkin.getRoomTypeId());
//房型入住数不收预定订单的影响
if(oldRoomType.getId().longValue() != newRoomType.getId().longValue()){
//说明房型发生了变化,原来的房型入住数恢复,新的房型入住数增加
oldRoomType.setLivedNum(oldRoomType.getLivedNum() - 1);
newRoomType.setLivedNum(newRoomType.getLivedNum() + 1);
if(bookOrderId == null){
/**
* 房间类型信息删除操作
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(Long id){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的信息!");
return ret;
}
try {
if(roomTypeService.delete(id) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
} catch (Exception e) {
// TODO: handle exception
ret.put("type", "error");
ret.put("msg", "该房间类型下存在房间信息,请先删除该房间类型下的所有房间信息!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "删除成功!");
return ret;
}
}
/**
/**
* 入住管理后台控制器
*
*/
@RequestMapping("/admin/checkin")
@Controller
public class CheckinController {
@Autowired
private RoomService roomService;
@Autowired
private RoomTypeService roomTypeService;
@Autowired
private BookOrderService bookOrderService;
@Autowired
private CheckinService checkinService;
/**
//要把房间状态设置为已入住
room.setStatus(1);
roomService.edit(room);
}
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 入住信息编辑操作
* @param account
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Checkin checkin,
@RequestParam(name="bookOrderId",required=false) Long bookOrderId
){
Map<String, String> ret = new HashMap<String, String>();
if(checkin == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的入住信息!");
return ret;
}
if(checkin.getRoomId() == null){
ret.put("type", "error");
ret.put("msg", "房间不能为空!");
return ret;
}
if(checkin.getRoomTypeId() == null){
ret.put("type", "error");
ret.put("msg", "房型不能为空!");
return ret;
}
if(StringUtils.isEmpty(checkin.getName())){
ret.put("type", "error");
ret.put("msg", "入住联系人名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(checkin.getMobile())){
ret.put("type", "error");
ret.put("msg", "入住联系人手机号不能为空!");
return ret;
}
if(StringUtils.isEmpty(checkin.getIdCard())){
ret.put("type", "error");
ret.put("msg", "联系人身份证号不能为空!");
return ret;
}
return ret;
}
if(isExist(user.getUsername(), 0l)){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在,请重新输入!");
return ret;
}
if(userService.add(user) <= 0){
ret.put("type", "error");
ret.put("msg", "用户添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 编辑用户
* @param user
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(User user){
Map<String, String> ret = new HashMap<String, String>();
if(user == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的用户信息!");
return ret;
}
if(StringUtils.isEmpty(user.getUsername())){
ret.put("type", "error");
ret.put("msg", "请填写用户名!");
return ret;
}
// if(StringUtils.isEmpty(user.getPassword())){
// ret.put("type", "error");
// ret.put("msg", "请填写密码!");
// return ret;
queryMap.put("offset", 0);
queryMap.put("pageSize", 99999);
return menuService.findList(queryMap);
}
/**
* 添加权限
* @param ids
* @return
*/
@RequestMapping(value="/add_authority",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> addAuthority(
@RequestParam(name="ids",required=true) String ids,
@RequestParam(name="roleId",required=true) Long roleId
){
Map<String,String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "请选择相应的权限!");
return ret;
}
if(roleId == null){
ret.put("type", "error");
ret.put("msg", "请选择相应的角色!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] idArr = ids.split(",");
if(idArr.length > 0){
authorityService.deleteByRoleId(roleId);
}
for(String id:idArr){
Authority authority = new Authority();
authority.setMenuId(Long.valueOf(id));
authority.setRoleId(roleId);
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
ret.put("type", "error");
ret.put("msg", "请填写正确的预定订单信息!");
return ret;
}
if(bookOrder.getAccountId() == null){
ret.put("type", "error");
ret.put("msg", "客户不能为空!");
return ret;
}
if(bookOrder.getRoomTypeId() == null){
ret.put("type", "error");
ret.put("msg", "房型不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getName())){
ret.put("type", "error");
ret.put("msg", "预定订单联系人名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getMobile())){
ret.put("type", "error");
ret.put("msg", "预定订单联系人手机号不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getIdCard())){
ret.put("type", "error");
ret.put("msg", "联系人身份证号不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getArriveDate())){
ret.put("type", "error");
ret.put("msg", "到达时间不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getLeaveDate())){
ret.put("type", "error");
ret.put("msg", "离店时间不能为空!");
return ret;
}
bookOrder.setCreateTime(new Date());
if(bookOrderService.add(bookOrder) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
RoomType roomType = roomTypeService.find(bookOrder.getRoomTypeId());
//预定成功后去修改该房型的预定数
if(roomType != null){
if(menu.getParentId() == null){
menu.setParentId(0l);
}
if(menuService.edit(menu) <= 0){
ret.put("type", "error");
ret.put("msg", "修改失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "修改成功!");
return ret;
}
/**
* 删除菜单信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(
@RequestParam(name="id",required=true) Long id
){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的菜单信息!");
return ret;
}
List<Menu> findChildernList = menuService.findChildernList(id);
if(findChildernList != null && findChildernList.size() > 0){
//表示该分类下存在子分类,不能删除
ret.put("type", "error");
ret.put("msg", "该分类下存在子分类,不能删除!");
return ret;
}
if(menuService.delete(id) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "删除成功!");
if(StringUtils.isEmpty(newPassword)){
retMap.put("type", "error");
retMap.put("msg", "请填写新密码!");
return retMap;
}
Account loginedAccount = (Account)request.getSession().getAttribute("account");
if(!oldPassword.equals(loginedAccount.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "原密码错误!");
return retMap;
}
loginedAccount.setPassword(newPassword);
if(accountService.edit(loginedAccount) <= 0){
retMap.put("type", "error");
retMap.put("msg", "修改失败,请联系管理员!");
return retMap;
}
retMap.put("type", "success");
retMap.put("msg", "修改密码成功!");
return retMap;
}
/**
* 判断用户是否存在
* @param name
* @param id
* @return
*/
private boolean isExist(String name,Long id){
Account account = accountService.findByName(name);
if(account == null)return false;
if(account != null && account.getId().longValue() == id)return false;
return true;
}
}
loginedAccount.setMobile(account.getMobile());
loginedAccount.setName(account.getName());
loginedAccount.setRealName(account.getRealName());
if(accountService.edit(loginedAccount) <= 0){
retMap.put("type", "error");
retMap.put("msg", "修改失败,请联系管理员!");
return retMap;
}
request.getSession().setAttribute("account", loginedAccount);
retMap.put("type", "success");
retMap.put("msg", "修改成功!");
return retMap;
}
/**
* 修改密码提交
* @param account
* @return
*/
@RequestMapping(value="/update_pwd",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> updatePwdAct(String oldPassword,String newPassword,HttpServletRequest request){
Map<String,String> retMap = new HashMap<String, String>();
if(StringUtils.isEmpty(oldPassword)){
retMap.put("type", "error");
retMap.put("msg", "请填写原来的密码!");
return retMap;
}
if(StringUtils.isEmpty(newPassword)){
retMap.put("type", "error");
retMap.put("msg", "请填写新密码!");
return retMap;
}
Account loginedAccount = (Account)request.getSession().getAttribute("account");
if(!oldPassword.equals(loginedAccount.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "原密码错误!");
return retMap;
}
loginedAccount.setPassword(newPassword);
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
if(logService.delete(ids) <= 0){
ret.put("type", "error");
ret.put("msg", "日志删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "日志删除成功!");
return ret;
}
}
/**
* 营业统计控制器
*
*/
@RequestMapping("/admin/stats")
@Controller
public class StatsController {
@Autowired
private CheckinService checkinService;
/**
* 统计页面
* @param model
* @return
*/
/**
* 删除菜单信息
* @param id
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(
@RequestParam(name="id",required=true) Long id
){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的菜单信息!");
return ret;
}
List<Menu> findChildernList = menuService.findChildernList(id);
if(findChildernList != null && findChildernList.size() > 0){
//表示该分类下存在子分类,不能删除
ret.put("type", "error");
ret.put("msg", "该分类下存在子分类,不能删除!");
return ret;
}
if(menuService.delete(id) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "删除成功!");
return ret;
}
}
/**
* 客户信息添加操作
* @param account
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Account account){
Map<String, String> ret = new HashMap<String, String>();
if(account == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的客户信息!");
return ret;
}
if(StringUtils.isEmpty(account.getName())){
ret.put("type", "error");
ret.put("msg", "客户名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(account.getPassword())){
ret.put("type", "error");
ret.put("msg", "客户密码不能为空!");
return ret;
}
if(isExist(account.getName(), 0l)){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在!");
return ret;
}
if(accountService.add(account) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 客户信息编辑操作
* @param account
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Account account){
Map<String, String> ret = new HashMap<String, String>();
if(account == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的客户信息!");
return ret;
}
/**
* 营业统计控制器
*
*/
@RequestMapping("/admin/stats")
@Controller
public class StatsController {
@Autowired
private CheckinService checkinService;
/**
* 统计页面
* @param model
* @return
*/
@RequestMapping(value="/stats",method=RequestMethod.GET)
public ModelAndView stats(ModelAndView model){
model.setViewName("stats/stats");
return model;
}
/**
* 根据类型来获取统计数据
* @param type
* @return
*/
@RequestMapping(value="/get_stats",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getStats(String type){
Map<String, Object> ret = new HashMap<String, Object>();
if(StringUtils.isEmpty(type)){
ret.put("type", "error");
ret.put("msg", "请选择统计类型!");
return ret;
}
switch (type) {
case "month":{
ret.put("type", "success");
ret.put("content", getStatsValue(checkinService.getStatsByMonth()));
return ret;
}
case "day":{
ret.put("type", "success");
ret.put("content", getStatsValue(checkinService.getStatsByDay()));
return ret;
}