HotelAction.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. package com.happy.action;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.happy.Model.*;
  5. import com.happy.Until.GetHttpParam;
  6. import com.happy.Until.PwdDefind;
  7. import com.happy.Until.ResUtil;
  8. import com.happy.Until.UUIDUtil;
  9. import com.happy.dto.HotelEto;
  10. import com.happy.dto.IPage;
  11. import com.happy.service.*;
  12. import com.opensymphony.xwork2.ActionSupport;
  13. import net.sf.json.JSONObject;
  14. import org.apache.struts2.ServletActionContext;
  15. import org.springframework.beans.BeanUtils;
  16. import javax.annotation.Resource;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.util.List;
  20. public class HotelAction extends ActionSupport {
  21. private HttpServletRequest request;
  22. public HttpServletResponse response;
  23. @Resource
  24. public AdminManagerService adminManagerService;
  25. @Resource
  26. public HotelService hotelService;
  27. @Resource
  28. public HotelDictService hotelDictService;
  29. @Resource
  30. public FileService fileService;
  31. public Integer id;
  32. public Integer managerId;//所属商家账号id
  33. public Integer code;//查询字典编码
  34. public int page; // 当前页
  35. public int rows;// 每页显示的行数rows
  36. public HttpServletRequest getRequest() {
  37. return request;
  38. }
  39. public void setRequest(HttpServletRequest request) {
  40. this.request = request;
  41. }
  42. public void setServletRequest(HttpServletRequest request) {
  43. this.request = request;
  44. }
  45. public HttpServletResponse getResponse() {
  46. return response;
  47. }
  48. public void setResponse(HttpServletResponse response) {
  49. this.response = response;
  50. }
  51. /**
  52. * 描述:维护民宿信息
  53. * @return
  54. */
  55. public String updateHotel(){
  56. JSONObject resultJson = new JSONObject();
  57. Gson gson = new Gson();
  58. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  59. if (json == null) {
  60. resultJson.put("message", "请传入参数");
  61. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  62. return null;
  63. }
  64. HotelEto hotelEto = new HotelEto();
  65. try{
  66. hotelEto = gson.fromJson(json.toString(), new TypeToken<HotelEto>() {}.getType());
  67. Hotel hotel = new Hotel();
  68. BeanUtils.copyProperties(hotelEto,hotel);
  69. int hotelId = hotel.getId()!= null ? hotel.getId():Math.toIntExact(UUIDUtil.generateID());
  70. int m = 0;
  71. //保存基本信息
  72. if(hotel.getId()!= null){
  73. m = hotelService.updateHotel(hotel);
  74. }else{
  75. hotel.setId(hotelId);
  76. m = hotelService.insertHotel(hotel);
  77. }
  78. //保存详细图附件
  79. if(hotelEto.getFileList()!=null && hotelEto.getFileList().size()>0){
  80. if(hotel.getId()!= null){
  81. fileService.delLinkFile(hotel.getId());
  82. }
  83. for(File file : hotelEto.getFileList()){
  84. file.setLinkId(hotelId);
  85. fileService.insertFile(file);
  86. }
  87. }else{
  88. resultJson.put("message", "请上传详细图");
  89. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  90. return null;
  91. }
  92. if (m > 0) {
  93. resultJson.put("message", "维护成功");
  94. resultJson.put("code", 200);
  95. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  96. return null;
  97. } else {
  98. resultJson.put("message", "维护失败");
  99. resultJson.put("code", 502);
  100. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  101. return null;
  102. }
  103. } catch (Exception e){
  104. e.printStackTrace();
  105. }
  106. resultJson.put("message", "未知异常");
  107. resultJson.put("code", 205);
  108. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  109. return null;
  110. }
  111. /**
  112. * 描述:查看民宿详细
  113. * @return
  114. */
  115. public String getByHotelInfo(){
  116. JSONObject resultJson = new JSONObject();
  117. StringBuilder s1 = new StringBuilder("");
  118. if (managerId!=null){
  119. s1.append(" and manager_id = '").append(managerId).append("'");
  120. }else{
  121. resultJson.put("message", "请传入登陆人账号Id");
  122. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  123. return null;
  124. }
  125. //查询商户信息
  126. AdminManager adminManager = adminManagerService.getById(managerId);
  127. //查询民宿信息
  128. Hotel hotel = hotelService.getOen(s1.toString());
  129. HotelEto hotelEto = new HotelEto();
  130. BeanUtils.copyProperties(adminManager,hotelEto);
  131. BeanUtils.copyProperties(hotel,hotelEto);
  132. StringBuilder fileSqlx = new StringBuilder("");
  133. fileSqlx.append("and link_id = '").append(id).append("'");
  134. List<File> fileList = fileService.queryList(fileSqlx.toString());
  135. hotelEto.setFileList(fileList);
  136. resultJson.put("message", "查询成功");
  137. resultJson.put("code", 200);
  138. resultJson.put("date", hotelEto);
  139. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  140. return null;
  141. }
  142. /**
  143. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  144. * @return
  145. */
  146. public String insterHotelDict(){
  147. JSONObject resultJson = new JSONObject();
  148. Gson gson = new Gson();
  149. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  150. if (json == null) {
  151. resultJson.put("message", "请传入参数");
  152. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  153. return null;
  154. }
  155. HotelDict hotelDict = new HotelDict();
  156. try{
  157. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  158. if(hotelDict==null){
  159. resultJson.put("message", "数据为空");
  160. resultJson.put("code", 500);
  161. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  162. return null;
  163. }
  164. if(hotelDict.getName()==null || hotelDict.getCode()==null){
  165. resultJson.put("message", "各参数不能为空");
  166. resultJson.put("code", 500);
  167. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  168. return null;
  169. }
  170. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  171. resultJson.put("message", "服务图标不能为空");
  172. resultJson.put("code", 500);
  173. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  174. return null;
  175. }
  176. StringBuilder getOneSqlx = new StringBuilder("");
  177. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  178. .append(" and name = '").append(hotelDict.getName()).append("'");
  179. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  180. if(listc != null){
  181. resultJson.put("message", "已新增过相同名称的数据");
  182. resultJson.put("code", 500);
  183. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  184. return null;
  185. }
  186. int m = hotelDictService.insertHotelDict(hotelDict);
  187. if (m > 0) {
  188. resultJson.put("message", "添加成功");
  189. resultJson.put("code", 200);
  190. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  191. return null;
  192. } else {
  193. resultJson.put("message", "添加失败");
  194. resultJson.put("code", 502);
  195. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  196. return null;
  197. }
  198. }catch (Exception e){
  199. e.printStackTrace();
  200. resultJson.put("message", "未知异常:"+ e);
  201. resultJson.put("code", 205);
  202. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  203. }
  204. resultJson.put("message", "未知异常");
  205. resultJson.put("code", 205);
  206. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  207. return null;
  208. }
  209. /**
  210. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  211. * @return
  212. */
  213. public String updateHotelDict(){
  214. JSONObject resultJson = new JSONObject();
  215. Gson gson = new Gson();
  216. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  217. if (json == null) {
  218. resultJson.put("message", "请传入参数");
  219. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  220. return null;
  221. }
  222. HotelDict hotelDict = new HotelDict();
  223. try{
  224. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  225. if(hotelDict==null){
  226. resultJson.put("message", "数据为空");
  227. resultJson.put("code", 500);
  228. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  229. return null;
  230. }
  231. if(hotelDict.getId()==null){
  232. resultJson.put("message", "修改Id不能为空");
  233. resultJson.put("code", 500);
  234. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  235. return null;
  236. }
  237. if(hotelDict.getName()==null || hotelDict.getCode()==null){
  238. resultJson.put("message", "各参数不能为空");
  239. resultJson.put("code", 500);
  240. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  241. return null;
  242. }
  243. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  244. resultJson.put("message", "服务图标不能为空");
  245. resultJson.put("code", 500);
  246. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  247. return null;
  248. }
  249. StringBuilder getOneSqlx = new StringBuilder("");
  250. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  251. .append(" and name = '").append(hotelDict.getName()).append("'")
  252. .append(" and id != '").append(hotelDict.getId()).append("'");
  253. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  254. if(listc != null){
  255. resultJson.put("message", "已新增过相同名称的数据");
  256. resultJson.put("code", 500);
  257. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  258. return null;
  259. }
  260. int m = hotelDictService.insertHotelDict(hotelDict);
  261. if (m > 0) {
  262. resultJson.put("message", "修改成功");
  263. resultJson.put("code", 200);
  264. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  265. return null;
  266. } else {
  267. resultJson.put("message", "修改失败");
  268. resultJson.put("code", 502);
  269. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  270. return null;
  271. }
  272. }catch (Exception e){
  273. e.printStackTrace();
  274. resultJson.put("message", "未知异常:"+ e);
  275. resultJson.put("code", 205);
  276. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  277. }
  278. resultJson.put("message", "未知异常");
  279. resultJson.put("code", 205);
  280. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  281. return null;
  282. }
  283. /**
  284. * 描述:删除民宿配置字典
  285. * @return
  286. */
  287. public String delHotelDict(){
  288. JSONObject resultJson = new JSONObject();
  289. if (id == null) {
  290. resultJson.put("message", "请传入id");
  291. resultJson.put("code", 500);
  292. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  293. return null;
  294. }
  295. int m = hotelDictService.delHotelDict(id);
  296. if (m > 0) {
  297. resultJson.put("message", "删除成功");
  298. resultJson.put("code", 200);
  299. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  300. return null;
  301. }
  302. resultJson.put("message", "未知异常");
  303. resultJson.put("code", 205);
  304. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  305. return null;
  306. }
  307. /**
  308. * 描述:查询民宿配置列表
  309. * @return
  310. */
  311. public String queryList(){
  312. JSONObject resultJson = new JSONObject();
  313. StringBuilder s1 = new StringBuilder("");
  314. StringBuilder s2 = new StringBuilder("");
  315. StringBuilder s3 = new StringBuilder("");
  316. StringBuilder s4 = new StringBuilder("");
  317. if(code==null){//查询全部
  318. s1.append("and code = '1'");
  319. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  320. s2.append("and code = '2'");
  321. List<HotelDict> list2 = hotelDictService.queryList(s2.toString());
  322. s1.append("and code = '3'");
  323. List<HotelDict> list3 = hotelDictService.queryList(s3.toString());
  324. s1.append("and code = '4'");
  325. List<HotelDict> list4 = hotelDictService.queryList(s4.toString());
  326. resultJson.put("message", "查询成功");
  327. resultJson.put("code", 200);
  328. resultJson.put("date1", list1);
  329. resultJson.put("date2", list2);
  330. resultJson.put("date3", list3);
  331. resultJson.put("date4", list4);
  332. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  333. return null;
  334. }else{
  335. s1.append("and code = '").append(code).append("'");
  336. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  337. resultJson.put("message", "查询成功");
  338. resultJson.put("code", 200);
  339. resultJson.put("date1", list1);
  340. return null;
  341. }
  342. }
  343. }