BookingCommentDaoImpl.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. package com.happy.dao.impl;
  2. import com.happy.Model.BookingComment;
  3. import com.happy.Model.HotelCoupon;
  4. import com.happy.Model.HouseNumber;
  5. import com.happy.Until.Func;
  6. import com.happy.Until.SqlUtil;
  7. import com.happy.Until.UUIDUtil;
  8. import com.happy.dao.BookingCommentDao;
  9. import com.happy.vo.BookingCommentPageVo;
  10. import com.happy.vo.EvaluatePageVo;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  13. import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  14. import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  15. import org.springframework.stereotype.Repository;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.UUID;
  19. @Repository("BookingCommentDao")
  20. public class BookingCommentDaoImpl implements BookingCommentDao {
  21. @Autowired
  22. private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
  23. public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
  24. return namedParameterJdbcTemplate;
  25. }
  26. public void setNamedParameterJdbcTemplate(
  27. NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
  28. this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
  29. }
  30. private String selectSql = "select " +
  31. "a.id,a.comment_id,a.comment_parent_id,a.comment_name,a.booking_id,a.hotel_id,a.house_id,a.content,a.comment_status,a.score,a.score_ws," +
  32. "a.score_fw,a.score_ss,a.score_wz,a.create_id,a.create_username,a.create_date,a.modify_date,a.status,b.check_out_time,c.user_name as createName"+
  33. " from booking_comment a" +
  34. " left join booking b on b.id = a.booking_id"+
  35. " left join users c on c.id = a.create_id" +
  36. " where 1=1 ";
  37. /**
  38. * ������ۣ�����������
  39. * @param bookingComment
  40. * @return
  41. */
  42. @Override
  43. public String insertBookingComment(BookingComment bookingComment) {
  44. String sql = "insert into `booking_comment`(id,comment_id,comment_parent_id,comment_name,booking_id,hotel_id,house_id,content,comment_status,score, score_ws,score_fw,score_ss,score_wz,create_id,create_username,create_date,modify_date,status) values(:id,:comment_id,:comment_parent_id,:comment_name,:booking_id,:hotel_id,:house_id,:content,:comment_status,:score,:score_ws,:score_fw,:score_ss,:score_wz,:create_id,:create_username,:create_date,:modify_date,:status) ";
  45. MapSqlParameterSource sps = new MapSqlParameterSource();
  46. sps.addValue("comment_id", bookingComment.getCommentId());
  47. sps.addValue("comment_parent_id", bookingComment.getCommentParentId());
  48. sps.addValue("comment_name", bookingComment.getCommentName());
  49. sps.addValue("booking_id",bookingComment.getBookingId());
  50. sps.addValue("hotel_id", bookingComment.getHotelId());
  51. sps.addValue("house_id", bookingComment.getHouseId());
  52. sps.addValue("content", bookingComment.getContent());
  53. // ���ʱĬ�ϴ��ظ�
  54. sps.addValue("comment_status",bookingComment.getCommentStatus());
  55. sps.addValue("score", bookingComment.getScore());
  56. sps.addValue("score_ws", bookingComment.getScoreWs());
  57. sps.addValue("score_fw", bookingComment.getScoreFw());
  58. sps.addValue("score_ss", bookingComment.getScoreSs());
  59. sps.addValue("score_wz", bookingComment.getScoreWz());
  60. sps.addValue("create_id", bookingComment.getCreateId());
  61. sps.addValue("create_username",bookingComment.getCreateUsername() );
  62. sps.addValue("create_date",bookingComment.getCreateDate());
  63. sps.addValue("modify_date",bookingComment.getModifyDate());
  64. sps.addValue("status", 1);
  65. String id ="";
  66. if(bookingComment.getId()==null){
  67. id = UUIDUtil.generateID()+"";
  68. sps.addValue("id", id);
  69. }else{
  70. id=bookingComment.getId()+"";
  71. sps.addValue("id", id);
  72. }
  73. int num = 0;
  74. try{
  75. num = namedParameterJdbcTemplate.update(sql, sps);
  76. }
  77. catch(Exception e){
  78. e.printStackTrace();
  79. }
  80. if (num>0) {
  81. return id;
  82. }else {
  83. id=num+"";
  84. }
  85. return id;
  86. }
  87. /**
  88. * ���۷�ҳ����
  89. * @param hotelId
  90. * @param page
  91. * @param rows
  92. * @return
  93. */
  94. @Override
  95. public List<BookingCommentPageVo> evaluatePage(String hotelId, int page, int rows) {
  96. int start = (page - 1) * rows;// ÿҳ����ʼ��
  97. String sql="SELECT bc.id AS id, bc.score AS score ,u.user_name AS userName,u.head_photo AS headPhoto,b.live_time AS liveTime,bc.create_date AS commentTime,h.h_name AS houseName,bc.content AS content,fi2.url AS url,ifnull( cc.commentSum, 0 ) AS commentCount FROM `booking_comment` bc LEFT JOIN ( SELECT fi.link_id, GROUP_CONCAT( fi.url ) AS url FROM file_info fi GROUP BY fi.link_id ) fi2 ON fi2.link_id = bc.id LEFT JOIN users u ON u.id = bc.create_id LEFT JOIN booking b ON b.id = bc.booking_id AND status_del = 1 LEFT JOIN house h ON h.id = bc.house_id AND h.status = 1 LEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL GROUP BY comment_id AND status = 1 ) cc ON bc.id = cc.comment_parent_id WHERE bc.comment_parent_id IS NULL AND bc.status = 1 and bc.hotel_id = :hotelId ORDER BY bc.create_date DESC LIMIT :start,:rows";
  98. MapSqlParameterSource sps = new MapSqlParameterSource();
  99. sps.addValue("start", start);
  100. sps.addValue("rows", rows);
  101. sps.addValue("hotelId",hotelId);
  102. List<BookingCommentPageVo> list = namedParameterJdbcTemplate.query(sql, sps,
  103. new BeanPropertyRowMapper<>(BookingCommentPageVo.class));
  104. if (list != null && list.size() > 0) return list;
  105. return null;
  106. }
  107. /**
  108. * ȫ�����۵��ܴ���
  109. * @param hotelId
  110. * @return
  111. */
  112. @Override
  113. public int evaluateTotal(String hotelId) {
  114. String sql="SELECT\n" +
  115. "\tcount(1) \n" +
  116. "FROM\n" +
  117. "\t`booking_comment` bc\n" +
  118. "\tLEFT JOIN ( SELECT fi.link_id, GROUP_CONCAT( fi.url ) AS url FROM file_info fi GROUP BY fi.link_id ) fi2 ON fi2.link_id = bc.id\n" +
  119. "\tLEFT JOIN users u ON u.id = bc.create_id\n" +
  120. "\tLEFT JOIN booking b ON b.id = bc.booking_id \n" +
  121. "\tAND status_del = 1\n" +
  122. "\tLEFT JOIN house h ON h.id = bc.house_id \n" +
  123. "\tAND h.`status` = 1\n" +
  124. "\tLEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL GROUP BY comment_id AND `status` = 1 ) cc ON bc.id = cc.comment_parent_id \n" +
  125. "WHERE\n" +
  126. "\tbc.comment_parent_id IS NULL \n" +
  127. "\tAND bc.`status` = 1 \n" +
  128. "\tAND bc.hotel_id = :hotelId \n" +
  129. "ORDER BY\n" +
  130. "\tbc.create_date DESC";
  131. MapSqlParameterSource sps = new MapSqlParameterSource();
  132. sps.addValue("hotelId",hotelId);
  133. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  134. }
  135. /**
  136. * ��ͼ�����۷�ҳ
  137. * @param hotelId
  138. * @param page
  139. * @param rows
  140. * @return
  141. */
  142. @Override
  143. public List<BookingCommentPageVo> evaluatePagepicture(String hotelId, int page, int rows) {
  144. int start = (page - 1) * rows;// ÿҳ����ʼ��
  145. String sql="SELECT bc.id AS id, bc.score AS score ,u.user_name AS userName,u.head_photo AS headPhoto,b.live_time AS liveTime,bc.create_date AS commentTime,h.h_name AS houseName,bc.content AS content,fi2.url AS url,ifnull( cc.commentSum, 0 ) AS commentCount FROM `booking_comment` bc INNER JOIN ( SELECT fi.link_id, GROUP_CONCAT( fi.url ) AS url FROM file_info fi GROUP BY fi.link_id ) fi2 ON fi2.link_id = bc.id LEFT JOIN users u ON u.id = bc.create_id LEFT JOIN booking b ON b.id = bc.booking_id AND status_del = 1 LEFT JOIN house h ON h.id = bc.house_id AND h.status = 1 LEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL GROUP BY comment_id AND status = 1 ) cc ON bc.id = cc.comment_parent_id WHERE bc.comment_parent_id IS NULL AND bc.status = 1 and bc.hotel_id = :hotelId ORDER BY bc.create_date DESC LIMIT :start,:rows";
  146. MapSqlParameterSource sps = new MapSqlParameterSource();
  147. sps.addValue("start", start);
  148. sps.addValue("rows", rows);
  149. sps.addValue("hotelId",hotelId);
  150. List<BookingCommentPageVo> list = namedParameterJdbcTemplate.query(sql, sps,
  151. new BeanPropertyRowMapper<>(BookingCommentPageVo.class));
  152. if (list != null && list.size() > 0) return list;
  153. return null;
  154. }
  155. @Override
  156. public int evaluateTotalpicture(String hotelId) {
  157. String sql="SELECT\n" +
  158. "\tcount(1) \n" +
  159. "FROM\n" +
  160. "\t`booking_comment` bc\n" +
  161. "\tINNER JOIN ( SELECT fi.link_id, GROUP_CONCAT( fi.url ) AS url FROM file_info fi GROUP BY fi.link_id ) fi2 ON fi2.link_id = bc.id\n" +
  162. "\tLEFT JOIN users u ON u.id = bc.create_id\n" +
  163. "\tLEFT JOIN booking b ON b.id = bc.booking_id \n" +
  164. "\tAND status_del = 1\n" +
  165. "\tLEFT JOIN house h ON h.id = bc.house_id \n" +
  166. "\tAND h.`status` = 1\n" +
  167. "\tLEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL GROUP BY comment_id AND `status` = 1 ) cc ON bc.id = cc.comment_parent_id \n" +
  168. "WHERE\n" +
  169. "\tbc.comment_parent_id IS NULL \n" +
  170. "\tAND bc.`status` = 1 \n" +
  171. "\tAND bc.hotel_id = :hotelId \n" +
  172. "ORDER BY\n" +
  173. "\tbc.create_date DESC";
  174. MapSqlParameterSource sps = new MapSqlParameterSource();
  175. sps.addValue("hotelId",hotelId);
  176. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  177. }
  178. /**
  179. * �����̼����۵ķ�ҳ
  180. * @param hotelId
  181. * @param page
  182. * @param rows
  183. * @return
  184. */
  185. @Override
  186. public List<BookingCommentPageVo> evaluatePageComment(String hotelId, int page, int rows) {
  187. int start = (page - 1) * rows;// ÿҳ����ʼ��
  188. String sql="SELECT bc.id AS id, bc.score AS score ,u.user_name AS userName,u.head_photo AS headPhoto,b.live_time AS liveTime,bc.create_date AS commentTime,h.h_name AS houseName,bc.content AS content,fi2.url AS url,ifnull( cc.commentSum, 0 ) AS commentCount FROM `booking_comment` bc LEFT JOIN ( SELECT fi.link_id, GROUP_CONCAT( fi.url ) AS url FROM file_info fi GROUP BY fi.link_id ) fi2 ON fi2.link_id = bc.id LEFT JOIN users u ON u.id = bc.create_id LEFT JOIN booking b ON b.id = bc.booking_id AND status_del = 1 LEFT JOIN house h ON h.id = bc.house_id AND h.status = 1 LEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL GROUP BY comment_id AND status = 1 ) cc ON bc.id = cc.comment_parent_id WHERE bc.comment_parent_id IS NULL AND bc.status = 1 and bc.hotel_id = :hotelId and bc.comment_status=2 ORDER BY bc.create_date DESC LIMIT :start,:rows";
  189. MapSqlParameterSource sps = new MapSqlParameterSource();
  190. sps.addValue("start", start);
  191. sps.addValue("rows", rows);
  192. sps.addValue("hotelId",hotelId);
  193. List<BookingCommentPageVo> list = namedParameterJdbcTemplate.query(sql, sps,
  194. new BeanPropertyRowMapper<>(BookingCommentPageVo.class));
  195. if (list != null && list.size() > 0) return list;
  196. return null;
  197. }
  198. /**
  199. * �����̼����۵��ܴ���
  200. * @param hotelId
  201. * @return
  202. */
  203. @Override
  204. public int evaluateTotalComment(String hotelId) {
  205. String sql="SELECT\n" +
  206. "\tcount(1) \n" +
  207. "FROM\n" +
  208. "\t`booking_comment` bc\n" +
  209. "\tLEFT JOIN ( SELECT fi.link_id, GROUP_CONCAT( fi.url ) AS url FROM file_info fi GROUP BY fi.link_id ) fi2 ON fi2.link_id = bc.id\n" +
  210. "\tLEFT JOIN users u ON u.id = bc.create_id\n" +
  211. "\tLEFT JOIN booking b ON b.id = bc.booking_id \n" +
  212. "\tAND status_del = 1\n" +
  213. "\tLEFT JOIN house h ON h.id = bc.house_id \n" +
  214. "\tAND h.`status` = 1\n" +
  215. "\tLEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL GROUP BY comment_id AND `status` = 1 ) cc ON bc.id = cc.comment_parent_id \n" +
  216. "WHERE\n" +
  217. "\tbc.comment_parent_id IS NULL \n" +
  218. "\tAND bc.`status` = 1 \n" +
  219. "\tAND bc.hotel_id = :hotelId \n" +
  220. "\tAND bc.comment_status=2 \n" +
  221. "ORDER BY\n" +
  222. "\tbc.create_date DESC";
  223. MapSqlParameterSource sps = new MapSqlParameterSource();
  224. sps.addValue("hotelId",hotelId);
  225. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  226. }
  227. @Override
  228. public EvaluatePageVo evaluateScore(String hotelId) {
  229. String sql="SELECT\n" +
  230. "\tround( AVG( score ), 1 ) as score ,\n" +
  231. "\tround( AVG( score_wz ), 1 ) as scoreWz,\n" +
  232. "\tround( AVG( score_ws ), 1 ) as scoreWs,\n" +
  233. "\tround( AVG( score_ss ), 1 ) as scoreSs,\n" +
  234. "\tround( AVG( score_fw ), 1 ) as scoreFw \n" +
  235. "FROM\n" +
  236. "\t`booking_comment` \n" +
  237. "WHERE\n" +
  238. "\tcomment_parent_id IS NULL \n" +
  239. "\tAND hotel_id = :hotelId \n" +
  240. "\tAND `status` = 1";
  241. MapSqlParameterSource sps = new MapSqlParameterSource();
  242. sps.addValue("hotelId",hotelId);
  243. List<EvaluatePageVo> list = null;
  244. try{
  245. list = namedParameterJdbcTemplate.query(sql, sps,
  246. new BeanPropertyRowMapper<>(EvaluatePageVo.class));
  247. }catch (Exception e){
  248. e.printStackTrace();
  249. }
  250. if(list != null && list.size()>0) return list.get(0);
  251. return null;
  252. }
  253. @Override
  254. public int insterCommpent(BookingComment bookingComment) {
  255. String sql = "INSERT INTO booking_comment (id, comment_id, comment_parent_id, comment_name, content,create_date,modify_date, status,comment_status,create_id,create_username) VALUES (:id, :comment_id, :comment_parent_id, :comment_name, :content, :create_date, :modify_date, :status,:comment_status,:create_id,:create_username)";
  256. MapSqlParameterSource sps = new MapSqlParameterSource();
  257. sps.addValue("comment_id",bookingComment.getCommentId());
  258. sps.addValue("comment_parent_id",bookingComment.getCommentParentId());
  259. sps.addValue("comment_name",bookingComment.getCommentName());
  260. sps.addValue("content",bookingComment.getContent());
  261. sps.addValue("create_date",UUIDUtil.getNewDate());
  262. sps.addValue("modify_date",UUIDUtil.getNewDate());
  263. sps.addValue("status",1);
  264. sps.addValue("comment_status",1);
  265. sps.addValue("create_id",bookingComment.getCreateId());
  266. sps.addValue("create_username",bookingComment.getCreateUsername());
  267. if(bookingComment.getId()==null){
  268. sps.addValue("id", String.valueOf(UUID.randomUUID()));
  269. }else{
  270. sps.addValue("id", bookingComment.getId());
  271. }
  272. int num = 0;
  273. try{
  274. num = namedParameterJdbcTemplate.update(sql, sps);
  275. }
  276. catch(Exception e){
  277. e.printStackTrace();
  278. }
  279. return num;
  280. }
  281. @Override
  282. public int updateCommpentStatus(BookingComment bookingComment) {
  283. StringBuffer stringBuffer = new StringBuffer(" update `booking_comment` set ");
  284. MapSqlParameterSource sps = new MapSqlParameterSource();
  285. if (!Func.checkNull(String.valueOf(bookingComment.getCommentStatus()))){
  286. stringBuffer.append(" comment_status=:comment_status,");
  287. stringBuffer.append(" modify_date=:modify_date");
  288. sps.addValue("comment_status", bookingComment.getCommentStatus());
  289. sps.addValue("modify_date",UUIDUtil.getNewDate());
  290. }
  291. // 将要修改的数据填充到查询语句中
  292. stringBuffer.append(" where id=:id ");
  293. sps.addValue("id", bookingComment.getId());
  294. int num = 0;
  295. try{
  296. num = namedParameterJdbcTemplate.update(stringBuffer.toString(), sps);
  297. }
  298. catch(Exception e){
  299. e.printStackTrace();
  300. }
  301. return num;
  302. }
  303. @Override
  304. public List<BookingComment> queryPage(String sqlx, int page, int rows) {
  305. SqlUtil.filterKeyword(sqlx);
  306. int start = (page - 1) * rows;// 每页的起始下标
  307. String sql = selectSql + sqlx + " and a.comment_id is null " + " ORDER BY create_date DESC limit :start,:rows ";
  308. MapSqlParameterSource sps = new MapSqlParameterSource();
  309. sps.addValue("start", start);
  310. sps.addValue("rows", rows);
  311. List<BookingComment> list = namedParameterJdbcTemplate.query(sql, sps,
  312. new BeanPropertyRowMapper<>(BookingComment.class));
  313. if (list != null && list.size() > 0) return list;
  314. return null;
  315. }
  316. @Override
  317. public int queryTotal(String sqlx) {
  318. SqlUtil.filterKeyword(sqlx);
  319. String sql = "SELECT count(*) FROM ("+ selectSql + " and a.comment_id is null " +") a where status != 0 "+sqlx;
  320. MapSqlParameterSource sps = new MapSqlParameterSource();
  321. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  322. }
  323. @Override
  324. public List<BookingComment> getByBookId(String bookId) {
  325. String sql = selectSql + " and a.booking_id = :id and a.comment_id is null and status != 0";
  326. MapSqlParameterSource sps = new MapSqlParameterSource();
  327. sps.addValue("id",bookId);
  328. List<BookingComment> list = new ArrayList<>();
  329. try{
  330. list = namedParameterJdbcTemplate.query(sql,sps, new BeanPropertyRowMapper<>(BookingComment.class));
  331. }catch (Exception e){
  332. e.printStackTrace();
  333. }
  334. if(list != null && list.size()>0) return list;
  335. return null;
  336. }
  337. @Override
  338. public List<BookingComment> getByParentId(String parentId) {
  339. String sql = selectSql + " and a.comment_parent_id = :id and a.comment_id = :id and status != 0";
  340. MapSqlParameterSource sps = new MapSqlParameterSource();
  341. sps.addValue("id",parentId);
  342. List<BookingComment> list = new ArrayList<>();
  343. try{
  344. list = namedParameterJdbcTemplate.query(sql,sps, new BeanPropertyRowMapper<>(BookingComment.class));
  345. }catch (Exception e){
  346. e.printStackTrace();
  347. }
  348. if(list != null && list.size()>0) return list;
  349. return null;
  350. }
  351. @Override
  352. public List<BookingComment> getByCommentId(String commentId) {
  353. String sql = selectSql + " and a.comment_id = :id and status != 0";
  354. MapSqlParameterSource sps = new MapSqlParameterSource();
  355. sps.addValue("id",commentId);
  356. List<BookingComment> list = new ArrayList<>();
  357. try{
  358. list = namedParameterJdbcTemplate.query(sql,sps, new BeanPropertyRowMapper<>(BookingComment.class));
  359. }catch (Exception e){
  360. e.printStackTrace();
  361. }
  362. if(list != null && list.size()>0) return list;
  363. return null;
  364. }
  365. }