5b38785b33b06d877101ef639ca5d5e675c85b4d..046305f178960ad0024f111e7f042e54befc66c7
2019-11-02 liuxiaolong
fix style
046305 对比 | 目录
2019-11-02 liuxiaolong
fix count mechine limit 65535
bcffe0 对比 | 目录
2019-11-02 liuxiaolong
add .gitignore
15e0c7 对比 | 目录
1个文件已添加
5个文件已修改
158 ■■■■ 已修改文件
.gitignore 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/cloud/count/dao/CountDao.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/cloud/count/listener/CountListener.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/cloud/count/service/serviceImpl/CountServiceImpl.java 99 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/index.html 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/static/count.css 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
New file
@@ -0,0 +1,5 @@
.idea
.vscode
logs
target
.iml
src/main/java/com/cloud/count/dao/CountDao.java
@@ -58,9 +58,9 @@
//    @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")
    @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")
    @Select("select * from countstate where id=1")
    CountState getCountState();
}
src/main/java/com/cloud/count/listener/CountListener.java
@@ -2,6 +2,7 @@
import com.cloud.count.dao.CountDao;
import com.cloud.count.model.CountState;
import com.cloud.count.model.People;
import com.cloud.count.service.CountService;
import com.cloud.count.service.serviceImpl.CountServiceImpl;
import com.cloud.count.utils.XmlUtil;
import org.slf4j.Logger;
@@ -62,29 +63,38 @@
                        byte[] b=new byte[1024];
                        is.read(b);
                        String str = new String(b);
//                        logger.info(str);
                        sendAck(iWriter);
                        try{
                            String xmlStr = XmlUtil.toXmlStr(str);
                            // 如果存在TotalEnters。则证明返回的是实时数据的xml
                            People people = null;
                            if(xmlStr.indexOf("TotalEnters")>-1){
                                people = XmlUtil.realTimeXmlToPeople(xmlStr);
                                dao.savePeople(people);
                                CountServiceImpl.totalEnters = people.getEnters();
                                CountServiceImpl.totalExits = people.getExits();
                                int inCreEnter = CountServiceImpl.addEnter(people.getEnters());//进入人数增量
                                int inCreExit = CountServiceImpl.addExit(people.getExits());//出去人数增量
                                System.out.println("TotalEnters:"+people.getEnters());
                                CountServiceImpl.totalEnters += inCreEnter;
                                CountServiceImpl.totalExits += inCreExit;
                                if( CountServiceImpl.totalEnters < CountServiceImpl.baseEnters){
                                    //表示统计设备重新启动了,统计参数归零
                                    CountServiceImpl.initCountArgs(people);
                                }
                                people.setEnters(CountServiceImpl.totalEnters);//将累加后的数量存到数据库中
                                people.setExits(CountServiceImpl.totalExits);
                                boolean resultB = dao.savePeople(people);
                                //总进入数量或者总出去数量,不一定哪一个先到2字节int的上限65535
//                                if( CountServiceImpl.totalEnters < CountServiceImpl.baseEnters){
//                                    //表示统计设备重新启动了,统计参数归零
//                                    CountServiceImpl.initCountArgs(people);
//                                }
                               op: if(!isServerReboot){
                                    isServerReboot = true;
                                    CountState state = dao.getCountState();//恢复统计状态
                                    Date nowDate = new Date();
                                    Date BaseDate = new Date(state.getBaseTime()*1000L);
                                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                    if(!sdf.format(nowDate).equals(sdf.format(BaseDate))){
                                    if(!sdf.format(nowDate).equals(sdf.format(BaseDate))){//历史数据不等于当天
                                        CountServiceImpl.baseEnters  = people.getEnters();
                                        CountServiceImpl.baseExits = people.getExits();
                                        CountServiceImpl.realtimeBaseEnters = people.getEnters();
@@ -92,6 +102,7 @@
                                        CountServiceImpl.errorCount = 0;
                                        break op;
                                    }
                                    //还原状态
                                    CountServiceImpl.baseEnters  = state.getBaseEnters();
                                    CountServiceImpl.baseExits = state.getBaseExits();
                                    CountServiceImpl.totalEnters = state.getTotalEnters();
@@ -117,6 +128,8 @@
                                currentState.setErrorCount(CountServiceImpl.errorCount);
                                currentState.setBaseTime(people.getTimestamp());
                                dao.updateCountState(currentState);//更新当前统计状态
                            } else {
                                System.out.println("noTotalEners");
                            }
                            // 如果存在ReportData。则证明返回的是统计数据的xml
                            if(xmlStr.indexOf("ReportData")>-1){
@@ -124,7 +137,7 @@
                                dao.savePeople(people);
                            }
                        }catch (Exception e){
                            System.out.println(e.getMessage());
                        }
                    }catch (IOException ex){
src/main/java/com/cloud/count/service/serviceImpl/CountServiceImpl.java
@@ -32,6 +32,19 @@
     */
    public static volatile int totalExits = 0;
    /**
     * 统计设备可统计的最大数量
     */
    private static final int MAXCOUNT = 65535;
    /**
     * 统计设备单词可统计的最大数量
     */
    private static final int MAXCOUNTONCE = 100;
    /**
     * 计算的进入中间变量
     */
    private static volatile int tmpEnter = 0;
    private static volatile int tmpExit = 0;
    /**
     * 实时计算时作为计算的进校人数基准值
     */
    public static volatile int realtimeBaseEnters = 0;
@@ -56,6 +69,32 @@
    private static Map<Integer,Integer> dayAllMap = new HashMap<>();
    private static Map<Integer,Integer> dayOutMap = new HashMap<>();
    private static Map<Integer,Integer> dayInMap = new HashMap<>();
    public static int addEnter(int count) {
        int inCre = 0;
        if(tmpEnter <= count){
            inCre = count - tmpEnter;
        } else {
            if(tmpEnter >= (MAXCOUNT-MAXCOUNTONCE) && count <= MAXCOUNT) {
                inCre = count + MAXCOUNT - tmpEnter;
            }
        }
        tmpEnter = count;
        return inCre;
    }
    public static int addExit(int count) {
        int inCre = 0;
        if(tmpExit <= count){
            inCre = count - tmpExit;
        } else {
            if(tmpExit >= (MAXCOUNT-MAXCOUNTONCE) && count <= MAXCOUNT) {
                inCre = count + MAXCOUNT - tmpExit;
            }
        }
        tmpExit = count;
        return inCre;
    }
    /**
     * 统计参数初始化,用于统计设备重启情况(发送的第一条报文)
@@ -87,6 +126,15 @@
        Map<String,Object> map = new HashMap<>(16);
        // 获取一些初始值
        Config config = dao.getConfig();
        if(config==null) {
            config = new Config();
            config.setCor(1);
            config.setPassword("123456");
            config.setCountStartTime("06:00");
            config.setInit(1);
            config.setInitialPeople(60);
            config.setInitialTime("00:00");
        }
        // 初始人数值
        int initialPeople = (config.getInit()==1)?config.getInitialPeople():0;
        // 校正人数值
@@ -148,32 +196,33 @@
                people[i]=initialPeople;
                set = hourset; //这行代码很重要,表示重新统计
            }else {
//                System.out.println("第"+i+"个小时的数据:");
               // people[i] = dao.countInPeople(set-60,hourset+3599)- dao.countOutPeople(set-60,hourset+3599)+initialPeople+correctionPeople;
                //使用缓存dayAllMap
                people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
//                if(countType == 1){
//                    if(dayInMap.containsKey(i) && minute >1 && (i != minute-1)){
//                        people[i] = dayInMap.get(i);
//                    }else{
//                        people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
//                        dayInMap.put(i, people[i]);
//                    }
//                } else if(countType == 0) {
//                    if(dayAllMap.containsKey(i) && minute >1 && (i != minute-1)){
//                        people[i] = dayAllMap.get(i);
//                    }else{
//                        people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
//                        dayAllMap.put(i, people[i]);
//                    }
//                } else {
//                    if(dayOutMap.containsKey(i) && minute >1 && (i != minute-1)){
//                        people[i] = dayOutMap.get(i);
//                    }else{
//                        people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
//                        dayOutMap.put(i, people[i]);
//                    }
//                }
                //每次都实时计算,会重复计算历史数据
//                people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
                //采用缓存的方式,算过的就不再计算了
                if(countType == 1){
                    if(dayInMap.containsKey(i) && minute >1 && (i != minute-1)){
                        people[i] = dayInMap.get(i);
                    }else{
                        people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
                        dayInMap.put(i, people[i]);
                    }
                } else if(countType == 0) {
                    if(dayAllMap.containsKey(i) && minute >1 && (i != minute-1)){
                        people[i] = dayAllMap.get(i);
                    }else{
                        people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
                        dayAllMap.put(i, people[i]);
                    }
                } else {
                    if(dayOutMap.containsKey(i) && minute >1 && (i != minute-1)){
                        people[i] = dayOutMap.get(i);
                    }else{
                        people[i] = getDataValue(map,countType,set-60,hourset+1799,initialPeople,correctionPeople);
                        dayOutMap.put(i, people[i]);
                    }
                }
            }
src/main/resources/index.html
@@ -73,7 +73,7 @@
                        <!--</div>-->
                    </div>
                </div>
                <div class="curInDiv">
                <div class="curInDiv" style="margin-left:10px;">
                    <div class="curOutBg">
                        <!--<div style="margin:30px auto;text-align:left;height:137px; width:200px">-->
                        <span>
@@ -290,8 +290,8 @@
    $(function () {
        startRequest();
        setInterval("startRequest()", 10000 );
        setInterval("nowPeople()", 10000);
        setInterval("startRequest()", 3000 );
        setInterval("nowPeople()", 3000);
    });
    function update() {
        $.messager.confirm('消息','确定进行基础设置吗?',function(r){
src/main/resources/static/count.css
@@ -54,6 +54,8 @@
    background:#3C3C3C;
    display:inline;
    border: none;
    width: 34px;
    margin-left:15px;
}
.reloadImg{
    background-image: url('zz.png');
@@ -66,23 +68,22 @@
}
.curInDiv{
    background:#F0F4F7;
    width:153px;
    width:173px;
}
.curInBg{
    background-image:url('03.jpg');
    backround-repeat: no-repeat;
    text-align:center;
    height:40px;
    width:153px;
    margin-left:10px;
    margin-right:10px;
    width:173px;
    margin-left:5px;
}
.curOutBg{
    background-image:url('02.jpg');
    backround-repeat: no-repeat;
    text-align:center;
    height:40px;
    width:153px;
    width:173px;
}
.rightDiv{
    width:100%;