| | |
| | | public class CountListener implements ApplicationListener<ContextRefreshedEvent> { |
| | | static ServerSocket server; |
| | | static Integer port = 2010; |
| | | static boolean isServerReboot = false; |
| | | |
| | | @Autowired |
| | | private CountDao dao; |
| | | |
| | | @Override |
| | | public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { |
| | |
| | | if(contextRefreshedEvent.getApplicationContext().getParent() !=null){ |
| | | return; |
| | | } |
| | | 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))){//历史数据不等于当天 |
| | | // CountServiceImpl.baseEnters = people.getEnters(); |
| | | // CountServiceImpl.baseExits = people.getExits(); |
| | | // CountServiceImpl.realtimeBaseEnters = people.getEnters(); |
| | | // CountServiceImpl.realtimebBaseExits = people.getExits(); |
| | | // CountServiceImpl.errorCount = 0; |
| | | |
| | | People initPeople = new People(); |
| | | initPeople.setEnters(0); |
| | | initPeople.setExits(0); |
| | | CountServiceImpl.initCountArgs(initPeople); |
| | | CountServiceImpl.errorCount = 0; |
| | | break op; |
| | | } |
| | | //还原状态 |
| | | CountServiceImpl.baseEnters = state.getBaseEnters(); |
| | | CountServiceImpl.baseExits = state.getBaseExits(); |
| | | CountServiceImpl.totalEnters = state.getTotalEnters(); |
| | | CountServiceImpl.totalExits = state.getTotalExits(); |
| | | CountServiceImpl.realtimeBaseEnters = state.getRealtimeBaseEnters(); |
| | | CountServiceImpl.realtimebBaseExits = state.getRealtimeBaseExits(); |
| | | CountServiceImpl.errorCount = state.getErrorCount(); |
| | | } |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |