fix:刷新标记失效时追加备注而不是覆盖

This commit is contained in:
2026-11-09 11:24:32 +08:00
parent f38f11ae96
commit b90252c093
2 changed files with 15 additions and 6 deletions
@@ -229,7 +229,8 @@ func isRockTokenNotFoundError(err error) bool {
// markTokenAbnormalByRefresh 把刷新时确认已失效的 Token 标记为「已上报失效」。
//
// 备注策略:仅在原备注为空时写入系统原因,避免覆盖人工备注。
// 备注策略:原备注为空时直接写入;已有备注时用换行追加系统原因,保留人工内容,
// 且相同原因不会重复追加。
// 已交付(status=redeemed 或 redeemed_at 非空)的 Token 不会被降级。
func (s *RockService) markTokenAbnormalByRefresh(ctx context.Context, token *model.RockToken, remark, message string) (*TokenBindingRefreshResult, error) {
if token == nil {
@@ -243,8 +244,12 @@ func (s *RockService) markTokenAbnormalByRefresh(ctx context.Context, token *mod
"status": model.RockStatusAbnormal,
"updated_at": time.Now(),
}
if strings.TrimSpace(token.Remark) == "" {
existingRemark := strings.TrimSpace(token.Remark)
switch {
case existingRemark == "":
updates["remark"] = remark
case !strings.Contains(existingRemark, remark):
updates["remark"] = existingRemark + "\n" + remark
}
if err := s.db.WithContext(ctx).Model(token).Updates(updates).Error; err != nil {
return nil, err