Kaynağa Gözat

docs(health): 用户115高尿酸 食材推荐指数-50 + 健康方案/任务(含后续修正)执行记录

Xiaogang Liao 5 gün önce
ebeveyn
işleme
ac128092db

+ 65 - 0
docs/2026-11-15-用户115-高尿酸-食材指数调整与健康方案-执行报告.md

@@ -0,0 +1,65 @@
+# 用户115(李志清)高尿酸健康管理 — 生产库执行报告
+
+| 项 | 内容 |
+|---|---|
+| 执行日期 | 2026-11-15(2026-11-16 后续修正) |
+| 操作人 | AI 助手(经用户确认方案后执行) |
+| 对象 | 用户115(李志清,family_members.id=75,family_id=119) |
+| 依据报告 | health_reports.id=64(gut_flora,2026-11-13,报告编号 555711538) |
+| 数据库 | 生产库 zxyj(JD Cloud RDS) |
+
+## 一、食材推荐指数调整(-50)
+
+**口径**:沿用系统 disease_intake_limits 痛风禁令口径 —— 动物内脏 + 部分海鲜 + 浓肉汤 + 含糖饮料(果汁)。
+
+**操作**:food_recommend_idx(user_id=115)中 25 种高尿酸食材 index_score = index_score - 50,逐条写 food_recommend_idx_log(change_reason=高尿酸健康管理调整:痛风禁令口径高尿酸食材(动物内脏/部分海鲜/浓肉汤/含糖饮料),推荐指数-50)。
+
+| 类别 | 食材(减50后) |
+|---|---|
+| 动物内脏(5) | 猪脑-80、猪肝-36、鹅肝-41、鸡心-42、鸡肝-44 |
+| 部分海鲜(15) | 鱼子酱-85、虾-58、蛤蜊-57、扇贝-52、贻贝-47、鲍鱼-48、蟹-40、龙虾-50、小龙虾-33、牡蛎-33、章鱼-38、鱿鱼-39、墨鱼-46、沙丁鱼-19、凤尾鱼-37 |
+| 浓肉汤(2) | 牛肉汤-50、鸡汤-61 |
+| 含糖饮料(3) | 苹果汁-72、橙汁7、橙菠萝汁-25 |
+
+> **后续修正(2026-11-16)**:猪头肉(原-50 后 -84)按用户要求撤销调整 —— 猪头肉为面肉、非动物内脏,已还原为 -34,并写"口径修正:猪头肉非动物内脏(面肉),撤销高尿酸-50调整"逆转日志(-84 → -34)。
+
+**验证**:剩余 25 条日志 previous - new = 50 精确;food_recommend_idx 总数 224 不变。
+
+> 说明:属一次性数据调整,未改 foods.score;报告重算时将按最新报告重建(用户确认的语义)。
+
+## 二、健康方案 + 任务创建
+
+**方案**:health_plans.id=30(family 119 / member 75 / status=published / plan_type=health_plan / total_days=14)
+- plan_content:报告解读(菌群 整体51、平衡35、多样性37、有益菌22、有害菌65、核心菌属87、慢性病风险46、营养73)+ 初步方案
+- plan_json:结构化 sections(12 条任务意图;服药任务 action_type=use)
+
+**任务**:tasks 12 条(source_type=health_plan,source_id=30)
+
+| id | 任务 | 类型 | 前置 |
+|---|---|---|---|
+| 5361 | 牙科洗牙 + 牙周检查 | 打卡/一次性 | — |
+| 5362 | 空腹血糖 + HbA1c | 打卡/一次性 | — |
+| 5363 | 血尿酸 + 肾功能(肌酐/eGFR) | 打卡/一次性 | — |
+| 5364 | 购买:PHGG瓜尔豆益生元 | 购买(cart 商品55) | — |
+| 5365 | 购买:AKK + 乳杆菌 | 购买(无平台商品) | — |
+| 5366 | 购买:Enagic 姜黄 | 购买(cart 商品15) | — |
+| 5367 | 购买:EPA + DHA | 购买(cart 商品79) | — |
+| 5368 | 每天饮用2.5-3升还原水 | 饮食/每日 | — |
+| 5369 | 服用:PHGG瓜尔豆益生元(每日) | **使用**/每日 | 5364 |
+| 5370 | 服用:AKK + 乳杆菌(每日) | **使用**/每日 | 5365 |
+| 5371 | 服用:Enagic 姜黄(每日) | **使用**/每日 | 5366 |
+| 5372 | 服用:EPA + DHA(每日) | **使用**/每日 | 5367 |
+
+> **后续修正(2026-11-16)**:4 条服药任务由"打卡任务/checkin"调整为"使用任务/use"(系统 D6 购买→使用依赖链语义),plan_json 同步。
+
+**"每个购买任务完成后,开始服药任务"**:服药任务各自 prerequisite_task_id 绑定对应购买任务(5369→5364、5370→5365、5371→5366、5372→5367)。
+
+## 三、回滚
+
+执行前已建快照备份表(可一键恢复):food_recommend_idx_bak_20261115、food_recommend_idx_log_bak_20261115、health_plans_bak_20261115、tasks_bak_20261115。
+
+## 四、脚本与文档
+
+- docs/scripts/2026-11-15-user115-uric-plan.py(dry-run / verify / apply,幂等防重复)
+- docs/scripts/2026-11-16-user115-followup.py(后续修正:撤销猪头肉 + 服药任务转使用任务)
+- 本报告

+ 318 - 0
docs/scripts/2026-11-15-user115-uric-plan.py

@@ -0,0 +1,318 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+用户115(李志清 / family_members.id=75 / family_id=119 / user_id=115)高尿酸健康管理数据操作
+
+Part A: food_recommend_idx 高尿酸食材推荐指数 -50(痛风禁令口径 26 种)+ 变更日志
+Part B: health_plans 健康方案(报告解读 + 初步方案)+ 12 条 tasks(购买任务为服药任务前置)
+
+操作对象:生产库 zxyj(JD Cloud RDS)。执行前已建立快照备份表(可回滚)。
+"""
+import pymysql, json, datetime, sys
+
+DB = dict(host='mysql-internet-cn-north-1-23feae22680e4dfa.rds.jdcloud.com',
+          port=3306, user='cfc', password='cfc@1314', database='zxyj', charset='utf8mb4')
+
+USER_ID, MEMBER_ID, FAMILY_ID, REPORT_ID = 115, 75, 119, 64
+TODAY = '2026-11-15'
+STAMP = TODAY.replace('-', '')
+
+# 痛风禁令口径(disease_intake_limits 痛风规则):动物内脏 + 部分海鲜 + 浓肉汤 + 含糖饮料(果汁)
+HIGH_UA_FOOD_IDS = [
+    7526, 7522, 7525, 7536, 7532, 7535,                                        # 动物内脏
+    7449, 7444, 7445, 7437, 7447, 7452, 7446, 7465, 7436, 7440, 7443, 7450,
+    7433, 7463, 7432,                                                          # 部分海鲜
+    7517, 7533,                                                                # 浓肉汤
+    7491, 7480, 7482,                                                          # 含糖饮料(果汁)
+]
+CHANGE_REASON = ('高尿酸健康管理调整:痛风禁令口径高尿酸食材'
+                 '(动物内脏/部分海鲜/浓肉汤/含糖饮料),推荐指数-50')
+
+APPLY = '--apply' in sys.argv
+VERIFY = '--verify' in sys.argv
+
+conn = pymysql.connect(**DB)
+cur = conn.cursor()
+
+def q(sql, args=None):
+    cur.execute(sql, args)
+    return cur.fetchall()
+
+def run(sql, args=None):
+    cur.execute(sql, args)
+    return cur.rowcount
+
+# ---------------------------------------------------------------- 快照备份
+def backup():
+    for tbl, where in [
+        ('food_recommend_idx', 'user_id=%d' % USER_ID),
+        ('food_recommend_idx_log', 'user_id=%d' % USER_ID),
+        ('health_plans', 'family_id=%d' % FAMILY_ID),
+        ('tasks', 'family_id=%d' % FAMILY_ID),
+    ]:
+        bak = '%s_bak_%s' % (tbl, STAMP)
+        run('DROP TABLE IF EXISTS %s' % bak)
+        run('CREATE TABLE %s AS SELECT * FROM %s WHERE %s' % (bak, tbl, where))
+        n = q('SELECT COUNT(*) FROM %s' % bak)[0][0]
+        print('[backup] %s -> %s (%d rows)' % (tbl, bak, n))
+
+# ---------------------------------------------------------------- Part A
+def part_a():
+    in_clause = ','.join(str(int(x)) for x in HIGH_UA_FOOD_IDS)  # 仅整数,安全内联
+    rows = q('SELECT id, food_id, food_name, index_score FROM food_recommend_idx '
+             'WHERE user_id=%s AND food_id IN (' + in_clause + ')',
+             (USER_ID,))
+    got = {r[1]: r for r in rows}
+    missing = [x for x in HIGH_UA_FOOD_IDS if x not in got]
+    print('[A] 命中 %d/%d 种;缺失: %s' % (len(rows), len(HIGH_UA_FOOD_IDS), missing or '无'))
+    if missing:
+        # 缺失说明 ID 漂移,安全起见中止
+        print('[A] ABORT: 存在未命中的食材ID,请核对后重跑')
+        return False
+
+    changed = []
+    for r in rows:
+        idx_id, food_id, food_name, old = r
+        new = old - 50
+        changed.append((idx_id, food_id, food_name, old, new))
+        print('[A] %s: %d -> %d' % (food_name, old, new))
+
+    if APPLY or VERIFY:
+        for idx_id, food_id, food_name, old, new in changed:
+            run('UPDATE food_recommend_idx SET index_score=%s WHERE id=%s', (new, idx_id))
+            run('INSERT INTO food_recommend_idx_log '
+                '(user_id, food_id, food_name, previous_index, new_index, health_report_id, change_reason, changed_at) '
+                'VALUES (%s,%s,%s,%s,%s,%s,%s,%s)',
+                (USER_ID, food_id, food_name, old, new, REPORT_ID, CHANGE_REASON, datetime.datetime.now()))
+        print('[A] 已更新 %d 条 index_score 并写 %d 条变更日志' % (len(changed), len(changed)))
+    else:
+        print('[A] DRY-RUN 未落库')
+    return True
+
+# ---------------------------------------------------------------- Part B
+def plan_content_md():
+    return """# 李志清|肠道菌群报告解读与高尿酸初步干预方案
+
+> 依据:肠道菌群检测报告(报告编号 555711538 / 报告ID 64 / 2026-11-13)
+> 成员:李志清(家庭成员ID 75)|已知血液学情况:**血尿酸偏高**(血检结果,非本报告内容)
+
+## 一、报告解读
+
+### 1.1 报告评分总览
+
+| 维度 | 得分 | 判读 |
+|---|---|---|
+| 整体评分 | 51 | 中等偏低 |
+| 肠健康 | 51 | 需干预 |
+| 慢性病风险 | 46 | 偏高 |
+| 营养 | 73 | 相对良好 |
+| 菌群平衡 | 35 | 偏低 |
+| 菌群多样性 | 37 | 偏低 |
+| 有益菌 | 22 | 明显不足 |
+| 有害菌 | 65 | 偏高 |
+| 核心菌属 | 87 | 良好 |
+
+### 1.2 解读要点
+
+1. **菌群失衡**:有益菌 22 分(明显不足)、有害菌 65 分(偏高),平衡分仅 35 → 肠道定植能力弱,有害代谢产物(炎症、代谢负担)易累积。
+2. **多样性不足**:多样性 37 分,菌株类型偏单一,饮食结构单一进一步限制菌群可塑性 → 需要"喂菌 + 补菌"两条腿同时走。
+3. **核心菌属基础尚可**:核心菌属 87 分 → 干预重点不是重建菌群,而是补上"养料(益生元)+ 菌株(益生菌)",把多样性与有益菌占比拉起来。
+4. **慢性病风险偏高**:慢性病风险 46 分,与有害菌偏高、营养代谢负担相关 → 炎症与代谢管理需同步进行。
+5. **尿酸偏高(外部已知)**:血尿酸偏高压缩了"低嘌呤"饮食空间,且与肠道菌群代谢相互影响 → 本方案饮食端已按痛风禁令口径下调高尿酸食材推荐指数(-50),并安排血尿酸 + 肾功能复查以确认安全边界。
+
+### 1.3 干预主线
+
+**喂菌(PHGG 瓜尔豆益生元)→ 补菌(AKK + 乳杆菌)→ 抗炎(Enagic 姜黄)→ 优杆菌(EPA + DHA)→ 生活方式(还原水 2.5–3 L/日 + 体检排查)**
+
+## 二、初步方案
+
+### 2.1 马上要做(第 1 周内完成)
+
+| # | 事项 | 类型 | 说明 |
+|---|---|---|---|
+| 1 | 牙科洗牙 + 牙周检查 | 体检 | 排查口腔慢性炎症源(全身炎症与代谢负担的常见来源) |
+| 2 | 空腹血糖 + HbA1c | 体检 | 建立血糖基线(菌群失衡与胰岛素敏感性相关) |
+| 3 | 血尿酸 + 肾功能(肌酐/eGFR) | 体检 | 量化尿酸水平并评估肾功能,作为饮食与补充剂的安全边界 |
+| 4 | 购买 PHGG 瓜尔豆益生元 | 购买 | 喂菌:为肠道菌群提供可利用的益生元底物 |
+| 5 | 购买 AKK + 乳杆菌 | 购买 | 补菌:补充有益菌株(平台暂无含 AKK 菌株商品,先按补菌方向备货) |
+| 6 | 购买 Enagic 姜黄 | 购买 | 抗炎:针对有害菌偏高带来的炎症负担 |
+| 7 | 购买 EPA + DHA | 购买 | 优杆菌:支持核心菌属与肠膜完整性 |
+| 8 | 每天 2.5–3 升还原水 | 每日 | 分次饮用,增加饮水与排泄,帮助冲刷嘌呤代谢产物 |
+
+### 2.2 购买完成后的服药任务
+
+每个购买任务完成后,自动开始对应的每日服药任务(PHGG 益生元 / AKK + 乳杆菌 / Enagic 姜黄 / EPA + DHA),具体用法按产品说明执行。
+"""
+
+def plan_json_obj():
+    tasks = [
+        dict(action_type='checkin', title='牙科洗牙 + 牙周检查', dimension='body', frequency='once',
+             notes='排查口腔慢性炎症源'),
+        dict(action_type='checkin', title='空腹血糖 + HbA1c', dimension='body', frequency='once',
+             notes='建立血糖基线'),
+        dict(action_type='checkin', title='血尿酸 + 肾功能(肌酐/eGFR)', dimension='body', frequency='once',
+             notes='量化尿酸水平并评估肾功能'),
+        dict(action_type='buy', title='购买:PHGG瓜尔豆益生元', dimension='wealth', frequency='once',
+             notes='喂菌:为肠道菌群提供可利用益生元底物'),
+        dict(action_type='buy', title='购买:AKK + 乳杆菌', dimension='wealth', frequency='once',
+             notes='补菌:补充有益菌株'),
+        dict(action_type='buy', title='购买:Enagic 姜黄', dimension='wealth', frequency='once',
+             notes='抗炎:针对有害菌偏高带来的炎症负担'),
+        dict(action_type='buy', title='购买:EPA + DHA', dimension='wealth', frequency='once',
+             notes='优杆菌:支持核心菌属与肠膜完整性'),
+        dict(action_type='diet', title='每天饮用2.5-3升还原水', dimension='body', frequency='daily',
+             notes='分次饮用,帮助冲刷嘌呤代谢产物'),
+        dict(action_type='checkin', title='服用:PHGG瓜尔豆益生元(每日)', dimension='body', frequency='daily',
+             notes='按产品说明每日服用'),
+        dict(action_type='checkin', title='服用:AKK + 乳杆菌(每日)', dimension='body', frequency='daily',
+             notes='按产品说明每日服用'),
+        dict(action_type='checkin', title='服用:Enagic 姜黄(每日)', dimension='body', frequency='daily',
+             notes='按产品说明每日服用'),
+        dict(action_type='checkin', title='服用:EPA + DHA(每日)', dimension='body', frequency='daily',
+             notes='按产品说明每日服用'),
+    ]
+    return {
+        'overview': ('依据 2026-11-13 肠道菌群检测报告(报告ID 64):整体 51 / 有益菌 22(不足)/ '
+                     '有害菌 65(偏高)/ 多样性 37 / 核心菌属 87;已知血尿酸偏高。'
+                     '干预主线:喂菌 + 补菌 + 抗炎 + 优杆菌 + 还原水生活方式。'),
+        'sections': [
+            {'key': 'diet', 'title': '报告解读与初步干预方案',
+             'content': '有益菌不足、有害菌偏高、多样性不足,需喂菌/补菌;已知尿酸偏高,饮食端已下调高尿酸食材推荐指数。',
+             'items': [], 'tasks': tasks},
+        ],
+        'abnormal_indicators': [
+            {'member': '李志清', 'indicator': '有益菌', 'value': '22', 'unit': '分'},
+            {'member': '李志清', 'indicator': '有害菌', 'value': '65', 'unit': '分'},
+            {'member': '李志清', 'indicator': '菌群多样性', 'value': '37', 'unit': '分'},
+            {'member': '李志清', 'indicator': '血尿酸', 'value': '偏高', 'unit': ''},
+        ],
+        'knowledge_sources': [],
+    }
+
+def part_b():
+    # 幂等:family 119 已有同名方案则中止
+    dup = q('SELECT id FROM health_plans WHERE family_id=%s AND goal LIKE %s',
+            (FAMILY_ID, '%李志清%肠道菌群%'))
+    if dup:
+        print('[B] ABORT: 已存在方案 id=%s,中止以防重复' % dup[0][0])
+        return
+
+    now = datetime.datetime.now()
+    today_end = now.replace(hour=23, minute=59, second=59, microsecond=0)
+    plan_end = (now + datetime.timedelta(days=14)).replace(hour=23, minute=59, second=59, microsecond=0)
+
+    content = plan_content_md()
+    pj = json.dumps(plan_json_obj(), ensure_ascii=False)
+
+    # 1) health_plans
+    run('INSERT INTO health_plans '
+        '(family_id, member_ids, dimensions, goal, plan_content, member_name, created_at, updated_at, plan_json, status, total_days, plan_type) '
+        'VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
+        (FAMILY_ID, str(MEMBER_ID), 'body,action',
+         '基于2026-11-13肠道菌群检测报告的解读与高尿酸初步干预方案',
+         content, '李志清', now, now, pj, 'published', 14, 'health_plan'))
+    plan_id = q('SELECT LAST_INSERT_ID()')[0][0]
+    print('[B] health_plans id=%s' % plan_id)
+
+    # 2) 任务行字段
+    def base_row(**kw):
+        row = dict(family_id=FAMILY_ID, family_member_id=MEMBER_ID, child_id=MEMBER_ID,
+                   creator_id=USER_ID, executor_type='child', executor_id=MEMBER_ID,
+                   source_type='health_plan', source_id=plan_id,
+                   need_review=0, review_by_category=0, status='pending',
+                   member_only=0, is_flow_task=1, dimension_code='body',
+                   is_daily_progress=0, duration=0, is_template=0,
+                   task_type=None, repeat_type='none', frequency=None,
+                   deadline=None, prerequisite_task_id=None,
+                   action_type=None, action_config=None, complete_types=None,
+                   created_at=now, updated_at=now, points=10)
+        row.update(kw)
+        return row
+
+    def insert_task(row):
+        cols = list(row.keys())
+        ph = ','.join(['%s'] * len(cols))
+        run('INSERT INTO tasks (%s) VALUES (%s)' % (','.join(cols), ph),
+            tuple(row[c] for c in cols))
+        return q('SELECT LAST_INSERT_ID()')[0][0]
+
+    # 2a) 体检 3(一次性)
+    exam_titles = [
+        ('牙科洗牙 + 牙周检查', '排查口腔慢性炎症源(全身炎症与代谢负担常见来源)'),
+        ('空腹血糖 + HbA1c', '建立血糖基线(菌群失衡与胰岛素敏感性相关)'),
+        ('血尿酸 + 肾功能(肌酐/eGFR)', '量化尿酸水平并评估肾功能,作为饮食与补充剂安全边界'),
+    ]
+    for title, desc in exam_titles:
+        tid = insert_task(base_row(title=title, description=desc, points=10,
+                                   category='打卡任务', task_type='onetime', repeat_type='none',
+                                   frequency=None, is_template=0, deadline=today_end, action_type='checkin'))
+        print('[B] 体检任务 id=%s: %s' % (tid, title))
+
+    # 2b) 购买 4(一次性,category=购买任务)
+    purchases = [
+        ('购买:PHGG瓜尔豆益生元', 55, '瓜尔纤维', '喂菌:为肠道菌群提供可利用益生元底物'),
+        ('购买:AKK + 乳杆菌', None, '益生菌', '补菌:补充有益菌株(平台暂无含AKK菌株商品)'),
+        ('购买:Enagic 姜黄', 15, '姜黄', '抗炎:针对有害菌偏高带来的炎症负担'),
+        ('购买:EPA + DHA', 79, '鱼油', '优杆菌:支持核心菌属与肠膜完整性'),
+    ]
+    purchase_ids = []
+    for title, product_id, cat, desc in purchases:
+        row = base_row(title=title, description=desc + '(方案ID ' + str(plan_id) + ',品类:' + cat + ')',
+                       points=10, category='购买任务', task_type='onetime', repeat_type='none',
+                       frequency=None, is_template=0, deadline=today_end)
+        if product_id is not None:
+            row['action_type'] = 'cart'
+            row['action_config'] = json.dumps({'productId': product_id, 'quantity': 1,
+                                               'planId': plan_id, 'category': cat}, ensure_ascii=False)
+        tid = insert_task(row)
+        purchase_ids.append(tid)
+        print('[B] 购买任务 id=%s: %s (product=%s)' % (tid, title, product_id or '无'))
+
+    # 2c) 饮水 1(每日)
+    wtid = insert_task(base_row(title='每天饮用2.5-3升还原水',
+                                description='分次饮用,增加饮水与排泄,帮助冲刷嘌呤代谢产物',
+                                points=5, category='饮食任务', task_type='recurring',
+                                repeat_type='daily', frequency='daily', is_template=1,
+                                deadline=plan_end, action_type='diet'))
+    print('[B] 饮水任务 id=%s: 每天2.5-3升还原水' % wtid)
+
+    # 2d) 服药 4(每日,前置=对应购买任务)
+    meds = [
+        ('服用:PHGG瓜尔豆益生元(每日)', '按产品说明每日服用,餐后为佳', 0),
+        ('服用:AKK + 乳杆菌(每日)', '按产品说明每日服用', 1),
+        ('服用:Enagic 姜黄(每日)', '按产品说明每日服用,抗炎方向', 2),
+        ('服用:EPA + DHA(每日)', '按产品说明每日服用,优杆菌方向', 3),
+    ]
+    for title, desc, pi in meds:
+        tid = insert_task(base_row(title=title, description=desc, points=5,
+                                   category='打卡任务', task_type='recurring',
+                                   repeat_type='daily', frequency='daily', is_template=1,
+                                   deadline=plan_end, action_type='checkin',
+                                   prerequisite_task_id=purchase_ids[pi]))
+        print('[B] 服药任务 id=%s: %s (prereq=%s)' % (tid, title, purchase_ids[pi]))
+
+    print('[B] 方案ID=%s,共生成 12 条任务' % plan_id)
+
+# ---------------------------------------------------------------- main
+print('=== 用户115 高尿酸健康管理 ===')
+if APPLY:
+    print('模式: APPLY')
+    backup()
+    ok = part_a()
+    if ok:
+        part_b()
+        conn.commit()
+        print('[main] 已提交')
+elif VERIFY:
+    print('模式: VERIFY(事务内执行+回滚,不落库)')
+    ok = part_a()
+    if ok:
+        part_b()
+    conn.rollback()
+    print('[main] VERIFY 已回滚,未持久化任何数据')
+else:
+    print('模式: DRY-RUN')
+    part_a()
+    print('[B] DRY-RUN 未执行方案/任务创建')
+print('=== 完成 ===')
+conn.close()

+ 75 - 0
docs/scripts/2026-11-16-user115-followup.py

@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""用户115 高尿酸 后续修正
+① 撤销 猪头肉(7522) 的 -50(口径:猪头肉为面肉,非动物内脏)→ 还原 -34 + 写逆转日志
+② 服药任务 5369-5372:category 打卡任务→使用任务,action_type checkin→use;同步 plan_json
+"""
+import pymysql, json, datetime
+
+DB = dict(host='mysql-internet-cn-north-1-23feae22680e4dfa.rds.jdcloud.com',
+          port=3306, user='cfc', password='cfc@1314', database='zxyj', charset='utf8mb4')
+USER_ID, MEMBER_ID, FAMILY_ID, REPORT_ID = 115, 75, 119, 64
+PLAN_ID = 30
+MED_TASK_IDS = [5369, 5370, 5371, 5372]
+
+conn = pymysql.connect(**DB)
+cur = conn.cursor()
+
+def q(sql, args=None):
+    cur.execute(sql, args)
+    return cur.fetchall()
+
+def run(sql, args=None):
+    cur.execute(sql, args)
+    return cur.rowcount
+
+now = datetime.datetime.now()
+
+# ---------- ① 撤销猪头肉 -50 ----------
+rows = q('SELECT id, food_id, food_name, index_score FROM food_recommend_idx WHERE user_id=%s AND food_id=7522', (USER_ID,))
+for r in rows:
+    idx_id, food_id, food_name, cur_score = r
+    if cur_score == -84:
+        run('UPDATE food_recommend_idx SET index_score=%s WHERE id=%s', (-34, idx_id))
+        run('INSERT INTO food_recommend_idx_log '
+            '(user_id, food_id, food_name, previous_index, new_index, health_report_id, change_reason, changed_at) '
+            'VALUES (%s,%s,%s,%s,%s,%s,%s,%s)',
+            (USER_ID, food_id, food_name, cur_score, -34, REPORT_ID,
+             '口径修正:猪头肉非动物内脏(面肉),撤销高尿酸-50调整', now))
+        print('[1] 猪头肉 %s -> -34(已撤销)' % food_name)
+    elif cur_score == -34:
+        print('[1] 猪头肉已是 -34,无需撤销')
+    else:
+        print('[1] 猪头肉当前指数异常: %s,跳过' % cur_score)
+
+# ---------- ② 服药任务 → 使用任务 ----------
+if not MED_TASK_IDS:
+    print('[2] 无服药任务ID,跳过')
+else:
+    ph = ','.join(str(x) for x in MED_TASK_IDS)
+    b = q('SELECT id, title, category, action_type FROM tasks WHERE id IN (%s)' % ph)
+    if len(b) != 4:
+        print('[2] 命中 %d 条服药任务(预期4):%s' % (len(b), [x[0] for x in b]))
+    for tid, title, cat, act in b:
+        run('UPDATE tasks SET category=%s, action_type=%s WHERE id=%s', ('使用任务', 'use', tid))
+        print('[2] 任务 %s「%s」: %s/%s -> 使用任务/use' % (tid, title, cat, act))
+    # 同步 plan_json
+    pj = q('SELECT plan_json FROM health_plans WHERE id=%s', (PLAN_ID,))[0][0]
+    root = pj if isinstance(pj, dict) else json.loads(pj)
+    changed = 0
+    for sec in root.get('sections', []):
+        for t in sec.get('tasks', []):
+            if t.get('title', '').startswith('服用:'):
+                if t.get('action_type') != 'use':
+                    t['action_type'] = 'use'
+                    changed += 1
+    if changed:
+        run('UPDATE health_plans SET plan_json=%s, updated_at=%s WHERE id=%s',
+            (json.dumps(root, ensure_ascii=False), now, PLAN_ID))
+        print('[2] plan_json 已同步 %d 条服药任务 action_type -> use' % changed)
+    else:
+        print('[2] plan_json 无需变更')
+
+conn.commit()
+print('=== 完成 ===')
+conn.close()