go-wxhelper/service/robot/select.go

26 lines
723 B
Go

package robot
import (
"database/sql"
"wechat-robot/internal/database"
"wechat-robot/model/entity"
robotParam "wechat-robot/model/param/robot"
)
// GetAll
// @description: 查询所有机器人
// @param p robotParam.GetAll 查询所有机器人入参
// @return records []entity.Robot 查询所有机器人返回值
// @return err error 查询所有机器人返回值
func GetAll(p robotParam.GetAll) (records []entity.Robot, err error) {
tx := database.Client.Order("created_at desc")
if p.Keyword != "" {
tx.Where("nickname LIKE @keyword OR remark LIKE @keyword", sql.Named("keyword", "%"+p.Keyword+"%"))
}
if p.Tag != "" {
tx.Where("tag LIKE ?", "%"+p.Tag+"%")
}
err = tx.Find(&records).Error
return
}