| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- 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<String> pictureList) {
- // 添加评论表并返回主键
- String id = bookingCommentDao.insertBookingComment(bookingComment);
- int i = 1;
- if (pictureList != null && 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);
- }
- if (vos!=null&&vos.size()>0) {
- for (BookingCommentPageVo vo : vos) {
- if (vo.getUrl()!=null) {
- List<String> dateTimeList = vo.getUrl();
- String s = dateTimeList.get(0);
- String[] split = s.split(",");
- ArrayList<String> 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<CommentVo> 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<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 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<String> dateTimeList = vo.getUrl();
- String s = dateTimeList.get(0);
- String[] split = s.split(",");
- ArrayList<String> 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<PersonageCommentVo> iPage = new IPage();
- List<PersonageCommentVo> 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<String> url = vo.getUrl();
- List<String> houseUrl = vo.getHouseUrl();
- if (url != null && url.size() > 0) {
- String s = url.get(0);
- String[] split = s.split(",");
- ArrayList<String> 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<String> 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<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());
- List<BookingComment> 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<BookingComment> parentCommentList = bookingCommentDao.getByCommentId(parentComment.getId());
- List<BookingComment> 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<BookingComment> list = new ArrayList<>();
- // if (comment.getLowCommentList()!=null) {
- // list = comment.getLowCommentList();
- // }
- // List<BookingComment> low = bookingCommentDao.getByCommentId(comment.getId());
- // if(low != null){
- // list.addAll(low);
- // for(BookingComment low1 : list){
- // getLowcomment(low1,comment);
- // }
- // }
- // }
- private void getLowcomment(BookingComment comment, List<BookingComment> parentCommentList) {
- List<BookingComment> list = new ArrayList<>();
- List<BookingComment> low = bookingCommentDao.getByCommentId(comment.getId());
- if (low != null) {
- for (BookingComment low1 : low) {
- parentCommentList.add(low1);
- getLowcomment(low1, parentCommentList);
- }
- }
- }
- }
|