|
|
@@ -0,0 +1,225 @@
|
|
|
+package com.happy.action;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
+import com.happy.Model.Admin;
|
|
|
+import com.happy.Model.AdminManager;
|
|
|
+import com.happy.Model.AdminPower;
|
|
|
+import com.happy.Model.HotelDict;
|
|
|
+import com.happy.Until.GetHttpParam;
|
|
|
+import com.happy.Until.PwdDefind;
|
|
|
+import com.happy.Until.ResUtil;
|
|
|
+import com.happy.dto.IPage;
|
|
|
+import com.happy.service.AdminManagerService;
|
|
|
+import com.happy.service.AdminService;
|
|
|
+import com.happy.service.HotelDictService;
|
|
|
+import com.opensymphony.xwork2.ActionSupport;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import org.apache.struts2.ServletActionContext;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class HotelAction extends ActionSupport {
|
|
|
+
|
|
|
+ private HttpServletRequest request;
|
|
|
+ public HttpServletResponse response;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ public HotelDictService hotelDictService;
|
|
|
+
|
|
|
+ public Integer id;
|
|
|
+ public int page; // 当前页
|
|
|
+ public int rows;// 每页显示的行数rows
|
|
|
+
|
|
|
+ public HttpServletRequest getRequest() {
|
|
|
+ return request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRequest(HttpServletRequest request) {
|
|
|
+ this.request = request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setServletRequest(HttpServletRequest request) {
|
|
|
+ this.request = request;
|
|
|
+ }
|
|
|
+
|
|
|
+ public HttpServletResponse getResponse() {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setResponse(HttpServletResponse response) {
|
|
|
+ this.response = response;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String insterHotelDict(){
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ HotelDict hotelDict = new HotelDict();
|
|
|
+ try{
|
|
|
+ hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
|
|
|
+ if(hotelDict==null){
|
|
|
+ resultJson.put("message", "数据为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(hotelDict.getName()==null || hotelDict.getCode()==null){
|
|
|
+ resultJson.put("message", "各参数不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
|
|
|
+ resultJson.put("message", "服务图标不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ StringBuilder getOneSqlx = new StringBuilder("");
|
|
|
+ getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
|
|
|
+ .append(" and name = '").append(hotelDict.getName()).append("'");
|
|
|
+ HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
|
|
|
+ if(listc != null){
|
|
|
+ resultJson.put("message", "已新增过相同名称的数据");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ int m = hotelDictService.insertHotelDict(hotelDict);
|
|
|
+ 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", "未知异常:"+ e);
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ }
|
|
|
+ resultJson.put("message", "未知异常");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String updateHotelDict(){
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ HotelDict hotelDict = new HotelDict();
|
|
|
+ try{
|
|
|
+ hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
|
|
|
+ if(hotelDict==null){
|
|
|
+ resultJson.put("message", "数据为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(hotelDict.getId()==null){
|
|
|
+ resultJson.put("message", "修改Id不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(hotelDict.getName()==null || hotelDict.getCode()==null){
|
|
|
+ resultJson.put("message", "各参数不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
|
|
|
+ resultJson.put("message", "服务图标不能为空");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ StringBuilder getOneSqlx = new StringBuilder("");
|
|
|
+ getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
|
|
|
+ .append(" and name = '").append(hotelDict.getName()).append("'")
|
|
|
+ .append(" and id != '").append(hotelDict.getId()).append("'");
|
|
|
+ HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
|
|
|
+ if(listc != null){
|
|
|
+ resultJson.put("message", "已新增过相同名称的数据");
|
|
|
+ resultJson.put("code", 500);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ int m = hotelDictService.insertHotelDict(hotelDict);
|
|
|
+ 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", "未知异常:"+ e);
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ }
|
|
|
+ resultJson.put("message", "未知异常");
|
|
|
+ resultJson.put("code", 205);
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述:删除
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String delHotelDict(){
|
|
|
+ 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 = hotelDictService.delHotelDict(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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|