bookCommentAction.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.House;
  6. import com.happy.Until.GetHttpParam;
  7. import com.happy.Until.ResUtil;
  8. import com.happy.common.controller.BaseController;
  9. import com.happy.dto.BookCommentDto;
  10. import com.happy.dto.IPage;
  11. import com.happy.service.BookingCommentService;
  12. import com.happy.service.BookingComplaintService;
  13. import net.sf.json.JSONObject;
  14. import org.apache.struts2.ServletActionContext;
  15. import org.apache.struts2.interceptor.ServletRequestAware;
  16. import javax.annotation.Resource;
  17. import java.util.List;
  18. public class bookCommentAction extends BaseController implements ServletRequestAware {
  19. public String keywords;//关键字搜索
  20. public String score; //评分
  21. public Integer bookId; //关联订单id
  22. public String commentStartTime;//起始时间
  23. public String commentEndTime;//结束时间
  24. public String checkoutStartTime;//退房起始时间
  25. public String checkoutEndTime;//退房结束时间
  26. public String managerId;//商家id
  27. @Resource(name = "BookingCommentService")
  28. private BookingCommentService bookingCommentService;
  29. public String queryPage(){
  30. JSONObject resultJson = new JSONObject();
  31. StringBuilder s1 = new StringBuilder("");
  32. StringBuilder s2 = new StringBuilder("");
  33. if (managerId != null){
  34. s1.append(" and b.hotel_manager_id = ").append(managerId).append(" ");
  35. s2.append(" and a.hotel_manager_id = ").append(managerId).append(" ");
  36. }else {
  37. resultJson.put("message", "查询失败!商户id不能为空!");
  38. resultJson.put("code", 500);
  39. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  40. }
  41. if (keywords != null){
  42. s1.append(" and (a.booking_id like '%").append(keywords).append("%'");
  43. // s1.append(" or a.comment_name like '%").append(keywords).append("%'");
  44. s1.append(" or c.user_name like '%").append(keywords).append("%')");
  45. s2.append(" and (a.booking_id like '%").append(keywords).append("%'");
  46. s2.append(" or a.createName like '%").append(keywords).append("%')");
  47. }
  48. if (score != null){
  49. s1.append(" and a.score >= ").append(score).append(" ");
  50. s2.append(" and a.score >= ").append(score).append(" ");
  51. }
  52. if (commentStartTime != null){
  53. s1.append(" and DATE_FORMAT(a.create_date, '%Y-%m-%d') >= '").append(commentStartTime).append("' ");
  54. s2.append(" and DATE_FORMAT(a.create_date, '%Y-%m-%d') >= '").append(commentStartTime).append("' ");
  55. }
  56. if (commentEndTime != null){
  57. s1.append(" and DATE_FORMAT(a.create_date, '%Y-%m-%d') <= '").append(commentEndTime).append("' ");
  58. s2.append(" and DATE_FORMAT(a.create_date, '%Y-%m-%d') <= '").append(commentEndTime).append("' ");
  59. }
  60. if (checkoutStartTime != null){
  61. s1.append(" and DATE_FORMAT(b.check_out_time, '%Y-%m-%d') >= '").append(checkoutStartTime).append("' ");
  62. s2.append(" and DATE_FORMAT(a.check_out_time, '%Y-%m-%d') >= '").append(checkoutStartTime).append("' ");
  63. }
  64. if (checkoutEndTime != null){
  65. s1.append(" and DATE_FORMAT(b.check_out_time, '%Y-%m-%d') <= '").append(checkoutEndTime).append("' ");
  66. s2.append(" and DATE_FORMAT(a.check_out_time, '%Y-%m-%d') <= '").append(checkoutEndTime).append("' ");
  67. }
  68. if (status != null){
  69. s1.append(" and a.comment_status = ").append(status).append(" ");
  70. s2.append(" and a.comment_status = ").append(status).append(" ");
  71. }
  72. IPage<BookingComment> list = bookingCommentService.queryPage(s1.toString(),s2.toString(), page, rows);
  73. if(list != null && !"".equals(list)){
  74. resultJson.put("message", "查询分页成功");
  75. resultJson.put("code", 200);
  76. resultJson.put("data", list);
  77. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  78. }else{
  79. resultJson.put("message", "查询分页失败");
  80. resultJson.put("code", 500);
  81. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  82. }
  83. return null;
  84. }
  85. public String getByBookId(){
  86. JSONObject resultJson = new JSONObject();
  87. if (bookId == null) {
  88. resultJson.put("message", "请传入订单id");
  89. resultJson.put("code", 500);
  90. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  91. return null;
  92. }
  93. BookCommentDto book = bookingCommentService.getByBookingId(bookId);
  94. if (book != null) {
  95. resultJson.put("message", "查询成功");
  96. resultJson.put("code", 200);
  97. resultJson.put("data", book);
  98. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  99. return null;
  100. }else{
  101. resultJson.put("message", "未查到评价信息");
  102. resultJson.put("code", 500);
  103. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  104. return null;
  105. }
  106. }
  107. public String getById(){
  108. JSONObject resultJson = new JSONObject();
  109. if (id == null) {
  110. resultJson.put("message", "请传入订单id");
  111. resultJson.put("code", 500);
  112. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  113. return null;
  114. }
  115. BookCommentDto list = bookingCommentService.getById(id);
  116. if (list != null) {
  117. resultJson.put("message", "查询成功");
  118. resultJson.put("code", 200);
  119. resultJson.put("data", list);
  120. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  121. return null;
  122. }else{
  123. resultJson.put("message", "未查到评价信息");
  124. resultJson.put("code", 500);
  125. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  126. return null;
  127. }
  128. }
  129. public String insterCommpent(){
  130. JSONObject resultJson = new JSONObject();
  131. Gson gson = new Gson();
  132. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  133. if (json == null) {
  134. resultJson.put("message", "请传入参数");
  135. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  136. return null;
  137. }
  138. BookingComment bookingComment = null;
  139. try{
  140. bookingComment = gson.fromJson(json.toString(), new TypeToken<BookingComment>() {}.getType());
  141. if (bookingComment.getCommentId()==null || bookingComment.getContent()==null || bookingComment.getCommentParentId()==null || bookingComment.getCommentName()==null){
  142. resultJson.put("message", "各参数不能为空");
  143. resultJson.put("code", 500);
  144. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  145. return null;
  146. }
  147. bookingComment.setCommentName("商家");//商家回复
  148. int m = bookingCommentService.insterCommpent(bookingComment);
  149. if (m > 0){
  150. resultJson.put("message", "回复成功");
  151. resultJson.put("code", 200);
  152. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  153. }else {
  154. resultJson.put("message", "回复失败");
  155. resultJson.put("code", 500);
  156. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  157. return null;
  158. }
  159. }catch (Exception e) {
  160. e.printStackTrace();
  161. }
  162. resultJson.put("message", "未知异常");
  163. resultJson.put("code", 205);
  164. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  165. return null;
  166. }
  167. }