140 lines
6.1 KiB
Go
140 lines
6.1 KiB
Go
package mongo
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"finclip-app-manager/domain/entity"
|
|
"finclip-app-manager/domain/repository"
|
|
"finclip-app-manager/infrastructure/utility"
|
|
mgo "gitlab.finogeeks.club/finclip-backend-v2/finclip-mgo"
|
|
"gitlab.finogeeks.club/finclip-backend-v2/finclip-mgo/bson"
|
|
)
|
|
|
|
var _ repository.IAppTempInfoRepo = new(AppTempInfoByMongoRepo)
|
|
|
|
type AppTempInfoByMongoRepo struct {
|
|
}
|
|
|
|
type AppTempInfoMongo struct {
|
|
AppID string `json:"appId" bson:"app_id"` //id
|
|
Name string `json:"name" bson:"name"` //名字
|
|
Sequence int `json:"sequence" bson:"sequence"` //版本号
|
|
AppClass string `json:"appClass" bson:"app_class"` //用途
|
|
AppType string `json:"appType" bson:"app_type"` //应用类型--mop使用为了和应用市场区分开
|
|
StatusValue string `json:"statusValue" bson:"status_value"`
|
|
StatusReason string `json:"statusReason" bson:"status_reason"`
|
|
StatusLastUpdated int64 `json:"statusLastUpdated" bson:"status_last_updated"`
|
|
StatusModifiedBy string `json:"statusModifiedBy" bson:"status_modified_by"`
|
|
DeveloperID string `json:"developerId" bson:"developer_id"` //开发者id
|
|
GroupID string `json:"groupId" bson:"group_id"` //组id
|
|
Created int64 `json:"created" bson:"created"`
|
|
CreatedBy string `json:"createdBy" bson:"created_by"`
|
|
CustomDataDetailDescription string `bson:"customData_detail_description" json:"customDataDetailDescription"` //小程序详细描述
|
|
CustomDataSourceFile string `bson:"customData_source_file" json:"customDataSourceFile"`
|
|
CustomDataVersionDescription string `bson:"customData_version_description" json:"customDataVersionDescription"` //小程序编译包版本描述
|
|
CustomDataDeveloper string `bson:"customData_developer" json:"customDataDeveloper"` //开发者
|
|
Version string `json:"version" bson:"version"` //应用版本
|
|
CoreDescription string `json:"coreDescription" bson:"core_description"` //核心描述
|
|
Logo string `json:"logo" bson:"logo"` //图标
|
|
}
|
|
|
|
func (a AppTempInfoByMongoRepo) Insert(ctx context.Context, info *entity.AppTempInfo) error {
|
|
return appTempInfoTable.Insert(ctx, convertAppTempInfoToAppTempInfoMongo(info))
|
|
}
|
|
|
|
func (a AppTempInfoByMongoRepo) UpdateInfo(ctx context.Context, info *entity.AppTempInfo) error {
|
|
mgoInfo := convertAppTempInfoToAppTempInfoMongo(info)
|
|
return appTempInfoTable.UpdateOne(ctx, bson.M{"app_id": info.AppID, "sequence": info.Sequence}, mgoInfo)
|
|
}
|
|
|
|
func (a AppTempInfoByMongoRepo) GetInfoByAppId(ctx context.Context, appId string) (*entity.AppTempInfo, error) {
|
|
appTempInfoMongo := AppTempInfoMongo{}
|
|
err := appTempInfoTable.GetOne(ctx, bson.M{"app_id": appId, "sequence": entity.AppTempDefSequence}, &appTempInfoMongo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info := convertAppTempInfoMongoToAppTempInfo(appTempInfoMongo)
|
|
return &info, err
|
|
}
|
|
|
|
func (a AppTempInfoByMongoRepo) GetInfoByAppIdAndSeq(ctx context.Context, appId string, seq int) (*entity.AppTempInfo, error) {
|
|
appTempInfoMongo := AppTempInfoMongo{}
|
|
err := appTempInfoTable.GetOne(ctx, bson.M{"app_id": appId, "sequence": seq}, &appTempInfoMongo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info := convertAppTempInfoMongoToAppTempInfo(appTempInfoMongo)
|
|
return &info, err
|
|
}
|
|
|
|
func (a AppTempInfoByMongoRepo) NotFound(err error) bool {
|
|
return err == mgo.ErrNotFound
|
|
}
|
|
|
|
func convertAppTempInfoToAppTempInfoMongo(appTempInfo *entity.AppTempInfo) AppTempInfoMongo {
|
|
result := AppTempInfoMongo{}
|
|
|
|
result.AppID = appTempInfo.AppID
|
|
result.Name = appTempInfo.Name
|
|
result.Sequence = appTempInfo.Sequence
|
|
result.AppClass = appTempInfo.AppClass
|
|
result.AppType = appTempInfo.AppType
|
|
result.StatusValue = appTempInfo.Status.Value
|
|
result.StatusReason = appTempInfo.Status.Reason
|
|
result.StatusLastUpdated = appTempInfo.Status.LastUpdated
|
|
result.StatusModifiedBy = appTempInfo.Status.ModifiedBy
|
|
result.DeveloperID = appTempInfo.DeveloperID
|
|
result.GroupID = appTempInfo.GroupID
|
|
result.Created = appTempInfo.Created
|
|
result.CreatedBy = appTempInfo.CreatedBy
|
|
result.CustomDataDetailDescription = appTempInfo.CustomData.DetailDescription
|
|
result.CustomDataSourceFile = utility.InterfaceToJsonString(appTempInfo.CustomData.SourceFile)
|
|
result.CustomDataVersionDescription = appTempInfo.CustomData.VersionDescription
|
|
result.CustomDataDeveloper = appTempInfo.CustomData.Developer
|
|
result.Version = appTempInfo.Version
|
|
result.CoreDescription = appTempInfo.CoreDescription
|
|
result.Logo = appTempInfo.Logo
|
|
|
|
return result
|
|
}
|
|
|
|
func convertAppTempInfoMongoToAppTempInfo(appTempInfoMongo AppTempInfoMongo) entity.AppTempInfo {
|
|
result := entity.AppTempInfo{}
|
|
|
|
status := entity.Status{
|
|
Value: appTempInfoMongo.StatusValue,
|
|
Reason: appTempInfoMongo.StatusReason,
|
|
LastUpdated: appTempInfoMongo.StatusLastUpdated,
|
|
ModifiedBy: appTempInfoMongo.StatusModifiedBy,
|
|
}
|
|
|
|
var sourceFile []entity.CustomDataSourceFile
|
|
json.Unmarshal([]byte(appTempInfoMongo.CustomDataSourceFile), &sourceFile)
|
|
|
|
customData := entity.CustomDataInfo{
|
|
DetailDescription: appTempInfoMongo.CustomDataDetailDescription,
|
|
SourceFile: sourceFile,
|
|
VersionDescription: appTempInfoMongo.CustomDataVersionDescription,
|
|
Developer: appTempInfoMongo.CustomDataDeveloper,
|
|
}
|
|
|
|
result.AppID = appTempInfoMongo.AppID
|
|
result.Name = appTempInfoMongo.Name
|
|
result.Sequence = appTempInfoMongo.Sequence
|
|
result.AppClass = appTempInfoMongo.AppClass
|
|
result.AppType = appTempInfoMongo.AppType
|
|
result.Status = status
|
|
result.DeveloperID = appTempInfoMongo.DeveloperID
|
|
result.GroupID = appTempInfoMongo.GroupID
|
|
result.Created = appTempInfoMongo.Created
|
|
result.CreatedBy = appTempInfoMongo.CreatedBy
|
|
result.CustomData = customData
|
|
result.Version = appTempInfoMongo.Version
|
|
result.CoreDescription = appTempInfoMongo.CoreDescription
|
|
result.Logo = appTempInfoMongo.Logo
|
|
|
|
return result
|
|
}
|