HotelDictImplDao.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.happy.dao.impl;
  2. import com.happy.Model.HotelDict;
  3. import com.happy.Until.UUIDUtil;
  4. import com.happy.dao.HotelDictDao;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  7. import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  8. import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  9. import org.springframework.stereotype.Repository;
  10. import java.util.List;
  11. @Repository("HotelDictDao")
  12. public class HotelDictImplDao implements HotelDictDao {
  13. @Autowired
  14. private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
  15. public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
  16. return namedParameterJdbcTemplate;
  17. }
  18. public void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
  19. this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
  20. }
  21. @Override
  22. public int insertHotelDict(HotelDict hotelDict) {
  23. String sql = "INSERT INTO hotel_dict (id, name, file_url, create_id, create_date, modify_date, status) VALUES (:id, :name, :file_url, :create_id, :create_date, :modify_date, :status);\n";
  24. MapSqlParameterSource sps = new MapSqlParameterSource();
  25. sps.addValue("name",hotelDict.getName());
  26. sps.addValue("file_url",hotelDict.getFileUrl());
  27. sps.addValue("create_id",hotelDict.getCreateId());
  28. sps.addValue("create_date",hotelDict.getCreateDate());
  29. sps.addValue("modify_date",hotelDict.getModifyDate());
  30. sps.addValue("status",hotelDict.getStatus());
  31. if(hotelDict.getId()==null){
  32. sps.addValue("id", UUIDUtil.generateID());
  33. }
  34. int num = 0;
  35. try{
  36. num = namedParameterJdbcTemplate.update(sql, sps);
  37. }
  38. catch(Exception e){
  39. e.printStackTrace();
  40. }
  41. return num;
  42. }
  43. @Override
  44. public int updateHotelDict(HotelDict hotelDict) {
  45. String sql = "UPDATE hotel_dict SET name=:name, file_url=:file_url, create_id=:create_id, modify_date=:modify_date, status=:status WHERE id = :id";
  46. MapSqlParameterSource sps = new MapSqlParameterSource();
  47. sps.addValue("name",hotelDict.getName());
  48. sps.addValue("file_url",hotelDict.getFileUrl());
  49. sps.addValue("create_id",hotelDict.getCreateId());
  50. sps.addValue("modify_date",hotelDict.getModifyDate());
  51. sps.addValue("status",hotelDict.getStatus());
  52. sps.addValue("id", hotelDict.getId());
  53. int num = 0;
  54. try{
  55. num = namedParameterJdbcTemplate.update(sql, sps);
  56. }
  57. catch(Exception e){
  58. e.printStackTrace();
  59. }
  60. return num;
  61. }
  62. @Override
  63. public int delHotelDict(int id) {
  64. String sql = "DELETE FROM `hotel_dict` WHERE id = :id ";
  65. MapSqlParameterSource sps = new MapSqlParameterSource();
  66. sps.addValue("id",id);
  67. int num = 0;
  68. try{
  69. num = namedParameterJdbcTemplate.update(sql, sps);
  70. }catch (Exception e){
  71. e.printStackTrace();
  72. }
  73. return num;
  74. }
  75. @Override
  76. public HotelDict getById(int id) {
  77. String sql = "SELECT * FROM `hotel_dict` WHERE id = :id ";
  78. MapSqlParameterSource sps = new MapSqlParameterSource();
  79. sps.addValue("id",id);
  80. List<HotelDict> list = null;
  81. try{
  82. list = namedParameterJdbcTemplate.query(sql, sps,
  83. new BeanPropertyRowMapper<>(HotelDict.class));
  84. }catch (Exception e){
  85. e.printStackTrace();
  86. }
  87. if(list != null && list.size()>0) return list.get(0);
  88. return null;
  89. }
  90. @Override
  91. public List<HotelDict> queryPage(String sqlx, int page, int rows) {
  92. int start = (page - 1) * rows;// 每页的起始下标
  93. String sql = "SELECT * FROM `hotel_dict` WHERE 1=1 "+sqlx+" ORDER BY id DESC limit :start,:rows ";
  94. MapSqlParameterSource sps = new MapSqlParameterSource();
  95. sps.addValue("start", start);
  96. sps.addValue("rows", rows);
  97. List<HotelDict> list = namedParameterJdbcTemplate.query(sql, sps,
  98. new BeanPropertyRowMapper<>(HotelDict.class));
  99. if (list != null && list.size() > 0) return list;
  100. return null;
  101. }
  102. @Override
  103. public int queryTotal(String sqlx) {
  104. String sql = "SELECT count(*) FROM`hotel_dict` where 1=1 "+sqlx;
  105. MapSqlParameterSource sps = new MapSqlParameterSource();
  106. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  107. }
  108. @Override
  109. public List<HotelDict> queryList(String sqlx) {
  110. String sql = "SELECT * FROM `hotel_dict` WHERE 1=1 "+sqlx;
  111. List<HotelDict> list = null;
  112. try{
  113. list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(HotelDict.class));
  114. }catch (Exception e){
  115. e.printStackTrace();
  116. }
  117. if(list != null && list.size()>0) return list;
  118. return null;
  119. }
  120. }