#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import os
import re

ROOT = os.path.expanduser('~/Desktop/Hermes输出-工作类')
acts = json.load(open(os.path.join(ROOT, '数据/daily_activities_mcp.json'), encoding='utf-8'))['items']


def sh(s, n=420):
    return re.sub(r'<[^>]+>', ' ', re.sub(r'\s+', ' ', str(s)))[:n]


for k in ['丹威', '雅为', '基灵', '陆军军医', '丽禾', '安可瑞', '瑞佰']:
    hit = [a for a in acts if k in str(a.get('field_5f20fc', '')) or k in str(a.get('name', ''))]
    hit.sort(key=lambda a: str(a.get('start_time', '')))
    print('\n' + '#' * 80)
    print('### %s 活动 %d 条' % (k, len(hit)))
    for a in hit[-10:]:
        print('  [%s] %s | %s | %s' % (a.get('start_time'), (a.get('owner') or {}).get('name_cn'),
                                       (a.get('field_76654e') or {}).get('label'), sh(a.get('name'), 50)))
        print('      ', sh(a.get('field_b99055'), 420))

# customer_360 集团口径核对
c360 = json.load(open(os.path.join(ROOT, '数据/customer_360.json'), encoding='utf-8'))
print('\n\n' + '=' * 80)
print('customer_360 updated_at', c360.get('updated_at'), 'groups', len(c360['groups']))
want = ['丽珠集团', '天隆集团', '东方基因集团', '佰奥莱博集团', '复星集团', '海尔施集团', '安瑞科集团']
for g in c360['groups']:
    if g['name'] in want:
        print('\n▶ %s | members=%s' % (g['name'], g.get('members')))
        print('   y2024=%s y2025=%s y2026=%s h2_2026=%s | sales=%s' % (g.get('y2024'), g.get('y2025'), g.get('y2026'), g.get('h2_2026'), g.get('sales')))
        for p in (g.get('top_products') or [])[:6]:
            print('     - %s %s %s' % (p.get('sku'), p.get('name', '')[:22], p.get('amt')))
