package report import ( "context" "time" "kingdee-dbapi/config" "kingdee-dbapi/logger" ) var ctx context.Context var cancel context.CancelFunc func Start() { ctx, cancel = context.WithCancel(context.Background()) go queryTasks(ctx) } func RestartReport() { cancel() Start() } func queryTasks(c context.Context) { logger.Debug("启动数据上报任务") for { select { case <-c.Done(): logger.Debug("停止上报") return default: // 上报订单 if config.Options.OrderTopic != "" { SendOrder() } // 上报即时库存 if config.Options.InventoryTopic != "" { SendInventory() } // 上报bom if config.Options.BomTopic != "" { SendBom(false) } time.Sleep(time.Duration(config.Options.SyncInterval) * time.Second) } } } func HandleBomQuery(msg []byte) error { SendBom(true) return nil }