ManageService.java 1.65 KB
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();
    }
}