fix:刷新标记失效时追加备注而不是覆盖
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user