// get adspace list, may filtered by adspace name func GetAdspaceList(page int64, page_size int64, sort string, mediaid int, adspacename string) (adspaceVos []AdspaceVo, count int64) { var offset int64 if page <= 1 { offset = 0 } else { offset = (page - 1) * page_size } var maps []orm.Params o := orm.NewOrm() var r orm.RawSeter var query string = "SELECT a.id, a.name, a.media_id, a.description, a.pmp_adspace_key, m.name as media, a.est_daily_imp, a.est_daily_clk, a.est_daily_ctr FROM pmp_adspace a, pmp_media m WHERE a.media_id = m.id AND a.del_flg != 1 " var adspacenamecon string = "%" + adspacename + "%" if mediaid == -1 && adspacename == "" { query = query + "ORDER BY a.id ASC limit ? offset ?" r = o.Raw(query, page_size, offset) } else if mediaid != -1 && adspacename != "" { query = query + "AND m.id=? AND a.name like ? ORDER BY a.id ASC limit ? offset ?" r = o.Raw(query, mediaid, adspacenamecon, page_size, offset) } else if mediaid != -1 { query = query + "AND m.id=? ORDER BY a.id ASC limit ? offset ?" r = o.Raw(query, mediaid, page_size, offset) } else { query = query + "AND a.name like ? ORDER BY a.id ASC limit ? offset ?" r = o.Raw(query, adspacenamecon, page_size, offset) } num, err := r.Values(&maps) if err == nil { fmt.Println("adspace nums: ", num) } else { fmt.Println(err) return nil, 0 } if maps == nil || len(maps) == 0 { fmt.Println("query return with no rows. ") return nil, 0 } fmt.Println(maps) var impstr, clkstr, ctrstr, descstr string var idint, mediaidint int var namestr, mediastr, pmpAdspaceKeystr string for index := 0; index < len(maps); index++ { imp := maps[index]["est_daily_imp"] clk := maps[index]["est_daily_clk"] ctr := maps[index]["est_daily_ctr"] if impv, ok := imp.(string); ok { impstr = impv } if clkv, ok := clk.(string); ok { clkstr = clkv } if ctrv, ok := ctr.(string); ok { ctrstr = ctrv } est := impstr + "," + clkstr + "," + ctrstr // fmt.Println("**********" + est + "**********") if idv, ok := maps[index]["id"].(string); ok { idint, _ = strconv.Atoi(idv) } if idv, ok := maps[index]["media_id"].(string); ok { mediaidint, _ = strconv.Atoi(idv) } if namev, ok := maps[index]["name"].(string); ok { namestr = namev } if mediav, ok := maps[index]["media"].(string); ok { mediastr = mediav } if descv, ok := maps[index]["description"].(string); ok { descstr = descv } if v, ok := maps[index]["pmp_adspace_key"].(string); ok { pmpAdspaceKeystr = v } adspaceVos = append(adspaceVos, AdspaceVo{Id: idint, Name: namestr, MediaName: mediastr, EstDaily: est, MediaId: mediaidint, Description: descstr, PmpAdspaceKey: pmpAdspaceKeystr}) } return adspaceVos, int64(len(adspaceVos)) }