package admin import ( . "../../../hotime" . "../../common" "../../dri/baidu" "fmt" "github.com/xuri/excelize" "io/ioutil" "os" "strings" "time" ) var TestCtr = Ctr{ "test": func(this *Context) { data := excel1() this.Display(0, data) }, "tt": func(this *Context) { tag_ctg := this.Db.Get("tag_ctg", "id", Map{"name": "企业数据分析"}) if tag_ctg == nil { tag_ctg = Map{} tag_ctg["id"] = this.Db.Insert("tag_ctg", Map{"name": "企业数据分析", "admin_id": this.Session("admin_id").ToInt(), "create_time": time.Now().Unix(), "modify_time": time.Now().Unix()}) } id := tag_ctg.GetCeilInt("id") if id == 0 { this.Display(3, "分类数据上传失败") return } num := 0 for k, v := range ADataType { tag := this.Db.Get("tag", "id", Map{"sn": k}) if tag == nil { tag = Map{"sn": k, "name": v, "tag_ctg_id": id, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix()} if strings.Index(k, "DF") == len(k)-2 { tag["unit"] = "分" } tagId := this.Db.Insert("tag", tag) if tagId != 0 { num++ } } } this.Display(0, num) }, "api": func(this *Context) { //curl -i --get --include 'http://api.81api.com/getCompanyBaseInfo/小米科技有限责任公司/' -H 'Authorization:APPCODE 你自己的AppCode' //aliyun.DefaultCompany.Init("06c6a07e89dd45c88de040ee1489eef7") //data,err:=aliyun.DefaultCompany.GetCompanyBaseInfo("小米科技有限责任公司") //fmt.Println(data) //if err!=nil{ // this.Display(4,err) // return //} data1, _ := baidu.DefaultBaiDuMap.GetPosition("简阳市东溪镇奎星路28号") this.Display(0, ObjToMap(data1)) }, "temp": func(this *Context) { count := 0 for true { data := this.Db.Get("area_copy", "id,parent_id,`index`,parent_code", Map{"index": nil, "ORDER": "`level` ASC"}) if data == nil { break } count++ //if data.GetCeilInt("parent_id")==0{ // data["parent_id"]=3750 //} parentData := this.Db.Get("area_copy", "id,parent_id,`index`", Map{"area_code": data.GetString("parent_code")}) if parentData == nil { this.Db.Update("area_copy", Map{"index": data.GetString("id") + ","}, Map{"id": data.GetString("id")}) } else { this.Db.Update("area_copy", Map{"index": parentData.GetString("index") + data.GetString("id") + ",", "parent_id": parentData["id"]}, Map{"id": data.GetString("id")}) } } this.Display(0, count) }, "tempctg": func(this *Context) { dataBytes, e := ioutil.ReadFile("2017.json") if e != nil { this.Display(4, e) return } data := ObjToSlice(string(dataBytes)) for k, _ := range data { ins := data.GetMap(k) ins["level"] = 1 id := this.Db.Insert("category", Map{"name": ins.GetString("name"), "code": ins.GetString("code"), "level": ins["level"], "parent_id": 1, "admin_id": this.Session("admin_id").ToInt(), "create_time": time.Now().Unix(), "modify_time": time.Now().Unix(), }) if id != 0 { ins["id"] = id } ins["index"] = ",1," + ObjToStr(id) + "," this.Db.Update("category", Map{"index": ins["index"]}, Map{"id": ins["id"]}) run(ins, this) } }, } func excel1() Slice { xlsx, err := excelize.OpenFile("tpt/piduqu.xlsx") if err != nil { fmt.Println(err) os.Exit(1) } list := xlsx.GetSheetList() data := Slice{} for _, v := range list { rows, e := xlsx.GetRows(v) fmt.Println(rows, e) data = append(data, rows) //for k1,v1:=range rows{ // //} } return data } func run(ins Map, this *Context) { cs := ins.GetSlice("children") if cs == nil { return } for ck, _ := range cs { cins := cs.GetMap(ck) cins["level"] = ins.GetCeilInt("level") + 1 id := this.Db.Insert("category", Map{"name": cins.GetString("name"), "code": cins.GetString("code"), "level": cins["level"], "parent_id": ins["id"], "admin_id": this.Session("admin_id").ToInt(), "create_time": time.Now().Unix(), "modify_time": time.Now().Unix(), }) if id != 0 { cins["id"] = id } cins["index"] = ins.GetString("index") + ObjToStr(id) + "," this.Db.Update("category", Map{"index": cins["index"]}, Map{"id": cins["id"]}) run(cins, this) } }