| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package task
- import (
- "dsbqj-admin/model/mongo/version"
- "dsbqj-admin/pkg/util"
- "sync"
- "github.com/kamva/mgm/v3"
- "go.mongodb.org/mongo-driver/bson"
- )
- var VersionTask *Versions
- type Versions struct {
- sync.Mutex
- VChannels util.SafeMap[string, *ChannelVersions]
- }
- type ChannelVersions struct {
- VList util.SafeArray[*version.Version]
- VMap util.SafeMap[string, *version.Version]
- }
- func VersionInit() *Versions {
- VersionTask = new(Versions)
- return VersionTask
- }
- func (this *Versions) Exec() {
- var versions = make([]*version.Version, 0)
- err := mgm.Coll(&version.Version{}).SimpleFind(&versions, bson.M{})
- if err == nil {
- this.VChannels.Clear()
- for _, v := range versions {
- if _, ok := this.VChannels.Get(v.Channel); !ok {
- this.VChannels.Set(v.Channel, new(ChannelVersions))
- }
- channelVersion, _ := this.VChannels.Get(v.Channel)
- channelVersion.VList.Push(v)
- channelVersion.VMap.Set(v.Version, v)
- }
- }
- }
- func (this *Versions) Check(version string, channel string) *version.Version {
- channelVersions, ok := this.VChannels.Get(channel)
- if !ok { // 遍历列表
- return nil
- }
- data, ok := channelVersions.VMap.Get(version)
- if !ok {
- for _, v := range channelVersions.VList.View() {
- if v.Default && v.Version == version && v.Channel == channel {
- data = v
- break
- }
- }
- }
- return data
- }
- func (this *Versions) Servers(channel string) []*version.Version {
- var res = make([]*version.Version, 0)
- if channelVersions, ok := this.VChannels.Get(channel); ok {
- for _, v := range channelVersions.VList.View() {
- if v.Channel == channel {
- res = append(res, v)
- }
- }
- }
- return res
- }
|