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;
|
}
|
}
|