fix: add instance center Add fuzzy queries of ai

This commit is contained in:
qiwang 2024-10-09 11:51:20 +08:00
parent c12484bf2e
commit 6ab1fa8fd7
3 changed files with 35 additions and 18 deletions

View File

@ -37,6 +37,7 @@ type (
InstanceCenterReq{
InstanceType int32 `form:"instance_type"`
InstanceClass string `form:"instance_class,optional"`
InstanceName string `form:"instance_name,optional"`
}
InstanceCenterResp {
InstanceCenterList []InstanceCenterList `json:"instanceCenterList" copier:"InstanceCenterList"`

View File

@ -32,30 +32,45 @@ func (l *InstanceCenterLogic) InstanceCenter(req *types.InstanceCenterReq) (*typ
var InstanceCenterLists []types.InstanceCenterList
if req.InstanceType == 0 {
l.svcCtx.DbEngin.Raw("select * from ai_instance_center").Scan(&InstanceCenter)
tx := l.svcCtx.DbEngin.Raw("select * from ai_instance_center where instance_name like CONCAT(?, '%')", req.InstanceName).Scan(&InstanceCenter)
if tx.Error == nil {
logx.Error("find nil")
}
} else if req.InstanceType != 0 && req.InstanceClass == "" {
l.svcCtx.DbEngin.Raw("select * from ai_instance_center where instance_type = ? ", req.InstanceType).Scan(&InstanceCenter)
tx := l.svcCtx.DbEngin.Raw("select * from ai_instance_center where instance_type = ? and instance_name like CONCAT(?, '%')", req.InstanceType, req.InstanceName).Scan(&InstanceCenter)
if tx.Error == nil {
logx.Error("find nil")
}
} else {
l.svcCtx.DbEngin.Raw("select * from ai_instance_center where instance_type = ? and instance_class = ?", req.InstanceType, req.InstanceClass).Scan(&InstanceCenter)
tx := l.svcCtx.DbEngin.Raw("select * from ai_instance_center where instance_type = ? and instance_class = ? and instance_name like CONCAT(?, '%')", req.InstanceType, req.InstanceClass, req.InstanceName).Scan(&InstanceCenter)
if tx.Error == nil {
logx.Error("find nil")
}
}
var instanceCenter = *InstanceCenter
if InstanceCenter == nil {
resp.Code = 200
resp.Msg = "No content found"
} else {
var instanceCenter = *InstanceCenter
for _, instanceCenter := range instanceCenter {
var instanceCenterlist types.InstanceCenterList
instanceCenterlist.InstanceName = instanceCenter.InstanceName
instanceCenterlist.InstanceType = instanceCenter.InstanceType
instanceCenterlist.InstanceClass = instanceCenter.InstanceClass
instanceCenterlist.Description = instanceCenter.Description
instanceCenterlist.InstanceClassChinese = instanceCenter.InstanceClassChinese
instanceCenterlist.Version = instanceCenter.Version
instanceCenterlist.LogoPath = instanceCenter.LogoPath
InstanceCenterLists = append(InstanceCenterLists, instanceCenterlist)
for _, instanceCenter := range instanceCenter {
var instanceCenterlist types.InstanceCenterList
instanceCenterlist.InstanceName = instanceCenter.InstanceName
instanceCenterlist.InstanceType = instanceCenter.InstanceType
instanceCenterlist.InstanceClass = instanceCenter.InstanceClass
instanceCenterlist.Description = instanceCenter.Description
instanceCenterlist.InstanceClassChinese = instanceCenter.InstanceClassChinese
instanceCenterlist.Version = instanceCenter.Version
instanceCenterlist.LogoPath = instanceCenter.LogoPath
InstanceCenterLists = append(InstanceCenterLists, instanceCenterlist)
}
resp.Code = 200
resp.Msg = "success"
resp.InstanceCenterList = InstanceCenterLists
resp.TotalCount = len(InstanceCenterLists)
}
resp.Code = 200
resp.Msg = "success"
resp.InstanceCenterList = InstanceCenterLists
resp.TotalCount = len(InstanceCenterLists)
return &resp, nil
}

View File

@ -3668,6 +3668,7 @@ type InstanceCenterList struct {
type InstanceCenterReq struct {
InstanceType int32 `form:"instance_type"`
InstanceClass string `form:"instance_class,optional"`
InstanceName string `form:"instance_name,optional"`
}
type InstanceCenterResp struct {