|
@@ -3,12 +3,14 @@ package com.happy.action;
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
import com.happy.Model.Admin;
|
|
import com.happy.Model.Admin;
|
|
|
|
|
+import com.happy.Model.AdminManager;
|
|
|
import com.happy.Model.Booking;
|
|
import com.happy.Model.Booking;
|
|
|
import com.happy.Model.House;
|
|
import com.happy.Model.House;
|
|
|
import com.happy.Until.GetHttpParam;
|
|
import com.happy.Until.GetHttpParam;
|
|
|
import com.happy.Until.PwdDefind;
|
|
import com.happy.Until.PwdDefind;
|
|
|
import com.happy.Until.ResUtil;
|
|
import com.happy.Until.ResUtil;
|
|
|
import com.happy.Until.ResponseUtil;
|
|
import com.happy.Until.ResponseUtil;
|
|
|
|
|
+import com.happy.dto.IPage;
|
|
|
import com.happy.service.BookService;
|
|
import com.happy.service.BookService;
|
|
|
import com.happy.service.HouseService;
|
|
import com.happy.service.HouseService;
|
|
|
import com.opensymphony.xwork2.ActionSupport;
|
|
import com.opensymphony.xwork2.ActionSupport;
|
|
@@ -33,6 +35,7 @@ public class houseAction extends ActionSupport implements ServletRequestAware {
|
|
|
public BookService bookService;
|
|
public BookService bookService;
|
|
|
|
|
|
|
|
public Integer id;
|
|
public Integer id;
|
|
|
|
|
+ public String hName;//房型名称
|
|
|
public int page; // 当前页
|
|
public int page; // 当前页
|
|
|
public int rows;// 每页显示的行数rows
|
|
public int rows;// 每页显示的行数rows
|
|
|
|
|
|
|
@@ -56,4 +59,203 @@ public class houseAction extends ActionSupport implements ServletRequestAware {
|
|
|
this.response = response;
|
|
this.response = response;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 描述:新增房型
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public String insterHouser(){
|
|
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
|
|
|
|
|
+ if (json == null) {
|
|
|
|
|
+ resultJson.put("message", "请传入参数");
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ House house = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ house = gson.fromJson(json.toString(), new TypeToken<House>() {}.getType());
|
|
|
|
|
+ if (house == null) {
|
|
|
|
|
+ resultJson.put("message", "数据为空");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (house.getManagerId()==null || house.gethName()==null || house.getPrice()==null || house.getNumber()==null || house.gethAreas()==null){
|
|
|
|
|
+ resultJson.put("message", "各参数不能为空");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ StringBuilder getOneSqlx = new StringBuilder("");
|
|
|
|
|
+ getOneSqlx.append(" and h_name = '").append(house.gethName()).append("'");
|
|
|
|
|
+ House listc = houseService.getOen(getOneSqlx.toString());
|
|
|
|
|
+ if (listc != null) {
|
|
|
|
|
+ resultJson.put("message", "房型已存在");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ int m = houseService.insertHouse(house);
|
|
|
|
|
+ if (m > 0) {
|
|
|
|
|
+ resultJson.put("message", "新增成功");
|
|
|
|
|
+ resultJson.put("code", 200);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resultJson.put("message", "新增失败");
|
|
|
|
|
+ resultJson.put("code", 502);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ resultJson.put("message", "未知异常");
|
|
|
|
|
+ resultJson.put("code", 205);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 描述:修改房型
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public String updateHouser(){
|
|
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
|
|
|
|
|
+ if (json == null) {
|
|
|
|
|
+ resultJson.put("message", "请传入参数");
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ House house = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ house = gson.fromJson(json.toString(), new TypeToken<House>() {}.getType());
|
|
|
|
|
+ if (house == null) {
|
|
|
|
|
+ resultJson.put("message", "数据为空");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (house.getId() == null) {
|
|
|
|
|
+ resultJson.put("message", "房型Id为空");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (house.getManagerId()==null || house.gethName()==null || house.getPrice()==null || house.getNumber()==null || house.gethAreas()==null){
|
|
|
|
|
+ resultJson.put("message", "各参数不能为空");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ StringBuilder getOneSqlx = new StringBuilder("");
|
|
|
|
|
+ getOneSqlx.append(" and h_name = '").append(house.gethName()).append("'");
|
|
|
|
|
+ getOneSqlx.append(" and id != '").append(house.getId()).append("'");
|
|
|
|
|
+ House listc = houseService.getOen(getOneSqlx.toString());
|
|
|
|
|
+ if (listc != null) {
|
|
|
|
|
+ resultJson.put("message", "房型已存在");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ int m = houseService.updateHouse(house);
|
|
|
|
|
+ if (m > 0) {
|
|
|
|
|
+ resultJson.put("message", "修改成功");
|
|
|
|
|
+ resultJson.put("code", 200);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resultJson.put("message", "修改败");
|
|
|
|
|
+ resultJson.put("code", 502);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ resultJson.put("message", "未知异常");
|
|
|
|
|
+ resultJson.put("code", 205);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 描述:删除房型
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public String delHouser(){
|
|
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
|
|
+ if (id == null) {
|
|
|
|
|
+ resultJson.put("message", "请传入id");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ int m = houseService.delHouse(id);
|
|
|
|
|
+ if (m > 0) {
|
|
|
|
|
+ resultJson.put("message", "删除成功");
|
|
|
|
|
+ resultJson.put("code", 200);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ resultJson.put("message", "未知异常");
|
|
|
|
|
+ resultJson.put("code", 205);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 描述:根据Id查询详细
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public String getById(){
|
|
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
|
|
+ if (id == null) {
|
|
|
|
|
+ resultJson.put("message", "请传入id");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ House house = houseService.getById(id);
|
|
|
|
|
+ if (house != null) {
|
|
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
|
|
+ resultJson.put("code", 200);
|
|
|
|
|
+ resultJson.put("date", house);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ resultJson.put("message", "未查到信息");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 描述:分页查询
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public String queryPage(){
|
|
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
|
|
+ StringBuilder s1 = new StringBuilder("");
|
|
|
|
|
+ if (hName!=null){
|
|
|
|
|
+ s1.append(" and h_name like '%").append(hName).append("'");
|
|
|
|
|
+ }
|
|
|
|
|
+ IPage<House> houseIPage = houseService.queryPage(s1.toString(),page,rows);
|
|
|
|
|
+ if(houseIPage!=null && !"".equals(houseIPage)){
|
|
|
|
|
+ resultJson.put("message", "查询分页成功");
|
|
|
|
|
+ resultJson.put("code", 200);
|
|
|
|
|
+ resultJson.put("date", houseIPage);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ resultJson.put("message", "查询分页失败");
|
|
|
|
|
+ resultJson.put("code", 500);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|