v1.0.29: 碎片处理按dp方案2修订 - 完整度改三层独立判定(核心100%/重要60%/非必要40%,任一不达标即碎片)+字段分层调整(persons email升核心,companies核心扩5字段)+指标卡5张(新增累计处理,本月/累计=硬+软合计)+软碎片列表加各层完整度列+硬碎片完整度改已填/总可填
This commit is contained in:
+94
-61
@@ -1,46 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* 完整度计算引擎(碎片处理方案 v1.0.27)
|
||||
* 公式:完整度 = 100 - (缺失核心字段数×20) - (缺失重要字段数×8) - (缺失补充字段数×2),下限 0%
|
||||
* 阈值:persons/companies ≥65%,social_accounts ≥60%,media_commercial_attributes ≥55%
|
||||
* 完整度判定引擎(碎片处理方案 v2,2026-08-09)
|
||||
* 三层独立判定:任一楼层不达标 → is_incomplete = 1
|
||||
* - 核心层 必须 100% 达标(不达标 = 缺核心,最高优先级)
|
||||
* - 重要层 必须 ≥ 60% 达标(不达标 = 缺重要)
|
||||
* - 非必要层 必须 ≥ 40% 达标(不达标 = 待补充)
|
||||
* 每层完整度 = 该层已填字段数 ÷ 该层总字段数 × 100%
|
||||
* 整体完整度 = 全部已填字段数 ÷ 全部字段数 × 100%(展示用)
|
||||
* 说明:persons 的 phone/email 为虚拟字段(来自 social_accounts 关联记录)
|
||||
*/
|
||||
require_once __DIR__ . '/db.php';
|
||||
|
||||
/** 四表字段分层定义(key => 层级),threshold 为完整度阈值 */
|
||||
/** 四表字段分层定义(key => 所属层;virtual 为关联虚拟字段) */
|
||||
const COMPLETENESS_LAYERS = [
|
||||
'persons' => [
|
||||
'core' => ['full_name'],
|
||||
'important' => ['work_location'],
|
||||
'supplementary' => ['gender', 'nationality', 'education', 'graduated_from', 'hometown', 'id_type', 'id_number'],
|
||||
'virtual' => ['phone' => 'core', 'email' => 'important'], // 关联 social_accounts.platform
|
||||
'threshold' => 65,
|
||||
'core' => ['full_name'],
|
||||
'important' => ['work_location'],
|
||||
'optional' => ['gender', 'nationality', 'education', 'graduated_from', 'hometown', 'id_type', 'id_number'],
|
||||
'virtual' => ['phone' => 'core', 'email' => 'core'], // 关联 social_accounts.platform
|
||||
],
|
||||
'companies' => [
|
||||
'core' => ['display_name', 'industry'],
|
||||
'important' => ['address', 'business_role', 'country'],
|
||||
'supplementary' => ['name_zh', 'name_en', 'registration_number', 'legal_form', 'legal_representative',
|
||||
'business_scope', 'established_date', 'registered_capital', 'industry_subdivision',
|
||||
'latest_employee_count', 'latest_annual_revenue', 'is_listed', 'stock_code', 'website'],
|
||||
'virtual' => [],
|
||||
'threshold' => 65,
|
||||
'core' => ['display_name', 'name_zh', 'name_en', 'business_role', 'industry'],
|
||||
'important' => ['address', 'country'],
|
||||
'optional' => ['registration_number', 'legal_form', 'legal_representative', 'business_scope',
|
||||
'established_date', 'registered_capital', 'industry_subdivision',
|
||||
'latest_employee_count', 'latest_annual_revenue', 'is_listed', 'stock_code', 'website'],
|
||||
'virtual' => [],
|
||||
],
|
||||
'social_accounts' => [
|
||||
'core' => ['platform', 'account_id'],
|
||||
'important' => ['is_primary'],
|
||||
'supplementary' => ['profile_url', 'remark'],
|
||||
'virtual' => [],
|
||||
'threshold' => 60,
|
||||
'core' => ['platform', 'account_id'],
|
||||
'important' => ['is_primary'],
|
||||
'optional' => ['profile_url', 'remark'],
|
||||
'virtual' => [],
|
||||
],
|
||||
'media' => [
|
||||
'core' => ['social_account_id', 'account_level'],
|
||||
'important' => ['follower_count', 'content_categories'],
|
||||
'supplementary' => ['certification_type', 'avg_read_count', 'special_requirements', 'media_remark'],
|
||||
'virtual' => [],
|
||||
'threshold' => 55,
|
||||
'core' => ['social_account_id', 'account_level'],
|
||||
'important' => ['follower_count', 'content_categories'],
|
||||
'optional' => ['avg_read_count', 'certification_type', 'special_requirements', 'media_remark'],
|
||||
'virtual' => [],
|
||||
],
|
||||
];
|
||||
|
||||
/** 各层达标门槛(%) */
|
||||
const COMPLETENESS_THRESHOLDS = ['core' => 100, 'important' => 60, 'optional' => 40];
|
||||
|
||||
/** 字段中文名(前端展示缺失字段用) */
|
||||
const COMPLETENESS_LABELS = [
|
||||
'full_name' => '姓名', 'phone' => '手机', 'email' => '邮箱', 'work_location' => '工作所在地',
|
||||
@@ -65,54 +68,85 @@ function completenessIsMissing($v)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分层定义计算完整度
|
||||
* 三层完整度计算
|
||||
* @param string $table persons|companies|social_accounts|media
|
||||
* @param array $row 该表记录(persons 需已注入虚拟字段 phone/email)
|
||||
* @return array { score:int, missing_core:[], missing_important:[], missing_supp:[], level:string }
|
||||
* @return array {
|
||||
* layers: { core:{filled,total,rate,passed}, important:{...}, optional:{...} },
|
||||
* overall: float, overall_passed: bool,
|
||||
* missing: { core:[], important:[], optional:[] },
|
||||
* level: core|important|optional|complete
|
||||
* }
|
||||
*/
|
||||
function completenessCalc($table, $row)
|
||||
{
|
||||
$layers = COMPLETENESS_LAYERS[$table] ?? null;
|
||||
$default = [
|
||||
'layers' => ['core' => ['filled' => 0, 'total' => 0, 'rate' => 100, 'passed' => true]],
|
||||
'overall' => 100, 'overall_passed' => true,
|
||||
'missing' => ['core' => [], 'important' => [], 'optional' => []],
|
||||
'level' => 'complete',
|
||||
];
|
||||
if (!$layers) {
|
||||
return ['score' => 100, 'missing_core' => [], 'missing_important' => [], 'missing_supp' => [], 'level' => 'complete'];
|
||||
return $default;
|
||||
}
|
||||
$missing = ['core' => [], 'important' => [], 'supplementary' => []];
|
||||
|
||||
foreach (['core' => 'core', 'important' => 'important', 'supplementary' => 'supplementary'] as $layer => $bucket) {
|
||||
$result = [];
|
||||
$missing = ['core' => [], 'important' => [], 'optional' => []];
|
||||
$totalAll = 0;
|
||||
$filledAll = 0;
|
||||
|
||||
foreach (['core', 'important', 'optional'] as $layer) {
|
||||
$total = count($layers[$layer]);
|
||||
$filled = 0;
|
||||
foreach ($layers[$layer] as $field) {
|
||||
if (completenessIsMissing($row[$field] ?? null)) {
|
||||
$missing[$bucket][] = $field;
|
||||
$missing[$layer][] = $field;
|
||||
} else {
|
||||
$filled++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 虚拟字段(如人员 phone/email)按配置的层级计入
|
||||
foreach (($layers['virtual'] ?? []) as $field => $layer) {
|
||||
if (completenessIsMissing($row[$field] ?? null)) {
|
||||
$missing[$layer][] = $field;
|
||||
// 虚拟字段(persons phone/email)按配置层计入
|
||||
foreach (($layers['virtual'] ?? []) as $vf => $vLayer) {
|
||||
if ($vLayer !== $layer) {
|
||||
continue;
|
||||
}
|
||||
$total++;
|
||||
if (completenessIsMissing($row[$vf] ?? null)) {
|
||||
$missing[$layer][] = $vf;
|
||||
} else {
|
||||
$filled++;
|
||||
}
|
||||
}
|
||||
$rate = $total > 0 ? round($filled / $total * 100, 1) : 100;
|
||||
$result[$layer] = [
|
||||
'filled' => $filled,
|
||||
'total' => $total,
|
||||
'rate' => $rate,
|
||||
'passed' => $rate >= COMPLETENESS_THRESHOLDS[$layer],
|
||||
];
|
||||
$totalAll += $total;
|
||||
$filledAll += $filled;
|
||||
}
|
||||
|
||||
$score = 100
|
||||
- count($missing['core']) * 20
|
||||
- count($missing['important']) * 8
|
||||
- count($missing['supplementary']) * 2;
|
||||
$score = max(0, $score);
|
||||
$overall = $totalAll > 0 ? round($filledAll / $totalAll * 100, 1) : 100;
|
||||
$overallPassed = $result['core']['passed'] && $result['important']['passed'] && $result['optional']['passed'];
|
||||
|
||||
$level = 'complete';
|
||||
if (!empty($missing['core'])) {
|
||||
if (!$result['core']['passed']) {
|
||||
$level = 'core'; // 缺核心(红)
|
||||
} elseif (!empty($missing['important'])) {
|
||||
} elseif (!$result['important']['passed']) {
|
||||
$level = 'important'; // 缺重要(橙)
|
||||
} elseif (!empty($missing['supplementary'])) {
|
||||
$level = 'supplementary'; // 待补充(蓝)
|
||||
} elseif (!$result['optional']['passed']) {
|
||||
$level = 'optional'; // 待补充(蓝)
|
||||
}
|
||||
|
||||
return [
|
||||
'score' => $score,
|
||||
'missing_core' => $missing['core'],
|
||||
'missing_important' => $missing['important'],
|
||||
'missing_supp' => $missing['supplementary'],
|
||||
'level' => $level,
|
||||
'layers' => $result,
|
||||
'overall' => $overall,
|
||||
'overall_passed' => $overallPassed,
|
||||
'missing' => $missing,
|
||||
'level' => $level,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -138,7 +172,7 @@ function personWithVirtualFields(PDO $pdo, array $row)
|
||||
* @param PDO $pdo
|
||||
* @param string $table persons|companies|social_accounts|media
|
||||
* @param int $id
|
||||
* @return array { row, score, missing_core, missing_important, missing_supp, level, threshold }
|
||||
* @return array|null { row, layers, overall, overall_passed, missing, level, is_complete }
|
||||
*/
|
||||
function completenessInfo(PDO $pdo, $table, $id)
|
||||
{
|
||||
@@ -176,19 +210,18 @@ function completenessInfo(PDO $pdo, $table, $id)
|
||||
}
|
||||
$calc = completenessCalc($table, $row);
|
||||
return [
|
||||
'row' => $row,
|
||||
'score' => $calc['score'],
|
||||
'missing_core' => $calc['missing_core'],
|
||||
'missing_important' => $calc['missing_important'],
|
||||
'missing_supp' => $calc['missing_supp'],
|
||||
'level' => $calc['level'],
|
||||
'threshold' => COMPLETENESS_LAYERS[$table]['threshold'] ?? 65,
|
||||
'is_complete' => $calc['score'] >= (COMPLETENESS_LAYERS[$table]['threshold'] ?? 65),
|
||||
'row' => $row,
|
||||
'layers' => $calc['layers'],
|
||||
'overall' => $calc['overall'],
|
||||
'overall_passed' => $calc['overall_passed'],
|
||||
'missing' => $calc['missing'],
|
||||
'level' => $calc['level'],
|
||||
'is_complete' => $calc['overall_passed'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新某条记录的 is_incomplete 标记(完整度低于阈值 → 1)
|
||||
* 更新某条记录的 is_incomplete 标记(任一楼层不达标 → 1)
|
||||
* @param PDO $pdo
|
||||
* @param string $table persons|companies|social_accounts|media
|
||||
* @param int $id
|
||||
|
||||
@@ -1,45 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* 硬碎片公共逻辑:字段分层 / 完整度计算 / 内容摘要
|
||||
* 硬碎片公共逻辑:完整度计算(按非空字段直接计数)+ 内容摘要
|
||||
* 被 hard_list.php 与 hard_detail.php 共用
|
||||
*/
|
||||
|
||||
/** 硬碎片字段分层(按 source_type) */
|
||||
const HARD_LAYERS = [
|
||||
'company' => ['core' => ['company_name', 'contact_phone'], 'important' => ['contact_email'], 'supplementary' => ['person_name', 'description', 'target_product_category']],
|
||||
'person' => ['core' => ['person_name', 'contact_phone'], 'important' => ['contact_email'], 'supplementary' => ['company_name', 'description', 'target_product_category']],
|
||||
'product' => ['core' => ['company_name', 'target_product_category'], 'important' => ['contact_phone', 'contact_email'], 'supplementary' => ['person_name', 'description']],
|
||||
'need' => ['core' => ['company_name', 'target_product_category'], 'important' => ['contact_phone', 'contact_email'], 'supplementary' => ['person_name', 'description']],
|
||||
'mixed' => ['core' => ['company_name', 'person_name'], 'important' => ['contact_phone', 'contact_email'], 'supplementary' => ['description', 'target_product_category']],
|
||||
];
|
||||
/** 硬碎片可统计字段(公司名/联系人/电话/邮箱/品类/描述) */
|
||||
const HARD_FIELDS = ['company_name', 'person_name', 'contact_phone', 'contact_email', 'target_product_category', 'description'];
|
||||
const HARD_LABELS = [
|
||||
'company_name' => '公司名称', 'person_name' => '联系人', 'contact_phone' => '电话',
|
||||
'contact_email' => '邮箱', 'target_product_category' => '产品品类', 'description' => '描述',
|
||||
];
|
||||
|
||||
/** 计算硬碎片完整度与缺失层级 */
|
||||
/** 计算硬碎片完整度:已填字段数 ÷ 总可填字段数 × 100% */
|
||||
function hardCompleteness($row)
|
||||
{
|
||||
$layers = HARD_LAYERS[$row['source_type']] ?? HARD_LAYERS['mixed'];
|
||||
$missing = ['core' => [], 'important' => [], 'supplementary' => []];
|
||||
foreach (['core', 'important', 'supplementary'] as $layer) {
|
||||
foreach ($layers[$layer] as $field) {
|
||||
if ($row[$field] === null || trim((string)$row[$field]) === '') {
|
||||
$missing[$layer][] = $field;
|
||||
}
|
||||
$filled = 0;
|
||||
$missing = [];
|
||||
foreach (HARD_FIELDS as $field) {
|
||||
if ($row[$field] !== null && trim((string)$row[$field]) !== '') {
|
||||
$filled++;
|
||||
} else {
|
||||
$missing[] = $field;
|
||||
}
|
||||
}
|
||||
$score = 100 - count($missing['core']) * 20 - count($missing['important']) * 8 - count($missing['supplementary']) * 2;
|
||||
$score = max(0, $score);
|
||||
$level = 'complete';
|
||||
if (!empty($missing['core'])) {
|
||||
$level = 'core';
|
||||
} elseif (!empty($missing['important'])) {
|
||||
$level = 'important';
|
||||
} elseif (!empty($missing['supplementary'])) {
|
||||
$level = 'supplementary';
|
||||
}
|
||||
return ['score' => $score, 'level' => $level, 'missing' => $missing];
|
||||
$total = count(HARD_FIELDS);
|
||||
$score = $total > 0 ? (int)round($filled / $total * 100) : 0;
|
||||
return ['score' => $score, 'missing' => $missing];
|
||||
}
|
||||
|
||||
/** 内容摘要:拼接已有关键信息 */
|
||||
|
||||
@@ -24,7 +24,6 @@ if (!$row) {
|
||||
|
||||
$calc = hardCompleteness($row);
|
||||
$row['completeness'] = $calc['score'];
|
||||
$row['level'] = $calc['level'];
|
||||
$row['missing'] = $calc['missing'];
|
||||
$row['summary'] = hardSummary($row);
|
||||
$row['source_type_label'] = ['company' => '企业', 'person' => '人员', 'product' => '产品', 'need' => '需求', 'mixed' => '混合'][$row['source_type']] ?? $row['source_type'];
|
||||
|
||||
@@ -52,7 +52,6 @@ $list = [];
|
||||
foreach ($rows as $r) {
|
||||
$calc = hardCompleteness($r);
|
||||
$r['completeness'] = $calc['score'];
|
||||
$r['level'] = $calc['level'];
|
||||
$r['missing'] = $calc['missing'];
|
||||
$r['summary'] = hardSummary($r);
|
||||
$r['source_type_label'] = ['company' => '企业', 'person' => '人员', 'product' => '产品', 'need' => '需求', 'mixed' => '混合'][$r['source_type']] ?? $r['source_type'];
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* 软碎片详情接口 GET /api/fragment/soft_detail.php?table=persons&id=1
|
||||
* 返回:{ table, id, name, score, level, missing_core, missing_important, missing_supp, threshold, row }
|
||||
* 返回:{ table, table_label, id, name, overall, level, layers, missing_core, missing_important,
|
||||
* missing_optional, missing_labels, row }
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
@@ -41,16 +42,20 @@ switch ($table) {
|
||||
break;
|
||||
}
|
||||
|
||||
$label = function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; };
|
||||
|
||||
Response::success([
|
||||
'table' => $table,
|
||||
'table_label' => $tableLabels[$table],
|
||||
'id' => $id,
|
||||
'name' => $name ?: ('#' . $id),
|
||||
'score' => $info['score'],
|
||||
'overall' => $info['overall'],
|
||||
'level' => $info['level'],
|
||||
'threshold' => $info['threshold'],
|
||||
'missing_core' => array_map(function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; }, $info['missing_core']),
|
||||
'missing_important' => array_map(function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; }, $info['missing_important']),
|
||||
'missing_supp' => array_map(function ($f) { return ['key' => $f, 'label' => COMPLETENESS_LABELS[$f] ?? $f]; }, $info['missing_supp']),
|
||||
'layers' => $info['layers'],
|
||||
'missing_core' => array_map($label, $info['missing']['core']),
|
||||
'missing_important' => array_map($label, $info['missing']['important']),
|
||||
'missing_optional' => array_map($label, $info['missing']['optional']),
|
||||
'missing_labels' => array_map(function ($f) { return COMPLETENESS_LABELS[$f] ?? $f; },
|
||||
array_merge($info['missing']['core'], $info['missing']['important'], $info['missing']['optional'])),
|
||||
'row' => $info['row'],
|
||||
]);
|
||||
|
||||
+26
-18
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* 软碎片列表接口 GET /api/fragment/soft_list.php
|
||||
* 参数:page / limit / table(所属表 persons|companies|social_accounts|media)/ level(core|important|supplementary)/ keyword
|
||||
* 返回:{ list, total, page, limit },每行含 完整度 score、缺失层级标签、名称、缺失字段、所属表、录入时间
|
||||
* 参数:page / limit / table(persons|companies|social_accounts|media)/ level(core|important|optional)/ keyword
|
||||
* 返回:{ list, total, page, limit }
|
||||
* 每行:{ table, table_label, id, name, overall 整体完整度, level 缺失层级,
|
||||
* layer_rates {core,important,optional}, missing_fields 缺失字段(按核心→重要→非必要优先级), created_at }
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
@@ -17,10 +19,10 @@ $level = trim($_REQUEST['level'] ?? '');
|
||||
$keyword = trim($_REQUEST['keyword'] ?? '');
|
||||
|
||||
$tableMap = [
|
||||
'persons' => ['label' => '人员', 'name' => 'full_name'],
|
||||
'companies' => ['label' => '企业', 'name' => 'display_name'],
|
||||
'social_accounts' => ['label' => '联系方式', 'name' => 'account_id'],
|
||||
'media' => ['label' => '媒体', 'name' => null], // media 需 JOIN social_accounts 取名
|
||||
'persons' => ['label' => '人员', 'name' => 'full_name'],
|
||||
'companies' => ['label' => '企业', 'name' => 'display_name'],
|
||||
'social_accounts' => ['label' => '联系方式', 'name' => 'account_id'],
|
||||
'media' => ['label' => '媒体', 'name' => null], // media 需 JOIN social_accounts 取名
|
||||
];
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
@@ -32,7 +34,7 @@ foreach ($tableMap as $t => $cfg) {
|
||||
}
|
||||
if ($t === 'media') {
|
||||
$rows = $pdo->query(
|
||||
"SELECT m.social_account_id AS id, sa.account_id AS name, m.updated_at AS created_at
|
||||
"SELECT m.social_account_id AS id, sa.account_id AS name, sa.created_at AS created_at
|
||||
FROM media_commercial_attributes m
|
||||
LEFT JOIN social_accounts sa ON sa.id = m.social_account_id
|
||||
WHERE m.is_incomplete = 1"
|
||||
@@ -48,24 +50,30 @@ foreach ($tableMap as $t => $cfg) {
|
||||
if ($level !== '' && $info['level'] !== $level) {
|
||||
continue;
|
||||
}
|
||||
$missingFields = array_merge($info['missing_core'], $info['missing_important'], $info['missing_supp']);
|
||||
// 缺失字段按优先级:核心 → 重要 → 非必要
|
||||
$missingFields = array_merge($info['missing']['core'], $info['missing']['important'], $info['missing']['optional']);
|
||||
$all[] = [
|
||||
'table' => $t,
|
||||
'table_label' => $cfg['label'],
|
||||
'id' => (int)$r['id'],
|
||||
'name' => $r['name'] ?: ('#' . $r['id']),
|
||||
'score' => $info['score'],
|
||||
'level' => $info['level'],
|
||||
'table' => $t,
|
||||
'table_label' => $cfg['label'],
|
||||
'id' => (int)$r['id'],
|
||||
'name' => $r['name'] ?: ('#' . $r['id']),
|
||||
'overall' => $info['overall'],
|
||||
'level' => $info['level'],
|
||||
'layer_rates' => [
|
||||
'core' => $info['layers']['core']['rate'],
|
||||
'important' => $info['layers']['important']['rate'],
|
||||
'optional' => $info['layers']['optional']['rate'],
|
||||
],
|
||||
'missing_fields' => array_map(function ($f) { return COMPLETENESS_LABELS[$f] ?? $f; }, $missingFields),
|
||||
'created_at' => $r['created_at'] ?? null,
|
||||
'created_at' => $r['created_at'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 按完整度升序(最残缺的排前面),再按时间倒序
|
||||
// 排序:整体完整度升序(最残缺在前),同分按时间倒序
|
||||
usort($all, function ($a, $b) {
|
||||
if ($a['score'] !== $b['score']) {
|
||||
return $a['score'] <=> $b['score'];
|
||||
if ($a['overall'] !== $b['overall']) {
|
||||
return $a['overall'] <=> $b['overall'];
|
||||
}
|
||||
return strcmp($b['created_at'] ?? '', $a['created_at'] ?? '');
|
||||
});
|
||||
|
||||
@@ -135,10 +135,10 @@ if (!$info) {
|
||||
Response::error('记录不存在');
|
||||
}
|
||||
|
||||
logCurrent('complete', 'fragment', $table, $id, ['fields' => array_keys($fields), 'score' => $info['score']]);
|
||||
logCurrent('complete', 'fragment', $table, $id, ['fields' => array_keys($fields), 'overall' => $info['overall']]);
|
||||
|
||||
Response::success([
|
||||
'score' => $info['score'],
|
||||
'overall' => $info['overall'],
|
||||
'level' => $info['level'],
|
||||
'is_complete' => $info['is_complete'],
|
||||
], $info['is_complete'] ? '补全完成' : '已更新,完整度 ' . $info['score'] . '%');
|
||||
], $info['is_complete'] ? '补全完成' : '已更新,整体完整度 ' . $info['overall'] . '%');
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* 碎片处理中心 - 顶部指标卡接口 GET /api/fragment/stats_overview.php
|
||||
* 返回:{ hard_total 硬碎片总数, soft_total 软碎片总数, month_new 本月新增,
|
||||
* month_processed 本月处理, pending 待处理碎片 }
|
||||
* 碎片处理中心 - 顶部概览接口 GET /api/fragment/stats_overview.php
|
||||
* 指标:
|
||||
* - hard_total 硬碎片待处理数(preliminary_data 未终结)
|
||||
* - soft_total 软碎片待处理数(四主表 is_incomplete=1)
|
||||
* - month_new 本月新增(硬碎片本月新增 + 软碎片本月新增)
|
||||
* - month_processed 本月处理(本月已转换硬碎片 + 本月已补全软碎片)
|
||||
* - cumulative 累计处理(历史已转换硬碎片 + 历史已补全软碎片)
|
||||
* - pending 待处理碎片(硬待处理 + 软待处理)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
@@ -11,39 +16,63 @@ require_once __DIR__ . '/../common/auth.php';
|
||||
checkPermission('preliminary');
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$monthStart = "DATE_FORMAT(CURDATE(), '%Y-%m-01')";
|
||||
|
||||
// 硬碎片:preliminary_data 中未终结(未转换/未废弃)的记录
|
||||
// 硬碎片待处理数
|
||||
$hardTotal = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status NOT IN ('已转换','已废弃')"
|
||||
)->fetchColumn();
|
||||
|
||||
// 软碎片:四张主表 is_incomplete=1 之和
|
||||
// 软碎片待处理数(四主表 is_incomplete=1 之和)
|
||||
$softTotal = 0;
|
||||
foreach (['companies', 'persons', 'social_accounts', 'media_commercial_attributes'] as $t) {
|
||||
$softTotal += (int)$pdo->query("SELECT COUNT(*) FROM `$t` WHERE is_incomplete = 1")->fetchColumn();
|
||||
}
|
||||
|
||||
// 本月新增(硬碎片按 created_at)
|
||||
$monthNew = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND created_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')"
|
||||
// 本月新增硬碎片(created_at 在本月)
|
||||
$hardMonthNew = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND created_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
|
||||
// 本月处理(已转换/已废弃且 processed_at 在本月)
|
||||
$monthProcessed = (int)$pdo->query(
|
||||
// 本月新增软碎片(is_incomplete=1 且本月创建;media 的创建时间取关联 social_accounts)
|
||||
$softMonthNew = 0;
|
||||
foreach (['companies', 'persons', 'social_accounts'] as $t) {
|
||||
$softMonthNew += (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM `$t` WHERE is_incomplete = 1 AND created_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
}
|
||||
$softMonthNew += (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM media_commercial_attributes m
|
||||
WHERE m.is_incomplete = 1
|
||||
AND EXISTS (SELECT 1 FROM social_accounts sa WHERE sa.id = m.social_account_id AND sa.created_at >= $monthStart)"
|
||||
)->fetchColumn();
|
||||
|
||||
// 本月已转换硬碎片
|
||||
$hardConvertedMonth = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data
|
||||
WHERE is_active = 1 AND status IN ('已转换','已废弃')
|
||||
AND processed_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')"
|
||||
WHERE is_active = 1 AND status = '已转换' AND processed_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
|
||||
// 待处理碎片
|
||||
$pending = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status = '待处理'"
|
||||
// 本月已补全软碎片(fragment 模块 complete 日志)
|
||||
$softCompletedMonth = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM system_logs WHERE action = 'complete' AND module = 'fragment' AND created_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
|
||||
// 历史累计已转换硬碎片
|
||||
$hardConvertedTotal = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status = '已转换'"
|
||||
)->fetchColumn();
|
||||
|
||||
// 历史累计已补全软碎片
|
||||
$softCompletedTotal = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM system_logs WHERE action = 'complete' AND module = 'fragment'"
|
||||
)->fetchColumn();
|
||||
|
||||
Response::success([
|
||||
'hard_total' => $hardTotal,
|
||||
'soft_total' => $softTotal,
|
||||
'month_new' => $monthNew,
|
||||
'month_processed' => $monthProcessed,
|
||||
'pending' => $pending,
|
||||
'hard_total' => $hardTotal,
|
||||
'soft_total' => $softTotal,
|
||||
'month_new' => $hardMonthNew + $softMonthNew,
|
||||
'month_processed' => $hardConvertedMonth + $softCompletedMonth,
|
||||
'cumulative' => $hardConvertedTotal + $softCompletedTotal,
|
||||
'pending' => $hardTotal + $softTotal,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user