commit | author | age
|
9bcb19
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.sys.core.log.factory; |
|
26 |
|
|
27 |
import cn.hutool.extra.spring.SpringUtil; |
|
28 |
import cn.hutool.log.Log; |
|
29 |
import org.aspectj.lang.JoinPoint; |
|
30 |
import vip.xiaonuo.core.annotion.BusinessLog; |
|
31 |
import vip.xiaonuo.core.context.requestno.RequestNoContext; |
|
32 |
import vip.xiaonuo.sys.modular.log.entity.SysOpLog; |
|
33 |
import vip.xiaonuo.sys.modular.log.entity.SysVisLog; |
|
34 |
import vip.xiaonuo.sys.modular.log.service.SysOpLogService; |
|
35 |
import vip.xiaonuo.sys.modular.log.service.SysVisLogService; |
|
36 |
|
|
37 |
import java.util.TimerTask; |
|
38 |
|
|
39 |
|
|
40 |
/** |
|
41 |
* 日志操作任务创建工厂 |
|
42 |
* |
|
43 |
* @author xuyuxiang |
|
44 |
* @date 2020/3/12 14:18 |
|
45 |
*/ |
|
46 |
public class LogTaskFactory { |
|
47 |
|
|
48 |
private static final Log log = Log.get(); |
|
49 |
|
|
50 |
private static final SysVisLogService sysVisLogService = SpringUtil.getBean(SysVisLogService.class); |
|
51 |
|
|
52 |
private static final SysOpLogService sysOpLogService = SpringUtil.getBean(SysOpLogService.class); |
|
53 |
|
|
54 |
/** |
|
55 |
* 登录日志 |
|
56 |
* |
|
57 |
* @author xuyuxiang |
|
58 |
* @date 2020/3/12 15:21 |
|
59 |
*/ |
|
60 |
public static TimerTask loginLog(SysVisLog sysVisLog, final String account, String success, String failMessage) { |
|
61 |
return new TimerTask() { |
|
62 |
@Override |
|
63 |
public void run() { |
|
64 |
try { |
|
65 |
LogFactory.createSysLoginLog(sysVisLog, account, success, failMessage); |
|
66 |
sysVisLogService.save(sysVisLog); |
|
67 |
} catch (Exception e) { |
|
68 |
log.error(">>> 创建登录日志异常,请求号为:{},具体信息为:{}", RequestNoContext.get(), e.getMessage()); |
|
69 |
} |
|
70 |
} |
|
71 |
}; |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* 登出日志 |
|
76 |
* |
|
77 |
* @author xuyuxiang |
|
78 |
* @date 2020/3/12 15:21 |
|
79 |
*/ |
|
80 |
public static TimerTask exitLog(SysVisLog sysVisLog, String account) { |
|
81 |
return new TimerTask() { |
|
82 |
@Override |
|
83 |
public void run() { |
|
84 |
try { |
|
85 |
LogFactory.createSysExitLog(sysVisLog, account); |
|
86 |
sysVisLogService.save(sysVisLog); |
|
87 |
} catch (Exception e) { |
|
88 |
log.error(">>> 创建退出日志异常,请求号为:{},具体信息为:{}", RequestNoContext.get(), e.getMessage()); |
|
89 |
} |
|
90 |
} |
|
91 |
}; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* 操作日志 |
|
96 |
* |
|
97 |
* @author xuyuxiang |
|
98 |
* @date 2020/3/12 15:21 |
|
99 |
*/ |
|
100 |
public static TimerTask operationLog(SysOpLog sysOpLog, String account, BusinessLog businessLog, JoinPoint joinPoint, String result) { |
|
101 |
return new TimerTask() { |
|
102 |
@Override |
|
103 |
public void run() { |
|
104 |
try { |
|
105 |
LogFactory.createSysOperationLog(sysOpLog, account, businessLog, joinPoint, result); |
|
106 |
sysOpLogService.save(sysOpLog); |
|
107 |
} catch (Exception e) { |
|
108 |
log.error(">>> 创建操作日志异常,请求号为:{},具体信息为:{}", RequestNoContext.get(), e.getMessage()); |
|
109 |
} |
|
110 |
} |
|
111 |
}; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* 异常日志 |
|
116 |
* |
|
117 |
* @author xuyuxiang |
|
118 |
* @date 2020/3/12 15:21 |
|
119 |
*/ |
|
120 |
public static TimerTask exceptionLog(SysOpLog sysOpLog, String account, BusinessLog businessLog, JoinPoint joinPoint, Exception exception) { |
|
121 |
return new TimerTask() { |
|
122 |
@Override |
|
123 |
public void run() { |
|
124 |
try { |
|
125 |
LogFactory.createSysExceptionLog(sysOpLog, account, businessLog, joinPoint, exception); |
|
126 |
sysOpLogService.save(sysOpLog); |
|
127 |
} catch (Exception e) { |
|
128 |
log.error(">>> 创建异常日志异常,请求号为:{},具体信息为:{}", RequestNoContext.get(), e.getMessage()); |
|
129 |
} |
|
130 |
} |
|
131 |
}; |
|
132 |
} |
|
133 |
} |