基于javaweb+mysql的jsp+servlet酒店客房管理系统(java+jsp+html+bootstrap+jquery+servlet+mysql)

基于javaweb+mysql的jsp+servlet酒店客房管理系统(java+jsp+html+bootstrap+jquery+servlet+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的JSP+Servlet酒店客房管理系统(java+jsp+html+bootstrap+jquery+servlet+mysql)

项目介绍

酒店管理系统共分为三个角色,客房经理、前台管理员、客户,各个角色的权限各不相同; 客房经理功能包括:登录、注册、前台用户管理、客房管理、优惠活动、查看留言、更换客房、房费续交、订单查看、报修统计、入驻统计、退房等功能;

前台管理员主要功能: 前台管理:包括客房查询、更换客房、房费续交、订单查看、报修统计、入住统计、退房、查看留言;

客户主要功能: 主要查看用户信息:个人信息、优惠活动、客房信息、订单管理、留言等;

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

技术栈

  1. 后端:Servlet 2. 前端:JSP+bootstrap+jQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/SLH 登录 注:tomcat中配置项目路径必须为/SLH,否则会报错; 客房经理用户名密码:admin/admin 前台管理员用户名密码:test/123456 客户用户名密码:jack/123456

	private String lookOrder(HttpServletRequest request,
			HttpServletResponse response) {
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
		String isoccupancy = request.getParameter("isoccupancy")==null?"":request.getParameter("isoccupancy");
		String sql = "select o.id,o.orderno,u.name,o.roomno,o.handleuser,o.ordertime,o.ordermoney,o.prepay,o.ordertype,o.occupancytime,o.outtime ,o.isoccupancy,o.iscompensation,o.compensationmoney,o.compensationgoods from orders o,users u where u.id=o.orderuser and 1=1";
		int page=0;
		String prepage = request.getParameter("page")==null?"":request.getParameter("page");
		if(prepage.equals("")){
			page = 1;
		}else page = Integer.parseInt(prepage);
		int pagesize = 5;
		
		String csql="select count(*) total from orders o,users u where u.id=o.orderuser and 1=1 ";
		if(!roomno.equals("")){
			sql+="  and o.roomno = '"+roomno+"'";
			csql+="  and o.roomno = '"+roomno+"'";
		}
		if(!name.equals("")){
			sql+="  and u.name=  '"+ name+"'";
			csql+="  and u.name= '"+ name+"'";
		}
		if(!idcard.equals("")){
			sql+=" and u.idcard = '"+idcard+"'";
			csql+=" and u.idcard = '"+idcard+"'";
		}
		if(!isoccupancy.equals("")){
			sql+=" and o.isoccupancy = "+isoccupancy;
			csql+=" and o.isoccupancy = "+isoccupancy;
		}
		
		sql+=" order by u.id limit "+(page-1)*pagesize+"," +pagesize;
		String total = new DBHelper().queryField(csql, null, "total");
		Map<String ,String>map = null;
		if(total!=null && !total.equals("")){
			int totalCount = Integer.parseInt(total);
			map = new HashMap<String, String>();
			map.put("total", totalCount+"");
			map.put("prepage", page+"");
	private String findOrderById(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		String uid = ((Users)request.getSession().getAttribute("user")).getId();
		
		String sql = "select o.id,o.orderno,u.name,o.occupancytime,o.ordertime,o.ordermoney,o.prepay,o.ordertype,o.roomno,o.day,o.isoccupancy from orders o,users u where u.id = o.orderuser and o.id = ? and u.id = ?";
		String fields[]={"id","orderno","name","occupancytime","ordertime","ordermoney","prepay","ordertype","roomno","day","isoccupancy"};
		Map<String,String> map = new DBHelper().queryObject(sql, new String[]{id,uid}, fields);
		if(map!=null && !map.isEmpty()){
			return JSONObject.fromObject(map).toString();
		}else return "error:获取您的订单信息失败!";
		
	}
	private String motifyuser(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		String age = request.getParameter("age")==null?"":request.getParameter("age");
		String sex = request.getParameter("sex")==null?"":request.getParameter("sex");
		String realname = request.getParameter("realname")==null?"":request.getParameter("realname");
		String phone = request.getParameter("phone")==null?"":request.getParameter("phone");
		
		String reg = "^[1-9]+$";
		Pattern p = Pattern.compile(reg);
		
		
		if(id.equals("")) return "error:用户ID为空!";
		if(age.equals("")) return "error:年龄为空";
		if(!p.matcher(age).matches()) return "error:请输入正确的年龄";
		if(Integer.parseInt(age)>150) return "error:请输入真实的年龄";
		if(sex.equals("")) return "error:请选择性别!";
		if(realname.equals("")) return "error:真实姓名为空!";
		if(phone.equals("")) return "error:联系方式为空";
		
		String sql = "update users set age =?,sex=?,realname=?,phone=? where id= ?";
		String params[]={age,sex,realname,phone,id};
		int rows = new DBHelper().alertData(sql, params);
		if(rows > 0){
			Users u = (Users)request.getSession().getAttribute("user");
			u.setAge(age);
			u.setSex(sex);
			u.setRealname(realname);
			u.setPhone(phone);
			return "修改信息成功!";
		} 
		else return "error:修改信息失败!";
	}
	private String message(HttpServletRequest request,
			HttpServletResponse response) {
		String id = Keys.createKey("M");
		String title = request.getParameter("title")==null?"":request.getParameter("title");
		String sql = "update orders set roomno = ?,handleuser=?  where id = ?";
		String params[]={roomno,handleuser,id};
		int rows = new DBHelper().alertData(sql, params);
		if(rows > 0) return "成功!";
		else return "error:修改失败";
	}
	private String changeRoom(HttpServletRequest request,
			HttpServletResponse response) {
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
		String isoccupancy = request.getParameter("isoccupancy")==null?"":request.getParameter("isoccupancy");
		String sql = "select o.id,o.orderno,u.name,o.roomno,o.handleuser,o.ordertime,o.ordermoney,o.prepay,o.ordertype,o.occupancytime,o.outtime ,o.isoccupancy,o.iscompensation,o.compensationmoney,o.day,o.compensationgoods from orders o,users u where u.id=o.orderuser and o.isoccupancy not in(3,4) and 1=1";
		int page=0;
		String prepage = request.getParameter("page")==null?"":request.getParameter("page");
		if(prepage.equals("")){
			page = 1;
		}else page = Integer.parseInt(prepage);
		int pagesize = 5;
		
		String csql="select count(*) total from orders o,users u where u.id=o.orderuser and o.isoccupancy not in(3,4) and 1=1 ";
		if(!roomno.equals("")){
			sql+="  and o.roomno = '"+roomno+"'";
			csql+="  and o.roomno = '"+roomno+"'";
		}
		if(!name.equals("")){
			sql+="  and u.name=  '"+ name+"'";
			csql+="  and u.name= '"+ name+"'";
		}
		if(!idcard.equals("")){
			sql+=" and u.idcard = '"+idcard+"'";
			csql+=" and u.idcard = '"+idcard+"'";
		}
		if(!isoccupancy.equals("")){
			sql+=" and o.isoccupancy = "+isoccupancy;
			csql+=" and o.isoccupancy = "+isoccupancy;
		}
		
		sql+=" order by u.id limit "+(page-1)*pagesize+"," +pagesize;
		String total = new DBHelper().queryField(csql, null, "total");
		Map<String ,String>map = null;
		if(total!=null && !total.equals("")){
			int totalCount = Integer.parseInt(total);
			map = new HashMap<String, String>();
		String otherpaygoods = request.getParameter("otherpaygoods")==null?"":request.getParameter("otherpaygoods");
		String iscompensation = request.getParameter("iscompensation")==null?"":request.getParameter("iscompensation");
		String compensationmoney = request.getParameter("compensationmoney")==null?"":request.getParameter("compensationmoney");
		String compensationgoods = request.getParameter("compensationgoods")==null?"":request.getParameter("compensationgoods");
		String cash = request.getParameter("cash")==null?"":request.getParameter("cash");
		String ChangMoney = request.getParameter("ChangMoney")==null?"":request.getParameter("ChangMoney");
		String time = DateUtil.dateFormat();
		String reg = "^[0-9]+$";
		Pattern p = Pattern.compile(reg);
		if(!(p.matcher(cash)).matches()) return "error:现金格式有误!";
		if(!(p.matcher(ChangMoney)).matches()) return "error:找零格式有误!";
		if(id.equals("")) return "error:房间ID为空";
		if(roomno.equals("")) return "error:房间号为空";
		if(!otherpay.equals("") && Integer.parseInt(otherpay) > 0 && otherpaygoods.equals("")) return "error:其他费用物品不能为空!";
		if(otherpay.equals("")) otherpay = "0";
		if(iscompensation.equals("1")){
			if(compensationmoney.equals("")) return "error:赔偿金额不能为空!";
			if(compensationgoods.equals("")) return "error:赔偿物品不能为空!";
		}else{
			iscompensation = "2";
		}
		
		String rsql = "update rooms set isempty = 1 where roomno = ?";
		int r = new DBHelper().alertData(rsql, new String[]{roomno});
		if(r <=0 ) return "error:修改房间状态失败!";
		
		String osql = "update orders set isoccupancy = 3 where id = ?";
		int o = new DBHelper().alertData(osql, new String[]{id});
		if(o <=0 ) return "error:修改订单状态失败!";
		
		String sql="update orders set iscompensation=?,compensationmoney=?,compensationgoods=? ,otherpay=? ,otherpaygoods=?,cash=?,changemoney=?,outtime=? where id=?";
		String params[]={iscompensation,compensationmoney,compensationgoods,otherpay,otherpaygoods,cash,ChangMoney,time,id};
		int rows = new DBHelper().alertData(sql, params);
		if(rows > 0) return "添加赔偿成功";
		else return "添加赔偿失败!";
	}

	private String lookOrder(HttpServletRequest request,
			HttpServletResponse response) {
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		String isdelete = request.getParameter("isdelete")==null?"":request.getParameter("isdelete");
		
		if(id.equals("")){
			return "error:用户id不能为空!";
		}
		if(name.equals("")){
			return "error:用户名不能为空!";
		}
		String sql = "update users set name = ?,age=?,sex=?,realname=?,phone=?,idcard=? ,isdelete=?where id = ?";
		String params[]={name,age,sex,realname,phone,idcard,isdelete,id};
		
		int rows = new DBHelper().alertData(sql, params);
		if(rows>0){
			return "修改成功!";
		}else
			return "error:修改失败!";
	}

	private String deleteManager(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		if(id.equals("")){
			return "error:用户ID为空";
		}
		String sql = "update users set isdelete = 1 where id = ?";
		int rows = new DBHelper().alertData(sql, new String[]{id});
		if(rows>0){
			return "删除成功";
		}else
		   return "error:删除失败";
	}

	private String addManager(HttpServletRequest request,
			HttpServletResponse response) {
		String sql = "insert into users(id,name,password,age,sex,realname,role,phone,idcard,isdelete)values(?,?,?,?,?,?,?,?,?,?)";
		
		String id = Keys.createKey("U");
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		String password = request.getParameter("password")==null?"":request.getParameter("password");
		String age = request.getParameter("age")==null?"":request.getParameter("age");
		String sex = request.getParameter("sex")==null?"":request.getParameter("sex");
		String realname = request.getParameter("realname")==null?"":request.getParameter("realname");
		String phone = request.getParameter("phone")==null?"":request.getParameter("phone");
		String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
		String cname = "select name from users where name = ?";
		String cnname = new DBHelper().queryField(cname, new String[]{name}, "name");
		if(cnname!=null && !cnname.equals("")) return "error:用户名重复,请修改";
		if(name.equals("")){
			return "error:用户名不能为空!";
		}
		if(password.equals("")){
			return "error:密码不能为空!";
		}
		if(r <= 0) return "error:房间状态修改失败!";
		String osql = "update orders set isoccupancy = 4 where id = ?";
		int o = new DBHelper().alertData(osql, new String[]{oid});
		if(o > 0) return "修改成功!";
		else return "error:取消订单失败!";
	}

	private String findOrderByOrderId(HttpServletRequest request,
			HttpServletResponse response){
		String id = request.getParameter("id").equals("")?"":request.getParameter("id");
		String sql="select o.id,u.name,o.orderno,o.day,o.occupancytime,o.roomno,o.ordertime,o.ordertype,o.ordermoney,o.otherpay,o.otherpaygoods,o.prepay,o.isoccupancy,o.iscompensation,o.compensationmoney,o.compensationgoods from orders o,users u where u.id = o.orderuser and o.id = ?";
		String fields []= {"id","name","orderno","day","occupancytime","roomno","ordertime","ordertype","ordermoney","otherpay","otherpaygoods","prepay","isoccupancy","iscompensation","compensationmoney","compensationgoods"};
		Map<String, String>map = new DBHelper().queryObject(sql, new String[]{id}, fields);
		if(map!=null && !map.isEmpty()) return JSONObject.fromObject(map).toString();
		else return "error:获取订单信息失败";
	}
	private String findCheckOut(HttpServletRequest request,
			HttpServletResponse response) {
		String roomno = request.getParameter("roomno").equals("")?"":request.getParameter("roomno");
		String idcard = request.getParameter("idcard").equals("")?"":request.getParameter("idcard");
		String isoccupancy = request.getParameter("isoccupancy").equals("")?"":request.getParameter("isoccupancy");
		String name = request.getParameter("name").equals("")?"":request.getParameter("name");
		//if(roomno==null || roomno.equals("")) return "error:房间号不能为空!";
		String sql="select o.id,u.name,o.orderno,o.day,o.roomno,o.ordertime,o.occupancytime,o.ordertype,o.ordermoney,o.otherpay,o.otherpaygoods,o.prepay,o.isoccupancy,o.iscompensation,o.compensationmoney,o.compensationgoods from orders o,users u where u.id = o.orderuser and 1=1 ";
		int page=0;
		String prepage = request.getParameter("page")==null?"":request.getParameter("page");
		if(prepage.equals("")){
			page = 1;
		}else page = Integer.parseInt(prepage);
		int pagesize = 5;
		
		String csql="select count(*) total from orders o,users u where u.id=o.orderuser   and 1=1 ";
		if(roomno!=null && !roomno.equals("")){
			sql+="  and o.roomno=  '"+ roomno+"'";
			csql+="  and o.roomno= '"+ roomno+"'";
		}
		if(!name.equals("")){
			sql+="  and u.name=  '"+ name+"'";
			csql+="  and u.name= '"+ name+"'";
		}
		String isoccupancy = request.getParameter("isoccupancy").equals("")?"2":request.getParameter("isoccupancy");
		String occupancytime = request.getParameter("occupancytime")==null?"":request.getParameter("occupancytime");
		if(id.equals("")) return "error:订单Id为空!";
		if(prepay.equals("") ||prepay.equals("0") ) return "error:预付金额为空、!";
		if(roomno.equals("")) return "error:房间号不能为空!";
		
		String rsql = "update rooms set isempty = ? where roomno = ?";
		String isempty = "1";
		if(isoccupancy.equals("1")) isempty = "3";
		if(isoccupancy.equals("2")) isempty = "2";
		if(isoccupancy.equals("3") || isoccupancy.equals("4")) isempty = "1";
		String rparams[]={isempty,roomno};
		int rrows = new DBHelper().alertData(rsql, rparams);
		if(rrows <= 0) return "error:修改房间状态失败";
		String sql = "update orders set prepay = ?,handleuser=?,isoccupancy=?,occupancytime=?  where id = ?";
		String params[]={prepay,handleuser,isoccupancy,occupancytime,id};
		int rows = new DBHelper().alertData(sql, params);
		if(rows > 0) return "成功!";
		else return "error:修改失败";
	}

	private String checkOut(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("oid")==null?"":request.getParameter("oid");
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String otherpay = request.getParameter("otherpay")==null?"":request.getParameter("otherpay");
		String otherpaygoods = request.getParameter("otherpaygoods")==null?"":request.getParameter("otherpaygoods");
		String iscompensation = request.getParameter("iscompensation")==null?"":request.getParameter("iscompensation");
		String compensationmoney = request.getParameter("compensationmoney")==null?"":request.getParameter("compensationmoney");
		String compensationgoods = request.getParameter("compensationgoods")==null?"":request.getParameter("compensationgoods");
		String cash = request.getParameter("cash")==null?"":request.getParameter("cash");
		String ChangMoney = request.getParameter("ChangMoney")==null?"":request.getParameter("ChangMoney");
		String time = DateUtil.dateFormat();
		String reg = "^[0-9]+$";
		Pattern p = Pattern.compile(reg);
		if(!(p.matcher(cash)).matches()) return "error:现金格式有误!";
		if(!(p.matcher(ChangMoney)).matches()) return "error:找零格式有误!";
		if(id.equals("")) return "error:房间ID为空";
		if(roomno.equals("")) return "error:房间号为空";
		if(!otherpay.equals("") && Integer.parseInt(otherpay) > 0 && otherpaygoods.equals("")) return "error:其他费用物品不能为空!";
		if(otherpay.equals("")) otherpay = "0";
		if(iscompensation.equals("1")){
			if(compensationmoney.equals("")) return "error:赔偿金额不能为空!";
			if(compensationgoods.equals("")) return "error:赔偿物品不能为空!";
		}else{
			iscompensation = "2";
		}
		
		String rsql = "update rooms set isempty = 1 where roomno = ?";
		int r = new DBHelper().alertData(rsql, new String[]{roomno});

public class CustomerServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void destroy() {
		super.destroy(); 
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		int state = 0;
		String value = "";
		String cause = "";
		String result = "";
		
		String flag = request.getParameter("flag")==null?"":request.getParameter("flag");
		if(flag.equals("")){
			state = 0;
			result = "error:参数错误!";
		}else if(flag.equals("customerInfo")){
			result = customerInfo(request,response);
		}else if(flag.equals("motifyuser")){
			//修改用户信息
		}
		if(!idcard.equals("")){
			sql+=" and u.idcard = '"+idcard+"'";
			csql+=" and u.idcard = '"+idcard+"'";
		}
		if(!isoccupancy.equals("")){
			sql+=" and o.isoccupancy = "+isoccupancy;
			csql+=" and o.isoccupancy = "+isoccupancy;
		}
		
		sql+=" order by u.id limit "+(page-1)*pagesize+"," +pagesize;
		String total = new DBHelper().queryField(csql, null, "total");
		Map<String ,String>map = null;
		if(total!=null && !total.equals("")){
			int totalCount = Integer.parseInt(total);
			map = new HashMap<String, String>();
			map.put("total", totalCount+"");
			map.put("prepage", page+"");
			map.put("totalPage", (totalCount%pagesize==0?totalCount/pagesize:totalCount/pagesize+1)+"");
			String fields[]={"id","orderno","name","roomno","day","handleuser","ordertime","ordermoney","prepay","ordertype","occupancytime","outtime" ,"isoccupancy","iscompensation","compensationmoney","compensationgoods"};
			List<Map<String, String>> list = new DBHelper().queryObjects(sql, null, fields);
			if(list!=null && list.size()>0){
				list.add(map);
				return JSONArray.fromObject(list).toString();
			}else
				return "error:没有用户的入住信息!";
		}else{
			return "error:没有用户的入住信息!";
		}
	}
	
	
	private String StayCount(HttpServletRequest request,
			HttpServletResponse response) {
		String isoccupancy = request.getParameter("isoccupancy")==null?"":request.getParameter("isoccupancy");
		int page =0;
		String prepage = request.getParameter("page")==null?"":request.getParameter("page");
		if(prepage.equals("")){
			page = 1;
		}else page = Integer.parseInt(prepage);
		int pagesize = 5;
		
		String sql = "select u.id, o.orderno,o.roomno,u.name,u.realname,o.isoccupancy,o.occupancytime,o.outtime,u.idcard,u.phone from orders o,users u where o.orderuser = u.id and 1=1 ";
		String csql = "select count(*) total from orders o,users u where o.orderuser = u.id and 1=1 ";
		if(isoccupancy!=null && !isoccupancy.equals("")){
				json.accumulateAll(map);
			}*/
			return JSONArray.fromObject(list).toString();
		}else{
			return "error:管理员信息未获取到!";
		}
	}

	public void init() throws ServletException {
		 
	}

}

public class CustomerServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void destroy() {
		super.destroy(); 
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String oparams[]={oid,orderno,orderuser,handleuser,ordertime,ordermoney,ordertype,roomno,isoccupancy,occupancytime,day,prepay};
		int orows = new DBHelper().alertData(osql, oparams);
		if(orows > 0) return "下单成功";
		else return "error:用户添加成功,但下单失败";
		
		
	}

	private String editOrder(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("orderId")==null?"":request.getParameter("orderId");
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String handleuser = ((Users)request.getSession().getAttribute("user")).getId();
		String prepay = request.getParameter("prepay").equals("")?"0":request.getParameter("prepay");
		String isoccupancy = request.getParameter("isoccupancy").equals("")?"2":request.getParameter("isoccupancy");
		String occupancytime = request.getParameter("occupancytime")==null?"":request.getParameter("occupancytime");
		if(id.equals("")) return "error:订单Id为空!";
		if(prepay.equals("") ||prepay.equals("0") ) return "error:预付金额为空、!";
		if(roomno.equals("")) return "error:房间号不能为空!";
		
		String rsql = "update rooms set isempty = ? where roomno = ?";
		String isempty = "1";
		if(isoccupancy.equals("1")) isempty = "3";
		if(isoccupancy.equals("2")) isempty = "2";
		if(isoccupancy.equals("3") || isoccupancy.equals("4")) isempty = "1";
		String rparams[]={isempty,roomno};
		int rrows = new DBHelper().alertData(rsql, rparams);
		if(rrows <= 0) return "error:修改房间状态失败";
		String sql = "update orders set prepay = ?,handleuser=?,isoccupancy=?,occupancytime=?  where id = ?";
		String params[]={prepay,handleuser,isoccupancy,occupancytime,id};
		int rows = new DBHelper().alertData(sql, params);
		if(rows > 0) return "成功!";
		else return "error:修改失败";
	}

	private String checkOut(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("oid")==null?"":request.getParameter("oid");
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String otherpay = request.getParameter("otherpay")==null?"":request.getParameter("otherpay");
		String otherpaygoods = request.getParameter("otherpaygoods")==null?"":request.getParameter("otherpaygoods");
		String iscompensation = request.getParameter("iscompensation")==null?"":request.getParameter("iscompensation");
		String compensationmoney = request.getParameter("compensationmoney")==null?"":request.getParameter("compensationmoney");
		String compensationgoods = request.getParameter("compensationgoods")==null?"":request.getParameter("compensationgoods");
		String cash = request.getParameter("cash")==null?"":request.getParameter("cash");
		String ChangMoney = request.getParameter("ChangMoney")==null?"":request.getParameter("ChangMoney");
		String time = DateUtil.dateFormat();
		String reg = "^[0-9]+$";
		Pattern p = Pattern.compile(reg);
		if(!(p.matcher(cash)).matches()) return "error:现金格式有误!";
		
	}

	private String messages(HttpServletRequest request,
			HttpServletResponse response) {
		String sql = "select m.id,m.title,m.content,u.name as user,m.time from message m,users u  where m.messageuser = u.id";
		List<Map<String, String>>list = new DBHelper().queryObjects(sql, null, new String[]{"id","title","content","user","time"});
		if(list!=null && list.size()>0){
			return JSONArray.fromObject(list).toString();
		}else  return "error:未获取到留言信息";
	}

	private String findRoom(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		if(id.equals("")) return "error:ID不能为空!";
		String sql = "select * from rooms where id = ?";
		String params[]={id};
		String fields[]={"id","roomno","type","price","isempty","des","pic"};
		Map<String, String> map = new DBHelper().queryObject(sql, params, fields);
		if(map!=null && !map.isEmpty()){
			if(map.containsKey("pic") &&( map.get("pic")==null || map.get("pic").equals(""))){
				map.put("pic", "");
			}else{
				map.put("pic",request.getRequestURL().toString().split("SLH")[0]+"SLH"+"/"+ImageUtil.PATH+"/"+map.get("pic"));
			}
			return JSONObject.fromObject(map).toString();
		}else
			return "error:房间信息未查到!";
	}

	private String findManager(HttpServletRequest request,
			HttpServletResponse response) {
		String uid = request.getParameter("uid")==null?"":request.getParameter("uid");
		if(uid.equals("")){
			return "error:用户ID不能为空!";
		}
		String sql = "select * from users where id = ?";
		String params[]={uid};
		String fields[]={"id","name","age","sex","realname","role","phone","idcard","isdelete"};
		Map<String, String>map = new DBHelper().queryObject(sql, params, fields);
		if(map!=null && !map.isEmpty()){
			return JSONObject.fromObject(map).toString();
		}else
			return "error:用户信息未获取到!";
	}

	private String  addDiscount(HttpServletRequest request,
			HttpServletResponse response) {
		String id = Keys.createKey("D");
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		String desc = request.getParameter("desc")==null?"":request.getParameter("desc");
		String userID = ((Users)request.getSession().getAttribute("user")).getId();
			}else
				return "error:未获取到房间的信息";
		}else return "error:未获取到房间的信息";
		
		
	}

	private String editManager(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		String age = request.getParameter("age")==null?"":request.getParameter("age");
		String sex = request.getParameter("sex")==null?"":request.getParameter("sex");
		String realname = request.getParameter("realname")==null?"":request.getParameter("realname");
		String phone = request.getParameter("phone")==null?"":request.getParameter("phone");
		String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
		String isdelete = request.getParameter("isdelete")==null?"":request.getParameter("isdelete");
		
		if(id.equals("")){
			return "error:用户id不能为空!";
		}
		if(name.equals("")){
			return "error:用户名不能为空!";
		}
		String sql = "update users set name = ?,age=?,sex=?,realname=?,phone=?,idcard=? ,isdelete=?where id = ?";
		String params[]={name,age,sex,realname,phone,idcard,isdelete,id};
		
		int rows = new DBHelper().alertData(sql, params);
		if(rows>0){
			return "修改成功!";
		}else
			return "error:修改失败!";
	}

	private String deleteManager(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		if(id.equals("")){
			return "error:用户ID为空";
		}
		String sql = "update users set isdelete = 1 where id = ?";
		int rows = new DBHelper().alertData(sql, new String[]{id});
		if(rows>0){
			return "删除成功";
		}else
		   return "error:删除失败";
	}
		String sql = "insert into rooms(id,roomno,type,price,isempty,des,pic)values(?,?,?,?,?,?,?)";
		String params[]={id,roomno,type,price,isempty,des,pic};
		
		int rows = new DBHelper().alertData(sql, params);
		if(rows>0) return "成功!";
		else return "error:添加失败";
		
	}

	private String rooms(HttpServletRequest request, HttpServletResponse response) {
		String type = request.getParameter("type")==null?"":request.getParameter("type");
		String price = request.getParameter("price")==null?"":request.getParameter("price");
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String isempty = request.getParameter("isempty")==null?"":request.getParameter("isempty");
		int page=0;
		String prepage = request.getParameter("page")==null?"":request.getParameter("page");
		if(prepage.equals("")){
			page = 1;
		}else page = Integer.parseInt(prepage);
		int pagesize = 5;
		String csql="select count(*) total from rooms where  1=1 " ;
		String sql = "select id,roomno,type,price,isempty,des,pic from rooms where  1=1 ";
		if(!type.equals("")){
			sql+= " and type="+type+"";
			csql+= " and type="+type+"";
		}
		if(!price.equals("")){
			String s[]= price.split("-");
			sql +=" and price between "+s[0]+ " and "+s[1] ; 
			csql +=" and price between "+s[0]+ " and "+s[1] ; 
		}
		if(!roomno.equals("")){
			sql += " and roomno = '" + roomno+"'";
			csql += " and roomno = '" + roomno+"'";
		}
		if(!isempty.equals("")){ 
			sql += " and isempty = "+isempty;
			csql += " and isempty = "+isempty;
		}
		
		sql += "  order by id limit "+(page-1)*pagesize + ","+pagesize+"";
		String conmoney = request.getParameter("conmoney")==null?"":request.getParameter("conmoney");
		if(id.equals("")) return "error:id不能为空";
		if(conday.equals("")) return "error:续费天数不能为空";else day = Integer.parseInt(conday);
		if(conmoney.equals("")) return "error:续费金额不能为空";else money = Double.parseDouble(conmoney);
		String sql = "update orders set day = day+"+day+" , prepay=prepay+"+money +" where id = '"+id+"'";
		int rows = new DBHelper().alertData(sql, null);
		if(rows>0) return "成功!";
		else return "error:失败";
	}

	private String change(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("orderId")==null?"":request.getParameter("orderId");
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String handleuser = ((Users)request.getSession().getAttribute("user")).getId();
		String oldroomno = request.getParameter("oldroomno")==null?"":request.getParameter("oldroomno");
		if(id.equals("")) return "error:订单Id为空!";
		if(roomno.equals("")) return "error:房间号不能为空!";
		
		String rsql = "update rooms set isempty = ? where roomno = ?";
		String isempty = "3";
		String rparams[]={isempty,roomno};
		int rrows = new DBHelper().alertData(rsql, rparams);
		if(rrows <= 0) return "error:修改房间状态失败";
		
		rsql = "update rooms set isempty = ? where roomno = ?";
		isempty="1";
		String oparams[]={isempty,oldroomno};
		rrows = new DBHelper().alertData(rsql, oparams);
		if(rrows <= 0) return "error:修改房间状态失败";
		
		String sql = "update orders set roomno = ?,handleuser=?  where id = ?";
		String params[]={roomno,handleuser,id};
		int rows = new DBHelper().alertData(sql, params);
		if(rows > 0) return "成功!";
		else return "error:修改失败";
	}
	private String changeRoom(HttpServletRequest request,
			HttpServletResponse response) {
		String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
		String isoccupancy = request.getParameter("isoccupancy")==null?"":request.getParameter("isoccupancy");
		String sql = "select o.id,o.orderno,u.name,o.roomno,o.handleuser,o.ordertime,o.ordermoney,o.prepay,o.ordertype,o.occupancytime,o.outtime ,o.isoccupancy,o.iscompensation,o.compensationmoney,o.day,o.compensationgoods from orders o,users u where u.id=o.orderuser and o.isoccupancy not in(3,4) and 1=1";
		int page=0;
		String prepage = request.getParameter("page")==null?"":request.getParameter("page");
		}else if(flag.equals("editOrder")){
			//前台修改订单信息
			result = editOrder(request,response);
		}else if (flag.equals("addCusAndOrder")){
			//前台添加用户和订单
			result = addCusAndOrder(request,response);
		}else if (flag.equals("StayCount")){
			//入住统计
			result = StayCount(request,response);
		}else if (flag.equals("repairing")){
			//报修
			result = repairing(request,response);
		}else if(flag.equals("repairCount")){
			//报修列表
			result = repairCount(request,response);
		}else if (flag.equals("findRoomNoRepir")){
			//获取所有的房间号
			result = findRoomNo(request,response);
		}else if (flag.equals("lookOrder")){
			//订单查看
			result = lookOrder(request,response);
		}else if(flag.equals("findCheckOut")){
			//获取退房信息
			result = findCheckOut(request,response);
		}else if(flag.equals("checkOut")){
			//退房
			result = checkOut(request,response);
		}else if(flag.equals("findOrderByOrderId")){
			//通过订单ID获取订单信息
			result = findOrderByOrderId(request,response);
		}else if(flag.equals("findExitUser")){
			//查看用户是否存在
			result = findExitUser(request,response);
		}else if(flag.equals("findRoomNo")){
			//获取房间号
			result = findRoomNo(request,response);
		}else if(flag.equals("findRoomPrice")){
			//获取房间的价格
			result = findRoomPrice(request,response);
		}else if(flag.equals("delOrder")){
			//删除订单
			result = delOrder(request,response);
		}else if (flag.equals("findOrderStatus")){
			//查看订单状态
			result = findOrderStatus(request,response);
		if(!idcard.equals("")){
			sql+=" and u.idcard = '"+idcard+"'";
			csql+=" and u.idcard = '"+idcard+"'";
		}
		if(!isoccupancy.equals("")){
			sql+=" and o.isoccupancy = "+isoccupancy;
			csql+=" and o.isoccupancy = "+isoccupancy;
		}
		
		sql+=" order by u.id limit "+(page-1)*pagesize+"," +pagesize;
		String total = new DBHelper().queryField(csql, null, "total");
		Map<String ,String>map = null;
		if(total!=null && !total.equals("")){
			int totalCount = Integer.parseInt(total);
			map = new HashMap<String, String>();
			map.put("total", totalCount+"");
			map.put("prepage", page+"");
			map.put("totalPage", (totalCount%pagesize==0?totalCount/pagesize:totalCount/pagesize+1)+"");
			String fields[]={"id","orderno","name","roomno","day","handleuser","ordertime","ordermoney","prepay","ordertype","occupancytime","outtime" ,"isoccupancy","iscompensation","compensationmoney","compensationgoods"};
			List<Map<String, String>> list = new DBHelper().queryObjects(sql, null, fields);
			if(list!=null && list.size()>0){
				list.add(map);
				return JSONArray.fromObject(list).toString();
			}else
				return "error:没有用户的入住信息!";
		}else{
			return "error:没有用户的入住信息!";
		}
	}
	
	
	private String StayCount(HttpServletRequest request,
			HttpServletResponse response) {
		String isoccupancy = request.getParameter("isoccupancy")==null?"":request.getParameter("isoccupancy");
		int page =0;
		String prepage = request.getParameter("page")==null?"":request.getParameter("page");
		if(prepage.equals("")){
			page = 1;
		}else page = Integer.parseInt(prepage);
		int pagesize = 5;
		
		String sql = "select u.id, o.orderno,o.roomno,u.name,u.realname,o.isoccupancy,o.occupancytime,o.outtime,u.idcard,u.phone from orders o,users u where o.orderuser = u.id and 1=1 ";
		String csql = "select count(*) total from orders o,users u where o.orderuser = u.id and 1=1 ";
		if(isoccupancy!=null && !isoccupancy.equals("")){
			sql += "and isoccupancy = "+isoccupancy;
			csql += "and isoccupancy = "+isoccupancy;
		}
		sql += " order by u.id limit "+(page-1)*pagesize+","+pagesize;
		
	}

	private String delOrder(HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		if(id==null || id.equals("")) return "订单编号不能为空!";
		String sql = "delete from orders where id = ?";
		//获取删除订单的所对应房间的ID
		String csql ="select r.id from rooms r, orders o where o.roomno = r.roomno and o.id=?";
		String rid = new DBHelper().queryField(csql, new String[]{id}, "id");
		if(rid!=null && !rid.equals("")){
			//修改房间状态
			String rsql = "update rooms set isempty = ? where id = ?";
			String rparams[]={"1",rid};
			int rrows = new DBHelper().alertData(rsql, rparams);
			if(rrows <= 0) return "error:修改房间状态失败";
			else {
				//删除订单
				int rows = new DBHelper().alertData(sql, new String[]{id});
				if(rows > 0) return "订单删除成功!";
				else return "error:订单删除失败!";
			}
		}else return "error:获取房间ID失败!";
		
	}
	private String findOrderStatus(HttpServletRequest request,
			HttpServletResponse response){
		String sql="select isoccupancy from orders where id = ?";
		String id = request.getParameter("id")==null?"":request.getParameter("id");
		if(id==null || id.equals("")) return "error:订单编号不能为空!";
		String isoccupancy = new DBHelper().queryField(sql, new String[]{id}, "isoccupancy");
		if(isoccupancy!=null && !isoccupancy.equals("")){
			return isoccupancy;
		}else
			return "error:获取订单状态失败";
	}

	public String findExitUser(HttpServletRequest request,
			HttpServletResponse response){
		String name = request.getParameter("name")==null?"":request.getParameter("name");
		if(name.equals("")) return "error:用户名为空";
		String sql = "select id, name,password,realname,idcard,phone,role from users where name = ?";
		Map<String, String>map = new DBHelper().queryObject(sql, new String[]{name}, new String[]{"id","name","password","realname","idcard","phone","role"});
		if(map!=null && !map.isEmpty()){

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值