liuxiaolong
2019-11-02 15e0c74b59753e03488654412cb1ad39d5b4a22b
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.cloud.count.controller;
import com.cloud.count.dao.CountDao;
import com.cloud.count.model.Config;
import com.cloud.count.service.CountService;
import com.cloud.count.service.serviceImpl.CountServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
@Api(value = "CountController", description = "计数统计")
@RestController
@RequestMapping("/api-count")
public class CountController {
 
    @Autowired
    private CountService countService;
    @Autowired
    private CountDao dao;
 
    // 统计数据
    @RequestMapping("/count")
    public Map<String,Object> count() throws ParseException {
        Map<String,Object> map = countService.getData();
        return map;
    }
    //统计从现在开始计时之后的进出人数
    @RequestMapping("/nowPeople")
    public Map<String,Object> nowPeople(@RequestParam("initialTime") String initialTime) throws ParseException {
 
        if("111".equals(initialTime)){
            CountServiceImpl.realtimeBaseEnters = CountServiceImpl.totalEnters;
            CountServiceImpl.realtimebBaseExits = CountServiceImpl.totalExits;
        }
 
        return countService.getNowData(null);
 
    }
    // 改变统计的数据,可以是 0校内人数 1 进校人数 -1 出校人数
    @RequestMapping("/changeCountType")
    public void changeCountType(@RequestParam("countType") int countType)  {
        System.out.println("countType:"+countType);
        countService.countType(countType);
    }
    // 得到配置信息,防止信息泄露把密码设为空
    @RequestMapping("/getConfig")
    public Config getConfig(){
        Config config = countService.getConfig();
        config.setPassword("");
        return  config;
    }
    // 把所有数据库信息清空
    @RequestMapping("/reset")
    public void reset(){
        countService.setOld();
        dao.reset();
    }
    /**关于配置的设置在这里说明一下
     * `initialTime`   '初始时间' ,要求是到了初始时间,index.html显示的进校人数,出校人数,校内人数等重新开始计算
     * `initialPeople`  '初始人数' ,
     * `correctionPeople`  '校正人数' ,
     * 在这里说明下 进校人数= 从数据库计算的人数+校正人数
     * 校内人数=进校人数+初始人数
     * `password`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码' ,
     * 密码目前没有用,因为需求改动,一开始还是有用的
     * `countStartTime`  varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
     * `init`  int(1) NOT NULL DEFAULT 1 COMMENT '初始设置是否可用(1 表示可用, 0 表示不可用)' ,
     * `cor`  int(1) NOT NULL DEFAULT 1 COMMENT '校正设置是否可用(1 表示可用, 0 表示不可用)' ,
     *
    */
    @RequestMapping(value = "/configInfo")
    public Map<String,Object> configInfo(  String initialTime,int initialPeople,int correctionPeople,int init,int cor){
        Config config = countService.getConfig();
        config.setInitialPeople(initialPeople);
        config.setCorrectionPeople(correctionPeople);
        config.setInitialTime(initialTime);
        config.setInit(init);
        config.setCor(cor);
        countService.updateConfig(config);
        Map<String,Object> map = new HashMap<>(4);
        map.put("msg",true);
        return  map;
    }
 
    @RequestMapping(value = "/configStartTime")
    public Map<String,Object> configStartTime( @RequestParam("configStartTime") String configStartTime){
        Config config = countService.getConfig();
        config.setCountStartTime(configStartTime);
        countService.updateConfig(config);
        Map<String,Object> map = new HashMap<>(4);
        map.put("msg",true);
        return  map;
    }
    @RequestMapping("/configPassword")
    public Map<String,Object> configPassword( @RequestParam("old") String old,@RequestParam("password") String password){
        Config config =countService.getConfig();
        Map<String,Object> map = new HashMap<>(4);
        map.put("msg",false);
        if(config.getPassword().equals(old)){
            countService.updateConfigPassword(password);
            map.put("msg",true);
        }
        return  map;
    }
    @RequestMapping("/checkPw")
    public Map<String,Object>  checkPw( @RequestParam("password") String password){
        Config config = countService.getConfig();
        Map<String,Object> map = new HashMap<>(4);
        map.put("msg",false);
        if(config.getPassword().equals(password)){
            config.setLink("/static/update.html");
            map.put("config",config);
            map.put("msg",true);
        }
        return  map;
    }
}