(tag string, newTag *string, modelMapping *string, models *string, group *string, priority *int64, weight *uint)
| 638 | } |
| 639 | |
| 640 | func EditChannelByTag(tag string, newTag *string, modelMapping *string, models *string, group *string, priority *int64, weight *uint) error { |
| 641 | updateData := Channel{} |
| 642 | shouldReCreateAbilities := false |
| 643 | updatedTag := tag |
| 644 | // 如果 newTag 不为空且不等于 tag,则更新 tag |
| 645 | if newTag != nil && *newTag != tag { |
| 646 | updateData.Tag = newTag |
| 647 | updatedTag = *newTag |
| 648 | } |
| 649 | if modelMapping != nil && *modelMapping != "" { |
| 650 | updateData.ModelMapping = modelMapping |
| 651 | } |
| 652 | if models != nil && *models != "" { |
| 653 | shouldReCreateAbilities = true |
| 654 | updateData.Models = *models |
| 655 | } |
| 656 | if group != nil && *group != "" { |
| 657 | shouldReCreateAbilities = true |
| 658 | updateData.Group = *group |
| 659 | } |
| 660 | if priority != nil { |
| 661 | updateData.Priority = priority |
| 662 | } |
| 663 | if weight != nil { |
| 664 | updateData.Weight = weight |
| 665 | } |
| 666 | |
| 667 | err := DB.Model(&Channel{}).Where("tag = ?", tag).Updates(updateData).Error |
| 668 | if err != nil { |
| 669 | return err |
| 670 | } |
| 671 | if shouldReCreateAbilities { |
| 672 | channels, err := GetChannelsByTag(updatedTag, false) |
| 673 | if err == nil { |
| 674 | for _, channel := range channels { |
| 675 | err = channel.UpdateAbilities(nil) |
| 676 | if err != nil { |
| 677 | common.SysError("failed to update abilities: " + err.Error()) |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | } else { |
| 682 | err := UpdateAbilityByTag(tag, newTag, priority, weight) |
| 683 | if err != nil { |
| 684 | return err |
| 685 | } |
| 686 | } |
| 687 | return nil |
| 688 | } |
| 689 | |
| 690 | func UpdateChannelUsedQuota(id int, quota int) { |
| 691 | if common.BatchUpdateEnabled { |
no test coverage detected