Browse Source

feat(web): 家庭工作台报告抽屉改为代传上传+解析流程(家庭预填/成员下拉/PDF上传/proxy-parse预览/proxy-confirm入库)+美化(空态/状态标签/统计) + TDD 7例(回归18例绿/构建通过)

Xiaogang Liao 2 days ago
parent
commit
ee2254aee9

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-6740b94bac24a12b9f1455fb88a7ded7bc884e33
+4ca36146e85399e87ea53022976e188f00960854

+ 1 - 1
cfc-web/package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "cfc-web",
   "name": "cfc-web",
-  "version": "1.0.2704",
+  "version": "1.0.2705",
   "private": true,
   "private": true,
   "scripts": {
   "scripts": {
     "dev": "vue-cli-service serve",
     "dev": "vue-cli-service serve",

+ 17 - 0
cfc-web/public/CHANGELOG-v1.0.md

@@ -4,6 +4,23 @@
 
 
 ---
 ---
 
 
+## v1.0.2705 (2026-11-23)
+
+### 新功能
+- 补齐spec P1-4/POI-1 分享有效期可配 coupon.share.expire-days(默认7,解析非法回退)+种子 + TDD(89例绿)
+- 华为Health Kit订阅回调端点 POST /healthkit/notifications(连通性测试返回204, 可选Secret验签HMAC-SHA256+Base64, 真实通知仅记日志待后续业务处理) + TDD 8例
+
+### Bug 修复
+- 分享/转赠放开所有券类型(去掉applicableTo=MEMBERSHIP限制,保留归属/AVAILABLE/ACTIVE/未过期校验) - 需求变更2026-11-23 + TDD(24例, coupon全量86例绿)
+- survey_records.template_id改为可空(HL-01健康阅卷source=health_review不绑定模板, 提交时templateId=null被MyBatis跳过致NOT NULL无默认值400) schema.sql+幂等迁移500+回归测试
+
+### 其他
+- - 后端21文件+1121行,前端6文件;小程序改动需微信发版(未含)
+- - prebuild 自动生成 .last_build_commit/package.json/CHANGELOG
+- - 部署验证:迁移499补录3订单+6提醒实测在库,API 4接口200,双前端200,ERROR0,jar md5一致
+- 
+
+
 ## v1.0.2704 (2026-11-20)
 ## v1.0.2704 (2026-11-20)
 
 
 ### 文档
 ### 文档

+ 18 - 1
cfc-web/public/CHANGELOG.md

@@ -1,6 +1,6 @@
 # 更新日志
 # 更新日志
 
 
-> 当前版本: v1.0.2704
+> 当前版本: v1.0.2705
 
 
 ## 历史版本
 ## 历史版本
 
 
@@ -8,6 +8,23 @@
 
 
 ---
 ---
 
 
+## v1.0.2705 (2026-11-23)
+
+### 新功能
+- 补齐spec P1-4/POI-1 分享有效期可配 coupon.share.expire-days(默认7,解析非法回退)+种子 + TDD(89例绿)
+- 华为Health Kit订阅回调端点 POST /healthkit/notifications(连通性测试返回204, 可选Secret验签HMAC-SHA256+Base64, 真实通知仅记日志待后续业务处理) + TDD 8例
+
+### Bug 修复
+- 分享/转赠放开所有券类型(去掉applicableTo=MEMBERSHIP限制,保留归属/AVAILABLE/ACTIVE/未过期校验) - 需求变更2026-11-23 + TDD(24例, coupon全量86例绿)
+- survey_records.template_id改为可空(HL-01健康阅卷source=health_review不绑定模板, 提交时templateId=null被MyBatis跳过致NOT NULL无默认值400) schema.sql+幂等迁移500+回归测试
+
+### 其他
+- - 后端21文件+1121行,前端6文件;小程序改动需微信发版(未含)
+- - prebuild 自动生成 .last_build_commit/package.json/CHANGELOG
+- - 部署验证:迁移499补录3订单+6提醒实测在库,API 4接口200,双前端200,ERROR0,jar md5一致
+- 
+
+
 ## v1.0.2704 (2026-11-20)
 ## v1.0.2704 (2026-11-20)
 
 
 ### 文档
 ### 文档

+ 43 - 0
cfc-web/src/__tests__/views/ReportDrawerProxy.contract.spec.js

@@ -0,0 +1,43 @@
+import { readFileSync } from 'fs'
+import { resolve } from 'path'
+
+// 契约:家庭工作台报告抽屉「手动新增」改为报告代传(上传PDF→解析→确认入库)
+// 需求:美化并调整后台报告(查看/手动新增)页面,手动新增走报告上传/解析流程
+const VUE_PATH = resolve(__dirname, '../../views/FamilyWorkbench.vue')
+const source = readFileSync(VUE_PATH, 'utf8')
+
+describe('FamilyWorkbench 报告抽屉代传流程', () => {
+  test('引入代传 API:proxyParseReport / proxyConfirmReport', () => {
+    expect(source).toMatch(/proxyParseReport/)
+    expect(source).toMatch(/proxyConfirmReport/)
+  })
+
+  test('报告对象成员下拉来自 getFamilyMemberList(家庭预填)', () => {
+    expect(source).toMatch(/getFamilyMemberList/)
+    expect(source).toMatch(/familyId/)
+  })
+
+  test('上传PDF文件选择(el-upload, accept .pdf)', () => {
+    expect(source).toMatch(/el-upload/)
+    expect(source).toMatch(/\.pdf/)
+  })
+
+  test('解析预览 + 确认入库两段式', () => {
+    expect(source).toMatch(/previewResult|parsePreview|解析预览/)
+    expect(source).toMatch(/handleConfirm|确认入库/)
+  })
+
+  test('已移除旧的简易手动新增表单(createFamilyReport / reportForm.personName)', () => {
+    expect(source).not.toMatch(/createFamilyReport/)
+    expect(source).not.toMatch(/reportForm\.personName/)
+  })
+
+  test('报告抽屉美化:空态 + 状态标签', () => {
+    expect(source).toMatch(/el-empty|暂无报告|暂无数据/)
+    expect(source).toMatch(/el-tag|StatusTag|statusTag/)
+  })
+
+  test('代传成功后刷新列表', () => {
+    expect(source).toMatch(/loadOverview\(\)/)
+  })
+})

+ 143 - 52
cfc-web/src/views/FamilyWorkbench.vue

@@ -95,23 +95,74 @@
       </el-table>
       </el-table>
     </el-drawer>
     </el-drawer>
 
 
-    <!-- 报告抽屉 -->
-    <el-drawer title="报告(查看 / 手动新增)" :visible.sync="reportDrawerVisible" size="65%">
-      <div class="mb-12">
-        <el-button type="primary" size="mini" @click="reportFormVisible = true">手动新增报告</el-button>
-      </div>
-      <div class="wb-summary" v-if="reportSummary.total !== undefined">
-        <span>总数 <b>{{ reportSummary.total }}</b></span>
-        <span>状态:<b v-for="(v, k) in reportSummary.byStatus" :key="k">{{ k }} {{ v }} </b></span>
-        <span>类型:<b v-for="(v, k) in reportSummary.byType" :key="k">{{ k }} {{ v }} </b></span>
+    <!-- 报告抽屉(查看 + 代传上传) -->
+    <el-drawer title="报告管理(查看 / 代传上传)" :visible.sync="reportDrawerVisible" size="65%">
+      <div class="report-drawer-body">
+        <!-- 代传上传:家庭已锁定为当前工作台家庭,仅选成员 -->
+        <el-card shadow="never" class="report-upload-card">
+          <div slot="header"><span class="report-sec-title">代传报告上传</span><span class="report-sec-hint">上传 PDF → 自动解析 → 确认入库</span></div>
+          <el-form :model="reportUpload" label-width="90px" size="small">
+            <el-form-item label="报告对象">
+              <el-select v-model="reportUpload.subjectId" placeholder="请选择家庭成员" filterable clearable class="report-full">
+                <el-option v-for="m in reportMembers" :key="m.id" :label="m.nickname || m.realName || ('成员'+m.id)" :value="m.id" />
+              </el-select>
+            </el-form-item>
+            <el-form-item label="报告文件">
+              <el-upload ref="reportUploader" action="" :auto-upload="false" :limit="1" accept=".pdf"
+                :on-change="onReportFileChange" :on-exceed="() => {}">
+                <el-button size="small" type="primary">选择 PDF 文件</el-button>
+                <span v-if="reportUpload.file" class="report-file-name">{{ reportUpload.file.name }}</span>
+                <div slot="tip" class="el-upload__tip">仅支持 PDF,不超过 50MB</div>
+              </el-upload>
+            </el-form-item>
+            <el-form-item label="备注">
+              <el-input v-model="reportUpload.note" type="textarea" :rows="2" placeholder="选填" class="report-full" />
+            </el-form-item>
+            <el-form-item>
+              <el-button type="primary" size="small" :loading="reportUploading" @click="submitReportUpload">上传并解析</el-button>
+            </el-form-item>
+          </el-form>
+
+          <!-- 解析预览 → 确认入库 -->
+          <div v-if="reportPreview" class="report-preview">
+            <div class="report-preview-head">
+              <span class="report-sec-title">解析结果预览</span>
+              <el-tag :type="reportPreview.needBind ? 'warning' : 'success'" size="mini">{{ reportPreview.needBind ? '待绑定成员' : '已匹配成员' }}</el-tag>
+            </div>
+            <el-descriptions :column="2" border size="mini">
+              <el-descriptions-item label="被检测人">{{ reportPreview.extractedName || '-' }}</el-descriptions-item>
+              <el-descriptions-item label="报告编号">{{ reportPreview.extractedReportNumber || '-' }}</el-descriptions-item>
+              <el-descriptions-item label="报告日期">{{ reportPreview.extractedReportDate || '-' }}</el-descriptions-item>
+              <el-descriptions-item label="综合分">
+                {{ reportPreview.payload && reportPreview.payload.summary ? reportPreview.payload.summary.overallScore : '-' }}
+              </el-descriptions-item>
+            </el-descriptions>
+            <div class="report-preview-actions">
+              <el-button size="small" @click="reportPreview = null">取消</el-button>
+              <el-button size="small" type="primary" :loading="reportConfirming" @click="confirmReportUpload">确认入库</el-button>
+            </div>
+          </div>
+        </el-card>
+
+        <!-- 统计概览 -->
+        <div class="wb-summary report-summary" v-if="reportSummary.total !== undefined">
+          <span>总数 <b>{{ reportSummary.total }}</b></span>
+          <span>状态:<b v-for="(v, k) in reportSummary.byStatus" :key="k"><el-tag size="mini" class="report-mini-tag">{{ k }} {{ v }}</el-tag> </b></span>
+          <span>类型:<b v-for="(v, k) in reportSummary.byType" :key="k"><el-tag size="mini" type="info" class="report-mini-tag">{{ k }} {{ v }}</el-tag> </b></span>
+        </div>
+
+        <!-- 报告列表 -->
+        <el-table :data="reportList" size="small" border>
+          <el-table-column prop="reportDate" label="日期" width="110"></el-table-column>
+          <el-table-column prop="personName" label="成员" width="90"></el-table-column>
+          <el-table-column prop="reportType" label="类型" width="110"></el-table-column>
+          <el-table-column prop="overallScore" label="综合分" width="80"></el-table-column>
+          <el-table-column label="状态" width="90">
+            <template slot-scope="{ row }"><el-tag size="mini" :type="reportStatusTagType(row.status)">{{ reportStatusLabel(row.status) }}</el-tag></template>
+          </el-table-column>
+          <template slot="empty"><el-empty description="暂无报告,可通过上方代传上传"></el-empty></template>
+        </el-table>
       </div>
       </div>
-      <el-table :data="reportList" size="small" border>
-        <el-table-column prop="reportDate" label="日期" width="110"></el-table-column>
-        <el-table-column prop="personName" label="成员" width="90"></el-table-column>
-        <el-table-column prop="reportType" label="类型" width="110"></el-table-column>
-        <el-table-column prop="overallScore" label="综合分" width="80"></el-table-column>
-        <el-table-column prop="status" label="状态" width="80"></el-table-column>
-      </el-table>
     </el-drawer>
     </el-drawer>
 
 
     <!-- CF值获取抽屉 -->
     <!-- CF值获取抽屉 -->
@@ -192,25 +243,6 @@
       </div>
       </div>
     </el-dialog>
     </el-dialog>
 
 
-    <!-- 报告手动新增 -->
-    <el-dialog title="手动新增报告" :visible.sync="reportFormVisible" width="520px">
-      <el-form :model="reportForm" label-width="100px" size="small">
-        <el-form-item label="成员姓名"><el-input v-model="reportForm.personName"></el-input></el-form-item>
-        <el-form-item label="报告类型">
-          <el-select v-model="reportForm.reportType" placeholder="报告类型">
-            <el-option label="体检" value="physical_exam"></el-option>
-            <el-option label="肠道菌群" value="gut_flora"></el-option>
-          </el-select>
-        </el-form-item>
-        <el-form-item label="报告日期"><el-date-picker v-model="reportForm.reportDate" type="date" value-format="yyyy-MM-dd"></el-date-picker></el-form-item>
-        <el-form-item label="综合分"><el-input-number v-model="reportForm.overallScore" :min="0"></el-input-number></el-form-item>
-        <el-form-item label="备注"><el-input type="textarea" v-model="reportForm.remark"></el-input></el-form-item>
-      </el-form>
-      <div slot="footer">
-        <el-button size="small" @click="reportFormVisible = false">取消</el-button>
-        <el-button size="small" type="primary" @click="submitReportForm">保存</el-button>
-      </div>
-    </el-dialog>
   </div>
   </div>
 </template>
 </template>
 
 
@@ -220,14 +252,13 @@ import {
   getFamilyWorkbench,
   getFamilyWorkbench,
   getFamilyMessages,
   getFamilyMessages,
   getConversationMessages,
   getConversationMessages,
-  createFamilyReport,
   createFamilyTask,
   createFamilyTask,
   updateFamilyTask,
   updateFamilyTask,
   createFamilyPlan,
   createFamilyPlan,
   updateFamilyPlan,
   updateFamilyPlan,
   getFamilyCfLogs
   getFamilyCfLogs
 } from "@/api/familyWorkbench"
 } from "@/api/familyWorkbench"
-import { getFamilyTasks, getFamilyOverview } from "@/api/admin"
+import { getFamilyTasks, getFamilyOverview, getFamilyMemberList, proxyParseReport, proxyConfirmReport } from "@/api/admin"
 import ChildrenPanel from '@/views/admin/ChildrenPanel.vue'
 import ChildrenPanel from '@/views/admin/ChildrenPanel.vue'
 import PointsPanel from '@/views/admin/PointsPanel.vue'
 import PointsPanel from '@/views/admin/PointsPanel.vue'
 import WishesPanel from '@/views/admin/WishesPanel.vue'
 import WishesPanel from '@/views/admin/WishesPanel.vue'
@@ -268,8 +299,12 @@ export default {
       planForm: {},
       planForm: {},
       reportDrawerVisible: false,
       reportDrawerVisible: false,
       reportList: [],
       reportList: [],
-      reportFormVisible: false,
-      reportForm: {},
+      // 报告抽屉内嵌代传流程(上传PDF→解析→确认入库)
+      reportMembers: [],
+      reportUpload: { subjectId: null, file: null, note: "" },
+      reportPreview: null,
+      reportUploading: false,
+      reportConfirming: false,
       cfDrawerVisible: false,
       cfDrawerVisible: false,
       cfLogList: [],
       cfLogList: [],
       cfLogTotal: 0,
       cfLogTotal: 0,
@@ -365,6 +400,7 @@ export default {
       } else if (key === "reports") {
       } else if (key === "reports") {
         this.reportDrawerVisible = true
         this.reportDrawerVisible = true
         this.loadOverview()
         this.loadOverview()
+        this.loadReportMembers()
       } else if (key === "messages") {
       } else if (key === "messages") {
         this.messageDrawerVisible = true
         this.messageDrawerVisible = true
         this.loadConversations(1)
         this.loadConversations(1)
@@ -442,26 +478,69 @@ export default {
         this.$message.error(error.message || "保存失败")
         this.$message.error(error.message || "保存失败")
       }
       }
     },
     },
-    async submitReportForm() {
+    // 报告代传:加载当前家庭成员作为报告对象下拉
+    async loadReportMembers() {
       try {
       try {
-        const data = {
-          personName: this.reportForm.personName,
-          reportType: this.reportForm.reportType,
-          overallScore: this.reportForm.overallScore,
-          remark: this.reportForm.remark
-        }
-        if (this.reportForm.reportDate) {
-          data.reportDate = new Date(this.reportForm.reportDate + "T00:00:00").toISOString()
+        const res = await getFamilyMemberList({ familyId: this.familyId })
+        this.reportMembers = (res && res.data) || []
+      } catch (error) {
+        this.reportMembers = []
+      }
+    },
+    onReportFileChange(file) {
+      this.reportUpload.file = file && file.raw ? file.raw : null
+    },
+    // 报告代传第一步:上传PDF → 解析预览
+    async submitReportUpload() {
+      if (!this.reportUpload.subjectId) { this.$message.warning("请选择报告对象"); return }
+      if (!this.reportUpload.file) { this.$message.warning("请选择 PDF 文件"); return }
+      this.reportUploading = true
+      try {
+        const res = await proxyParseReport({
+          familyId: this.familyId,
+          subjectId: this.reportUpload.subjectId,
+          file: this.reportUpload.file,
+          note: this.reportUpload.note
+        })
+        if (res && res.code === 200 && res.data) {
+          this.reportPreview = res.data
+          this.$refs.reportUploader && this.$refs.reportUploader.clearFiles()
+          this.reportUpload.file = null
+        } else {
+          this.$message.error((res && res.message) || "解析失败")
         }
         }
-        await createFamilyReport(this.familyId, data)
-        this.$message.success("报告已创建")
-        this.reportFormVisible = false
+      } catch (error) {
+        this.$message.error((error && error.message) || "解析失败,请重试")
+      } finally {
+        this.reportUploading = false
+      }
+    },
+    // 报告代传第二步:确认入库 → 刷新列表与统计
+    async confirmReportUpload() {
+      if (!this.reportPreview || !this.reportPreview.draftId) { this.$message.warning("解析结果无效,请重新上传"); return }
+      this.reportConfirming = true
+      try {
+        await proxyConfirmReport({ draftId: this.reportPreview.draftId, subjectId: this.reportUpload.subjectId })
+        this.$message.success("报告已入库")
+        this.reportPreview = null
+        this.reportUpload.note = ""
         this.loadOverview()
         this.loadOverview()
         this.loadWorkbench()
         this.loadWorkbench()
       } catch (error) {
       } catch (error) {
-        this.$message.error(error.message || "创建失败")
+        this.$message.error((error && error.message) || "入库失败")
+      } finally {
+        this.reportConfirming = false
       }
       }
     },
     },
+    // 报告状态美化:中文标签 + 标签颜色
+    reportStatusLabel(status) {
+      const map = { pending: "待处理", completed: "已完成", processing: "解析中", failed: "失败", reviewed: "已审核" }
+      return map[status] || status || "未知"
+    },
+    reportStatusTagType(status) {
+      const map = { pending: "warning", completed: "success", processing: "info", failed: "danger", reviewed: "success" }
+      return map[status] || "info"
+    },
     async loadConversations(page) {
     async loadConversations(page) {
       this.conversationPage = page
       this.conversationPage = page
       try {
       try {
@@ -513,4 +592,16 @@ export default {
 .message-meta { font-size: 12px; color: var(--adm-text-45); }
 .message-meta { font-size: 12px; color: var(--adm-text-45); }
 .message-content { margin-top: 4px; white-space: pre-wrap; word-break: break-all; }
 .message-content { margin-top: 4px; white-space: pre-wrap; word-break: break-all; }
 .pagination-right-mt12 { margin-top: 12px; text-align: right; }
 .pagination-right-mt12 { margin-top: 12px; text-align: right; }
+/* 报告抽屉(代传上传 + 美化) */
+.report-drawer-body { padding-right: 8px; }
+.report-upload-card { margin-bottom: 16px; }
+.report-sec-title { font-weight: 600; color: var(--adm-text-88); }
+.report-sec-hint { font-size: 12px; color: var(--adm-text-45); margin-left: 12px; }
+.report-full { width: 100%; }
+.report-file-name { margin-left: 10px; font-size: 12px; color: #409eff; }
+.report-preview { margin-top: 12px; padding: 12px; background: #f8f9fb; border-radius: 4px; }
+.report-preview-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
+.report-preview-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
+.report-summary { align-items: center; }
+.report-mini-tag { margin: 0 2px; }
 </style>
 </style>