|
@@ -117,7 +117,7 @@ async def create_institution_controller(
|
|
|
scope_data = None
|
|
scope_data = None
|
|
|
adapter_type = data.get("applicable_scope")
|
|
adapter_type = data.get("applicable_scope")
|
|
|
if adapter_type and adapter_type not in ("NONE", "none"):
|
|
if adapter_type and adapter_type not in ("NONE", "none"):
|
|
|
- ADAPTER_TYPE_MAP = {"all": "EMPLOYEE_ALL", "employee": "EMPLOYEE_SELECT", "department": "DEPARTMENT_SELECT"}
|
|
|
|
|
|
|
+ ADAPTER_TYPE_MAP = {"all": "EMPLOYEE_ALL", "employee": "EMPLOYEE_SELECT", "department": "EMPLOYEE_DEPARTMENT"}
|
|
|
mapped_adapter = ADAPTER_TYPE_MAP.get(adapter_type, adapter_type)
|
|
mapped_adapter = ADAPTER_TYPE_MAP.get(adapter_type, adapter_type)
|
|
|
scope_data = {
|
|
scope_data = {
|
|
|
"adapter_type": mapped_adapter,
|
|
"adapter_type": mapped_adapter,
|
|
@@ -295,22 +295,46 @@ async def modify_institution_controller(
|
|
|
# 提取 scope 变更数据(需与基础修改分两次请求)
|
|
# 提取 scope 变更数据(需与基础修改分两次请求)
|
|
|
applicable_scope = data.get("applicable_scope", "")
|
|
applicable_scope = data.get("applicable_scope", "")
|
|
|
scope_info = None
|
|
scope_info = None
|
|
|
|
|
+ enterprise_id = data.get("enterprise_id", "")
|
|
|
if applicable_scope and applicable_scope not in ("NONE", "none"):
|
|
if applicable_scope and applicable_scope not in ("NONE", "none"):
|
|
|
- enterprise_id = data.get("enterprise_id", "")
|
|
|
|
|
- ADAPTER_MAP = {"all": "EMPLOYEE_ALL", "employee": "EMPLOYEE_SELECT", "department": "DEPARTMENT_SELECT"}
|
|
|
|
|
|
|
+ ADAPTER_MAP = {"all": "EMPLOYEE_ALL", "employee": "EMPLOYEE_SELECT", "department": "EMPLOYEE_DEPARTMENT"}
|
|
|
|
|
+ new_adapter = ADAPTER_MAP.get(applicable_scope, applicable_scope)
|
|
|
|
|
+
|
|
|
|
|
+ # 查询当前scope:计算旧→新的差异
|
|
|
|
|
+ old_ids = []
|
|
|
|
|
+ try:
|
|
|
|
|
+ scope_old = await InstitutionScopeService.scopepageinfo_query_service(
|
|
|
|
|
+ auth=auth, institution_id=institution_id, enterprise_id=enterprise_id,
|
|
|
|
|
+ page_num=1, page_size=500,
|
|
|
|
|
+ )
|
|
|
|
|
+ old_ids = [str(i) for i in (scope_old.get("owner_id_list") or []) if i]
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ log.warning(f"查询旧scope失败,将全量覆盖: institution_id={institution_id}")
|
|
|
|
|
+
|
|
|
|
|
+ new_ids_raw = data.get("scope_owner_id_list") or []
|
|
|
|
|
+ new_ids = [str(i) for i in new_ids_raw if i is not None and str(i).strip()]
|
|
|
|
|
+
|
|
|
|
|
+ # 计算差异
|
|
|
|
|
+ old_set, new_set = set(old_ids), set(new_ids)
|
|
|
|
|
+ add_ids = list(new_set - old_set)
|
|
|
|
|
+ delete_ids = list(old_set - new_set)
|
|
|
|
|
+
|
|
|
scope_info = {
|
|
scope_info = {
|
|
|
"enterprise_id": enterprise_id,
|
|
"enterprise_id": enterprise_id,
|
|
|
- "adapter_type": ADAPTER_MAP.get(applicable_scope, applicable_scope),
|
|
|
|
|
|
|
+ "adapter_type": new_adapter,
|
|
|
"owner_type": "ENTERPRISE_PAY_UID",
|
|
"owner_type": "ENTERPRISE_PAY_UID",
|
|
|
}
|
|
}
|
|
|
- if applicable_scope in ("employee", "department"):
|
|
|
|
|
- owner_ids = data.get("scope_owner_id_list") or []
|
|
|
|
|
- valid_ids = [str(i) for i in owner_ids if i is not None and str(i).strip()]
|
|
|
|
|
- if valid_ids:
|
|
|
|
|
- scope_info["add_owner_id_list"] = valid_ids
|
|
|
|
|
- else:
|
|
|
|
|
- scope_info = None
|
|
|
|
|
- log.info("适用范围为按员工/按部门但未提供员工/部门ID,跳过 scope 修改")
|
|
|
|
|
|
|
+ if add_ids:
|
|
|
|
|
+ scope_info["add_owner_id_list"] = add_ids
|
|
|
|
|
+ if delete_ids:
|
|
|
|
|
+ scope_info["delete_owner_id_list"] = delete_ids
|
|
|
|
|
+ log.info(
|
|
|
|
|
+ f"scope 差异: add={add_ids}, delete={delete_ids}, "
|
|
|
|
|
+ f"old_count={len(old_ids)}, new_count={len(new_ids)}"
|
|
|
|
|
+ )
|
|
|
|
|
+ if not add_ids and not delete_ids:
|
|
|
|
|
+ scope_info = None
|
|
|
|
|
+ log.info("scope 无变化,跳过")
|
|
|
# 从请求中移除 scope 数据,避免与基础修改冲突
|
|
# 从请求中移除 scope 数据,避免与基础修改冲突
|
|
|
data.pop("modify_scope_info", None)
|
|
data.pop("modify_scope_info", None)
|
|
|
|
|
|