Przeglądaj źródła

民宿配置添删改

raojiaolong@163.com 2 lat temu
rodzic
commit
47eb136809

+ 13 - 0
mhotel/src/com/happy/Model/HotelDict.java

@@ -11,6 +11,11 @@ public class HotelDict {
 
 	private Integer id;
 
+    /**
+     * 编码
+     */
+    private Integer code;
+
 	/**
 	 * 名称
 	 */
@@ -49,6 +54,14 @@ public class HotelDict {
         this.id = id;
     }
 
+    public Integer getCode() {
+        return code;
+    }
+
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+
     public String getName() {
         return name;
     }

+ 225 - 0
mhotel/src/com/happy/action/HotelAction.java

@@ -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;
+    }
+
+}

+ 3 - 3
mhotel/src/com/happy/action/adminAction.java

@@ -167,7 +167,7 @@ public class adminAction extends ActionSupport implements ServletRequestAware {
                 return null;
             }
             if(admin.getId()==null){
-                resultJson.put("message", "修改用户Id不能为空");
+                resultJson.put("message", "修改Id不能为空");
                 resultJson.put("code", 500);
                 ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
                 return null;
@@ -185,8 +185,8 @@ public class adminAction extends ActionSupport implements ServletRequestAware {
                 return null;
             }
             StringBuilder getOneSqlx = new StringBuilder("");
-            getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'");
-            getOneSqlx.append(" and id != '").append(admin.getId()).append("'");
+            getOneSqlx.append(" and admin_name = '").append(admin.getAdminName()).append("'")
+                    .append(" and id != '").append(admin.getId()).append("'");
             Admin listc = adminService.getOen(getOneSqlx.toString());
             if (listc != null) {
                 resultJson.put("message", "该用户已存在");

+ 4 - 2
mhotel/src/com/happy/dao/impl/HotelDictImplDao.java

@@ -28,9 +28,10 @@ public class HotelDictImplDao implements HotelDictDao {
 
     @Override
     public int insertHotelDict(HotelDict hotelDict) {
-        String sql = "INSERT INTO hotel_dict (id, name, file_url, create_id, create_date, modify_date, status) VALUES (:id, :name, :file_url, :create_id, :create_date, :modify_date, :status);\n";
+        String sql = "INSERT INTO hotel_dict (id, code, name, file_url, create_id, create_date, modify_date, status) VALUES (:id, :code, :name, :file_url, :create_id, :create_date, :modify_date, :status);\n";
 
         MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("code",hotelDict.getCode());
         sps.addValue("name",hotelDict.getName());
         sps.addValue("file_url",hotelDict.getFileUrl());
         sps.addValue("create_id",hotelDict.getCreateId());
@@ -52,8 +53,9 @@ public class HotelDictImplDao implements HotelDictDao {
 
     @Override
     public int updateHotelDict(HotelDict hotelDict) {
-        String sql = "UPDATE hotel_dict SET name=:name, file_url=:file_url, create_id=:create_id, modify_date=:modify_date, status=:status WHERE id = :id";
+        String sql = "UPDATE hotel_dict SET code=:code, name=:name, file_url=:file_url, create_id=:create_id, modify_date=:modify_date, status=:status WHERE id = :id";
         MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("code",hotelDict.getCode());
         sps.addValue("name",hotelDict.getName());
         sps.addValue("file_url",hotelDict.getFileUrl());
         sps.addValue("create_id",hotelDict.getCreateId());

+ 1 - 1
mhotel/src/com/happy/service/AdminManagerService.java

@@ -56,6 +56,6 @@ public interface AdminManagerService {
      * @param sqlx
      * @return
      */
-    public AdminManager getOen(String sqlx);
+    AdminManager getOen(String sqlx);
 
 }

+ 7 - 0
mhotel/src/com/happy/service/HotelDictService.java

@@ -50,4 +50,11 @@ public interface HotelDictService {
      * @return
      */
     List<HotelDict> queryList(String sqlx);
+
+    /**
+     * 描述:查询一条数据
+     * @param sqlx
+     * @return
+     */
+    HotelDict getOen(String sqlx);
 }

+ 9 - 0
mhotel/src/com/happy/service/impl/HotelDictImplService.java

@@ -1,5 +1,6 @@
 package com.happy.service.impl;
 
+import com.happy.Model.Admin;
 import com.happy.Model.HotelDict;
 import com.happy.dao.HotelDictDao;
 import com.happy.dto.IPage;
@@ -52,4 +53,12 @@ public class HotelDictImplService implements HotelDictService {
     public List<HotelDict> queryList(String sqlx) {
         return hotelDictDao.queryList(sqlx);
     }
+    @Override
+    public HotelDict getOen(String sqlx) {
+        List<HotelDict> list = hotelDictDao.queryList(sqlx);
+        if(list!=null && list.size()>0) return list.get(0);
+        return null;
+    }
+
+
 }