liuxiaolong
2019-05-23 86b189ee9072db4bf2648c16307eff1da077e8e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.cloud.count.dao;
import com.cloud.count.model.Config;
import com.cloud.count.model.CountState;
import com.cloud.count.model.People;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
 
@Repository
@Mapper
public interface CountDao {
    /**
     * 查询进出信息
     *
     * @return
     */
    @Select("select * from people where timestamp< #{end} and timestamp>#{begin}")
    List<People> listPeoples( @Param("begin") long begin,@Param("end") long end);
 
    /**
     * 统计进入人数
     *
     * @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 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);
 
    /**
     * 统计出去人数
     *
     * @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 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);
 
    /**
     * 插入一条People数据
     * @param people
     * @return
     */
    @Insert("INSERT INTO people(dateStr, startTime, endTime, enters,exits,timestamp) VALUES(#{dateStr},#{startTime},#{endTime},#{enters},#{exits},#{timestamp})")
    boolean savePeople(People people);
 
    @Update("update config set initialTime =#{initialTime},password=#{password},initialPeople=#{initialPeople},correctionPeople=#{correctionPeople},countStartTime=#{countStartTime},init=#{init},cor=#{cor} where id=1")
    boolean updateConfig(Config config);
 
    @Select("select * from config where id=1")
    Config getConfig();
 
    @Delete("truncate TABLE people")
    void reset();
 
//    @Update("update OldNew set oldin =#{oldin},oldout=#{oldout},realoldin=#{realoldin},realoldout=#{realoldout} where id=1")
//    boolean updateOldNew(OldNew OldNew);
 
//    @Select("select * from OldNew where id=1")
//    OldNew getOldNew();
 
    @Update("update CountState set baseEnters=#{baseEnters},baseExits=#{baseExits},totalEnters=#{totalEnters},totalExits=#{totalExits},realtimeBaseEnters=#{realtimeBaseEnters},realtimeBaseExits=#{realtimeBaseExits},errorCount=#{errorCount}, baseTime=#{baseTime} where id=1")
    boolean updateCountState(CountState state);
 
    @Select("select * from CountState where id=1")
    CountState getCountState();
}