feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理
清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
This commit is contained in:
1 parent
7cfd5d167e
commit
1e5aedb9ed
235 files changed
+11394
-9613
No files matched your search
@@ -16,7 +16,6 @@ from sqlalchemy import select
|
||||
from app.core.errors import ConflictError, NotFoundError, ValidationError
|
||||
from app.models import (
|
||||
ShippingBusinessSequence,
|
||||
ShippingCase,
|
||||
ShippingCustomer,
|
||||
ShippingCustomerExternalRef,
|
||||
ShippingCustomerIdentifier,
|
||||
@@ -27,6 +26,7 @@ from app.models import (
|
||||
ShippingOrderCustomerMatch,
|
||||
ShippingCustomerShadowMatch,
|
||||
ShippingCustomerShadowResolution,
|
||||
ShippingNotice,
|
||||
)
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ def _build_customer_lifecycle_impact(customer: ShippingCustomer) -> dict[str, An
|
||||
}
|
||||
shadow_normalized = len(matched_resolution_ids)
|
||||
blockers = {
|
||||
'business_cases': db.session.query(ShippingCase.id).filter_by(customer_id=customer.id).count(),
|
||||
'shipping_notices': db.session.query(ShippingNotice.id).filter_by(customer_id=customer.id).count(),
|
||||
'business_sequences': db.session.query(ShippingBusinessSequence.id).filter_by(customer_id=customer.id).count(),
|
||||
'external_references': db.session.query(ShippingCustomerExternalRef.id).filter_by(customer_id=customer.id).count(),
|
||||
'order_customer_matches': db.session.query(ShippingOrderCustomerMatch.id).filter_by(customer_id=customer.id).count(),
|
||||
|
||||
@@ -17,7 +17,6 @@ from sqlalchemy.exc import IntegrityError
|
||||
from app import db
|
||||
from app.core.errors import ConflictError, NotFoundError, ValidationError
|
||||
from app.models import (
|
||||
ShippingCase,
|
||||
ShippingCustomer,
|
||||
ShippingCustomerExternalRef,
|
||||
ShippingCustomerIdentifier,
|
||||
@@ -25,6 +24,7 @@ from app.models import (
|
||||
ShippingCustomerSite,
|
||||
ShippingCustomerSiteIdentifier,
|
||||
ShippingIdentityEvidence,
|
||||
ShippingNotice,
|
||||
)
|
||||
from app.services.shipping_notice.customer_normalization import (
|
||||
clean_text,
|
||||
@@ -117,7 +117,7 @@ def serialize_customer(
|
||||
record: ShippingCustomer,
|
||||
*,
|
||||
include_identifiers: bool = False,
|
||||
case_count: int | None = None,
|
||||
notice_count: int | None = None,
|
||||
identifier_count: int | None = None,
|
||||
identity_evidence_count: int | None = None,
|
||||
) -> dict[str, Any]:
|
||||
@@ -127,7 +127,7 @@ def serialize_customer(
|
||||
Args:
|
||||
record: 标准客户 ORM 记录。
|
||||
include_identifiers: 是否附带识别证据明细。
|
||||
case_count: 列表查询预聚合的业务单数量;为空时现场查询。
|
||||
notice_count: 列表查询预聚合的发货通知数量;为空时现场查询。
|
||||
identifier_count: 历史固定类型证据数量,仅供存量审计显示。
|
||||
identity_evidence_count: 配置化客户主体证据数量;为空时现场查询。
|
||||
Returns:
|
||||
@@ -144,7 +144,7 @@ def serialize_customer(
|
||||
'updated_by_id': record.updated_by_id,
|
||||
'created_at': record.created_at.isoformat() if record.created_at else None,
|
||||
'updated_at': record.updated_at.isoformat() if record.updated_at else None,
|
||||
'case_count': case_count if case_count is not None else db.session.query(ShippingCase.id).filter_by(customer_id=record.id).count(),
|
||||
'notice_count': notice_count if notice_count is not None else db.session.query(ShippingNotice.id).filter_by(customer_id=record.id).count(),
|
||||
'identifier_count': identifier_count if identifier_count is not None else db.session.query(ShippingCustomerIdentifier.id).filter_by(customer_id=record.id).count(),
|
||||
'identity_evidence_count': identity_evidence_count if identity_evidence_count is not None else db.session.query(
|
||||
ShippingIdentityEvidence.id,
|
||||
@@ -173,9 +173,9 @@ def list_customers(params: dict[str, Any]) -> dict[str, Any]:
|
||||
Returns:
|
||||
items、total、page、page_size、pages。
|
||||
"""
|
||||
case_counts = (
|
||||
db.session.query(ShippingCase.customer_id.label('customer_id'), func.count(ShippingCase.id).label('case_count'))
|
||||
.group_by(ShippingCase.customer_id)
|
||||
notice_counts = (
|
||||
db.session.query(ShippingNotice.customer_id.label('customer_id'), func.count(ShippingNotice.id).label('notice_count'))
|
||||
.group_by(ShippingNotice.customer_id)
|
||||
.subquery()
|
||||
)
|
||||
identifier_counts = (
|
||||
@@ -207,12 +207,12 @@ def list_customers(params: dict[str, Any]) -> dict[str, Any]:
|
||||
query = (
|
||||
db.session.query(
|
||||
ShippingCustomer,
|
||||
func.coalesce(case_counts.c.case_count, 0),
|
||||
func.coalesce(notice_counts.c.notice_count, 0),
|
||||
func.coalesce(identifier_counts.c.identifier_count, 0),
|
||||
func.coalesce(identity_evidence_counts.c.identity_evidence_count, 0)
|
||||
+ func.coalesce(site_identity_evidence_counts.c.identity_evidence_count, 0),
|
||||
)
|
||||
.outerjoin(case_counts, case_counts.c.customer_id == ShippingCustomer.id)
|
||||
.outerjoin(notice_counts, notice_counts.c.customer_id == ShippingCustomer.id)
|
||||
.outerjoin(identifier_counts, identifier_counts.c.customer_id == ShippingCustomer.id)
|
||||
.outerjoin(identity_evidence_counts, identity_evidence_counts.c.customer_id == ShippingCustomer.id)
|
||||
.outerjoin(site_identity_evidence_counts, site_identity_evidence_counts.c.customer_id == ShippingCustomer.id)
|
||||
@@ -244,10 +244,10 @@ def list_customers(params: dict[str, Any]) -> dict[str, Any]:
|
||||
return {
|
||||
'items': [
|
||||
serialize_customer(
|
||||
customer, case_count=int(case_count), identifier_count=int(identifier_count),
|
||||
customer, notice_count=int(notice_count), identifier_count=int(identifier_count),
|
||||
identity_evidence_count=int(identity_evidence_count),
|
||||
)
|
||||
for customer, case_count, identifier_count, identity_evidence_count in items
|
||||
for customer, notice_count, identifier_count, identity_evidence_count in items
|
||||
],
|
||||
'total': total,
|
||||
'page': page,
|
||||
|
||||
Reference in new issue
Block a user