Authored by chenchao

support set bussiness date

... ... @@ -52,4 +52,13 @@ public class ManageController {
return new ApiResponse.ApiResponseBuilder()
.code(200).message("sendMail success").build();
}
@RequestMapping("/setBussinessDate")
@ResponseBody
public ApiResponse setBussinessDate(int open,int close){
manageService.doBusinessDate(open, close);
return new ApiResponse.ApiResponseBuilder()
.code(200).message("setBussinessDate success").build();
}
}
... ...
package com.yoho.rfid.service;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import com.yoho.rfid.model.SystemConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
/**
... ... @@ -8,9 +14,10 @@ import org.springframework.stereotype.Service;
*/
@Service
public class ManageService {
private final Logger logger = LoggerFactory.getLogger(getClass());
private static final Object lockOfSendMail = new Object();
private final static Lock lock = new ReentrantLock();
/**
* 暴露在接口,可能会有并发操作
* @param isSend true:发送,也是默认值; false:不发送;
... ... @@ -22,8 +29,21 @@ public class ManageService {
}
}
public void closeHour(){
public void doBusinessDate(int openHour, int closeHour){
final Lock writelock = lock;
writelock.lock();
try{
//跨天的设置会不会有问题 如 openHour 23 ,closeHour 3;典型的夜店
if(openHour<0 || closeHour<0 || openHour>23 || closeHour>23 || openHour>closeHour){
logger.warn("fuck u, man, what r u fucking doing, u look at openHour {},closeHour {}",openHour, closeHour);
return;
}
SystemConfig systemConfig = SystemConfig.getInstance();
systemConfig.setOpenHour(openHour);
systemConfig.setCloseHour(closeHour);
}finally{
writelock.unlock();
}
}
public SystemConfig showSystemConfig(){
... ...
... ... @@ -203,6 +203,7 @@ public class MonitorService {
public void run() {
logger.info("1'st time in AppReportTask");
long cnt = 0L;
long timeout = appRebootTimeout*1000L;
while(true){
try {
Thread.currentThread().sleep(5000L);
... ... @@ -228,12 +229,13 @@ public class MonitorService {
long lastUpdateDT = req.getUpdateDateTime();
long currentDT = System.currentTimeMillis();
long diff = currentDT - lastUpdateDT;
long timeout = appRebootTimeout*1000L;
if(diff > timeout){
logger.warn("AppReportMap find reeboot, req {},currentDT {}, diff {}, timeout {}",
req, currentDT, diff, timeout);
//reboot
//infoScreenService.reboot(req.getIp(), req.getScreenType());
//TODO use queue to split send mail function, use a thread to send mail
mailService.send(buildMailContent4AppCrash(req.getIp(), req.getScreenType()).toString(),false);
needRemove.add(req.getIp());
}
... ... @@ -260,6 +262,7 @@ public class MonitorService {
public void run() {
logger.info("1'st time in HeartBeatTask");
long cnt = 0L;
long timeout = heartBeatTimeout*1000L;
while(true){
try {
Thread.currentThread().sleep(5000L);
... ... @@ -285,7 +288,7 @@ public class MonitorService {
long lastUpdateDT = packet.getUpdateDateTime();
long currentDT = System.currentTimeMillis();
long diff = currentDT - lastUpdateDT;
long timeout = heartBeatTimeout*1000L;
//todo 合并多个,只发送一封邮件
if(diff > timeout){
//reboot
... ...