ManageService.java
1.65 KB
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
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;
/**
* Created by chenchao on 2017/11/1.
*/
@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:不发送;
*/
public void sendMail(boolean isSend){
SystemConfig systemConfig = SystemConfig.getInstance();
synchronized (lockOfSendMail) {
systemConfig.setSendMail(isSend);
}
}
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(){
return SystemConfig.getInstance();
}
}