feat(日志管理): 列表改按上报用户精确筛选,去掉设备/文件名模糊搜索与设备列

- /api/admin/device-logs/files 的 keyword LIKE 换成 uid 等值过滤:device_log_file 只有 uid 没有
  username,模糊匹配设备名会跨用户串结果,而下拉里选中的用户必须是精确命中。
- 采集配置弹窗的 keyword(终端覆盖搜索)与查看器标题里的设备名保留:那是设备维度唯一还有用的地方。
- 新增护栏 tests/device-logs-user-filter.test.ts(5 例,变异自证 5/5 转红):表头回出现「设备」、
  占位行 colspan 与列数不符、接口带回 keyword、下拉没绑上、用户选项没在 onMounted 加载,都会红。
- 上一笔提交里 DeviceLogsPage 已按 uid 传参,本笔补齐 api 层与后端,故单独 checkout 上一笔时 vue-tsc 不过。
This commit is contained in:
2026-10-04 01:19:55 +08:00
parent 4a6e139ae9
commit ea1b1909b2
5 changed files with 116 additions and 13 deletions
@@ -1,6 +1,8 @@
package com.nanri.aiimage.modules.devicelog.service;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.common.mapper.AdminUserMapper;
@@ -184,4 +186,37 @@ class DeviceLogServiceTest {
assertThat(vo.getContent()).isEqualTo("AAAA\nBBBB\n");
assertThat(vo.isTruncated()).isFalse();
}
// ---------------------------------------------------------------- 列表筛选
/** 捕获 page() 传给 selectCount 的查询条件(计数与列表走同一条 wrapper 构造)。 */
@SuppressWarnings("rawtypes")
private AbstractWrapper capturePageWrapper(String source, Long uid) {
when(mapper.selectCount(any())).thenReturn(0L);
service().page(source, uid, null, null, 1L, 15L);
ArgumentCaptor<Wrapper> captor = ArgumentCaptor.forClass(Wrapper.class);
verify(mapper).selectCount(captor.capture());
return (AbstractWrapper) captor.getValue();
}
@Test
void pageFiltersByUidExactly() {
AbstractWrapper wrapper = capturePageWrapper(null, 7L);
assertThat(wrapper.getSqlSegment()).contains("uid =");
assertThat(wrapper.getParamNameValuePairs().values()).contains(7L);
}
@Test
void pageWithoutUidKeepsAnonymousReportersVisible() {
// 未登录的桌面端与麦象采集机 uid 为空:不指定用户时它们必须仍在结果里
assertThat(capturePageWrapper(null, null).getSqlSegment()).doesNotContain("uid");
}
/** 契约:列表筛选已改为用户维度,设备名/设备ID/文件名的模糊匹配不再存在于查询路径。 */
@Test
void pageNoLongerMatchesDeviceOrFileNameFuzzily() {
String sql = capturePageWrapper("client", 7L).getSqlSegment();
assertThat(sql).contains("source =");
assertThat(sql).doesNotContain("device_name", "device_id", "file_name");
}
}