pgc_update.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package http
  2. import (
  3. "encoding/json"
  4. "go-common/app/service/main/search/dao"
  5. "go-common/app/service/main/search/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. // pgcUpdate .
  11. func pgcUpdate(c *bm.Context) {
  12. params := c.Request.Form
  13. appid := params.Get("appid")
  14. if appid == "" {
  15. c.JSON(nil, ecode.RequestErr)
  16. return
  17. }
  18. switch appid {
  19. case "pgc_media":
  20. go pgcMediaUpdate(c)
  21. default:
  22. c.JSON(nil, ecode.RequestErr)
  23. }
  24. }
  25. func pgcMediaUpdate(c *bm.Context) {
  26. var (
  27. err error
  28. bulkItem []dao.BulkMapItem
  29. )
  30. params := c.Request.Form
  31. data := params.Get("data")
  32. if data == "" {
  33. return
  34. }
  35. var arr []map[string]interface{}
  36. if err = json.Unmarshal([]byte(data), &arr); err != nil {
  37. log.Error("json.Unmarshal error(%v)", err)
  38. return
  39. }
  40. key := []string{"season_id", "copyright", "latest_time", "dm_count", "play_count", "fav_count", "area_id", "score",
  41. "is_finish", "season_version", "season_status", "release_date", "pub_time", "season_month", "copyright_info"}
  42. for _, v := range arr {
  43. item := &model.PgcMediaUptParams{}
  44. var (
  45. ok bool
  46. id float64
  47. )
  48. if _, ok = v["media_id"]; !ok {
  49. continue
  50. }
  51. if id, ok = v["media_id"].(float64); !ok {
  52. continue
  53. }
  54. item.MediaID = int64(id)
  55. itemField := make(map[string]interface{})
  56. for _, k := range key {
  57. var it interface{}
  58. if it, ok = v[k]; ok && v[k] != nil {
  59. itemField[k] = it
  60. }
  61. }
  62. item.Field = itemField
  63. bulkItem = append(bulkItem, item)
  64. }
  65. if err = svr.UpdateMap(c, "externalPublic", bulkItem); err != nil {
  66. log.Error("srv.Update erro(%v)", err)
  67. }
  68. }