本文整理汇总了Golang中github.com/astaxie/beego/orm.NewCondition函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCondition函数的具体用法?Golang NewCondition怎么用?Golang NewCondition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewCondition函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: QueryMineTeams
func QueryMineTeams(query string, uid int64) (orm.QuerySeter, error) {
qs := orm.NewOrm().QueryTable(new(Team))
condMine := orm.NewCondition()
condMine = condMine.Or("Creator", uid)
tids, err := Tids(uid)
if err != nil {
return qs, err
}
if len(tids) > 0 {
condMine = condMine.Or("Id__in", tids)
}
condResult := orm.NewCondition().AndCond(condMine)
if query != "" {
condQuery := orm.NewCondition()
condQuery = condQuery.And("Name__icontains", query)
condResult = condResult.AndCond(condQuery)
}
qs = qs.SetCond(condResult)
return qs, nil
}
示例2: GetAll
// @Title 获取日志列表
// @Description 获取日志列表
// @Param level query int false "日志级别"
// @Param type query int false "日志类型"
// @Param by query string false "记录产生者"
// @Param on_begin query string false "日志记录起始时间"
// @Param on_end query string false "日志记录终止时间"
// @Param pageIndex query int false "页码, 默认1"
// @Param pageSize query int false "每页显示条数, 默认30"
// @Success 200 {object} models.Log
// @Failure 400 请求的参数不正确
// @router / [get]
func (this *LogController) GetAll() {
cond := orm.NewCondition()
if level, _ := this.GetInt64("level", -1); level != -1 {
cond = cond.And("Level", level)
}
if typi, _ := this.GetInt64("type", -1); typi != -1 {
cond = cond.And("Type", typi)
}
if by := this.GetString("by"); by != "" {
cond = cond.And("LogBy", by)
}
if on_begin := this.GetString("on_begin"); on_begin != "" {
cond = cond.And("LogOn__gt", on_begin)
}
if on_end := this.GetString("on_end"); on_end != "" {
cond = cond.And("LogOn__lt", on_end)
}
pageIndex, _ := this.GetInt("pageIndex", 1)
pageSize, _ := this.GetInt("pageSize", 30)
logs, total, err := models.GetAllLogs(cond, pageIndex, pageSize)
if err != nil {
this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
}
this.Data["json"] = map[string]interface{}{
"code": 0,
"data": logs,
"total": total,
}
this.ServeJson()
}
示例3: UpdateResourcePools
func UpdateResourcePools(resourcesPools []ResourcesPools) ([]ResourcesPools, error) {
qs := orm.NewOrm().QueryTable(new(ResourcesPools))
cond := orm.NewCondition()
cond1 := cond.And("id__isnull", false)
qs.SetCond(cond1).Delete()
insert, _ := qs.PrepareInsert()
for index, values := range resourcesPools {
id, err := insert.Insert(&values)
if err != nil {
beego.Error("Insert ResourcePools error :%s", err)
} else {
values.Id = id
resourcesPools[index] = values
}
}
insert.Close()
return resourcesPools, nil
}
示例4: QueryRoles
func QueryRoles(query string) orm.QuerySeter {
qs := orm.NewOrm().QueryTable(new(Role))
if query != "" {
qs = qs.SetCond(orm.NewCondition().Or("Name__icontains", query))
}
return qs
}
示例5: Search
func (this *TbOption) Search(key string, columns map[string]string, offset, limit int) []Tb {
tbs := make([]Tb, 0)
cond := orm.NewCondition()
if len(columns) > 0 {
condColumn := orm.NewCondition()
for column, columnVal := range columns {
condColumn = condColumn.And(fmt.Sprintf("%s__icontains", column), columnVal)
}
cond = cond.AndCond(condColumn)
}
if len(key) > 0 {
cond = cond.AndCond(cond.Or("title__icontains", key).Or("desc__icontains", key).Or("why__icontains", key).Or("fix__icontains", key))
}
this.Orm.QueryTable("Tb").SetCond(cond).OrderBy("-id").Offset(offset).Limit(limit).All(&tbs)
return tbs
}
示例6: CanRegistered
func (this *UserService) CanRegistered(userName string, email string) (canName bool, canEmail bool, err error) {
cond := orm.NewCondition()
cond = cond.Or("Username", userName).Or("email", email)
var maps []orm.Params
var n int64
n, err = this.Queryable().SetCond(cond).Values(&maps, "Username", "email")
if err != nil {
return false, false, err
}
canName = true
canEmail = true
if n > 0 {
for _, m := range maps {
if canName && orm.ToStr(m["Username"]) == userName {
canName = false
}
if canEmail && orm.ToStr(m["Email"]) == email {
canEmail = false
}
}
}
return canName, canEmail, nil
}
示例7: Get
func (this *OptionController) Get() {
this.CheckAvaliable("选项设置")
this.TplNames = "manage/basic/option.tpl"
this.LayoutSections["LayoutFooter"] = "manage/basic/option_script.tpl"
cond := orm.NewCondition()
if section := this.GetString(":section"); section != "" {
cond = cond.And("section", section)
}
var optionSections []models.OptionSection = make([]models.OptionSection, 0)
var optionList []models.Option
if _, err := models.Orm.QueryTable("option").SetCond(cond).All(&optionList); err == nil {
for _, option := range optionList {
if !putOptionToSection(option, &optionSections) {
var new_section models.OptionSection
new_section.Options = make([]models.Option, 1)
new_section.SectionName = option.SectionName
new_section.Options[0] = option
if len(optionSections) > 0 {
optionSections[len(optionSections)-1].HasNext = true
}
optionSections = append(optionSections, new_section)
}
}
} else {
beego.Error(err.Error())
}
this.Data["OptionSections"] = &optionSections
}
示例8: GetAll
// @Title 获取警告列表
// @Description 获取警告列表
// @Param tid query int false "终端ID"
// @Param uid query int false "用户ID"
// @Param gid query int false "车队ID"
// @Param time_begin query string false "警告记录起始时间"
// @Param time_end query string false "警告记录终止时间"
// @Param pageIndex query int false "页码, 默认1"
// @Param pageSize query int false "每页显示条数, 默认30"
// @Success 200 {object} models.Warning
// @Failure 400 请求的参数不正确
// @router / [get]
func (this *WarningController) GetAll() {
cond := orm.NewCondition()
if tid, _ := this.GetInt64("tid", -1); tid != -1 {
cond = cond.And("TerminalId", tid)
}
if uid, _ := this.GetInt64("uid", -1); uid != -1 {
cond = cond.And("UserId", uid)
}
if gid, _ := this.GetInt64("gid", -1); gid != -1 {
cond = cond.And("GroupId", gid)
}
if on_begin := this.GetString("time_begin"); on_begin != "" {
cond = cond.And("CreateOn__gt", on_begin)
}
if on_end := this.GetString("time_end"); on_end != "" {
cond = cond.And("CreateOn__lt", on_end)
}
pageIndex, _ := this.GetInt("pageIndex", 1)
pageSize, _ := this.GetInt("pageSize", 30)
warnings, total, err := models.GetAllWarnings(cond, pageIndex, pageSize)
if err != nil {
this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
}
this.Data["json"] = map[string]interface{}{
"code": 0,
"data": warnings,
"total": total,
}
this.ServeJson()
}
示例9: CanRegistered
func CanRegistered(userName string, email string) (bool, bool, error) {
cond := orm.NewCondition()
cond = cond.Or("UserName", userName).Or("Email", email)
var maps []orm.Params
o := orm.NewOrm()
n, err := o.QueryTable("user").SetCond(cond).Values(&maps, "UserName", "Email")
if err != nil {
return false, false, err
}
e1 := true
e2 := true
if n > 0 {
for _, m := range maps {
if e1 && orm.ToStr(m["UserName"]) == userName {
e1 = false
}
if e2 && orm.ToStr(m["Email"]) == email {
e2 = false
}
}
}
return e1, e2, nil
}
示例10: ParseQuery
func (this *Base) ParseQuery(fields ...string) *orm.Condition {
cond := orm.NewCondition()
for _, v := range fields {
entity := this.GetString("q" + v)
if len(entity) != 0 {
switch entity[0] {
case '*':
{
cond = cond.And(v+"__icontains", entity[1:])
}
case '?':
{
cond = cond.Or(v+"__icontains", entity[1:])
}
case '!':
{
cond = cond.AndNot(v+"__icontains", entity[1:])
}
case '~':
{
cond = cond.OrNot(v+"__icontains", entity[1:])
}
}
}
}
return cond
}
示例11: GetMessageList
// @router /api/manage/weixin/message/getMessageList [post]
func (this *MessageController) GetMessageList() {
this.CheckAvaliable("消息查看")
lastID, _ := this.GetInt("lastID")
size, _ := this.GetInt("size")
if size == 0 {
size = 25
}
cond := orm.NewCondition()
if lastID > 0 {
cond = cond.And("Id__lt", lastID)
}
var messageList []models.Message
if _, err := models.Orm.QueryTable("message").SetCond(cond).OrderBy("-Id").Limit(size).All(&messageList); err == nil {
var messageExList []models.MessageEx = make([]models.MessageEx, len(messageList))
for i, v := range messageList {
var user models.FollowUser
user.UserId = v.UserId
models.Orm.Read(&user, "UserId")
messageExList[i] = models.MessageEx{Message: v, User: user}
messageExList[i].CreateOnFmt = v.CreateOn.Format("2006-01-02 15:04:05")
}
this.Data["json"] = &messageExList
} else {
beego.Error(err.Error())
}
this.ServeJson()
}
示例12: QueryUsers
func QueryUsers(query string) orm.QuerySeter {
qs := orm.NewOrm().QueryTable(new(User))
if query != "" {
cond := orm.NewCondition()
cond = cond.Or("Name__icontains", query).Or("Email__icontains", query)
qs = qs.SetCond(cond)
}
return qs
}
示例13: ReadInMonth
func (this *PlanOption) ReadInMonth(startTime, endTime int64) []Plan {
plans := make([]Plan, 0)
cond := orm.NewCondition()
condS := cond.And("startTime__gt", startTime).And("startTime__lt", endTime)
condE := cond.And("endTime__gt", startTime).And("endTime__lt", endTime)
condR := cond.And("realTime__gt", startTime).And("realTime__lt", endTime)
this.Orm.QueryTable("plan").SetCond(cond.AndCond(condS).OrCond(condE).OrCond(condR)).All(&plans)
return plans
}
示例14: GetList
func (pl *ProjectList) GetList(filter map[string]interface{}) (projects []*models.Project, err error) {
qs := models.GetDB().QueryTable("projects").RelatedSel("BussinessUser", "Progress", "ArtUser", "TechUser", "Registrant").OrderBy("-created").Filter("del_status", 0)
for k, v := range filter {
if !isKeyFitForFilter(k) {
continue
}
if k == "start_date" {
start, _ := time.Parse(timeFormat, v.(string))
qs = qs.Filter("started__gte", start)
continue
}
if k == "end_date" {
end, _ := time.Parse(timeFormat, v.(string))
qs = qs.Filter("started__lte", end)
continue
}
qs = qs.Filter(k, v)
}
if filter["user"] != nil {
cond := orm.NewCondition()
cond1 := cond.And("tech_user_id", filter["user"]).Or("art_user_id", filter["user"]).Or("registrant", filter["user"]).Or("bussiness_user_id", filter["user"])
qs = qs.SetCond(cond1)
}
count, err := qs.Count()
if err != nil {
return nil, err
}
pl.count = count
if filter["limit"] != nil {
qs = qs.Limit(filter["limit"].(int))
}
if filter["offset"] != nil {
qs = qs.Offset(filter["offset"].(int))
}
_, err = qs.All(&pl.projectList)
if err != nil {
return nil, err
}
//
err = setProjectListJobsNum(pl.projectList)
if err != nil {
return nil, err
}
return pl.projectList, nil
}
示例15: GetQuestionsCount
//-----------------------------------------------------------------------------
func GetQuestionsCount(offset int, limit int, path string) (int64, error) {
if path == "unanswered" {
cond1 := orm.NewCondition().And("ReplyCount", 0).Or("Ctype", Unanswered)
total, err := Questions().SetCond(cond1).Limit(limit, offset).Count()
return total, err
} else {
total, err := Questions().Limit(limit, offset).Count()
return total, err
}
}