BookingCommentImplDao.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. package com.happy.dao.impl;
  2. import com.happy.Model.BookingComment;
  3. import com.happy.Until.Func;
  4. import com.happy.Until.SqlUtil;
  5. import com.happy.Until.UUIDUtil;
  6. import com.happy.dao.BookingCommentDao;
  7. import com.happy.vo.BookingCommentPageVo;
  8. import com.happy.vo.EvaluatePageVo;
  9. import com.happy.vo.*;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  12. import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  13. import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  14. import org.springframework.stereotype.Repository;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. import java.util.UUID;
  18. @Repository("BookingCommentDao")
  19. public class BookingCommentImplDao implements BookingCommentDao {
  20. @Autowired
  21. private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
  22. public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
  23. return namedParameterJdbcTemplate;
  24. }
  25. public void setNamedParameterJdbcTemplate(
  26. NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
  27. this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
  28. }
  29. private String selectSql = "select " +
  30. "a.id,b.order_num,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," +
  31. "a.score_fw,a.score_ss,a.score_wz,a.create_id,a.create_username, DATE_FORMAT(a.create_date, '%Y-%m-%d %H:%i:%s') create_date, DATE_FORMAT(a.modify_date, '%Y-%m-%d %H:%i:%s') modify_date,a.status,DATE_FORMAT(b.check_out_time, '%Y-%m-%d %H:%i:%s') as checkOutTime,c.user_name as createName,b.hotel_manager_id,c.head_photo as headPhoto" +
  32. " from booking_comment a" +
  33. " left join booking b on b.id = a.booking_id" +
  34. " left join users c on c.id = a.create_id" +
  35. " where 1=1 ";
  36. /**
  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, " +
  45. "score_ws,score_fw,score_ss,score_wz,create_id,create_username,create_date,modify_date,status) " +
  46. "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) ";
  47. MapSqlParameterSource sps = new MapSqlParameterSource();
  48. sps.addValue("comment_id", bookingComment.getCommentId());
  49. sps.addValue("comment_parent_id", bookingComment.getCommentParentId());
  50. sps.addValue("comment_name", bookingComment.getCommentName());
  51. sps.addValue("booking_id", bookingComment.getBookingId());
  52. sps.addValue("hotel_id", bookingComment.getHotelId());
  53. sps.addValue("house_id", bookingComment.getHouseId());
  54. sps.addValue("content", bookingComment.getContent());
  55. // ���ʱĬ�ϴ��ظ�
  56. sps.addValue("comment_status", bookingComment.getCommentStatus());
  57. sps.addValue("score", bookingComment.getScore());
  58. sps.addValue("score_ws", bookingComment.getScoreWs());
  59. sps.addValue("score_fw", bookingComment.getScoreFw());
  60. sps.addValue("score_ss", bookingComment.getScoreSs());
  61. sps.addValue("score_wz", bookingComment.getScoreWz());
  62. sps.addValue("create_id", bookingComment.getCreateId());
  63. sps.addValue("create_username", bookingComment.getCreateUsername());
  64. sps.addValue("create_date", bookingComment.getCreateDate());
  65. sps.addValue("modify_date", bookingComment.getModifyDate());
  66. sps.addValue("status", 2);
  67. String id = "";
  68. if (bookingComment.getId() == null) {
  69. id = UUIDUtil.generateID() + "";
  70. sps.addValue("id", id);
  71. } else {
  72. id = bookingComment.getId() + "";
  73. sps.addValue("id", id);
  74. }
  75. int num = 0;
  76. try {
  77. num = namedParameterJdbcTemplate.update(sql, sps);
  78. } catch (Exception e) {
  79. e.printStackTrace();
  80. }
  81. if (num > 0) {
  82. return id;
  83. } else {
  84. id = num + "";
  85. }
  86. return id;
  87. }
  88. /**
  89. * ���۷�ҳ����
  90. *
  91. * @param hotelId
  92. * @param page
  93. * @param rows
  94. * @return
  95. */
  96. @Override
  97. public List<BookingCommentPageVo> evaluatePage(String hotelId, int page, int rows) {
  98. int start = (page - 1) * rows;// ÿҳ����ʼ��
  99. 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 AND status = 1 GROUP BY comment_parent_id ) 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";
  100. MapSqlParameterSource sps = new MapSqlParameterSource();
  101. sps.addValue("start", start);
  102. sps.addValue("rows", rows);
  103. sps.addValue("hotelId", hotelId);
  104. List<BookingCommentPageVo> list = namedParameterJdbcTemplate.query(sql, sps,
  105. new BeanPropertyRowMapper<>(BookingCommentPageVo.class));
  106. if (list != null && list.size() > 0) return list;
  107. return null;
  108. }
  109. /**
  110. * ȫ�����۵��ܴ���
  111. *
  112. * @param hotelId
  113. * @return
  114. */
  115. @Override
  116. public int evaluateTotal(String hotelId) {
  117. String sql = "SELECT\n" +
  118. "\tcount(1) \n" +
  119. "FROM\n" +
  120. "\t`booking_comment` bc\n" +
  121. "\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" +
  122. "\tLEFT JOIN users u ON u.id = bc.create_id\n" +
  123. "\tLEFT JOIN booking b ON b.id = bc.booking_id \n" +
  124. "\tAND status_del = 1\n" +
  125. "\tLEFT JOIN house h ON h.id = bc.house_id \n" +
  126. "\tAND h.`status` = 1\n" +
  127. "\tLEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL AND `status` = 1 GROUP BY comment_parent_id ) cc ON bc.id = cc.comment_parent_id \n" +
  128. "WHERE\n" +
  129. "\tbc.comment_parent_id IS NULL \n" +
  130. "\tAND bc.`status` = 1 \n" +
  131. "\tAND bc.hotel_id = :hotelId \n" +
  132. "ORDER BY\n" +
  133. "\tbc.create_date DESC";
  134. MapSqlParameterSource sps = new MapSqlParameterSource();
  135. sps.addValue("hotelId", hotelId);
  136. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  137. }
  138. /**
  139. * ��ͼ�����۷�ҳ
  140. *
  141. * @param hotelId
  142. * @param page
  143. * @param rows
  144. * @return
  145. */
  146. @Override
  147. public List<BookingCommentPageVo> evaluatePagepicture(String hotelId, int page, int rows) {
  148. int start = (page - 1) * rows;// ÿҳ����ʼ��
  149. 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 AND status = 1 GROUP BY comment_parent_id ) 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";
  150. MapSqlParameterSource sps = new MapSqlParameterSource();
  151. sps.addValue("start", start);
  152. sps.addValue("rows", rows);
  153. sps.addValue("hotelId", hotelId);
  154. List<BookingCommentPageVo> list = namedParameterJdbcTemplate.query(sql, sps,
  155. new BeanPropertyRowMapper<>(BookingCommentPageVo.class));
  156. if (list != null && list.size() > 0) return list;
  157. return null;
  158. }
  159. @Override
  160. public int evaluateTotalpicture(String hotelId) {
  161. String sql = "SELECT\n" +
  162. "\tcount(1) \n" +
  163. "FROM\n" +
  164. "\t`booking_comment` bc\n" +
  165. "\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" +
  166. "\tLEFT JOIN users u ON u.id = bc.create_id\n" +
  167. "\tLEFT JOIN booking b ON b.id = bc.booking_id \n" +
  168. "\tAND status_del = 1\n" +
  169. "\tLEFT JOIN house h ON h.id = bc.house_id \n" +
  170. "\tAND h.`status` = 1\n" +
  171. "\tLEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL AND `status` = 1 GROUP BY comment_parent_id ) cc ON bc.id = cc.comment_parent_id \n" +
  172. "WHERE\n" +
  173. "\tbc.comment_parent_id IS NULL \n" +
  174. "\tAND bc.`status` = 1 \n" +
  175. "\tAND bc.hotel_id = :hotelId \n" +
  176. "ORDER BY\n" +
  177. "\tbc.create_date DESC";
  178. MapSqlParameterSource sps = new MapSqlParameterSource();
  179. sps.addValue("hotelId", hotelId);
  180. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  181. }
  182. /**
  183. * �����̼����۵ķ�ҳ
  184. *
  185. * @param hotelId
  186. * @param page
  187. * @param rows
  188. * @return
  189. */
  190. @Override
  191. public List<BookingCommentPageVo> evaluatePageComment(String hotelId, int page, int rows) {
  192. int start = (page - 1) * rows;// ÿҳ����ʼ��
  193. 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 AND status = 1 GROUP BY comment_parent_id ) 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";
  194. MapSqlParameterSource sps = new MapSqlParameterSource();
  195. sps.addValue("start", start);
  196. sps.addValue("rows", rows);
  197. sps.addValue("hotelId", hotelId);
  198. List<BookingCommentPageVo> list = namedParameterJdbcTemplate.query(sql, sps,
  199. new BeanPropertyRowMapper<>(BookingCommentPageVo.class));
  200. if (list != null && list.size() > 0) return list;
  201. return null;
  202. }
  203. /**
  204. * �����̼����۵��ܴ���
  205. *
  206. * @param hotelId
  207. * @return
  208. */
  209. @Override
  210. public int evaluateTotalComment(String hotelId) {
  211. String sql = "SELECT\n" +
  212. "\tcount(1) \n" +
  213. "FROM\n" +
  214. "\t`booking_comment` bc\n" +
  215. "\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" +
  216. "\tLEFT JOIN users u ON u.id = bc.create_id\n" +
  217. "\tLEFT JOIN booking b ON b.id = bc.booking_id \n" +
  218. "\tAND status_del = 1\n" +
  219. "\tLEFT JOIN house h ON h.id = bc.house_id \n" +
  220. "\tAND h.`status` = 1\n" +
  221. "\tLEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL AND `status` = 1 GROUP BY comment_parent_id ) cc ON bc.id = cc.comment_parent_id \n" +
  222. "WHERE\n" +
  223. "\tbc.comment_parent_id IS NULL \n" +
  224. "\tAND bc.`status` = 1 \n" +
  225. "\tAND bc.hotel_id = :hotelId \n" +
  226. "\tAND bc.comment_status=2 \n" +
  227. "ORDER BY\n" +
  228. "\tbc.create_date DESC";
  229. MapSqlParameterSource sps = new MapSqlParameterSource();
  230. sps.addValue("hotelId", hotelId);
  231. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  232. }
  233. @Override
  234. public EvaluatePageVo evaluateScore(String hotelId) {
  235. String sql = "SELECT\n" +
  236. "\tround( AVG( score ), 1 ) as score ,\n" +
  237. "\tround( AVG( score_wz ), 1 ) as scoreWz,\n" +
  238. "\tround( AVG( score_ws ), 1 ) as scoreWs,\n" +
  239. "\tround( AVG( score_ss ), 1 ) as scoreSs,\n" +
  240. "\tround( AVG( score_fw ), 1 ) as scoreFw \n" +
  241. "FROM\n" +
  242. "\t`booking_comment` \n" +
  243. "WHERE\n" +
  244. "\tcomment_parent_id IS NULL \n" +
  245. "\tAND hotel_id = :hotelId \n" +
  246. "\tAND `status` = 1";
  247. MapSqlParameterSource sps = new MapSqlParameterSource();
  248. sps.addValue("hotelId", hotelId);
  249. List<EvaluatePageVo> list = null;
  250. try {
  251. list = namedParameterJdbcTemplate.query(sql, sps,
  252. new BeanPropertyRowMapper<>(EvaluatePageVo.class));
  253. } catch (Exception e) {
  254. e.printStackTrace();
  255. }
  256. if (list != null && list.size() > 0) return list.get(0);
  257. return null;
  258. }
  259. @Override
  260. public List<CommentVo> commentVoList(String bookingCommentId) {
  261. String sql = "SELECT\n" +
  262. "\tbc.id as id ,\n" +
  263. "\tbc.comment_id as commentId,\n" +
  264. "\tbc.comment_name as commentName,\n" +
  265. "\tbc.create_username as userName,\n" +
  266. "\tu.head_photo as headPhoto,\n" +
  267. "\tbc.create_date as dateTime,\n" +
  268. "\tbc.content as content \n" +
  269. "FROM\n" +
  270. "\t`booking_comment` bc\n" +
  271. "\tLEFT JOIN users u ON u.id = bc.create_id \n" +
  272. "WHERE\n" +
  273. "\tbc.comment_parent_id = :bookingCommentId and bc.status=1";
  274. MapSqlParameterSource sps = new MapSqlParameterSource();
  275. sps.addValue("bookingCommentId", bookingCommentId);
  276. List<CommentVo> list = namedParameterJdbcTemplate.query(sql, sps,
  277. new BeanPropertyRowMapper<>(CommentVo.class));
  278. if (list != null && list.size() > 0) return list;
  279. return null;
  280. }
  281. @Override
  282. public int insterCommpent(BookingComment bookingComment) {
  283. 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)";
  284. MapSqlParameterSource sps = new MapSqlParameterSource();
  285. sps.addValue("comment_id", bookingComment.getCommentId());
  286. sps.addValue("comment_parent_id", bookingComment.getCommentParentId());
  287. sps.addValue("comment_name", bookingComment.getCommentName());
  288. sps.addValue("content", bookingComment.getContent());
  289. sps.addValue("create_date", UUIDUtil.getNewDate());
  290. sps.addValue("modify_date", UUIDUtil.getNewDate());
  291. sps.addValue("status", 1);
  292. sps.addValue("comment_status", 1);
  293. sps.addValue("create_id", bookingComment.getCreateId());
  294. sps.addValue("create_username", bookingComment.getCreateUsername());
  295. if (bookingComment.getId() == null) {
  296. sps.addValue("id", String.valueOf(UUID.randomUUID()));
  297. } else {
  298. sps.addValue("id", bookingComment.getId());
  299. }
  300. int num = 0;
  301. try {
  302. num = namedParameterJdbcTemplate.update(sql, sps);
  303. } catch (Exception e) {
  304. e.printStackTrace();
  305. }
  306. return num;
  307. }
  308. @Override
  309. public CommentDetailsVo commentDetails(String bookingCommentId) {
  310. String sql = "SELECT\n" +
  311. "\tbc.id AS id,\n" +
  312. "\tu.user_name AS userName,\n" +
  313. "\tu.head_photo AS headPhoto,\n" +
  314. "\tbc.score AS score,\n" +
  315. "\tb.live_time AS liveTime,\n" +
  316. "\tbc.create_date AS commentTime,\n" +
  317. "\tb.house_name AS houseName,\n" +
  318. "\tbc.content AS content,\n" +
  319. "\tfi2.url AS url,\n" +
  320. "\tb.hotel_name AS hotelName,\n" +
  321. "\t( SELECT round( AVG( score ), 1 ) FROM `booking_comment` WHERE comment_parent_id IS NULL AND `status` = 1 AND hotel_id = bc.hotel_id ) AS hotelScore,\n" +
  322. "\thd.`name` AS hotelTownship,\n" +
  323. "\tb.hotel_type AS hotelType,\n" +
  324. "\tifnull( cc.commentSum, 0 ) AS commentCount ,h.cover_img as coverImg,b.hotel_id as hotelId \n" +
  325. "FROM\n" +
  326. "\t`booking_comment` bc\n" +
  327. "\tLEFT JOIN users u ON u.id = bc.create_id\n" +
  328. "\tLEFT JOIN booking b ON b.id = bc.booking_id LEFT JOIN hotel h ON h.id=b.hotel_id \n" +
  329. "\tAND b.status_del = 1\n" +
  330. "\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" +
  331. "\tLEFT JOIN hotel_dict hd ON hd.id = b.hotel_township \n" +
  332. "\tAND hd.`status` = 1\n" +
  333. "\tLEFT JOIN ( SELECT comment_parent_id, count( 1 ) commentSum FROM booking_comment WHERE comment_parent_id IS NOT NULL AND `status` = 1 GROUP BY comment_parent_id ) cc ON bc.id = cc.comment_parent_id\n" +
  334. "\tWHERE bc.`status`=1 and bc.id= :bookingCommentId";
  335. MapSqlParameterSource sps = new MapSqlParameterSource();
  336. sps.addValue("bookingCommentId", bookingCommentId);
  337. List<CommentDetailsVo> list = null;
  338. try {
  339. list = namedParameterJdbcTemplate.query(sql, sps,
  340. new BeanPropertyRowMapper<>(CommentDetailsVo.class));
  341. } catch (Exception e) {
  342. e.printStackTrace();
  343. }
  344. if (list != null && list.size() > 0) return list.get(0);
  345. return null;
  346. }
  347. @Override
  348. public int updateCommpentStatus(BookingComment bookingComment) {
  349. StringBuffer stringBuffer = new StringBuffer(" update `booking_comment` set ");
  350. MapSqlParameterSource sps = new MapSqlParameterSource();
  351. if (!Func.checkNull(String.valueOf(bookingComment.getCommentStatus()))) {
  352. stringBuffer.append(" comment_status=:comment_status,");
  353. stringBuffer.append(" modify_date=:modify_date");
  354. sps.addValue("comment_status", bookingComment.getCommentStatus());
  355. sps.addValue("modify_date", UUIDUtil.getNewDate());
  356. }
  357. // 将要修改的数据填充到查询语句中
  358. stringBuffer.append(" where id=:id ");
  359. sps.addValue("id", bookingComment.getId());
  360. int num = 0;
  361. try {
  362. num = namedParameterJdbcTemplate.update(stringBuffer.toString(), sps);
  363. } catch (Exception e) {
  364. e.printStackTrace();
  365. }
  366. return num;
  367. }
  368. @Override
  369. public BookingComment queryById(String id) {
  370. String sql = selectSql + " and a.id = :id";
  371. MapSqlParameterSource sps = new MapSqlParameterSource();
  372. sps.addValue("id",id);
  373. List<BookingComment> list = null;
  374. try {
  375. list = namedParameterJdbcTemplate.query(sql, sps,
  376. new BeanPropertyRowMapper<>(BookingComment.class));
  377. } catch (Exception e) {
  378. e.printStackTrace();
  379. }
  380. if (list != null && list.size() > 0) return list.get(0);
  381. return null;
  382. }
  383. @Override
  384. public int update(BookingComment bookingComment) {
  385. StringBuffer stringBuffer = new StringBuffer(" update `booking_comment` set ");
  386. MapSqlParameterSource sps = new MapSqlParameterSource();
  387. // 将要修改的数据填充到查询语句中
  388. appendValue(bookingComment,stringBuffer,sps);
  389. stringBuffer.append(" where id=:id ");
  390. sps.addValue("id", bookingComment.getId());
  391. int num = 0;
  392. try{
  393. num = namedParameterJdbcTemplate.update(stringBuffer.toString(), sps);
  394. }
  395. catch(Exception e){
  396. e.printStackTrace();
  397. }
  398. return num;
  399. }
  400. @Override
  401. public List<BookingComment> queryPage(String sqlx, int page, int rows) {
  402. SqlUtil.filterKeyword(sqlx);
  403. int start = (page - 1) * rows;// 每页的起始下标
  404. String sql = selectSql + sqlx + " and a.comment_id is null " + " ORDER BY create_date DESC limit :start,:rows ";
  405. MapSqlParameterSource sps = new MapSqlParameterSource();
  406. sps.addValue("start", start);
  407. sps.addValue("rows", rows);
  408. List<BookingComment> list = namedParameterJdbcTemplate.query(sql, sps,
  409. new BeanPropertyRowMapper<>(BookingComment.class));
  410. if (list != null && list.size() > 0) return list;
  411. return null;
  412. }
  413. @Override
  414. public int queryTotal(String sqlx) {
  415. SqlUtil.filterKeyword(sqlx);
  416. String sql = "SELECT count(*) FROM (" + selectSql + " and a.comment_id is null " + ") a where status != 0 " + sqlx;
  417. MapSqlParameterSource sps = new MapSqlParameterSource();
  418. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  419. }
  420. @Override
  421. public List<BookingComment> getByBookId(String bookId) {
  422. String sql = selectSql + " and a.booking_id = :id and a.comment_id is null and status != 0";
  423. MapSqlParameterSource sps = new MapSqlParameterSource();
  424. sps.addValue("id", bookId);
  425. List<BookingComment> list = new ArrayList<>();
  426. try {
  427. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(BookingComment.class));
  428. } catch (Exception e) {
  429. e.printStackTrace();
  430. }
  431. if (list != null && list.size() > 0) return list;
  432. return null;
  433. }
  434. @Override
  435. public List<BookingComment> getByParentId(String parentId) {
  436. String sql = selectSql + " and a.comment_parent_id = :id and a.comment_id = :id and status != 0";
  437. MapSqlParameterSource sps = new MapSqlParameterSource();
  438. sps.addValue("id", parentId);
  439. List<BookingComment> list = new ArrayList<>();
  440. try {
  441. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(BookingComment.class));
  442. } catch (Exception e) {
  443. e.printStackTrace();
  444. }
  445. if (list != null && list.size() > 0) return list;
  446. return null;
  447. }
  448. @Override
  449. public List<BookingComment> getByCommentId(String commentId) {
  450. String sql = selectSql + " and a.comment_id = :id and status != 0";
  451. MapSqlParameterSource sps = new MapSqlParameterSource();
  452. sps.addValue("id", commentId);
  453. List<BookingComment> list = new ArrayList<>();
  454. try {
  455. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(BookingComment.class));
  456. } catch (Exception e) {
  457. e.printStackTrace();
  458. }
  459. if (list != null && list.size() > 0) return list;
  460. return null;
  461. }
  462. /**
  463. * ´ýÆÀ¼Û
  464. *
  465. * @param usersId
  466. * @param page
  467. * @param rows
  468. * @return
  469. */
  470. @Override
  471. public List<PersonageCommentVo> personageNotCommentPage(String usersId, int page, int rows) {
  472. int start = (page - 1) * rows;// ÿҳµÄÆðʼÏÂ
  473. String sql = "SELECT\n" +
  474. "\tb.id AS id,\n" +
  475. "\tbc.id as bookingCommentId ,b.hotel_id as hotelId,b.house_id as houseId,\n" +
  476. "\tb.hotel_name AS hotelName,\n" +
  477. "\tb.house_order_number AS houseOrderNumber,\n" +
  478. "\tb.house_name AS houseName ,\n" +
  479. "\tb.live_time as liveTime,\n" +
  480. "\tb.check_out_time as checkOutTime,\n" +
  481. "\tb.pay_account as payAccount\n" +
  482. "\t,b.create_userid ,fi.url as url\n" +
  483. "FROM\n" +
  484. "\t`booking` b\n" +
  485. "\tLEFT JOIN booking_comment bc on b.id=bc.booking_id AND bc.comment_parent_id IS NULL AND bc.`status`!=0\n" +
  486. "\t\n" +
  487. "\tLEFT JOIN users u on u.id =b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id\n" +
  488. "\t\n" +
  489. "\tWHERE bc.id IS NULL AND u.id= :usersId AND b.order_status=5 AND b.status_del=1 ORDER BY b.order_start_time DESC LIMIT :start,:rows";
  490. MapSqlParameterSource sps = new MapSqlParameterSource();
  491. sps.addValue("start", start);
  492. sps.addValue("rows", rows);
  493. sps.addValue("usersId", usersId);
  494. List<PersonageCommentVo> list = namedParameterJdbcTemplate.query(sql, sps,
  495. new BeanPropertyRowMapper<>(PersonageCommentVo.class));
  496. if (list != null && list.size() > 0) return list;
  497. return null;
  498. }
  499. /**
  500. * ÒÑÆÀ¼Û
  501. *
  502. * @param usersId
  503. * @param page
  504. * @param rows
  505. * @return
  506. */
  507. @Override
  508. public List<PersonageCommentVo> personageCommentPage(String usersId, int page, int rows) {
  509. int start = (page - 1) * rows;// ÿҳµÄÆðʼÏÂ
  510. String sql = "SELECT\n" +
  511. "\tb.id AS id,\n" +
  512. "\tbc.id AS bookingCommentId,\n" +
  513. "\tb.hotel_name AS hotelName,\n" +
  514. "\tb.house_order_number AS houseOrderNumber,\n" +
  515. "\tb.house_name AS houseName,\n" +
  516. "\tb.live_time AS liveTime,\n" +
  517. "\tb.check_out_time AS checkOutTime,\n" +
  518. "\tb.pay_account AS payAccount ,fi.url as url\n" +
  519. "FROM\n" +
  520. "\t`booking` b\n" +
  521. "\tINNER JOIN booking_comment bc ON b.id = bc.booking_id \n" +
  522. "\tAND bc.comment_parent_id IS NULL \n" +
  523. "\tAND bc.`status` = 1\n" +
  524. "\tLEFT JOIN users u ON u.id = b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id \n" +
  525. "WHERE\n" +
  526. "\tu.id = :usersId \n" +
  527. "\tAND b.order_status = 5 \n" +
  528. "\tAND b.status_del =1 ORDER BY b.order_start_time DESC LIMIT :start,:rows";
  529. MapSqlParameterSource sps = new MapSqlParameterSource();
  530. sps.addValue("start", start);
  531. sps.addValue("rows", rows);
  532. sps.addValue("usersId", usersId);
  533. List<PersonageCommentVo> list = namedParameterJdbcTemplate.query(sql, sps,
  534. new BeanPropertyRowMapper<>(PersonageCommentVo.class));
  535. if (list != null && list.size() > 0) return list;
  536. return null;
  537. }
  538. /**
  539. * ´ýÆÀÂÛ´ÎÊý
  540. *
  541. * @param usersId
  542. * @return
  543. */
  544. @Override
  545. public int personageNotCommentTotal (String usersId){
  546. String sql = "SELECT\n" +
  547. "\t count(1) \n" +
  548. "FROM\n" +
  549. "\t`booking` b\n" +
  550. "\tLEFT JOIN booking_comment bc on b.id=bc.booking_id AND bc.comment_parent_id IS NULL AND bc.`status`=1\n" +
  551. "\t\n" +
  552. "\tLEFT JOIN users u on u.id =b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id \n" +
  553. "\t\n" +
  554. "\tWHERE bc.id IS NULL AND u.id= :usersId AND b.order_status=5 AND b.status_del=1 ";
  555. MapSqlParameterSource sps = new MapSqlParameterSource();
  556. sps.addValue("usersId", usersId);
  557. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  558. }
  559. /**
  560. * ÒÑÆÀ¼Û×ÜÊý
  561. *
  562. * @param usersId
  563. * @return
  564. */
  565. @Override
  566. public int personageCommentTotal (String usersId){
  567. String sql = "SELECT\n" +
  568. "\t count(1) \n" +
  569. "FROM\n" +
  570. "\t`booking` b\n" +
  571. "\tINNER JOIN booking_comment bc ON b.id = bc.booking_id \n" +
  572. "\tAND bc.comment_parent_id IS NULL \n" +
  573. "\tAND bc.`status` = 1\n" +
  574. "\tLEFT JOIN users u ON u.id = b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id \n" +
  575. "WHERE\n" +
  576. "\tu.id = :usersId \n" +
  577. "\tAND b.order_status = 5 \n" +
  578. "\tAND b.status_del =1 ";
  579. MapSqlParameterSource sps = new MapSqlParameterSource();
  580. sps.addValue("usersId", usersId);
  581. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  582. }
  583. @Override
  584. public PersonageDetailsVo personageDetails (String bookingCommentId){
  585. String sql = "SELECT\n" +
  586. "\tbc.id AS id,\n" +
  587. "\tbc.create_date as commentTime, \n" +
  588. "\tbc.score AS score,\n" +
  589. "\tbc.content AS content,\n" +
  590. "\tfi2.url AS url,\n" +
  591. "\tb.hotel_name AS hotelName,\n" +
  592. "\tb.house_order_number AS houseOrderNumber,\n" +
  593. "\tb.house_name AS houseName ,\n" +
  594. "\tb.live_time as liveTime,\n" +
  595. "\tb.check_out_time as checkOutTime,\n" +
  596. "\tb.pay_account as payAccount,u.user_name as name,u.head_photo as headPhoto , fi4.url as houseUrl ,b.id as bookingId \n" +
  597. "FROM\n" +
  598. "\t`booking_comment` bc\n" +
  599. "\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" +
  600. "\tLEFT JOIN booking b on b.id=bc.booking_id LEFT JOIN users u on u.id=bc.create_id LEFT JOIN ( SELECT fi3.link_id, GROUP_CONCAT( fi3.url ) AS url FROM file_info fi3 GROUP BY fi3.link_id ) fi4 ON fi4.link_id = b.house_id \n" +
  601. "\tWHERE bc.comment_parent_id is NULL AND bc.`status`=1 and bc.id= :bookingCommentId";
  602. MapSqlParameterSource sps = new MapSqlParameterSource();
  603. sps.addValue("bookingCommentId", bookingCommentId);
  604. List<PersonageDetailsVo> list = null;
  605. try {
  606. list = namedParameterJdbcTemplate.query(sql, sps,
  607. new BeanPropertyRowMapper<>(PersonageDetailsVo.class));
  608. } catch (Exception e) {
  609. e.printStackTrace();
  610. }
  611. if (list != null && list.size() > 0) return list.get(0);
  612. return null;
  613. }
  614. @Override
  615. public BookingComment getBycommentId(String commentId) {
  616. String sql="SELECT * FROM `booking_comment` WHERE id= :commentId";
  617. MapSqlParameterSource sps = new MapSqlParameterSource();
  618. sps.addValue("commentId", commentId);
  619. List<BookingComment> list = null;
  620. try {
  621. list = namedParameterJdbcTemplate.query(sql, sps,
  622. new BeanPropertyRowMapper<>(BookingComment.class));
  623. } catch (Exception e) {
  624. e.printStackTrace();
  625. }
  626. if (list != null && list.size() > 0) return list.get(0);
  627. return null;
  628. }
  629. @Override
  630. public List<PersonageCommentVo> auditPageComment(String usersId, int page, int rows) {
  631. int start = (page - 1) * rows;// ÿҳµÄÆðʼÏÂ
  632. String sql = "SELECT\n" +
  633. "\tb.id AS id,\n" +
  634. "\tbc.id AS bookingCommentId,\n" +
  635. "\tb.hotel_name AS hotelName,\n" +
  636. "\tb.house_order_number AS houseOrderNumber,\n" +
  637. "\tb.house_name AS houseName,\n" +
  638. "\tb.live_time AS liveTime,\n" +
  639. "\tb.check_out_time AS checkOutTime,\n" +
  640. "\tb.pay_account AS payAccount ,fi.url as url\n" +
  641. "FROM\n" +
  642. "\t`booking` b\n" +
  643. "\tINNER JOIN booking_comment bc ON b.id = bc.booking_id \n" +
  644. "\tAND bc.comment_parent_id IS NULL \n" +
  645. "\tAND bc.`status` = 2\n" +
  646. "\tLEFT JOIN users u ON u.id = b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id \n" +
  647. "WHERE\n" +
  648. "\tu.id = :usersId \n" +
  649. "\tAND b.order_status = 5 \n" +
  650. "\tAND b.status_del =1 ORDER BY b.order_start_time DESC LIMIT :start,:rows";
  651. MapSqlParameterSource sps = new MapSqlParameterSource();
  652. sps.addValue("start", start);
  653. sps.addValue("rows", rows);
  654. sps.addValue("usersId", usersId);
  655. List<PersonageCommentVo> list = namedParameterJdbcTemplate.query(sql, sps,
  656. new BeanPropertyRowMapper<>(PersonageCommentVo.class));
  657. if (list != null && list.size() > 0) return list;
  658. return null;
  659. }
  660. @Override
  661. public int auditTotalComment(String usersId) {
  662. String sql = "SELECT\n" +
  663. "\t count(1) \n" +
  664. "FROM\n" +
  665. "\t`booking` b\n" +
  666. "\tINNER JOIN booking_comment bc ON b.id = bc.booking_id \n" +
  667. "\tAND bc.comment_parent_id IS NULL \n" +
  668. "\tAND bc.`status` = 2\n" +
  669. "\tLEFT JOIN users u ON u.id = b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id \n" +
  670. "WHERE\n" +
  671. "\tu.id = :usersId \n" +
  672. "\tAND b.order_status = 5 \n" +
  673. "\tAND b.status_del =1 ";
  674. MapSqlParameterSource sps = new MapSqlParameterSource();
  675. sps.addValue("usersId", usersId);
  676. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  677. }
  678. @Override
  679. public List<PersonageCommentVo> refuseAuditPageComment(String usersId, int page, int rows) {
  680. int start = (page - 1) * rows;// ÿҳµÄÆðʼÏÂ
  681. String sql = "SELECT\n" +
  682. "\tb.id AS id,\n" +
  683. "\tbc.id AS bookingCommentId,\n" +
  684. "\tb.hotel_name AS hotelName,\n" +
  685. "\tb.house_order_number AS houseOrderNumber,\n" +
  686. "\tb.house_name AS houseName,\n" +
  687. "\tb.live_time AS liveTime,\n" +
  688. "\tb.check_out_time AS checkOutTime,\n" +
  689. "\tb.pay_account AS payAccount ,fi.url as url,w.workflow_remark as remark\n" +
  690. "FROM\n" +
  691. "\t`booking` b\n" +
  692. "\tINNER JOIN booking_comment bc ON b.id = bc.booking_id \n" +
  693. "\tAND bc.comment_parent_id IS NULL \n" +
  694. "\tAND bc.`status` = 3\n" +
  695. "\tLEFT JOIN users u ON u.id = b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id LEFT JOIN workflow w ON bc.id=w.link_id \n" +
  696. "WHERE\n" +
  697. "\tu.id = :usersId \n" +
  698. "\tAND b.order_status = 5 \n" +
  699. "\tAND b.status_del =1 ORDER BY b.order_start_time DESC LIMIT :start,:rows";
  700. MapSqlParameterSource sps = new MapSqlParameterSource();
  701. sps.addValue("start", start);
  702. sps.addValue("rows", rows);
  703. sps.addValue("usersId", usersId);
  704. List<PersonageCommentVo> list = namedParameterJdbcTemplate.query(sql, sps,
  705. new BeanPropertyRowMapper<>(PersonageCommentVo.class));
  706. if (list != null && list.size() > 0) return list;
  707. return null;
  708. }
  709. @Override
  710. public int refuseAuditTotalComment(String usersId) {
  711. String sql = "SELECT\n" +
  712. "\t count(1) \n" +
  713. "FROM\n" +
  714. "\t`booking` b\n" +
  715. "\tINNER JOIN booking_comment bc ON b.id = bc.booking_id \n" +
  716. "\tAND bc.comment_parent_id IS NULL \n" +
  717. "\tAND bc.`status` = 3\n" +
  718. "\tLEFT JOIN users u ON u.id = b.create_userid LEFT JOIN file_info fi on fi.link_id=b.house_id LEFT JOIN workflow w ON bc.id=w.link_id \n" +
  719. "WHERE\n" +
  720. "\tu.id = :usersId \n" +
  721. "\tAND b.order_status = 5 \n" +
  722. "\tAND b.status_del =1 ";
  723. MapSqlParameterSource sps = new MapSqlParameterSource();
  724. sps.addValue("usersId", usersId);
  725. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  726. }
  727. public void appendValue(BookingComment bookingComment, StringBuffer stringBuffer, MapSqlParameterSource sps){
  728. if (!Func.checkNull(bookingComment.getCommentId())){
  729. stringBuffer.append(" comment_id=:comment_id ,");
  730. sps.addValue("comment_id",bookingComment.getCommentId());
  731. }
  732. if (!Func.checkNull(bookingComment.getCommentParentId())){
  733. stringBuffer.append(" comment_parent_id=:comment_parent_id ,");
  734. sps.addValue("comment_parent_id",bookingComment.getCommentParentId());
  735. }
  736. if (!Func.checkNull(bookingComment.getCommentName())){
  737. stringBuffer.append(" comment_name=:comment_name ,");
  738. sps.addValue("comment_name",bookingComment.getCommentName());
  739. }
  740. if (!Func.checkNull(bookingComment.getHotelId())){
  741. stringBuffer.append(" hotel_id=:hotel_id ,");
  742. sps.addValue("hotel_id",bookingComment.getHotelId());
  743. }
  744. if (!Func.checkNull(bookingComment.getBookingId())){
  745. stringBuffer.append(" booking_id=:booking_id ,");
  746. sps.addValue("booking_id",bookingComment.getBookingId());
  747. }
  748. if (!Func.checkNull(bookingComment.getHouseId())){
  749. stringBuffer.append(" house_id=:house_id ,");
  750. sps.addValue("house_id",bookingComment.getHouseId());
  751. }
  752. if (!Func.checkNull(bookingComment.getContent())){
  753. stringBuffer.append(" content=:content ,");
  754. sps.addValue("content",bookingComment.getContent());
  755. }
  756. if (!Func.checkNull(bookingComment.getCommentStatus())){
  757. stringBuffer.append(" comment_status=:comment_status ,");
  758. sps.addValue("comment_status",bookingComment.getCommentStatus());
  759. }
  760. if (!Func.checkNull(String.valueOf(bookingComment.getScore()))){
  761. stringBuffer.append(" score=:score ,");
  762. sps.addValue("score",bookingComment.getScore());
  763. }
  764. if (!Func.checkNull(String.valueOf(bookingComment.getScoreWs()))){
  765. stringBuffer.append(" score_ws=:score_ws ,");
  766. sps.addValue("score_ws",bookingComment.getScoreWs());
  767. }
  768. if (!Func.checkNull(String.valueOf(bookingComment.getScoreFw()))){
  769. stringBuffer.append(" score_fw=:score_fw ,");
  770. sps.addValue("score_fw",bookingComment.getScoreFw());
  771. }
  772. if (!Func.checkNull(String.valueOf(bookingComment.getScoreSs()))){
  773. stringBuffer.append(" score_ss=:score_ss ,");
  774. sps.addValue("score_ss",bookingComment.getScoreSs());
  775. }
  776. if (!Func.checkNull(String.valueOf(bookingComment.getScoreWz()))){
  777. stringBuffer.append(" score_wz=:score_wz ,");
  778. sps.addValue("score_wz",bookingComment.getScoreWz());
  779. }
  780. if (!Func.checkNull(String.valueOf(bookingComment.getCreateId()))){
  781. stringBuffer.append(" create_id=:create_id ,");
  782. sps.addValue("create_id",bookingComment.getCreateId());
  783. }
  784. if (!Func.checkNull(bookingComment.getCreateUsername())){
  785. stringBuffer.append(" create_username=:create_username ,");
  786. sps.addValue("create_username",bookingComment.getCreateUsername());
  787. }
  788. if (!Func.checkNull(bookingComment.getCreateDate())){
  789. stringBuffer.append(" create_date=:create_date ,");
  790. sps.addValue("create_date",bookingComment.getCreateDate());
  791. }
  792. if (!Func.checkNull(bookingComment.getStatus())){
  793. stringBuffer.append(" status=:status ,");
  794. sps.addValue("status",bookingComment.getStatus());
  795. }
  796. stringBuffer.append(" modify_date=:modify_date ");
  797. sps.addValue("modify_date", UUIDUtil.getNewDate());
  798. }
  799. }