|
|
@@ -590,52 +590,51 @@ class InstitutionService:
|
|
|
return None
|
|
|
|
|
|
# 合并本地DB的自定义字段(支付宝不包含的字段)
|
|
|
+ # 无条件覆盖,保证前端有数据
|
|
|
try:
|
|
|
crud = InstitutionCRUD(auth)
|
|
|
local_obj = await crud.get(institution_id=institution_id, enterprise_id=enterprise_id)
|
|
|
if local_obj:
|
|
|
local_dict = InstitutionListOutSchema.model_validate(local_obj).model_dump()
|
|
|
for field in ("applicable_scope", "grant_mode", "period_type", "amount",
|
|
|
- "single_limit", "effective_time_type", "employee_ids",
|
|
|
- "scope_owner_id_list", "enterprise_id", "status",
|
|
|
- "created_time", "updated_time", "consult_mode"):
|
|
|
- if field in local_dict and local_dict[field] is not None:
|
|
|
- result_dict[field] = local_dict[field]
|
|
|
+ "single_limit", "effective_time_type", "enterprise_id", "status",
|
|
|
+ "created_time", "updated_time", "consult_mode",
|
|
|
+ "effective_start_date", "effective_end_date", "institution_name",
|
|
|
+ "institution_desc", "expense_type", "scene_type", "currency"):
|
|
|
+ val = local_dict.get(field)
|
|
|
+ if val is not None:
|
|
|
+ result_dict[field] = val
|
|
|
except Exception as e:
|
|
|
log.warning(f"合并本地DB字段失败: {e}")
|
|
|
|
|
|
- # 从支付宝 owner_id_list 映射为前端需要的 employee_ids
|
|
|
+ # 从收入额度记录(quota records)获取员工ID列表
|
|
|
+ if not result_dict.get("employee_ids"):
|
|
|
+ from app.plugin.module_payment.expense.quota.model import QuotaModel
|
|
|
+ quota_stmt = select(QuotaModel).where(
|
|
|
+ QuotaModel.institution_id == institution_id,
|
|
|
+ QuotaModel.employee_id.isnot(None),
|
|
|
+ QuotaModel.employee_id != "",
|
|
|
+ )
|
|
|
+ quota_result = await auth.db.execute(quota_stmt)
|
|
|
+ emp_ids = list(set(
|
|
|
+ q.employee_id for q in quota_result.scalars().all() if q.employee_id
|
|
|
+ ))
|
|
|
+ if emp_ids:
|
|
|
+ result_dict["employee_ids"] = emp_ids
|
|
|
+ result_dict["scope_owner_id_list"] = emp_ids
|
|
|
+
|
|
|
+ # 从支付宝 owner_id_list 映射(若以上均未取到)
|
|
|
owner_ids = result_dict.get("owner_id_list")
|
|
|
- adapter_type = result_dict.get("adapter_type")
|
|
|
if not result_dict.get("employee_ids") and owner_ids and isinstance(owner_ids, list):
|
|
|
result_dict["employee_ids"] = owner_ids
|
|
|
- if not result_dict.get("scope_owner_id_list") and owner_ids and isinstance(owner_ids, list):
|
|
|
result_dict["scope_owner_id_list"] = owner_ids
|
|
|
+
|
|
|
+ # adapter_type → applicable_scope 兜底
|
|
|
+ adapter_type = result_dict.get("adapter_type")
|
|
|
if adapter_type and not result_dict.get("applicable_scope"):
|
|
|
scope_map = {"EMPLOYEE_SELECT": "employee", "EMPLOYEE_DEPARTMENT": "department", "EMPLOYEE_ALL": "all"}
|
|
|
result_dict["applicable_scope"] = scope_map.get(adapter_type, result_dict.get("applicable_scope", "none"))
|
|
|
|
|
|
- # 补充:从 scope 接口获取员工列表(detailinfo.query 可能不返回 owner_id_list)
|
|
|
- if not result_dict.get("employee_ids"):
|
|
|
- try:
|
|
|
- scope_result = await InstitutionScopeService.scopepageinfo_query_service(
|
|
|
- auth=auth,
|
|
|
- institution_id=institution_id,
|
|
|
- enterprise_id=enterprise_id,
|
|
|
- page_num=1,
|
|
|
- page_size=500,
|
|
|
- )
|
|
|
- owner_list = scope_result.get("owner_id_list", []) or []
|
|
|
- adapter = scope_result.get("adapter_type")
|
|
|
- if owner_list and adapter in ("EMPLOYEE_SELECT", None):
|
|
|
- result_dict["employee_ids"] = owner_list
|
|
|
- result_dict["scope_owner_id_list"] = owner_list
|
|
|
- if adapter and not result_dict.get("applicable_scope"):
|
|
|
- scope_map = {"EMPLOYEE_SELECT": "employee", "EMPLOYEE_DEPARTMENT": "department", "EMPLOYEE_ALL": "all"}
|
|
|
- result_dict["applicable_scope"] = scope_map.get(adapter, result_dict.get("applicable_scope", "none"))
|
|
|
- except Exception as e:
|
|
|
- log.debug(f"查询 scope 补充员工列表失败(不影响主流程): {e}")
|
|
|
-
|
|
|
# 补充本地规则和额度
|
|
|
from app.plugin.module_payment.expense.rule.model import ExpenseRuleModel
|
|
|
from app.plugin.module_payment.expense.quota.model import QuotaModel
|