BookingCommentImplService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. package com.happy.service.impl;
  2. import com.happy.Model.*;
  3. import com.happy.dao.BookingCommentDao;
  4. import com.happy.dao.FileInfoDao;
  5. import com.happy.dto.BookCommentDto;
  6. import com.happy.dto.IPage;
  7. import com.happy.service.BookService;
  8. import com.happy.service.BookingCommentService;
  9. import com.happy.service.FileService;
  10. import com.happy.service.HouseService;
  11. import com.happy.vo.*;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import javax.annotation.Resource;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. @Service("BookingCommentService")
  18. public class BookingCommentImplService implements BookingCommentService {
  19. @Resource
  20. BookingCommentDao bookingCommentDao;
  21. @Resource
  22. BookService bookService;
  23. @Resource
  24. HouseService houseService;
  25. @Resource
  26. public FileInfoDao fileDao;
  27. @Resource
  28. FileService fileService;
  29. /**
  30. * 添加评论
  31. *
  32. * @param pictureList
  33. * @param bookingComment
  34. * @return
  35. */
  36. @Override
  37. @Transactional(rollbackFor = Exception.class)
  38. public int orderRate(BookingComment bookingComment, List<String> pictureList) {
  39. // 添加评论表并返回主键
  40. String id = bookingCommentDao.insertBookingComment(bookingComment);
  41. int i = 1;
  42. if (pictureList != null && pictureList.size() > 0) {
  43. List<FileInfo> fileInfoList = new ArrayList<>();
  44. for (String s : pictureList) {
  45. String[] split = s.split("/");
  46. String s1 = split[split.length - 1];
  47. FileInfo fileInfo = new FileInfo();
  48. fileInfo.setLinkId(id);
  49. fileInfo.setName(s1);
  50. fileInfo.setUrl(s);
  51. fileInfoList.add(fileInfo);
  52. }
  53. i = fileService.batchInsertFile(fileInfoList);
  54. }
  55. if (Long.valueOf(id) > 0 && i > 0) {
  56. return i;
  57. } else {
  58. return 0;
  59. }
  60. }
  61. @Override
  62. public IPage evaluatePage(int status, String hotelId, int page, int rows) {
  63. IPage<BookingCommentPageVo> iPage = new IPage();
  64. List<BookingCommentPageVo> vos = null;
  65. int total = 0;
  66. // 全部
  67. if (status == 0) {
  68. vos = bookingCommentDao.evaluatePage(hotelId, page, rows);
  69. total = bookingCommentDao.evaluateTotal(hotelId);
  70. } else if (status == 1) {
  71. // 带图
  72. vos = bookingCommentDao.evaluatePagepicture(hotelId, page, rows);
  73. total = bookingCommentDao.evaluateTotalpicture(hotelId);
  74. } else if (status == 2) {
  75. vos = bookingCommentDao.evaluatePageComment(hotelId, page, rows);
  76. total = bookingCommentDao.evaluateTotalComment(hotelId);
  77. }
  78. if (vos!=null&&vos.size()>0) {
  79. for (BookingCommentPageVo vo : vos) {
  80. if (vo.getUrl()!=null) {
  81. List<String> dateTimeList = vo.getUrl();
  82. String s = dateTimeList.get(0);
  83. String[] split = s.split(",");
  84. ArrayList<String> strings = new ArrayList<>();
  85. for (int i = 0; i < split.length; i++) {
  86. strings.add(split[i]);
  87. }
  88. vo.setUrl(strings);
  89. }
  90. }
  91. }
  92. iPage.setPage(page);
  93. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  94. iPage.setRows(rows);
  95. iPage.setTotal(total);
  96. iPage.setPageList(vos);
  97. return iPage;
  98. }
  99. @Override
  100. public EvaluatePageVo evaluateScore(String hotelId) {
  101. EvaluatePageVo vo=bookingCommentDao.evaluateScore(hotelId);
  102. int totalCount = bookingCommentDao.evaluateTotal(hotelId);
  103. int pictureTotalCount = bookingCommentDao.evaluateTotalpicture(hotelId);
  104. int commentTotalCount = bookingCommentDao.evaluateTotalComment(hotelId);
  105. vo.setTotalCount(totalCount);
  106. vo.setPictureCount(pictureTotalCount);
  107. vo.setCommentCount(commentTotalCount);
  108. return vo;
  109. }
  110. @Override
  111. public List<CommentVo> commentVoList(String bookingCommentId) {
  112. return bookingCommentDao.commentVoList(bookingCommentId);
  113. }
  114. @Override
  115. public int replyComment(BookingComment bookingComment) {
  116. //
  117. String id = bookingCommentDao.insertBookingComment(bookingComment);
  118. if (Long.valueOf(id) > 0) {
  119. return 1;
  120. } else {
  121. return 0;
  122. }
  123. }
  124. @Override
  125. public IPage<BookingComment> queryPage(String sqlx, String sql, int page, int rows) {
  126. IPage<BookingComment> iPage = new IPage();
  127. List<BookingComment> hotelCouponList = bookingCommentDao.queryPage(sqlx, page, rows);
  128. int total = bookingCommentDao.queryTotal(sql);
  129. iPage.setPageList(hotelCouponList);
  130. iPage.setPage(page);
  131. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  132. iPage.setRows(rows);
  133. iPage.setTotal(total);
  134. return iPage;
  135. }
  136. @Override
  137. public BookCommentDto getByBookingId(Integer id) {
  138. Booking book = bookService.getById(id);
  139. House house = houseService.getById(Integer.parseInt(book.getHouseId()));
  140. BookCommentDto bookCommentDto = new BookCommentDto();
  141. bookCommentDto.setBook(book);
  142. bookCommentDto.setHouse(house);
  143. return bookCommentDto;
  144. }
  145. @Override
  146. public int insterCommpent(BookingComment bookingComment) {
  147. BookingComment comment = new BookingComment();
  148. comment.setId(bookingComment.getCommentId());
  149. comment.setCommentStatus("2");
  150. int m = bookingCommentDao.updateCommpentStatus(comment);
  151. int i = bookingCommentDao.insterCommpent(bookingComment);
  152. if (i > 0 && m > 0) {
  153. return i;
  154. } else {
  155. return 0;
  156. }
  157. }
  158. @Override
  159. public BookingComment queryById(String id) {
  160. return bookingCommentDao.queryById(id);
  161. }
  162. @Override
  163. public int update(BookingComment bookingComment) {
  164. return bookingCommentDao.update(bookingComment);
  165. }
  166. @Override
  167. public CommentDetailsVo commentDetails(String bookingId) {
  168. CommentDetailsVo vo = bookingCommentDao.commentDetails(bookingId);
  169. if (vo.getUrl()!=null) {
  170. List<String> dateTimeList = vo.getUrl();
  171. String s = dateTimeList.get(0);
  172. String[] split = s.split(",");
  173. ArrayList<String> strings = new ArrayList<>();
  174. for (int i = 0; i < split.length; i++) {
  175. strings.add(split[i]);
  176. }
  177. vo.setUrl(strings);
  178. }
  179. return vo;
  180. }
  181. @Override
  182. public IPage personageComment(int status, String usersId, int page, int rows) {
  183. IPage<PersonageCommentVo> iPage = new IPage();
  184. List<PersonageCommentVo> vos = null;
  185. int total = 0;
  186. // 待评价
  187. if (status == 0) {
  188. vos = bookingCommentDao.personageNotCommentPage(usersId, page, rows);
  189. total = bookingCommentDao.personageNotCommentTotal(usersId);
  190. } else if (status == 1) {
  191. // 已评价
  192. vos = bookingCommentDao.personageCommentPage(usersId, page, rows);
  193. total = bookingCommentDao.personageCommentTotal(usersId);
  194. } else if (status == 2) {
  195. // 待审核
  196. vos = bookingCommentDao.auditPageComment(usersId, page, rows);
  197. total = bookingCommentDao.auditTotalComment(usersId);
  198. }else if (status == 3) {
  199. // 审批拒绝
  200. vos = bookingCommentDao.refuseAuditPageComment(usersId, page, rows);
  201. total = bookingCommentDao.refuseAuditTotalComment(usersId);
  202. }
  203. iPage.setPage(page);
  204. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  205. iPage.setRows(rows);
  206. iPage.setTotal(total);
  207. iPage.setPageList(vos);
  208. return iPage;
  209. }
  210. @Override
  211. public PersonageDetailsVo personageDetails(String bookingCommentId) {
  212. PersonageDetailsVo vo = bookingCommentDao.personageDetails(bookingCommentId);
  213. List<String> url = vo.getUrl();
  214. List<String> houseUrl = vo.getHouseUrl();
  215. if (url != null && url.size() > 0) {
  216. String s = url.get(0);
  217. String[] split = s.split(",");
  218. ArrayList<String> strings = new ArrayList<>();
  219. for (int i = 0; i < split.length; i++) {
  220. strings.add(split[i]);
  221. }
  222. vo.setUrl(strings);
  223. }
  224. if (url != houseUrl && houseUrl.size() > 0) {
  225. String s = houseUrl.get(0);
  226. String[] split = s.split(",");
  227. ArrayList<String> strings = new ArrayList<>();
  228. for (int i = 0; i < split.length; i++) {
  229. strings.add(split[i]);
  230. }
  231. vo.setHouseUrl(strings);
  232. }
  233. return vo;
  234. }
  235. @Override
  236. public PersonageCommentCountVo personageCommentCount(String usersId) {
  237. PersonageCommentCountVo vo = new PersonageCommentCountVo();
  238. //带评价数量
  239. Integer waiting = bookingCommentDao.personageNotCommentTotal(usersId);
  240. vo.setWaitingCount(waiting);
  241. // 已评价
  242. Integer rated = bookingCommentDao.personageCommentTotal(usersId);
  243. vo.setRatedCount(rated);
  244. return vo;
  245. }
  246. @Override
  247. public BookingComment getBycommentId(String commentId) {
  248. return bookingCommentDao.getBycommentId(commentId);
  249. }
  250. @Override
  251. public BookCommentDto getById(String bookId) {
  252. List<BookingComment> list = bookingCommentDao.getByBookId(bookId);
  253. if (list == null) return null;
  254. BookCommentDto bookCommentDto = new BookCommentDto();
  255. bookCommentDto.setBook(bookService.getById(Integer.parseInt(bookId)));
  256. BookingComment comment = list.stream().findFirst().orElse(null);
  257. if (comment != null) {
  258. List<FileInfo> fileInfos = fileDao.queryList("and link_id ='" + comment.getId() + "'");
  259. bookCommentDto.setFileInfos(fileInfos);
  260. }
  261. for (BookingComment bookingComment : list) {
  262. List<BookingComment> listByParentId = bookingCommentDao.getByParentId(bookingComment.getId());
  263. List<BookingComment> bookingCommentList = new ArrayList<>();
  264. if (listByParentId!=null&&listByParentId.size()>0) {
  265. for (BookingComment parentComment : listByParentId) {
  266. bookingCommentList.add(getComment(parentComment));
  267. }
  268. }
  269. bookingComment.setLowCommentList(bookingCommentList);
  270. }
  271. bookCommentDto.setBookingCommentList(list);
  272. return bookCommentDto;
  273. }
  274. public BookingComment getComment(BookingComment parentComment) {
  275. if (parentComment != null) {
  276. List<BookingComment> parentCommentList = bookingCommentDao.getByCommentId(parentComment.getId());
  277. List<BookingComment> list = new ArrayList<>();
  278. if (parentComment != null && parentCommentList != null) {
  279. for (BookingComment low : parentCommentList) {//一级评论
  280. list.add(low);
  281. getLowcomment(low, list);
  282. }
  283. parentComment.setLowCommentList(list);
  284. }
  285. }
  286. return parentComment;
  287. }
  288. // private void getLowcomment(BookingComment comment){
  289. // List<BookingComment> list = new ArrayList<>();
  290. // if (comment.getLowCommentList()!=null) {
  291. // list = comment.getLowCommentList();
  292. // }
  293. // List<BookingComment> low = bookingCommentDao.getByCommentId(comment.getId());
  294. // if(low != null){
  295. // list.addAll(low);
  296. // for(BookingComment low1 : list){
  297. // getLowcomment(low1,comment);
  298. // }
  299. // }
  300. // }
  301. private void getLowcomment(BookingComment comment, List<BookingComment> parentCommentList) {
  302. List<BookingComment> list = new ArrayList<>();
  303. List<BookingComment> low = bookingCommentDao.getByCommentId(comment.getId());
  304. if (low != null) {
  305. for (BookingComment low1 : low) {
  306. parentCommentList.add(low1);
  307. getLowcomment(low1, parentCommentList);
  308. }
  309. }
  310. }
  311. }