finclip-app-manager/infrastructure/db/repo/mysql/app_temp_info.go

181 lines
8.4 KiB
Go
Raw Normal View History

2023-10-31 14:07:26 +08:00
package mysql
import (
"context"
"encoding/json"
"finclip-app-manager/domain/entity"
"finclip-app-manager/domain/repository"
"finclip-app-manager/infrastructure/utility"
"gorm.io/gorm"
)
var _ repository.IAppTempInfoRepo = new(AppTempInfoByMysqlRepo)
type AppTempInfoByMysqlRepo struct {
}
type AppTempInfoMysql struct {
Id uint64 `json:"id" gorm:"primary_key;column:id;type:BIGINT(16) AUTO_INCREMENT;comment:'自增id'" sql:"auto_increment;primary_key"`
AppID string `json:"appId" gorm:"column:app_id;type:varchar(64);comment:id"`
Name string `json:"name" gorm:"column:name;type:varchar(256);comment:名字"`
Sequence int `json:"sequence" gorm:"column:sequence;type:INT(4);comment:版本号"`
AppClass string `json:"appClass" gorm:"column:app_class;type:varchar(64);comment:用途"`
AppType string `json:"appType" gorm:"column:app_type;type:varchar(64);comment:应用类型--mop使用为了和应用市场区分开"`
StatusValue string `json:"statusValue" gorm:"column:status_value;type:varchar(64);comment:状态值"`
StatusReason string `json:"statusReason" gorm:"column:status_reason;type:varchar(64);comment:状态原因"`
StatusLastUpdated int64 `json:"statusLastUpdated" gorm:"column:status_last_updated;type:BIGINT(16);comment:状态更新时间"`
StatusModifiedBy string `json:"statusModifiedBy" gorm:"column:status_modified_by;type:varchar(64);comment:状态更新人"`
DeveloperID string `json:"developerId" gorm:"column:developer_id;type:varchar(64);comment:开发者id"`
GroupID string `json:"groupId" gorm:"column:group_id;type:varchar(64);comment:组id"`
Created int64 `json:"created" gorm:"column:created;type:BIGINT(16);comment:创建时间"`
CreatedBy string `json:"createdBy" gorm:"column:created_by;type:varchar(64);comment:组id"`
CustomDataDetailDescription string `json:"customDataDetailDescription" gorm:"column:customData_detail_description;type:varchar(64);comment:小程序详细描述"`
CustomDataSourceFile string `json:"customDataSourceFile" gorm:"column:customData_source_file;type:TEXT;comment:编译文件"`
CustomDataVersionDescription string `json:"customDataVersionDescription" gorm:"column:customData_version_description;type:varchar(64);comment:小程序编译包版本描述"`
CustomDataDeveloper string `json:"customDataDeveloper" gorm:"column:customData_developer;type:varchar(64);comment:开发者"`
Version string `json:"version" gorm:"column:version;type:varchar(64);comment:应用版本"`
CoreDescription string `json:"coreDescription" gorm:"column:core_description;type:varchar(64);comment:核心描述"`
Logo string `json:"logo" gorm:"column:logo;type:varchar(64);comment:图标"`
ProjectType int `gorm:"column:project_type;type:tinyint(1);default:0;comment:'项目类型'"`
}
func (AppTempInfoMysql) TableName() string {
return "app_temp_info_mysqls"
}
func (b AppTempInfoByMysqlRepo) Insert(ctx context.Context, info *entity.AppTempInfo) error {
sqlInfo := convertAppTempInfoToAppTempInfoMysql(info)
return DB.Debug().Model(&AppTempInfoMysql{}).Create(&sqlInfo).Error
}
func (b AppTempInfoByMysqlRepo) UpdateInfo(ctx context.Context, info *entity.AppTempInfo) error {
query := "app_id = ? and sequence = ?"
args := []interface{}{info.AppID, info.Sequence}
sqlInfo := convertAppTempInfoToAppTempInfoMysql(info)
params := map[string]interface{}{
"app_id": sqlInfo.AppID,
"name": sqlInfo.Name,
"sequence": sqlInfo.Sequence,
"app_class": sqlInfo.AppClass,
"app_type": sqlInfo.AppType,
"status_value": sqlInfo.StatusValue,
"status_reason": sqlInfo.StatusValue,
"status_last_updated": sqlInfo.StatusLastUpdated,
"status_modified_by": sqlInfo.StatusModifiedBy,
"developer_id": sqlInfo.DeveloperID,
"group_id": sqlInfo.GroupID,
"created": sqlInfo.Created,
"created_by": sqlInfo.CreatedBy,
"customData_detail_description": sqlInfo.CustomDataDetailDescription,
"customData_source_file": sqlInfo.CustomDataSourceFile,
"customData_version_description": sqlInfo.CustomDataVersionDescription,
"customData_developer": sqlInfo.CustomDataDeveloper,
"version": sqlInfo.Version,
"core_description": sqlInfo.CoreDescription,
"logo": sqlInfo.Logo,
}
return DB.Model(&AppTempInfoMysql{}).Where(query, args...).Updates(&params).Error
}
func (b AppTempInfoByMysqlRepo) GetInfoByAppId(ctx context.Context, appId string) (*entity.AppTempInfo, error) {
query := "app_id = ? and sequence = ?"
args := []interface{}{appId, entity.AppTempDefSequence}
appTempInfoMysql := AppTempInfoMysql{}
err := DB.Model(&AppTempInfoMysql{}).Where(query, args...).First(&appTempInfoMysql).Error
if err != nil {
return nil, err
}
result := convertAppTempInfoMysqlToAppTempInfo(appTempInfoMysql)
return &result, err
}
func (b AppTempInfoByMysqlRepo) GetInfoByAppIdAndSeq(ctx context.Context, appId string, seq int) (*entity.AppTempInfo, error) {
query := "app_id = ? and sequence = ?"
args := []interface{}{appId, seq}
appTempInfoMysql := AppTempInfoMysql{}
err := DB.Model(&AppTempInfoMysql{}).Where(query, args...).First(&appTempInfoMysql).Error
if err != nil {
return nil, err
}
result := convertAppTempInfoMysqlToAppTempInfo(appTempInfoMysql)
return &result, err
}
func (b AppTempInfoByMysqlRepo) NotFound(err error) bool {
return err == gorm.ErrRecordNotFound
}
func convertAppTempInfoToAppTempInfoMysql(appTempInfo *entity.AppTempInfo) AppTempInfoMysql {
result := AppTempInfoMysql{}
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
result.ProjectType = appTempInfo.ProjectType
return result
}
func convertAppTempInfoMysqlToAppTempInfo(appTempInfoMysql AppTempInfoMysql) entity.AppTempInfo {
result := entity.AppTempInfo{}
status := entity.Status{
Value: appTempInfoMysql.StatusValue,
Reason: appTempInfoMysql.StatusReason,
LastUpdated: appTempInfoMysql.StatusLastUpdated,
ModifiedBy: appTempInfoMysql.StatusModifiedBy,
}
var sourceFile []entity.CustomDataSourceFile
json.Unmarshal([]byte(appTempInfoMysql.CustomDataSourceFile), &sourceFile)
customData := entity.CustomDataInfo{
DetailDescription: appTempInfoMysql.CustomDataDetailDescription,
SourceFile: sourceFile,
VersionDescription: appTempInfoMysql.CustomDataVersionDescription,
Developer: appTempInfoMysql.CustomDataDeveloper,
}
result.AppID = appTempInfoMysql.AppID
result.Name = appTempInfoMysql.Name
result.Sequence = appTempInfoMysql.Sequence
result.AppClass = appTempInfoMysql.AppClass
result.AppType = appTempInfoMysql.AppType
result.Status = status
result.DeveloperID = appTempInfoMysql.DeveloperID
result.GroupID = appTempInfoMysql.GroupID
result.Created = appTempInfoMysql.Created
result.CreatedBy = appTempInfoMysql.CreatedBy
result.CustomData = customData
result.Version = appTempInfoMysql.Version
result.CoreDescription = appTempInfoMysql.CoreDescription
result.Logo = appTempInfoMysql.Logo
result.ProjectType = appTempInfoMysql.ProjectType
return result
}