func ChangePassword(id int64, cipher string) error { _, b, err := gos.PraseCipher([]byte(cipher)) if err != nil { return gos.NewError(0, err) } arr := bytes.Split(b, separator) obj := db.DataRow{} obj["salt"], obj["token"] = UserToken(string(arr[0]), arr[1]) _, err = db.NewUpdateBuilder("users").Where("id=?", id).Update(obj) return err }
func (u *ArticleModel) Update(cid, title string, body []byte) (bool, error) { vo := NewArticleVO(int64(0), title, body) vo.Html = blackfriday.MarkdownCommon(body) reg, _ := regexp.Compile("\\<[\\S\\s]+?\\>") vo.Description = reg.ReplaceAll(vo.Html, []byte("")) _, err := db.NewUpdateBuilder(u.Table()).Where("cid=?", cid).Update(vo) if err != nil { return false, err } return true, err }
func (s *jsonGgcgData) Parse() []*ggcgVO { dataset := make([]*ggcgVO, 0) query := db.NewQueryBuilder("stock") upd := db.NewUpdateBuilder("stock") var tmp []string var arr []string var row db.DataRow var ggcg *ggcgVO for _, item := range s.Data { arr = strings.Split(item, ",") tmp = strings.Split(strings.ToLower(arr[15]), ".") row, _ = query.Where("code=? and ctype=?", tmp[0], tmp[1]).QueryOne() if row.Empty() { continue } upd.Where("id=?", row.GetInt64("id")).Update(db.DataRow{"name": arr[9]}) // "0.00444,谢飞鹏,002420,谢杏思,A股,2015-11-16,-17800, 0 ,9.44, 毅昌股份,父母,YCGF,竞价交易,-168032,董事,002420.SZ" // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // "0.00025,邓伦明,002539,邓伦德,A股,2015-11-17,-2500, 0, 14.65, 新都化工,兄弟姐妹,XDHG,竞价交易,-36625,监事,002539.SZ", // "0.00012,马东杰,002771,马东伟,A股,2015-11-16, 100, 0, 129.12, 真视通,兄弟姐妹,ZST,竞价交易,12912,监事,002771.SZ", // "0.00012,马东杰,002771,马东伟,A股,2015-11-16, -100, 0, 129.8, 真视通,兄弟姐妹,ZST,竞价交易,-12980,监事,002771.SZ", // "0.00628,郝先进,002690,郝先进,A股,2015-11-16,42430,23581180,30.26,美亚光电,本人,MYGD,竞价交易,1283931.8,董事、高管,002690.SZ" ggcg = &ggcgVO{ StockID: row.GetInt64("id"), Date: arr[5], Person: arr[3], Price: util.ParseMoney(arr[8]), Amount: util.ParseMoney(arr[6]), Total: util.ParseMoney(arr[13]), Remain: int64(util.ParseMoney(arr[7])), Proportion: util.ParseMoney(arr[0]), Reason: arr[12], PersonRel: arr[1], PersonRelType: arr[10], Job: arr[14], } dataset = append(dataset, ggcg) } return dataset }
// FillStockData 抓取数据 func FillStockData() { // http://stockData.stock.hexun.com/600028.shtml upd := db.NewUpdateBuilder("stock") ist := db.NewInsertBuilder("") q := db.NewQueryBuilder("") dataset, _ := db.NewQueryBuilder("stock").Select("id,code,ctype").Limit(0).Query() for _, data := range dataset { if data.GetInt("industry_id") == 0 || data.GetInt("icb_id") == 0 { industry, icb, err := FetchStockData(data.GetString("code")) if err != nil { gos.DoError(err) continue } if data.GetInt("industry_id") == 0 { ist.Table("industry").Insert(industry) row, err := q.Table("industry").Where("name=?", industry.Name).QueryOne() if err != nil { gos.DoError(err) } else if !row.Empty() { upd.Where("id=?", data.GetInt64("id")).Update(db.DataRow{"industry_id": row.GetInt64("id")}) } } if data.GetInt("icb_id") == 0 { ist.Table("icb").Insert(icb) row, err := q.Table("icb").Where("name=?", icb.Name).QueryOne() if err != nil { gos.DoError(err) } else if !row.Empty() { upd.Where("id=?", data.GetInt64("id")).Update(db.DataRow{"icb_id": row.GetInt64("id")}) } } } } }
func (a *WriterApi) Save(args util.MapData) (string, error) { cid := args.GetString("cid") title := args.GetString("title") body := args.GetBytes("body") images := args.GetStringSlice("images") au := a.GetUserAuth() var err error model := article.NewArticleModel() if cid == "" { cid, err = model.New(au.UserID(), title, body) } else { _, err = model.Update(cid, title, body) } if err != nil { return cid, err } article, _ := db.NewQueryBuilder(model.Table()).Select("id").Where("cid=?", cid).QueryOne() if article.Empty() { return cid, gos.DoError("没有找到相应的记录") } count := len(images) if count > 0 { image := db.DataRow{} image["article_id"] = article.GetInt64("id") for i := 0; i < count; i++ { images[i] = fmt.Sprint("'", images[i], "'") } db.NewUpdateBuilder("images"). Where(fmt.Sprint("name in (", strings.Join(images, ","), ")")). Update(image) } return cid, nil }
// fetchAndFillYyb 抓取数据 func fetchAndFillYyb(page int) (int, error) { // http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=LHB&sty=YYTJ&stat=6&sr=0&st=1&p=2&ps=50&js=var%20XvAVhGPE={%22data%22:[(x)],%22pages%22:%22(pc)%22,%22update%22:%22(ud)%22}&rt=48257541 formt := `http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx?type=LHB&sty=YYTJ&stat=6&sr=0&st=1&p=%d&ps=%d&js=var%%20XvAVhGPE={"data":[(x)],"pages":"(pc)","update":"(ud)"}&rt=%d` pageLimit := 100 body, err := wget.GetBody(fmt.Sprintf(formt, page, pageLimit, time.Now().Unix())) if err != nil { return -1, err } exists := db.NewExistsBuilder("yyb") ist := db.NewInsertBuilder("yyb") upd := db.NewUpdateBuilder("yyb") query := db.NewQueryBuilder("yyb") var yyb *yybStruct var yybLub *yybLhbStruct var arr []string var row db.DataRow src := body[bytes.Index(body, []byte("={"))+1:] v := &jsonYybData{} err = json.Unmarshal(src, v) if err != nil { return -1, err } // "80136686,2,216,135,七喜控股|协鑫集成|恒信移动,2991067145.735,广东,80000073,440000,105,6089657316.805,3098590171.07,华泰证券股份有限公司广州天河东路证券营业部,002027.SZ|002506.SZ|300081.SZ" for i, item := range v.Data { arr = strings.Split(item, ",") yyb = &yybStruct{Code: arr[0], Name: arr[12], Area: arr[6]} if !exists.Table("yyb").Where("code=?", yyb.Code).Exists() { gos.Log.Info("insert", yyb.Code) ist.Table("yyb").Insert(yyb) } row, _ = query.Table("yyb").Where("code=?", yyb.Code).QueryOne() if row.Empty() { return -1, fmt.Errorf("code %s not found", yyb.Code) } yybLub = &yybLhbStruct{ YybID: row.GetInt64("id"), Updated: v.Update, Rank: pageLimit*(page-1) + i + 1, Amount: util.ParseMoney(arr[10]), Buy: util.ParseMoney(arr[11]), Sell: util.ParseMoney(arr[5]), Num: int(util.ParseMoney(arr[2])), NumBuy: int(util.ParseMoney(arr[3])), NumSell: int(util.ParseMoney(arr[9])), } if exists.Table("yyb_lhb").Where("yyb_id=?", yybLub.YybID).Exists() { gos.Log.Info("update", yyb.Code, yybLub.YybID) upd.Table("yyb_lhb").Where("yyb_id=?", yybLub.YybID).Update(yybLub) } else { gos.Log.Info("insert", yyb.Code, yybLub.YybID) ist.Table("yyb_lhb").Insert(yybLub) } } return int(util.ParseMoney(v.Pages)), nil }