| 53 | } |
| 54 | |
| 55 | func (i *imlServiceModelMappingService) Save(ctx context.Context, input *Save) error { |
| 56 | info, err := i.store.First(ctx, map[string]interface{}{"sid": input.Sid}) |
| 57 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| 58 | return err |
| 59 | } |
| 60 | userID := utils.UserId(ctx) |
| 61 | if info != nil { |
| 62 | info.Content = input.Content |
| 63 | info.Updater = userID |
| 64 | info.UpdateAt = time.Now() |
| 65 | return i.store.Save(ctx, info) |
| 66 | } |
| 67 | return i.store.Insert(ctx, &service.ModelMapping{ |
| 68 | Sid: input.Sid, |
| 69 | Content: input.Content, |
| 70 | CreateAt: time.Now(), |
| 71 | UpdateAt: time.Now(), |
| 72 | Creator: userID, |
| 73 | Updater: userID, |
| 74 | }) |
| 75 | } |