用户列表

This commit is contained in:
wuchao 2024-05-07 10:00:35 +08:00
parent c7813a4863
commit 3f0836c5cd
2 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package userinfomodel
import (
"github.com/qit-team/snow-core/db"
"sync"
"time"
)
var (
once sync.Once
m *UserInfoModel
)
// 实体
type UserInfo struct {
Id int `xorm:"'Id' int(11)"`
Clientuniqueidentification string `xorm:"'ClientUniqueIdentification' varchar(255)"`
Mobile string `xorm:"'Mobile' varchar(13)"`
Status int `xorm:"'Status' TINYINT"`
Lastupdatetime time.Time `xorm:"'LastUpdateTime' datetime"`
Createtime time.Time `xorm:"'CreateTime' datetime"`
}
// 表名
func (m *UserInfo) TableName() string {
return "UserInfo"
}
// 私有化防止被外部new
type UserInfoModel struct {
db.Model //组合基础Model集成基础Model的属性和方法
}
// 单例模式
func GetInstance() *UserInfoModel {
once.Do(func() {
m = new(UserInfoModel)
//m.DiName = "" //设置数据库实例连接默认db.SingletonMain
})
return m
}
func (m *UserInfoModel) GetListByMobile(mobile string, limits ...int) (banners []*UserInfo, err error) {
banners = make([]*UserInfo, 0)
err = m.GetList(&banners, "Mobile like ?", []interface{}{"%" + mobile + "%"}, limits)
return
}

55
app/services/user.go Normal file
View File

@ -0,0 +1,55 @@
package services
import (
"fmt"
"github.com/ahmetb/go-linq/v3"
"qteam/app/http/entities/backend"
"qteam/app/models/userinfomodel"
"xorm.io/builder"
)
func GetListByMobile(mobile string, page int, limit int) (userlist []*userinfomodel.UserInfo, err error) {
limitStart := GetLimitStart(limit, page)
userlist, err = userinfomodel.GetInstance().GetListByMobile(mobile, limitStart...)
return
}
func GetListByWhere(where map[string]interface{}, page int, limit int) (count int64, UserList []backend.UserListResponse, err error) {
conn := builder.NewCond()
UserListInfo := []userinfomodel.UserInfo{}
for k, v := range where {
if v != "" {
conn = conn.And(builder.Like{k, fmt.Sprint(v)})
}
}
session := userinfomodel.GetInstance().GetDb().Where(conn)
if page != 0 && limit != 0 {
session = session.Limit(page, (page-1)*limit)
}
count, err = session.FindAndCount(&UserListInfo)
linq.From(UserListInfo).SelectT(func(in userinfomodel.UserInfo) (d backend.UserListResponse) {
d = in.ToDomain()
return d
}).ToSlice(&UserList)
if err != nil {
return
}
return
}
func GetLimitStart(limit int, page int) (arr []int) {
arr = make([]int, 2)
if limit <= 0 {
limit = 20
}
arr[0] = limit
if page > 0 {
arr[1] = (page - 1) * limit
} else {
arr[1] = 0
}
return
}