Пример #1
0
// IncreasePullCount ...
func IncreasePullCount(name string) (err error) {
	o := GetOrmer()
	num, err := o.QueryTable("repository").Filter("name", name).Update(
		orm.Params{
			"pull_count":  orm.ColValue(orm.ColAdd, 1),
			"update_time": time.Now(),
		})
	if num == 0 {
		err = fmt.Errorf("Failed to increase repository pull count with name: %s %s", name, err.Error())
	}
	return err
}
Пример #2
0
func (self *NovelCollectModel) PutCollect(novelid int) (map[string]interface{}, error) {
	o := orm.NewOrm()
	_, err := o.QueryTable("novel").Filter("id", novelid).Update(orm.Params{
		"novelcollect": orm.ColValue(orm.ColAdd, 1),
	})
	if err != nil {
		return nil, err
	}
	ret := map[string]interface{}{
		"novelid": novelid,
	}
	return ret, nil
}
Пример #3
0
func (m *Post) Delete() error {
	if m.Tags != "" {
		o := orm.NewOrm()
		oldtags := strings.Split(strings.Trim(m.Tags, ","), ",")
		//标签统计-1
		o.QueryTable(&Tag{}).Filter("name__in", oldtags).Update(orm.Params{"count": orm.ColValue(orm.Col_Minus, 1)})
		//删掉tag_post表的记录
		o.QueryTable(&TagPost{}).Filter("postid", m.Id).Delete()
	}
	if _, err := orm.NewOrm().Delete(m); err != nil {
		return err
	}
	return nil
}
Пример #4
0
//根据id获取文章 todo 点击量模型未构建 返回改文章对应的标签
func GetArticleById(id interface{}) (Article, error) {
	article := Article{}
	o := orm.NewOrm()
	err := o.QueryTable("article").Filter("Id", id).RelatedSel().One(&article)

	if err == nil {
		o.QueryTable("article").Filter("Id", id).Update(orm.Params{
			"Views": orm.ColValue(orm.Col_Add, 1),
		})
		//查询该文章对应的标签
		//		var tags []*Tag
		//		_, err = o.QueryTable("tag").Filter("Articles__Article__Id", id).All(&tags)
		//		article.Tags = tags
	}

	return article, err
}
Пример #5
0
func PostBrowsersAdd(uid int, ip string, post *models.Post) {
	var key string
	if uid == 0 {
		key = ip
	} else {
		key = utils.ToStr(uid)
	}
	key = fmt.Sprintf("PCA.%d.%s", post.Id, key)
	if setting.Cache.Get(key) != nil {
		return
	}
	_, err := models.Posts().Filter("Id", post.Id).Update(orm.Params{
		"Browsers": orm.ColValue(orm.Col_Add, 1),
	})
	if err != nil {
		beego.Error("PostCounterAdd ", err)
	}
	setting.Cache.Put(key, true, 60)
}
Пример #6
0
func (this *CommentModel) AddComment(comment *Comment) (int64, error) {
	o := ORM()
	o.Begin()
	comment_id, err := o.Insert(comment)
	if err == nil {
		// adding comment count of the post
		_, err := o.QueryTable(TABLE_NAME_POST).Filter("PostId", comment.Post.PostId).Update(orm.Params{
			"CommentCount": orm.ColValue(orm.ColAdd, 1),
		})
		if err != nil {
			// error adding count
			o.Rollback()
		} else {
			o.Commit()
		}
	} else {
		// error adding comment
		o.Rollback()
	}
	return comment_id, err
}
Пример #7
0
func UpdateBet(uId int, uName string, uAvtar string, horseId int, money int) int {
	configure := new(Configure)
	configure = GetStatus()
	if configure.CValue != "1" {
		return -1100
	}

	o := orm.NewOrm()
	var bet Bet
	bet.Uid = uId

	err := o.Read(&bet, "Uid")
	if err == orm.ErrNoRows {
		bet.Uname = uName
		bet.Uavtar = uAvtar
		bet.Horseid = horseId
		bet.Money = money

		_, err = o.Insert(&bet)
		if err != nil {
			beego.Error(err)
			return -1
		}
	} else if err == nil {
		bet.Money = money
		_, err = o.QueryTable("bet").Filter("Uid", uId).Update(orm.Params{
			"money": orm.ColValue(orm.Col_Add, money),
		})
		if err != nil {
			beego.Error(err)
			return -2
		}
	} else {
		beego.Error(err)
		return -3
	}
	return 1
}
Пример #8
0
//保存
func (this *ArticleController) Save() {
	var (
		id      int64  = 0
		title   string = strings.TrimSpace(this.GetString("title"))
		content string = this.GetString("content")
		tags    string = strings.TrimSpace(this.GetString("tags"))
		urlname string = strings.TrimSpace(this.GetString("urlname"))
		color   string = strings.TrimSpace(this.GetString("color"))
		cover   string = strings.TrimSpace(this.GetString("cover"))
		timestr string = strings.TrimSpace(this.GetString("posttime"))
		status  int64  = 0
		istop   int8   = 0
		urltype int8   = 0
		post    models.Post
	)

	if title == "" {
		this.showmsg("标题不能为空!")
	}

	id, _ = this.GetInt64("id")
	status, _ = this.GetInt64("status")

	if this.GetString("istop") == "1" {
		istop = 1
	}
	if this.GetString("urltype") == "1" {
		urltype = 1
	}
	if status != 1 && status != 2 {
		status = 0
	}
	if cover == "" {
		cover = "/static/upload/defaultcover.png"
	}
	addtags := make([]string, 0)
	//标签过滤
	if tags != "" {
		tagarr := strings.Split(tags, ",")
		for _, v := range tagarr {
			if tag := strings.TrimSpace(v); tag != "" {
				exists := false
				for _, vv := range addtags {
					if vv == tag {
						exists = true
						break
					}
				}
				if !exists {
					addtags = append(addtags, tag)
				}
			}
		}
	}

	if id < 1 {
		post.Userid = this.userid
		post.Author = this.username
		post.Posttime = this.getTime()
		post.Updated = this.getTime()
		post.Insert()
		models.Cache.Delete("latestblog")
	} else {
		post.Id = id
		if post.Read() != nil {
			goto RD
		}
		if post.Tags != "" {
			var tagobj models.Tag
			var tagpostobj models.TagPost
			oldtags := strings.Split(strings.Trim(post.Tags, ","), ",")
			//标签统计-1
			tagobj.Query().Filter("name__in", oldtags).Update(orm.Params{"count": orm.ColValue(orm.ColMinus, 1)})
			//删掉tag_post表的记录
			tagpostobj.Query().Filter("postid", post.Id).Delete()
		}
	}

	if len(addtags) > 0 {
		for _, v := range addtags {
			tag := models.Tag{Name: v}
			if tag.Read("Name") == orm.ErrNoRows {
				tag.Count = 1
				tag.Insert()
			} else {
				tag.Count += 1
				tag.Update("Count")
			}
			tp := models.TagPost{Tagid: tag.Id, Postid: post.Id, Poststatus: int8(status), Posttime: this.getTime()}
			tp.Insert()
		}
		post.Tags = "," + strings.Join(addtags, ",") + ","
	}
	if posttime, err := time.Parse("2006-01-02 15:04:05", timestr); err == nil {
		post.Posttime = posttime
	} else {
		post.Posttime, _ = time.Parse("2006-01-02 15:04:05", post.Posttime.Format("2006-01-02 15:04:05"))
	}
	post.Status = int8(status)
	post.Title = title
	post.Color = color
	post.Istop = istop
	post.Cover = cover
	post.Content = content
	post.Urlname = urlname
	post.Urltype = urltype
	post.Updated = this.getTime()
	post.Update("tags", "status", "title", "color", "cover", "istop", "content", "urlname", "urltype", "updated", "posttime")

RD:
	this.Redirect("/admin/article/list", 302)
}
Пример #9
0
func AddPV(id interface{}) {
	o := orm.NewOrm()
	o.QueryTable("Topic").Filter("Id", id).Update(orm.Params{"PV": orm.ColValue(orm.Col_Add, 1)})
}
Пример #10
0
func UpdateUserCourseHour(uid int64, count int) error {
	o := orm.NewOrm()
	_, err := o.QueryTable("user").Filter("id", uid).Update(orm.Params{
		"coursehour": orm.ColValue(orm.ColAdd, count)})
	return err
}
Пример #11
0
func (this *ProjectEnvironmentController) BuildApi() {

	//projectenvid := this.Input().Get("projectenvid")
	envid := this.Input().Get("envid")
	intenvid, _ := strconv.Atoi(envid)

	rundeckbuildjobid := this.Input().Get("rundeckbuildjobid")
	//rundeckpackagejobid := this.Input().Get("rundeckpackagejobid")
	projectid := this.Input().Get("projectid")
	branchname := this.Input().Get("branchname")

	o := orm.NewOrm()

	//添加版本号数据以及更新项目版本号
	var project models.Projectinfo

	o.QueryTable("Projectinfo").Filter("Id", projectid).Update(orm.Params{
		"BuildNumber": orm.ColValue(orm.Col_Add, 1),
	})

	o.QueryTable("Projectinfo").Filter("Id", projectid).One(&project)

	now := time.Now()

	fmt.Println(now)

	var pb models.Projectbuild
	pb.Projectid = project.Id
	pb.Buildnumber = project.Buildnumber
	pb.Branchname = branchname
	pb.Created = now
	pb.Buildstatus = 1
	pb.Envid = intenvid
	id, _ := o.Insert(&pb)

	//获取项目环境信息进行编译部署
	var env models.Environmentinfo
	o.QueryTable("Environmentinfo").Filter("id", envid).One(&env)

	args := map[string]string{"BUILD_NUMBER": strconv.Itoa(project.Buildnumber), "Branch_NAME": branchname, "Repository_Path": project.Repositorypath}

	response := utility.RundeckRunJob(env.Rundeckapiurl, env.Rundeckapiauthtoken, rundeckbuildjobid, args)
	fmt.Println(response)

	//parse rundeck api xml response
	r := models.RunJobExecutions{}
	xml_err := xml.Unmarshal([]byte(response), &r)

	if xml_err != nil {
		fmt.Printf("error: %v", xml_err)
		this.Data["json"] = xml_err //url.QueryEscape(logs[0].Packagepath)
		this.ServeJson()
	}

	if r.Exs != nil {
		o.QueryTable("Projectbuild").Filter("Id", id).Update(orm.Params{
			"BuildStatus": 2,
			"ExecutionId": r.Exs[0].Id,
		})
		fmt.Println(r.Exs[0].Id)
	}
	//rundeck执行完成之后读取git hash
	dat, _ := ioutil.ReadFile("/Volumes/ftproot/mtime/upversion/MtimeGoConfigWeb/2/config-web/GitBranchHash")
	//check(err)
	fmt.Print(string(dat))

	o.QueryTable("Projectbuild").Filter("Id", id).Update(orm.Params{
		"BranchHash": string(dat),
	})

	//fmt.Println(response)

	//fmt.Println(projectenvid)
	//fmt.Println(envid)
	//fmt.Println(rundeckbuildjobid)
	//fmt.Println(rundeckpackagejobid)
	//fmt.Println(projectid)
	//fmt.Println(branchname)

	this.Data["json"] = models.BuildApiModel{models.JsonResultBaseStruct{Result: true, Message: "操作成功"}, r.Exs[0].Id}
	this.ServeJson()
}
Пример #12
0
func UpdateCourseSelected(cid int64, count int) error {
	o := orm.NewOrm()
	_, err := o.QueryTable("course").Filter("id", cid).Update(orm.Params{
		"selected": orm.ColValue(orm.ColAdd, count)})
	return err
}
Пример #13
0
func UpdateRaceRuselt(WinnerId int) int {
	configure := new(Configure)
	configure = GetStatus()
	if configure.CValue != "2" {
		return -1101
	}

	o := orm.NewOrm()

	// 事务开始
	err := o.Begin()

	winNum, err := o.QueryTable("horse").Filter("id", WinnerId).Update(orm.Params{
		"win": orm.ColValue(orm.Col_Add, 1),
	})
	if err != nil || winNum != 1 {
		beego.Error(err)
		return -1
	}

	loseNum, err := o.QueryTable("horse").Exclude("id", WinnerId).Update(orm.Params{
		"lose": orm.ColValue(orm.Col_Add, 1),
	})
	if err != nil || loseNum != 5 {
		beego.Error(err)
		return -2
	}

	if winNum == 1 && loseNum == 5 {
		err = o.Commit()
	} else {
		err = o.Rollback()
		return -3
	}

	if err != nil {
		beego.Error(err)
		return 0
	}

	// 将中奖者的记录从bet表移动到winlog表
	bets, err := GetBet(WinnerId)
	// winlogs := make([]*Winlog,0)
	if err != nil {
		beego.Error(err)
		if err != orm.ErrNoRows {
			return -5
		}
	} else {
		var winlog Winlog
		timeStr := time.Now().Format("2006-01-02 15:04:05")
		qs := o.QueryTable("winlog")
		i, _ := qs.PrepareInsert()
		for _, val := range bets {
			winlog.Uid = val.Uid
			winlog.Uname = val.Uname
			winlog.Uavtar = val.Uavtar
			winlog.Horseid = val.Horseid
			winlog.Money = val.Money
			winlog.Time = timeStr
			_, err := i.Insert(&winlog)
			if err != nil {
				beego.Error(err)
				return -4
			}
		}
		i.Close()
	}

	UpdateStatus("0")
	return 1
}