Repository navigation
feat(notice): 公告已读状态(未读数 / 标记已读) - #553
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
公告目前只有「一条广播记录」,谁读过完全不知道:
/notice/*没有已读接口,小程序端也无法区分新公告。这个 PR 增加按用户的已读状态:sys_notice_read(user_id + notice_id唯一,read_at),公告/用户删除级联清理;GET /system/notice/unread-count→{ unread }(首页红点)GET /system/notice/read-ids→[int](列表标未读)POST /system/notice/read→ 传notice_ids标指定公告,不传则全部标为已读,返回剩余未读数顺手修了一个会挡住这个功能的既有问题:
GET /notice/available用NoticeCRUD.page()查询,非超管会被基座叠加created_id = 当前用户的数据范围条件 → 普通用户查不到任何公告(公告由运营创建)。已改为显式直查并预加载审计关系,返回结构与分页参数保持不变。Changes
backend/app/modules/system/notice/{model,schema,service,controller}.py:已读记录表 + 3 个接口 +available_page直查backend/app/alembic/versions/2026_11_03_0900_a1b2c3d4e5f6.py:新表迁移(down_revision = e082c18b2f01)backend/tests/test_notice_read_state.py:未读数增量、幂等标记、全部已读、按用户隔离、未登录 401backend/tests/conftest.py:新增TEST_DB_TYPE=postgres开关(默认仍是 sqlite,CI 行为不变),因为 SQLite 与 PG 在唯一约束/迁移上行为并不一致,涉及迁移的改动需要能在 PG 上验证frontend/app/src/api/module_system/notice.ts、subPages/module_system/notices/index.vue、locales/{zh,en}.json:未读红点 / 点开即已读 / 全部已读口径说明
0 = 启用(对外可见)、1 = 停用。模型注释里写的「0:草稿 1:已发布 2:已归档」与代码不一致,本 PR 没有改动状态语义,只按代码实际口径实现(避免夹带行为变更)。available_page仍是最多 10 条、按 id 升序,未改分页与排序,只修数据权限。Testing
TEST_DB_TYPE=postgres TEST_DB_PORT=<pg> pytest tests -q→ 229 passed(含新增 3 个已读用例)pytest tests/test_notice_read_state.py -q→ 3 passed(PostgreSQL,非 SQLite)pnpm type-check→ green;pnpm build:h5→ 构建通过;改动文件eslint无报错已知与本次无关:
frontend/app/src/subPages/module_system/tickets/index.vue在 dev 分支上就有一个TICKET_STATUS_MAP未使用的 lint 报错,未处理。