package com.happy.dao.Impl; import com.happy.Model.*; import com.happy.Model.Common.Common; import com.happy.Model.Tour.TravelSecond; import com.happy.Until.TimeExchange; import com.happy.dao.SecondBuffertDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Repository; import java.util.List; @Repository("SecondBuffertDao") public class SecondBuffertImplDao implements SecondBuffertDao { @Autowired private NamedParameterJdbcTemplate namedParameterJdbcTemplate; public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { return namedParameterJdbcTemplate; } public void setNamedParameterJdbcTemplate( NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; } public int insertSecondBufferT(SecondBufferT secondBufferT){ 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)"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("dateT", secondBufferT.getDateT()); sps.addValue("smT", secondBufferT.getSmT()); sps.addValue("smT_increase", secondBufferT.getSmT_increase()); sps.addValue("smLt", secondBufferT.getSmLt()); sps.addValue("red_count", secondBufferT.getRed_count()); sps.addValue("red_increase", secondBufferT.getRed_increase()); sps.addValue("yellow_count", secondBufferT.getYellow_count()); sps.addValue("yellow_increase", secondBufferT.getYellow_increase()); sps.addValue("green_count", secondBufferT.getGreen_count()); sps.addValue("green_increase", secondBufferT.getGreen_increase()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } // 人数统计 public int insertSecondBufferC(SecondBufferC secondBufferC){ 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)"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("dateT", secondBufferC.getDateT()); sps.addValue("dateTime", secondBufferC.getDateTime()); sps.addValue("smT", secondBufferC.getSmT()); sps.addValue("smT_increase", secondBufferC.getSmT_increase()); sps.addValue("smLt", secondBufferC.getSmLt()); sps.addValue("red_count", secondBufferC.getRed_count()); sps.addValue("red_increase", secondBufferC.getRed_increase()); sps.addValue("yellow_count", secondBufferC.getYellow_count()); sps.addValue("yellow_increase", secondBufferC.getYellow_increase()); sps.addValue("green_count", secondBufferC.getGreen_count()); sps.addValue("green_increase", secondBufferC.getGreen_increase()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } // 第二道防线扫描汇总 public List querySecondBufferT(){ String sql = "select * from secondbuffert where id in(select MAX(id) from secondbuffert) "; MapSqlParameterSource sps = new MapSqlParameterSource(); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(SecondBufferT.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线景点当日绿码人数统计 public List querySpjdGreen(String sm_date){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", sm_date); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(SecondBufferT.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线扫描汇总------红黄码发热汇总 public List querySecondBufferRy(){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(SecondBufferT.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线扫描汇总------红黄码发热汇总 public List querySbRyByDate(String sm_date){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", sm_date); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(SecondBufferT.class)); if (list != null && list.size() > 0) { return list; } return null; } // 最近7天人员分布 public List querySecondBufferTLastSeven(){ 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) "; MapSqlParameterSource sps = new MapSqlParameterSource(); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(SecondBufferT.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线扫码人数汇总 public List querySecondBufferC(){ String sql = "select * from `secondbufferc` where id in(select MAX(id) from `secondbufferc`) "; MapSqlParameterSource sps = new MapSqlParameterSource(); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(SecondBufferC.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线处理情况 public List queryHandler(){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); System.out.println(TimeExchange.getDate()); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(Handlde.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线发热人员 public int queryHot(){ String sql = "select count(*) from `sm_message_x` where ishot='1' and protect_type='2' and sm_date=:sm_date "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); return namedParameterJdbcTemplate.queryForInt(sql, sps); } // 第二道防线红码人员详情 public List queryRed(String startDate, String endDate){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("startDate", startDate); sps.addValue("endDate", endDate); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(User.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线黄码人员详情 public List queryYellow(String startDate,String endDate,int page, int rows){ int start = (page - 1) * rows;// 每页的起始下标 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("startDate", startDate); sps.addValue("endDate", endDate); sps.addValue("start", start); sps.addValue("rows", rows); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(User.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第一道防线黄码人员总数-分页 public int queryYellowTotal(String startDate,String endDate){ String sql = "select count(*) from `sm_message_x` where protect_type='2' and sm_color='黄码' and sm_date between :startDate and :endDate "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("startDate", startDate); sps.addValue("endDate", endDate); return namedParameterJdbcTemplate.queryForInt(sql, sps); } // 第二道防线地址类型 public List queryPt(){ String sql = "select * from `secondplacetype` "; MapSqlParameterSource sps = new MapSqlParameterSource(); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(Secondplacetype.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线景点名称 public List queryJd(){ String sql = "select * from `secondplace` "; MapSqlParameterSource sps = new MapSqlParameterSource(); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(Secondplace.class)); if (list != null && list.size() > 0) { return list; } return null; } // 第二道防线景点名称 public List queryJdByname(String place_name){ String sql = "select * from `secondplace` where place_name like :place_name "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("place_name", "%"+place_name+"%"); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(Secondplace.class)); if (list != null && list.size() > 0) { return list; } return null; } //插入TravelSecond public int insertTravelSecond(TravelSecond travelSecond,String dayId){ String sql = "SELECT * from travel_second where place_name = :place_name and day_id= :dayId limit 1"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("place_name", travelSecond.getPlaceName()); sps.addValue("place_id", travelSecond.getPlaceId()); sps.addValue("dayNum", travelSecond.getDayNum()); sps.addValue("totalNum", travelSecond.getTotalNum()); sps.addValue("maxValue", travelSecond.getMaxValue()); sps.addValue("dayId", dayId); List travelSecondList= namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(TravelSecond.class)); if(travelSecondList==null||travelSecondList.size()<1){ sql = "INSERT INTO `travel_second`(`place_name`, `dayNum`, `totalNum`, `maxValue`,day_id,place_id) VALUES (:place_name,:dayNum, :totalNum, :maxValue,:dayId,:place_id)"; }else { sps.addValue("id", travelSecondList.get(0).getId()); sql = "update travel_second set dayNum = :dayNum, totalNum = :totalNum,`maxValue` = :maxValue where id = :id"; } int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public TravelSecond queryTravelSecond(String place_name){ String sql = "SELECT * from travel_second where place_name = :place_name and day_id= :dayId limit 1"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("place_name", place_name); sps.addValue("dayId", TimeExchange.getDate()); List travelSecondList= namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(TravelSecond.class)); if(travelSecondList!=null&&travelSecondList.size()>0){ return travelSecondList.get(0); } return null; } // 第二道防线各场所详情 public SecondPlaceJc querySpjc(String place_type){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("place_type", place_type); sps.addValue("sm_date", TimeExchange.getDate()); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 第二道防线亮码详情 public SecondPlaceJc querySl(){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 第二道防线亮码绿码详情 public SecondPlaceJc querySlGreen(){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 第二道防线各景点详情 public SecondPlaceJc querySpjd(){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 各酒店医院详细名称 public List queryCommon(String place_type){ String sql = "select distinct hotel as common from `sm_message` where sm_date=:sm_date and place_type=:place_type "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); sps.addValue("place_type", place_type); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(Common.class)); if (list != null && list.size() > 0) { return list; } return null; } // 根据详细名称查红黄码详情 public SecondPlaceJc queryByCommon(String place_type,String hotel){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); sps.addValue("place_type", place_type); sps.addValue("hotel", hotel); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 第二道防线各场所绿码详情 public SecondPlaceJc queryGreen(String place_type){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("place_type", place_type); sps.addValue("sm_date", TimeExchange.getDate()); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 第二道防线各门店绿码详情 public SecondPlaceJc queryGreenByCommon(String place_type,String hotel){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("place_type", place_type); sps.addValue("sm_date", TimeExchange.getDate()); sps.addValue("hotel", hotel); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 第二道防线发热加时间搜索 public List queryByTime(int page, int rows,String sqlx){ int start = (page - 1) * rows;// 每页的起始下标 String sql = "select * from `sm_message_x` where protect_type='2' and ishot='1' " + sqlx +" order by sm_time desc limit :start,:rows "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("start", start); sps.addValue("rows", rows); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(User.class)); if (list != null && list.size() > 0) { return list; } return null; } // 查询用户表中的总记录数 public int findUsersTotal(String s1) { String sql = "select count(*) from `sm_message_x` where protect_type='2' and ishot='1' "+s1; MapSqlParameterSource sps = new MapSqlParameterSource(); return namedParameterJdbcTemplate.queryForInt(sql, sps); } // 第二道防线累积加时间搜索 public List queryLjByTime(int page, int rows,String sqlx){ int start = (page - 1) * rows;// 每页的起始下标 String sql = "select * from `sm_message_x` where protect_type='2' " + sqlx +" order by sm_time desc limit :start,:rows "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("start", start); sps.addValue("rows", rows); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(User.class)); if (list != null && list.size() > 0) { return list; } return null; } // 查询用户表中的累积总记录数 public int findLjUsersTotal(String s1) { String sql = "select count(*) from `sm_message_x` where protect_type='2' "+s1; MapSqlParameterSource sps = new MapSqlParameterSource(); return namedParameterJdbcTemplate.queryForInt(sql, sps); } // 第二道防线累积红黄码详情 public SecondPlaceJc queryLjRy(){ 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' "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", TimeExchange.getDate()); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 第二道防线累积绿码详情 public SecondPlaceJc queryLjGreen(){ 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' "; MapSqlParameterSource sps = new MapSqlParameterSource(); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper<>(SecondPlaceJc.class)); } // 各景点日、月、年统计 public Tz queryView(String sm_place){ 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 "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_day", TimeExchange.getDate()); sps.addValue("sm_month", TimeExchange.getMonth()+"%"); sps.addValue("sm_year", TimeExchange.getYear()+"%"); sps.addValue("sm_place", sm_place); return namedParameterJdbcTemplate.queryForObject(sql,sps,new BeanPropertyRowMapper(Tz.class)); } /** =================昨日累积缓存 =============================**/ // 第二道防线昨日累积扫描汇总 public SecondBufferT querySbYesLj(String sm_date){ String sql = "select COUNT(*) as smT from (select * from `sm_message` where protect_type=2 and sm_date=:sm_date group by UUID ) a "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("sm_date", sm_date); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(SecondBufferT.class)); if (list != null && list.size() > 0) { return list.get(0); } return null; } // 第二道防线查询缓存数据 public List querySbCache(String dateT){ String sql = "select * from `secondbuffert` where dateT=:dateT "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("dateT", dateT); List list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper(SecondBufferT.class)); if (list != null && list.size() > 0) { return list; } return null; } // 插入缓存 public int insertSbT(SecondBufferT secondBufferT){ 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)"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("dateT", secondBufferT.getDateT()); sps.addValue("smT", secondBufferT.getSmT()); sps.addValue("smT_increase", secondBufferT.getSmT_increase()); sps.addValue("smLt", secondBufferT.getSmLt()); sps.addValue("red_count", secondBufferT.getRed_count()); sps.addValue("red_increase", secondBufferT.getRed_increase()); sps.addValue("yellow_count", secondBufferT.getYellow_count()); sps.addValue("yellow_increase", secondBufferT.getYellow_increase()); sps.addValue("green_count", secondBufferT.getGreen_count()); sps.addValue("green_increase", secondBufferT.getGreen_increase()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } }