gigibox
2023-06-21 8a5f5dc40e82bf98e307082726ebe860002e019f
report/tasks.go
@@ -4,6 +4,7 @@
   "encoding/json"
   "io/ioutil"
   "kingdee-dbapi/logger"
   "time"
   "kingdee-dbapi/cache"
   "kingdee-dbapi/config"
@@ -78,8 +79,22 @@
   }
}
var invReportedCache = make(map[string]float64, 0)
var fullLoad bool
func SendInventory() {
   var list []kingdee.Inventory
   // 设置每天凌晨1点上报一次全量数据
   hour := time.Now().Hour()
   if hour == 1 {
      if fullLoad == false {
         invReportedCache = make(map[string]float64, 0)
         fullLoad = true
      }
   } else {
      fullLoad = false
   }
   if config.Options.Debug {
      data, err := ioutil.ReadFile(inventoryLocalStore)
@@ -95,7 +110,18 @@
      }
   } else {
      list = kingdee.ICInventory()
      logger.Debug("查询到%d条库存数据", len(list))
      for i := 0; i < len(list); {
         cacheKey := list[i].FNumber + list[i].FBatchNo + list[i].FStockNo
         if qty, ok := invReportedCache[cacheKey]; ok && qty == list[i].FUnitQty {
            list = append(list[:i], list[i+1:]...)
         } else {
            invReportedCache[cacheKey] = list[i].FUnitQty
            i++
         }
      }
   }
   // 每次发 100 条
@@ -119,9 +145,13 @@
      ok := nsqclient.Produce(config.Options.InventoryTopic, b)
      if !ok {
         logger.Warn("库存数据上报失败")
         //上报失败, 缓存清空
         invReportedCache = make(map[string]float64, 0)
      } else {
         successCnt = end
      }
   }
   logger.Debug("已上报%d条库存数据", successCnt)
}