SecondBufferPImplDao.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.happy.dao.Impl;
  2. import com.happy.Model.SecondBufferP;
  3. import com.happy.Model.User;
  4. import com.happy.dao.SecondBufferPDao;
  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.ArrayList;
  11. import java.util.List;
  12. @Repository("SecondBufferPDao")
  13. public class SecondBufferPImplDao implements SecondBufferPDao {
  14. @Autowired
  15. private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
  16. public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
  17. return namedParameterJdbcTemplate;
  18. }
  19. public void setNamedParameterJdbcTemplate(
  20. NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
  21. this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
  22. }
  23. public int insertSecondBufferP(SecondBufferP secondBufferP){
  24. String sql = "insert into `secondbufferp`(dateT,`dateTime`,place,red_count,yellow_count,green_count,url) values(:dateT,:dateTime,:place,:red_count,:yellow_count,:green_count,:url)";
  25. MapSqlParameterSource sps = new MapSqlParameterSource();
  26. sps.addValue("dateT", secondBufferP.getDateT());
  27. sps.addValue("dateTime", secondBufferP.getDateTime());
  28. sps.addValue("place", secondBufferP.getPlace());
  29. sps.addValue("red_count", secondBufferP.getRed_count());
  30. sps.addValue("yellow_count", secondBufferP.getYellow_count());
  31. sps.addValue("green_count", secondBufferP.getGreen_count());
  32. sps.addValue("url", secondBufferP.getUrl());
  33. System.out.println(secondBufferP.getRed_count());
  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. // 各景点扫码详情
  44. public List<SecondBufferP> querySecondBufferP(){
  45. String sql = "select * from `secondbufferp` where id in(select MAX(id) from `secondbufferp` group by place) ";
  46. MapSqlParameterSource sps = new MapSqlParameterSource();
  47. List<SecondBufferP> list = namedParameterJdbcTemplate.query(sql, sps,
  48. new BeanPropertyRowMapper<SecondBufferP>(SecondBufferP.class));
  49. if (list != null && list.size() > 0) {
  50. return list;
  51. }
  52. return null;
  53. }
  54. // 各景点扫码详情
  55. public List<SecondBufferP> querySecondBufferpByPlace(String place){
  56. String sql = "select * from `secondbufferp` where place=:place and id=(select max(id) from `secondbufferp` where place=:place) ";
  57. MapSqlParameterSource sps = new MapSqlParameterSource();
  58. sps.addValue("place",place);
  59. List<SecondBufferP> list = namedParameterJdbcTemplate.query(sql, sps,
  60. new BeanPropertyRowMapper<SecondBufferP>(SecondBufferP.class));
  61. List<SecondBufferP> list2 = new ArrayList<>();
  62. if (list != null && list.size() > 0) {
  63. return list;
  64. } else {
  65. SecondBufferP sp = new SecondBufferP();
  66. sp.setGreen_count("0");
  67. sp.setRed_count("0");
  68. sp.setYellow_count("0");
  69. list2.add(sp);
  70. return list2;
  71. }
  72. }
  73. // 各景点人员扫码信息
  74. public List<User> queryByPlace(String sm_place){
  75. String sql = "select * from `sm_message` where protect_type='2' and sm_place=:sm_place order by `id` desc limit 0,20 ";
  76. MapSqlParameterSource sps = new MapSqlParameterSource();
  77. sps.addValue("sm_place", sm_place);
  78. List<User> list = namedParameterJdbcTemplate.query(sql, sps,
  79. new BeanPropertyRowMapper<User>(User.class));
  80. if (list != null && list.size() > 0) {
  81. return list;
  82. }
  83. return null;
  84. }
  85. }