parent
24b5313ccf
commit
a129eb36ae
@ -0,0 +1,42 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||||
|
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Nodes 列出从机节点
|
||||||
|
func (service *AdminListService) Nodes() serializer.Response {
|
||||||
|
var res []model.Node
|
||||||
|
total := 0
|
||||||
|
|
||||||
|
tx := model.DB.Model(&model.Node{})
|
||||||
|
if service.OrderBy != "" {
|
||||||
|
tx = tx.Order(service.OrderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range service.Conditions {
|
||||||
|
tx = tx.Where(k+" = ?", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(service.Searches) > 0 {
|
||||||
|
search := ""
|
||||||
|
for k, v := range service.Searches {
|
||||||
|
search += k + " like '%" + v + "%' OR "
|
||||||
|
}
|
||||||
|
search = strings.TrimSuffix(search, " OR ")
|
||||||
|
tx = tx.Where(search)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总数用于分页
|
||||||
|
tx.Count(&total)
|
||||||
|
|
||||||
|
// 查询记录
|
||||||
|
tx.Limit(service.PageSize).Offset((service.Page - 1) * service.PageSize).Find(&res)
|
||||||
|
|
||||||
|
return serializer.Response{Data: map[string]interface{}{
|
||||||
|
"total": total,
|
||||||
|
"items": res,
|
||||||
|
}}
|
||||||
|
}
|
Loading…
Reference in new issue