🀄 完善标签查询功能

This commit is contained in:
dushixiang
2021-01-06 20:29:48 +08:00
parent fbac4c7c2b
commit 1a3a4025d5
4 changed files with 82 additions and 10 deletions

View File

@ -43,7 +43,7 @@ func FindAssetByConditions(protocol string) (o []Asset, err error) {
return
}
func FindPageAsset(pageIndex, pageSize int, name, protocol string) (o []Asset, total int64, err error) {
func FindPageAsset(pageIndex, pageSize int, name, protocol, tags string) (o []Asset, total int64, err error) {
db := global.DB
if len(name) > 0 {
db = db.Where("name like ?", "%"+name+"%")
@ -53,6 +53,13 @@ func FindPageAsset(pageIndex, pageSize int, name, protocol string) (o []Asset, t
db = db.Where("protocol = ?", protocol)
}
if len(tags) > 0 {
tagArr := strings.Split(tags, ",")
for i := range tagArr {
db = db.Where("find_in_set(?, tags)", tagArr[i])
}
}
err = db.Order("created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
if o == nil {
@ -105,5 +112,5 @@ func FindAssetTags() (o []string, err error) {
o = append(o, split...)
}
return o, nil
return utils.Distinct(o), nil
}