源码获取:博客首页 "资源" 里下载!
基础环境
搭建环境
- Tomcat 8.5
- Java 1.8+
- Mysql 5.7
涉及技术
Spring、Mybatis、MySql、easyui、h-ui、Jsp、echars
项目介绍
酒店管理系统的目标是为用户提供高效的服务,减少手工处理的繁琐与误差,及时准确地反映酒店工作情况、经营信息,从而提高酒店工作质量,获得更好的经济效益,实现客房管理的规范化、自动化。具体目标包括:
- 高效的客房预订及订单处理。
- 准确无误地记录客人每笔消费信息。
- 实时、快速、准确提供客房动态。
- 酒店收益的最终统计。
- 系统运行稳定可靠、各项维护功能齐全、易于维护。
- 简单、友好的操作界面
前台页面:
模块 | 主要功能 |
---|---|
酒店信息展示 | 客房信息展示、房间状态查询、房间预定、客房信息检索、 |
会员用户预订 | 会员注册登录、用户中心、订单查询、用户信息修改、用户密码修改 |
后台页面:
模块 | 主要功能 |
---|---|
系统设置 | 菜单管理、角色管理、修改密码 |
用户管理 | 用户列表管理 |
系统日志 | 日志列表 |
酒店管理 | 楼层管理、房型管理、房间管理、客户管理、预订管理、入住管理 |
营业统计 | 统计图标 |
客户管理后台控制器:
/**
* 客户管理后台控制器
* @author yy
*
*/
@RequestMapping("/admin/account")
@Controller
public class AccountController {
@Autowired
private AccountService accountService;
/**
* 客户管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("account/list");
return model;
}
/**
* 客户信息添加操作
* @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;
}
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(), account.getId())){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在!");
return ret;
}
if(accountService.edit(account) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "修改成功!");
return ret;
}
/**
* 分页查询客户信息
* @param name
* @param page
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String,Object> list(
@RequestParam(name="name",defaultValue="") String name,
@RequestParam(name="realName",defaultValue="") String realName,
@RequestParam(name="idCard",defaultValue="") String idCard,
@RequestParam(name="mobile",defaultValue="") String mobile,
@RequestParam(name="status",required=false) Integer status,
Page page
){
Map<String,Object> ret = new HashMap<String, Object>();
Map<String,Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
queryMap.put("status", status);
queryMap.put("realName", realName);
queryMap.put("idCard", idCard);
queryMap.put("mobile", mobile);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", accountService.findList(queryMap));
ret.put("total", accountService.getTotal(queryMap));
return ret;
}
/**
* 客户信息删除操作
* @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(accountService.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;
}
/**
* 判断用户名是否存在
* @param name
* @param id
* @return
*/
private boolean isExist(String name,Long id){
Account findByName = accountService.findByName(name);
if(findByName == null)return false;
if(findByName.getId().longValue() == id.longValue())return false;
return true;
}
}
角色role控制器:
/**
* 角色role控制器
* @author yy
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("/role/list");
return model;
}
/**
* 获取角色列表
* @param page
* @param name
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(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("name", name);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", roleService.findList(queryMap));
ret.put("total", roleService.getTotal(queryMap));
return ret;
}
/**
* 角色添加
* @param role
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Role role){
Map<String, String> ret = new HashMap<String, String>();
if(role == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的角色信息!");
return ret;
}
if(StringUtils.isEmpty(role.getName())){
ret.put("type", "error");
ret.put("msg", "请填写角色名称!");
return ret;
}
if(roleService.add(role) <= 0){
ret.put("type", "error");
ret.put("msg", "角色添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 角色修改
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Role role){
Map<String, String> ret = new HashMap<String, String>();
if(role == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的角色信息!");
return ret;
}
if(StringUtils.isEmpty(role.getName())){
ret.put("type", "error");
ret.put("msg", "请填写角色名称!");
return ret;
}
if(roleService.edit(role) <= 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(Long id){
Map<String, String> ret = new HashMap<String, String>();
if(id == null){
ret.put("type", "error");
ret.put("msg", "请选择要删除的角色!");
return ret;
}
try {
if(roleService.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;
}
/**
* 获取所有的菜单信息
* @return
*/
@RequestMapping(value="/get_all_menu",method=RequestMethod.POST)
@ResponseBody
public List<Menu> getAllMenu(){
Map<String, Object> queryMap = new HashMap<String, Object>();
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", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
@RequestParam(name="roleId",required=true) Long roleId
){
return authorityService.findListByRoleId(roleId);
}
}
前台首页控制器:
/**
* 前台首页控制器
* @author yy
*
*/
@RequestMapping("/home")
@Controller
public class HomeController {
@Autowired
private RoomTypeService roomTypeService;
@Autowired
private AccountService accountService;
/**
* 前台首页
* @param model
* @param name
* @return
*/
@RequestMapping(value="/index",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model,
@RequestParam(name="name",defaultValue="") String name
){
Map<String,Object> queryMap = new HashMap<String, Object>();
queryMap.put("name", name);
queryMap.put("offset", 0);
queryMap.put("pageSize", 999);
model.addObject("roomTypeList", roomTypeService.findList(queryMap));
model.setViewName("home/index/index");
model.addObject("kw", name);
return model;
}
/**
* 登录页面
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public ModelAndView login(ModelAndView model
){
model.setViewName("home/index/login");
return model;
}
/**
* 注册页面
* @param model
* @return
*/
@RequestMapping(value="/reg",method=RequestMethod.GET)
public ModelAndView reg(ModelAndView model
){
model.setViewName("home/index/reg");
return model;
}
/**
* 登录信息提交
* @param account
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> loginAct(Account account,String vcode,HttpServletRequest request){
Map<String,String> retMap = new HashMap<String, String>();
if(account == null){
retMap.put("type", "error");
retMap.put("msg", "请填写正确的用户信息!");
return retMap;
}
if(StringUtils.isEmpty(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "用户名不能为空!");
return retMap;
}
if(StringUtils.isEmpty(account.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "密码不能为空!");
return retMap;
}
if(StringUtils.isEmpty(vcode)){
retMap.put("type", "error");
retMap.put("msg", "验证码不能为空!");
return retMap;
}
Object attribute = request.getSession().getAttribute("accountLoginCpacha");
if(attribute == null){
retMap.put("type", "error");
retMap.put("msg", "验证码过期,请刷新!");
return retMap;
}
if(!vcode.equalsIgnoreCase(attribute.toString())){
retMap.put("type", "error");
retMap.put("msg", "验证码错误!");
return retMap;
}
Account findByName = accountService.findByName(account.getName());
if(findByName == null){
retMap.put("type", "error");
retMap.put("msg", "用户名不存在!");
return retMap;
}
if(!account.getPassword().equals(findByName.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "密码错误!");
return retMap;
}
if(findByName.getStatus() == -1){
retMap.put("type", "error");
retMap.put("msg", "该用户已被禁用,请联系管理员!");
return retMap;
}
request.getSession().setAttribute("account", findByName);
request.getSession().setAttribute("accountLoginCpacha", null);
retMap.put("type", "success");
retMap.put("msg", "登录成功!");
return retMap;
}
/**
* 注册信息提交
* @param account
* @return
*/
@RequestMapping(value="/reg",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> regAct(Account account){
Map<String,String> retMap = new HashMap<String, String>();
if(account == null){
retMap.put("type", "error");
retMap.put("msg", "请填写正确的用户信息!");
return retMap;
}
if(StringUtils.isEmpty(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "用户名不能为空!");
return retMap;
}
if(StringUtils.isEmpty(account.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "密码不能为空!");
return retMap;
}
if(StringUtils.isEmpty(account.getMobile())){
retMap.put("type", "error");
retMap.put("msg", "手机号不能为空!");
return retMap;
}
if(isExist(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "该用户名已经存在!");
return retMap;
}
if(accountService.add(account) <= 0){
retMap.put("type", "error");
retMap.put("msg", "注册失败,请联系管理员!");
return retMap;
}
retMap.put("type", "success");
retMap.put("msg", "注册成功!");
return retMap;
}
/**
* 退出登录
* @param request
* @return
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public String logout(HttpServletRequest request){
request.getSession().setAttribute("account", null);
return "redirect:login";
}
private boolean isExist(String name){
Account account = accountService.findByName(name);
if(account == null)return false;
return true;
}
}
前台用户控制器:
/**
* 前台用户控制器
* @author yy
*
*/
@RequestMapping("/home/account")
@Controller
public class HomeAccountController {
@Autowired
private RoomTypeService roomTypeService;
@Autowired
private AccountService accountService;
@Autowired
private BookOrderService bookOrderService;
/**
* 前台用户中心首页
* @param model
* @param name
* @return
*/
@RequestMapping(value="/index",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model,HttpServletRequest request
){
Account account = (Account)request.getSession().getAttribute("account");
Map<String,Object> queryMap = new HashMap<String, Object>();
queryMap.put("accountId", account.getId());
queryMap.put("offset", 0);
queryMap.put("pageSize", 999);
model.addObject("bookOrderList", bookOrderService.findList(queryMap));
model.addObject("roomTypeList", roomTypeService.findAll());
model.setViewName("home/account/index");
return model;
}
/**
* 预定房间页面
* @param model
* @return
*/
@RequestMapping(value="/book_order",method=RequestMethod.GET)
public ModelAndView bookOrder(ModelAndView model,Long roomTypeId
){
model.addObject("roomType", roomTypeService.find(roomTypeId));
model.setViewName("home/account/book_order");
return model;
}
/**
* 预定信息提交
* @param account
* @return
*/
@RequestMapping(value="/book_order",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> bookOrderAct(BookOrder bookOrder,HttpServletRequest request){
Map<String, String> ret = new HashMap<String, String>();
if(bookOrder == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的预定订单信息!");
return ret;
}
Account account = (Account)request.getSession().getAttribute("account");
if(account == null){
ret.put("type", "error");
ret.put("msg", "客户不能为空!");
return ret;
}
bookOrder.setAccountId(account.getId());
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());
bookOrder.setStatus(0);
if(bookOrderService.add(bookOrder) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
RoomType roomType = roomTypeService.find(bookOrder.getRoomTypeId());
//预定成功后去修改该房型的预定数
if(roomType != null){
roomType.setBookNum(roomType.getBookNum() + 1);
roomType.setAvilableNum(roomType.getAvilableNum() - 1);
roomTypeService.updateNum(roomType);
//如果可用的房间数为0,则设置该房型状态已满
if(roomType.getAvilableNum() == 0){
roomType.setStatus(0);
roomTypeService.edit(roomType);
}
}
ret.put("type", "success");
ret.put("msg", "预定成功!");
return ret;
}
/**
* 修改个人信息提交
* @param account
* @return
*/
@RequestMapping(value="/update_info",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> updateInfoAct(Account account,HttpServletRequest request){
Map<String,String> retMap = new HashMap<String, String>();
if(account == null){
retMap.put("type", "error");
retMap.put("msg", "请填写正确的用户信息!");
return retMap;
}
if(StringUtils.isEmpty(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "用户名不能为空!");
return retMap;
}
Account loginedAccount = (Account)request.getSession().getAttribute("account");
if(isExist(account.getName(),loginedAccount.getId())){
retMap.put("type", "error");
retMap.put("msg", "该用户名已经存在!");
return retMap;
}
loginedAccount.setAddress(account.getAddress());
loginedAccount.setIdCard(account.getIdCard());
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(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;
}
}
源码获取:博客首页 "资源" 里下载!