Skip to content

Commit

Permalink
update resource instance query
Browse files Browse the repository at this point in the history
  • Loading branch information
zgyzgyhero committed Jan 16, 2025
1 parent 5bf96fd commit 059a64d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
12 changes: 7 additions & 5 deletions platform-core/models/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ type ResourceItem struct {
ResourceServerId string `json:"resourceServerId" xorm:"resource_server_id"` // 关联资源
AdditionalProperties string `json:"additionalProperties" xorm:"additional_properties"` // 连接参数
CreatedBy string `json:"createdBy" xorm:"created_by"` // 创建人
CreatedDate time.Time `json:"createdDate" xorm:"created_date"` // 创建时间
CreatedDate time.Time `json:"-" xorm:"created_date"` // 创建时间
IsAllocated bool `json:"isAllocated" xorm:"is_allocated"` // 是否分配
Name string `json:"name" xorm:"name"` // 名称
Purpose string `json:"purpose" xorm:"purpose"` // 描述
Status string `json:"status" xorm:"status"` // 状态
Type string `json:"type" xorm:"type"` // 类型
UpdatedBy string `json:"updatedBy" xorm:"updated_by"` // 更新人
UpdatedDate time.Time `json:"updatedDate" xorm:"updated_date"` // 更新时间
UpdatedDate time.Time `json:"-" xorm:"updated_date"` // 更新时间
Username string `json:"username" xorm:"username"` // 连接用户名
Password string `json:"password" xorm:"password"` // 连接用户密码
}

type ResourceItemQueryRow struct {
ResourceItem
ResourceServer string `json:"resourceServer"`
Port string `json:"port"`
Used bool `json:"used"`
ResourceServer string `json:"resourceServer"`
Port string `json:"port"`
Used bool `json:"used"`
CreatedDateString string `json:"createdDate"` // 创建时间
UpdatedDateString string `json:"updatedDate"` // 更新时间
}

type ResourceServerListPageData struct {
Expand Down
19 changes: 16 additions & 3 deletions platform-core/services/database/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func QueryResourceItem(ctx context.Context, param *models.QueryRequestParam) (re
}
for _, row := range queryRows {
tmpRow := models.ResourceItemQueryRow{ResourceItem: *row}
tmpRow.CreatedDateString = tmpRow.CreatedDate.Format(models.DateTimeFormat)
tmpRow.UpdatedDateString = tmpRow.UpdatedDate.Format(models.DateTimeFormat)
for _, resourceRow := range resourceList.Contents {
if resourceRow.Id == row.ResourceServerId {
tmpRow.ResourceServer = resourceRow.Host
Expand Down Expand Up @@ -221,6 +223,12 @@ func decodeUIAesPassword(seed, password string) (decodePwd string, err error) {
func CreateResourceItem(ctx context.Context, params []*models.ResourceItem, operator string) (err error) {
var actions []*db.ExecAction
nowTime := time.Now()
var existResourceItemRows []*models.ResourceItem
err = db.MysqlEngine.Context(ctx).SQL("select id,name,`type` from resource_item").Find(&existResourceItemRows)
if err != nil {
err = exterror.Catch(exterror.New().DatabaseQueryError, err)
return
}
for _, v := range params {
if v.Type != "mysql_database" {
err = fmt.Errorf("item type %s illegal", v.Type)
Expand All @@ -230,6 +238,12 @@ func CreateResourceItem(ctx context.Context, params []*models.ResourceItem, oper
err = fmt.Errorf("resource server can not empty")
return
}
for _, existRow := range existResourceItemRows {
if existRow.Type == v.Type && existRow.Name == v.Name {
err = fmt.Errorf("resourceItem type:%s name:%s already exists", v.Type, v.Name)
return
}
}
v.Id = "rs_item_" + guid.CreateGuid()
if decodePwd, tmpErr := DecodeUIPassword(ctx, v.Password); tmpErr != nil {
err = fmt.Errorf("try to decode ui password fail,%s ", tmpErr.Error())
Expand Down Expand Up @@ -370,10 +384,9 @@ func ValidateResourceServer(ctx context.Context, resourceServer *models.Resource
if len(queryResult) > 0 {
legalFlag := false
if resourceServer.Id != "" {
for _, v := range queryResult {
if v["id"] == resourceServer.Id {
if len(queryResult) == 1 {
if queryResult[0]["id"] == resourceServer.Id {
legalFlag = true
break
}
}
}
Expand Down

0 comments on commit 059a64d

Please sign in to comment.