BookingCommentImplService.java 13 KB

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