add log management
This commit is contained in:
parent
c22819d863
commit
7591ed081c
|
|
@ -7,6 +7,7 @@ import com.bonus.common.core.utils.StringUtils;
|
||||||
import com.bonus.common.core.utils.ip.IpUtils;
|
import com.bonus.common.core.utils.ip.IpUtils;
|
||||||
|
|
||||||
import com.bonus.system.api.model.LoginUser;
|
import com.bonus.system.api.model.LoginUser;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.ibatis.type.Alias;
|
import org.apache.ibatis.type.Alias;
|
||||||
|
|
@ -33,6 +34,7 @@ public class SysLogsVo {
|
||||||
/**
|
/**
|
||||||
* 日志id
|
* 日志id
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "日志ID")
|
||||||
private String logId;
|
private String logId;
|
||||||
/**
|
/**
|
||||||
* 操作人名称
|
* 操作人名称
|
||||||
|
|
@ -41,58 +43,73 @@ public class SysLogsVo {
|
||||||
/**
|
/**
|
||||||
* 访问ip
|
* 访问ip
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作ip")
|
||||||
private String ip;
|
private String ip;
|
||||||
/**
|
/**
|
||||||
* 操作人id
|
* 操作人id
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作人ID")
|
||||||
private String userId;
|
private String userId;
|
||||||
/**
|
/**
|
||||||
* 操作模块
|
* 操作模块
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作模块")
|
||||||
private String model;
|
private String model;
|
||||||
/**
|
/**
|
||||||
* 操作时间
|
* 操作时间
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作时间")
|
||||||
private String operaTime;
|
private String operaTime;
|
||||||
/**
|
/**
|
||||||
* 操作详情
|
* 操作详情
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作详情")
|
||||||
private String operateDetail;
|
private String operateDetail;
|
||||||
/**
|
/**
|
||||||
*操作类型
|
*操作类型
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作类型 增删改查 登陆 登出")
|
||||||
private String operaType;
|
private String operaType;
|
||||||
/**
|
/**
|
||||||
* 操作方法
|
* 操作方法
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "执行方法")
|
||||||
private String method;
|
private String method;
|
||||||
/**
|
/**
|
||||||
*请求路径
|
*请求路径
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "操作页面路径URI")
|
||||||
private String operaUri;
|
private String operaUri;
|
||||||
/**
|
/**
|
||||||
* 日志类型 1 业务日志 0 系统日志 2异常日志
|
* 日志类型 1 业务日志 0 系统日志 2异常日志
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "日志类型 1 业务日志 0 系统日志 2异常日志")
|
||||||
private int logType;
|
private int logType;
|
||||||
/**
|
/**
|
||||||
* 执行结果
|
* 执行结果
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "执行结果(1.成功/2.失败)")
|
||||||
private String result;
|
private String result;
|
||||||
|
// private String fruit;
|
||||||
/**
|
/**
|
||||||
* 执行时间
|
* 执行时间
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "执行时间(秒/ms)")
|
||||||
private String times;
|
private String times;
|
||||||
/**
|
/**
|
||||||
* 失败原因
|
* 失败原因
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "失败原因")
|
||||||
private String failureReason;
|
private String failureReason;
|
||||||
/**
|
/**
|
||||||
* 异常等级
|
* 异常等级
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "异常事件等级(高、中、低")
|
||||||
private String grade;
|
private String grade;
|
||||||
/**
|
/**
|
||||||
* 异常类型(ip异常/越权)
|
* 异常类型(ip异常/越权)
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(value = "异常类型(ip异常/越权)")
|
||||||
private String errType;
|
private String errType;
|
||||||
/**
|
/**
|
||||||
* 方法类型
|
* 方法类型
|
||||||
|
|
@ -103,6 +120,7 @@ public class SysLogsVo {
|
||||||
*/
|
*/
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "操作参数")
|
||||||
private String params;
|
private String params;
|
||||||
/**
|
/**
|
||||||
* 返回的数据
|
* 返回的数据
|
||||||
|
|
@ -110,12 +128,29 @@ public class SysLogsVo {
|
||||||
private String resultData;
|
private String resultData;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private int num;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序字段 1,2,3,4,5,6,7,8,
|
||||||
|
*/
|
||||||
|
private String logSort;
|
||||||
|
/**
|
||||||
|
* 倒序 1 正序 2
|
||||||
|
*/
|
||||||
|
private String logDesc;
|
||||||
|
|
||||||
|
private String startTime;
|
||||||
|
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
|
private String type;
|
||||||
/**
|
/**
|
||||||
* 越权记录
|
* 越权记录
|
||||||
* @param loginUser
|
* @param loginUser
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static SysLogsVo getSysLogsVo(LoginUser loginUser, ProceedingJoinPoint joinPoint) {
|
public static SysLogsVo getExceedAuthorithSysLogsVo(LoginUser loginUser, ProceedingJoinPoint joinPoint) {
|
||||||
SysLogsVo vo=new SysLogsVo();
|
SysLogsVo vo=new SysLogsVo();
|
||||||
try{
|
try{
|
||||||
String uuid= UUID.randomUUID().toString().replace("-","").toUpperCase();
|
String uuid= UUID.randomUUID().toString().replace("-","").toUpperCase();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public class ValidateUtils {
|
||||||
|
|
||||||
public static int MIN_LENGTH=8;
|
public static int MIN_LENGTH=8;
|
||||||
|
|
||||||
public static String PASSWORD_ERROR = "密码必须包含大小写字母、数字、特殊字符,且长度在%s-%s位之间";
|
public static String CHECKPWD_ERROR = "密码必须包含大小写字母、数字、特殊字符,且长度在%s-%s位之间";
|
||||||
/**
|
/**
|
||||||
* 密码校验
|
* 密码校验
|
||||||
*
|
*
|
||||||
|
|
@ -30,10 +30,10 @@ public class ValidateUtils {
|
||||||
public static String isPwd(String password) {
|
public static String isPwd(String password) {
|
||||||
|
|
||||||
if (password.length() < MIN_LENGTH) {
|
if (password.length() < MIN_LENGTH) {
|
||||||
return String.format(PASSWORD_ERROR,MIN_LENGTH,MAX_LENGTH);
|
return String.format(CHECKPWD_ERROR,MIN_LENGTH,MAX_LENGTH);
|
||||||
}
|
}
|
||||||
if (password.length() > MAX_LENGTH) {
|
if (password.length() > MAX_LENGTH) {
|
||||||
return String.format(PASSWORD_ERROR,MIN_LENGTH,MAX_LENGTH);
|
return String.format(CHECKPWD_ERROR,MIN_LENGTH,MAX_LENGTH);
|
||||||
}
|
}
|
||||||
boolean hasUpperCase = false;
|
boolean hasUpperCase = false;
|
||||||
boolean hasLowerCase = false;
|
boolean hasLowerCase = false;
|
||||||
|
|
@ -54,6 +54,6 @@ public class ValidateUtils {
|
||||||
if(hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar){
|
if(hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return String.format(PASSWORD_ERROR,MIN_LENGTH,MAX_LENGTH);
|
return String.format(CHECKPWD_ERROR,MIN_LENGTH,MAX_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,10 @@ public class Sm2Util {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String privateKey = getPrivateKey();
|
String privateKey = getPrivateKey();
|
||||||
String publicKey = getPublicKey();
|
String publicKey = getPublicKey();
|
||||||
System.err.println(privateKey);
|
String msg= encrypt(publicKey,"1234567890");
|
||||||
System.err.println(publicKey);
|
// String msg2= decrypt(privateKey,msg);
|
||||||
String msg= encrypt(publicKey,"张三");
|
|
||||||
String msg2= decrypt(privateKey,msg);
|
|
||||||
System.err.println(msg);
|
System.err.println(msg);
|
||||||
System.err.println(msg2);
|
// System.err.println(msg2);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 加密
|
* 加密
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.bonus.common.core.utils.encryption;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.SmUtil;
|
||||||
|
import cn.hutool.crypto.digest.SM3;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author weiweiw
|
||||||
|
* SM3加解密
|
||||||
|
*/
|
||||||
|
public class Sm3Util {
|
||||||
|
|
||||||
|
static SM3 sm3 = SmUtil.sm3WithSalt("2cc0c5f9f1749f1632efa9f63e902323".getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String msg= encrypt("1234567890");
|
||||||
|
System.err.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encrypt(String data) {
|
||||||
|
return Sm3Util.sm3.digestHex(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encrypt(InputStream data) {
|
||||||
|
return Sm3Util.sm3.digestHex(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encrypt(File dataFile) {
|
||||||
|
return Sm3Util.sm3.digestHex(dataFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -46,4 +46,11 @@ public class Sm4Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String msg= encode("1234567890");
|
||||||
|
System.err.println(msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,4 +38,26 @@ public class SystemGlobal {
|
||||||
*/
|
*/
|
||||||
public final static String PUT="PUT";
|
public final static String PUT="PUT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功数据数量
|
||||||
|
*/
|
||||||
|
public final static int SUCCESS_NUM=1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常日志
|
||||||
|
*/
|
||||||
|
public final static String LOG_ERR="2";
|
||||||
|
|
||||||
|
public final static int LOG_DEFEAT=1024;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线路工程类型
|
||||||
|
*/
|
||||||
|
public final static String LINE_TYPE="线路";
|
||||||
|
|
||||||
|
public final static String ERR_NUM="NAN";
|
||||||
|
|
||||||
|
//
|
||||||
|
public final static String LOG_TYPE="1";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,4 +151,15 @@ public class BaseController
|
||||||
{
|
{
|
||||||
return result ? success() : error();
|
return result ? success() : error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TableDataInfo getDataTableBad(List<?> list,String msg)
|
||||||
|
{
|
||||||
|
TableDataInfo rspData = new TableDataInfo();
|
||||||
|
rspData.setCode(HttpStatus.SUCCESS);
|
||||||
|
rspData.setRows(list);
|
||||||
|
rspData.setMsg(msg);
|
||||||
|
rspData.setTotal(new PageInfo(list).getTotal());
|
||||||
|
return rspData;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.bonus.common.log.annotation;
|
package com.bonus.common.log.annotation;
|
||||||
|
|
||||||
import com.bonus.common.log.enums.BusinessType;
|
|
||||||
import com.bonus.common.log.enums.OperaType;
|
import com.bonus.common.log.enums.OperaType;
|
||||||
import com.bonus.common.log.enums.OperatorType;
|
import com.bonus.common.log.enums.OperatorType;
|
||||||
|
|
||||||
|
|
@ -59,4 +58,17 @@ public @interface SysLog
|
||||||
* 排除指定的请求参数
|
* 排除指定的请求参数
|
||||||
*/
|
*/
|
||||||
public String[] excludeParamNames() default {};
|
public String[] excludeParamNames() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作类型
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String grade() default OperaType.QUERY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志类型
|
||||||
|
*/
|
||||||
|
String type() default "业务日志";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ package com.bonus.common.log.enums;
|
||||||
*/
|
*/
|
||||||
public class OperaType {
|
public class OperaType {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备份
|
||||||
|
*/
|
||||||
|
public final static String COPY_LOG="备份";
|
||||||
/**
|
/**
|
||||||
* 查询
|
* 查询
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,6 @@ public class AuthLogic
|
||||||
*/
|
*/
|
||||||
public void checkPermi(RequiresPermissions requiresPermissions, ProceedingJoinPoint joinPoint)
|
public void checkPermi(RequiresPermissions requiresPermissions, ProceedingJoinPoint joinPoint)
|
||||||
{
|
{
|
||||||
|
|
||||||
SecurityContextHolder.setPermission(StringUtils.join(requiresPermissions.value(), ","));
|
SecurityContextHolder.setPermission(StringUtils.join(requiresPermissions.value(), ","));
|
||||||
if (requiresPermissions.logical() == Logical.AND) {
|
if (requiresPermissions.logical() == Logical.AND) {
|
||||||
try{
|
try{
|
||||||
|
|
@ -164,10 +163,13 @@ public class AuthLogic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录越权日志
|
||||||
|
*/
|
||||||
public void addErrorLogs(ProceedingJoinPoint joinPoint,RequiresPermissions requiresPermissions){
|
public void addErrorLogs(ProceedingJoinPoint joinPoint,RequiresPermissions requiresPermissions){
|
||||||
try{
|
try{
|
||||||
LoginUser loginUser = getLoginUser();
|
LoginUser loginUser = getLoginUser();
|
||||||
SysLogsVo vo=SysLogsVo.getSysLogsVo(loginUser,joinPoint);
|
SysLogsVo vo=SysLogsVo.getExceedAuthorithSysLogsVo(loginUser,joinPoint);
|
||||||
LogsUtils.setRequestValue(joinPoint,vo,null);
|
LogsUtils.setRequestValue(joinPoint,vo,null);
|
||||||
SysLogsVo sysLogsVo=new SysLogsVo();
|
SysLogsVo sysLogsVo=new SysLogsVo();
|
||||||
sysLogsVo.setParams(requiresPermissions.value()[0]);
|
sysLogsVo.setParams(requiresPermissions.value()[0]);
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,12 @@
|
||||||
<groupId>com.bonus</groupId>
|
<groupId>com.bonus</groupId>
|
||||||
<artifactId>bonus-common-swagger</artifactId>
|
<artifactId>bonus-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>30.0-jre</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,173 @@
|
||||||
|
package com.bonus.system.controller;
|
||||||
|
|
||||||
|
import com.bonus.common.core.domain.R;
|
||||||
|
//import com.bonus.common.core.utils.WordUtils;
|
||||||
|
import com.bonus.common.core.web.controller.BaseController;
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.common.core.web.page.TableDataInfo;
|
||||||
|
import com.bonus.common.log.annotation.SysLog;
|
||||||
|
import com.bonus.common.log.enums.OperaType;
|
||||||
|
import com.bonus.common.core.utils.global.SystemGlobal;
|
||||||
|
import com.bonus.system.api.domain.SysLogsVo;
|
||||||
|
//import com.bonus.system.service.ExportSqlService;
|
||||||
|
import com.bonus.system.service.ISysLogService;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:cwchen
|
||||||
|
* @date:2024-02-28-14:01
|
||||||
|
* @version:1.0
|
||||||
|
* @description:系统日志
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/sys/sysLog/")
|
||||||
|
@Slf4j
|
||||||
|
public class SysLogController extends BaseController {
|
||||||
|
|
||||||
|
@Resource(name = "ISysLogService")
|
||||||
|
private ISysLogService service;
|
||||||
|
// /**
|
||||||
|
// * 存储的路径
|
||||||
|
// */
|
||||||
|
// @Value("${sql.filePath}")
|
||||||
|
// private String filePath;
|
||||||
|
|
||||||
|
@ApiOperation(value = "保存系统日志")
|
||||||
|
@PostMapping("saveLogs")
|
||||||
|
public AjaxResult saveLogs(@RequestBody SysLogsVo sysLog) {
|
||||||
|
return service.saveLogs(sysLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("addLogs")
|
||||||
|
public void addLogs(@RequestBody SysLogsVo sysLog,HttpServletRequest request) {
|
||||||
|
service.saveLogs(sysLog,request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Autowired
|
||||||
|
// private ExportSqlService exportSqlService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询系统日志")
|
||||||
|
@GetMapping("getSystemLogs")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->系统日志", grade = OperaType.QUERY, details = "查询系统日志列表", type = "系统日志")
|
||||||
|
public TableDataInfo getSystemLogs(SysLogsVo dto) {
|
||||||
|
try{
|
||||||
|
dto.setLogType(0);
|
||||||
|
startPage();
|
||||||
|
List<SysLogsVo> list = service.getSystemLogs(dto);
|
||||||
|
return getDataTable(list);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
return getDataTableBad(new ArrayList<>(),"请求出错了");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询业务日志")
|
||||||
|
@GetMapping("getYwLogs")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->业务日志", grade = OperaType.QUERY, details = "查询业务日志列表", type = "系统日志")
|
||||||
|
public TableDataInfo getYwLogs(SysLogsVo dto) {
|
||||||
|
try{
|
||||||
|
dto.setLogType(1);
|
||||||
|
startPage();
|
||||||
|
List<SysLogsVo> list = service.getSystemLogs(dto);
|
||||||
|
return getDataTable(list);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
return getDataTableBad(new ArrayList<>(),"请求出错了");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询异常日志")
|
||||||
|
@GetMapping("getErrLogs")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->异常日志", grade = OperaType.QUERY, details = "查询系统异常日志", type = "系统日志")
|
||||||
|
public TableDataInfo getErrLogs(SysLogsVo dto) {
|
||||||
|
try{
|
||||||
|
dto.setLogType(2);
|
||||||
|
startPage();
|
||||||
|
List<SysLogsVo> list = service.getSystemLogs(dto);
|
||||||
|
return getDataTable(list);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
return getDataTableBad(new ArrayList<>(),"请求出错了");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ApiOperation(value = "日志备份")
|
||||||
|
@GetMapping("downloadErrLogs")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->异常日志", grade = OperaType.COPY_LOG, details = "异常日志备份", type = "系统日志")
|
||||||
|
public void downloadErrLogs(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
// try {
|
||||||
|
// String dateTimeNow=exportSqlService.export("2");
|
||||||
|
// String path=filePath + ExportSqlService.TABLE_NAME + dateTimeNow+ SystemGlobal.TEXT_FIX;
|
||||||
|
// WordUtils.fileDown(path, "sys_log"+ dateTimeNow+".sql",response);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logger.error("文件下载失败", e);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "日志备份")
|
||||||
|
@GetMapping("downloadYwLogs")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志-->业务日志", grade = OperaType.COPY_LOG, details = "业务日志备份", type = "系统日志")
|
||||||
|
public void downloadYwLogs(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
// try {
|
||||||
|
// String dateTimeNow=exportSqlService.export("1");
|
||||||
|
// String path=filePath + ExportSqlService.TABLE_NAME + dateTimeNow+ SystemGlobal.TEXT_FIX;
|
||||||
|
// WordUtils.fileDown(path, "sys_log"+ dateTimeNow+".sql",response);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logger.error("文件下载失败", e);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "日志备份")
|
||||||
|
@GetMapping("downloadSysLogs")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->系统日志", grade = OperaType.COPY_LOG, details = "系统日志备份", type = "系统日志")
|
||||||
|
public void downloadSysLogs(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
// try {
|
||||||
|
// String dateTimeNow=exportSqlService.export("0");
|
||||||
|
// String path=filePath + ExportSqlService.TABLE_NAME + dateTimeNow+ SystemGlobal.TEXT_FIX;
|
||||||
|
// WordUtils.fileDown(path, "sys_log"+ dateTimeNow+".sql",response);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logger.error("文件下载失败", e);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询日志容量")
|
||||||
|
@PostMapping("getLogsSet")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->日志容量配置", grade = OperaType.QUERY, details = "查询日志容量", type = "系统日志")
|
||||||
|
public R<String> getLogsSet() {
|
||||||
|
return service.getLogsSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "设置日志容量")
|
||||||
|
@PostMapping("setLogsSet")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->日志容量配置", grade = OperaType.QUERY, details = "修改日志容量", type = "系统日志")
|
||||||
|
public R<String> setLogsSet(@RequestBody String capacity) {
|
||||||
|
return service.setLogsSet(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询日志统计分析")
|
||||||
|
@PostMapping("getLogStatistics")
|
||||||
|
@SysLog(title = "审计日志", module = "审计日志->日志分析", grade = OperaType.QUERY, details = "查询日志分析", type = "系统日志")
|
||||||
|
public R<Map<String,Object>> getLogStatistics(@RequestBody SysLogsVo dto) {
|
||||||
|
return service.getLogStatistics(dto);
|
||||||
|
}
|
||||||
|
@ApiOperation(value = "查询日志告警")
|
||||||
|
@PostMapping("logWarn")
|
||||||
|
public R<Map<String,Object>> logWarn() {
|
||||||
|
return service.logWarn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
package com.bonus.system.mapper;
|
||||||
|
|
||||||
|
//import cn.afterturn.easypoi.excel.entity.ExportExcelItem;
|
||||||
|
import com.bonus.system.api.domain.SysLogsVo;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:bonus
|
||||||
|
* @version:1.0
|
||||||
|
* @description:系统日志-数据库访问层
|
||||||
|
*/
|
||||||
|
@Repository(value = "SysLogMapper")
|
||||||
|
public interface SysLogMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存系统日志
|
||||||
|
*
|
||||||
|
* @param sysLog
|
||||||
|
* @description 保存系统日志
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/28 14:35
|
||||||
|
*/
|
||||||
|
void saveLogs(SysLogsVo sysLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询日志
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysLogsVo> getSystemLogs(SysLogsVo dto);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询日志容量
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getLogsSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据插入
|
||||||
|
* @param capacity
|
||||||
|
*/
|
||||||
|
void setLogsSet(String capacity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新数据
|
||||||
|
* @param capacity
|
||||||
|
*/
|
||||||
|
void updateLogsSet(String capacity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采茶戏
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getLogStatistics(SysLogsVo dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按照类型查询
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysLogsVo> getLogsList(SysLogsVo dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 方法查找模块
|
||||||
|
* @param operUri
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SysLogsVo getModule(@Param("module") String operUri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当日异常告警数量
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getErrorLogs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询日志容量
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getLogsRl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询全部日志细腻系
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysLogsVo> getAllLogs(SysLogsVo dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
* @param sysLog
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getModuleName(SysLogsVo sysLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查模块是否存在
|
||||||
|
* @param sysLog
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getModuleIsc(SysLogsVo sysLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询全部日志
|
||||||
|
* @param logType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysLogsVo> getLogsLists(@Param("logType") String logType);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.bonus.system.service;
|
||||||
|
|
||||||
|
import com.bonus.common.core.domain.R;
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.system.api.domain.SysLogsVo;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:cwchen
|
||||||
|
* @date:2024-02-28-14:01
|
||||||
|
* @version:1.0
|
||||||
|
* @description:系统日志-业务层
|
||||||
|
*/
|
||||||
|
public interface ISysLogService {
|
||||||
|
/**
|
||||||
|
* 保存系统日志
|
||||||
|
*
|
||||||
|
* @param sysLog
|
||||||
|
* @return AjaxResult
|
||||||
|
* @description
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/28 14:33
|
||||||
|
*/
|
||||||
|
AjaxResult saveLogs(SysLogsVo sysLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询系统日志
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysLogsVo> getSystemLogs(SysLogsVo dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询日志容量信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
R<String> getLogsSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审计日志容量配置
|
||||||
|
* @param capacity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
R<String> setLogsSet(String capacity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询·日志统计
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
R<Map<String, Object>> getLogStatistics(SysLogsVo dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*日志容量告警
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
R<Map<String, Object>> logWarn( );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存日志
|
||||||
|
* @param sysLog
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void saveLogs(SysLogsVo sysLog, HttpServletRequest request);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,268 @@
|
||||||
|
package com.bonus.system.service.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import com.bonus.common.core.utils.DateUtils;
|
||||||
|
import com.bonus.common.core.utils.StringUtils;
|
||||||
|
import com.bonus.system.service.ISysLogService;
|
||||||
|
import com.bonus.common.core.domain.R;
|
||||||
|
import com.bonus.common.core.utils.ip.IpUtils;
|
||||||
|
import com.bonus.common.core.utils.uuid.IdUtils;
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
|
import com.bonus.common.core.utils.global.SystemGlobal;
|
||||||
|
import com.bonus.system.api.domain.SysLogsVo;
|
||||||
|
import com.bonus.system.api.model.LoginUser;
|
||||||
|
import com.bonus.system.mapper.SysLogMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:cwchen
|
||||||
|
* @date:2024-02-28-14:02
|
||||||
|
* @version:1.0
|
||||||
|
* @description:系统日志-业务逻辑层
|
||||||
|
*/
|
||||||
|
@Service(value = "ISysLogService")
|
||||||
|
@Slf4j
|
||||||
|
public class SysLogServiceImpl implements ISysLogService {
|
||||||
|
|
||||||
|
@Resource(name = "SysLogMapper")
|
||||||
|
private SysLogMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult saveLogs(SysLogsVo sysLog) {
|
||||||
|
try {
|
||||||
|
//weiweiw
|
||||||
|
// if(sysLog.getResult() == SystemGlobal.SUCCESS_NUM){
|
||||||
|
// sysLog.setFruit("成功");
|
||||||
|
// }else {
|
||||||
|
// sysLog.setFruit("失败");
|
||||||
|
// }
|
||||||
|
//如果是异常日志
|
||||||
|
if(SystemGlobal.LOG_ERR.equals(sysLog.getErrType()) && StringUtils.isEmpty(sysLog.getModel())) {
|
||||||
|
SysLogsVo sysLog1=mapper.getModule(sysLog.getOperaUri());
|
||||||
|
if(sysLog1!=null){
|
||||||
|
sysLog.setModel(sysLog1.getModel());
|
||||||
|
sysLog.setOperateDetail(sysLog1.getOperateDetail());
|
||||||
|
}else {
|
||||||
|
if(StringUtils.isEmpty(sysLog1.getModel())){
|
||||||
|
sysLog.setModel("未知的请求模块");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mapper.saveLogs(sysLog);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存系统日志");
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveLogs(SysLogsVo sysLog, HttpServletRequest request) {
|
||||||
|
try{
|
||||||
|
// sysLog.setFruit("失败");
|
||||||
|
sysLog.setLogId(IdUtils.fastUUID());
|
||||||
|
sysLog.setIp(IpUtils.getIpAddr(request));
|
||||||
|
sysLog.setGrade("高");
|
||||||
|
sysLog.setErrType("越权访问");
|
||||||
|
sysLog.setFailureReason("页面未授权");
|
||||||
|
sysLog.setOperaType("查询");
|
||||||
|
sysLog.setOperateDetail("查看页面");
|
||||||
|
String module=mapper.getModuleName(sysLog);
|
||||||
|
sysLog.setLogType(2);
|
||||||
|
sysLog.setResult(String.valueOf(2));
|
||||||
|
sysLog.setOperaTime(DateUtils.getTime());
|
||||||
|
sysLog.setModel(module);
|
||||||
|
LoginUser user= SecurityUtils.getLoginUser();
|
||||||
|
sysLog.setUserId(String.valueOf(user.getUserid()));
|
||||||
|
sysLog.setOperaUserName(user.getUsername());
|
||||||
|
|
||||||
|
String modules=mapper.getModuleIsc(sysLog);
|
||||||
|
if(StringUtils.isNotEmpty(module)){
|
||||||
|
if(StringUtils.isEmpty(module)){
|
||||||
|
sysLog.setModel(modules);
|
||||||
|
}
|
||||||
|
mapper.saveLogs(sysLog);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysLogsVo> getSystemLogs(SysLogsVo dto) {
|
||||||
|
try{
|
||||||
|
//// weiweiw
|
||||||
|
// if (StringUtils.isEmpty(dto.getOperaTime())) {
|
||||||
|
// dto.setStartTime(DateTimeHelper.getNowDay());
|
||||||
|
// dto.setEndTime(DateTimeHelper.getNowDay());
|
||||||
|
// }else {
|
||||||
|
// dto.setStartTime(dto.getOperTime().split(" - ")[0].trim());
|
||||||
|
// dto.setEndTime(dto.getOperTime().split(" - ")[1].trim());
|
||||||
|
// }
|
||||||
|
return mapper.getSystemLogs(dto);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public R<String> getLogsSet() {
|
||||||
|
try{
|
||||||
|
String capacity=mapper.getLogsSet();
|
||||||
|
if(StringUtils.isEmpty(capacity)){
|
||||||
|
return R.ok("1024");
|
||||||
|
}
|
||||||
|
return R.ok(capacity);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
return R.ok(SystemGlobal.LOG_DEFEAT+"");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统日志 调试
|
||||||
|
* @param capacity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public R<String> setLogsSet(String capacity) {
|
||||||
|
try{
|
||||||
|
if(StringUtils.isNotEmpty(capacity)){
|
||||||
|
if(SystemGlobal.ERR_NUM.equals(capacity.toUpperCase())){
|
||||||
|
return R.fail("请输入数字");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return R.fail("日志容量最低是"+SystemGlobal.LOG_DEFEAT+"Mb");
|
||||||
|
}
|
||||||
|
|
||||||
|
Double cap=Double.parseDouble(capacity);
|
||||||
|
if(cap<SystemGlobal.LOG_DEFEAT){
|
||||||
|
return R.fail("日志容量最低是"+SystemGlobal.LOG_DEFEAT+"Mb");
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
return R.fail("请输入数字");
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
String city=mapper.getLogsSet();
|
||||||
|
if(StringUtils.isEmpty(city)){
|
||||||
|
mapper.setLogsSet(capacity);
|
||||||
|
}else {
|
||||||
|
mapper.updateLogsSet(capacity);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
return R.fail("系统异常");
|
||||||
|
}
|
||||||
|
return R.ok("设置成功","'设置成功'");
|
||||||
|
}
|
||||||
|
public final static String SUCCESS="成功";
|
||||||
|
/**
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public R<Map<String, Object>> getLogStatistics(SysLogsVo dto) {
|
||||||
|
Map<String,Object> map= Maps.newHashMap();
|
||||||
|
try{
|
||||||
|
|
||||||
|
List<SysLogsVo> all=mapper.getAllLogs(dto);
|
||||||
|
if(StringUtils.isNotEmpty(all)){
|
||||||
|
int allNum= all.stream().mapToInt(SysLogsVo::getNum).sum();
|
||||||
|
map.put("allNum",allNum);
|
||||||
|
all.forEach(vo->{
|
||||||
|
if("1".equals(vo.getResult())){
|
||||||
|
map.put("sNum",vo.getNum());
|
||||||
|
}else {
|
||||||
|
map.put("eNum",vo.getNum());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (SystemGlobal.LOG_TYPE.equals(dto.getType())){
|
||||||
|
List<Integer> type=new ArrayList<>();
|
||||||
|
List<String> typeList=new ArrayList<>();
|
||||||
|
typeList.add("系统日志");typeList.add("业务日志");typeList.add("异常日志");
|
||||||
|
type.add(0);type.add(1);type.add(2);
|
||||||
|
List<Integer> nums=new ArrayList<>();
|
||||||
|
type.forEach(str->{
|
||||||
|
dto.setLogType(str);
|
||||||
|
int num=mapper.getLogStatistics(dto);
|
||||||
|
nums.add(num);
|
||||||
|
});
|
||||||
|
map.put("list",typeList);
|
||||||
|
map.put("nums",nums);
|
||||||
|
}else {
|
||||||
|
List<String> typeList=new ArrayList<>();
|
||||||
|
List<Integer> nums=new ArrayList<>();
|
||||||
|
List<SysLogsVo> list=mapper.getLogsList(dto);
|
||||||
|
list.forEach(vo->{
|
||||||
|
typeList.add(vo.getOperaType());
|
||||||
|
nums.add(vo.getNum());
|
||||||
|
});
|
||||||
|
map.put("list",typeList);
|
||||||
|
map.put("nums",nums);
|
||||||
|
}
|
||||||
|
return R.ok(map);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
return R.ok(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志容量告警
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public R<Map<String, Object>> logWarn() {
|
||||||
|
Map<String, Object> map=Maps.newHashMap();
|
||||||
|
try {
|
||||||
|
double bfb=0.9;
|
||||||
|
//查询当日的告警
|
||||||
|
int num =mapper.getErrorLogs();
|
||||||
|
if(num>0){
|
||||||
|
map.put("logWarn","1");
|
||||||
|
map.put("err","您有新的异常告警"+num +",请及时处理!");
|
||||||
|
}else{
|
||||||
|
map.put("logWarn","0");
|
||||||
|
}
|
||||||
|
String rl=mapper.getLogsRl();
|
||||||
|
String city=mapper.getLogsSet();
|
||||||
|
Double d=Double.parseDouble(rl);
|
||||||
|
Double max=Double.parseDouble(city)*bfb;
|
||||||
|
if(d>=max){
|
||||||
|
map.put("warnType","1");
|
||||||
|
map.put("warnError","日志容量告警,当日日志内存为"+d+"MB,日志内存超过总内存的90%,请及时处理!");
|
||||||
|
}else {
|
||||||
|
map.put("warnType","0");
|
||||||
|
}
|
||||||
|
return R.ok(map);
|
||||||
|
}catch (Exception e){
|
||||||
|
map.put("logWarn","0");
|
||||||
|
map.put("warnType","0");
|
||||||
|
log.error(e.toString(),e);
|
||||||
|
}
|
||||||
|
return R.ok(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,209 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.bonus.system.mapper.SysLogMapper">
|
||||||
|
|
||||||
|
<!--保存系统日志-->
|
||||||
|
<insert id="saveLogs" parameterType="SysLogsVo">
|
||||||
|
insert into sys_logs(
|
||||||
|
log_id,opera_user_name,ip,user_id,
|
||||||
|
model,oper_time,method,params,
|
||||||
|
operate_detail,oper_type,oper_uri,
|
||||||
|
log_type,result,times,
|
||||||
|
failure_reason,grade,err_type,
|
||||||
|
method_type,title,result_data
|
||||||
|
)values (
|
||||||
|
#{logId},#{operaUserName},#{ip},#{userId},
|
||||||
|
#{model},#{operaTime},#{method},#{params},
|
||||||
|
#{operateDetail},#{operaType},#{operaUri},
|
||||||
|
#{logType},#{result},#{times},
|
||||||
|
#{failureReason},#{grade},#{errType},
|
||||||
|
#{methodType},#{title},#{resultData}
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
<!-- <insert id="saveLogs">-->
|
||||||
|
<!-- INSERT INTO sys_logs-->
|
||||||
|
<!-- <trim prefix="(" suffix=")" suffixOverrides=",">-->
|
||||||
|
<!-- <if test="logId != null and logId != ''">log_id,</if>-->
|
||||||
|
<!-- <if test="ip != null and ip!=''">ip,</if>-->
|
||||||
|
<!-- <if test="userId != null ">user_id,</if>-->
|
||||||
|
<!-- <if test="model != null and model!=''">model,</if>-->
|
||||||
|
<!-- <if test="operaUserName != null and operaUserName!=''">opera_user_name,</if>-->
|
||||||
|
<!-- <if test="operTime != null and operTime!=''">oper_time,</if>-->
|
||||||
|
<!-- <if test="method != null and method!=''">method,</if>-->
|
||||||
|
<!-- <if test="params != null and params!=''">params,</if>-->
|
||||||
|
<!-- <if test="operateDetail != null and operateDetail!=''">operate_detail,</if>-->
|
||||||
|
<!-- <if test="operType != null and operType!=''">oper_type,</if>-->
|
||||||
|
<!-- <if test="operUri != null and operUri!=''">oper_uri,</if>-->
|
||||||
|
<!-- <if test="logType != null">log_type,</if>-->
|
||||||
|
<!-- <if test="fruit != null">result,</if>-->
|
||||||
|
<!-- <if test="times != null and times!=''">times,</if>-->
|
||||||
|
<!-- <if test="failureReason != null and failureReason!=''">failure_reason,</if>-->
|
||||||
|
<!-- <if test="grade != null and grade!=''">grade,</if>-->
|
||||||
|
<!-- <if test="errType != null and errType!=''">err_type,</if>-->
|
||||||
|
<!-- </trim>-->
|
||||||
|
<!-- <trim prefix="values (" suffix=")" suffixOverrides=",">-->
|
||||||
|
<!-- <if test="logId != null and logId != ''">#{logId},</if>-->
|
||||||
|
<!-- <if test="ip != null and ip!=''">#{ip},</if>-->
|
||||||
|
<!-- <if test="userId != null">#{userId},</if>-->
|
||||||
|
<!-- <if test="model != null and model!=''">#{model},</if>-->
|
||||||
|
<!-- <if test="operaUserName != null and operaUserName!=''">#{operaUserName},</if>-->
|
||||||
|
<!-- <if test="operTime != null and operTime!=''">#{operTime},</if>-->
|
||||||
|
<!-- <if test="method != null and method!=''">#{method},</if>-->
|
||||||
|
<!-- <if test="params != null and params!=''">#{params},</if>-->
|
||||||
|
<!-- <if test="operateDetail != null and operateDetail!=''">#{operateDetail},</if>-->
|
||||||
|
<!-- <if test="operType != null and operType!=''">#{operType},</if>-->
|
||||||
|
<!-- <if test="operUri != null and operUri!=''">#{operUri},</if>-->
|
||||||
|
<!-- <if test="logType != null">#{logType},</if>-->
|
||||||
|
<!-- <if test="fruit != null">#{fruit},</if>-->
|
||||||
|
<!-- <if test="times != null and times!=''">#{times},</if>-->
|
||||||
|
<!-- <if test="failureReason != null and failureReason!=''">#{failureReason},</if>-->
|
||||||
|
<!-- <if test="grade != null and grade!=''">#{grade},</if>-->
|
||||||
|
<!-- <if test="errType != null and errType!=''">#{errType},</if>-->
|
||||||
|
<!-- </trim>-->
|
||||||
|
<!-- </insert>-->
|
||||||
|
<insert id="setLogsSet">
|
||||||
|
insert into sys_logs_set(capacity) value(#{capacity})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateLogsSet">
|
||||||
|
update sys_logs_set set capacity=#{capacity}
|
||||||
|
</update>
|
||||||
|
<select id="getSystemLogs" resultType="com.bonus.system.api.domain.SysLogsVo">
|
||||||
|
SELECT log_id,opera_user_name operaUserName,ip,user_id userId,model,
|
||||||
|
oper_time operTime,method,params,result fruit,
|
||||||
|
operate_detail operateDetail,oper_type operType,oper_uri operUri,
|
||||||
|
log_type logType,failure_reason failureReason,grade,
|
||||||
|
err_type errType,method_type methodType,times
|
||||||
|
from sys_logs
|
||||||
|
where log_type=#{logType}
|
||||||
|
<if test="operaUserName!=null and operaUserName!=''">
|
||||||
|
and opera_user_name LIKE concat('%',#{operaUserName},'%')
|
||||||
|
</if>
|
||||||
|
<if test="model!=null and model!=''">
|
||||||
|
and model LIKE concat('%',#{model},'%')
|
||||||
|
</if>
|
||||||
|
<if test="operType!=null and operType!=''">
|
||||||
|
and oper_type LIKE concat('%',#{operType},'%')
|
||||||
|
</if>
|
||||||
|
<if test="params!=null and params!=''">
|
||||||
|
and params LIKE concat('%',#{params},'%')
|
||||||
|
</if>
|
||||||
|
<if test="fruit!=null and fruit!=''">
|
||||||
|
and result =#{fruit}
|
||||||
|
</if>
|
||||||
|
<if test="errType!=null and errType!=''">
|
||||||
|
and err_type=#{errType}
|
||||||
|
</if>
|
||||||
|
<if test="grade!=null and grade!=''">
|
||||||
|
and grade=#{grade}
|
||||||
|
</if>
|
||||||
|
<if test="endTime!=null and endTime!=''">
|
||||||
|
and oper_time BETWEEN concat(#{startTime}, ' 00:00:00') AND concat(#{endTime},' 23:59:59')
|
||||||
|
</if>
|
||||||
|
<if test="ip!=null and ip!=''">
|
||||||
|
and ip=#{ip}
|
||||||
|
</if>
|
||||||
|
<if test="logSort!=null and logDesc !=null and logSort!='' and logDesc!='' ">
|
||||||
|
order by
|
||||||
|
<if test='logSort=="1"'>
|
||||||
|
oper_time
|
||||||
|
</if>
|
||||||
|
<if test='logSort=="2"'>
|
||||||
|
opera_user_name
|
||||||
|
</if>
|
||||||
|
<if test='logSort=="3"'>
|
||||||
|
model
|
||||||
|
</if>
|
||||||
|
<if test='logSort=="4"'>
|
||||||
|
ip
|
||||||
|
</if>
|
||||||
|
<if test='logSort=="5"'>
|
||||||
|
grade
|
||||||
|
</if>
|
||||||
|
<if test='logDesc=="1"'>
|
||||||
|
DESC
|
||||||
|
</if>
|
||||||
|
<if test='logDesc=="2"'>
|
||||||
|
ASC
|
||||||
|
</if>
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
<select id="getLogsSet" resultType="java.lang.String">
|
||||||
|
select capacity
|
||||||
|
from sys_logs_set
|
||||||
|
</select>
|
||||||
|
<select id="getLogStatistics" resultType="java.lang.Integer">
|
||||||
|
select COUNT(1) num
|
||||||
|
FROM sys_logs
|
||||||
|
where log_type=#{logType}
|
||||||
|
<if test="endTime!=null and endTime!=''">
|
||||||
|
and oper_time BETWEEN concat(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime},' 23:59:59')
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
<select id="getLogsList" resultType="com.bonus.system.api.domain.SysLogsVo">
|
||||||
|
select COUNT(1) num,oper_type operType
|
||||||
|
FROM sys_logs
|
||||||
|
WHERE oper_type IS NOT NULL
|
||||||
|
<if test="endTime!=null and endTime!=''">
|
||||||
|
and oper_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime},' 23:59:59')
|
||||||
|
</if>
|
||||||
|
GROUP by oper_type
|
||||||
|
</select>
|
||||||
|
<!--查询模块-->
|
||||||
|
<select id="getModule" resultType="com.bonus.system.api.domain.SysLogsVo">
|
||||||
|
select CONCAT(IFNULL(sm.menu_name,''),'->',IFNULL(sm2.menu_name,'')) module ,sm3.menu_name operateDetail
|
||||||
|
from sys_menu sm
|
||||||
|
left join sys_menu sm2 on sm2.p_id=sm.menu_id and sm2.menu_type=1
|
||||||
|
left join sys_menu sm3 on sm3.p_id=sm2.menu_id and sm3.menu_type=2
|
||||||
|
where sm3.menu_auth=#{module}
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
<select id="getErrorLogs" resultType="java.lang.Integer">
|
||||||
|
select count(1)
|
||||||
|
from sys_logs
|
||||||
|
where log_type=2
|
||||||
|
and DATE_FORMAT(oper_time,'%Y-%m-%d')=CURRENT_DATE
|
||||||
|
</select>
|
||||||
|
<select id="getLogsRl" resultType="java.lang.String">
|
||||||
|
SELECT
|
||||||
|
round(((data_length + index_length) / 1024 / 1024), 2) AS 'Size in MB'
|
||||||
|
FROM information_schema.TABLES
|
||||||
|
WHERE table_schema = 'jj_zhgd' AND table_name = 'sys_logs'
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getAllLogs" resultType="com.bonus.system.api.domain.SysLogsVo">
|
||||||
|
select count(1) num,result fruit
|
||||||
|
from sys_logs
|
||||||
|
where oper_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime},' 23:59:59')
|
||||||
|
GROUP BY result
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getModuleName" resultType="java.lang.String">
|
||||||
|
select CONCAT(IFNULL(sm.menu_name,''),'->',IFNULL(sm2.menu_name,'')) module
|
||||||
|
from sys_menu sm
|
||||||
|
left join sys_menu sm2 on sm2.p_id=sm.menu_id and sm2.menu_type=1
|
||||||
|
where sm2.menu_url=#{operUri}
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getModuleIsc" resultType="java.lang.String">
|
||||||
|
select menu_name
|
||||||
|
from sys_menu sm
|
||||||
|
where sm.menu_url=#{operUri}
|
||||||
|
limit 1
|
||||||
|
</select>
|
||||||
|
<!--查询全部日志-->
|
||||||
|
<select id="getLogsLists" resultType="com.bonus.system.api.domain.SysLogsVo">
|
||||||
|
SELECT
|
||||||
|
log_id logId, opera_user_name operaUserName,ip,
|
||||||
|
user_id userId, model, oper_time operTime,
|
||||||
|
method,params ,operate_detail operateDetail,
|
||||||
|
oper_type operType,oper_uri operUri, log_type logType,
|
||||||
|
result fruit,times,failure_reason failureReason,
|
||||||
|
grade,err_type errType, method_type methodType,
|
||||||
|
title
|
||||||
|
FROM sys_logs
|
||||||
|
where log_type=#{logType}
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
|
|
@ -16,6 +16,7 @@ app_source_jars=(
|
||||||
"bonus-modules/bonus-job/target/bonus-job.jar"
|
"bonus-modules/bonus-job/target/bonus-job.jar"
|
||||||
"bonus-modules/bonus-oss/target/bonus-oss.jar"
|
"bonus-modules/bonus-oss/target/bonus-oss.jar"
|
||||||
"bonus-modules/bonus-system/target/bonus-system.jar"
|
"bonus-modules/bonus-system/target/bonus-system.jar"
|
||||||
|
"bonus-visual/target/bonus-visual-monitor.jar"
|
||||||
)
|
)
|
||||||
|
|
||||||
for source_jar in "${app_source_jars[@]}"; do
|
for source_jar in "${app_source_jars[@]}"; do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue