调整操作日志查询条件,优化登录日志采集逻辑

This commit is contained in:
2026-08-07 15:59:03 +08:00
parent 4e2c7d51e4
commit 7c6b0f84ea
5 changed files with 39 additions and 40 deletions
@@ -37,13 +37,13 @@ public interface SysOptLogMapper extends BaseMapper<SysOptLog> {
/**
* 获取该账号的操作日志
*
* @param accountId 账号ID
* @param account 账号
* @param startTime 开始时间(包含)
* @param endTime 结束时间(包含)
* @return 操作日志
*/
List<SysOptLogTitleCountResp> getOptCount(
@Param("accountId") Long accountId,
@Param("account") String account,
@Param("startTime") Instant startTime,
@Param("endTime") Instant endTime
);
@@ -24,10 +24,10 @@ import java.time.Instant;
public class SysOptLogAccountReq implements Serializable {
/**
* 账号ID
* 账号
*/
@Schema(description = "账号ID")
private Long accountId;
@Schema(description = "账号")
private String account;
/**
* 创建时间范围[开始时间(包含),结束时间(包含)],不能为空且需同时包含开始,结束时间
@@ -247,32 +247,17 @@ public class SysOptLogServiceImpl implements SysOptLogService {
if (startTime.isAfter(endTime)) {
throw new BizWarning("开始时间不能大于结束时间");
}
Long accountId = req.getAccountId();
if (Objects.isNull(accountId)) {
String account = req.getAccount();
if (StringUtils.isBlank(account)) {
throw new BizWarning("账号ID不能为空");
}
// 获取该账号的操作日志
List<SysOptLogTitleCountResp> list = sysOptLogBaseService.getBaseMapper().getOptCount(accountId, startTime, endTime);
List<SysOptLogTitleCountResp> list = sysOptLogBaseService.getBaseMapper().getOptCount(account, startTime, endTime);
SysOptLogTitleTreeResp root = buildOptTree(list);
root.setTitle(getAccount(accountId));
root.setTitle(account);
return Result.ok(root);
}
/**
* 查询账号名称
*
* @param accountId 账号ID
* @return 账号名称
*/
private String getAccount(Long accountId) {
LambdaQueryWrapper<SysOptLog> query = new LambdaQueryWrapper<>();
query.select(SysOptLog::getAccount);
query.eq(SysOptLog::getAccountId, accountId);
query.last("LIMIT 1");
SysOptLog data = sysOptLogBaseService.getOne(query);
return Objects.isNull(data) ? null : data.getAccount();
}
/**
* 构建操作统计树
*
@@ -4,12 +4,12 @@
<!-- 获取操作账号列表 -->
<select id="getOptAccountList" resultType="xtools.app.sys.model.dto.resp.SysOptLogAccountResp">
SELECT account_id AS accountId,
MAX(account) AS account,
SELECT MAX(account_id) AS accountId,
account AS account,
COUNT(*) AS `count`
FROM sys_opt_log
WHERE gmt_create BETWEEN #{startTime} AND #{endTime}
GROUP BY account_id
GROUP BY account
ORDER BY COUNT(*) DESC
</select>
@@ -18,7 +18,7 @@
SELECT title,
COUNT(*) AS `count`
FROM sys_opt_log
WHERE account_id = #{accountId}
WHERE account = #{account}
AND gmt_create BETWEEN #{startTime} AND #{endTime}
GROUP BY title
</select>