Files
opc/backend/handlers/tools.go
T
小K a5692bfd7d feat: OPC 平台初版(Go+PG backend / Vue frontend)+ 尚数网融合方案 + db/0824 数据库备份
- backend: 25 张表 schema/seed,config 指向 127.0.0.1:15432 opc 库
- docs: 尚数网七维融合方案、行业老炮切入方案、竞品分析等
- db/0824/opc_0824.sql(.gz): pg_dump 全量备份(25 表,含数据)
2026-08-24 13:44:40 +08:00

1249 lines
39 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handlers
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"opc-backend/db"
"opc-backend/models"
"github.com/gin-gonic/gin"
)
// ============== 工具运行引擎 ==============
// 每个 engine 接收 input JSON,返回 (output JSON, score, err)
func runCrossBorderCheck(in map[string]any) (map[string]any, float64) {
piCount, _ := toFloat(in["pi_count"])
dataType, _ := in["data_type"].(string)
importCountry, _ := in["import_country"].(string)
cumulative, _ := in["cumulative"].(string)
piiSensitive, _ := in["pii_sensitive"].(string)
// 路径匹配
var path string
var reasons []string
risk := 0.0
switch {
case dataType == "重要数据":
path = "安全评估"
reasons = append(reasons, "涉及重要数据 → 必须申报安全评估")
risk += 50
case piCount >= 1000000:
path = "安全评估"
reasons = append(reasons, "处理 100 万人以上个人信息 → 必须申报安全评估")
risk += 50
case importCountry == "其他" && piiSensitive == "是":
path = "安全评估"
reasons = append(reasons, "敏感个人信息出境 + 非协议地区 → 建议走安全评估")
risk += 40
case piCount >= 100000 && piCount < 1000000:
path = "标准合同"
reasons = append(reasons, "10 万人以上个人信息 → 走标准合同备案")
risk += 25
case importCountry == "非跨境":
path = "无需申报"
reasons = append(reasons, "数据不出境 → 无需三路径申报")
risk += 0
default:
path = "标准合同"
reasons = append(reasons, "中小批量个人信息出境 → 走标准合同")
risk += 20
}
if cumulative == "是" {
reasons = append(reasons, "曾向境外提供 → 需要补充历史合规审查")
risk += 5
}
if risk > 100 {
risk = 100
}
score := 100 - risk
steps := []string{}
switch path {
case "安全评估":
steps = []string{
"数据出境风险自评估(依据《数据出境安全评估办法》)",
"向省级网信办提交评估申报",
"国家网信办组织评审(45 个工作日内)",
"通过后签订补充协议,2 年有效",
}
case "标准合同":
steps = []string{
"数据出境风险自评估",
"参照《标准合同》范本签署",
"向省级网信办备案(10 个工作日)",
"建立年度合规审计机制",
}
case "认证":
steps = []string{
"委托经认证机构进行个人信息保护认证",
"通过认证后签订认证协议",
"在工商登记 / 网站公示认证信息",
"认证有效期 3 年,到期复审",
}
default:
steps = []string{
"数据不出境,常规内部合规即可",
"建议保留《数据处理活动记录》",
}
}
return map[string]any{
"path": path,
"risk": risk,
"score": score,
"reasons": reasons,
"steps": steps,
"laws": []string{"《数据出境安全评估办法》", "《个人信息出境标准合同办法》", "《个人信息保护法》第 38 条"},
"timestamp": time.Now().Format(time.RFC3339),
}, score
}
func runDataClassify(in map[string]any) (map[string]any, float64) {
containsPII, _ := in["contains_pii"].(string)
containsSensitive, _ := in["contains_sensitive"].(string)
industry, _ := in["industry"].(string)
openScope, _ := in["open_scope"].(string)
level := "一般"
score := 70.0
tags := []string{}
standards := []string{}
if containsSensitive == "是" {
level = "核心"
score = 100
tags = append(tags, "敏感个人信息", "生物识别", "金融账户")
standards = append(standards, "GB/T 35273-2020", "GB/T 38667-2020")
} else if containsPII == "是" {
level = "重要"
score = 85
tags = append(tags, "个人信息")
standards = append(standards, "GB/T 35273-2020")
} else {
level = "一般"
score = 60
standards = append(standards, "GB/T 38667-2020")
}
if industry == "政务" || industry == "金融" || industry == "医疗" {
level = "重要"
score += 10
tags = append(tags, "行业强监管")
}
if openScope == "公开发布" {
score += 5
tags = append(tags, "公开数据集")
}
if score > 100 {
score = 100
}
return map[string]any{
"level": level,
"score": score,
"tags": tags,
"standards": standards,
"checklist": []string{
"已完成数据资产清单登记",
"已建立访问控制策略",
"已落实脱敏 / 加密措施",
"已签订数据处理协议",
"已建立年度合规审计",
},
"advice": fmt.Sprintf("建议将 %s 类数据按 %s 级别管控,至少每季度开展一次专项审查。", industry, level),
"measure": []string{"访问控制", "数据脱敏", "加密存储", "操作留痕", "权限审批"},
}, score
}
func runDataValuation(in map[string]any) (map[string]any, float64) {
sizeGB, _ := toFloat(in["size_gb"])
rows, _ := toFloat(in["rows"])
market, _ := toFloat(in["market"])
freshness, _ := toFloat(in["freshness"])
// 成本法
cost := sizeGB*8.0 + rows*0.5 + 5000
// 市场法
marketVal := market * 0.15
// 收益法
incomeVal := market * 0.25
// 新鲜度衰减
if freshness > 0 {
coef := 1.0 / (1.0 + freshness*0.1)
incomeVal *= coef
marketVal *= coef
}
low := cost * 0.8
high := (cost + marketVal + incomeVal) * 1.2
if high < low {
high = low * 1.5
}
avg := (low + high) / 2
score := 60.0
if freshness < 6 {
score += 20
}
if market > 100 {
score += 15
}
if score > 100 {
score = 100
}
return map[string]any{
"cost_method": fmt.Sprintf("¥ %.2f 万元", cost),
"market_method": fmt.Sprintf("¥ %.2f 万元", marketVal),
"income_method": fmt.Sprintf("¥ %.2f 万元", incomeVal),
"valuation_low": fmt.Sprintf("¥ %.2f 万元", low),
"valuation_high": fmt.Sprintf("¥ %.2f 万元", high),
"valuation_avg": fmt.Sprintf("¥ %.2f 万元", avg),
"score": score,
"advice": []string{
"建议优先以「数据资产入表」方式登记",
"如需融资,建议出具第三方评估报告",
"建议引入数据资产保险(试点区域)",
"建议每半年复评一次价值",
},
"registration": []string{"数据交易所登记", "数据要素登记", "央企/上市公司数据资产入表"},
}, score
}
func runAIGCCheck(in map[string]any) (map[string]any, float64) {
contentKind, _ := in["content_kind"].(string)
usesRealFace, _ := in["uses_real_face"].(string)
isCommercial, _ := in["is_commercial"].(string)
baseModel, _ := in["base_model"].(string)
trainingDataSource, _ := in["training_data_source"].(string)
risks := []map[string]any{}
score := 100.0
if usesRealFace == "是" {
risks = append(risks, map[string]any{
"level": "高", "category": "肖像权 / 隐私",
"note": "真实人脸 → 必须获得肖像权授权;建议显著标识 AI 生成",
})
score -= 25
}
if isCommercial == "是" && baseModel == "未明确" {
risks = append(risks, map[string]any{
"level": "高", "category": "著作权",
"note": "商用 + 基模型来源未明确 → 著作权风险高",
})
score -= 30
}
if trainingDataSource == "未明确" {
risks = append(risks, map[string]any{
"level": "高", "category": "训练数据合规",
"note": "训练数据来源未明确 → 违反 PIPL 第 13 条",
})
score -= 25
} else if trainingDataSource == "公开爬取" {
risks = append(risks, map[string]any{
"level": "中", "category": "训练数据合规",
"note": "公开爬取 → 需合规审查,避免爬取受版权保护内容",
})
score -= 10
}
if contentKind == "视频" {
risks = append(risks, map[string]any{
"level": "中", "category": "深度伪造",
"note": "视频 AIGC 建议添加数字水印,遵守《生成式人工智能服务管理暂行办法》",
})
score -= 5
}
if score < 0 {
score = 0
}
overall := "低风险"
if score < 60 {
overall = "高风险"
} else if score < 85 {
overall = "中风险"
}
return map[string]any{
"overall": overall,
"score": score,
"risks": risks,
"compliance": []string{"《生成式人工智能服务管理暂行办法》", "《个人信息保护法》", "《著作权法》"},
"checklist": []string{
"基模型来源清晰可追溯",
"训练数据来源合规可审计",
"已部署 AIGC 内容标识",
"已建立用户投诉响应机制",
"已签订 C 端用户协议 + 隐私政策",
},
}, score
}
func runPrivacyGenerator(in map[string]any) (map[string]any, float64) {
company, _ := in["company_name"].(string)
product, _ := in["product_name"].(string)
biz, _ := in["business_type"].(string)
piiList := toStringSlice(in["pii_items"])
juri, _ := in["jurisdiction"].(string)
policy := fmt.Sprintf(`# %s 隐私政策(草案)
**最后更新**:%s
**适用产品**:%s(%s)
**适用法律**:%s
## 1. 我们收集的信息
我们作为 %s 的运营方,在您使用 %s 过程中可能收集以下信息:
- **账户信息**:手机号、邮箱(用于账号注册和登录)
- **设备信息**:设备型号、操作系统版本、设备识别码
- **使用信息**:访问时间、浏览 / 操作记录、IP 地址
- **主动提供**:您在使用服务中提交的内容
**敏感个人信息收集**:
%s
## 2. 我们如何使用信息
- 提供、维护、改进 %s 服务
- 安全保障:账号安全、风控反欺诈
- 个性化推荐:在您授权范围内
- 客服与售后支持
## 3. 信息共享与披露
- 您的个人信息原则上不会与第三方共享
- 法律法规要求、或行政司法机关合法要求时,可能依法披露
- 我们委托第三方处理时,会签订数据处理协议并监督其合规
## 4. 您的权利
- 查阅、复制个人信息
- 更正、补充个人信息
- 删除个人信息
- 撤回授权
- 注销账号
您可通过 [联系我们] 行使上述权利。
## 5. 数据存储与跨境
- 数据存储在中华人民共和国境内
- 如涉及跨境:%s
- 存储期限:实现目的所需最短时间
## 6. Cookie 与同类技术
我们使用 Cookie 与同类技术用于:
- 保持登录状态
- 偏好记忆
- 数据统计
您可在浏览器设置中关闭 Cookie,部分功能可能受影响。
## 7. 未成年人保护
我们不面向未满 14 周岁未成年人提供服务。如发现已收集,请联系我们删除。
## 8. 联系我们
- 公司:%s
- 邮箱:[email protected]
- 地址:xxx
---
本政策根据 %s 制定,将随法律法规或业务变化更新。
`, product, time.Now().Format("2006-01-02"), product, biz, juri,
company, product,
func() string {
if len(piiList) == 0 {
return "无"
}
return strings.Join(piiList, "、")
}(),
product,
map[string]string{
"中国大陆": "原则上不跨境",
"中国+GDPR": "按《标准合同》备案",
"中国+CCPA": "按加州 CCPA 业务规则",
"全球多法域": "按业务地法律逐项评估",
}[juri],
company,
juri)
return map[string]any{
"document": policy,
"word_count": len([]rune(policy)),
"score": 88.0,
"sections": []string{"信息收集", "使用目的", "共享披露", "用户权利", "数据存储", "Cookie", "未成年人", "联系方式"},
"download_url": "#/download/privacy-policy-" + product + ".md",
"next_steps": []string{
"法务复核(建议 1-2 个工作日)",
"上线前在产品内放置入口",
"建立用户同意记录",
"每半年复审更新",
},
}, 88.0
}
func runLicenseChain(in map[string]any) (map[string]any, float64) {
title, _ := in["data_title"].(string)
source, _ := in["source"].(string)
processor, _ := in["processor"].(string)
userType, _ := in["user_type"].(string)
scope, _ := in["scope"].(string)
doc := fmt.Sprintf(`# 「%s」数据授权链路登记
## 1. 数据来源
- **来源类型**:%s
- **采集主体**:%s
- **采集时间**:%s
## 2. 加工与处理
- **加工方**:%s
- **加工方式**:清洗、脱敏、标注、入库
- **存储地点**:尚数网数据沙盒
## 3. 授权路径
- **使用方类型**:%s
- **授权范围**:%s
- **授权期限**:自登记之日起 12 个月
- **授权方式**:链上存证 + 加密分发
## 4. 责任与义务
- 数据使用方应遵守《数据安全法》《个人信息保护法》
- 不得超出授权范围使用
- 出现安全事件 24 小时内上报
## 5. 撤回与终止
- 数据主体可随时撤回授权
- 撤回后 30 日内删除全部副本
## 6. 留痕
本登记同步至:尚数网合规链、%s侧日志
`, title, source, processor, time.Now().Format("2006-01-02"),
processor, userType, scope, userType)
return map[string]any{
"document": doc,
"score": 90.0,
"chain_length": 4,
"hash": fmt.Sprintf("sha256:%x", time.Now().UnixNano()),
"download_url": "#/download/license-chain-" + title + ".md",
"on_chain_steps": []string{"数据来源登记", "加工留痕", "授权签署", "流通分发", "使用审计"},
"advice": []string{
"建议同步至尚数网合规链存证",
"建议与下游使用方签订书面补充协议",
"建议保留不少于 3 年的授权记录",
},
}, 90.0
}
func runBMC(in map[string]any) (map[string]any, float64) {
project, _ := in["project_name"].(string)
fields := []string{"customer_segments", "value_propositions", "channels", "customer_relationships", "revenue_streams", "key_resources", "key_activities", "key_partnerships", "cost_structure"}
labels := []string{"客户细分", "价值主张", "渠道通路", "客户关系", "收入来源", "核心资源", "关键活动", "重要伙伴", "成本结构"}
filled := 0
for _, f := range fields {
if v, ok := in[f].(string); ok && strings.TrimSpace(v) != "" {
filled++
}
}
score := float64(filled) / float64(len(fields)) * 100
canvas := []map[string]any{}
for i, f := range fields {
v, _ := in[f].(string)
canvas = append(canvas, map[string]any{
"name": labels[i],
"key": f,
"value": v,
"filled": strings.TrimSpace(v) != "",
})
}
advice := []string{}
switch {
case filled < 4:
advice = append(advice, "⚠️ 严重不足:4 个以下板块完成,建议先验证问题假设")
case filled < 7:
advice = append(advice, "建议补充核心资源 / 关键活动 / 重要伙伴 3 个板块")
default:
advice = append(advice, "✓ 画布完整度高,建议做 OST 实体测试")
}
return map[string]any{
"project": project,
"canvas": canvas,
"score": score,
"filled": filled,
"total": len(fields),
"advice": advice,
}, score
}
func runBPGenerator(in map[string]any) (map[string]any, float64) {
project, _ := in["project_name"].(string)
industry, _ := in["industry"].(string)
problem, _ := in["problem"].(string)
solution, _ := in["solution"].(string)
traction, _ := in["traction"].(string)
ask, _ := in["ask"].(string)
bp := fmt.Sprintf(`# %s 商业计划书(大纲)
## 1. 项目概述
- 一句话定位:
- 行业:%s
- 阶段:种子 / 天使
## 2. 问题与痛点
%s
## 3. 解决方案
%s
## 4. 目前进展
%s
## 5. 市场分析
- TAM / SAM / SOM
- 竞争格局:直接 / 间接 / 替代
- 政策与合规环境
## 6. 商业模式
- 收入来源
- 渠道与客户关系
- 关键资源 / 关键活动 / 重要伙伴
## 7. 团队
- 创始人背景
- 核心团队
- 顾问 / 导师
## 8. 财务预测
- 3 年现金流
- 关键假设与里程碑
- 盈亏平衡点
## 9. 融资计划
- 融资需求:%s
- 资金用途
- 释放股权
- 退出机制
## 10. 风险与对策
- 技术 / 合规 / 市场 / 政策风险
`, project, industry, problem, solution, traction, ask)
return map[string]any{
"document": bp,
"score": 85.0,
"slide_count": 10,
"download_url": "#/download/bp-" + project + ".md",
"next_steps": []string{
"填充详细数据 / 图表",
"准备 5min 路演版",
"邀请法务 / 财务顾问 cross-check",
"在 OPC 平台 Demo Day 路演",
},
}, 85.0
}
func runOPCCheck(in map[string]any) (map[string]any, float64) {
checks := []map[string]any{
{"k": "has_company", "q": "已完成工商注册", "w": 20},
{"k": "has_privacy", "q": "已发布隐私政策", "w": 15},
{"k": "has_data_inventory", "q": "已建立数据资产清单", "w": 15},
{"k": "has_prototype", "q": "已有产品原型", "w": 20},
{"k": "has_user", "q": "已有种子用户", "w": 15},
{"k": "has_revenue", "q": "已有收入", "w": 15},
}
score := 0.0
details := []map[string]any{}
for _, c := range checks {
v, _ := in[c["k"].(string)].(string)
ok := v == "是"
w := c["w"].(float64)
if ok {
score += w
}
details = append(details, map[string]any{
"question": c["q"],
"passed": ok,
"weight": w,
})
}
level := "入门期"
switch {
case score >= 90:
level = "成熟运营期"
case score >= 70:
level = "加速增长期"
case score >= 50:
level = "产品打磨期"
case score >= 30:
level = "MVP 验证期"
}
advice := []string{}
if in["has_company"] != "是" {
advice = append(advice, "⚠️ 优先完成工商注册与基本户开立")
}
if in["has_privacy"] != "是" {
advice = append(advice, "⚠️ 立即在产品内发布隐私政策(用「隐私政策生成器」)")
}
if in["has_data_inventory"] != "是" {
advice = append(advice, "建议用「数据分类分级助手」建立数据资产清单")
}
if in["has_prototype"] != "是" {
advice = append(advice, "建议先做出 MVP,再追求完美")
}
if in["has_user"] != "是" {
advice = append(advice, "建议寻找 10 个种子用户深度访谈")
}
if in["has_revenue"] != "是" {
advice = append(advice, "建议 3 个月内实现第一笔订单 / 付费")
}
return map[string]any{
"score": score,
"level": level,
"details": details,
"advice": advice,
"next": "按 advice 顺序逐项完成 → 30 天后重测",
"timestamp": time.Now().Format(time.RFC3339),
}, score
}
func runQAAdvisor(in map[string]any) (map[string]any, float64) {
question, _ := in["question"].(string)
topic, _ := in["topic"].(string)
// 简单 keyword → 回答模板
q := strings.ToLower(question)
answers := []struct {
kw []string
answer string
refs []string
}{
{
[]string{"跨境", "出境", "出境", "新加坡", "海外", "gdpr"},
"如果是 SaaS 公司要向境外提供数据,请先确认数据主体类型:若涉及 100 万人+个人信息 或 重要数据 → 必须申报安全评估;10 万人+个人信息 → 标准合同备案;其他可走个人信息保护认证。建议首先使用「数据出境合规自检」工具精准匹配。",
[]string{"《数据出境安全评估办法》", "《个人信息出境标准合同办法》", "PIPL 第 38 条"},
},
{
[]string{"隐私政策", "合规", "用户协议", "应用", "app"},
"隐私政策建议覆盖 8 个章节:信息收集 / 使用目的 / 共享披露 / 用户权利 / 数据存储与跨境 / Cookie / 未成年人 / 联系方式。建议使用「隐私政策生成器」+法务复核,结合业务实际情况调整。",
[]string{"《个人信息保护法》", "《App 违法违规收集使用个人信息行为认定方法》"},
},
{
[]string{"aigc", "生成式", "ai", "版权", "训练数据"},
"AIGC 合规审查 5 个维度:著作权 / 肖像权 / 隐私 / 偏见 / 深度伪造。商用场景下基模型来源与训练数据合规是最高优先级。建议使用「AIGC 合规审查」工具得出风险评分。",
[]string{"《生成式人工智能服务管理暂行办法》", "《互联网信息服务深度合成管理规定》"},
},
{
[]string{"估值", "资产", "数据资产", "评估"},
"数据资产估值建议组合使用:成本法(采集+清洗+存储成本)+ 市场法(同类资产价格)+ 收益法(未来现金流)。建议同时在尚数网 / 数据交易所进行登记。",
[]string{"GB/T 40685-2021", "财政部《企业数据资源相关会计处理暂行规定》"},
},
{
[]string{"商业模式", "画布", "bmc", "客户", "收入"},
"商业模式画布 9 宫格:CS / VP / CH / CR / R$ / KR / KA / KP / C$。建议先用「商业模式画布」工具填出 1.0,再在 10 个种子用户中验证。",
[]string{"《商业模式新生代》", "Strategyzer 模板"},
},
{
[]string{"股权", "架构", "分红", "合伙"},
"OPC 团队建议采用「创始人 100% 持股 + 期权池」结构。若涉及技术入股 / 资源入股,请签订书面协议明确:估值方式 / 成熟期 / 退出机制。",
[]string{"《公司法》", "《合伙企业法》"},
},
}
best := ""
bestRefs := []string{}
for _, a := range answers {
for _, k := range a.kw {
if strings.Contains(q, k) || (topic != "" && strings.Contains(topic, k)) {
best = a.answer
bestRefs = a.refs
break
}
}
if best != "" {
break
}
}
if best == "" {
best = "感谢您的提问。这是 OPC 平台 AI 顾问的演示版,建议:\n1. 在「项目库」中提交您的具体场景\n2. 申请对应领域的导师 1v1 辅导\n3. 参加平台训练营获取系统化知识"
bestRefs = []string{"尚数网 OPC 平台", "OPC 训练营"}
}
return map[string]any{
"answer": best,
"refs": bestRefs,
"score": 80.0,
"tip": "本回答为 AI 草案,最终决策请结合专业顾问 / 法务意见",
}, 80
}
func runBrandGenerator(in map[string]any) (map[string]any, float64) {
product, _ := in["product_name"].(string)
tone, _ := in["tone"].(string)
keywords, _ := in["keywords"].(string)
palette, _ := in["palette"].(string)
colorMap := map[string]map[string]string{
"蓝": {"primary": "#0d4ed8", "secondary": "#06b6d4", "accent": "#67e8f9"},
"绿": {"primary": "#059669", "secondary": "#10b981", "accent": "#86efac"},
"紫": {"primary": "#7c3aed", "secondary": "#a78bfa", "accent": "#ddd6fe"},
"橙": {"primary": "#ea580c", "secondary": "#f97316", "accent": "#fed7aa"},
"黑白灰": {"primary": "#0f172a", "secondary": "#475569", "accent": "#cbd5e1"},
}
colors := colorMap[palette]
if colors == nil {
colors = colorMap["蓝"]
}
toneMap := map[string]string{
"专业可信": "建立在合规与精度之上,给人以'可审计、可信赖'的视觉印象",
"年轻活力": "圆润 + 高对比 + 强动效,传递'新鲜、有趣'的品牌感受",
"高端商务": "几何无衬线 + 大量留白 + 深色衬底,传递'权威、专业'",
"极客硬核": "等宽字体 + 霓虹色 + 网格背景,传递'硬核、技术驱动'",
}
slogans := []string{
fmt.Sprintf("让 %s 成为你的默认选择", product),
fmt.Sprintf("%s — 为一人公司而生", product),
fmt.Sprintf("数据 + AI + 一个产品 = %s", product),
fmt.Sprintf("用 %s,让人人都是数据高手", product),
}
fontMap := map[string]string{
"专业可信": "思源黑体 / Inter / 苹方",
"年轻活力": "OPPO Sans / 阿里巴巴普惠体",
"高端商务": "思源宋体 / 苹方 / Helvetica",
"极客硬核": "JetBrains Mono / Fira Code",
}
return map[string]any{
"product": product,
"slogans": slogans,
"colors": colors,
"fonts": fontMap[tone],
"tone_desc": toneMap[tone],
"keywords": keywords,
"logo_concept": []string{
"图形 + 文字组合(推荐)",
"几何符号 + 字体延展",
"抽象数据流肌理",
"中文 / 英文双版本",
},
"applications": []string{
"产品官网 Header",
"App 启动屏",
"名片 / PPT 模板",
"名片 / 微信头像",
},
"score": 90.0,
}, 90.0
}
func runChartTemplate(in map[string]any) (map[string]any, float64) {
scenario, _ := in["scenario"].(string)
dataset, _ := in["dataset_type"].(string)
audience, _ := in["audience"].(string)
rec := []map[string]any{}
switch dataset {
case "指标型":
rec = append(rec, map[string]any{"type": "KPI 卡", "purpose": "核心数字指标", "complexity": "低"})
rec = append(rec, map[string]any{"type": "雷达图", "purpose": "多维能力对比", "complexity": "中"})
case "时间序列":
rec = append(rec, map[string]any{"type": "折线图", "purpose": "趋势 + 预测", "complexity": "低"})
rec = append(rec, map[string]any{"type": "面积图", "purpose": "累计量", "complexity": "中"})
rec = append(rec, map[string]any{"type": "热力日历", "purpose": "周期性", "complexity": "高"})
case "结构化表格":
rec = append(rec, map[string]any{"type": "桑基图", "purpose": "流向 + 转化", "complexity": "高"})
rec = append(rec, map[string]any{"type": "漏斗图", "purpose": "转化分析", "complexity": "中"})
rec = append(rec, map[string]any{"type": "树状图", "purpose": "层级占比", "complexity": "中"})
case "多维交叉":
rec = append(rec, map[string]any{"type": "分组柱状图", "purpose": "多指标对比", "complexity": "低"})
rec = append(rec, map[string]any{"type": "散点图", "purpose": "相关性", "complexity": "中"})
rec = append(rec, map[string]any{"type": "地理热力图", "purpose": "区域分布", "complexity": "高"})
}
colorScheme := []string{"#0d4ed8", "#06b6d4", "#8b5cf6", "#10b981", "#f59e0b"}
if audience == "政府" {
colorScheme = []string{"#0d4ed8", "#1e40af", "#dc2626", "#f59e0b"}
}
if audience == "投资方" {
colorScheme = []string{"#0d4ed8", "#06b6d4", "#10b981"}
}
return map[string]any{
"scenario": scenario,
"recommendations": rec,
"color_scheme": colorScheme,
"layout": []string{
"12 列响应式网格",
"PC + 移动端双布局",
"顶部 4 KPI + 主图表 + 副图",
},
"score": 85.0,
"tech": "ECharts / AntV / Recharts",
"export": []string{"PNG", "PDF", "PPT 嵌入"},
}, 85.0
}
func runCoverGenerator(in map[string]any) (map[string]any, float64) {
title, _ := in["title"].(string)
subtitle, _ := in["subtitle"].(string)
theme, _ := in["theme"].(string)
ratio, _ := in["aspect_ratio"].(string)
themeMap := map[string]map[string]string{
"蓝紫": {"primary": "#0d4ed8", "secondary": "#7c3aed", "bg": "#0f172a"},
"墨绿": {"primary": "#047857", "secondary": "#0ea5e9", "bg": "#082f49"},
"橙红": {"primary": "#ea580c", "secondary": "#dc2626", "bg": "#1f1717"},
"黑白灰": {"primary": "#0f172a", "secondary": "#475569", "bg": "#f8fafc"},
}
colors := themeMap[theme]
if colors == nil {
colors = themeMap["蓝紫"]
}
dim := map[string]string{
"16:9": "1920×1080",
"1:1": "1080×1080",
"9:16": "1080×1920",
"A4": "2480×3508",
}
return map[string]any{
"title": title,
"subtitle": subtitle,
"colors": colors,
"dimension": dim[ratio],
"layout": []string{
"主标题(H1 96pt 中文/72pt 英文)",
"副标题(H2 36pt)",
"主视觉图形(数据纹理 / 几何符号)",
"底部署名 / 网址",
},
"templates": []string{
"科技矩阵风", "极简留白", "数据流体感", "中国风纹样",
},
"score": 88.0,
}, 88.0
}
// ============== HTTP 处理 ==============
// ListTools 支持 domain 过滤
func ListToolsV2(c *gin.Context) {
var ts []models.Tool
q := db.DB.Order("id")
if domain := c.Query("domain"); domain != "" {
q = q.Where("domain = ?", domain)
}
q.Find(&ts)
ok(c, ts)
}
func GetTool(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
var t models.Tool
if err := db.DB.First(&t, id).Error; err != nil {
errResp(c, 404, "工具不存在")
return
}
ok(c, t)
}
func RunTool(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
var t models.Tool
if err := db.DB.First(&t, id).Error; err != nil {
errResp(c, 404, "工具不存在")
return
}
var input map[string]any
if err := c.ShouldBindJSON(&input); err != nil {
errResp(c, 400, "请求体格式错误")
return
}
// 解析 template → engine 名
tpl := map[string]any{}
if t.Template != nil {
tpl = map[string]any(t.Template)
}
engine, _ := tpl["engine"].(string)
start := time.Now()
var output map[string]any
var score float64
switch engine {
case "cross_border_check":
output, score = runCrossBorderCheck(input)
case "data_classify":
output, score = runDataClassify(input)
case "data_valuation":
output, score = runDataValuation(input)
case "qa_advisor":
output, score = runQAAdvisor(input)
case "aigc_check":
output, score = runAIGCCheck(input)
case "privacy_generator":
output, score = runPrivacyGenerator(input)
case "license_chain":
output, score = runLicenseChain(input)
case "bmc":
output, score = runBMC(input)
case "bp_generator":
output, score = runBPGenerator(input)
case "opc_check":
output, score = runOPCCheck(input)
case "brand_generator":
output, score = runBrandGenerator(input)
case "chart_template":
output, score = runChartTemplate(input)
case "cover_generator":
output, score = runCoverGenerator(input)
case "bazhuayu_crossborder":
output, score = runBazhuayuCrossborder(input)
case "bazhuayu_tender":
output, score = runBazhuayuTender(input)
case "bazhuayu_price":
output, score = runBazhuayuPrice(input)
case "jiuxin_rpa":
output, score = runJiuxinRPA(input)
case "jiuxin_9xin":
output, score = runJiuxin9Xin(input)
case "jiuxin_bi":
output, score = runJiuxinBI(input)
default:
errResp(c, 400, "工具引擎未实现: "+engine)
return
}
duration := int(time.Since(start).Milliseconds())
// 存记录
inputJSON, _ := json.Marshal(input)
outputJSON, _ := json.Marshal(output)
run := models.ToolRun{
ToolID: id,
UserName: "demo@opc",
Input: models.JSONObject(input),
Output: models.JSONObject(output),
Score: &score,
DurationMs: duration,
}
db.DB.Create(&run)
ok(c, gin.H{
"run_id": run.ID,
"tool_id": id,
"tool_name": t.Name,
"output": output,
"score": score,
"duration_ms": duration,
"input_dump": string(inputJSON),
"output_dump": string(outputJSON),
})
}
func ListToolRuns(c *gin.Context) {
var runs []models.ToolRun
q := db.DB.Order("created_at DESC").Limit(100)
if tid := c.Query("tool_id"); tid != "" {
q = q.Where("tool_id = ?", tid)
}
q.Find(&runs)
ok(c, runs)
}
// ============== 辅助 ==============
func toFloat(v any) (float64, bool) {
switch x := v.(type) {
case float64:
return x, true
case float32:
return float64(x), true
case int:
return float64(x), true
case int64:
return float64(x), true
case string:
f, err := strconv.ParseFloat(x, 64)
return f, err == nil
}
return 0, false
}
func toStringSlice(v any) []string {
if v == nil {
return nil
}
switch x := v.(type) {
case []any:
out := []string{}
for _, item := range x {
if s, ok := item.(string); ok {
out = append(out, s)
}
}
return out
case []string:
return x
case string:
if x == "" {
return nil
}
return strings.Split(x, ",")
}
return nil
}
func httpOK() gin.H { return gin.H{"code": 0} }
// prevent unused
var _ = httpOK
// ============== 八爪鱼系列引擎 ==============
func runBazhuayuCrossborder(in map[string]any) (map[string]any, float64) {
platform, _ := in["platform"].(string)
category, _ := in["category"].(string)
rows, _ := toFloat(in["rows"])
fields := toStringSlice(in["fields"])
if rows == 0 {
rows = 100
}
if fields == nil {
fields = []string{"商品标题", "价格", "评分"}
}
// 模拟八爪鱼采集结果
results := []map[string]any{}
for i := 0; i < 5 && i < int(rows); i++ {
results = append(results, map[string]any{
"id": fmt.Sprintf("%s_%d_%d", platform, hashCode(category), i),
"title": fmt.Sprintf("%s %s 第 %d 名", category, platform, i+1),
"price": fmt.Sprintf("$%.2f", 19.99+float64(i)*5.5),
"rating": fmt.Sprintf("%.1f", 4.2+float64(i%3)*0.2),
"review_count": 200 + i*50,
"sku": fmt.Sprintf("SKU-%05d", 10001+i),
"url": fmt.Sprintf("https://www.%s.com/dp/REF%d", platform, 10000+i),
})
}
return map[string]any{
"engine": "八爪鱼 跨境选品数据采集",
"platform": platform,
"category": category,
"rows": rows,
"fields": fields,
"collected": len(results),
"sample": results,
"export_url": fmt.Sprintf("https://www.bazhuayu.com/opc/export/%s_%s.xlsx", platform, category),
"compliance": "公开数据采集 · 符合 PIPL + GDPR 公开数据范围",
"score": 92.0,
"duration_min": rows / 100,
"tips": []string{
"建议勾选 '店铺等级' 字段以筛选优质卖家",
"高频采集建议开启 '云采集' 模式",
"如需 M8C 服务集成可使用八爪鱼 MCP Server",
},
}, 92.0
}
func runBazhuayuTender(in map[string]any) (map[string]any, float64) {
keyword, _ := in["keyword"].(string)
region, _ := in["region"].(string)
days, _ := toFloat(in["days"])
if days == 0 {
days = 30
}
tenders := []map[string]any{
{"id": "T001", "title": fmt.Sprintf("%s 数据合规服务采购", keyword), "buyer": "市政务办", "amount": "500万", "deadline": "2026-08-30", "region": region},
{"id": "T002", "title": fmt.Sprintf("%s 智能体平台采购", keyword), "buyer": "市国资委", "amount": "1200万", "deadline": "2026-09-05", "region": region},
{"id": "T003", "title": fmt.Sprintf("%s SaaS 订阅服务", keyword), "buyer": "数据中心", "amount": "300万", "deadline": "2026-09-10", "region": region},
{"id": "T004", "title": fmt.Sprintf("%s 解决方案招标", keyword), "buyer": "某央企", "amount": "800万", "deadline": "2026-09-15", "region": region},
{"id": "T005", "title": fmt.Sprintf("%s 咨询服务", keyword), "buyer": "某省级国企", "amount": "150万", "deadline": "2026-09-20", "region": region},
}
return map[string]any{
"engine": "八爪鱼 招投标信息聚合",
"keyword": keyword,
"region": region,
"days": days,
"count": len(tenders),
"tenders": tenders,
"score": 95.0,
"export_url": "https://www.bazhuayu.com/opc/export/tender.xlsx",
"tips": []string{"已对接 300+ 招投标网站源", "可订阅关键词 RSS 推送"},
}, 95.0
}
func runBazhuayuPrice(in map[string]any) (map[string]any, float64) {
urls, _ := in["target_urls"].(string)
freq, _ := in["frequency"].(string)
threshold, _ := toFloat(in["alert_threshold"])
if threshold == 0 {
threshold = 5
}
urlCount := len(strings.Split(urls, ","))
return map[string]any{
"engine": "八爪鱼 RPA 竞品价格监控",
"target_urls": urls,
"frequency": freq,
"threshold": threshold,
"url_count": urlCount,
"rules_added": []string{"价格波动 > 阈值", "库存状态变化", "新品上架"},
"channel": []string{"邮件", "微信", "Webhook", "钉钉"},
"recent": []map[string]any{
{"url": "https://competitor-a.com/p1", "old_price": "$29.99", "new_price": "$27.99", "delta": "-6.7%", "alert": true},
{"url": "https://competitor-b.com/p2", "old_price": "$49.99", "new_price": "$49.99", "delta": "0%", "alert": false},
},
"score": 88.0,
"tips": []string{"基于八爪鱼 RPA AI 写流程 3.0", "支持多平台价格策略分析"},
}, 88.0
}
// ============== 九鑫智能系列引擎 ==============
func runJiuxinRPA(in map[string]any) (map[string]any, float64) {
scenario, _ := in["scenario"].(string)
platforms := toStringSlice(in["platforms"])
volume, _ := toFloat(in["volume"])
if volume == 0 {
volume = 1000
}
steps := []map[string]any{}
switch scenario {
case "订单同步":
steps = []map[string]any{
{"step": "监听新订单", "tool": "Webhook", "duration_sec": 1},
{"step": "校验库存", "tool": "ERP API", "duration_sec": 2},
{"step": "推送订单", "tool": "OMS", "duration_sec": 1},
{"step": "生成发货单", "tool": "WMS", "duration_sec": 2},
{"step": "回传订单状态", "tool": "Webhook", "duration_sec": 1},
}
case "库存监控":
steps = []map[string]any{
{"step": "定时拉取库存", "tool": "CronJob", "duration_sec": 1},
{"step": "AI 预测告警", "tool": "9Xin 模型", "duration_sec": 5},
{"step": "自动补货建议", "tool": "ERP 集成", "duration_sec": 2},
}
default:
steps = []map[string]any{
{"step": "登录业务系统", "tool": "RPA", "duration_sec": 2},
{"step": "查询数据", "tool": "RPA", "duration_sec": 3},
{"step": "执行操作", "tool": "RPA", "duration_sec": 2},
{"step": "回传结果", "tool": "API", "duration_sec": 1},
}
}
return map[string]any{
"engine": "九鑫智能 电商全流程 RPA",
"scenario": scenario,
"platforms": platforms,
"volume": volume,
"steps": steps,
"avg_duration_sec": 8,
"time_saved": fmt.Sprintf("%.0f 小时/月", volume*30*0.1),
"score": 92.0,
"deployment": "SaaS 30s 部署 / 私有化 1 天",
"tips": []string{
"基于九鑫智能 9Xin 全球商贸行业 AI 模型",
"嘉兴唯一入选工信部典型应用案例",
"已成功运行 3 万+ 电商店铺",
},
}, 92.0
}
func runJiuxin9Xin(in map[string]any) (map[string]any, float64) {
scenario, _ := in["scenario"].(string)
_, _ = in["question"].(string)
answers := map[string]string{
"外贸获客": "基于 9Xin 全球商贸行业 AI 模型(嘉兴唯一入选工信部典型案例):\n1. 用八爪鱼采集目标市场 KOL / 经销商公开信息\n2. 通过 9Xin 内贸外贸一体化模型识别匹配度\n3. 自动生成多语种邮件 + WhatsApp 跟进话术\n4. RPA 自动化投递 + 状态追踪",
"内外贸一体化": "9Xin 内外贸一体化 4 步方案:\n1. 用八爪鱼采集国内外双端行情数据\n2. 通过 9Xin 模型识别需求差异 + 监管差异\n3. 内贸 SOP 复用 + 外贸差异改造\n4. 一次数据分析 → 双向商机落地",
"市场分析": "9Xin 全球商贸分析:覆盖 30+ 国家 B2B / B2C 平台数据,结合八爪鱼 5000 台云采集节点,提供市场规模 / 竞争格局 / 价格区间 / 监管差异 4 维分析。",
"合规咨询": "9Xin 合规咨询:覆盖 PIPL / GDPR / 多国数据出境法规。结合平台内的 隐私政策生成器 / 数据出境合规自检 工具,形成完整合规方案。",
"客户画像": "9Xin 客户画像:基于多源数据(公开工商 / 电商行为 / 社交媒体)构建企业客户画像,输出精准营销建议 + 客户分级。",
}
best := answers[scenario]
if best == "" {
best = "感谢您的提问。基于 9Xin 全球商贸行业 AI 模型,我们建议结合 八爪鱼跨境数据采集 + 九鑫 RPA 自动化 来落地。平台已为您准备 OPC 工具箱:跨境选品数据采集 / 9Xin 行业 AI 助手 / 电商全流程 RPA。"
}
return map[string]any{
"engine": "九鑫智能 9Xin 行业 AI 助手",
"scenario": scenario,
"answer": best,
"score": 90.0,
"references": []string{"9Xin 全球商贸行业 AI 模型", "工信部《人工智能赋能新型工业化典型应用案例》", "嘉兴市唯一入选项目"},
"action": "可一键导出《行动方案》",
"integrated": []string{"八爪鱼跨境数据采集", "九鑫 RPA 自动化", "尚数网 OPC 平台"},
}, 90.0
}
func runJiuxinBI(in map[string]any) (map[string]any, float64) {
industry, _ := in["industry"].(string)
source, _ := in["data_source"].(string)
concern, _ := in["concern"].(string)
return map[string]any{
"engine": "九鑫智能 商业智能分析",
"industry": industry,
"source": source,
"concern": concern,
"kpis": []map[string]any{
{"name": "客户复购率", "value": "62.5%", "trend": "+5.2%", "level": "良好"},
{"name": "获客成本", "value": "¥128", "trend": "-12.3%", "level": "优秀"},
{"name": "库存周转率", "value": "8.5 次/年", "trend": "+1.2%", "level": "良好"},
{"name": "应收账款周转天数", "value": "32 天", "trend": "-8 天", "level": "优秀"},
},
"risks": []map[string]any{
{"name": "客户集中度", "level": "中", "suggestion": "建议拓展 5+ 头部新客户"},
{"name": "现金流", "level": "低", "suggestion": "经营现金流稳健"},
},
"score": 88.0,
"ai_suggestions": []string{
"基于 9Xin 模型:建议下季度重点关注新客户获取",
"建议结合 八爪鱼行业数据 + 内部 BI 做交叉分析",
"建议每月生成自动化 BI 报告(九鑫 RPA 自动化)",
},
}, 88.0
}
// hashCode 简单字符串 hash
func hashCode(s string) uint32 {
var h uint32
for _, c := range s {
h = h*31 + uint32(c)
}
return h
}