AndroidStation - 有的扫码枪(Newtologic DW-8200,T95MAX/Android 12)用 KEYCODE_DPAD_CENTER 当结束键, 之前只认 ENTER/TAB:结束键会落到当前焦点按钮上(一扫就进「服务设置」,焦点在 「清空记录」时还会清空记录),而且扫码只能等 50ms 超时才提交。现在按 deviceId 认 “刚发过条码字符的那台设备”,DPAD_CENTER 也算结束键,遥控器 OK 键不受影响。 - 新增「播报走本机扬声器(AV / 3.5mm)」开关(默认关):个别机型插 HDMI 时 HAL 会把 媒体声音锁在 HDMI 声卡,需要显式指定内建扬声器。 桌面端 - 发现列表改为按 MAC 就地合并,不再整表 Clear(每 3 秒一次刷新会把 ListView 的选中项 和滚动位置清掉,现场表现为“设备选不中”)。 - 「添加为通道」从标题行移到列表行内「操作」列,不再依赖选中项。 后端 - NVR 唯一键由全局 (host, port, username) 改为 (subject_id, host, port, username): 不同仓库的内网地址经常相同,之前会报「已被其他主体添加」。查重也只查本主体。 - 新增迁移 20261116010000-scope-nvr-unique-to-subject 与按主体范围的测试。 构建 - android_client/build.ps1:gradle 把 javac 的 stderr 提示写出来时,PowerShell 的 $ErrorActionPreference='Stop' 会把它当终止错误,release 包必失败;改为只以退出码判定。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
88 lines
3.3 KiB
JavaScript
88 lines
3.3 KiB
JavaScript
'use strict';
|
||
|
||
const { app, assert } = require('egg-mock/bootstrap');
|
||
|
||
/**
|
||
* NVR 唯一性只约束「本主体」
|
||
*
|
||
* 现场问题:A 仓库添加过 `192.168.8.242:8000`,B 仓库再加同一个内网地址时被拒绝
|
||
* (`NVR 192.168.8.242:8000 已被其他主体添加`)。内网地址在不同仓库之间撞车是正常的,
|
||
* 唯一键必须是 `(subject_id, host, port, username)`,查重也只能查本主体。
|
||
*/
|
||
describe('test/app/service/nvr-subject-scope.test.js', () => {
|
||
const SUBJECT_A = 11;
|
||
const SUBJECT_B = 22;
|
||
const ADDRESS = { host: '192.168.8.242', port: 8000, username: 'admin' };
|
||
|
||
function instance(data) {
|
||
const row = { ...data };
|
||
row.toJSON = () => ({ ...row });
|
||
row.update = async patch => Object.assign(row, patch);
|
||
row.restore = async () => { row.deletedAt = null; };
|
||
return row;
|
||
}
|
||
|
||
/** 极简 NVR 表:findOne 按 where 里的 subject_id + host/port/username 过滤,模拟真实唯一键的范围 */
|
||
function fakeNvrModel(rows) {
|
||
const calls = [];
|
||
return {
|
||
calls,
|
||
async findOne({ where }) {
|
||
calls.push(where);
|
||
return rows.find(row => Number(row.subjectId) === Number(where.subjectId)
|
||
&& row.host === where.host
|
||
&& Number(row.port) === Number(where.port)
|
||
&& row.username === where.username) || null;
|
||
},
|
||
async findByPk(id) {
|
||
return rows.find(row => String(row.id) === String(id)) || null;
|
||
},
|
||
async create(values) {
|
||
const row = instance({ id: rows.length + 101, deletedAt: null, ...values });
|
||
rows.push(row);
|
||
return row;
|
||
},
|
||
};
|
||
}
|
||
|
||
function serviceWith(rows) {
|
||
const service = app.createAnonymousContext().service.nvr;
|
||
Object.defineProperty(service, 'Nvr', { value: fakeNvrModel(rows), configurable: true });
|
||
return service;
|
||
}
|
||
|
||
it('别的仓库已经用同一个内网地址,本仓库仍然能添加', async () => {
|
||
const rows = [ instance({ id: 7, subjectId: SUBJECT_A, deletedAt: null, name: 'A仓录像机', ...ADDRESS }) ];
|
||
const service = serviceWith(rows);
|
||
|
||
const created = await service.create({ subjectId: SUBJECT_B, userId: 9, password: 'p@ss', ...ADDRESS });
|
||
|
||
assert(created.subjectId === SUBJECT_B, JSON.stringify(created));
|
||
assert(rows.length === 2, '不同主体各存一条,不能被判成冲突');
|
||
assert(rows[1].host === ADDRESS.host);
|
||
});
|
||
|
||
it('查重只看本主体:where 里必须带 subjectId', async () => {
|
||
const rows = [];
|
||
const service = serviceWith(rows);
|
||
|
||
await service.create({ subjectId: SUBJECT_B, userId: 9, password: 'p@ss', ...ADDRESS });
|
||
|
||
const where = service.Nvr.calls[0];
|
||
assert(Number(where.subjectId) === SUBJECT_B, `查重条件必须限定主体:${JSON.stringify(where)}`);
|
||
});
|
||
|
||
it('同一个主体重复添加同一台 NVR:更新原记录(含之前软删的)', async () => {
|
||
const rows = [ instance({ id: 8, subjectId: SUBJECT_B, deletedAt: new Date(), name: '旧名字', ...ADDRESS }) ];
|
||
const service = serviceWith(rows);
|
||
|
||
const updated = await service.create({
|
||
subjectId: SUBJECT_B, userId: 9, name: '新名字', password: 'p@ss', ...ADDRESS,
|
||
});
|
||
|
||
assert(rows.length === 1, '同一主体内不应新增第二条');
|
||
assert(rows[0].deletedAt === null, '软删的记录要复活');
|
||
assert(updated.name === '新名字', JSON.stringify(updated));
|
||
});
|
||
});
|