package com.happy.service.impl; import com.happy.Model.BookingComment; import com.happy.Model.FileInfo; import com.happy.dao.BookingCommentDao; import com.happy.service.BookingCommentService; import com.happy.service.FileService; 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.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); } iPage.setPage(page); iPage.setTotalPage((int) Math.ceil((double) total / rows)); iPage.setRows(rows); iPage.setTotal(total); iPage.setPageList(vos); return iPage; } @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 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()); for (BookingComment parentComment : listByParentId){ getComment(parentComment); } bookingComment.setLowCommentList(listByParentId); } bookCommentDto.setBookingCommentList(list); return bookCommentDto; } public BookingComment getComment(BookingComment parentComment){ if(parentComment!=null){ List parentCommentList = bookingCommentDao.getByCommentId(parentComment.getId()); if(parentComment != null && parentCommentList != null){ for(BookingComment low : parentCommentList){//一级评论 getLowcomment(low); } } } 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); comment.setLowCommentList(list); for(BookingComment low1 : list){ getLowcomment(low1,comment); } } } private void getLowcomment(BookingComment comment,BookingComment parentCommentList){ List list = new ArrayList<>(); if (parentCommentList.getLowCommentList()!=null) { list = parentCommentList.getLowCommentList(); } List low = bookingCommentDao.getByCommentId(comment.getId()); if(low!=null){ list.addAll(low); comment.setLowCommentList(low); for(BookingComment low1 : list){ getLowcomment(low1,comment); } } } }