package com.happy.service.impl; import com.happy.Model.*; import com.happy.dao.BookingCommentDao; import com.happy.dao.FileInfoDao; import com.happy.dto.BookCommentDto; import com.happy.dto.IPage; import com.happy.service.BookService; import com.happy.service.BookingCommentService; import com.happy.service.FileService; import com.happy.service.HouseService; import com.happy.vo.*; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; @Service("BookingCommentService") public class BookingCommentImplService implements BookingCommentService { @Resource BookingCommentDao bookingCommentDao; @Resource BookService bookService; @Resource HouseService houseService; @Resource public FileInfoDao fileDao; @Resource FileService fileService; /** * 添加评论 * * @param pictureList * @param bookingComment * @return */ @Override @Transactional(rollbackFor = Exception.class) public int orderRate(BookingComment bookingComment, List pictureList) { // 添加评论表并返回主键 String id = bookingCommentDao.insertBookingComment(bookingComment); int i = 1; if (pictureList != null && pictureList.size() > 0) { List fileInfoList = new ArrayList<>(); for (String s : pictureList) { String[] split = s.split("/"); String s1 = split[split.length - 1]; FileInfo fileInfo = new FileInfo(); fileInfo.setLinkId(id); fileInfo.setName(s1); fileInfo.setUrl(s); fileInfoList.add(fileInfo); } i = fileService.batchInsertFile(fileInfoList); } if (Long.valueOf(id) > 0 && i > 0) { return i; } else { return 0; } } @Override public IPage evaluatePage(int status, String hotelId, int page, int rows) { IPage iPage = new IPage(); List vos = null; int total = 0; // 全部 if (status == 0) { vos = bookingCommentDao.evaluatePage(hotelId, page, rows); total = bookingCommentDao.evaluateTotal(hotelId); } else if (status == 1) { // 带图 vos = bookingCommentDao.evaluatePagepicture(hotelId, page, rows); total = bookingCommentDao.evaluateTotalpicture(hotelId); } else if (status == 2) { vos = bookingCommentDao.evaluatePageComment(hotelId, page, rows); total = bookingCommentDao.evaluateTotalComment(hotelId); } if (vos!=null&&vos.size()>0) { for (BookingCommentPageVo vo : vos) { if (vo.getUrl()!=null) { List dateTimeList = vo.getUrl(); String s = dateTimeList.get(0); String[] split = s.split(","); ArrayList strings = new ArrayList<>(); for (int i = 0; i < split.length; i++) { strings.add(split[i]); } vo.setUrl(strings); } } } iPage.setPage(page); iPage.setTotalPage((int) Math.ceil((double) total / rows)); iPage.setRows(rows); iPage.setTotal(total); iPage.setPageList(vos); return iPage; } @Override public EvaluatePageVo evaluateScore(String hotelId) { EvaluatePageVo vo=bookingCommentDao.evaluateScore(hotelId); int totalCount = bookingCommentDao.evaluateTotal(hotelId); int pictureTotalCount = bookingCommentDao.evaluateTotalpicture(hotelId); int commentTotalCount = bookingCommentDao.evaluateTotalComment(hotelId); vo.setTotalCount(totalCount); vo.setPictureCount(pictureTotalCount); vo.setCommentCount(commentTotalCount); return vo; } @Override public List commentVoList(String bookingCommentId) { return bookingCommentDao.commentVoList(bookingCommentId); } @Override public int replyComment(BookingComment bookingComment) { // String id = bookingCommentDao.insertBookingComment(bookingComment); if (Long.valueOf(id) > 0) { return 1; } else { return 0; } } @Override public IPage queryPage(String sqlx, String sql, int page, int rows) { IPage iPage = new IPage(); List hotelCouponList = bookingCommentDao.queryPage(sqlx, page, rows); int total = bookingCommentDao.queryTotal(sql); iPage.setPageList(hotelCouponList); iPage.setPage(page); iPage.setTotalPage((int) Math.ceil((double) total / rows)); iPage.setRows(rows); iPage.setTotal(total); return iPage; } @Override public BookCommentDto getByBookingId(Integer id) { Booking book = bookService.getById(id); House house = houseService.getById(Integer.parseInt(book.getHouseId())); BookCommentDto bookCommentDto = new BookCommentDto(); bookCommentDto.setBook(book); bookCommentDto.setHouse(house); return bookCommentDto; } @Override public int insterCommpent(BookingComment bookingComment) { BookingComment comment = new BookingComment(); comment.setId(bookingComment.getCommentId()); comment.setCommentStatus("2"); int m = bookingCommentDao.updateCommpentStatus(comment); int i = bookingCommentDao.insterCommpent(bookingComment); if (i > 0 && m > 0) { return i; } else { return 0; } } @Override public BookingComment queryById(String id) { return bookingCommentDao.queryById(id); } @Override public int update(BookingComment bookingComment) { return bookingCommentDao.update(bookingComment); } @Override public CommentDetailsVo commentDetails(String bookingId) { CommentDetailsVo vo = bookingCommentDao.commentDetails(bookingId); if (vo.getUrl()!=null) { List dateTimeList = vo.getUrl(); String s = dateTimeList.get(0); String[] split = s.split(","); ArrayList strings = new ArrayList<>(); for (int i = 0; i < split.length; i++) { strings.add(split[i]); } vo.setUrl(strings); } return vo; } @Override public IPage personageComment(int status, String usersId, int page, int rows) { IPage iPage = new IPage(); List vos = null; int total = 0; // 待评价 if (status == 0) { vos = bookingCommentDao.personageNotCommentPage(usersId, page, rows); total = bookingCommentDao.personageNotCommentTotal(usersId); } else if (status == 1) { // 已评价 vos = bookingCommentDao.personageCommentPage(usersId, page, rows); total = bookingCommentDao.personageCommentTotal(usersId); } else if (status == 2) { // 待审核 vos = bookingCommentDao.auditPageComment(usersId, page, rows); total = bookingCommentDao.auditTotalComment(usersId); }else if (status == 3) { // 审批拒绝 vos = bookingCommentDao.refuseAuditPageComment(usersId, page, rows); total = bookingCommentDao.refuseAuditTotalComment(usersId); } iPage.setPage(page); iPage.setTotalPage((int) Math.ceil((double) total / rows)); iPage.setRows(rows); iPage.setTotal(total); iPage.setPageList(vos); return iPage; } @Override public PersonageDetailsVo personageDetails(String bookingCommentId) { PersonageDetailsVo vo = bookingCommentDao.personageDetails(bookingCommentId); List url = vo.getUrl(); List houseUrl = vo.getHouseUrl(); if (url != null && url.size() > 0) { String s = url.get(0); String[] split = s.split(","); ArrayList strings = new ArrayList<>(); for (int i = 0; i < split.length; i++) { strings.add(split[i]); } vo.setUrl(strings); } if (url != houseUrl && houseUrl.size() > 0) { String s = houseUrl.get(0); String[] split = s.split(","); ArrayList strings = new ArrayList<>(); for (int i = 0; i < split.length; i++) { strings.add(split[i]); } vo.setHouseUrl(strings); } return vo; } @Override public PersonageCommentCountVo personageCommentCount(String usersId) { PersonageCommentCountVo vo = new PersonageCommentCountVo(); //带评价数量 Integer waiting = bookingCommentDao.personageNotCommentTotal(usersId); vo.setWaitingCount(waiting); // 已评价 Integer rated = bookingCommentDao.personageCommentTotal(usersId); vo.setRatedCount(rated); return vo; } @Override public BookingComment getBycommentId(String commentId) { return bookingCommentDao.getBycommentId(commentId); } @Override public BookCommentDto getById(String bookId) { List list = bookingCommentDao.getByBookId(bookId); if (list == null) return null; BookCommentDto bookCommentDto = new BookCommentDto(); bookCommentDto.setBook(bookService.getById(Integer.parseInt(bookId))); BookingComment comment = list.stream().findFirst().orElse(null); if (comment != null) { List fileInfos = fileDao.queryList("and link_id ='" + comment.getId() + "'"); bookCommentDto.setFileInfos(fileInfos); } for (BookingComment bookingComment : list) { List listByParentId = bookingCommentDao.getByParentId(bookingComment.getId()); List bookingCommentList = new ArrayList<>(); if (listByParentId!=null&&listByParentId.size()>0) { for (BookingComment parentComment : listByParentId) { bookingCommentList.add(getComment(parentComment)); } } bookingComment.setLowCommentList(bookingCommentList); } bookCommentDto.setBookingCommentList(list); return bookCommentDto; } public BookingComment getComment(BookingComment parentComment) { if (parentComment != null) { List parentCommentList = bookingCommentDao.getByCommentId(parentComment.getId()); List list = new ArrayList<>(); if (parentComment != null && parentCommentList != null) { for (BookingComment low : parentCommentList) {//一级评论 list.add(low); getLowcomment(low, list); } parentComment.setLowCommentList(list); } } return parentComment; } // private void getLowcomment(BookingComment comment){ // List list = new ArrayList<>(); // if (comment.getLowCommentList()!=null) { // list = comment.getLowCommentList(); // } // List low = bookingCommentDao.getByCommentId(comment.getId()); // if(low != null){ // list.addAll(low); // for(BookingComment low1 : list){ // getLowcomment(low1,comment); // } // } // } private void getLowcomment(BookingComment comment, List parentCommentList) { List list = new ArrayList<>(); List low = bookingCommentDao.getByCommentId(comment.getId()); if (low != null) { for (BookingComment low1 : low) { parentCommentList.add(low1); getLowcomment(low1, parentCommentList); } } } }