upsert.go 824 B

123456789101112131415161718192021222324252627282930313233343536
  1. package http
  2. import (
  3. "encoding/json"
  4. "strings"
  5. "go-common/app/admin/main/search/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. func upsert(c *bm.Context) {
  11. up := &model.UpsertParams{}
  12. if err := c.Bind(up); err != nil {
  13. return
  14. }
  15. dataBody := map[string][]model.MapData{}
  16. decoder := json.NewDecoder(strings.NewReader(up.DataStr))
  17. decoder.UseNumber()
  18. if err := decoder.Decode(&dataBody); err != nil {
  19. log.Error("s.http.upsert(%v) json error(%v)", err, dataBody)
  20. }
  21. if len(dataBody) == 0 {
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. for _, n := range dataBody {
  26. for _, m := range n {
  27. if err := m.NumberToInt64(); err != nil {
  28. log.Error("s.http.upsert(%v) to int64 error(%v)", err, m)
  29. }
  30. }
  31. }
  32. c.JSON(nil, svr.Upsert(c, up, dataBody))
  33. }