AppBookingCommentAction.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. package com.happy.action;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import com.happy.Model.BookingComment;
  5. import com.happy.Model.weixin.Users;
  6. import com.happy.Until.*;
  7. import com.happy.dto.BookCommentDto;
  8. import com.happy.dto.HotelEto;
  9. import com.happy.dto.IPage;
  10. import com.happy.dto.OrderRateDto;
  11. import com.happy.service.BookingCommentService;
  12. import com.happy.service.UserService;
  13. import com.happy.vo.*;
  14. import com.opensymphony.xwork2.ActionSupport;
  15. import com.alibaba.fastjson.JSONObject;
  16. import org.apache.struts2.ServletActionContext;
  17. import org.apache.struts2.interceptor.ServletRequestAware;
  18. import org.springframework.beans.BeanUtils;
  19. import javax.annotation.Resource;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.io.BufferedReader;
  23. import java.io.InputStreamReader;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. /**
  28. * 评价
  29. */
  30. public class AppBookingCommentAction extends ActionSupport implements ServletRequestAware {
  31. private HttpServletRequest request;
  32. public HttpServletResponse response;
  33. public HttpServletRequest getRequest() {
  34. return request;
  35. }
  36. public void setRequest(HttpServletRequest request) {
  37. this.request = request;
  38. }
  39. @Override
  40. public void setServletRequest(HttpServletRequest request) {
  41. this.request = request;
  42. }
  43. public HttpServletResponse getResponse() {
  44. return response;
  45. }
  46. public void setResponse(HttpServletResponse response) {
  47. this.response = response;
  48. }
  49. @Resource
  50. public BookingCommentService bookingCommentService;
  51. @Resource
  52. public UserService userService;
  53. // 回复评论id
  54. public String commentId;
  55. // 回复主评论id
  56. public String commentParentId;
  57. // 回复人名称
  58. public String commentName;
  59. // 评论订单id
  60. public String bookingId;
  61. // 评论民宿id
  62. public String hotelId;
  63. // 评论房型id
  64. public String houseId;
  65. // 内容
  66. public String content;
  67. // 评价状态
  68. public String commentStatus;
  69. // 总评分
  70. public Double score;
  71. // 卫生评分
  72. public Double scoreWs;
  73. // 服务评分
  74. public Double scoreFw;
  75. // 设施评分
  76. public Double scoreSs;
  77. // 位置评分
  78. public Double scoreWz;
  79. // 创建人
  80. public Integer createId;
  81. public String createUsername;
  82. // 创建时间
  83. public String createDate;
  84. // 修改时间
  85. public String modifyDate;
  86. public List<String> pictureList;
  87. public List<String> getPictureList() {
  88. return pictureList;
  89. }
  90. public void setPictureList(List<String> pictureList) {
  91. this.pictureList = pictureList;
  92. }
  93. public String getBookingId() {
  94. return bookingId;
  95. }
  96. public void setBookingId(String bookingId) {
  97. this.bookingId = bookingId;
  98. }
  99. public String getCommentId() {
  100. return commentId;
  101. }
  102. public void setCommentId(String commentId) {
  103. this.commentId = commentId;
  104. }
  105. public String getCommentParentId() {
  106. return commentParentId;
  107. }
  108. public void setCommentParentId(String commentParentId) {
  109. this.commentParentId = commentParentId;
  110. }
  111. public String getCommentName() {
  112. return commentName;
  113. }
  114. public void setCommentName(String commentName) {
  115. this.commentName = commentName;
  116. }
  117. public String getHotelId() {
  118. return hotelId;
  119. }
  120. public void setHotelId(String hotelId) {
  121. this.hotelId = hotelId;
  122. }
  123. public String getHouseId() {
  124. return houseId;
  125. }
  126. public void setHouseId(String houseId) {
  127. this.houseId = houseId;
  128. }
  129. public String getContent() {
  130. return content;
  131. }
  132. public void setContent(String content) {
  133. this.content = content;
  134. }
  135. public Double getScore() {
  136. return score;
  137. }
  138. public void setScore(Double score) {
  139. this.score = score;
  140. }
  141. public Double getScoreWs() {
  142. return scoreWs;
  143. }
  144. public void setScoreWs(Double scoreWs) {
  145. this.scoreWs = scoreWs;
  146. }
  147. public Double getScoreFw() {
  148. return scoreFw;
  149. }
  150. public void setScoreFw(Double scoreFw) {
  151. this.scoreFw = scoreFw;
  152. }
  153. public Double getScoreSs() {
  154. return scoreSs;
  155. }
  156. public void setScoreSs(Double scoreSs) {
  157. this.scoreSs = scoreSs;
  158. }
  159. public Double getScoreWz() {
  160. return scoreWz;
  161. }
  162. public void setScoreWz(Double scoreWz) {
  163. this.scoreWz = scoreWz;
  164. }
  165. public Integer getCreateId() {
  166. return createId;
  167. }
  168. public void setCreateId(Integer createId) {
  169. this.createId = createId;
  170. }
  171. public String getCreateUsername() {
  172. return createUsername;
  173. }
  174. public void setCreateUsername(String createUsername) {
  175. this.createUsername = createUsername;
  176. }
  177. public String getCreateDate() {
  178. return createDate;
  179. }
  180. public void setCreateDate(String createDate) {
  181. this.createDate = createDate;
  182. }
  183. public String getModifyDate() {
  184. return modifyDate;
  185. }
  186. public void setModifyDate(String modifyDate) {
  187. this.modifyDate = modifyDate;
  188. }
  189. public int page; // 当前页
  190. public int rows;// 每页显示的行数rows
  191. public int status; //状态,0显示全部,1显示有附件,2显示有回复
  192. public int getPage() {
  193. return page;
  194. }
  195. public void setPage(int page) {
  196. this.page = page;
  197. }
  198. public int getRows() {
  199. return rows;
  200. }
  201. public void setRows(int rows) {
  202. this.rows = rows;
  203. }
  204. public int getStatus() {
  205. return status;
  206. }
  207. public void setStatus(int status) {
  208. this.status = status;
  209. }
  210. public String bookingCommentId;
  211. public String getBookingCommentId() {
  212. return bookingCommentId;
  213. }
  214. public void setBookingCommentId(String bookingCommentId) {
  215. this.bookingCommentId = bookingCommentId;
  216. }
  217. public String usersId;
  218. public String getUsersId() {
  219. return usersId;
  220. }
  221. public void setUsersId(String usersId) {
  222. this.usersId = usersId;
  223. }
  224. public Integer userId;
  225. public Integer getUserId() {
  226. return userId;
  227. }
  228. public void setUserId(Integer userId) {
  229. this.userId = userId;
  230. }
  231. /**
  232. * 添加评论
  233. */
  234. public JSONObject orderRate() {
  235. JSONObject jsonObject = new JSONObject();
  236. JSONObject json = GetHttpParam.getHttpParam(request);
  237. System.out.println("参数:"+json.toString());
  238. if (json == null) {
  239. jsonObject.put("code", 400);
  240. jsonObject.put("success", false);
  241. jsonObject.put("message", "缺少数据---orderRate");
  242. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  243. return null;
  244. }
  245. OrderRateDto orderRateDto = JSONObject.parseObject(json.toString(), OrderRateDto.class);
  246. if (Func.checkNull(orderRateDto.toString())) {
  247. jsonObject.put("code", 400);
  248. jsonObject.put("success", false);
  249. jsonObject.put("message", "缺少数据---orderRate");
  250. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  251. return null;
  252. }
  253. if (orderRateDto.getScore() == null || orderRateDto.getScore() < 0 || orderRateDto.getScoreFw() == null || orderRateDto.getScoreFw() < 0 || orderRateDto.getScoreSs() == null || orderRateDto.getScoreSs() < 0 || orderRateDto.getScoreWs() == null || orderRateDto.getScoreWs() < 0 || orderRateDto.getScoreWz() == null || orderRateDto.getScoreWz() < 0 || orderRateDto.getBookingId() == null || orderRateDto.getHotelId() == null || orderRateDto.getHouseId() == null) {
  254. jsonObject.put("code", 400);
  255. jsonObject.put("success", false);
  256. jsonObject.put("message", "缺少数据---orderRate");
  257. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  258. return null;
  259. }
  260. BookingComment bookingComment = BookingComment.builder().bookingId(orderRateDto.getBookingId())
  261. .hotelId(orderRateDto.getHotelId()).houseId(orderRateDto.getHouseId()).content(orderRateDto.getContent()).commentStatus(orderRateDto.getCommentStatus())
  262. .score(orderRateDto.getScore()).scoreWs(orderRateDto.getScoreWs()).scoreFw(orderRateDto.getScoreFw())
  263. .scoreSs(orderRateDto.getScoreSs()).scoreWz(orderRateDto.getScoreWz()).createId(orderRateDto.getCreateId())
  264. .createUsername(orderRateDto.getCreateUsername()).createDate(orderRateDto.getCreateDate())
  265. .modifyDate(orderRateDto.getModifyDate()).build();
  266. int a = bookingCommentService.orderRate(bookingComment,orderRateDto.getPictureList());
  267. if (a > 0) {
  268. jsonObject.put("code", 200);
  269. jsonObject.put("message", "添加成功");
  270. jsonObject.put("success", true);
  271. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  272. return null;
  273. }
  274. jsonObject.put("message", "未知异常");
  275. jsonObject.put("success", false);
  276. jsonObject.put("code", 205);
  277. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  278. return null;
  279. }
  280. public JSONObject unevaluatedOrder(){
  281. JSONObject jsonObject = new JSONObject();
  282. if (page <= 0 || rows <= 0) {
  283. jsonObject.put("code", 400);
  284. jsonObject.put("success", false);
  285. jsonObject.put("message", "未传入page,rows数据---unevaluatedOrder");
  286. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  287. return null;
  288. }
  289. if (Func.checkNull(hotelId)||Func.checkNull(userId+"")) {
  290. jsonObject.put("code", 400);
  291. jsonObject.put("success", false);
  292. jsonObject.put("message", "未传入hotelId,usersId数据---unevaluatedOrder");
  293. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  294. return null;
  295. }
  296. UnevaluatedOrder vo=userService.collect(hotelId,userId);
  297. IPage<PersonageCommentVo> iPage = bookingCommentService.personageComment(0, userId+"", page, rows);
  298. vo.setPage(iPage);
  299. jsonObject.put("code", 200);
  300. jsonObject.put("message", "查看成功");
  301. jsonObject.put("success", true);
  302. jsonObject.put("data", vo);
  303. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  304. return null;
  305. }
  306. /**
  307. * 评价列表
  308. *
  309. * @return
  310. */
  311. public JSONObject evaluatePage() {
  312. JSONObject jsonObject = new JSONObject();
  313. if (Func.checkNull(hotelId)) {
  314. jsonObject.put("code", 400);
  315. jsonObject.put("success", false);
  316. jsonObject.put("message", "未传入hotel_id数据---evaluatePage");
  317. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  318. return null;
  319. }
  320. if (Func.checkNull(status + "")) {
  321. jsonObject.put("code", 400);
  322. jsonObject.put("success", false);
  323. jsonObject.put("message", "未传入status数据---evaluatePage");
  324. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  325. return null;
  326. }
  327. if (page <= 0 || rows <= 0) {
  328. jsonObject.put("code", 400);
  329. jsonObject.put("success", false);
  330. jsonObject.put("message", "未传入page,rows数据---evaluatePage");
  331. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  332. return null;
  333. }
  334. // 获取分页数据
  335. IPage<BookingCommentPageVo> iPage = bookingCommentService.evaluatePage(status, hotelId, page, rows);
  336. // 计算评分
  337. EvaluatePageVo vo = bookingCommentService.evaluateScore(hotelId);
  338. jsonObject.put("code", 200);
  339. jsonObject.put("message", "成功");
  340. jsonObject.put("success", true);
  341. jsonObject.put("page", iPage);
  342. jsonObject.put("score", vo);
  343. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  344. return null;
  345. }
  346. /**
  347. * 回复评论
  348. *
  349. * @return
  350. */
  351. public JSONObject replyComment() {
  352. JSONObject jsonObject = new JSONObject();
  353. if (Func.checkNull(content) || Func.checkNull(commentParentId)||Func.checkNull(commentId)) {
  354. jsonObject.put("code", 400);
  355. jsonObject.put("success", false);
  356. jsonObject.put("message", "缺少数据---replyComment");
  357. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  358. return null;
  359. }
  360. String commentName=this.commentName;
  361. BookingComment byId = bookingCommentService.getBycommentId(commentId);
  362. if (byId!=null) {
  363. Integer createId1 = byId.getCreateId();
  364. Users users = userService.queryByUserId(createId1 + "");
  365. if (users!=null) {
  366. commentName=users.getUser_name();
  367. }
  368. }
  369. BookingComment bookingComment = BookingComment.builder().commentId(commentId).commentParentId(commentParentId).commentName(commentName).bookingId(bookingId)
  370. .hotelId(hotelId).houseId(houseId).content(content).commentStatus(commentStatus)
  371. .score(score).scoreWs(scoreWs).scoreFw(scoreFw)
  372. .scoreSs(scoreSs).scoreWz(scoreWz).createId(createId)
  373. .createUsername(createUsername).createDate(createDate)
  374. .modifyDate(modifyDate).build();
  375. int i = bookingCommentService.replyComment(bookingComment);
  376. if (i > 0) {
  377. jsonObject.put("code", 200);
  378. jsonObject.put("message", "回复成功");
  379. jsonObject.put("success", true);
  380. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  381. return null;
  382. }
  383. jsonObject.put("message", "未知异常");
  384. jsonObject.put("code", 205);
  385. jsonObject.put("success", false);
  386. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  387. return null;
  388. }
  389. /**
  390. * 评论详情
  391. * @return
  392. */
  393. public JSONObject commentDetails() {
  394. JSONObject jsonObject = new JSONObject();
  395. if (Func.checkNull(bookingCommentId)) {
  396. jsonObject.put("code", 400);
  397. jsonObject.put("success", false);
  398. jsonObject.put("message", "未传入bookingCommentId数据---commentDetails");
  399. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  400. return null;
  401. }
  402. // 评论
  403. List<CommentVo> commentVoList = bookingCommentService.commentVoList(bookingCommentId);
  404. List<CommentListVo> commentListVos=null;
  405. if (commentVoList!=null&&commentVoList.size()>0) {
  406. commentListVos = TreeRecordsUtil.queryCommentTreeRecords(bookingCommentId, commentVoList);
  407. }
  408. // 详情
  409. CommentDetailsVo commentDetailsVo =bookingCommentService.commentDetails(bookingCommentId);
  410. if (commentDetailsVo.getCommentTime()!=null) {
  411. commentDetailsVo.setCommentTime(DateUtil.parseDateToStr((Func.parseDate(commentDetailsVo.getCommentTime())), DateUtil.Time_Formatter_Day));
  412. }
  413. if (commentDetailsVo.getLiveTime()!=null) {
  414. commentDetailsVo.setLiveTime(DateUtil.parseDateToStr((Func.parseDate(commentDetailsVo.getLiveTime())), DateUtil.Time_Formatter_Day));
  415. }
  416. jsonObject.put("code", 200);
  417. jsonObject.put("message", "成功");
  418. jsonObject.put("success", true);
  419. jsonObject.put("comment",commentListVos);
  420. jsonObject.put("commentDetails",commentDetailsVo);
  421. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  422. return null;
  423. }
  424. /**
  425. * 个人评论分页数据
  426. * @return
  427. */
  428. public JSONObject personageComment(){
  429. JSONObject jsonObject = new JSONObject();
  430. if (Func.checkNull(usersId)) {
  431. jsonObject.put("code", 400);
  432. jsonObject.put("success", false);
  433. jsonObject.put("message", "未传入usersIdId数据---personageComment");
  434. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  435. return null;
  436. }
  437. if (Func.checkNull(status + "")) {
  438. jsonObject.put("code", 400);
  439. jsonObject.put("success", false);
  440. jsonObject.put("message", "未传入status数据---personageComment");
  441. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  442. return null;
  443. }
  444. if (page <= 0 || rows <= 0) {
  445. jsonObject.put("code", 400);
  446. jsonObject.put("success", false);
  447. jsonObject.put("message", "未传入page,rows数据---personageComment");
  448. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  449. return null;
  450. }
  451. IPage<PersonageCommentVo> ipage=bookingCommentService.personageComment(status, usersId, page, rows);
  452. IPage<CommentDetailsVo> voIPage = new IPage<>();
  453. BeanUtils.copyProperties(ipage,voIPage);
  454. List<PersonageCommentVo> pageList = ipage.getPageList();
  455. PersonageCommentCountVo vo = bookingCommentService.personageCommentCount(usersId);
  456. if (pageList == null || pageList.size() <= 0 ||status==0) {
  457. jsonObject.put("code", 200);
  458. jsonObject.put("message", "成功");
  459. jsonObject.put("success", true);
  460. jsonObject.put("page", voIPage);
  461. jsonObject.put("data", vo);
  462. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  463. return null;
  464. }
  465. ArrayList<CommentDetailsVo> commentDetailsVos = new ArrayList<>();
  466. for (PersonageCommentVo personageCommentVo : pageList) {
  467. String bookingCommentId1 = personageCommentVo.getBookingCommentId();
  468. CommentDetailsVo commentDetailsVo =bookingCommentService.commentDetails(bookingCommentId1);
  469. commentDetailsVo.setVo(personageCommentVo);
  470. commentDetailsVos.add(commentDetailsVo);
  471. }
  472. voIPage.setPageList(commentDetailsVos);
  473. jsonObject.put("code", 200);
  474. jsonObject.put("message", "成功");
  475. jsonObject.put("success", true);
  476. jsonObject.put("page", voIPage);
  477. jsonObject.put("data", vo);
  478. ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  479. return null;
  480. }
  481. /**
  482. * 个人评论详情
  483. * @return
  484. */
  485. public JSONObject personageDetails(){
  486. JSONObject jsonObject = new JSONObject();
  487. if (Func.checkNull(bookingCommentId)) {
  488. jsonObject.put("code", 400);
  489. jsonObject.put("success", false);
  490. jsonObject.put("message", "未传入bookingCommentId数据---commentDetails");
  491. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  492. return null;
  493. }
  494. // 评论
  495. List<CommentVo> commentVoList = bookingCommentService.commentVoList(bookingCommentId);
  496. List<CommentListVo> commentListVos=null;
  497. if (commentVoList!=null&&commentVoList.size()>0) {
  498. commentListVos = TreeRecordsUtil.queryCommentTreeRecords(bookingCommentId, commentVoList);
  499. }
  500. // 详情
  501. PersonageDetailsVo personageDetailsVo =bookingCommentService.personageDetails(bookingCommentId);
  502. if (personageDetailsVo.getCommentTime()!=null) {
  503. personageDetailsVo.setCommentTime(DateUtil.parseDateToStr((Func.parseDate(personageDetailsVo.getCommentTime())), DateUtil.Time_Formatter_Day));
  504. }
  505. if (personageDetailsVo.getLiveTime()!=null) {
  506. personageDetailsVo.setLiveTime(DateUtil.parseDateToStr((Func.parseDate(personageDetailsVo.getLiveTime())), DateUtil.Time_Formatter_Day));
  507. }
  508. if (personageDetailsVo.getCheckOutTime()!=null) {
  509. personageDetailsVo.setCheckOutTime(DateUtil.parseDateToStr((Func.parseDate(personageDetailsVo.getCheckOutTime())), DateUtil.Time_Formatter_Day));
  510. }
  511. jsonObject.put("code", 200);
  512. jsonObject.put("message", "成功");
  513. jsonObject.put("success", true);
  514. jsonObject.put("comment",commentListVos);
  515. jsonObject.put("commentDetails",personageDetailsVo);
  516. ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
  517. return null;
  518. }
  519. }