Browse Source

4-18 9:51

master
zhangqiyang 5 months ago
parent
commit
f7a9ce2d76
  1. 28
      src/main/java/com/system/log/controller/LogController.java
  2. 8
      src/main/java/com/system/log/corn/LogBackupJob.java
  3. 48
      src/main/java/com/system/log/service/LogService.java

28
src/main/java/com/system/log/controller/LogController.java

@ -60,9 +60,31 @@ public class LogController extends JpaSupport {
FileUtils.downloadFile(response, file);
}
// 导出操作日志
public void exportLog(ActionRequest request, ActionResponse response) throws IOException {
File file = logService.exportLog(request, response);
// 导出系统管理员操作日志
public void exportSystemManageUserLog(ActionRequest request, ActionResponse response)
throws IOException {
File file = logService.exportLog(request, response, "1");
FileUtils.downloadFile(response, file);
}
// 导出安全保密员操作日志
public void exportSecurityUserLog(ActionRequest request, ActionResponse response)
throws IOException {
File file = logService.exportLog(request, response, "2");
FileUtils.downloadFile(response, file);
}
// 导出安全审计员操作日志
public void exportSecurityAuditUserLog(ActionRequest request, ActionResponse response)
throws IOException {
File file = logService.exportLog(request, response, "3");
FileUtils.downloadFile(response, file);
}
// 导出业务用户操作日志
public void exportServiceUserLog(ActionRequest request, ActionResponse response)
throws IOException {
File file = logService.exportLog(request, response, "4");
FileUtils.downloadFile(response, file);
}

8
src/main/java/com/system/log/corn/LogBackupJob.java

@ -74,10 +74,10 @@ public class LogBackupJob implements Job {
logConfig.setBackupTime(backupTime);
// 计算文件大小,单位以M表示,精确小数点后两位
Map<String, String> fileSizeMap = logService.getSize(filePath);
logConfig.setThresholdSystemManageUserSize(fileSizeMap.get("16"));
logConfig.setThresholdSecurityUserSize(fileSizeMap.get("1"));
logConfig.setThresholdSecurityAuditUserSize(fileSizeMap.get("2"));
logConfig.setThresholdServiceUserSize(fileSizeMap.get("3"));
logConfig.setThresholdSystemManageUserSize(fileSizeMap.get("1"));
logConfig.setThresholdSecurityUserSize(fileSizeMap.get("2"));
logConfig.setThresholdSecurityAuditUserSize(fileSizeMap.get("3"));
logConfig.setThresholdServiceUserSize(fileSizeMap.get("4"));
logConfig.setFilePath(filePath);
if (logConfig.getRecordType().equals("Current")) {

48
src/main/java/com/system/log/service/LogService.java

@ -343,7 +343,8 @@ public class LogService {
// return getFileContent(fileList, null, null, null, null);
// }
public File exportLog(ActionRequest request, ActionResponse response) throws IOException {
public File exportLog(ActionRequest request, ActionResponse response, String userAuth)
throws IOException {
String password = request.getContext().get("password").toString();
String confirmPassword = request.getContext().get("confirmPassword").toString();
String startTime = request.getContext().get("exportStartTime").toString();
@ -366,37 +367,42 @@ public class LogService {
List<LogEntity> selectResult = new ArrayList<>();
List<LogEntity> logEntitiesList = logEntityRepository.all().fetch();
if (startTime != null && endTime != null) {
// 如果输入的开始时间与结束时间都不为空,则输出时间范围内的所有记录
// 如果输入的开始时间与结束时间都不为空,则输出时间范围内符合用户角色的所有记录
for (LogEntity logEntity : logEntitiesList) {
if ((getSqlLongTime(logEntity.getTime()) > getSqlLongTime(startTime))
&& (getSqlLongTime(logEntity.getTime()) < getSqlLongTime(endTime))) {
&& (getSqlLongTime(logEntity.getTime()) < getSqlLongTime(endTime))
&& userAuth.equals(logEntity.getUserAuth().getValue())) {
selectResult.add(logEntity);
}
}
}
if (startTime == null && endTime != null) {
// 如果输入的开始时间为空,则输出结束时间之前的所有记录
// 如果输入的开始时间为空,则输出结束时间之前的符合用户角色的所有记录
for (LogEntity logEntity : logEntitiesList) {
if ((getSqlLongTime(logEntity.getTime()) < getSqlLongTime(endTime))) {
if ((getSqlLongTime(logEntity.getTime()) < getSqlLongTime(endTime))
&& userAuth.equals(logEntity.getUserAuth().getValue())) {
selectResult.add(logEntity);
}
}
}
if (startTime != null && endTime == null) {
// 如果输入的结束时间为空,则输出开始时间之后的所有记录
// 如果输入的结束时间为空,则输出开始时间之后的符合用户角色的所有记录
for (LogEntity logEntity : logEntitiesList) {
if ((getSqlLongTime(logEntity.getTime()) > getSqlLongTime(startTime))) {
if ((getSqlLongTime(logEntity.getTime()) > getSqlLongTime(startTime))
&& userAuth.equals(logEntity.getUserAuth().getValue())) {
selectResult.add(logEntity);
}
}
}
if (startTime == null && endTime == null) {
// 如果输入的时间都为空,则输出所有记录
// 如果输入的时间都为空,则输出符合用户角色的所有记录
for (LogEntity logEntity : logEntitiesList) {
selectResult.add(logEntity);
if (userAuth.equals(logEntity.getUserAuth().getValue())) {
selectResult.add(logEntity);
}
}
}
// Object jsonObject = JSONObject.toJSON(selectResult);
@ -664,10 +670,10 @@ public class LogService {
logConfig.setBackupTime(backupTime);
// 计算文件大小,单位以M表示,精确小数点后两位
Map<String, String> fileSizeMap = getSize(filePath);
logConfig.setThresholdSystemManageUserSize(fileSizeMap.get("16"));
logConfig.setThresholdSecurityUserSize("1");
logConfig.setThresholdSecurityAuditUserSize("2");
logConfig.setThresholdServiceUserSize("3");
logConfig.setThresholdSystemManageUserSize(fileSizeMap.get("1"));
logConfig.setThresholdSecurityUserSize("2");
logConfig.setThresholdSecurityAuditUserSize("3");
logConfig.setThresholdServiceUserSize("4");
logConfig.setFilePath(filePath);
if (logConfig.getRecordType().equals("Current")) {
logConfig.setRecordType("History");
@ -696,19 +702,19 @@ public class LogService {
if (getSqlLongTime(logEntity.getTime()) > getLongTime(logConfig.getLogStartTime())
&& getSqlLongTime(logEntity.getTime()) < getLongTime(logConfig.getLogEndTime())) {
// 如果当条记录时间大于开始时间小于结束时间,则判断角色
if (logEntity.getUserAuth().getValue().equals("16")) {
if (logEntity.getUserAuth().getValue().equals("1")) {
// 系统管理员
systemManageUserResult.add(logEntity);
}
if (logEntity.getUserAuth().getValue().equals("1")) {
if (logEntity.getUserAuth().getValue().equals("2")) {
// 安全保密员
securityUserSelectResult.add(logEntity);
}
if (logEntity.getUserAuth().getValue().equals("2")) {
if (logEntity.getUserAuth().getValue().equals("3")) {
// 安全审计员
securityAuditUserSelectResult.add(logEntity);
}
if (logEntity.getUserAuth().getValue().equals("3")) {
if (logEntity.getUserAuth().getValue().equals("4")) {
// 业务用户
serviceUserSelectResult.add(logEntity);
}
@ -836,10 +842,10 @@ public class LogService {
public Map<String, String> getSize(String filePath) {
Map<String, String> map = new HashMap<>();
map.put("16", getFileSize(filePath + "systemManageUser.zip"));
map.put("1", getFileSize(filePath + "securityUser.zip"));
map.put("2", getFileSize(filePath + "securityAuditUser.zip"));
map.put("3", getFileSize(filePath + "serviceUser.zip"));
map.put("1", getFileSize(filePath + "systemManageUser.zip"));
map.put("2", getFileSize(filePath + "securityUser.zip"));
map.put("3", getFileSize(filePath + "securityAuditUser.zip"));
map.put("4", getFileSize(filePath + "serviceUser.zip"));
return map;
}

Loading…
Cancel
Save