SecondBuffertImplDao.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. package com.happy.dao.Impl;
  2. import com.happy.Model.*;
  3. import com.happy.Model.Common.Common;
  4. import com.happy.Model.Tour.TravelSecond;
  5. import com.happy.Until.TimeExchange;
  6. import com.happy.dao.SecondBuffertDao;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  9. import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  10. import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  11. import org.springframework.stereotype.Repository;
  12. import java.util.List;
  13. @Repository("SecondBuffertDao")
  14. public class SecondBuffertImplDao implements SecondBuffertDao {
  15. @Autowired
  16. private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
  17. public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
  18. return namedParameterJdbcTemplate;
  19. }
  20. public void setNamedParameterJdbcTemplate(
  21. NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
  22. this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
  23. }
  24. public int insertSecondBufferT(SecondBufferT secondBufferT){
  25. String sql = "insert into secondbuffert(dateT,smT,smT_increase,smLt,red_count,red_increase,yellow_count,yellow_increase,green_count,green_increase) values(:dateT,:smT,:smT_increase,:smLt,:red_count,:red_increase,:yellow_count,:yellow_increase,:green_count,:green_increase)";
  26. MapSqlParameterSource sps = new MapSqlParameterSource();
  27. sps.addValue("dateT", secondBufferT.getDateT());
  28. sps.addValue("smT", secondBufferT.getSmT());
  29. sps.addValue("smT_increase", secondBufferT.getSmT_increase());
  30. sps.addValue("smLt", secondBufferT.getSmLt());
  31. sps.addValue("red_count", secondBufferT.getRed_count());
  32. sps.addValue("red_increase", secondBufferT.getRed_increase());
  33. sps.addValue("yellow_count", secondBufferT.getYellow_count());
  34. sps.addValue("yellow_increase", secondBufferT.getYellow_increase());
  35. sps.addValue("green_count", secondBufferT.getGreen_count());
  36. sps.addValue("green_increase", secondBufferT.getGreen_increase());
  37. int num = 0;
  38. try{
  39. num = namedParameterJdbcTemplate.update(sql, sps);
  40. }
  41. catch(Exception e){
  42. e.printStackTrace();
  43. }
  44. return num;
  45. }
  46. // 人数统计
  47. public int insertSecondBufferC(SecondBufferC secondBufferC){
  48. String sql = "insert into secondbufferc(dateT,dateTime,smT,smT_increase,smLt,red_count,red_increase,yellow_count,yellow_increase,green_count,green_increase) values(:dateT,:dateTime,:smT,:smT_increase,:smLt,:red_count,:red_increase,:yellow_count,:yellow_increase,:green_count,:green_increase)";
  49. MapSqlParameterSource sps = new MapSqlParameterSource();
  50. sps.addValue("dateT", secondBufferC.getDateT());
  51. sps.addValue("dateTime", secondBufferC.getDateTime());
  52. sps.addValue("smT", secondBufferC.getSmT());
  53. sps.addValue("smT_increase", secondBufferC.getSmT_increase());
  54. sps.addValue("smLt", secondBufferC.getSmLt());
  55. sps.addValue("red_count", secondBufferC.getRed_count());
  56. sps.addValue("red_increase", secondBufferC.getRed_increase());
  57. sps.addValue("yellow_count", secondBufferC.getYellow_count());
  58. sps.addValue("yellow_increase", secondBufferC.getYellow_increase());
  59. sps.addValue("green_count", secondBufferC.getGreen_count());
  60. sps.addValue("green_increase", secondBufferC.getGreen_increase());
  61. int num = 0;
  62. try{
  63. num = namedParameterJdbcTemplate.update(sql, sps);
  64. }
  65. catch(Exception e){
  66. e.printStackTrace();
  67. }
  68. return num;
  69. }
  70. // 第二道防线扫描汇总
  71. public List<SecondBufferT> querySecondBufferT(){
  72. String sql = "select * from secondbuffert where id in(select MAX(id) from secondbuffert) ";
  73. MapSqlParameterSource sps = new MapSqlParameterSource();
  74. List<SecondBufferT> list = namedParameterJdbcTemplate.query(sql, sps,
  75. new BeanPropertyRowMapper<SecondBufferT>(SecondBufferT.class));
  76. if (list != null && list.size() > 0) {
  77. return list;
  78. }
  79. return null;
  80. }
  81. // 第二道防线景点当日绿码人数统计
  82. public List<SecondBufferT> querySpjdGreen(String sm_date){
  83. String sql = "select IFNULL(SUM(IF(sm_color='绿码',1,0)),0) as green_count from(select * from `sm_message` where sm_date=:sm_date and sm_color='绿码' and sm_place in (select place_name from `secondplace`) group by UUID ) a ";
  84. MapSqlParameterSource sps = new MapSqlParameterSource();
  85. sps.addValue("sm_date", sm_date);
  86. List<SecondBufferT> list = namedParameterJdbcTemplate.query(sql, sps,
  87. new BeanPropertyRowMapper<>(SecondBufferT.class));
  88. if (list != null && list.size() > 0) {
  89. return list;
  90. }
  91. return null;
  92. }
  93. // 第二道防线扫描汇总------红黄码发热汇总
  94. public List<SecondBufferT> querySecondBufferRy(){
  95. String sql = "select IFNULL(SUM(IF(sm_color='红码',1,0)),0) as red_count, IFNULL(SUM(IF(sm_color='黄码',1,0)),0) as yellow_count,IFNULL(SUM(IF(ishot='1',1,0)),0) as hot_count from `sm_message_x` where protect_type='2' and (sm_color in ('红码', '黄码') or ishot='1') and sm_date=:sm_date ";
  96. MapSqlParameterSource sps = new MapSqlParameterSource();
  97. sps.addValue("sm_date", TimeExchange.getDate());
  98. List<SecondBufferT> list = namedParameterJdbcTemplate.query(sql, sps,
  99. new BeanPropertyRowMapper<SecondBufferT>(SecondBufferT.class));
  100. if (list != null && list.size() > 0) {
  101. return list;
  102. }
  103. return null;
  104. }
  105. // 第二道防线扫描汇总------红黄码发热汇总
  106. public List<SecondBufferT> querySbRyByDate(String sm_date){
  107. String sql = "select IFNULL(SUM(IF(sm_color='红码',1,0)),0) as red_count, IFNULL(SUM(IF(sm_color='黄码',1,0)),0) as yellow_count,IFNULL(SUM(IF(ishot='1',1,0)),0) as hot_count from `sm_message_x` where protect_type='2' and (sm_color in ('红码', '黄码') or ishot='1') and sm_date=:sm_date ";
  108. MapSqlParameterSource sps = new MapSqlParameterSource();
  109. sps.addValue("sm_date", sm_date);
  110. List<SecondBufferT> list = namedParameterJdbcTemplate.query(sql, sps,
  111. new BeanPropertyRowMapper<SecondBufferT>(SecondBufferT.class));
  112. if (list != null && list.size() > 0) {
  113. return list;
  114. }
  115. return null;
  116. }
  117. // 最近7天人员分布
  118. public List<SecondBufferT> querySecondBufferTLastSeven(){
  119. String sql = "select * from `secondbuffert` where id in(select id from(select dateT,MAX(id) as id from secondbuffert group by dateT order by dateT desc limit 0, 7) a) ";
  120. MapSqlParameterSource sps = new MapSqlParameterSource();
  121. List<SecondBufferT> list = namedParameterJdbcTemplate.query(sql, sps,
  122. new BeanPropertyRowMapper<SecondBufferT>(SecondBufferT.class));
  123. if (list != null && list.size() > 0) {
  124. return list;
  125. }
  126. return null;
  127. }
  128. // 第二道防线扫码人数汇总
  129. public List<SecondBufferC> querySecondBufferC(){
  130. String sql = "select * from `secondbufferc` where id in(select MAX(id) from `secondbufferc`) ";
  131. MapSqlParameterSource sps = new MapSqlParameterSource();
  132. List<SecondBufferC> list = namedParameterJdbcTemplate.query(sql, sps,
  133. new BeanPropertyRowMapper<SecondBufferC>(SecondBufferC.class));
  134. if (list != null && list.size() > 0) {
  135. return list;
  136. }
  137. return null;
  138. }
  139. // 第二道防线处理情况
  140. public List<Handlde> queryHandler(){
  141. String sql = "select IFNULL(SUM(IF(handler_state2=0,1,0)),0) as unhandled, IFNULL(SUM(IF(handler_state2=1,1,0)),0) as handled from `sm_message_x` where protect_type='2' and (sm_color in('红码','黄码') or ishot='1') and sm_date=:sm_date ";
  142. MapSqlParameterSource sps = new MapSqlParameterSource();
  143. sps.addValue("sm_date", TimeExchange.getDate());
  144. System.out.println(TimeExchange.getDate());
  145. List<Handlde> list = namedParameterJdbcTemplate.query(sql, sps,
  146. new BeanPropertyRowMapper<Handlde>(Handlde.class));
  147. if (list != null && list.size() > 0) {
  148. return list;
  149. }
  150. return null;
  151. }
  152. // 第二道防线发热人员
  153. public int queryHot(){
  154. String sql = "select count(*) from `sm_message_x` where ishot='1' and protect_type='2' and sm_date=:sm_date ";
  155. MapSqlParameterSource sps = new MapSqlParameterSource();
  156. sps.addValue("sm_date", TimeExchange.getDate());
  157. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  158. }
  159. // 第二道防线红码人员详情
  160. public List<User> queryRed(String startDate, String endDate){
  161. String sql = "select * from `sm_message_x` where protect_type='2' and sm_color='红码' and sm_date between :startDate and :endDate order by sm_time desc ";
  162. MapSqlParameterSource sps = new MapSqlParameterSource();
  163. sps.addValue("startDate", startDate);
  164. sps.addValue("endDate", endDate);
  165. List<User> list = namedParameterJdbcTemplate.query(sql, sps,
  166. new BeanPropertyRowMapper<User>(User.class));
  167. if (list != null && list.size() > 0) {
  168. return list;
  169. }
  170. return null;
  171. }
  172. // 第二道防线黄码人员详情
  173. public List<User> queryYellow(String startDate,String endDate,int page, int rows){
  174. int start = (page - 1) * rows;// 每页的起始下标
  175. String sql = "select * from `sm_message_x` where protect_type='2' and sm_color='黄码' and sm_date between :startDate and :endDate order by sm_time desc limit :start,:rows ";
  176. MapSqlParameterSource sps = new MapSqlParameterSource();
  177. sps.addValue("startDate", startDate);
  178. sps.addValue("endDate", endDate);
  179. sps.addValue("start", start);
  180. sps.addValue("rows", rows);
  181. List<User> list = namedParameterJdbcTemplate.query(sql, sps,
  182. new BeanPropertyRowMapper<User>(User.class));
  183. if (list != null && list.size() > 0) {
  184. return list;
  185. }
  186. return null;
  187. }
  188. // 第一道防线黄码人员总数-分页
  189. public int queryYellowTotal(String startDate,String endDate){
  190. String sql = "select count(*) from `sm_message_x` where protect_type='2' and sm_color='黄码' and sm_date between :startDate and :endDate ";
  191. MapSqlParameterSource sps = new MapSqlParameterSource();
  192. sps.addValue("startDate", startDate);
  193. sps.addValue("endDate", endDate);
  194. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  195. }
  196. // 第二道防线地址类型
  197. public List<Secondplacetype> queryPt(){
  198. String sql = "select * from `secondplacetype` ";
  199. MapSqlParameterSource sps = new MapSqlParameterSource();
  200. List<Secondplacetype> list = namedParameterJdbcTemplate.query(sql, sps,
  201. new BeanPropertyRowMapper<Secondplacetype>(Secondplacetype.class));
  202. if (list != null && list.size() > 0) {
  203. return list;
  204. }
  205. return null;
  206. }
  207. // 第二道防线景点名称
  208. public List<Secondplace> queryJd(){
  209. String sql = "select * from `secondplace` ";
  210. MapSqlParameterSource sps = new MapSqlParameterSource();
  211. List<Secondplace> list = namedParameterJdbcTemplate.query(sql, sps,
  212. new BeanPropertyRowMapper<Secondplace>(Secondplace.class));
  213. if (list != null && list.size() > 0) {
  214. return list;
  215. }
  216. return null;
  217. }
  218. // 第二道防线景点名称
  219. public List<Secondplace> queryJdByname(String place_name){
  220. String sql = "select * from `secondplace` where place_name like :place_name ";
  221. MapSqlParameterSource sps = new MapSqlParameterSource();
  222. sps.addValue("place_name", "%"+place_name+"%");
  223. List<Secondplace> list = namedParameterJdbcTemplate.query(sql, sps,
  224. new BeanPropertyRowMapper<Secondplace>(Secondplace.class));
  225. if (list != null && list.size() > 0) {
  226. return list;
  227. }
  228. return null;
  229. }
  230. //插入TravelSecond
  231. public int insertTravelSecond(TravelSecond travelSecond,String dayId){
  232. String sql = "SELECT * from travel_second where place_name = :place_name and day_id= :dayId limit 1";
  233. MapSqlParameterSource sps = new MapSqlParameterSource();
  234. sps.addValue("place_name", travelSecond.getPlaceName());
  235. sps.addValue("place_id", travelSecond.getPlaceId());
  236. sps.addValue("dayNum", travelSecond.getDayNum());
  237. sps.addValue("totalNum", travelSecond.getTotalNum());
  238. sps.addValue("maxValue", travelSecond.getMaxValue());
  239. sps.addValue("dayId", dayId);
  240. List<TravelSecond> travelSecondList= namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(TravelSecond.class));
  241. if(travelSecondList==null||travelSecondList.size()<1){
  242. sql = "INSERT INTO `travel_second`(`place_name`, `dayNum`, `totalNum`, `maxValue`,day_id,place_id) VALUES (:place_name,:dayNum, :totalNum, :maxValue,:dayId,:place_id)";
  243. }else {
  244. sps.addValue("id", travelSecondList.get(0).getId());
  245. sql = "update travel_second set dayNum = :dayNum, totalNum = :totalNum,`maxValue` = :maxValue where id = :id";
  246. }
  247. int num = 0;
  248. try{
  249. num = namedParameterJdbcTemplate.update(sql, sps);
  250. }
  251. catch(Exception e){
  252. e.printStackTrace();
  253. }
  254. return num;
  255. }
  256. public TravelSecond queryTravelSecond(String place_name){
  257. String sql = "SELECT * from travel_second where place_name = :place_name and day_id= :dayId limit 1";
  258. MapSqlParameterSource sps = new MapSqlParameterSource();
  259. sps.addValue("place_name", place_name);
  260. sps.addValue("dayId", TimeExchange.getDate());
  261. List<TravelSecond> travelSecondList= namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(TravelSecond.class));
  262. if(travelSecondList!=null&&travelSecondList.size()>0){
  263. return travelSecondList.get(0);
  264. }
  265. return null;
  266. }
  267. // 第二道防线各场所详情
  268. public SecondPlaceJc querySpjc(String place_type){
  269. String sql = "select IFNULL(SUM(IF(sm_color='红码',1,0)),0) as red_count,IFNULL(SUM(IF(sm_color='黄码',1,0)),0) as yellow_count,IFNULL(SUM(IF(ishot='1',1,0)),0) as hot_count,IFNULL(SUM(IF(iskey='1',1,0)),0) as key_count from `sm_message_x` where place_type=:place_type and sm_date=:sm_date ";
  270. MapSqlParameterSource sps = new MapSqlParameterSource();
  271. sps.addValue("place_type", place_type);
  272. sps.addValue("sm_date", TimeExchange.getDate());
  273. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  274. }
  275. // 第二道防线亮码详情
  276. public SecondPlaceJc querySl(){
  277. String sql = "select IFNULL(SUM(IF(sm_color='红码',1,0)),0) as red_count,IFNULL(SUM(IF(sm_color='黄码',1,0)),0) as yellow_count,IFNULL(SUM(IF(ishot='1',1,0)),0) as hot_count,IFNULL(SUM(IF(iskey='1',1,0)),0) as key_count from `sm_message_x` where sm_type='亮码' and sm_date=:sm_date ";
  278. MapSqlParameterSource sps = new MapSqlParameterSource();
  279. sps.addValue("sm_date", TimeExchange.getDate());
  280. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  281. }
  282. // 第二道防线亮码绿码详情
  283. public SecondPlaceJc querySlGreen(){
  284. String sql = "select IFNULL(COUNT(distinct UUID,sm_date,protect_type),0) as green_count from `sm_message` where sm_color='绿码' and sm_type='亮码' and sm_date=:sm_date ";
  285. MapSqlParameterSource sps = new MapSqlParameterSource();
  286. sps.addValue("sm_date", TimeExchange.getDate());
  287. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  288. }
  289. // 第二道防线各景点详情
  290. public SecondPlaceJc querySpjd(){
  291. String sql = "select IFNULL(SUM(IF(sm_color='红码',1,0)),0) as red_count,IFNULL(SUM(IF(sm_color='黄码',1,0)),0) as yellow_count,IFNULL(SUM(IF(ishot='1',1,0)),0) as hot_count,IFNULL(SUM(IF(iskey='1',1,0)),0) as key_count from `sm_message_x` where sm_place in (select place_name from `secondplace`) and sm_date=:sm_date ";
  292. MapSqlParameterSource sps = new MapSqlParameterSource();
  293. sps.addValue("sm_date", TimeExchange.getDate());
  294. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  295. }
  296. // 各酒店医院详细名称
  297. public List<Common> queryCommon(String place_type){
  298. String sql = "select distinct hotel as common from `sm_message` where sm_date=:sm_date and place_type=:place_type ";
  299. MapSqlParameterSource sps = new MapSqlParameterSource();
  300. sps.addValue("sm_date", TimeExchange.getDate());
  301. sps.addValue("place_type", place_type);
  302. List<Common> list = namedParameterJdbcTemplate.query(sql, sps,
  303. new BeanPropertyRowMapper<>(Common.class));
  304. if (list != null && list.size() > 0) {
  305. return list;
  306. }
  307. return null;
  308. }
  309. // 根据详细名称查红黄码详情
  310. public SecondPlaceJc queryByCommon(String place_type,String hotel){
  311. String sql = "select IFNULL(SUM(IF(sm_color='红码',1,0)),0) as red_count,IFNULL(SUM(IF(sm_color='黄码',1,0)),0) as yellow_count,IFNULL(SUM(IF(ishot='1',1,0)),0) as hot_count,IFNULL(SUM(IF(iskey='1',1,0)),0) as key_count from `sm_message_x` where sm_date=:sm_date and place_type=:place_type and hotel=:hotel ";
  312. MapSqlParameterSource sps = new MapSqlParameterSource();
  313. sps.addValue("sm_date", TimeExchange.getDate());
  314. sps.addValue("place_type", place_type);
  315. sps.addValue("hotel", hotel);
  316. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  317. }
  318. // 第二道防线各场所绿码详情
  319. public SecondPlaceJc queryGreen(String place_type){
  320. String sql = "select IFNULL(COUNT(distinct UUID,sm_date,protect_type),0) as green_count from `sm_message` where sm_color='绿码' and place_type=:place_type and sm_date=:sm_date ";
  321. MapSqlParameterSource sps = new MapSqlParameterSource();
  322. sps.addValue("place_type", place_type);
  323. sps.addValue("sm_date", TimeExchange.getDate());
  324. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  325. }
  326. // 第二道防线各门店绿码详情
  327. public SecondPlaceJc queryGreenByCommon(String place_type,String hotel){
  328. String sql = "select IFNULL(COUNT(distinct UUID,sm_date,protect_type),0) as green_count from `sm_message` where sm_color='绿码' and place_type=:place_type and sm_date=:sm_date and hotel=:hotel ";
  329. MapSqlParameterSource sps = new MapSqlParameterSource();
  330. sps.addValue("place_type", place_type);
  331. sps.addValue("sm_date", TimeExchange.getDate());
  332. sps.addValue("hotel", hotel);
  333. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  334. }
  335. // 第二道防线发热加时间搜索
  336. public List<User> queryByTime(int page, int rows,String sqlx){
  337. int start = (page - 1) * rows;// 每页的起始下标
  338. String sql = "select * from `sm_message_x` where protect_type='2' and ishot='1' " + sqlx +" order by sm_time desc limit :start,:rows ";
  339. MapSqlParameterSource sps = new MapSqlParameterSource();
  340. sps.addValue("start", start);
  341. sps.addValue("rows", rows);
  342. List<User> list = namedParameterJdbcTemplate.query(sql, sps,
  343. new BeanPropertyRowMapper<User>(User.class));
  344. if (list != null && list.size() > 0) {
  345. return list;
  346. }
  347. return null;
  348. }
  349. // 查询用户表中的总记录数
  350. public int findUsersTotal(String s1) {
  351. String sql = "select count(*) from `sm_message_x` where protect_type='2' and ishot='1' "+s1;
  352. MapSqlParameterSource sps = new MapSqlParameterSource();
  353. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  354. }
  355. // 第二道防线累积加时间搜索
  356. public List<User> queryLjByTime(int page, int rows,String sqlx){
  357. int start = (page - 1) * rows;// 每页的起始下标
  358. String sql = "select * from `sm_message_x` where protect_type='2' " + sqlx +" order by sm_time desc limit :start,:rows ";
  359. MapSqlParameterSource sps = new MapSqlParameterSource();
  360. sps.addValue("start", start);
  361. sps.addValue("rows", rows);
  362. List<User> list = namedParameterJdbcTemplate.query(sql, sps,
  363. new BeanPropertyRowMapper<User>(User.class));
  364. if (list != null && list.size() > 0) {
  365. return list;
  366. }
  367. return null;
  368. }
  369. // 查询用户表中的累积总记录数
  370. public int findLjUsersTotal(String s1) {
  371. String sql = "select count(*) from `sm_message_x` where protect_type='2' "+s1;
  372. MapSqlParameterSource sps = new MapSqlParameterSource();
  373. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  374. }
  375. // 第二道防线累积红黄码详情
  376. public SecondPlaceJc queryLjRy(){
  377. String sql = "select IFNULL(SUM(IF(sm_color='红码',1,0)),0) as red_count,IFNULL(SUM(IF(sm_color='黄码',1,0)),0) as yellow_count,IFNULL(SUM(IF(ishot='1',1,0)),0) as hot_count from `sm_message_x` where protect_type='2' ";
  378. MapSqlParameterSource sps = new MapSqlParameterSource();
  379. sps.addValue("sm_date", TimeExchange.getDate());
  380. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  381. }
  382. // 第二道防线累积绿码详情
  383. public SecondPlaceJc queryLjGreen(){
  384. String sql = "select IFNULL(COUNT(distinct UUID,sm_date,protect_type),0) as green_count from `sm_message` where sm_color='绿码' and protect_type='2' ";
  385. MapSqlParameterSource sps = new MapSqlParameterSource();
  386. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class));
  387. }
  388. // 各景点日、月、年统计
  389. public Tz queryView(String sm_place){
  390. String sql = "select IFNULL(SUM(IF(sm_date=:sm_day,1,0)),0) as daycount, IFNULL(SUM(IF(sm_date like :sm_month, 1,0)),0) as monthcount,IFNULL(SUM(IF(sm_date like :sm_year, 1,0)),0) as yearcount from `sm_message` where sm_place=:sm_place ";
  391. MapSqlParameterSource sps = new MapSqlParameterSource();
  392. sps.addValue("sm_day", TimeExchange.getDate());
  393. sps.addValue("sm_month", TimeExchange.getMonth()+"%");
  394. sps.addValue("sm_year", TimeExchange.getYear()+"%");
  395. sps.addValue("sm_place", sm_place);
  396. return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<Tz>(Tz.class));
  397. }
  398. /** =================昨日累积缓存 =============================**/
  399. // 第二道防线昨日累积扫描汇总
  400. public SecondBufferT querySbYesLj(String sm_date){
  401. String sql = "select COUNT(*) as smT from (select * from `sm_message` where protect_type=2 and sm_date=:sm_date group by UUID ) a ";
  402. MapSqlParameterSource sps = new MapSqlParameterSource();
  403. sps.addValue("sm_date", sm_date);
  404. List<SecondBufferT> list = namedParameterJdbcTemplate.query(sql, sps,
  405. new BeanPropertyRowMapper<SecondBufferT>(SecondBufferT.class));
  406. if (list != null && list.size() > 0) {
  407. return list.get(0);
  408. }
  409. return null;
  410. }
  411. // 第二道防线查询缓存数据
  412. public List<SecondBufferT> querySbCache(String dateT){
  413. String sql = "select * from `secondbuffert` where dateT=:dateT ";
  414. MapSqlParameterSource sps = new MapSqlParameterSource();
  415. sps.addValue("dateT", dateT);
  416. List<SecondBufferT> list = namedParameterJdbcTemplate.query(sql, sps,
  417. new BeanPropertyRowMapper<SecondBufferT>(SecondBufferT.class));
  418. if (list != null && list.size() > 0) {
  419. return list;
  420. }
  421. return null;
  422. }
  423. // 插入缓存
  424. public int insertSbT(SecondBufferT secondBufferT){
  425. String sql = "insert into secondbuffert(dateT,smT,smT_increase,smLt,red_count,red_increase,yellow_count,yellow_increase,green_count,green_increase) values(:dateT,:smT,:smT_increase,:smLt,:red_count,:red_increase,:yellow_count,:yellow_increase,:green_count,:green_increase)";
  426. MapSqlParameterSource sps = new MapSqlParameterSource();
  427. sps.addValue("dateT", secondBufferT.getDateT());
  428. sps.addValue("smT", secondBufferT.getSmT());
  429. sps.addValue("smT_increase", secondBufferT.getSmT_increase());
  430. sps.addValue("smLt", secondBufferT.getSmLt());
  431. sps.addValue("red_count", secondBufferT.getRed_count());
  432. sps.addValue("red_increase", secondBufferT.getRed_increase());
  433. sps.addValue("yellow_count", secondBufferT.getYellow_count());
  434. sps.addValue("yellow_increase", secondBufferT.getYellow_increase());
  435. sps.addValue("green_count", secondBufferT.getGreen_count());
  436. sps.addValue("green_increase", secondBufferT.getGreen_increase());
  437. int num = 0;
  438. try{
  439. num = namedParameterJdbcTemplate.update(sql, sps);
  440. }
  441. catch(Exception e){
  442. e.printStackTrace();
  443. }
  444. return num;
  445. }
  446. }