hotelAction.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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.ArrayList;
  22. import java.util.List;
  23. import java.util.UUID;
  24. public class hotelAction extends ActionSupport implements ServletRequestAware {
  25. private HttpServletRequest request;
  26. public HttpServletResponse response;
  27. @Resource
  28. public BookService bookService;
  29. @Resource
  30. public WorkflowService workflowService;
  31. @Resource
  32. public AdminManagerService adminManagerService;
  33. @Resource
  34. public HotelService hotelService;
  35. @Resource
  36. public HotelDictService hotelDictService;
  37. @Resource
  38. public HouseService houseService;
  39. @Resource
  40. public FileService fileService;
  41. public Integer id;
  42. public Integer managerId;//所属商家账号id
  43. public Integer code;//查询字典编码
  44. public int page; // 当前页
  45. public int rows;// 每页显示的行数rows
  46. public String fileListJson;
  47. public HttpServletRequest getRequest() {
  48. return request;
  49. }
  50. public void setRequest(HttpServletRequest request) {
  51. this.request = request;
  52. }
  53. public void setServletRequest(HttpServletRequest request) {
  54. this.request = request;
  55. }
  56. public HttpServletResponse getResponse() {
  57. return response;
  58. }
  59. public void setResponse(HttpServletResponse response) {
  60. this.response = response;
  61. }
  62. /**
  63. * 描述:维护民宿信息
  64. * @return
  65. */
  66. public String updateHotel(){
  67. JSONObject resultJson = new JSONObject();
  68. Gson gson = new Gson();
  69. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  70. if (json == null) {
  71. resultJson.put("message", "请传入参数");
  72. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  73. return null;
  74. }
  75. HotelEto hotelEto = new HotelEto();
  76. try{
  77. hotelEto = gson.fromJson(json.toString(), new TypeToken<HotelEto>() {}.getType());
  78. Hotel hotel = new Hotel();
  79. BeanUtils.copyProperties(hotelEto,hotel);
  80. int hotelId = hotel.getId()!=null ? hotel.getId():Math.toIntExact(UUIDUtil.generateID());
  81. if(hotelId==0){
  82. hotelId = Math.toIntExact(UUIDUtil.generateID());
  83. }
  84. int m = 0;
  85. //详细图附件
  86. List<FileInfo> fileList = JSONArray.parseArray(fileListJson, FileInfo.class);
  87. if(fileList==null){
  88. resultJson.put("message", "请上传详细图");
  89. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  90. return null;
  91. }
  92. //保存基本信息
  93. Hotel hotel1 = hotelService.getById(hotel.getId());
  94. boolean isOk = false;
  95. if(hotel1!= null){
  96. //修改
  97. if (1 == hotel1.getHstatus() && 2 == hotel.getHstatus()){ // 判断营业改休息
  98. StringBuilder s1 = new StringBuilder("");
  99. s1.append(" and order_status in ( 1,2,3,4,10) "); //待支付、已支付、待入住、已入住、退款中
  100. s1.append(" and hotel_id = '").append(hotel.getId()).append("' ");
  101. List<Booking> list = bookService.queryList(s1.toString()); // 查询分页
  102. if (list != null){
  103. resultJson.put("message", "民宿存在“待支付、已支付、待入住、已入住、退款中”状态的订单,不可更改民宿状态。");
  104. resultJson.put("code", 200);
  105. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  106. return null;
  107. }
  108. }
  109. //判断是否修改简介
  110. if (!hotel1.getRemark().equals(hotel.getRemark())){
  111. isOk = true;
  112. }
  113. //判断是否修改图片
  114. for(FileInfo file : fileList){
  115. if ( "0".equals(file.getLinkId())) isOk = true; break;
  116. }
  117. if (isOk){
  118. Workflow workflow = new Workflow();
  119. String id = String.valueOf(UUID.randomUUID());
  120. workflow.setLinkId(String.valueOf(hotel.getId()));
  121. workflow.setRemark(hotel.getRemark());
  122. workflow.setId(id);
  123. workflow.setStatus(1);
  124. workflow.setType(1);
  125. hotel.setRemark(hotel1.getRemark());
  126. int i = workflowService.insert(workflow);
  127. m = hotelService.updateHotel(hotel);
  128. if (i > 0 && m > 0){
  129. //将新修改的附件关联到流程id
  130. for(FileInfo file : fileList){
  131. file.setLinkId(id);
  132. file.setId(String.valueOf(UUIDUtil.generateID()));
  133. fileService.insertFile(file);
  134. }
  135. hotel.setRemark(hotel1.getRemark());
  136. resultJson.put("message", "已成功提交审批!");
  137. resultJson.put("code", 200);
  138. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  139. return null;
  140. }else {
  141. resultJson.put("message", "提交审批失败!");
  142. resultJson.put("code", 502);
  143. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  144. return null;
  145. }
  146. }
  147. }else{
  148. hotel.setId(hotelId);
  149. m = hotelService.insertHotel(hotel);
  150. }
  151. if (m > 0) {
  152. if(hotel.getId()!= null){
  153. fileService.delLinkFile(String.valueOf(hotel.getId()));
  154. }
  155. for(FileInfo file : fileList){
  156. FileInfo fileInfo = fileService.getById(file.getId());
  157. file.setLinkId(String.valueOf(hotelId));
  158. if(fileInfo==null){
  159. fileService.insertFile(file);
  160. }else{
  161. fileService.updateFile(file);
  162. }
  163. }
  164. resultJson.put("message", "维护成功");
  165. resultJson.put("code", 200);
  166. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  167. return null;
  168. } else {
  169. resultJson.put("message", "维护失败");
  170. resultJson.put("code", 502);
  171. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  172. return null;
  173. }
  174. } catch (Exception e){
  175. e.printStackTrace();
  176. }
  177. resultJson.put("message", "未知异常");
  178. resultJson.put("code", 205);
  179. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  180. return null;
  181. }
  182. /**
  183. * 描述:查看民宿详细
  184. * @return
  185. */
  186. public String getByHotelInfo(){
  187. JSONObject resultJson = new JSONObject();
  188. StringBuilder s1 = new StringBuilder("");
  189. if (managerId!=null){
  190. s1.append(" and manager_id = '").append(managerId).append("'");
  191. }else{
  192. resultJson.put("message", "请传入managerId");
  193. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  194. return null;
  195. }
  196. if(id!=null){
  197. s1.append(" and id = '").append(id).append("'");
  198. }
  199. //查询商户信息
  200. AdminManager adminManager = adminManagerService.getById(managerId);
  201. //查询民宿信息
  202. Hotel hotel = hotelService.getOen(s1.toString());
  203. HotelEto hotelEto = new HotelEto();
  204. if(adminManager!=null){
  205. hotelEto.setHotelName(adminManager.getHotelName());
  206. hotelEto.setHotelTownship(adminManager.getHotelTownship());
  207. hotelEto.setHotelTownshipName(adminManager.getHotelTownshipName());
  208. hotelEto.setCorpnName(adminManager.getCorpnName());
  209. hotelEto.setCorpnPhone(adminManager.getCorpnPhone());
  210. hotelEto.setManagerId(adminManager.getId());
  211. hotelEto.setBankCard(adminManager.getBankCard());
  212. hotelEto.setCardName(adminManager.getCardName());
  213. }
  214. if(hotel!=null){
  215. //获取有效民宿配置
  216. if(hotel.getHconfig() != null && !"".equals(hotel.getHconfig())){
  217. hotel.setHconfig(hotelDictService.setConfig(hotel.getHconfig()));
  218. }
  219. hotel.setRoomNumber(houseService.getHouseSum(managerId));
  220. hotel.sethTypeName(hotelDictService.getDictNameById(Integer.parseInt(hotel.getHtype())));
  221. BeanUtils.copyProperties(hotel,hotelEto);
  222. hotelEto.setHotelTownshipName(adminManager.getHotelTownshipName());
  223. StringBuilder fileSqlx = new StringBuilder("");
  224. fileSqlx.append("and link_id = '").append(hotel.getId()).append("'");
  225. List<FileInfo> fileList = fileService.queryList(fileSqlx.toString());
  226. hotelEto.setFileInfoList(fileList);
  227. resultJson.put("message", "查询成功");
  228. resultJson.put("code", 200);
  229. resultJson.put("data", hotelEto);
  230. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  231. }else{
  232. hotelEto.setHstatus(1);
  233. hotelEto.setIsCanorder(1);
  234. hotelEto.setIsOrder(1);
  235. hotelEto.setIsCheckout(1);
  236. hotelEto.setLockTime("15");
  237. }
  238. if(adminManager == null && hotel == null){
  239. resultJson.put("message", "未查到数据请检查参数");
  240. resultJson.put("code", 500);
  241. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  242. return null;
  243. }
  244. hotelEto.setId(Math.toIntExact(UUIDUtil.generateID()));
  245. resultJson.put("message", "查询成功");
  246. resultJson.put("code", 200);
  247. resultJson.put("data", hotelEto);
  248. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  249. return null;
  250. }
  251. /**
  252. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  253. * @return
  254. */
  255. public String insterHotelDict(){
  256. JSONObject resultJson = new JSONObject();
  257. Gson gson = new Gson();
  258. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  259. if (json == null) {
  260. resultJson.put("message", "请传入参数");
  261. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  262. return null;
  263. }
  264. HotelDict hotelDict = new HotelDict();
  265. try{
  266. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  267. if(hotelDict==null){
  268. resultJson.put("message", "数据为空");
  269. resultJson.put("code", 500);
  270. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  271. return null;
  272. }
  273. if(hotelDict.getName()==null || hotelDict.getCode()==null){
  274. resultJson.put("message", "各参数不能为空");
  275. resultJson.put("code", 500);
  276. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  277. return null;
  278. }
  279. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  280. resultJson.put("message", "服务图标不能为空");
  281. resultJson.put("code", 500);
  282. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  283. return null;
  284. }
  285. StringBuilder getOneSqlx = new StringBuilder("");
  286. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  287. .append(" and name = '").append(hotelDict.getName()).append("'");
  288. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  289. if(listc != null){
  290. resultJson.put("message", "已新增过相同名称的数据");
  291. resultJson.put("code", 500);
  292. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  293. return null;
  294. }
  295. int m = hotelDictService.insertHotelDict(hotelDict);
  296. if (m > 0) {
  297. resultJson.put("message", "添加成功");
  298. resultJson.put("code", 200);
  299. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  300. return null;
  301. } else {
  302. resultJson.put("message", "添加失败");
  303. resultJson.put("code", 502);
  304. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  305. return null;
  306. }
  307. }catch (Exception e){
  308. e.printStackTrace();
  309. resultJson.put("message", "未知异常:"+ e);
  310. resultJson.put("code", 205);
  311. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  312. }
  313. resultJson.put("message", "未知异常");
  314. resultJson.put("code", 205);
  315. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  316. return null;
  317. }
  318. /**
  319. * 描述:新增民宿配置字典 code 1.民宿类型;2.民宿服务;3.房型名称;4.房型服务
  320. * @return
  321. */
  322. public String updateHotelDict(){
  323. JSONObject resultJson = new JSONObject();
  324. Gson gson = new Gson();
  325. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  326. if (json == null) {
  327. resultJson.put("message", "请传入参数");
  328. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  329. return null;
  330. }
  331. HotelDict hotelDict = new HotelDict();
  332. try{
  333. hotelDict = gson.fromJson(json.toString(), new TypeToken<HotelDict>() {}.getType());
  334. if(hotelDict==null){
  335. resultJson.put("message", "数据为空");
  336. resultJson.put("code", 500);
  337. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  338. return null;
  339. }
  340. if(hotelDict.getId()==null){
  341. resultJson.put("message", "修改Id不能为空");
  342. resultJson.put("code", 500);
  343. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  344. return null;
  345. }
  346. if(hotelDict.getName()==null){
  347. resultJson.put("message", "各参数不能为空");
  348. resultJson.put("code", 500);
  349. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  350. return null;
  351. }
  352. if(hotelDict.getCode()==4 && hotelDict.getFileUrl()==null){
  353. resultJson.put("message", "服务图标不能为空");
  354. resultJson.put("code", 500);
  355. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  356. return null;
  357. }
  358. StringBuilder getOneSqlx = new StringBuilder("");
  359. getOneSqlx.append(" and code = '").append(hotelDict.getCode()).append("'")
  360. .append(" and name = '").append(hotelDict.getName()).append("'")
  361. .append(" and id != '").append(hotelDict.getId()).append("'");
  362. HotelDict listc = hotelDictService.getOen(getOneSqlx.toString());
  363. if(listc != null){
  364. resultJson.put("message", "已新增过相同名称的数据");
  365. resultJson.put("code", 500);
  366. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  367. return null;
  368. }
  369. int m = hotelDictService.updateHotelDict(hotelDict);
  370. if (m > 0) {
  371. resultJson.put("message", "修改成功");
  372. resultJson.put("code", 200);
  373. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  374. return null;
  375. } else {
  376. resultJson.put("message", "修改失败");
  377. resultJson.put("code", 502);
  378. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  379. return null;
  380. }
  381. }catch (Exception e){
  382. e.printStackTrace();
  383. resultJson.put("message", "未知异常:"+ e);
  384. resultJson.put("code", 205);
  385. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  386. }
  387. resultJson.put("message", "未知异常");
  388. resultJson.put("code", 205);
  389. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  390. return null;
  391. }
  392. /**
  393. * 描述:删除民宿配置字典
  394. * @return
  395. */
  396. public String delHotelDict(){
  397. JSONObject resultJson = new JSONObject();
  398. if (id == null) {
  399. resultJson.put("message", "请传入id");
  400. resultJson.put("code", 500);
  401. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  402. return null;
  403. }
  404. int m = hotelDictService.delHotelDict(id);
  405. if (m > 0) {
  406. resultJson.put("message", "删除成功");
  407. resultJson.put("code", 200);
  408. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  409. return null;
  410. }
  411. resultJson.put("message", "未知异常");
  412. resultJson.put("code", 205);
  413. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  414. return null;
  415. }
  416. /**
  417. * 描述:查询民宿配置列表
  418. * @return
  419. */
  420. public String queryList(){
  421. JSONObject resultJson = new JSONObject();
  422. StringBuilder s1 = new StringBuilder("");
  423. StringBuilder s2 = new StringBuilder("");
  424. StringBuilder s3 = new StringBuilder("");
  425. StringBuilder s4 = new StringBuilder("");
  426. if(code==null){//查询全部
  427. s1.append("and code = 1");
  428. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  429. s2.append("and code = 2");
  430. List<HotelDict> list2 = hotelDictService.queryList(s2.toString());
  431. s3.append("and code = 3");
  432. List<HotelDict> list3 = hotelDictService.queryList(s3.toString());
  433. s4.append("and code = 4");
  434. List<HotelDict> list4 = hotelDictService.queryList(s4.toString());
  435. resultJson.put("message", "查询成功");
  436. resultJson.put("code", 200);
  437. resultJson.put("date1", list1);
  438. resultJson.put("date2", list2);
  439. resultJson.put("date3", list3);
  440. resultJson.put("date4", list4);
  441. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  442. return null;
  443. }else{
  444. s1.append("and code = ").append(code);
  445. List<HotelDict> list1 = hotelDictService.queryList(s1.toString());
  446. resultJson.put("message", "查询成功");
  447. resultJson.put("code", 200);
  448. resultJson.put("data", list1);
  449. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  450. return null;
  451. }
  452. }
  453. /**
  454. * 描述:查询所有民宿信息列表
  455. *
  456. */
  457. public String queryAllHotel(){
  458. JSONObject resultJson = new JSONObject();
  459. List<Hotel> list = hotelService.queryList("");
  460. if (list != null){
  461. resultJson.put("message", "查询成功");
  462. resultJson.put("code", 200);
  463. resultJson.put("data", list);
  464. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  465. }else {
  466. resultJson.put("message", "数据为空!");
  467. resultJson.put("code", 205);
  468. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  469. }
  470. return null;
  471. }
  472. }