package com.github.brandonbai.smartmonitor.interceptor;

import java.util.Date;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.brandonbai.smartmonitor.pojo.Log;
import com.github.brandonbai.smartmonitor.pojo.Threshold;
import com.github.brandonbai.smartmonitor.service.LogService;
import com.github.brandonbai.smartmonitor.service.TokenService;

/**
 * 
 * LogAspect 
 * 日志存储切面
 * @author Feihu Ji
 * @since 2016年10月15日
 *
 */
@Aspect
@Component
public class LogAspect {

    @Autowired
    private TokenService tokenService;
    @Autowired
    private LogService logService;


    @AfterReturning("execution(* org.jifeihu.smartshed.service..*.updateThresholds(..))")
    public void saveLogUpdateThreshold(JoinPoint pjp) {
        Threshold threshold = (Threshold) pjp.getArgs()[0];
        Log log = new Log();
        log.setContent("修改id为"+threshold.getId()+"的阈值为："+threshold.getMin()+"~"+threshold.getMax());
        log.setTime(new Date());
        log.setType(Log.CHANGE_THRESHOLD);
        log.setUsername(tokenService.getUser().getId()+"");
        logService.addLog(log);
    }
    @AfterReturning("execution(* org.jifeihu.smartshed.service..*.controlDevice(..))")
    public void saveLogControl(JoinPoint pjp) {
        String command = (String) pjp.getArgs()[0];
        Log log = new Log();
        log.setContent("发送控制设备指令："+command);
        log.setTime(new Date());
        log.setType(Log.CONTROL_DEVICE);
        log.setUsername(tokenService.getUser().getId()+"");
        logService.addLog(log);
    }

}
@@ -851,37 +851,50 @@
 ution(* 
-org.jifeihu.smartshed
+com.github.brandonbai.smartmonitor
 .service
@@ -1388,29 +1388,42 @@
 n(* 
-org.jifeihu.smartshed
+com.github.brandonbai.smartmonitor
 .ser
@@ -1810,8 +1810,10 @@
   %7D%0D%0A%0D%0A%7D
+%0D%0A

Update LogAspect.java