bookCommentAction.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.checkOutTime, '%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.checkOutTime, '%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. System.out.println(s1.toString());
  73. System.out.println(s2.toString());
  74. IPage<BookingComment> list = bookingCommentService.queryPage(s1.toString(),s2.toString(), page, rows);
  75. if(list != null && !"".equals(list)){
  76. resultJson.put("message", "查询分页成功");
  77. resultJson.put("code", 200);
  78. resultJson.put("data", list);
  79. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  80. }else{
  81. resultJson.put("message", "查询分页失败");
  82. resultJson.put("code", 500);
  83. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  84. }
  85. return null;
  86. }
  87. public String getByBookId(){
  88. JSONObject resultJson = new JSONObject();
  89. if (bookId == null) {
  90. resultJson.put("message", "请传入订单id");
  91. resultJson.put("code", 500);
  92. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  93. return null;
  94. }
  95. BookCommentDto book = bookingCommentService.getByBookingId(bookId);
  96. if (book != null) {
  97. resultJson.put("message", "查询成功");
  98. resultJson.put("code", 200);
  99. resultJson.put("data", book);
  100. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  101. return null;
  102. }else{
  103. resultJson.put("message", "未查到评价信息");
  104. resultJson.put("code", 500);
  105. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  106. return null;
  107. }
  108. }
  109. public String getById(){
  110. JSONObject resultJson = new JSONObject();
  111. if (id == null) {
  112. resultJson.put("message", "请传入订单id");
  113. resultJson.put("code", 500);
  114. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  115. return null;
  116. }
  117. BookCommentDto list = bookingCommentService.getById(id);
  118. if (list != null) {
  119. resultJson.put("message", "查询成功");
  120. resultJson.put("code", 200);
  121. resultJson.put("data", list);
  122. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  123. return null;
  124. }else{
  125. resultJson.put("message", "未查到评价信息");
  126. resultJson.put("code", 500);
  127. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  128. return null;
  129. }
  130. }
  131. public String insterCommpent(){
  132. JSONObject resultJson = new JSONObject();
  133. Gson gson = new Gson();
  134. com.alibaba.fastjson.JSONObject json = GetHttpParam.getRequestParameters(request);
  135. if (json == null) {
  136. resultJson.put("message", "请传入参数");
  137. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  138. return null;
  139. }
  140. BookingComment bookingComment = null;
  141. try{
  142. bookingComment = gson.fromJson(json.toString(), new TypeToken<BookingComment>() {}.getType());
  143. if (bookingComment.getCommentId()==null || bookingComment.getContent()==null || bookingComment.getCommentParentId()==null || bookingComment.getCommentName()==null){
  144. resultJson.put("message", "各参数不能为空");
  145. resultJson.put("code", 500);
  146. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  147. return null;
  148. }
  149. bookingComment.setCreateUsername("商家");//商家回复
  150. int m = bookingCommentService.insterCommpent(bookingComment);
  151. if (m > 0){
  152. resultJson.put("message", "回复成功");
  153. resultJson.put("code", 200);
  154. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  155. }else {
  156. resultJson.put("message", "回复失败");
  157. resultJson.put("code", 500);
  158. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  159. return null;
  160. }
  161. }catch (Exception e) {
  162. e.printStackTrace();
  163. }
  164. resultJson.put("message", "未知异常");
  165. resultJson.put("code", 205);
  166. ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
  167. return null;
  168. }
  169. }