|
|
@@ -0,0 +1,118 @@ |
|
|
|
package db |
|
|
|
|
|
|
|
import ( |
|
|
|
"applet/app/db/model" |
|
|
|
"applet/app/utils" |
|
|
|
"applet/app/utils/logx" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"reflect" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
// BatchSelectUserLoginIpLists 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `UserLoginIpListFindByParams` 方法 |
|
|
|
func BatchSelectUserLoginIpLists(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserLoginIpList, error) { |
|
|
|
var UserLoginIpListData []model.UserLoginIpList |
|
|
|
if err := Db.In(utils.AnyToString(params["key"]), params["value"]). |
|
|
|
Find(&UserLoginIpListData); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &UserLoginIpListData, nil |
|
|
|
} |
|
|
|
|
|
|
|
// UserLoginIpListInsert 插入单条数据 |
|
|
|
func UserLoginIpListInsert(Db *xorm.Engine, UserLoginIpList *model.UserLoginIpList) (int64, error) { |
|
|
|
_, err := Db.InsertOne(UserLoginIpList) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return UserLoginIpList.Id, nil |
|
|
|
} |
|
|
|
|
|
|
|
// BatchAddUserLoginIpLists 批量新增数据 |
|
|
|
func BatchAddUserLoginIpLists(Db *xorm.Engine, UserLoginIpListData []*model.UserLoginIpList) (int64, error) { |
|
|
|
affected, err := Db.Insert(UserLoginIpListData) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return affected, nil |
|
|
|
} |
|
|
|
|
|
|
|
func GetUserLoginIpListCount(Db *xorm.Engine) int { |
|
|
|
var UserLoginIpList model.UserLoginIpList |
|
|
|
session := Db.Where("") |
|
|
|
count, err := session.Count(&UserLoginIpList) |
|
|
|
if err != nil { |
|
|
|
return 0 |
|
|
|
} |
|
|
|
return int(count) |
|
|
|
} |
|
|
|
|
|
|
|
// UserLoginIpListDelete 删除记录 |
|
|
|
func UserLoginIpListDelete(Db *xorm.Engine, id interface{}) (int64, error) { |
|
|
|
if reflect.TypeOf(id).Kind() == reflect.Slice { |
|
|
|
return Db.In("id", id).Delete(model.UserLoginIpList{}) |
|
|
|
} else { |
|
|
|
return Db.Where("id = ?", id).Delete(model.UserLoginIpList{}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// UserLoginIpListUpdate 更新记录 |
|
|
|
func UserLoginIpListUpdate(Db *xorm.Engine, id interface{}, UserLoginIpList *model.UserLoginIpList, forceColums ...string) (int64, error) { |
|
|
|
var ( |
|
|
|
affected int64 |
|
|
|
err error |
|
|
|
) |
|
|
|
if forceColums != nil { |
|
|
|
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(UserLoginIpList) |
|
|
|
} else { |
|
|
|
affected, err = Db.Where("id=?", id).Update(UserLoginIpList) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return affected, nil |
|
|
|
} |
|
|
|
|
|
|
|
// UserLoginIpListGetOneByParams 通过传入的参数查询数据(单条) |
|
|
|
func UserLoginIpListGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.UserLoginIpList, error) { |
|
|
|
var m model.UserLoginIpList |
|
|
|
var query = fmt.Sprintf("%s =?", params["key"]) |
|
|
|
has, err := Db.Where(query, params["value"]).Get(&m) |
|
|
|
if err != nil || has == false { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
|
|
|
|
// UserLoginIpListFindByParams 通过传入的参数查询数据(多条) |
|
|
|
func UserLoginIpListFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserLoginIpList, error) { |
|
|
|
var m []model.UserLoginIpList |
|
|
|
if params["value"] == nil { |
|
|
|
return nil, errors.New("参数有误") |
|
|
|
} |
|
|
|
if params["key"] == nil { |
|
|
|
//查询全部数据 |
|
|
|
err := Db.Find(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} else { |
|
|
|
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { |
|
|
|
//指定In查询 |
|
|
|
if err := Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} else { |
|
|
|
var query = fmt.Sprintf("%s =?", params["key"]) |
|
|
|
err := Db.Where(query, params["value"]).Find(&m) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |