基于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项目
技术栈
- 后端:Servlet 2. 前端:JSP+bootstrap+jQuery
使用说明
- 使用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
if(result.indexOf("error")!=-1){
state = 0;
value = result.substring(6,result.length());
}else{
state = 1;
value =result;
}
System.out.println(value.replace("\"", "'"));
out.println("{\"state\":\""+state+"\",\"value\":\""+value.replace("\"", "'")+"\",\"cause\":\""+cause+"\"}");
out.flush();
out.close();
}
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("")){
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();
String time = DateUtil.dateFormat();
if(name.equals("")){
return "error:名称不能为空!";
}
if(desc.equals("")){
return "error:请填写描述....";
}
String sql="insert into discount values(?,?,?,?,?)";
String params[]={id,name,desc,userID,time};
int rows = new DBHelper().alertData(sql, params);
if(rows>0){
return "成功!";
}else
return "error:添加失败!";
}
private String discounts(HttpServletRequest request,
HttpServletResponse response) {
String sql="select d.id,d.name,d.desc,u.name as username,d.time from discount as d inner join users as u where d.releaseuser = u.id";
String fields[]={"id","name","desc","username","time"};
List<Map<String,String>> list = new DBHelper().queryObjects(sql, null, fields);
if(list!=null && list.size()>0){
return JSONArray.fromObject(list).toString();
}else
return "error:没有获取到优惠信息!";
}
private String editRoom(HttpServletRequest request,
HttpServletResponse response) {
String id = request.getParameter("id")==null?"":request.getParameter("id");
String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
String type = request.getParameter("type")==null?"":request.getParameter("type");
String price = request.getParameter("price")==null?"":request.getParameter("price");
String isempty = request.getParameter("isempty")==null?"":request.getParameter("isempty");
String desc = request.getParameter("des")==null?"":request.getParameter("des");
u.setIdcard(map.get("idcard"));
request.getSession().setAttribute("user", u);
return "登陆成功";
}else{
return "error:用户密码错误!";
}
}
public String register(HttpServletRequest request, HttpServletResponse response){
String name = request.getParameter("name")==null?"":request.getParameter("name");
String password = request.getParameter("password")==null?"":request.getParameter("password");
String realname = request.getParameter("realname")==null?"":request.getParameter("realname");
String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
String phone = request.getParameter("phone")==null?"":request.getParameter("phone");
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(realname.equals("")) return "error:真实姓名为空!";
if(idcard.equals("")) return "error:身份证号码为空!";
if(phone.equals("")) return "error:手机号码为空!";
String id = Keys.createKey("U");
String sql = "insert into users(id,name,password,realname,idcard,phone,role,isdelete) values(?,?,?,?,?,?,?,?)";
String params[]={id,name,password,realname,idcard,phone,"3","0"};
int rows = new DBHelper().alertData(sql, params);
if(rows>0){
return "注册成功";
}else{
return "error:注册失败!";
}
}
public void init() throws ServletException {
}
public static void main(String[] args) {
int state = 1;
String value = "";
String cause = "";
String result = "";
response.setContentType("text/html,charset=utf-8");
PrintWriter out = response.getWriter();
String flag = request.getParameter("flag")==null?"":request.getParameter("flag");
if(flag.equals("")){
result = "error:参数错误!";
}else if (flag.equals("managers")){
//前台管理员列表
result = managers(request, response);
}else if(flag.equals("addManager")){
//添加
result = addManager(request,response);
}else if(flag.equals("deleteManager")){
//删除
result = deleteManager(request,response);
}else if(flag.equals("editManager")){
//编辑
result = editManager(request,response);
}else if (flag.equals("rooms")){
//客房列表
result = rooms(request,response);
}else if (flag.equals("addRoom")){
//添加客房
result = addRoom(request,response);
}else if(flag.equals("deleteRoom")){
//删除客房
result = deleteRoom(request,response);
}else if (flag.equals("editRoom")){
//编辑客房
result = editRoom(request,response);
}else if (flag.equals("discounts")){
//优惠折扣列表
result = discounts(request,response);
}else if(flag.equals("addDiscount")){
//添加折扣
result = addDiscount(request,response);
}else if(flag.equals("findManager")){
result = findManager(request,response);
}else if(flag.equals("findRoom")){
result = findRoom(request,response);
}else if(flag.equals("messages")){
//留言查看
result = messages(request,response);
}
if(result.indexOf("error")!=-1){
state = 0;
}
package com.slh.code.servlet;
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")){
String name = request.getParameter("name")==null?"":request.getParameter("name");
String password = request.getParameter("password")==null?"":request.getParameter("password");
String realname = request.getParameter("realname")==null?"":request.getParameter("realname");
String idcard = request.getParameter("idcard")==null?"":request.getParameter("idcard");
String phone = request.getParameter("phone")==null?"":request.getParameter("phone");
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(realname.equals("")) return "error:真实姓名为空!";
if(idcard.equals("")) return "error:身份证号码为空!";
if(phone.equals("")) return "error:手机号码为空!";
id = Keys.createKey("U");
String sql = "insert into users(id,name,password,realname,idcard,phone,role,isdelete) values(?,?,?,?,?,?,?,?)";
String params[]={id,name,password,realname,idcard,phone,"3","0"};
int rows = new DBHelper().alertData(sql, params);
if(rows <= 0) return "error:添加用户失败!";
}else{
//用户注册过
id = uid;
}
String oid = Keys.createKey("O");
String orderno = Keys.createKey("SLH");
String orderuser = id;
String handleuser = ((Users)request.getSession().getAttribute("user")).getId();
String ordertime = DateUtil.dateFormat();
String ordermoney = request.getParameter("ordermoney")==null?"":request.getParameter("ordermoney");
String ordertype = request.getParameter("ordertype")==null?"":request.getParameter("ordertype");
String roomno = request.getParameter("roomno")==null?"":request.getParameter("roomno");
String occupancytime = request.getParameter("occupancytime")==null?"":request.getParameter("occupancytime");
String day = request.getParameter("day")==null?"1":request.getParameter("day");
String isoccupancy = request.getParameter("isoccupancy")==null?"1":request.getParameter("isoccupancy");
String prepay = request.getParameter("prepay")==null?"1":request.getParameter("prepay");
if(roomno.equals("")) return "error:房间号不能为空!";
if(ordermoney.equals("")) return "error:订单价格不能为空";
if(occupancytime.equals("")) return "error:入住时间不能为空!";
if(isoccupancy.equals("")) isoccupancy="1";
if(ordertype.equals("3") && prepay.equals("")) return "error:前台订房需要预交定金!";
String rsql = "update rooms set isempty = ? where roomno = ?";
String isempty = "1";
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 {
PrintWriter out = response.getWriter();
int state = 0;
String value = "";
String cause = "";
String flag = request.getParameter("flag")==null?"":request.getParameter("flag").replaceAll("[\t\n\r]", "");
if(flag.equals("login")){
//登陆
String result = this.login(request, response);
if(result.indexOf("error")!=-1){
state = 0;
value = result.substring(6, result.length());
}else{
state = 1;
value = result;
}
}else if(flag.equals("register")){
//注册
String result = this.register(request, response);
if(result.indexOf("error")!=-1){
state = 0;
value = result.substring(6, result.length());
}else{
state = 1;
value = result;
}
} else if(flag.equals("exit")){
//退出系统
request.getSession().removeAttribute("user");
if(request.getSession().getAttribute("user")!=null && !request.getSession().getAttribute("user").equals("") ){
state = 0;
value = "退出系统失败!";
}else{
state = 1;
value = "成功!";
}
}else{
state = 0;
value = "参数错误!";
}
System.out.println("{'state':'"+state+"','value':'"+value+"','cause':'"+cause+"'}");
out.println("{\"state\":\""+state+"\",\"value\":\""+value+"\",\"cause\":\""+cause+"\"}");
out.close();
}
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+"");
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;
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()){
if(!map.get("role").equals("3")) return "error:@@@@该用户为内部人员,不可订房!";
return JSONObject.fromObject(map).toString();
}
}
public void init() throws ServletException {
}
}
package com.slh.code.servlet;
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();
if(map2.containsKey("pic") &&( map2.get("pic")==null || map2.get("pic").equals(""))){
map2.put("pic", "");
}else{
map2.put("pic",request.getRequestURL().toString().split("SLH")[0]+"SLH"+"/"+ImageUtil.PATH+"/"+map2.get("pic"));
}
}
list.add(map);
return JSONArray.fromObject(list).toString();
}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:修改失败!";
}
}else{
state = 1;
value = result;
}
}else if(flag.equals("register")){
//注册
String result = this.register(request, response);
if(result.indexOf("error")!=-1){
state = 0;
value = result.substring(6, result.length());
}else{
state = 1;
value = result;
}
} else if(flag.equals("exit")){
//退出系统
request.getSession().removeAttribute("user");
if(request.getSession().getAttribute("user")!=null && !request.getSession().getAttribute("user").equals("") ){
state = 0;
value = "退出系统失败!";
}else{
state = 1;
value = "成功!";
}
}else{
state = 0;
value = "参数错误!";
}
System.out.println("{'state':'"+state+"','value':'"+value+"','cause':'"+cause+"'}");
out.println("{\"state\":\""+state+"\",\"value\":\""+value+"\",\"cause\":\""+cause+"\"}");
out.close();
}
public String login(HttpServletRequest request, HttpServletResponse response){
String username = request.getParameter("username")==null?"":request.getParameter("username").replaceAll("[\t\r\n]", "");
if(username.equals("")){
return "error:用户名不能为空";
}
String sql_name = "select name from users where name =?";
String name = new DBHelper().queryField(sql_name, new String []{username}, "name");
if(name == null || name.equals("")){
return "error:用户名不存在!";
if(result.indexOf("error")!=-1){
state = 0;
value = result.substring(6,result.length());
}else{
state = 1;
value =result;
}
System.out.println(value.replaceAll("\"", "'"));
out.println("{\"state\":\""+state+"\",\"value\":\""+value.replaceAll("\"", "'")+"\",\"cause\":\""+cause+"\"}");
out.flush();
out.close();
}
private String continu(HttpServletRequest request,
HttpServletResponse response) {
int day =0;
double money = 0;
String id = request.getParameter("id")==null?"":request.getParameter("id");
String conday = request.getParameter("conday")==null?"":request.getParameter("conday");
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 = ?";
}else if(flag.equals("orderRoom")){
result = orderRoom(request,response);
}else if(flag.equals("orderLook")){
result = orderLook(request,response);
}else if(flag.equals("findOrderById")){
//获取单个订单信息
result = findOrderById(request,response);
}else if(flag.equals("editOrder")){
result = editOrder(request,response);
}else if(flag.equals("deleteOrder")){
result = deleteOrder(request,response);
}else if(flag.equals("message")){
//留言
result = message(request,response);
}
if(result.indexOf("error")!=-1){
state = 0;
value = result.substring(6,result.length());
}else{
state = 1;
value =result;
}
System.out.println(value);
out.println("{\"state\":\""+state+"\",\"value\":\""+value.replaceAll("\"", "'")+"\",\"cause\":\""+cause+"\"}");
out.flush();
out.close();
}
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]+$";
}
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 content = request.getParameter("content")==null?"":request.getParameter("content");
String messageuser = ((Users)request.getSession().getAttribute("user")).getId();
String time = DateUtil.dateFormat();
if(title.equals("")) return "error:标题不能为空!";
if(content.equals("")) return "error:内容不能为空!";
String sql = "insert into message(id,title,content,messageuser,time)values(?,?,?,?,?)";
String params[]={id,title,content,messageuser,time};
int rows = new DBHelper().alertData(sql, params);
if(rows >0) return "成功!";
else return "error:留言失败!";
}
private String deleteOrder(HttpServletRequest request,
HttpServletResponse response) {
String id= request.getParameter("id")==null?"":request.getParameter("id");
if(id.equals("")) return "error:订单ID不能为空!";
String sql = "delete from orders where id = ?";
String params[]={id};
int rows = new DBHelper().alertData(sql, params);
if(rows > 0) return "成功";
else return "error:删除订单失败!";
}
private String editOrder(HttpServletRequest request,
HttpServletResponse response) {
String id = request.getParameter("id")==null?"":request.getParameter("id");
String occupancytime = request.getParameter("occupancytime")==null?"":request.getParameter("occupancytime");
String day = request.getParameter("day")==null?"":request.getParameter("day");
if(id.equals("")) return "error:订单ID不能为空!";
if(occupancytime.equals("")) return "error:入住时间不能为空!";
if(day.equals("")) return "error:入住天数不能为空!";
state = 1;
value = result;
}
} else if(flag.equals("exit")){
//退出系统
request.getSession().removeAttribute("user");
if(request.getSession().getAttribute("user")!=null && !request.getSession().getAttribute("user").equals("") ){
state = 0;
value = "退出系统失败!";
}else{
state = 1;
value = "成功!";
}
}else{
state = 0;
value = "参数错误!";
}
System.out.println("{'state':'"+state+"','value':'"+value+"','cause':'"+cause+"'}");
out.println("{\"state\":\""+state+"\",\"value\":\""+value+"\",\"cause\":\""+cause+"\"}");
out.close();
}
public String login(HttpServletRequest request, HttpServletResponse response){
String username = request.getParameter("username")==null?"":request.getParameter("username").replaceAll("[\t\r\n]", "");
if(username.equals("")){
return "error:用户名不能为空";
}
String sql_name = "select name from users where name =?";
String name = new DBHelper().queryField(sql_name, new String []{username}, "name");
if(name == null || name.equals("")){
return "error:用户名不存在!";
}
String password = request.getParameter("password")==null?"":request.getParameter("password").replaceAll("[\r\t\n]", "");
if(password.equals("")){
return "error:密码不能为空!";
}
String sql = "select * from users where name = ? and password = ?";
String fields[] = new String[]{"id","name","age","sex","realname","role","phone","idcard"};
Map<String, String>map = new DBHelper().queryObject(sql, new String[]{username,password}, fields);
if(map!=null && !map.isEmpty()){
Users u = new Users();
u.setId(map.get("id"));
u.setName(map.get("name"));
map.put("prepage", page+"");
map.put("totalPage", (totalCount%pagesize==0?totalCount/pagesize:totalCount/pagesize+1)+"");
List<Map<String, String>>list = new DBHelper().queryObjects(sql, null, new String[]{"id","roomno","type","price","isempty","des","pic"});
if(list!=null && list.size()>0){
for (Map<String, String> map2 : list) {
//System.out.println(map2.get("pic").equals(""));
if(map2.containsKey("pic") &&( map2.get("pic")==null || map2.get("pic").equals(""))){
map2.put("pic", "");
}else{
map2.put("pic",request.getRequestURL().toString().split("SLH")[0]+"SLH"+"/"+ImageUtil.PATH+"/"+map2.get("pic"));
}
}
list.add(map);
return JSONArray.fromObject(list).toString();
}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){
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;
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","roomno","name","realname","isoccupancy","occupancytime","outtime","idcard","phone"};
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 cancleOrder(HttpServletRequest request,