func GetAllMusicTag(opts map[string]int) (Result, error) { var data Result // var data_map = make(map[string]string) o := orm.NewOrm() // rows := make([]db.AllMusicTags, 0) var rows []db.AllMusicTags var list = make([]string, opts["limit"]) /************放弃使用原生sql查询************/ // sql := "SELECT tag_name FROM all_music_tags limit " + opts["limit"] + " offset " + opts["offset"] // num, err := o.Raw(sql).Values(&obj) /******************************************/ qs := o.QueryTable("all_music_tags") num, err := qs.All(&rows, "TagName") if err == nil { tmpint, _ := strconv.Atoi(strconv.FormatInt(num, 10)) check := (tmpint % opts["limit"]) var total_pages int if check == 0 { total_pages = tmpint / opts["limit"] } else { total_pages = (tmpint / opts["limit"]) + 1 } data.TotalCount = tmpint data.TotalPages = total_pages // data_map["total_count"] = strconv.Itoa(tmpint) // data_map["total_pages"] = strconv.Itoa(total_pages) // fmt.Println("===total_pages===") // fmt.Println(total_pages) } num, err = qs.Limit(opts["limit"], opts["offset"]).All(&rows, "TagName") if err == nil && num > 0 { // fmt.Println("===rows===") // fmt.Println(rows) // fmt.Println(num) i := 0 for _, m := range rows { // fmt.Println("===in for range===") // fmt.Println(reflect.TypeOf(m.TagName)) // fmt.Println(m.TagName) list[i] = m.TagName i++ } data.List = list //todo go 语言接口 // jsonbyte, _ := json.Marshal(list) // list_str := string(jsonbyte) // data_map["list"] = list_str } else { common.WriteLog("select all music_tag error @MusicMod.GetAllMusicTag() : " + err.Error()) } fmt.Println("===data===") fmt.Println(data) return data, err // fmt.Println("===data===") // fmt.Println(data) }
/** * 之后注释该代码,因为九型人格添加完成后不需要再添加了 * @param {[type]} content string) (character_id int64, err error [description] */ func AddCharacter(content string) (character_id int64, err error) { var db_orm = orm.NewOrm() //orm不能定义为全局的 var res []orm.Params num, err := db_orm.Raw("SELECT * FROM character").Values(&res) if err == nil && num >= 9 { return -1, nil } character := &db.Character{ Introduction: content, } v, err := db_orm.Insert(character) if err != nil { common.WriteLog("add new character error @characterMod.AddOne() : " + err.Error()) return 0, err } return v, nil }
func AddMovieTag(content string) (tag_id int64, err error) { var db_orm = orm.NewOrm() //orm不能定义为全局的 movie_tag := &db.AllMovieTags{ TagName: content, } err = db_orm.Read(movie_tag, "TagName") if err != nil || movie_tag.TagName == "" { movie_tag = &db.AllMovieTags{ TagName: content, Created: time.Now(), Update: time.Now(), } v, e := db_orm.Insert(movie_tag) if e != nil { common.WriteLog("add new movie_tag error @MovieMod.AddMovieTag() : " + err.Error()) return 0, e } return v, nil } return -1, nil // 已经存在该tag不能添加重复的tag }