BookingCommentImplService.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package com.happy.service.impl;
  2. import com.happy.Model.BookingComment;
  3. import com.happy.Model.FileInfo;
  4. import com.happy.dao.BookingCommentDao;
  5. import com.happy.service.BookingCommentService;
  6. import com.happy.service.FileService;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import javax.annotation.Resource;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. @Service("BookingCommentService")
  13. public class BookingCommentImplService implements BookingCommentService {
  14. @Resource
  15. BookingCommentDao bookingCommentDao;
  16. @Resource
  17. BookService bookService;
  18. @Resource
  19. HouseService houseService;
  20. @Resource
  21. public FileInfoDao fileDao;
  22. @Resource
  23. FileService fileService;
  24. /**
  25. * �������
  26. *
  27. * @param pictureList
  28. * @param bookingComment
  29. * @return
  30. */
  31. @Override
  32. @Transactional(rollbackFor = Exception.class)
  33. public int orderRate( BookingComment bookingComment,List<String> pictureList) {
  34. // ������۱���������
  35. String id = bookingCommentDao.insertBookingComment(bookingComment);
  36. int i = 1;
  37. if (pictureList.size() > 0) {
  38. List<FileInfo> fileInfoList = new ArrayList<>();
  39. for (String s : pictureList) {
  40. String[] split = s.split("/");
  41. String s1 = split[split.length-1];
  42. FileInfo fileInfo = new FileInfo();
  43. fileInfo.setLinkId(id);
  44. fileInfo.setName(s1);
  45. fileInfo.setUrl(s);
  46. fileInfoList.add(fileInfo);
  47. }
  48. i = fileService.batchInsertFile(fileInfoList);
  49. }
  50. if (Long.valueOf(id) > 0 && i > 0) {
  51. return i;
  52. } else {
  53. return 0;
  54. }
  55. }
  56. @Override
  57. public IPage evaluatePage(int status, String hotelId, int page, int rows) {
  58. IPage<BookingCommentPageVo> iPage = new IPage();
  59. List<BookingCommentPageVo> vos = null;
  60. int total = 0;
  61. // ȫ��
  62. if (status == 0) {
  63. vos = bookingCommentDao.evaluatePage(hotelId, page, rows);
  64. total = bookingCommentDao.evaluateTotal(hotelId);
  65. } else if (status == 1) {
  66. // ��ͼ
  67. vos = bookingCommentDao.evaluatePagepicture(hotelId, page, rows);
  68. total = bookingCommentDao.evaluateTotalpicture(hotelId);
  69. } else if (status == 2) {
  70. vos = bookingCommentDao.evaluatePageComment(hotelId, page, rows);
  71. total = bookingCommentDao.evaluateTotalComment(hotelId);
  72. }
  73. iPage.setPage(page);
  74. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  75. iPage.setRows(rows);
  76. iPage.setTotal(total);
  77. iPage.setPageList(vos);
  78. return iPage;
  79. }
  80. @Override
  81. public int replyComment(BookingComment bookingComment) {
  82. //
  83. String id = bookingCommentDao.insertBookingComment(bookingComment);
  84. if (Long.valueOf(id) > 0) {
  85. return 1;
  86. } else {
  87. return 0;
  88. }
  89. }
  90. @Override
  91. public IPage<BookingComment> queryPage(String sqlx,String sql, int page, int rows) {
  92. IPage<BookingComment> iPage = new IPage();
  93. List<BookingComment> hotelCouponList = bookingCommentDao.queryPage(sqlx,page,rows);
  94. int total = bookingCommentDao.queryTotal(sql);
  95. iPage.setPageList(hotelCouponList);
  96. iPage.setPage(page);
  97. iPage.setTotalPage( (int)Math.ceil((double)total/rows));
  98. iPage.setRows(rows);
  99. iPage.setTotal(total);
  100. return iPage;
  101. }
  102. @Override
  103. public BookCommentDto getByBookingId(Integer id) {
  104. Booking book = bookService.getById(id);
  105. House house = houseService.getById(Integer.parseInt(book.getHouseId()));
  106. BookCommentDto bookCommentDto = new BookCommentDto();
  107. bookCommentDto.setBook(book);
  108. bookCommentDto.setHouse(house);
  109. return bookCommentDto;
  110. }
  111. @Override
  112. public int insterCommpent(BookingComment bookingComment) {
  113. BookingComment comment = new BookingComment();
  114. comment.setId(bookingComment.getCommentId());
  115. comment.setCommentStatus("2");
  116. int m = bookingCommentDao.updateCommpentStatus(comment);
  117. int i = bookingCommentDao.insterCommpent(bookingComment);
  118. if (i > 0 && m >0){
  119. return i;
  120. }else {
  121. return 0;
  122. }
  123. }
  124. @Override
  125. public BookCommentDto getById(String bookId) {
  126. List<BookingComment> list = bookingCommentDao.getByBookId(bookId);
  127. if (list == null) return null;
  128. BookCommentDto bookCommentDto = new BookCommentDto();
  129. bookCommentDto.setBook(bookService.getById(Integer.parseInt(bookId)));
  130. BookingComment comment = list.stream().findFirst().orElse(null);
  131. if (comment != null) {
  132. List<FileInfo> fileInfos = fileDao.queryList("and link_id ='" + comment.getId() + "'");
  133. bookCommentDto.setFileInfos(fileInfos);
  134. }
  135. for (BookingComment bookingComment : list){
  136. List<BookingComment> listByParentId = bookingCommentDao.getByParentId(bookingComment.getId());
  137. for (BookingComment parentComment : listByParentId){
  138. getComment(parentComment);
  139. }
  140. bookingComment.setLowCommentList(listByParentId);
  141. }
  142. bookCommentDto.setBookingCommentList(list);
  143. return bookCommentDto;
  144. }
  145. public BookingComment getComment(BookingComment parentComment){
  146. if(parentComment!=null){
  147. List<BookingComment> parentCommentList = bookingCommentDao.getByCommentId(parentComment.getId());
  148. if(parentComment != null && parentCommentList != null){
  149. for(BookingComment low : parentCommentList){//一级评论
  150. getLowcomment(low);
  151. }
  152. }
  153. }
  154. return parentComment;
  155. };
  156. private void getLowcomment(BookingComment comment){
  157. List<BookingComment> list = new ArrayList<>();
  158. if (comment.getLowCommentList()!=null) {
  159. list = comment.getLowCommentList();
  160. }
  161. List<BookingComment> low = bookingCommentDao.getByCommentId(comment.getId());
  162. if(low != null){
  163. list.addAll(low);
  164. comment.setLowCommentList(list);
  165. for(BookingComment low1 : list){
  166. getLowcomment(low1,comment);
  167. }
  168. }
  169. }
  170. private void getLowcomment(BookingComment comment,BookingComment parentCommentList){
  171. List<BookingComment> list = new ArrayList<>();
  172. if (parentCommentList.getLowCommentList()!=null) {
  173. list = parentCommentList.getLowCommentList();
  174. }
  175. List<BookingComment> low = bookingCommentDao.getByCommentId(comment.getId());
  176. if(low!=null){
  177. list.addAll(low);
  178. comment.setLowCommentList(low);
  179. for(BookingComment low1 : list){
  180. getLowcomment(low1,comment);
  181. }
  182. }
  183. }
  184. }