bookAction.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. package com.happy.action;
  2. import com.baidubce.model.User;
  3. import com.happy.Model.Booking;
  4. import com.happy.Model.HotelDict;
  5. import com.happy.Model.weixin.Users;
  6. import com.happy.Until.*;
  7. import com.happy.Until.Excel.toExcel;
  8. import com.happy.common.http.Message;
  9. import com.happy.dto.BookTypeEto;
  10. import com.happy.dto.IPage;
  11. import com.happy.service.BookService;
  12. import com.happy.service.HotelDictService;
  13. import com.happy.service.UserService;
  14. import com.opensymphony.xwork2.ActionSupport;
  15. import net.sf.json.JSONObject;
  16. import org.apache.struts2.ServletActionContext;
  17. import org.apache.struts2.interceptor.ServletRequestAware;
  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.Map;
  24. import java.util.Vector;
  25. import java.util.stream.Collectors;
  26. public class bookAction extends ActionSupport implements ServletRequestAware {
  27. private HttpServletRequest request;
  28. public HttpServletResponse response;
  29. @Resource
  30. public BookService bookService;
  31. @Resource
  32. public UserService userService;
  33. @Resource
  34. public HotelDictService hotelDictService;
  35. public int page; // 当前页
  36. public int rows;// 每页显示的行数rows
  37. public Integer id;
  38. public Integer type;
  39. public String orderStatus;//订单状态
  40. public String managerId;//商户Id
  41. public String payStartTime;//支付开始时间
  42. public String payEndTime;//支付结束时间
  43. public String ledgerParam;//台账列表查询参数
  44. public String hotelTownship;//所属乡镇
  45. public String minTotalPrice;//最小订单总价
  46. public String maxTotalPrice;//最大订单总价
  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 updateBookStatus(){
  67. JSONObject resultJson = new JSONObject();
  68. if (id == null) {
  69. resultJson.put("message", "请传入订单id");
  70. resultJson.put("code", 500);
  71. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  72. return null;
  73. }
  74. //根据id获取当前订单信息
  75. Booking book = bookService.getById(id);
  76. if(book==null){
  77. resultJson.put("message", "未查询到订单");
  78. resultJson.put("code", 500);
  79. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  80. return null;
  81. }
  82. //获取用户openId
  83. Users user = userService.queryByUserId(book.getCreateUserid());
  84. if(user.getOpenid()==null){
  85. resultJson.put("message", "用户openId为空,请该订单用户授权才能操作。");
  86. resultJson.put("code", 502);
  87. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  88. return null;
  89. }
  90. String msg = "";
  91. String sendMsg = "";
  92. try{
  93. switch (type){
  94. case 1://接单
  95. if(!"2".equals(book.getOrderStatus())){
  96. resultJson.put("message", "已支付状态才能接单");
  97. resultJson.put("code", 502);
  98. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  99. return null;
  100. }
  101. book.setOrderStatus("3");
  102. book.setUpdateTime(UUIDUtil.getNewDate());
  103. msg = "接单";
  104. sendMsg = "商家已接单";
  105. break;
  106. case 2://入住
  107. if(!"3".equals(book.getOrderStatus())){
  108. resultJson.put("message", "待入住状态才能办理入住");
  109. resultJson.put("code", 502);
  110. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  111. return null;
  112. }
  113. book.setOrderStatus("4");
  114. book.setUpdateTime(UUIDUtil.getNewDate());
  115. msg = "入住办理";
  116. break;
  117. case 3://退房
  118. if(!"4".equals(book.getOrderStatus())){
  119. resultJson.put("message", "已入住状态才能办理退房");
  120. resultJson.put("code", 502);
  121. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  122. return null;
  123. }
  124. book.setCheckOutTime(UUIDUtil.getNewDate());//退房时间
  125. book.setUpdateTime(UUIDUtil.getNewDate());
  126. book.setOrderStatus("5");
  127. msg = "退房";
  128. break;
  129. // case 4://退单
  130. // if(!"2".equals(book.getOrderStatus())){
  131. // resultJson.put("message", "已支付状态才能退单");
  132. // resultJson.put("code", 502);
  133. // ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  134. // return null;
  135. // }
  136. // book.setOrderStatus("8");
  137. // book.setUpdateTime(UUIDUtil.getNewDate());
  138. // msg = "退单";
  139. // sendMsg = "商家已退单";
  140. // break;
  141. }
  142. int m = bookService.updateBooking(book);
  143. if (m > 0) {
  144. //推送信息
  145. if(!"".equals(sendMsg)){
  146. String errmsg = Message.wxErrorMsg(Message.send(user.getOpenid(),book.getOrderNum(),book.getUserName(),sendMsg,book.getCreateTime().substring(0,10)));
  147. if("请求成功".equals(errmsg)){
  148. resultJson.put("message", msg+"成功");
  149. resultJson.put("code", 200);
  150. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  151. return null;
  152. }
  153. resultJson.put("message", msg+"成功"+",推送消息失败,原因:"+errmsg);
  154. resultJson.put("code", 500);
  155. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  156. return null;
  157. }
  158. resultJson.put("message", msg+"成功");
  159. resultJson.put("code", 500);
  160. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  161. return null;
  162. } else {
  163. resultJson.put("message", msg+"失败");
  164. resultJson.put("code", 502);
  165. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  166. return null;
  167. }
  168. }catch (Exception e){
  169. e.printStackTrace();
  170. }
  171. resultJson.put("message", "未知异常");
  172. resultJson.put("code", 205);
  173. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  174. return null;
  175. }
  176. /**
  177. * 描述:分页查询订单
  178. * @return
  179. */
  180. public String quearyBookPage(){
  181. JSONObject resultJson = new JSONObject();
  182. StringBuilder s1 = new StringBuilder("");
  183. if(managerId!=null){
  184. s1.append(" and hotel_manager_id = '").append(managerId).append("'");
  185. }
  186. if (ledgerParam!=null){
  187. s1.append(" and (order_num like '%").append(ledgerParam).append("%'")
  188. .append(" or user_name like '%").append(ledgerParam).append("%'")
  189. .append(" or user_phone like '%").append(ledgerParam).append("%')");
  190. }
  191. if(orderStatus!=null){
  192. s1.append(" and order_status = ").append(orderStatus);
  193. }
  194. if(payStartTime!=null && payEndTime!=null){
  195. s1.append(" and pay_time >= '").append(payStartTime).append("'")
  196. .append(" and pay_time <= '").append(payEndTime).append("'");
  197. }
  198. IPage<Booking> bookIPage = bookService.queryPage(s1.toString(),page,rows);
  199. //获取订单汇总信息
  200. BookTypeEto bookTypeEto = bookService.getBookStatusSum(s1.toString());
  201. bookTypeEto.setBookIPage(bookIPage);
  202. if(bookTypeEto!=null && !"".equals(bookTypeEto)){
  203. resultJson.put("message", "查询分页成功");
  204. resultJson.put("code", 200);
  205. resultJson.put("data", bookTypeEto);
  206. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  207. }else{
  208. resultJson.put("message", "查询分页失败");
  209. resultJson.put("code", 500);
  210. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  211. }
  212. return null;
  213. }
  214. /**
  215. * 描述:导出订单
  216. * @return
  217. */
  218. public String toBookExcel() {
  219. JSONObject resultJson = new JSONObject();
  220. StringBuilder s1 = new StringBuilder("");
  221. s1.append(" and hotel_manager_id = '").append(managerId).append("'");
  222. if (ledgerParam!=null){
  223. s1.append(" and (order_num like '%").append(ledgerParam).append("%'")
  224. .append(" or user_name like '%").append(ledgerParam).append("%'")
  225. .append(" or user_phone like '%").append(ledgerParam).append("%')");
  226. }
  227. if(orderStatus!=null){
  228. s1.append(" and order_status = ").append(orderStatus);
  229. }
  230. if(payStartTime!=null && payEndTime!=null){
  231. s1.append(" and pay_time >= '").append(payStartTime).append("'")
  232. .append(" and pay_time <= '").append(payEndTime).append("'");
  233. }
  234. List<Booking> list = bookService.queryList(s1.toString()); // 查询分页
  235. List<Vector> vectorsList = new ArrayList<>();
  236. if(list==null){
  237. resultJson.put("code", 500);
  238. resultJson.put("message", "无数据无法导出");
  239. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  240. resultJson.toString());
  241. }
  242. for(Booking book:list){
  243. Vector columnValue = new Vector();
  244. columnValue.add(book.getOrderNum());
  245. columnValue.add(book.getOrderName());
  246. columnValue.add(book.getUserName());
  247. columnValue.add(book.getUserPhone());
  248. columnValue.add(book.getHouseName());
  249. columnValue.add(book.getHouseOrderNumber());
  250. columnValue.add(book.getHouseTotalPrice());
  251. columnValue.add(book.getPayTime());
  252. vectorsList.add(columnValue);
  253. }
  254. // 项目路径地址
  255. String path = request.getSession().getServletContext()
  256. .getRealPath("/download/");// File.separator
  257. try{
  258. Vector columnName = new Vector();
  259. columnName.add("订单号");
  260. columnName.add("状态");
  261. columnName.add("预定人");
  262. columnName.add("手机号");
  263. columnName.add("预定房型");
  264. columnName.add("房间数");
  265. columnName.add("订单金额(元)");
  266. columnName.add("支付时间");
  267. String filePathName ="订单信息" + UUIDUtil.generateID() +"Report.xls";
  268. // 导出文件
  269. new toExcel().book(vectorsList, path + filePathName,
  270. "sheet1", columnName);
  271. String url = "http://"+request.getServerName()+":"+request.getServerPort() + request.getSession().getServletContext().getContextPath();
  272. resultJson.put("downurl", url + "/download/" + filePathName);
  273. resultJson.put("code", 200);
  274. resultJson.put("message", "导出成功");
  275. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  276. resultJson.toString());
  277. } catch (Exception e){
  278. e.printStackTrace();
  279. }
  280. return null;
  281. }
  282. /**
  283. * 描述:分页查询台账(查询以消费订单数据)
  284. * @return
  285. */
  286. public String quearyLedgerPage(){
  287. JSONObject resultJson = new JSONObject();
  288. StringBuilder s1 = new StringBuilder("");
  289. s1.append(" and order_status = 5");
  290. if(managerId!=null){
  291. s1.append(" and hotel_manager_id = '").append(managerId).append("'");
  292. }
  293. if (ledgerParam!=null){
  294. s1.append(" and (order_num like '%").append(ledgerParam).append("%'")
  295. .append(" or user_name like '%").append(ledgerParam).append("%'")
  296. .append(" or user_phone like '%").append(ledgerParam).append("%')");
  297. }
  298. if(payStartTime!=null && payEndTime!=null){
  299. s1.append(" and pay_time >= '").append(payStartTime).append("'")
  300. .append(" and pay_time <= '").append(payEndTime).append("'");
  301. }
  302. if(hotelTownship!=null){
  303. s1.append(" and hotel_township = '").append(hotelTownship).append("'");
  304. }
  305. if(minTotalPrice!=null){
  306. s1.append(" and house_total_price >= '").append(minTotalPrice).append("'");
  307. }
  308. if(maxTotalPrice!=null){
  309. s1.append(" and house_total_price <= '").append(maxTotalPrice).append("'");
  310. }
  311. IPage<Booking> bookIPage = bookService.queryPage(s1.toString(),page,rows);
  312. //获取订单汇总信息
  313. BookTypeEto bookTypeEto = bookService.getBookStatusSum(s1.toString());
  314. bookTypeEto.setBookIPage(bookIPage);
  315. if(bookTypeEto!=null && !"".equals(bookTypeEto)){
  316. resultJson.put("message", "查询分页成功");
  317. resultJson.put("code", 200);
  318. resultJson.put("data", bookTypeEto);
  319. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  320. }else{
  321. resultJson.put("message", "查询分页失败");
  322. resultJson.put("code", 500);
  323. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  324. }
  325. return null;
  326. }
  327. /**
  328. * 描述:根据Id查询订单详细
  329. * @return
  330. */
  331. public String getById(){
  332. JSONObject resultJson = new JSONObject();
  333. if (id == null) {
  334. resultJson.put("message", "请传入id");
  335. resultJson.put("code", 500);
  336. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  337. return null;
  338. }
  339. Booking book = bookService.getById(id);
  340. if (book != null) {
  341. resultJson.put("message", "查询成功");
  342. resultJson.put("code", 200);
  343. resultJson.put("data", book);
  344. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  345. return null;
  346. }else{
  347. resultJson.put("message", "未查到用户信息");
  348. resultJson.put("code", 500);
  349. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  350. return null;
  351. }
  352. }
  353. /**
  354. * 描述:导出台账
  355. * @return
  356. */
  357. public String toLedgerExcel() {
  358. JSONObject resultJson = new JSONObject();
  359. StringBuilder s1 = new StringBuilder("");
  360. s1.append(" and order_status = 5");
  361. s1.append(" and hotel_manager_id = '").append(managerId).append("'");
  362. if (ledgerParam!=null){
  363. s1.append(" and (order_num like '%").append(ledgerParam).append("%'")
  364. .append(" or user_name like '%").append(ledgerParam).append("%'")
  365. .append(" or user_phone like '%").append(ledgerParam).append("%')");
  366. }
  367. if(payStartTime!=null && payEndTime!=null){
  368. s1.append(" and pay_time >= '").append(payStartTime).append("'")
  369. .append(" and pay_time <= '").append(payEndTime).append("'");
  370. }
  371. if(hotelTownship!=null){
  372. s1.append(" and hotel_township = '").append(payStartTime).append("'");
  373. }
  374. if(minTotalPrice!=null){
  375. s1.append(" and house_total_price >= '").append(minTotalPrice).append("'");
  376. }
  377. if(maxTotalPrice!=null){
  378. s1.append(" and house_total_price <= '").append(maxTotalPrice).append("'");
  379. }
  380. List<Booking> list = bookService.queryList(s1.toString()); // 查询列表
  381. List<Vector> vectorsList = new ArrayList<>();
  382. for(Booking book:list){
  383. Vector columnValue = new Vector();
  384. columnValue.add(book.getOrderNum());
  385. columnValue.add(book.getUserName());
  386. columnValue.add(book.getUserPhone());
  387. columnValue.add(book.getHouseOrderNumber());
  388. columnValue.add(book.getPayAccount());
  389. columnValue.add(book.getPayTime());
  390. vectorsList.add(columnValue);
  391. }
  392. // 项目路径地址
  393. String path = request.getSession().getServletContext()
  394. .getRealPath("/download/");// File.separator
  395. try{
  396. Vector columnName = new Vector();
  397. columnName.add("订单号");
  398. columnName.add("预定人");
  399. columnName.add("手机号");
  400. columnName.add("房间数");
  401. columnName.add("订单金额");
  402. columnName.add("退房时间");
  403. String filePathName ="台账信息" + UUIDUtil.generateID() +"Report.xls";
  404. // 导出文件
  405. new toExcel().book(vectorsList, path + filePathName,
  406. "sheet1", columnName);
  407. String url = "http://"+request.getServerName()+":"+request.getServerPort() + request.getSession().getServletContext().getContextPath();
  408. resultJson.put("downurl", url + "/download/" + filePathName);
  409. resultJson.put("code", 200);
  410. resultJson.put("message", "导出成功");
  411. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  412. resultJson.toString());
  413. } catch (Exception e){
  414. e.printStackTrace();
  415. }
  416. return null;
  417. }
  418. /**
  419. * 描述:导出台账 管理端
  420. * @return
  421. */
  422. public String toLedgerAdmimnExcel() {
  423. JSONObject resultJson = new JSONObject();
  424. StringBuilder s1 = new StringBuilder("");
  425. s1.append(" and order_status = 5");
  426. if (ledgerParam!=null){
  427. s1.append(" and (order_num like '%").append(ledgerParam).append("%'")
  428. .append(" or user_name like '%").append(ledgerParam).append("%'")
  429. .append(" or user_phone like '%").append(ledgerParam).append("%')");
  430. }
  431. if(payStartTime!=null && payEndTime!=null){
  432. s1.append(" and pay_time >= '").append(payStartTime).append("'")
  433. .append(" and pay_time <= '").append(payEndTime).append("'");
  434. }
  435. if(hotelTownship!=null){
  436. s1.append(" and hotel_township = '").append(payStartTime).append("'");
  437. }
  438. if(minTotalPrice!=null){
  439. s1.append(" and house_total_price >= '").append(minTotalPrice).append("'");
  440. }
  441. if(maxTotalPrice!=null){
  442. s1.append(" and house_total_price <= '").append(maxTotalPrice).append("'");
  443. }
  444. List<Booking> list = bookService.queryList(s1.toString()); // 查询列表
  445. List<HotelDict> hotelDicts = hotelDictService.queryList("and code = 10");
  446. Map<Integer, String> dictMap = null;
  447. if(hotelDicts!=null && hotelDicts.size()>0){
  448. dictMap = hotelDicts.stream().collect(Collectors.toMap(HotelDict::getId, HotelDict::getName, (key1, key2) -> key1 ));
  449. }else{
  450. resultJson.put("message", "未查到民宿乡镇信息");
  451. resultJson.put("code", 500);
  452. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  453. return null;
  454. }
  455. List<Vector> vectorsList = new ArrayList<>();
  456. for(Booking book:list){
  457. Vector columnValue = new Vector();
  458. columnValue.add(dictMap.get(Integer.valueOf(book.getHotelTownship())));//所属乡镇
  459. columnValue.add(book.getHotelName());//乡宿名称
  460. columnValue.add(book.getOrderNum());//订单号
  461. columnValue.add(book.getPayAccount());//订单金额
  462. columnValue.add(book.getPayTime());//退房时间
  463. vectorsList.add(columnValue);
  464. }
  465. // 项目路径地址
  466. String path = request.getSession().getServletContext()
  467. .getRealPath("/download/");// File.separator
  468. try{
  469. Vector columnName = new Vector();
  470. columnName.add("所属乡镇");
  471. columnName.add("民宿名称");
  472. columnName.add("订单号");
  473. columnName.add("订单金额(元)");
  474. columnName.add("退房时间");
  475. String filePathName ="台账信息" + UUIDUtil.generateID() +"Report.xls";
  476. // 导出文件
  477. new toExcel().book(vectorsList, path + filePathName,
  478. "sheet1", columnName);
  479. String url = "http://"+request.getServerName()+":"+request.getServerPort() + request.getSession().getServletContext().getContextPath();
  480. resultJson.put("downurl", url + "/download/" + filePathName);
  481. resultJson.put("code", 200);
  482. resultJson.put("message", "导出成功");
  483. ResponseUtil.writeJson(ServletActionContext.getResponse(),
  484. resultJson.toString());
  485. } catch (Exception e){
  486. e.printStackTrace();
  487. }
  488. return null;
  489. }
  490. }