| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- 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<String> pictureList) {
- // ������۱���������
- String id = bookingCommentDao.insertBookingComment(bookingComment);
- int i = 1;
- if (pictureList.size() > 0) {
- List<FileInfo> 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<BookingCommentPageVo> iPage = new IPage();
- List<BookingCommentPageVo> 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<BookingComment> queryPage(String sqlx,String sql, int page, int rows) {
- IPage<BookingComment> iPage = new IPage();
- List<BookingComment> 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<BookingComment> 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<FileInfo> fileInfos = fileDao.queryList("and link_id ='" + comment.getId() + "'");
- bookCommentDto.setFileInfos(fileInfos);
- }
- for (BookingComment bookingComment : list){
- List<BookingComment> 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<BookingComment> parentCommentList = bookingCommentDao.getByCommentId(parentComment.getId());
- if(parentComment != null && parentCommentList != null){
- for(BookingComment low : parentCommentList){//一级评论
- getLowcomment(low);
- }
- }
- }
- return parentComment;
- };
- private void getLowcomment(BookingComment comment){
- List<BookingComment> list = new ArrayList<>();
- if (comment.getLowCommentList()!=null) {
- list = comment.getLowCommentList();
- }
- List<BookingComment> 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<BookingComment> list = new ArrayList<>();
- if (parentCommentList.getLowCommentList()!=null) {
- list = parentCommentList.getLowCommentList();
- }
- List<BookingComment> low = bookingCommentDao.getByCommentId(comment.getId());
- if(low!=null){
- list.addAll(low);
- comment.setLowCommentList(low);
- for(BookingComment low1 : list){
- getLowcomment(low1,comment);
- }
- }
- }
- }
|