Authored by chenchao

support set bussiness date

@@ -52,4 +52,13 @@ public class ManageController { @@ -52,4 +52,13 @@ public class ManageController {
52 return new ApiResponse.ApiResponseBuilder() 52 return new ApiResponse.ApiResponseBuilder()
53 .code(200).message("sendMail success").build(); 53 .code(200).message("sendMail success").build();
54 } 54 }
  55 +
  56 + @RequestMapping("/setBussinessDate")
  57 + @ResponseBody
  58 + public ApiResponse setBussinessDate(int open,int close){
  59 + manageService.doBusinessDate(open, close);
  60 + return new ApiResponse.ApiResponseBuilder()
  61 + .code(200).message("setBussinessDate success").build();
  62 + }
  63 +
55 } 64 }
1 package com.yoho.rfid.service; 1 package com.yoho.rfid.service;
2 2
  3 +import java.util.concurrent.locks.Lock;
  4 +import java.util.concurrent.locks.ReentrantLock;
  5 +
3 import com.yoho.rfid.model.SystemConfig; 6 import com.yoho.rfid.model.SystemConfig;
  7 +
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
4 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
5 11
6 /** 12 /**
@@ -8,9 +14,10 @@ import org.springframework.stereotype.Service; @@ -8,9 +14,10 @@ import org.springframework.stereotype.Service;
8 */ 14 */
9 @Service 15 @Service
10 public class ManageService { 16 public class ManageService {
11 - 17 + private final Logger logger = LoggerFactory.getLogger(getClass());
  18 +
12 private static final Object lockOfSendMail = new Object(); 19 private static final Object lockOfSendMail = new Object();
13 - 20 + private final static Lock lock = new ReentrantLock();
14 /** 21 /**
15 * 暴露在接口,可能会有并发操作 22 * 暴露在接口,可能会有并发操作
16 * @param isSend true:发送,也是默认值; false:不发送; 23 * @param isSend true:发送,也是默认值; false:不发送;
@@ -22,8 +29,21 @@ public class ManageService { @@ -22,8 +29,21 @@ public class ManageService {
22 } 29 }
23 } 30 }
24 31
25 - public void closeHour(){  
26 - 32 + public void doBusinessDate(int openHour, int closeHour){
  33 + final Lock writelock = lock;
  34 + writelock.lock();
  35 + try{
  36 + //跨天的设置会不会有问题 如 openHour 23 ,closeHour 3;典型的夜店
  37 + if(openHour<0 || closeHour<0 || openHour>23 || closeHour>23 || openHour>closeHour){
  38 + logger.warn("fuck u, man, what r u fucking doing, u look at openHour {},closeHour {}",openHour, closeHour);
  39 + return;
  40 + }
  41 + SystemConfig systemConfig = SystemConfig.getInstance();
  42 + systemConfig.setOpenHour(openHour);
  43 + systemConfig.setCloseHour(closeHour);
  44 + }finally{
  45 + writelock.unlock();
  46 + }
27 } 47 }
28 48
29 public SystemConfig showSystemConfig(){ 49 public SystemConfig showSystemConfig(){
@@ -203,6 +203,7 @@ public class MonitorService { @@ -203,6 +203,7 @@ public class MonitorService {
203 public void run() { 203 public void run() {
204 logger.info("1'st time in AppReportTask"); 204 logger.info("1'st time in AppReportTask");
205 long cnt = 0L; 205 long cnt = 0L;
  206 + long timeout = appRebootTimeout*1000L;
206 while(true){ 207 while(true){
207 try { 208 try {
208 Thread.currentThread().sleep(5000L); 209 Thread.currentThread().sleep(5000L);
@@ -228,12 +229,13 @@ public class MonitorService { @@ -228,12 +229,13 @@ public class MonitorService {
228 long lastUpdateDT = req.getUpdateDateTime(); 229 long lastUpdateDT = req.getUpdateDateTime();
229 long currentDT = System.currentTimeMillis(); 230 long currentDT = System.currentTimeMillis();
230 long diff = currentDT - lastUpdateDT; 231 long diff = currentDT - lastUpdateDT;
231 - long timeout = appRebootTimeout*1000L; 232 +
232 if(diff > timeout){ 233 if(diff > timeout){
233 logger.warn("AppReportMap find reeboot, req {},currentDT {}, diff {}, timeout {}", 234 logger.warn("AppReportMap find reeboot, req {},currentDT {}, diff {}, timeout {}",
234 req, currentDT, diff, timeout); 235 req, currentDT, diff, timeout);
235 //reboot 236 //reboot
236 //infoScreenService.reboot(req.getIp(), req.getScreenType()); 237 //infoScreenService.reboot(req.getIp(), req.getScreenType());
  238 + //TODO use queue to split send mail function, use a thread to send mail
237 mailService.send(buildMailContent4AppCrash(req.getIp(), req.getScreenType()).toString(),false); 239 mailService.send(buildMailContent4AppCrash(req.getIp(), req.getScreenType()).toString(),false);
238 needRemove.add(req.getIp()); 240 needRemove.add(req.getIp());
239 } 241 }
@@ -260,6 +262,7 @@ public class MonitorService { @@ -260,6 +262,7 @@ public class MonitorService {
260 public void run() { 262 public void run() {
261 logger.info("1'st time in HeartBeatTask"); 263 logger.info("1'st time in HeartBeatTask");
262 long cnt = 0L; 264 long cnt = 0L;
  265 + long timeout = heartBeatTimeout*1000L;
263 while(true){ 266 while(true){
264 try { 267 try {
265 Thread.currentThread().sleep(5000L); 268 Thread.currentThread().sleep(5000L);
@@ -285,7 +288,7 @@ public class MonitorService { @@ -285,7 +288,7 @@ public class MonitorService {
285 long lastUpdateDT = packet.getUpdateDateTime(); 288 long lastUpdateDT = packet.getUpdateDateTime();
286 long currentDT = System.currentTimeMillis(); 289 long currentDT = System.currentTimeMillis();
287 long diff = currentDT - lastUpdateDT; 290 long diff = currentDT - lastUpdateDT;
288 - long timeout = heartBeatTimeout*1000L; 291 +
289 //todo 合并多个,只发送一封邮件 292 //todo 合并多个,只发送一封邮件
290 if(diff > timeout){ 293 if(diff > timeout){
291 //reboot 294 //reboot