From 86b189ee9072db4bf2648c16307eff1da077e8e4 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期四, 23 五月 2019 14:39:10 +0800
Subject: [PATCH] fix in num,add sql index,change every 1s to every 10s

---
 src/main/resources/index.html                                           |   20 +++++++++++---------
 src/main/java/com/cloud/count/service/serviceImpl/CountServiceImpl.java |   19 ++++++++++---------
 src/main/java/com/cloud/count/dao/CountDao.java                         |    8 ++++----
 src/main/resources/application.yml                                      |    4 ++--
 4 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/src/main/java/com/cloud/count/dao/CountDao.java b/src/main/java/com/cloud/count/dao/CountDao.java
index 44b6e6d..134c1c9 100644
--- a/src/main/java/com/cloud/count/dao/CountDao.java
+++ b/src/main/java/com/cloud/count/dao/CountDao.java
@@ -23,8 +23,8 @@
      * @return
      */
 //    @Select("select COALESCE(sum(enters),0) from people where  timestamp BETWEEN #{begin} AND #{end}")
-    @Select("SELECT COALESCE(p2.enters-p1.enters,0) FROM (SELECT enters from people where  timestamp BETWEEN #{begin} AND #{end} ORDER BY id ASC LIMIT 1)p1,(SELECT enters from people where  timestamp BETWEEN #{begin} AND #{end} ORDER BY id DESC LIMIT 1)p2")
-    Integer countInPeople(@Param("begin") long begin,@Param("end") long end);
+    @Select("SELECT COALESCE(p2.enters-p1.enters,0) FROM (SELECT enters from people where dateStr=#{todayStr} and timestamp BETWEEN #{begin} AND #{end} ORDER BY id ASC LIMIT 1)p1,(SELECT enters from people where dateStr=#{todayStr} and timestamp BETWEEN #{begin} AND #{end} ORDER BY id DESC LIMIT 1)p2")
+    Integer countInPeople(@Param("begin") long begin,@Param("end") long end,@Param("todayStr") String todayStr);
 
     /**
      * 缁熻鍑哄幓浜烘暟
@@ -32,8 +32,8 @@
      * @return
      */
    // @Select("select COALESCE(sum(exits),0) from people where timestamp BETWEEN #{begin} AND #{end}")
-    @Select("SELECT COALESCE(p2.exits-p1.exits,0) FROM (SELECT exits from people where  timestamp BETWEEN #{begin} AND #{end} ORDER BY id ASC LIMIT 1)p1,(SELECT exits from people where  timestamp BETWEEN #{begin} AND #{end} ORDER BY id DESC LIMIT 1)p2")
-    Integer countOutPeople( @Param("begin") long begin,@Param("end") long end);
+    @Select("SELECT COALESCE(p2.exits-p1.exits,0) FROM (SELECT exits from people where dateStr=#{todayStr} and timestamp BETWEEN #{begin} AND #{end} ORDER BY id ASC LIMIT 1)p1,(SELECT exits from people where dateStr=#{todayStr} and timestamp BETWEEN #{begin} AND #{end} ORDER BY id DESC LIMIT 1)p2")
+    Integer countOutPeople( @Param("begin") long begin,@Param("end") long end,@Param("todayStr") String todayStr);
 
     /**
      * 鎻掑叆涓�鏉eople鏁版嵁
diff --git a/src/main/java/com/cloud/count/service/serviceImpl/CountServiceImpl.java b/src/main/java/com/cloud/count/service/serviceImpl/CountServiceImpl.java
index 0280098..7bbcf97 100644
--- a/src/main/java/com/cloud/count/service/serviceImpl/CountServiceImpl.java
+++ b/src/main/java/com/cloud/count/service/serviceImpl/CountServiceImpl.java
@@ -104,12 +104,12 @@
 
         // 浠庡紑濮嬭绠楁椂闂村埌鐜板湪鐨勮繘鏍℃暟
         //杩涙牎浜烘暟 = 褰撳墠鎶ユ枃totalEnters - 鍩哄噯杩涙牎浜烘暟 + 鏍℃鍊�
-        int inPeople = totalEnters - baseEnters + correctionPeople;
+        int inPeople = totalEnters - baseEnters + correctionPeople + initialPeople;
 
         int outPeople = totalExits - baseExits;
 
         // 鏍″唴鎬讳汉鏁� = 杩涙牎浜烘暟 - 鍑烘牎浜烘暟 + 鏍″唴鍒濆鍖栦汉鏁� + 璇樊鏁伴噺
-        int allPeople = inPeople - outPeople + initialPeople;
+        int allPeople = inPeople - outPeople;
 
         // 鐜板湪绂诲紑濮嬬粺璁$殑鏃堕棿鐨勫皬鏃舵暟 7涓灏忔椂 鎸�7涓皬鏃剁畻
         //int hour = (int)(Math.abs(now-set)+3599)/3600;
@@ -135,7 +135,7 @@
         // 浣嗘槸鍙細缁熻7锛�30锛屽垯7锛�30缁熻鐨勬暟鎹粯璁や负鍒濆浜烘暟锛屽苟涓斾互鍚庣殑浠�7锛�30寮�濮嬬粺璁�
         long hourset = set;
         for(int i=0;i<minute;i++){
-            if( (mm==i) && (countType==0) ){
+            if( (mm == i) && (countType==0) ){
                 people[i]=initialPeople;
                 set = hourset; //杩欒浠g爜寰堥噸瑕侊紝琛ㄧず閲嶆柊缁熻
             }else {
@@ -160,20 +160,21 @@
      * @return
      */
    private int getDataValue( Map<String, Object> map,int i,long start,long end,int initialPeople,int correctionPeople){
+       String todayStr = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
         switch (i){
             case 1:
                 map.put("countType","杩涙牎浜烘暟");
-                Integer countInPeople = dao.countInPeople(start,end);
-                countInPeople=countInPeople==null||countInPeople<0?0:countInPeople;
+                Integer countInPeople = dao.countInPeople(start, end, todayStr);
+                countInPeople=countInPeople==null||countInPeople < 0? 0 : countInPeople;
                 return countInPeople+correctionPeople;
             case -1:
                 map.put("countType","鍑烘牎浜烘暟");
-                Integer countOutPeople = dao.countOutPeople(start,end);
-                return countOutPeople==null||countOutPeople<0?0:countOutPeople;
+                Integer countOutPeople = dao.countOutPeople(start, end, todayStr);
+                return countOutPeople==null||countOutPeople < 0? 0 : countOutPeople;
             case 0:
                 map.put("countType","鏍″唴浜烘暟");
-                Integer in = dao.countInPeople(start,end);
-                Integer out = dao.countOutPeople(start,end);
+                Integer in = dao.countInPeople(start, end, todayStr);
+                Integer out = dao.countOutPeople(start, end, todayStr);
                 in = in==null||in<0?0:in;
                 out = out==null||out<0?0:out;
                 return in-out+initialPeople+correctionPeople;
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index e4f815f..9021fd7 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -3,9 +3,9 @@
     name: count-service
   datasource:
       driver-class-name: com.mysql.jdbc.Driver
-      url: jdbc:mysql://127.0.0.1:3306/count_device?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
+      url: jdbc:mysql://192.168.1.173:3306/count-service?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
       username: root
-      password: root
+      password: c++java123
       hikari:
         minimum-idle: 5
         maximum-pool-size: 20
diff --git a/src/main/resources/index.html b/src/main/resources/index.html
index 4954d35..1236e4e 100644
--- a/src/main/resources/index.html
+++ b/src/main/resources/index.html
@@ -20,17 +20,21 @@
 <div >
     <div style="background:#FFFFFF;background-size:100%;height:60px; width:100%;border:0px">
         <div style="background:#e6e6fa;height:60px;float:left; width:90%">
-            <div style="margin:10px 650px">
+            <div style="width:400px;margin:10px auto;">
                 <span style="font-size:32px;font-family:SimHei;font-weight:bold;text-align-all:center;">棣栭兘甯堣寖澶у绗簩闄勫睘涓</span>
             </div>
         </div>
 
-        <div style="background:#e6e6fa;height:60px;float:left; width:10%"><img onclick="update()" src="static/cl3.jpg" style="margin:0px  0px"></div>
+        <div style="background:#e6e6fa;height:60px;float:left; width:10%"><img onclick="update()" src="static/cl3.jpg" style="margin-top:4px;"></div>
+    </div>
+
+    <div style="display:flex;">
+
     </div>
 
     <div style="background:#F0F4F7;height:990px; width:100%;border:0">
-        <div style="background:#F0F4F7;height:100%;float:left; width:141px"></div>
-        <div style="background:#F0F4F7;height:100%;float:left; width:391px">
+        <!--<div style="background:#F0F4F7;height:100%;float:left; width:141px"></div>-->
+        <div style="background:#F0F4F7;height:100%;float:left; width:391px;margin-left:20px;margin-right:20px;">
             <div style="background:#F0F4F7;height:70px;float:left; width:391px"></div>
             <div onclick="changeCountType(1)" style="background:url('/static/01.jpg');height:160px;float:left; width:391px">
                 <div style="margin:60px -10px;text-align:center;float:left;height:160px; width:190px">
@@ -112,9 +116,7 @@
             </div>
             <span style="font-size:20px;font-family:SimHei;text-align-all:center;" id="start_time"></span>
         </div>
-
-        <div style="background:#F0F4F7;height:100%;float:left; width:86px">
-        </div>
+        <!--<div style="background:#F0F4F7;height:100%;float:left; width:86px"></div>-->
         <div style="background:#F0F4F7;height:100%;float:left; width:1201px">
             <div style="background:#F0F4F7;height:70px;float:right; width:1200px;text-align: right">
                 <span style="font-size:28px;font-family:SimHei;text-align-all:center;" id="date_time">2018骞�11鏈�1鏃�&nbsp;12:11&nbsp;鏄熸湡鍥�</span>
@@ -225,8 +227,8 @@
 
         $(function () {
             startRequest();
-            setInterval("startRequest()", 5000 );
-            setInterval("nowPeople()", 5000);
+            setInterval("startRequest()", 10000 );
+            setInterval("nowPeople()", 10000);
         });
         function update() {
             $.messager.confirm('娑堟伅','纭畾杩涜鍩虹璁剧疆鍚楋紵',function(r){

--
Gitblit v1.8.0