完善日志备份功能
This commit is contained in:
parent
7addd31f7a
commit
59dc67b8d4
|
|
@ -145,7 +145,7 @@ public class SysLogsVo {
|
|||
|
||||
private String endTime;
|
||||
|
||||
//日志类型 1 业务日志 0 系统日志 2异常日志
|
||||
//查询类型 1 按日志类型 2 按操作类型 3 按操作人
|
||||
private String type;
|
||||
|
||||
private String capacity;
|
||||
|
|
|
|||
|
|
@ -264,10 +264,6 @@ public class PasswordValidatorService {
|
|||
public void handleIpValidation(String username, SysUser user) {
|
||||
try {
|
||||
String nowIp = IpUtils.getIpAddr();
|
||||
AjaxResult ajaxResult = remoteUserService.selectSysIpWhitelist(SecurityConstants.INNER);
|
||||
if (ajaxResult.isSuccess()){
|
||||
|
||||
}
|
||||
String hisIp = redisService.getCacheObject("IP:" + user.getUserId());
|
||||
if (!nowIp.equals(hisIp)) {
|
||||
recordLogService.saveErrorLogs(username, System.currentTimeMillis(), user.getUserId().toString());
|
||||
|
|
|
|||
|
|
@ -78,13 +78,12 @@ public class SysPasswordService {
|
|||
if (!matches(user, password)) {
|
||||
retryCount = retryCount + 1;
|
||||
recordLogService.saveLogs(username, startTime, "密码输入错误", "用户不存在/密码错误", null, null);
|
||||
redisService.setCacheObject(getCacheKey(username), retryCount, dynamicLockTime, TimeUnit.MINUTES);
|
||||
redisService.setCacheObject(getCacheKey(username), retryCount, (long)lockTime, TimeUnit.MINUTES);
|
||||
throw new ServiceException("用户不存在/密码错误");
|
||||
} else {
|
||||
clearLoginRecordCache(username);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matches(SysUser user, String rawPassword) {
|
||||
return SecurityUtils.matchesPassword(rawPassword, user.getPassword());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public class SysLogController extends BaseController {
|
|||
|
||||
@ApiOperation(value = "查询系统日志")
|
||||
@GetMapping("getSystemLogs")
|
||||
@SysLog(title = "审计日志", module = "审计日志->系统日志", businessType = OperaType.QUERY, details = "查询系统日志列表", type = "系统日志")
|
||||
@SysLog(title = "审计日志", module = "审计日志->系统日志", businessType = OperaType.QUERY, details = "查询系统日志列表", type = "系统日志",logType = 0)
|
||||
public TableDataInfo getSystemLogs(SysLogsVo dto) {
|
||||
try{
|
||||
dto.setLogType(0);
|
||||
|
|
@ -124,31 +124,31 @@ public class SysLogController extends BaseController {
|
|||
@GetMapping("downloadErrLogs")
|
||||
@SysLog(title = "审计日志", module = "审计日志->异常日志", businessType = OperaType.COPY_LOG, logType = 0, 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);
|
||||
// }
|
||||
try {
|
||||
String dateTimeNow=exportSqlService.export("2");
|
||||
String path=filePath + ExportSqlService.TABLE_NAME + dateTimeNow+ SystemGlobal.TEXT_FIX;
|
||||
FileUtils.fileDownload(path, "sys_log"+ dateTimeNow+".sql",response);
|
||||
} catch (Exception e) {
|
||||
logger.error("文件下载失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "日志备份")
|
||||
@GetMapping("downloadYwLogs")
|
||||
@SysLog(title = "审计日志", module = "审计日志-->业务日志", businessType = OperaType.COPY_LOG,logType = 0, 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);
|
||||
// }
|
||||
try {
|
||||
String dateTimeNow=exportSqlService.export("1");
|
||||
String path=filePath + ExportSqlService.TABLE_NAME + dateTimeNow+ SystemGlobal.TEXT_FIX;
|
||||
FileUtils.fileDownload(path, "sys_log"+ dateTimeNow+".sql",response);
|
||||
} catch (Exception e) {
|
||||
logger.error("文件下载失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "日志备份")
|
||||
@GetMapping("downloadSysLogs")
|
||||
@SysLog(title = "审计日志", module = "审计日志->系统日志", businessType = OperaType.COPY_LOG, details = "系统日志备份", type = "系统日志")
|
||||
@SysLog(title = "审计日志", module = "审计日志->系统日志", businessType = OperaType.COPY_LOG, details = "系统日志备份", type = "系统日志",logType = 0)
|
||||
public void downloadSysLogs(HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
String dateTimeNow=exportSqlService.export("0");
|
||||
|
|
@ -162,7 +162,7 @@ public class SysLogController extends BaseController {
|
|||
|
||||
@ApiOperation(value = "查询日志容量")
|
||||
@PostMapping("getLogsSet")
|
||||
@SysLog(title = "审计日志", module = "审计日志->日志容量配置", businessType = OperaType.QUERY, details = "查询日志容量", type = "系统日志")
|
||||
@SysLog(title = "审计日志", module = "审计日志->日志容量配置", businessType = OperaType.QUERY, details = "查询日志容量", type = "系统日志",logType = 0)
|
||||
public R<String> getLogsSet() {
|
||||
return service.getLogsSet();
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ public class SysLogController extends BaseController {
|
|||
|
||||
@ApiOperation(value = "设置日志容量")
|
||||
@PostMapping("setLogsSet")
|
||||
@SysLog(title = "审计日志", module = "审计日志->日志容量配置", businessType = OperaType.QUERY, details = "修改日志容量", type = "系统日志")
|
||||
@SysLog(title = "审计日志", module = "审计日志->日志容量配置", businessType = OperaType.QUERY, details = "修改日志容量", type = "系统日志",logType = 0)
|
||||
public R<String> setLogsSet(@RequestBody SysLogsVo dto) {
|
||||
|
||||
return service.setLogsSet(dto.getCapacity());
|
||||
|
|
@ -179,7 +179,7 @@ public class SysLogController extends BaseController {
|
|||
|
||||
@ApiOperation(value = "查询日志统计分析")
|
||||
@PostMapping("getLogStatistics")
|
||||
@SysLog(title = "审计日志", module = "审计日志->日志分析", businessType = OperaType.QUERY, details = "查询日志分析", type = "系统日志")
|
||||
@SysLog(title = "审计日志", module = "审计日志->日志分析", businessType = OperaType.QUERY, details = "查询日志分析", type = "系统日志",logType = 0)
|
||||
public R<Map<String,Object>> getLogStatistics(@RequestBody SysLogsVo dto) {
|
||||
return service.getLogStatistics(dto);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,11 +59,19 @@ public interface SysLogMapper {
|
|||
int getLogStatistics(SysLogsVo dto);
|
||||
|
||||
/**
|
||||
* 按照类型查询
|
||||
* 按照操作类型查询
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
List<SysLogsVo> getLogsList(SysLogsVo dto);
|
||||
List<SysLogsVo> getLogsListByOperType(SysLogsVo dto);
|
||||
|
||||
/**
|
||||
* 按照操作人查询
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
List<SysLogsVo> getLogsListByOperUserName(SysLogsVo dto);
|
||||
|
||||
|
||||
/**
|
||||
* 通过 方法查找模块
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ public class ExportSqlService {
|
|||
@SneakyThrows
|
||||
public String export(String logType ) {
|
||||
|
||||
|
||||
|
||||
String dateTimeNow= DateUtils.dateTimeNow();
|
||||
String path=filePath + TABLE_NAME + dateTimeNow;
|
||||
List<SysLogsVo> list=mapper.getLogsLists(logType);
|
||||
|
|
@ -48,7 +46,7 @@ public class ExportSqlService {
|
|||
try {
|
||||
// 根据你的表结构生成你需要的SQL行
|
||||
String rowSql = "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) VALUES ('"
|
||||
",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 ('"
|
||||
+ isNotNull(logs.getLogId())+ "', '"
|
||||
+isNotNull(logs.getOperaUserName())+ "', '"
|
||||
+isNotNull(logs.getIp() )+ "', '"
|
||||
|
|
@ -66,8 +64,9 @@ public class ExportSqlService {
|
|||
+ isNotNull(logs.getFailureReason()) + "', '"
|
||||
+isNotNull( logs.getGrade()) + "', '"
|
||||
+isNotNull(logs.getErrType()) + "', '"
|
||||
+ isNotNull(logs.getMethod()) + "', '"+
|
||||
isNotNull(logs.getTitle())+ "');";
|
||||
+isNotNull(logs.getMethodType()) + "', '"
|
||||
+ isNotNull(logs.getTitle()) + "', '"+
|
||||
isNotNull(logs.getResultData())+ "');";
|
||||
writer.write(rowSql + System.lineSeparator());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
|||
|
|
@ -186,6 +186,7 @@ public class SysLogServiceImpl implements ISysLogService {
|
|||
dto.setEndTime(dto.getOperTime().split(" - ")[1].trim());
|
||||
}
|
||||
List<SysLogsVo> all=mapper.getAllLogs(dto);
|
||||
//先按操作结果查询
|
||||
if(StringUtils.isNotEmpty(all)){
|
||||
int allNum= all.stream().mapToInt(SysLogsVo::getNum).sum();
|
||||
map.put("allNum",allNum);
|
||||
|
|
@ -197,7 +198,9 @@ public class SysLogServiceImpl implements ISysLogService {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (SystemGlobal.LOG_TYPE.equals(dto.getType())){
|
||||
//按日志类型查询
|
||||
List<Integer> type=new ArrayList<>();
|
||||
List<String> typeList=new ArrayList<>();
|
||||
typeList.add("系统日志");typeList.add("业务日志");typeList.add("异常日志");
|
||||
|
|
@ -210,16 +213,27 @@ public class SysLogServiceImpl implements ISysLogService {
|
|||
});
|
||||
map.put("list",typeList);
|
||||
map.put("nums",nums);
|
||||
}else {
|
||||
}else if("2".equals(dto.getType())){
|
||||
//按操作类型查询
|
||||
List<String> typeList=new ArrayList<>();
|
||||
List<Integer> nums=new ArrayList<>();
|
||||
List<SysLogsVo> list=mapper.getLogsList(dto);
|
||||
List<SysLogsVo> list=mapper.getLogsListByOperType(dto);
|
||||
list.forEach(vo->{
|
||||
typeList.add(vo.getOperType());
|
||||
nums.add(vo.getNum());
|
||||
});
|
||||
map.put("list",typeList);
|
||||
map.put("nums",nums);
|
||||
}else if ("3".equals(dto.getType())){
|
||||
List<String> typeList=new ArrayList<>();
|
||||
List<Integer> nums=new ArrayList<>();
|
||||
List<SysLogsVo> list=mapper.getLogsListByOperUserName(dto);
|
||||
list.forEach(vo->{
|
||||
typeList.add(vo.getOperaUserName());
|
||||
nums.add(vo.getNum());
|
||||
});
|
||||
map.put("list",typeList);
|
||||
map.put("nums",nums);
|
||||
}
|
||||
return R.ok(map);
|
||||
}catch (Exception e){
|
||||
|
|
|
|||
|
|
@ -132,13 +132,13 @@
|
|||
ip
|
||||
</if>
|
||||
<if test='logSort=="5"'>
|
||||
grade
|
||||
oper_type
|
||||
</if>
|
||||
<if test='logDesc=="1"'>
|
||||
DESC
|
||||
COLLATE utf8mb4_unicode_ci DESC
|
||||
</if>
|
||||
<if test='logDesc=="2"'>
|
||||
ASC
|
||||
COLLATE utf8mb4_unicode_ci ASC
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
|
@ -154,7 +154,7 @@
|
|||
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 id="getLogsListByOperType" resultType="com.bonus.system.api.domain.SysLogsVo">
|
||||
select COUNT(1) num,oper_type operType
|
||||
FROM sys_logs
|
||||
WHERE oper_type IS NOT NULL
|
||||
|
|
@ -163,6 +163,16 @@
|
|||
</if>
|
||||
GROUP by oper_type
|
||||
</select>
|
||||
<select id="getLogsListByOperUserName" resultType="com.bonus.system.api.domain.SysLogsVo">
|
||||
select COUNT(1) num,opera_user_name operaUserName
|
||||
FROM sys_logs
|
||||
WHERE opera_user_name 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 opera_user_name
|
||||
</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
|
||||
|
|
|
|||
Loading…
Reference in New Issue