hotelAction.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. if(hotelId==0){
  74. hotelId = Math.toIntExact(UUIDUtil.generateID());
  75. }
  76. int m = 0;
  77. //详细图附件
  78. List<FileInfo> fileList = JSONArray.parseArray(fileListJson, FileInfo.class);
  79. if(fileList==null){
  80. resultJson.put("message", "请上传详细图");
  81. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  82. return null;
  83. }
  84. //保存基本信息
  85. Hotel hotel1 = hotelService.getById(hotel.getId());
  86. if(hotel1!= null){
  87. m = hotelService.updateHotel(hotel);
  88. }else{
  89. hotel.setId(hotelId);
  90. m = hotelService.insertHotel(hotel);
  91. }
  92. if (m > 0) {
  93. if(hotel.getId()!= null){
  94. fileService.delLinkFile(hotel.getId());
  95. }
  96. for(FileInfo file : fileList){
  97. FileInfo fileInfo = fileService.getById(file.getId());
  98. if(fileInfo==null){
  99. fileService.insertFile(file);
  100. }else{
  101. file.setLinkId(hotelId);
  102. fileService.updateFile(file);
  103. }
  104. }
  105. resultJson.put("message", "维护成功");
  106. resultJson.put("code", 200);
  107. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  108. return null;
  109. } else {
  110. resultJson.put("message", "维护失败");
  111. resultJson.put("code", 502);
  112. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  113. return null;
  114. }
  115. } catch (Exception e){
  116. e.printStackTrace();
  117. }
  118. resultJson.put("message", "未知异常");
  119. resultJson.put("code", 205);
  120. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  121. return null;
  122. }
  123. /**
  124. * 描述:查看民宿详细
  125. * @return
  126. */
  127. public String getByHotelInfo(){
  128. JSONObject resultJson = new JSONObject();
  129. StringBuilder s1 = new StringBuilder("");
  130. if (managerId!=null){
  131. s1.append(" and manager_id = '").append(managerId).append("'");
  132. }else{
  133. resultJson.put("message", "请传入managerId");
  134. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  135. return null;
  136. }
  137. if(id!=null){
  138. s1.append(" and id = '").append(id).append("'");
  139. }
  140. //查询商户信息
  141. AdminManager adminManager = adminManagerService.getById(managerId);
  142. //查询民宿信息
  143. Hotel hotel = hotelService.getOen(s1.toString());
  144. HotelEto hotelEto = new HotelEto();
  145. if(adminManager!=null){
  146. hotelEto.setHotelName(adminManager.getHotelName());
  147. hotelEto.setHotelTownship(adminManager.getHotelTownship());
  148. hotelEto.setHotelTownshipName(adminManager.getHotelTownshipName());
  149. hotelEto.setCorpnName(adminManager.getCorpnName());
  150. hotelEto.setCorpnPhone(adminManager.getCorpnPhone());
  151. hotelEto.setManagerId(adminManager.getId());
  152. //hotelEto.setBankCard(adminManager.getBankCard());
  153. }
  154. if(hotel!=null){
  155. //获取有效民宿配置
  156. if(hotel.getHconfig() != null && !"".equals(hotel.getHconfig())){
  157. hotel.setHconfig(hotelDictService.setConfig(hotel.getHconfig()));
  158. }
  159. BeanUtils.copyProperties(hotel,hotelEto);
  160. hotelEto.setHotelTownshipName(adminManager.getHotelTownshipName());
  161. StringBuilder fileSqlx = new StringBuilder("");
  162. fileSqlx.append("and link_id = '").append(hotel.getId()).append("'");
  163. List<FileInfo> fileList = fileService.queryList(fileSqlx.toString());
  164. hotelEto.setFileInfoList(fileList);
  165. resultJson.put("message", "查询成功");
  166. resultJson.put("code", 200);
  167. resultJson.put("data", hotelEto);
  168. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  169. }else{
  170. hotelEto.setHstatus(1);
  171. hotelEto.setIsCanorder(1);
  172. hotelEto.setIsOrder(1);
  173. hotelEto.setIsCanorder(1);
  174. }
  175. if(adminManager == null && hotel == null){
  176. resultJson.put("message", "未查到数据请检查参数");
  177. resultJson.put("code", 500);
  178. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  179. return null;
  180. }
  181. resultJson.put("message", "查询成功");
  182. resultJson.put("code", 200);
  183. resultJson.put("data", hotelEto);
  184. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  185. return null;
  186. }
  187. /**
  188. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  189. * @return
  190. */
  191. public String insterHotelDict(){
  192. JSONObject resultJson = new JSONObject();
  193. Gson gson = new Gson();
  194. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  195. if (json == null) {
  196. resultJson.put("message", "请传入参数");
  197. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  198. return null;
  199. }
  200. HotelDict hotelDict = new HotelDict();
  201. try{
  202. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  203. if(hotelDict==null){
  204. resultJson.put("message", "数据为空");
  205. resultJson.put("code", 500);
  206. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  207. return null;
  208. }
  209. if(hotelDict.getName()==null || hotelDict.getCode()==null){
  210. resultJson.put("message", "各参数不能为空");
  211. resultJson.put("code", 500);
  212. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  213. return null;
  214. }
  215. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  216. resultJson.put("message", "服务图标不能为空");
  217. resultJson.put("code", 500);
  218. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  219. return null;
  220. }
  221. StringBuilder getOneSqlx = new StringBuilder("");
  222. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  223. .append(" and name = '").append(hotelDict.getName()).append("'");
  224. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  225. if(listc != null){
  226. resultJson.put("message", "已新增过相同名称的数据");
  227. resultJson.put("code", 500);
  228. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  229. return null;
  230. }
  231. int m = hotelDictService.insertHotelDict(hotelDict);
  232. if (m > 0) {
  233. resultJson.put("message", "添加成功");
  234. resultJson.put("code", 200);
  235. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  236. return null;
  237. } else {
  238. resultJson.put("message", "添加失败");
  239. resultJson.put("code", 502);
  240. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  241. return null;
  242. }
  243. }catch (Exception e){
  244. e.printStackTrace();
  245. resultJson.put("message", "未知异常:"+ e);
  246. resultJson.put("code", 205);
  247. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  248. }
  249. resultJson.put("message", "未知异常");
  250. resultJson.put("code", 205);
  251. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  252. return null;
  253. }
  254. /**
  255. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  256. * @return
  257. */
  258. public String updateHotelDict(){
  259. JSONObject resultJson = new JSONObject();
  260. Gson gson = new Gson();
  261. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  262. if (json == null) {
  263. resultJson.put("message", "请传入参数");
  264. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  265. return null;
  266. }
  267. HotelDict hotelDict = new HotelDict();
  268. try{
  269. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  270. if(hotelDict==null){
  271. resultJson.put("message", "数据为空");
  272. resultJson.put("code", 500);
  273. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  274. return null;
  275. }
  276. if(hotelDict.getId()==null){
  277. resultJson.put("message", "修改Id不能为空");
  278. resultJson.put("code", 500);
  279. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  280. return null;
  281. }
  282. if(hotelDict.getName()==null){
  283. resultJson.put("message", "各参数不能为空");
  284. resultJson.put("code", 500);
  285. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  286. return null;
  287. }
  288. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  289. resultJson.put("message", "服务图标不能为空");
  290. resultJson.put("code", 500);
  291. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  292. return null;
  293. }
  294. StringBuilder getOneSqlx = new StringBuilder("");
  295. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  296. .append(" and name = '").append(hotelDict.getName()).append("'")
  297. .append(" and id != '").append(hotelDict.getId()).append("'");
  298. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  299. if(listc != null){
  300. resultJson.put("message", "已新增过相同名称的数据");
  301. resultJson.put("code", 500);
  302. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  303. return null;
  304. }
  305. int m = hotelDictService.updateHotelDict(hotelDict);
  306. if (m > 0) {
  307. resultJson.put("message", "修改成功");
  308. resultJson.put("code", 200);
  309. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  310. return null;
  311. } else {
  312. resultJson.put("message", "修改失败");
  313. resultJson.put("code", 502);
  314. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  315. return null;
  316. }
  317. }catch (Exception e){
  318. e.printStackTrace();
  319. resultJson.put("message", "未知异常:"+ e);
  320. resultJson.put("code", 205);
  321. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  322. }
  323. resultJson.put("message", "未知异常");
  324. resultJson.put("code", 205);
  325. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  326. return null;
  327. }
  328. /**
  329. * 描述:删除民宿配置字典
  330. * @return
  331. */
  332. public String delHotelDict(){
  333. JSONObject resultJson = new JSONObject();
  334. if (id == null) {
  335. resultJson.put("message", "请传入id");
  336. resultJson.put("code", 500);
  337. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  338. return null;
  339. }
  340. int m = hotelDictService.delHotelDict(id);
  341. if (m > 0) {
  342. resultJson.put("message", "删除成功");
  343. resultJson.put("code", 200);
  344. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  345. return null;
  346. }
  347. resultJson.put("message", "未知异常");
  348. resultJson.put("code", 205);
  349. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  350. return null;
  351. }
  352. /**
  353. * 描述:查询民宿配置列表
  354. * @return
  355. */
  356. public String queryList(){
  357. JSONObject resultJson = new JSONObject();
  358. StringBuilder s1 = new StringBuilder("");
  359. StringBuilder s2 = new StringBuilder("");
  360. StringBuilder s3 = new StringBuilder("");
  361. StringBuilder s4 = new StringBuilder("");
  362. if(code==null){//查询全部
  363. s1.append("and code = 1");
  364. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  365. s2.append("and code = 2");
  366. List<HotelDict> list2 = hotelDictService.queryList(s2.toString());
  367. s3.append("and code = 3");
  368. List<HotelDict> list3 = hotelDictService.queryList(s3.toString());
  369. s4.append("and code = 4");
  370. List<HotelDict> list4 = hotelDictService.queryList(s4.toString());
  371. resultJson.put("message", "查询成功");
  372. resultJson.put("code", 200);
  373. resultJson.put("date1", list1);
  374. resultJson.put("date2", list2);
  375. resultJson.put("date3", list3);
  376. resultJson.put("date4", list4);
  377. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  378. return null;
  379. }else{
  380. s1.append("and code = ").append(code);
  381. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  382. resultJson.put("message", "查询成功");
  383. resultJson.put("code", 200);
  384. resultJson.put("data", list1);
  385. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  386. return null;
  387. }
  388. }
  389. }