mirror of
https://github.com/primedigitaltech/market-assistant.git
synced 2026-07-22 08:01:34 +08:00
新增 matrix_group_label 与 jd_competitor_report 同源路径解析;API 使用 report_group 字符串;摘要返回 report_group_options;搜索行按 SKU 从合并表回填细类;导出含报告细类列;前端下拉展示饼干/米等名称。 Made-with: Cursor
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
"""任务数据集 ORM 行 ↔ API / 导出用的扁平字典。"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from .csv_schema import (
|
|
COMMENT_CSV_COLUMNS,
|
|
COMMENT_CSV_TO_FIELD,
|
|
DETAIL_CSV_COLUMNS,
|
|
DETAIL_CSV_TO_FIELD,
|
|
JD_SEARCH_INTERNAL_KEYS,
|
|
MERGED_INTERNAL_KEYS,
|
|
)
|
|
from .models import JdJobCommentRow, JdJobDetailRow, JdJobMergedRow, JdJobSearchRow
|
|
|
|
DETAIL_FIELDS_ORDER: tuple[str, ...] = tuple(DETAIL_CSV_TO_FIELD[c] for c in DETAIL_CSV_COLUMNS)
|
|
COMMENT_FIELDS_ORDER: tuple[str, ...] = tuple(COMMENT_CSV_TO_FIELD[c] for c in COMMENT_CSV_COLUMNS)
|
|
MERGED_FIELDS_ORDER: tuple[str, ...] = MERGED_INTERNAL_KEYS
|
|
|
|
|
|
def search_row_to_dict(r: JdJobSearchRow) -> dict[str, Any]:
|
|
out: dict[str, Any] = {"id": r.id, "row_index": r.row_index}
|
|
for k in JD_SEARCH_INTERNAL_KEYS:
|
|
out[k] = getattr(r, k) or ""
|
|
out["matrix_group_label"] = r.matrix_group_label or ""
|
|
return out
|
|
|
|
|
|
def detail_row_to_dict(r: JdJobDetailRow) -> dict[str, Any]:
|
|
out: dict[str, Any] = {"id": r.id, "row_index": r.row_index}
|
|
for k in DETAIL_FIELDS_ORDER:
|
|
out[k] = getattr(r, k) or ""
|
|
out["matrix_group_label"] = r.matrix_group_label or ""
|
|
return out
|
|
|
|
|
|
def comment_row_to_dict(r: JdJobCommentRow) -> dict[str, Any]:
|
|
out: dict[str, Any] = {"id": r.id, "row_index": r.row_index}
|
|
for k in COMMENT_FIELDS_ORDER:
|
|
out[k] = getattr(r, k) or ""
|
|
return out
|
|
|
|
|
|
def merged_row_to_dict(r: JdJobMergedRow) -> dict[str, Any]:
|
|
out: dict[str, Any] = {"id": r.id, "row_index": r.row_index}
|
|
for k in MERGED_FIELDS_ORDER:
|
|
out[k] = getattr(r, k) or ""
|
|
out["matrix_group_label"] = r.matrix_group_label or ""
|
|
return out
|