hotelAction.java 15 KB

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