package com.willalp.control.aspect;

import com.willalp.control.domain.HsControlStat;
import com.willalp.control.netty.model.ControlDataModel;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 *
 * @author hs
 */
@Aspect
@Component
public class ControlCacheAspect {
    private final static Logger log = LoggerFactory.getLogger(ControlCacheAspect.class);


    @Resource
    private ControlDataModel controlDataModel;


    /**
     * 对设备信息和执行口信息配置AOP切入
     */
    @Pointcut("execution(* com.willalp.device.service.impl.DeviceServiceImpl.*(..)) || " +
            "execution(* com.willalp.control.service.impl.HsControlUsenoConfigServiceImpl.*(..))")
    public void updateCache(){}

    @Pointcut(value = "execution(* com.willalp.control.service.IHsControlStatService.*(..)) && args(stat)", argNames = "stat")
    public void saveStat(HsControlStat stat){}

    /**
     * 对信息和执行口信息操作后 更新jvm中的缓存
     */
    @After("updateCache()")
    public void runUpdate(){
        log.info("更新 {设备} {执行口} 缓存");
        controlDataModel.updateMap();
    }


    /**
     * 前置操作 实体对象
     */
    @Before(value = "saveStat(stat)", argNames = "stat")
    public void runSave(HsControlStat stat){

    }
}

