1
0
forked from erp-dev/erp

fix: added name filter for api_man apis, fixed plate_orders search exclude id (only search via design_code)

This commit is contained in:
2025-12-09 14:15:31 +08:00
parent a36a7e5265
commit 86d0c916ca
8 changed files with 8391 additions and 35 deletions

View File

@@ -3,6 +3,7 @@ from typing import Optional, Dict, Any, List
from pydantic import BaseModel, Field, computed_field
from enum import Enum
import json
from asgiref.sync import sync_to_async
class Product(BaseModel):
@@ -243,10 +244,14 @@ async def fetch_products_from_mingdaoyun(page: int = 1, page_size: int = 100) ->
'pageIndex': page,
'pageSize': page_size,
'sortId': 'ctime',
'isAsc': False,
'isAsc': True,
}
)
data = response.get('data')
if data:
print(f'[product-sync] page={page} size={page_size} rows={len(data.get("rows", []))} total={data.get("total")}')
else:
print(f'[product-sync] page={page} size={page_size} received empty data')
if not data:
return [], 0
@@ -271,13 +276,95 @@ async def fetch_customers_from_mingdaoyun(page: int = 1, page_size: int = 100) -
'pageIndex': page,
'pageSize': page_size,
'sortId': 'ctime',
'isAsc': False,
'isAsc': True,
}
)
data = response.get('data')
if data:
print(f'[customer-sync] page={page} size={page_size} rows={len(data.get("rows", []))} total={data.get("total")}')
else:
print(f'[customer-sync] page={page} size={page_size} received empty data')
if not data:
return [], 0
customers = [pick_customer(item) for item in data.get('rows', [])]
total_count = data.get('total', 0)
return customers, total_count
fabric_type_map = {
'name': '62d52f4b8d2972284492de61',
}
class Fabric(BaseModel):
"""面料模型 - 请在此填入你的字段"""
name: str
def pick_fabric(fields: dict) -> Fabric:
"""
从字段字典中提取面料信息
"""
data = {k: fields.get(v, '') for k, v in fabric_type_map.items()}
return Fabric(**data)
async def sync_fabric_from_mingdaoyun(page: int = 1, page_size: int = 100) -> int:
"""
从明道云同步面料数据
"""
client = MingDaoYunClient(
app_key='208e55fea5cea59f',
sign='MWU0YmViYjkwZmM1ZDIzYzRiN2U3ZGQ4MmE4ZGNkMjc0MWM1ZmQ2ZjkwMjljODE4YmNkZTBhMzA0OTU2YzE2NA==',
base_url="https://api.mingdao.com"
)
response = await client.post(
endpoint='/v2/open/worksheet/getFilterRows',
data={
'worksheetId': '668ba100fb551c850214067d',
'pageIndex': page,
'pageSize': page_size,
'sortId': 'ctime',
'isAsc': False,
}
)
data = response.get('data')
if data:
rows = data.get("rows", [])
print(f'[fabric-sync] fetch rows={len(rows)} total={data.get("total")}')
if rows:
print(f'[fabric-sync] first row keys: {list(rows[0].keys())[:10]}')
print(f'[fabric-sync] first row sample: {rows[0]}')
else:
print(f'[fabric-sync] fetch empty data (page={page}, size={page_size})')
if not data:
return [], 0
fabrics = [pick_fabric(item) for item in data.get('rows', [])]
total_count = data.get('total', 0)
await sync_to_async(_create_fabric_quick_inputs)(
page,
page_size,
fabrics
)
return total_count
def _create_fabric_quick_inputs(page: int, page_size: int, fabrics: list[Fabric]) -> None:
from basic_info import models as basic_models
total = len(fabrics)
created_count = 0
sample_names = [fabric.name for fabric in fabrics[:5]]
print(f'[fabric-sync] page={page} size={page_size} fetched={total}')
print(f'[fabric-sync] sample names: {sample_names}')
for fabric in fabrics:
if not fabric.name:
continue
obj, created = basic_models.QuickInput.objects.update_or_create(
name=fabric.name,
group='布料名',
defaults={'value': fabric.name},
)
if created:
created_count += 1
print(f'[fabric-sync] page={page} new_records={created_count} updated_or_existing={total - created_count}')