finclip-app-manager/infrastructure/db/translator/mongo.go

499 lines
17 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package translator
import (
"finclip-app-manager/domain/entity"
"finclip-app-manager/infrastructure/db/entity/mongo"
)
type MgoTranslator struct {
}
func NewMgoTranslator() *MgoTranslator {
return &MgoTranslator{}
}
func (mtr *MgoTranslator) CovertAppToMgo(info *entity.App) *mongo.App {
if info == nil {
return nil
}
return &mongo.App{
AppID: info.AppID,
Name: info.Name,
Sequence: info.Sequence,
AppClass: info.AppClass,
AppTag: info.AppTag,
AppType: info.AppType,
Status: mtr.CovertStatusToMgo(info.Status),
//todo 这是个啥
//ApplyStatus:
PublishedStatus: mtr.CovertSpecificStatusToMgo(info.PublishedStatus),
UnpublishedStatus: mtr.CovertSpecificStatusToMgo(info.UnpublishedStatus),
ActionStatus: mtr.CovertSpecificStatusToMgo(info.ActionStatus),
DeveloperID: info.DeveloperID,
GroupID: info.GroupID,
Created: info.Created,
CreatedBy: info.CreatedBy,
DetailDescription: info.CustomData.DetailDescription,
CoreDescription: info.CoreDescription,
Logo: info.Logo,
Expire: info.Expire,
IsForbidden: info.IsForbidden,
PrivacySettingType: info.PrivacySettingType,
ProjectType: info.ProjectType,
}
}
func (mtr *MgoTranslator) CovertAppToEntity(info *mongo.App) *entity.App {
if info == nil {
return nil
}
return &entity.App{
AppID: info.AppID,
Name: info.Name,
Version: info.Version,
Sequence: info.Sequence,
AppClass: info.AppClass,
AppTag: info.AppTag,
AppType: info.AppType,
Status: mtr.CovertStatusToEntity(info.Status),
//todo 这是个啥
//ApplyStatus:
PublishedStatus: mtr.CovertSpecificStatusToEntity(info.PublishedStatus),
UnpublishedStatus: mtr.CovertSpecificStatusToEntity(info.UnpublishedStatus),
ActionStatus: mtr.CovertSpecificStatusToEntity(info.ActionStatus),
DeveloperID: info.DeveloperID,
GroupID: info.GroupID,
Created: info.Created,
CreatedBy: info.CreatedBy,
CustomData: entity.CustomDataInfo{
DetailDescription: info.DetailDescription,
SourceFile: make([]entity.CustomDataSourceFile, 0),
},
CoreDescription: info.CoreDescription,
Logo: info.Logo,
Expire: info.Expire,
IsForbidden: info.IsForbidden,
PrivacySettingType: info.PrivacySettingType,
ProjectType: info.ProjectType,
}
}
func (mtr *MgoTranslator) CovertAppVerToMgo(info *entity.AppVersion) *mongo.AppVersion {
if info == nil {
return nil
}
return &mongo.AppVersion{
AppID: info.AppID,
Name: info.Name,
AppClass: info.AppClass,
AppTag: info.AppTag,
AppType: info.AppType,
Status: mtr.CovertStatusToMgo(info.Status),
PublishingStatus: mtr.CovertSpecificStatusToMgo(info.PublishingStatus),
//todo 这是个啥
//ApplyStatus:
PublishingApprovalStatus: mtr.CovertSpecificStatusToMgo(info.PublishingApprovalStatus),
UnpublishingApprovalStatus: mtr.CovertSpecificStatusToMgo(info.UnpublishingApprovalStatus),
PublishedStatus: mtr.CovertSpecificStatusToMgo(info.PublishedStatus),
UnpublishedStatus: mtr.CovertUnpublishedStatusToMgo(info.UnpublishedStatus),
ApprovalStatus: mtr.CovertSpecificStatusToMgo(info.ApprovalStatus),
ActionStatus: mtr.CovertSpecificStatusToMgo(info.ActionStatus),
DeveloperID: info.DeveloperID,
GroupID: info.GroupID,
Created: info.Created,
CreatedBy: info.CreatedBy,
CustomData: mtr.CovertCustomDataToMgo(info.CustomData),
Version: info.Version,
Sequence: info.Sequence,
CorporationID: info.CorporationID,
CoreDescription: info.CoreDescription,
Logo: info.Logo,
TestInfo: mtr.CovertTestInfoToMgo(info.TestInfo),
NeedAutoPub: info.NeedAutoPub,
InGrayRelease: info.InGrayRelease,
Expire: info.Expire,
AppBuildID: info.AppBuildID,
}
}
func (mtr *MgoTranslator) CovertAppVerToEntity(info *mongo.AppVersion) *entity.AppVersion {
if info == nil {
return nil
}
return &entity.AppVersion{
AppID: info.AppID,
Name: info.Name,
AppClass: info.AppClass,
AppTag: info.AppTag,
AppType: info.AppType,
Status: mtr.CovertStatusToEntity(info.Status),
PublishingStatus: mtr.CovertSpecificStatusToEntity(info.PublishingStatus),
//todo 这是个啥
//ApplyStatus:
PublishingApprovalStatus: mtr.CovertSpecificStatusToEntity(info.PublishingApprovalStatus),
UnpublishingApprovalStatus: mtr.CovertSpecificStatusToEntity(info.UnpublishingApprovalStatus),
PublishedStatus: mtr.CovertSpecificStatusToEntity(info.PublishedStatus),
UnpublishedStatus: mtr.CovertUnpublishedStatusToEntity(info.UnpublishedStatus),
ApprovalStatus: mtr.CovertSpecificStatusToEntity(info.ApprovalStatus),
ActionStatus: mtr.CovertSpecificStatusToEntity(info.ActionStatus),
DeveloperID: info.DeveloperID,
GroupID: info.GroupID,
Created: info.Created,
CreatedBy: info.CreatedBy,
CustomData: mtr.CovertCustomDataToEntity(info.CustomData),
Version: info.Version,
Sequence: info.Sequence,
CorporationID: info.CorporationID,
CoreDescription: info.CoreDescription,
Logo: info.Logo,
TestInfo: mtr.CovertTestInfoToEntity(info.TestInfo),
NeedAutoPub: info.NeedAutoPub,
InGrayRelease: info.InGrayRelease,
IsRollback: info.IsRollback,
Expire: info.Expire,
AppBuildID: info.AppBuildID,
}
}
func (mtr *MgoTranslator) CovertStatusToMgo(info entity.Status) mongo.Status {
return mongo.Status{
Value: info.Value,
Reason: info.Reason,
LastUpdated: info.LastUpdated,
ModifiedBy: info.ModifiedBy,
}
}
func (mtr *MgoTranslator) CovertStatusToEntity(info mongo.Status) entity.Status {
return entity.Status{
Value: info.Value,
Reason: info.Reason,
LastUpdated: info.LastUpdated,
ModifiedBy: info.ModifiedBy,
}
}
func (mtr *MgoTranslator) CovertSpecificStatusToMgo(info entity.SpecificStatus) mongo.SpecificStatus {
return mongo.SpecificStatus{
Reason: info.Reason,
LastUpdated: info.LastUpdated,
ModifiedBy: info.ModifiedBy,
}
}
func (mtr *MgoTranslator) CovertSpecificStatusToEntity(info mongo.SpecificStatus) entity.SpecificStatus {
return entity.SpecificStatus{
Reason: info.Reason,
LastUpdated: info.LastUpdated,
ModifiedBy: info.ModifiedBy,
}
}
func (mtr *MgoTranslator) CovertUnpublishedStatusToMgo(info entity.UnpublishedStatus) mongo.UnpublishedStatus {
return mongo.UnpublishedStatus{
Reason: info.Reason,
LastUpdated: info.LastUpdated,
ModifiedBy: info.ModifiedBy,
Type: info.Type,
}
}
func (mtr *MgoTranslator) CovertUnpublishedStatusToEntity(info mongo.UnpublishedStatus) entity.UnpublishedStatus {
return entity.UnpublishedStatus{
Reason: info.Reason,
LastUpdated: info.LastUpdated,
ModifiedBy: info.ModifiedBy,
Type: info.Type,
}
}
func (mtr *MgoTranslator) CovertTestInfoToMgo(info entity.TestInfo) mongo.TestInfo {
return mongo.TestInfo{
Account: info.Account,
Password: info.Password,
Description: info.Description,
Images: info.Images,
}
}
func (mtr *MgoTranslator) CovertTestInfoToEntity(info mongo.TestInfo) entity.TestInfo {
return entity.TestInfo{
Account: info.Account,
Password: info.Password,
Description: info.Description,
Images: info.Images,
}
}
func (mtr *MgoTranslator) CovertCustomDataToMgo(info entity.CustomDataInfo) mongo.CustomDataInfo {
result := mongo.CustomDataInfo{
DetailDescription: info.DetailDescription,
SourceFile: make([]mongo.CustomDataSourceFile, 0),
VersionDescription: info.VersionDescription,
Developer: info.Developer,
}
for _, v := range info.SourceFile {
customInfo := mongo.CustomDataSourceFile{
FileMd5: v.FileMd5,
Name: v.Name,
SourceFileUrl: v.SourceFileUrl,
UploadDate: v.UploadDate,
Url: v.Url,
EncryptedUrl: v.EncryptedUrl,
EncryptedFileMd5: v.EncryptedFileMd5,
EncryptedFileSha256: v.EncryptedFileSha256,
BasicPackVer: v.BasicPackVer,
Packages: make([]mongo.Package, 0),
EncryptPackages: make([]mongo.Package, 0),
}
for _, p := range v.Packages {
customInfo.Packages = append(customInfo.Packages, mongo.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
for _, p := range v.EncryptPackages {
customInfo.EncryptPackages = append(customInfo.EncryptPackages, mongo.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
result.SourceFile = append(result.SourceFile, customInfo)
}
return result
}
func (mtr *MgoTranslator) CovertCustomDataToEntity(info mongo.CustomDataInfo) entity.CustomDataInfo {
result := entity.CustomDataInfo{
DetailDescription: info.DetailDescription,
SourceFile: make([]entity.CustomDataSourceFile, 0),
VersionDescription: info.VersionDescription,
Developer: info.Developer,
}
for _, v := range info.SourceFile {
customInfo := entity.CustomDataSourceFile{
FileMd5: v.FileMd5,
Name: v.Name,
SourceFileUrl: v.SourceFileUrl,
UploadDate: v.UploadDate,
Url: v.Url,
EncryptedUrl: v.EncryptedUrl,
EncryptedFileMd5: v.EncryptedFileMd5,
EncryptedFileSha256: v.EncryptedFileSha256,
BasicPackVer: v.BasicPackVer,
Packages: make([]entity.Package, 0),
EncryptPackages: make([]entity.Package, 0),
}
for _, p := range v.Packages {
customInfo.Packages = append(customInfo.Packages, entity.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
for _, p := range v.EncryptPackages {
customInfo.EncryptPackages = append(customInfo.EncryptPackages, entity.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
result.SourceFile = append(result.SourceFile, customInfo)
}
return result
}
func (mtr *MgoTranslator) CovertAppBuildInfoToMgo(info *entity.AppBuildInfo) *mongo.AppBuildInfo {
result := &mongo.AppBuildInfo{
Id: info.Id,
BuildInfoId: info.BuildInfoId,
Source: info.Source,
AppID: info.AppID,
GroupID: info.GroupID,
Created: info.Created,
UserId: info.UserId,
CreatedBy: info.CreatedBy,
CustomData: mongo.CustomDataInfo{
Developer: info.CustomData.Developer,
SourceFile: make([]mongo.CustomDataSourceFile, 0),
VersionDescription: info.CustomData.VersionDescription,
DetailDescription: info.CustomData.DetailDescription,
},
Version: info.Version,
StartParams: mongo.AppStartParams{
PathAndQuery: info.StartParams.PathAndQuery,
},
Status: info.Status,
}
for _, v := range info.CustomData.SourceFile {
item := mongo.CustomDataSourceFile{
FileMd5: v.FileMd5,
Name: v.Name,
SourceFileUrl: v.SourceFileUrl,
UploadDate: info.Created,
Url: v.Url,
EncryptedUrl: v.EncryptedUrl,
EncryptedFileMd5: v.EncryptedFileMd5,
EncryptedFileSha256: v.EncryptedFileSha256,
BasicPackVer: v.BasicPackVer,
Packages: make([]mongo.Package, 0),
EncryptPackages: make([]mongo.Package, 0),
}
for _, p := range v.Packages {
item.Packages = append(item.Packages, mongo.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
for _, p := range v.EncryptPackages {
item.EncryptPackages = append(item.EncryptPackages, mongo.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
result.CustomData.SourceFile = append(result.CustomData.SourceFile, item)
}
return result
}
func (mtr *MgoTranslator) CovertAppBuildInfoToEntity(info *mongo.AppBuildInfo) *entity.AppBuildInfo {
result := &entity.AppBuildInfo{
Id: info.Id,
BuildInfoId: info.BuildInfoId,
Source: info.Source,
AppID: info.AppID,
GroupID: info.GroupID,
Created: info.Created,
UserId: info.UserId,
CreatedBy: info.CreatedBy,
CustomData: entity.CustomDataInfo{
Developer: info.CustomData.Developer,
SourceFile: make([]entity.CustomDataSourceFile, 0),
VersionDescription: info.CustomData.VersionDescription,
DetailDescription: info.CustomData.DetailDescription,
},
Version: info.Version,
StartParams: entity.AppStartParams{
PathAndQuery: info.StartParams.PathAndQuery,
},
Status: info.Status,
}
for _, v := range info.CustomData.SourceFile {
item := entity.CustomDataSourceFile{
FileMd5: v.FileMd5,
Name: v.Name,
SourceFileUrl: v.SourceFileUrl,
UploadDate: v.UploadDate,
Url: v.Url,
EncryptedUrl: v.EncryptedUrl,
EncryptedFileMd5: v.EncryptedFileMd5,
EncryptedFileSha256: v.EncryptedFileSha256,
BasicPackVer: v.BasicPackVer,
Packages: make([]entity.Package, 0),
EncryptPackages: make([]entity.Package, 0),
}
for _, p := range v.Packages {
item.Packages = append(item.Packages, entity.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
for _, p := range v.EncryptPackages {
item.EncryptPackages = append(item.EncryptPackages, entity.Package{
Root: p.Root,
Name: p.Name,
Pages: p.Pages,
Independent: p.Independent,
Filename: p.Filename,
FileUrl: p.FileUrl,
FileMd5: p.FileMd5,
})
}
result.CustomData.SourceFile = append(result.CustomData.SourceFile, item)
}
return result
}
func (mtr *MgoTranslator) CovertPrivacySettingInfoToEntity(info *mongo.PrivacySettingInfoMongo) *entity.PrivacySettingInfo {
if info == nil {
return nil
}
result := entity.PrivacySettingInfo{
AppId: info.AppId,
CommitType: info.CommitType,
UserMessageType: info.UserMessageType,
SdkMessage: info.SdkMessage,
ContactInfoPhone: info.ContactInfoPhone,
ContactInfoEmail: info.ContactInfoEmail,
ContactInfoWeChat: info.ContactInfoWeChat,
ContactInfoOther: info.ContactInfoOther,
FixedStorageTime: info.FixedStorageTime,
IsShortestTime: info.IsShortestTime,
AdditionalDocName: info.AdditionalDocName,
AdditionalDocNetDiskId: info.AdditionalDocNetDiskId,
AdditionalDocContent: info.AdditionalDocContent,
IsFirstSave: info.IsFirstSave,
EffectiveTime: info.EffectiveTime,
CreateTime: info.CreateTime,
UpdateTime: info.UpdateTime,
}
return &result
}
func (mtr *MgoTranslator) CovertPrivacySettingInfoToMongo(info *entity.PrivacySettingInfo) *mongo.PrivacySettingInfoMongo {
if info == nil {
return nil
}
result := mongo.PrivacySettingInfoMongo{
AppId: info.AppId,
CommitType: info.CommitType,
UserMessageType: info.UserMessageType,
SdkMessage: info.SdkMessage,
ContactInfoPhone: info.ContactInfoPhone,
ContactInfoEmail: info.ContactInfoEmail,
ContactInfoWeChat: info.ContactInfoWeChat,
ContactInfoOther: info.ContactInfoOther,
FixedStorageTime: info.FixedStorageTime,
IsShortestTime: info.IsShortestTime,
AdditionalDocName: info.AdditionalDocName,
AdditionalDocNetDiskId: info.AdditionalDocNetDiskId,
AdditionalDocContent: info.AdditionalDocContent,
IsFirstSave: info.IsFirstSave,
EffectiveTime: info.EffectiveTime,
CreateTime: info.CreateTime,
UpdateTime: info.UpdateTime,
}
return &result
}