|
|
@@ -698,7 +698,9 @@ public class InstitutionService {
|
|
|
// 复制非 null 属性到已有实体 (排除 id 和 institutionId 避免覆盖)
|
|
|
BeanUtil.copyProperties(dto, existing, "id", "institutionId");
|
|
|
|
|
|
- // 金额/限额单独处理,确保变更生效
|
|
|
+ // 金额/限额单独处理,确保变更生效(先记旧值再设新值)
|
|
|
+ BigDecimal oldAmount = existing.getAmount();
|
|
|
+ BigDecimal oldSingleLimit = existing.getSingleLimit();
|
|
|
if (dto.getAmount() != null) existing.setAmount(dto.getAmount());
|
|
|
if (dto.getSingleLimit() != null) existing.setSingleLimit(dto.getSingleLimit());
|
|
|
|
|
|
@@ -723,6 +725,21 @@ public class InstitutionService {
|
|
|
|
|
|
institutionMapper.updateById(existing);
|
|
|
|
|
|
+ // 制度金额变更 → 同步更新该制度下所有员工额度的 total_amount + available_amount
|
|
|
+ if (dto.getAmount() != null && oldAmount != null
|
|
|
+ && dto.getAmount().compareTo(oldAmount) != 0) {
|
|
|
+ BigDecimal delta = dto.getAmount().subtract(oldAmount);
|
|
|
+ int updated = quotaMapper.update(null,
|
|
|
+ new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<QuotaEntity>()
|
|
|
+ .eq(QuotaEntity::getInstitutionId, existing.getInstitutionId())
|
|
|
+ .setSql("total_amount = total_amount + " + delta.toPlainString())
|
|
|
+ .setSql("available_amount = CASE WHEN status IN ('QUOTA_ACTIVE','QUOTA_EXHAUSTED') "
|
|
|
+ + "THEN available_amount + " + delta.toPlainString()
|
|
|
+ + " ELSE available_amount END"));
|
|
|
+ log.info("制度金额变更,已同步更新 {} 条额度: {} → {}, delta={}",
|
|
|
+ updated, oldAmount, dto.getAmount(), delta);
|
|
|
+ }
|
|
|
+
|
|
|
// 制度生效/失效时同步更新该制度下所有额度状态
|
|
|
// 对应 Python modify_institution_service 第 922-937 行
|
|
|
if (dto.getEffective() != null) {
|