package translator import ( "encoding/json" "finclip-app-manager/domain/entity" "finclip-app-manager/infrastructure/db/entity/sql" "strings" ) type SqlTranslator struct { } func NewSqlTranslator() *SqlTranslator { return &SqlTranslator{} } func (mtr *SqlTranslator) CovertAppToSql(info *entity.App) *sql.App { if info == nil { return nil } return &sql.App{ AppId: info.AppID, Name: info.Name, AppClass: info.AppClass, AppTag: strings.Join(info.AppTag, ","), AppType: info.AppType, StatusInfo: sql.AppStatusInfo{ AppId: info.AppID, StatusValue: info.Status.Value, StatusReason: info.Status.Reason, StatusUpdateTime: info.Status.LastUpdated, StatusUpdater: info.Status.ModifiedBy, PublishedReason: info.PublishedStatus.Reason, PublishedUpdateTime: info.PublishedStatus.LastUpdated, PublishedUpdater: info.PublishedStatus.ModifiedBy, UnpublishedReason: info.UnpublishedStatus.Reason, UnpublishedUpdateTime: info.UnpublishedStatus.LastUpdated, UnpublishedUpdater: info.UnpublishedStatus.ModifiedBy, ActionReason: info.ActionStatus.Reason, ActionUpdater: info.ActionStatus.ModifiedBy, ActionUpdateTime: info.ActionStatus.LastUpdated, }, //Status: mtr.CovertStatusToMgo(info.Status), //todo 这是个啥 //ApplyStatus: DeveloperId: info.DeveloperID, GroupId: info.GroupID, CreatedBy: info.CreatedBy, Desc: info.CoreDescription, DetailDesc: info.CustomData.DetailDescription, Logo: info.Logo, Expire: info.Expire, IsForbidden: info.IsForbidden, PrivacySettingType: info.PrivacySettingType, ProjectType: info.ProjectType, CreateTime: info.Created, } } func (mtr *SqlTranslator) CovertAppToEntity(info *sql.App) *entity.App { if info == nil { return nil } return &entity.App{ AppID: info.AppId, Name: info.Name, AppClass: info.AppClass, AppTag: strings.Split(info.AppTag, ","), AppType: info.AppType, Status: entity.Status{ Value: info.StatusInfo.StatusValue, Reason: info.StatusInfo.StatusReason, LastUpdated: info.StatusInfo.StatusUpdateTime, ModifiedBy: info.StatusInfo.StatusUpdater, }, PublishedStatus: entity.SpecificStatus{ Reason: info.StatusInfo.PublishedReason, LastUpdated: info.StatusInfo.PublishedUpdateTime, ModifiedBy: info.StatusInfo.PublishedUpdater, }, UnpublishedStatus: entity.SpecificStatus{ Reason: info.StatusInfo.UnpublishedReason, LastUpdated: info.StatusInfo.UnpublishedUpdateTime, ModifiedBy: info.StatusInfo.UnpublishedUpdater, }, ActionStatus: entity.SpecificStatus{ Reason: info.StatusInfo.ActionReason, LastUpdated: info.StatusInfo.ActionUpdateTime, ModifiedBy: info.StatusInfo.ActionUpdater, }, //todo 这是个啥 //ApplyStatus: DeveloperID: info.DeveloperId, GroupID: info.GroupId, CreatedBy: info.CreatedBy, CustomData: entity.CustomDataInfo{ DetailDescription: info.DetailDesc, SourceFile: make([]entity.CustomDataSourceFile, 0), }, CoreDescription: info.Desc, Logo: info.Logo, Expire: info.Expire, IsForbidden: info.IsForbidden, PrivacySettingType: info.PrivacySettingType, ProjectType: info.ProjectType, Created: info.CreateTime, } } func (mtr *SqlTranslator) CovertAppToAppV2(info *sql.App) *sql.AppV2 { if info == nil { return nil } return &sql.AppV2{ AppId: info.AppId, Name: info.Name, AppClass: info.AppClass, AppTag: info.AppTag, AppType: info.AppType, Class: info.Class, DeveloperId: info.DeveloperId, GroupId: info.GroupId, CreatedBy: info.CreatedBy, Desc: info.Desc, DetailDesc: info.DetailDesc, Logo: info.Logo, Expire: info.Expire, Ext: info.Ext, IsForbidden: info.IsForbidden, PrivacySettingType: info.PrivacySettingType, ProjectType: info.ProjectType, IsRollback: info.IsRollback, CreateTime: info.CreateTime, UpdateTime: info.UpdateTime, } } func (mtr *SqlTranslator) CovertAppVerToSql(info *entity.AppVersion) *sql.AppVersion { if info == nil { return nil } result := &sql.AppVersion{ AppId: info.AppID, Sequence: info.Sequence, Name: info.Name, Logo: info.Logo, Version: info.Version, Desc: info.CoreDescription, DetailDesc: info.CustomData.DetailDescription, Class: info.AppClass, Tag: strings.Join(info.AppTag, ","), AppType: info.AppType, DeveloperId: info.DeveloperID, GroupId: info.GroupID, AutoPub: info.NeedAutoPub, InGrayRelease: info.InGrayRelease, BuildInfoId: info.AppBuildID, StatusInfo: sql.AppVersionStatusInfo{ AppId: info.AppID, Sequence: info.Sequence, StatusReason: info.Status.Reason, StatusValue: info.Status.Value, StatusUpdateTime: info.Status.LastUpdated, StatusUpdater: info.Status.ModifiedBy, PublishingReason: info.PublishingStatus.Reason, PublishingUpdateTime: info.PublishingStatus.LastUpdated, PublishingUpdater: info.PublishingStatus.ModifiedBy, PublishedReason: info.PublishedStatus.Reason, PublishedUpdateTime: info.PublishedStatus.LastUpdated, PublishedUpdater: info.PublishedStatus.ModifiedBy, UnpublishedReason: info.UnpublishedStatus.Reason, UnpublishedUpdateTime: info.UnpublishedStatus.LastUpdated, UnpublishedUpdater: info.UnpublishedStatus.ModifiedBy, UnpublishedType: info.UnpublishedStatus.Type, ApprovalReason: info.ApprovalStatus.Reason, ApprovalUpdateTime: info.ApprovalStatus.LastUpdated, ApprovalUpdater: info.ApprovalStatus.ModifiedBy, ActionReason: info.ActionStatus.Reason, ActionUpdater: info.ActionStatus.ModifiedBy, ActionUpdateTime: info.ActionStatus.LastUpdated, PublishingApprovalReason: info.PublishingApprovalStatus.Reason, PublishingApprovalUpdateTime: info.PublishingApprovalStatus.LastUpdated, PublishingApprovalUpdater: info.PublishingApprovalStatus.ModifiedBy, CreateTime: info.Created, }, CreatedBy: info.CreatedBy, IsRollback: info.IsRollback, ExpireTime: info.Expire, CreateTime: info.Created, TestInfo: "", } testInfoByte, _ := json.Marshal(info.TestInfo) result.TestInfo = string(testInfoByte) return result } func (mtr *SqlTranslator) CovertAppVerToEntity(info *sql.AppVersion) *entity.AppVersion { if info == nil { return nil } result := &entity.AppVersion{ AppID: info.AppId, Name: info.Name, AppClass: info.Class, AppTag: strings.Split(info.Tag, ","), AppType: info.AppType, Version: info.Version, Sequence: info.Sequence, Logo: info.Logo, Status: entity.Status{ Value: info.StatusInfo.StatusValue, Reason: info.StatusInfo.StatusReason, LastUpdated: info.StatusInfo.StatusUpdateTime, ModifiedBy: info.StatusInfo.StatusUpdater, }, PublishingStatus: entity.SpecificStatus{ Reason: info.StatusInfo.PublishingReason, LastUpdated: info.StatusInfo.PublishingUpdateTime, ModifiedBy: info.StatusInfo.PublishingUpdater, }, UnpublishingStatus: entity.SpecificStatus{}, PublishingApprovalStatus: entity.SpecificStatus{ Reason: info.StatusInfo.PublishingApprovalReason, LastUpdated: info.StatusInfo.PublishingApprovalUpdateTime, ModifiedBy: info.StatusInfo.PublishingApprovalUpdater, }, UnpublishingApprovalStatus: entity.SpecificStatus{}, PublishedStatus: entity.SpecificStatus{ Reason: info.StatusInfo.PublishedReason, LastUpdated: info.StatusInfo.PublishedUpdateTime, ModifiedBy: info.StatusInfo.PublishedUpdater, }, UnpublishedStatus: entity.UnpublishedStatus{ Reason: info.StatusInfo.UnpublishedReason, LastUpdated: info.StatusInfo.UnpublishedUpdateTime, ModifiedBy: info.StatusInfo.UnpublishedUpdater, Type: info.StatusInfo.UnpublishedType, }, RequestStatus: entity.SpecificStatus{}, ApprovalStatus: entity.SpecificStatus{ Reason: info.StatusInfo.ApprovalReason, LastUpdated: info.StatusInfo.ApprovalUpdateTime, ModifiedBy: info.StatusInfo.ApprovalUpdater, }, ActionStatus: entity.SpecificStatus{ Reason: info.StatusInfo.ActionReason, LastUpdated: info.StatusInfo.ActionUpdateTime, ModifiedBy: info.StatusInfo.ActionUpdater, }, //todo 这是个啥 //ApplyStatus: DeveloperID: info.DeveloperId, GroupID: info.GroupId, Created: info.CreateTime, CreatedBy: info.CreatedBy, CustomData: *mtr.CovertBuildInfoToCustomDataInfoEntity(&info.BuildInfo, info.DetailDesc), CoreDescription: info.Desc, Expire: info.ExpireTime, IsRollback: info.IsRollback, TestInfo: entity.TestInfo{}, NeedAutoPub: info.AutoPub, InGrayRelease: info.InGrayRelease, AppBuildID: info.BuildInfoId, } json.Unmarshal([]byte(info.TestInfo), &result.TestInfo) return result } func (mtr *SqlTranslator) CovertAppVerToAppVerV2(info *sql.AppVersion) *sql.AppVersionV2 { if info == nil { return nil } result := &sql.AppVersionV2{ AppId: info.AppId, Name: info.Name, Class: info.Class, Tag: info.Tag, AppType: info.AppType, Version: info.Version, Sequence: info.Sequence, Logo: info.Logo, DeveloperId: info.DeveloperId, GroupId: info.GroupId, CreateTime: info.CreateTime, UpdateTime: info.UpdateTime, CreatedBy: info.CreatedBy, Desc: info.Desc, DetailDesc: info.DetailDesc, ExpireTime: info.ExpireTime, IsRollback: info.IsRollback, TestInfo: info.TestInfo, AutoPub: info.AutoPub, InGrayRelease: info.InGrayRelease, BuildInfoId: info.BuildInfoId, Ext: info.Ext, } return result } func (mtr *SqlTranslator) CovertBuildInfoToEntity(info *sql.AppBuildInfo) *entity.AppBuildInfo { if info == nil { return nil } result := entity.AppBuildInfo{ Id: info.TraceId, BuildInfoId: info.BuildInfoId, Source: info.Source, AppID: info.AppId, GroupID: info.GroupID, Created: info.CreateTime, UserId: info.UserId, CreatedBy: info.CreatedBy, CustomData: entity.CustomDataInfo{ DetailDescription: "", VersionDescription: info.VersionDescription, Developer: info.CreatedBy, SourceFile: []entity.CustomDataSourceFile{}, }, Version: info.Version, //VersionDescription: info.VersionDescription, StartParams: entity.AppStartParams{ PathAndQuery: info.PathAndQuery, }, Status: info.Status, } result.CustomData.SourceFile = make([]entity.CustomDataSourceFile, 0) item := entity.CustomDataSourceFile{ FileMd5: info.FileMd5, Name: info.Name, SourceFileUrl: info.SourceFileUrl, UploadDate: info.CreateTime, Url: info.Url, EncryptedUrl: info.EncryptedUrl, EncryptedFileMd5: info.EncryptedFileMd5, EncryptedFileSha256: info.EncryptedFileSha256, BasicPackVer: info.BasicPackVer, } if info.Packages != "" { json.Unmarshal([]byte(info.Packages), &item.Packages) } else { item.Packages = make([]entity.Package, 0) } if info.EncryptPackages != "" { json.Unmarshal([]byte(info.EncryptPackages), &item.EncryptPackages) } else { item.EncryptPackages = make([]entity.Package, 0) } result.CustomData.SourceFile = append(result.CustomData.SourceFile, item) return &result } func (mtr *SqlTranslator) CovertBuildInfoToSql(info *entity.AppBuildInfo) *sql.AppBuildInfo { if info == nil { return nil } result := sql.AppBuildInfo{ TraceId: info.Id, BuildInfoId: info.BuildInfoId, Source: info.Source, AppId: info.AppID, GroupID: info.GroupID, UserId: info.UserId, CreatedBy: info.CreatedBy, CreateTime: info.Created, Status: info.Status, Version: info.Version, VersionDescription: info.CustomData.VersionDescription, } var item = entity.CustomDataSourceFile{} if len(info.CustomData.SourceFile) > 0 { item = info.CustomData.SourceFile[0] } result.FileMd5 = item.FileMd5 result.Name = item.Name result.SourceFileUrl = item.SourceFileUrl result.Url = item.Url result.EncryptedUrl = item.EncryptedUrl result.EncryptedFileMd5 = item.EncryptedFileMd5 result.EncryptedFileSha256 = item.EncryptedFileSha256 result.BasicPackVer = item.BasicPackVer packagesByte, _ := json.Marshal(item.Packages) result.Packages = string(packagesByte) encryptPackagesByte, _ := json.Marshal(item.EncryptPackages) result.EncryptPackages = string(encryptPackagesByte) result.PathAndQuery = info.StartParams.PathAndQuery return &result } func (mtr *SqlTranslator) CovertBuildInfoToCustomDataInfoEntity(info *sql.AppBuildInfo, DetailDesc string) *entity.CustomDataInfo { if info == nil { return nil } result := entity.CustomDataInfo{ DetailDescription: DetailDesc, SourceFile: make([]entity.CustomDataSourceFile, 0), VersionDescription: info.VersionDescription, Developer: info.CreatedBy, } result.SourceFile = make([]entity.CustomDataSourceFile, 0) item := entity.CustomDataSourceFile{ FileMd5: info.FileMd5, Name: info.Name, SourceFileUrl: info.SourceFileUrl, UploadDate: info.CreateTime, Url: info.Url, EncryptedUrl: info.EncryptedUrl, EncryptedFileMd5: info.EncryptedFileMd5, EncryptedFileSha256: info.EncryptedFileSha256, BasicPackVer: info.BasicPackVer, } if info.Packages != "" { json.Unmarshal([]byte(info.Packages), &item.Packages) } else { item.Packages = make([]entity.Package, 0) } if info.EncryptPackages != "" { json.Unmarshal([]byte(info.EncryptPackages), &item.EncryptPackages) } else { item.EncryptPackages = make([]entity.Package, 0) } result.SourceFile = append(result.SourceFile, item) return &result } func (mtr *SqlTranslator) CovertPrivacySettingInfoToSql(info *entity.PrivacySettingInfo) *sql.PrivacySettingInfo { if info == nil { return nil } result := sql.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 *SqlTranslator) CovertPrivacySettingInfoToEntity(info *sql.PrivacySettingInfo) *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 }