AppHomePageImplService.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.happy.service.impl;
  2. import com.happy.Model.Booking;
  3. import com.happy.Model.Hotel;
  4. import com.happy.Model.House;
  5. import com.happy.Until.DateUtil;
  6. import com.happy.Until.Func;
  7. import com.happy.Until.TimeExchange;
  8. import com.happy.dao.BookDao;
  9. import com.happy.dao.HouseDao;
  10. import com.happy.dto.IPage;
  11. import com.happy.service.AppHomePageService;
  12. import com.happy.service.BookService;
  13. import com.happy.service.HotelService;
  14. import com.happy.service.HouseService;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.util.Date;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. @Service("AppHomePageService")
  22. public class AppHomePageImplService implements AppHomePageService {
  23. @Resource
  24. public BookDao bookDao;
  25. @Resource
  26. public HouseDao houseDao;
  27. @Resource
  28. public HouseService houseService;
  29. @Resource
  30. public HotelService hotelService;
  31. @Resource
  32. public BookService bookService;
  33. @Override
  34. public IPage<Hotel> getHotelList(String queryValue, int page, int rows) {
  35. IPage<Hotel> iPage = new IPage();
  36. StringBuilder strSql = new StringBuilder("");
  37. if (!Func.checkNull(queryValue)){
  38. strSql.append(" and hname like '%").append(queryValue).append("%' ");
  39. }
  40. return hotelService.queryPagePrice(strSql.toString(),page,rows);
  41. }
  42. @Override
  43. public int getHotelTotal(String queryValue) {
  44. return 0;
  45. }
  46. @Override
  47. public Hotel getHotelAndHouseByHotelId(String hotelId, String queryStartTime, String queryEndTime) {
  48. if (Func.checkNull(hotelId))
  49. return new Hotel();
  50. Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
  51. if (Func.checkNull(hotel.getManagerId()))
  52. return hotel;
  53. System.out.println(hotel.getManagerId());// 需求确定使用商户id关联房型
  54. StringBuffer strSql = new StringBuffer();
  55. strSql.append(" and manager_id = '").append(hotel.getManagerId()).append("' ");
  56. List<House> houseList = houseService.queryList(strSql.toString());
  57. if (houseList == null )
  58. return hotel;
  59. // Map<String, House> houseMap = new HashMap();
  60. // houseList.forEach((House house) ->{
  61. // if (house.getId() == 0)
  62. // return;
  63. // houseMap.put(Func.parseStr(house.getId()),house);
  64. // });
  65. // 判断是否有房间,对每个房型进行标识
  66. StringBuffer strSqlBook = new StringBuffer();
  67. strSqlBook.append(" and hotel_manager_id = '").append(hotel.getManagerId()).append("' ");
  68. strSqlBook.append(" and order_start_time >= '").append(queryStartTime).append("' ");
  69. strSqlBook.append(" and order_end_time < '").append(queryEndTime).append("' ");
  70. List<Booking> bookList = bookService.queryList(strSqlBook.toString());
  71. Map<String, Integer> houseBookingMap = new HashMap();
  72. if (bookList != null && bookList.size() > 0)
  73. {
  74. Integer numberTemp = new Integer(0);
  75. for (Booking booking: bookList) {
  76. if (Func.checkNull(booking.getHouseId()))
  77. continue;
  78. if (houseBookingMap.containsKey(booking.getHouseId()))
  79. {
  80. numberTemp = houseBookingMap.get(booking.getHouseId());
  81. int i = Func.parseInt(numberTemp) + booking.getHouseOrderNumber();
  82. houseBookingMap.put(booking.getHouseId(),i);
  83. continue;
  84. }
  85. houseBookingMap.put(booking.getHouseId(),booking.getHouseOrderNumber());
  86. }
  87. }
  88. houseList.forEach((House house) ->{
  89. if (!houseBookingMap.containsKey(Func.parseStr(house.getId())))
  90. return;
  91. int i = Func.parseInt(house.getNumber()) - Func.parseInt(houseBookingMap.get(house.getId()));
  92. house.setRemainRooms(Func.parseStr(i));
  93. });
  94. hotel.setHouseList(houseList);
  95. return hotel;
  96. }
  97. }