集合:资源地图(resources)
字数
1613 字
阅读时间
8 分钟
1. 目的与使用场景
- 存储校内外心理支持资源信息,支撑"我的"页资源地图导航、一键联系功能、资源推荐和运营分析。由资源管理后台、
/api/resources接口、联系记录埋点使用。
2. Schema 定义
| 字段 | 类型 | 必填 | 默认值 | 约束/校验 | 说明 | 隐私分级 |
|---|---|---|---|---|---|---|
| _id | string | 是 | - | TCB 自动 | 主键 | P1 |
| name | string | 是 | - | 长度 2-40 | 资源名称 | P1 |
| description | string | 否 | - | 长度 ≤ 200 | 简要说明 | P1 |
| category | string | 是 | campus | 枚举(campus,community,helpline,online,self_help,emergency) | 资源分类 | P1 |
| sub_category | string | 否 | - | 枚举(counseling,medical,peer_support,crisis,academic) | 子分类 | P1 |
| contact_info | object | 是 | - | {phone,email,wechat,url,address} | 联系方式 | P2 |
| operating_hours | object | 否 | - | {timezone,schedule[]} | 营业时间 | P1 |
| location | object | 否 | - | {campus,building,room,geo_point} | 地理位置 | P2 |
| support_anonymous | bool | 否 | true | - | 支持匿名联系 | P1 |
| appointment_required | bool | 否 | false | - | 需要预约 | P1 |
| service_scope | array | 否 | [] | 元素为 string | 服务范围 | P1 |
| eligibility | array | 否 | [] | 元素为 string | 适用人群 | P1 |
| confidentiality | string | 否 | standard | 枚举(standard,enhanced,anonymous) | 保密级别 | P1 |
| cost_info | string | 否 | 免费 | 长度 ≤ 50 | 费用说明 | P1 |
| languages | array | 否 | ["中文"] | 元素为 string | 支持语言 | P1 |
| accessibility | array | 否 | [] | 元素为 string | 无障碍设施 | P1 |
| tags | array | 否 | [] | 元素为 string | 标签 | P1 |
| rating | number | 否 | 0 | 0-5 | 用户评分 | P1 |
| usage_count | number | 否 | 0 | ≥0 | 使用次数 | P1 |
| status | string | 是 | active | 枚举(active,maintenance,inactive) | 状态 | P1 |
| priority | number | 否 | 50 | 1-100 | 显示优先级 | P1 |
| metadata | object | 否 | - | {logo_url,images[],verification_date,last_audit} | 扩展信息 | P1 |
| createdAt | date | 是 | - | 服务端时间 | 创建时间 | P1 |
| updatedAt | date | 是 | - | 服务端时间 | 更新时间 | P1 |
3. 索引与唯一约束
- 单字段索引:
category、sub_category、status、support_anonymous - 复合索引:
[category, status, priority desc]、[support_anonymous, status]、[location.campus, status] - 全文索引:
name、description、tags(支持搜索) - 设计理由:资源地图按分类和优先级展示;匿名筛选常用;校园内资源需按校区分组。
4. 访问控制(TCB 权限)
json
{
"read": "status == 'active' || auth.role in ['ops','counselor']",
"write": "auth.role in ['resource_admin','ops']"
}用户可查看活跃资源;运营负责资源维护和状态管理。
5. 关系与级联
- 通过
contact_logs记录用户联系行为 - 与
feedback关联收集用户评价 - 删除策略:活跃资源不删除,标记为 inactive;保留历史联系记录。
- 反范式:
usage_count、rating缓存统计数据,减少实时聚合。
6. 数据生命周期与合规
- 留存:资源信息长期保留;过期资源归档但不删除。
- 匿名化:联系记录单独存储,资源本身不含个人数据。
- 审计字段:
createdAt、updatedAt、metadata.verification_date。
7. API/云函数契约映射
| 接口/函数 | 读/写 | 使用字段 | 过滤条件 | 排序/分页 | 备注 | | /api/resources GET | 读 | name, description, category, contact_info, support_anonymous | status='active' | category, priority desc | 资源地图展示 | | /api/resources/:id GET | 读 | 所有字段(除内部统计) | _id 匹配 | - | 资源详情页 | | 资源后台 manageResource | 写 | status, contact_info, operating_hours | _id 匹配 | - | 运营维护 | | 联系记录云函数 logResourceContact | 读 | support_anonymous, contact_info | _id 匹配 | - | 联系前校验 | | 资源推荐服务 recommendResources | 读 | category, tags, location | 多条件筛选 | 相关性分 | 智能推荐 |
8. 示例文档(≥3条)
json
{
"_id": "res_campus_counseling_001",
"name": "学生心理健康教育中心",
"description": "提供专业心理咨询、团体辅导、心理测评等服务",
"category": "campus",
"sub_category": "counseling",
"contact_info": {
"phone": "010-12345678",
"email": "counseling@university.edu.cn",
"url": "https://counseling.university.edu.cn",
"address": "北苑学生活动中心3楼301室"
},
"operating_hours": {
"timezone": "Asia/Shanghai",
"schedule": [
{"day": "monday-fri", "time": "09:00-17:00"},
{"day": "saturday", "time": "09:00-12:00"}
]
},
"location": {
"campus": "北苑",
"building": "学生活动中心",
"room": "301",
"geo_point": {"latitude": 39.9842, "longitude": 116.3074}
},
"support_anonymous": true,
"appointment_required": true,
"service_scope": ["个人咨询", "团体辅导", "危机干预", "心理测评"],
"eligibility": ["在校生", "教职工"],
"confidentiality": "enhanced",
"cost_info": "免费",
"languages": ["中文"],
"accessibility": ["电梯", "无障碍通道"],
"tags": ["官方", "专业", "免费", "预约制"],
"rating": 4.8,
"usage_count": 1250,
"status": "active",
"priority": 90,
"metadata": {
"logo_url": "https://cdn.example.com/resources/counseling-logo.png",
"verification_date": "2024-03-01",
"last_audit": "2024-03-01"
},
"createdAt": "2024-01-15T08:00:00Z",
"updatedAt": "2024-03-15T10:30:00Z"
}
{
"_id": "res_hotline_national_001",
"name": "全国心理援助热线",
"description": "24小时专业心理危机干预热线",
"category": "helpline",
"sub_category": "crisis",
"contact_info": {
"phone": "400-161-9995",
"url": "https://psych.hotline.org.cn"
},
"operating_hours": {
"timezone": "Asia/Shanghai",
"schedule": [{"day": "everyday", "time": "00:00-24:00"}]
},
"support_anonymous": true,
"appointment_required": false,
"service_scope": ["危机干预", "情绪疏导", "心理支持"],
"eligibility": ["所有人"],
"confidentiality": "anonymous",
"cost_info": "免费",
"languages": ["中文"],
"tags": ["24小时", "全国", "危机干预", "匿名"],
"rating": 4.9,
"usage_count": 3420,
"status": "active",
"priority": 95,
"metadata": {
"verification_date": "2024-01-01"
},
"createdAt": "2024-01-10T08:00:00Z",
"updatedAt": "2024-01-10T08:00:00Z"
}
{
"_id": "res_community_peer_001",
"name": "阳光心理互助社",
"description": "学生心理互助组织,提供同伴支持和小组活动",
"category": "community",
"sub_category": "peer_support",
"contact_info": {
"wechat": "sunshine_support",
"email": "sunshine@university.edu.cn"
},
"location": {
"campus": "南苑",
"building": "学生社团楼",
"room": "205"
},
"support_anonymous": false,
"appointment_required": false,
"service_scope": ["同伴倾诉", "小组活动", "心理讲座"],
"eligibility": ["在校生"],
"confidentiality": "standard",
"cost_info": "免费",
"languages": ["中文"],
"tags": ["学生组织", "同伴支持", "小组活动"],
"rating": 4.5,
"usage_count": 680,
"status": "active",
"priority": 70,
"createdAt": "2024-02-01T08:00:00Z",
"updatedAt": "2024-03-20T14:20:00Z"
}9. 常用查询样例(≥3条)
javascript
// 获取校园内活跃资源
const campusResources = await db.collection('resources').where({
category: 'campus',
status: 'active'
}).orderBy('priority', 'desc').get();
// 查找支持匿名的危机干预资源
const anonymousCrisis = await db.collection('resources').where({
support_anonymous: true,
sub_category: 'crisis',
status: 'active'
}).orderBy('priority', 'desc').get();
// 按校区筛选资源
const northCampus = await db.collection('resources').where({
'location.campus': '北苑',
status: 'active'
}).orderBy('priority', 'desc').get();10. 边界与错误码
- 资源不存在:查询时返回空数组,联系时返回
E_RESOURCE_NOT_FOUND。 - 联系失败:记录到
contact_logs并返回E_RESOURCE_CONTACT_FAILED。 - 越权修改:非运营角色修改返回
E_FORBIDDEN。
11. 变更影响评估
- 新增资源需同步资源地图UI、推荐算法、埋点
resource_contact_attempt。 - 联系方式变更需通知相关预约系统。
- 优先级调整影响资源展示顺序。
12. 假设与待确认
- 假设联系记录存储在独立的
contact_logs集合;待确认是否需要内嵌联系方式点击统计。 - 待确认是否需要支持多语言资源名称和描述。
- 待确认资源审核流程和权限分配。