AppHomePageImplService.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package com.happy.service.impl;
  2. import com.happy.Model.Booking;
  3. import com.happy.Model.FileInfo;
  4. import com.happy.Model.Hotel;
  5. import com.happy.Model.House;
  6. import com.happy.Until.DateUtil;
  7. import com.happy.Until.Func;
  8. import com.happy.Until.TimeExchange;
  9. import com.happy.dao.BookDao;
  10. import com.happy.dao.HouseDao;
  11. import com.happy.dao.impl.FileImplInfoDao;
  12. import com.happy.dto.IPage;
  13. import com.happy.service.*;
  14. import org.springframework.stereotype.Service;
  15. import javax.annotation.Resource;
  16. import java.util.*;
  17. @Service("AppHomePageService")
  18. public class AppHomePageImplService implements AppHomePageService {
  19. @Resource
  20. public BookDao bookDao;
  21. @Resource
  22. public HouseDao houseDao;
  23. @Resource
  24. public HouseService houseService;
  25. @Resource
  26. public HotelService hotelService;
  27. @Resource
  28. public BookService bookService;
  29. @Resource
  30. public AdminManagerService adminManagerService;
  31. @Resource
  32. public FileService fileService;
  33. @Override
  34. public IPage<Hotel> getHotelList(String queryValue,String hotel_township, 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. if (!Func.checkNull(hotel_township)){
  41. strSql.append(" and c.hotel_township = '").append(hotel_township).append("' ");
  42. }
  43. return hotelService.queryPagePrice(strSql.toString(),page,rows);
  44. }
  45. @Override
  46. public int getHotelTotal(String queryValue) {
  47. return 0;
  48. }
  49. @Override
  50. public Hotel getHotelAndHouseByHotelId(String hotelId, String queryStartTime, String queryEndTime) {
  51. if (Func.checkNull(hotelId))
  52. return new Hotel();
  53. Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
  54. if (hotel == null || Func.checkNull(hotel.getManagerId()))
  55. return hotel;
  56. // 数据字典写入hotel
  57. Map dicMap = hotelService.queryHotelDicMap();
  58. if (!Func.checkNull(hotel.getHconfig()))
  59. {
  60. List<String> list = Arrays.asList(hotel.getHconfig().split(","));
  61. List hotelDicList = new ArrayList();
  62. for (String hotelDicId:list) {
  63. if (!dicMap.containsKey(Func.parseInt(hotelDicId)))
  64. continue;
  65. hotelDicList.add(dicMap.get(Func.parseInt(hotelDicId)));
  66. }
  67. hotel.setHconfigList(hotelDicList);
  68. }
  69. System.out.println(hotel.getManagerId());// 需求确定使用商户id关联房型
  70. StringBuffer strSql = new StringBuffer();
  71. strSql.append(" and manager_id = '").append(hotel.getManagerId()).append("' ");
  72. List<House> houseList = houseService.queryList(strSql.toString());
  73. if (houseList == null )
  74. return hotel;
  75. // 数据字典写入hotel
  76. List<String> hlist = new ArrayList<>();
  77. List houseDicList = new ArrayList();
  78. for (House house:houseList) {
  79. if (house == null || Func.checkNull(Func.parseStr(house.getNumber())))
  80. continue;
  81. // “,”号分逗开来
  82. hlist = Arrays.asList(house.gethConfig().split(","));
  83. houseDicList = new ArrayList();
  84. for (String houseDicId:hlist) {
  85. if (!dicMap.containsKey(Func.parseInt(houseDicId)))
  86. continue;
  87. houseDicList.add(dicMap.get(Func.parseInt(houseDicId)));
  88. }
  89. house.sethConfigList(houseDicList);
  90. }
  91. // 判断是否有房间,对每个房型进行标识
  92. StringBuffer strSqlBook = new StringBuffer();
  93. strSqlBook.append(" and hotel_manager_id = '").append(hotel.getManagerId()).append(" ' ");
  94. if (!Func.checkNull(queryStartTime))
  95. strSqlBook.append(" and order_start_time >= '").append(queryStartTime).append(" 00:00:00 ' ");
  96. if (!Func.checkNull(queryEndTime))
  97. strSqlBook.append(" and order_end_time < '").append(queryEndTime).append(" 23:59:59 ' ");
  98. List<Booking> bookList = bookService.queryList(strSqlBook.toString());
  99. Map<String, Integer> houseBookingMap = new HashMap();
  100. if (bookList != null && bookList.size() > 0)
  101. {
  102. Integer numberTemp = new Integer(0);
  103. for (Booking booking: bookList) {
  104. if (Func.checkNull(booking.getHouseId()))
  105. continue;
  106. if (houseBookingMap.containsKey(booking.getHouseId()))
  107. {
  108. numberTemp = houseBookingMap.get(booking.getHouseId());
  109. int i = Func.parseInt(numberTemp) + booking.getHouseOrderNumber();
  110. houseBookingMap.put(booking.getHouseId(),i);
  111. continue;
  112. }
  113. houseBookingMap.put(booking.getHouseId(),booking.getHouseOrderNumber());
  114. }
  115. }
  116. houseList.forEach((House house) ->{
  117. if (!houseBookingMap.containsKey(Func.parseStr(house.getId()))) {
  118. house.setRemainRooms(Func.parseStr(house.getNumber()));
  119. return;
  120. }
  121. StringBuilder fileSqlx = new StringBuilder("");
  122. fileSqlx.append("and link_id = '").append(house.getId()).append("'");
  123. List<FileInfo> fileInfoList = fileService.queryList(fileSqlx.toString());
  124. int i = Func.parseInt(house.getNumber()) - Func.parseInt(houseBookingMap.get(house.getId()));
  125. house.setRemainRooms(Func.parseStr(i));
  126. house.setFileInfoList(fileInfoList);
  127. });
  128. hotel.setHouseList(houseList);
  129. return hotel;
  130. }
  131. }