Merge branch 'dev' into runny827
feat(training): 新增精益培训视频与周任务管理 # Conflicts: # backend/app/models/__init__.py
This commit is contained in:
1 parent
85d27e9ffa
commit
91b7233872
812 files changed
+73763
-18908
No files matched your search
@@ -23,7 +23,7 @@ from app.models import (
|
||||
ShippingCustomerImportRow,
|
||||
ShippingCustomerLifecycleEvent,
|
||||
ShippingCustomerSite,
|
||||
ShippingOrderCustomerMatch,
|
||||
ShippingOrderTask,
|
||||
ShippingCustomerShadowMatch,
|
||||
ShippingCustomerShadowResolution,
|
||||
ShippingNotice,
|
||||
@@ -62,10 +62,19 @@ def _build_customer_lifecycle_impact(customer: ShippingCustomer) -> dict[str, An
|
||||
}
|
||||
shadow_normalized = len(matched_resolution_ids)
|
||||
blockers = {
|
||||
'shipping_notices': db.session.query(ShippingNotice.id).filter_by(customer_id=customer.id).count(),
|
||||
'shipping_notices': (
|
||||
db.session.query(ShippingNotice.id)
|
||||
.join(ShippingOrderTask, ShippingOrderTask.id == ShippingNotice.order_task_id)
|
||||
.join(ShippingCustomerShadowResolution, ShippingCustomerShadowResolution.candidate_id == ShippingOrderTask.candidate_id)
|
||||
.filter(
|
||||
ShippingCustomerShadowResolution.confirmed_customer_id == customer.id,
|
||||
)
|
||||
.distinct()
|
||||
.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(),
|
||||
'confirmed_customer_resolutions': db.session.query(ShippingCustomerShadowResolution.id).filter_by(confirmed_customer_id=customer.id).count(),
|
||||
'import_target_rows': db.session.query(ShippingCustomerImportRow.id).filter_by(target_customer_id=customer.id).count(),
|
||||
'import_result_rows': db.session.query(ShippingCustomerImportRow.id).filter_by(result_customer_id=customer.id).count(),
|
||||
'shadow_top_candidates': db.session.query(ShippingCustomerShadowResolution.id).filter_by(top_customer_id=customer.id).count(),
|
||||
|
||||
@@ -25,6 +25,8 @@ from app.models import (
|
||||
ShippingCustomerSiteIdentifier,
|
||||
ShippingIdentityEvidence,
|
||||
ShippingNotice,
|
||||
ShippingOrderTask,
|
||||
ShippingCustomerShadowResolution,
|
||||
)
|
||||
from app.services.shipping_notice.customer_normalization import (
|
||||
clean_text,
|
||||
@@ -144,7 +146,16 @@ 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,
|
||||
'notice_count': notice_count if notice_count is not None else db.session.query(ShippingNotice.id).filter_by(customer_id=record.id).count(),
|
||||
'notice_count': notice_count if notice_count is not None else (
|
||||
db.session.query(ShippingNotice.id)
|
||||
.join(ShippingOrderTask, ShippingOrderTask.id == ShippingNotice.order_task_id)
|
||||
.join(ShippingCustomerShadowResolution, ShippingCustomerShadowResolution.candidate_id == ShippingOrderTask.candidate_id)
|
||||
.filter(
|
||||
ShippingCustomerShadowResolution.confirmed_customer_id == record.id,
|
||||
)
|
||||
.distinct()
|
||||
.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,
|
||||
@@ -174,8 +185,11 @@ def list_customers(params: dict[str, Any]) -> dict[str, Any]:
|
||||
items、total、page、page_size、pages。
|
||||
"""
|
||||
notice_counts = (
|
||||
db.session.query(ShippingNotice.customer_id.label('customer_id'), func.count(ShippingNotice.id).label('notice_count'))
|
||||
.group_by(ShippingNotice.customer_id)
|
||||
db.session.query(ShippingCustomerShadowResolution.confirmed_customer_id.label('customer_id'), func.count(ShippingNotice.id).label('notice_count'))
|
||||
.join(ShippingOrderTask, ShippingOrderTask.candidate_id == ShippingCustomerShadowResolution.candidate_id)
|
||||
.join(ShippingNotice, ShippingNotice.order_task_id == ShippingOrderTask.id)
|
||||
.filter(ShippingCustomerShadowResolution.confirmed_customer_id.isnot(None))
|
||||
.group_by(ShippingCustomerShadowResolution.confirmed_customer_id)
|
||||
.subquery()
|
||||
)
|
||||
identifier_counts = (
|
||||
|
||||
@@ -19,6 +19,7 @@ from app.models import (
|
||||
ShippingOrderField,
|
||||
ShippingInventoryParsingProfile,
|
||||
ShippingInventoryConfigurationTestRun, ShippingInventoryStructureAnalysis,
|
||||
ShippingNoticeLine, ShippingNoticeLineInventoryMatch,
|
||||
ShippingExcelTemplate,
|
||||
ShippingInventorySourceParsingBindingAudit,
|
||||
ShippingReceiptReportConfig,
|
||||
@@ -497,7 +498,11 @@ def delete_source(source_id: int) -> None:
|
||||
for candidates in [(rule.action_payload_json or {}).get('source_codes', [])]
|
||||
if isinstance(candidates, list)
|
||||
)
|
||||
has_task = ShippingNotice.query.filter_by(inventory_source_code=source_code).count() > 0
|
||||
has_task = db.session.query(ShippingNoticeLine.id).filter(
|
||||
ShippingNoticeLine.inventory_source_code == source_code,
|
||||
).first() is not None or db.session.query(ShippingNoticeLineInventoryMatch.id).filter(
|
||||
ShippingNoticeLineInventoryMatch.inventory_source_code == source_code,
|
||||
).first() is not None
|
||||
has_export_run = any(
|
||||
source_code in {str(code).strip().upper() for code in source_codes}
|
||||
for run in ScheduleRun.query.all()
|
||||
|
||||
@@ -235,6 +235,22 @@ def create_user(data: dict[str, Any]) -> dict:
|
||||
|
||||
|
||||
def update_user(user_id: int, data: dict[str, Any]) -> dict:
|
||||
"""
|
||||
更新管理端用户资料,可选同步 Casdoor 改密。
|
||||
|
||||
核心逻辑:先写入本地字段;新密码与当前哈希相同则直接拒绝,避免 Casdoor 返回含 old password 的文案被误判成 401。
|
||||
|
||||
Args:
|
||||
user_id: 目标用户主键。
|
||||
data: 管理端提交的字段,password 为空表示不改密。
|
||||
|
||||
Returns:
|
||||
{'status': 'ok'}。
|
||||
|
||||
Raises:
|
||||
NotFoundError: 用户不存在。
|
||||
AppError: 邮箱非法、新密码未变化或 Casdoor 同步失败。
|
||||
"""
|
||||
user = db.session.get(User, user_id)
|
||||
if not user:
|
||||
raise NotFoundError('User not found')
|
||||
@@ -259,6 +275,12 @@ def update_user(user_id: int, data: dict[str, Any]) -> dict:
|
||||
if 'feature_permissions' in data or 'role' in data:
|
||||
permissions_payload = data.get('feature_permissions', user.feature_permissions)
|
||||
user.set_feature_permissions(permissions_payload)
|
||||
if new_password and user.check_password(new_password):
|
||||
raise AppError(
|
||||
code='AUTH.PASSWORD_UNCHANGED',
|
||||
message='New password must differ from the current password',
|
||||
http_status=400,
|
||||
)
|
||||
if new_password:
|
||||
user.set_password(new_password)
|
||||
if 'agent_ids' in data:
|
||||
|
||||
Reference in new issue
Block a user