智盟项目
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

78 rindas
2.2 KiB

  1. package svc
  2. import (
  3. offical "applet/app/db/official"
  4. "applet/app/task/md"
  5. "applet/app/utils"
  6. "applet/app/utils/cache"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/xiaoju"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/jinzhu/copier"
  12. "github.com/tidwall/gjson"
  13. "time"
  14. )
  15. func OilAddEs() {
  16. oilAddEsTime := offical.SysCfgByKeyStr("oil_add_es_time")
  17. today := utils.GetTimeRange("today")
  18. if utils.TimeStdParseUnix(oilAddEsTime) > today["start"] {
  19. return
  20. }
  21. PessimismLockValue := "zhiyingOilAddEsTime"
  22. key := fmt.Sprintf("zhiyingOilAddEsTime")
  23. //TODO::增加“悲观锁”防止串行
  24. getString, _ := cache.GetString(key)
  25. if getString == PessimismLockValue {
  26. fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次未执行完")
  27. return
  28. }
  29. cache.SetEx(key, PessimismLockValue, 3600*15) //8小时
  30. offical.DbsSysCfgUpdate("oil_add_es_time", time.Now().Format("2006-01-02 15:04:05"))
  31. CommOilAddEs(1)
  32. cache.Del(key)
  33. }
  34. func CommOilAddEs(p int) {
  35. platformKey := XiaojuKey()
  36. token := GetXiaojuToken(platformKey)
  37. data := map[string]interface{}{
  38. "pageIndex": p,
  39. "pageSize": 100,
  40. }
  41. list, _ := xiaoju.XiaojuStation(platformKey, token, data)
  42. //处理数据
  43. storeInfoList := gjson.Get(list, "storeInfoList").String()
  44. var store = make([]md.XiaojuGoods, 0)
  45. json.Unmarshal([]byte(storeInfoList), &store)
  46. count := len(store)
  47. for _, v := range store {
  48. var tmp md.XiaojuGoodsEs
  49. copier.Copy(&tmp, &v)
  50. tmp.HuiLabels = utils.SerializeStr(v.HuiLabels)
  51. for _, v1 := range v.ItemInfoList {
  52. var tmp2 = tmp
  53. tmp2.ItemName = v1.ItemName
  54. tmp2.IndexId = tmp2.StoreId + tmp2.ItemName
  55. tmp2.CityPrice = float64(v1.CityPrice) / 100
  56. tmp2.StorePrice = float64(v1.StorePrice) / 100
  57. tmp2.Location.Lon = tmp2.Lon
  58. tmp2.Location.Lat = tmp2.Lat
  59. doc, _ := es.FirstDoc(md.EggOilStation, tmp2.IndexId)
  60. if doc == nil {
  61. createDocRet, _ := es.CreateDoc(md.EggOilStation, tmp2.IndexId, tmp2)
  62. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  63. } else {
  64. createDocRet, _ := es.UpdateDoc(md.EggOilStation, tmp2.IndexId, tmp2)
  65. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  66. }
  67. }
  68. }
  69. if count == 100 {
  70. p++
  71. CommOilAddEs(p)
  72. return
  73. }
  74. return
  75. }