|
|
|
|
@ -31,28 +31,32 @@ public class LogApiServiceImpl extends ServiceImpl<LogApiMapper, LogApi> impleme |
|
|
|
|
@Override |
|
|
|
|
public List<LogRecord> logOnList(LogDTO log) { |
|
|
|
|
|
|
|
|
|
if(log.getUserId() != null){ |
|
|
|
|
User user = UserCache.getUser(Long.valueOf(log.getUserId())); |
|
|
|
|
log.setUserId(user.getAccount()); |
|
|
|
|
} |
|
|
|
|
// 按照月份查询日志所有数据
|
|
|
|
|
List<LogVO> logs = baseMapper.logOnList(log); |
|
|
|
|
|
|
|
|
|
// 返回集合创建
|
|
|
|
|
List<LogRecord> logRecords = new LinkedList<>(); |
|
|
|
|
LogRecord logRecord = new LogRecord(); |
|
|
|
|
|
|
|
|
|
// yyyy-MM-dd 日期格式转换
|
|
|
|
|
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
// yyyy-MM 年月日志标识
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); |
|
|
|
|
|
|
|
|
|
// 按照月份查询日志所有数据
|
|
|
|
|
List<LogVO> logs = baseMapper.logOnList(log); |
|
|
|
|
|
|
|
|
|
// 记录年月
|
|
|
|
|
AtomicReference<String> yearMonth = new AtomicReference<>(null); |
|
|
|
|
// logs遍历计数器
|
|
|
|
|
AtomicInteger count = new AtomicInteger(0); |
|
|
|
|
AtomicInteger count = new AtomicInteger(1); |
|
|
|
|
// logs总长度
|
|
|
|
|
int totalLogs = logs.size(); |
|
|
|
|
|
|
|
|
|
// 遍历日志数据
|
|
|
|
|
// logs.forEach(logInfo -> {
|
|
|
|
|
for (LogVO logInfo:logs){ |
|
|
|
|
|
|
|
|
|
count.incrementAndGet(); |
|
|
|
|
// 当前年月
|
|
|
|
|
String currentYearMonth = formatter.format(logInfo.getCreateTime()); |
|
|
|
|
|
|
|
|
|
@ -75,23 +79,20 @@ public class LogApiServiceImpl extends ServiceImpl<LogApiMapper, LogApi> impleme |
|
|
|
|
if (yearMonth.get().equals(currentYearMonth)) { |
|
|
|
|
// 将该条数据插入logs
|
|
|
|
|
logRecord.getLogs().add(logInfo); |
|
|
|
|
|
|
|
|
|
}else{ // 当前年月不等于记录年月
|
|
|
|
|
// 将当前年月赋值给记录年月
|
|
|
|
|
yearMonth.set(currentYearMonth); |
|
|
|
|
// 将上一组数据存入
|
|
|
|
|
for (LogVO logVO : logRecord.getLogs()){ |
|
|
|
|
User user = UserCache.getUser(logVO.getTenantId(), logVO.getCreateBy()); |
|
|
|
|
if(user != null){ |
|
|
|
|
logVO.setRealName(user.getRealName()); |
|
|
|
|
logVO.setTitle(user.getRealName() + logVO.getTitle()); |
|
|
|
|
User user1 = UserCache.getUser(logVO.getTenantId(), logVO.getCreateBy()); |
|
|
|
|
if(user1 != null){ |
|
|
|
|
logVO.setRealName(user1.getRealName()); |
|
|
|
|
logVO.setTitle(user1.getRealName() + logVO.getTitle()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// formatter1.format(logVO.getCreateTime()).substring(8);
|
|
|
|
|
String substring = formatter1.format(logVO.getCreateTime()).substring(8); |
|
|
|
|
logVO.setTime(substring.substring(0,2) + "日" + substring.substring(2)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
logRecords.add(logRecord); |
|
|
|
|
|
|
|
|
|
@ -110,21 +111,26 @@ public class LogApiServiceImpl extends ServiceImpl<LogApiMapper, LogApi> impleme |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 最后一次遍历,提交最后一组对象
|
|
|
|
|
if (count.get() == totalLogs) { |
|
|
|
|
// 遍历单条日志内容
|
|
|
|
|
for (LogVO logVO : logRecord.getLogs()) { |
|
|
|
|
User user = UserCache.getUser(logVO.getTenantId(), logVO.getCreateBy()); |
|
|
|
|
if(user != null){ |
|
|
|
|
logVO.setRealName(user.getRealName()); |
|
|
|
|
logVO.setTitle(user.getRealName() + logVO.getTitle()); |
|
|
|
|
// 查询缓存中的用户内容
|
|
|
|
|
User user1 = UserCache.getUser(logVO.getTenantId(), logVO.getCreateBy()); |
|
|
|
|
if(user1 != null){ |
|
|
|
|
logVO.setRealName(user1.getRealName()); |
|
|
|
|
logVO.setTitle(user1.getRealName() + logVO.getTitle()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String substring = formatter1.format(logVO.getCreateTime()).substring(8); |
|
|
|
|
logVO.setTime(substring.substring(0,2) + "日" + substring.substring(2)); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 最后一次执行的逻辑,将logRecord保存
|
|
|
|
|
logRecords.add(logRecord); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 计数器增加
|
|
|
|
|
count.incrementAndGet(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// logs.forEach(logVO -> {
|
|
|
|
|
|