dm_update.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // dmUpdate .
  11. func dmUpdate(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 "dm_search":
  20. dmMediaUpdate(c)
  21. default:
  22. c.JSON(nil, ecode.RequestErr)
  23. }
  24. }
  25. func dmMediaUpdate(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{"attr", "attr_format", "ctime", "mid", "mode", "msg", "mtime",
  41. "pool", "progress", "state", "type", "oidstr"}
  42. for _, v := range arr {
  43. item := &model.DmUptParams{}
  44. var (
  45. ok bool
  46. id float64
  47. oid float64
  48. )
  49. if _, ok = v["id"]; !ok {
  50. continue
  51. }
  52. if id, ok = v["id"].(float64); !ok {
  53. continue
  54. }
  55. if _, ok = v["oid"]; !ok {
  56. continue
  57. }
  58. if oid, ok = v["oid"].(float64); !ok {
  59. continue
  60. }
  61. item.ID = int64(id)
  62. item.Oid = int64(oid)
  63. itemField := make(map[string]interface{})
  64. for _, k := range key {
  65. var it interface{}
  66. if it, ok = v[k]; ok && v[k] != nil {
  67. itemField[k] = it
  68. }
  69. }
  70. item.Field = itemField
  71. bulkItem = append(bulkItem, item)
  72. }
  73. if err = svr.UpdateMap(c, "dmExternal", bulkItem); err != nil {
  74. log.Error("srv.Update erro(%v)", err)
  75. }
  76. c.JSON(nil, nil)
  77. }