Forráskód Böngészése

fix: 手工批量发放后保存额度记录到本地pay_expense_quota

- issue_batch_create_service新增:将每条员工额度写入pay_expense_quota
- 确保额度管理页面立即显示手工发放的额度数据
- 员工维度、金额、有效期、状态均为ACTIVE
alphah 2 hete
szülő
commit
9ec1345ddf

+ 33 - 0
backend/app/plugin/module_payment/expense/quota/service.py

@@ -419,6 +419,39 @@ class QuotaService:
         except Exception as e:
             log.warning(f"保存发放批次记录失败(不影响发放): {e}")
 
+        # 保存每条额度到 pay_expense_quota(确保额度管理页面有数据)
+        try:
+            from app.plugin.module_payment.expense.quota.model import QuotaModel
+            from app.plugin.module_payment.expense.quota.enums import QuotaStatusEnum
+            from sqlalchemy import insert
+            tenant_id = auth.user.tenant_id if auth.user else 1
+            effective_start = datetime.strptime(data.effective_start_date, "%Y-%m-%d %H:%M:%S") if data.effective_start_date else None
+            effective_end = datetime.strptime(data.effective_end_date, "%Y-%m-%d %H:%M:%S") if data.effective_end_date else None
+            if data.issue_target_info_list:
+                for item in data.issue_target_info_list:
+                    try:
+                        quota_amount = Decimal(item.issue_quota)
+                    except Exception:
+                        quota_amount = Decimal("0")
+                    stmt = insert(QuotaModel).values(
+                        employee_id=item.owner_id or "",
+                        institution_id=data.institution_id,
+                        quota_id=result.issue_batch_id,
+                        out_biz_no=f"batch_{data.batch_no}_{item.owner_id}",
+                        total_amount=quota_amount,
+                        available_amount=quota_amount,
+                        status=QuotaStatusEnum.QUOTA_ACTIVE.value,
+                        valid_from=effective_start,
+                        valid_to=effective_end,
+                        enterprise_id=data.enterprise_id,
+                        tenant_id=tenant_id,
+                    )
+                    await auth.db.execute(stmt)
+                await auth.db.flush()
+                log.info(f"手工发放 - 保存 {len(data.issue_target_info_list)} 条额度记录到本地")
+        except Exception as e:
+            log.warning(f"保存额度记录到本地失败(不影响发放): {e}")
+
         # 组装校验失败列表
         failed_list = None
         if hasattr(result, 'issue_quota_check_failed_list') and result.issue_quota_check_failed_list: