作者 唐旭辉

修复bug

@@ -35,11 +35,6 @@ func main() { @@ -35,11 +35,6 @@ func main() {
35 <-consumerRun.IsReady() 35 <-consumerRun.IsReady()
36 logs.Info("Sarama consumer up and running!...") 36 logs.Info("Sarama consumer up and running!...")
37 }() 37 }()
38 - // go func() {  
39 - // t := time.NewTimer(7 * time.Second)  
40 - // <-t.C  
41 - // produce.Producer()  
42 - // }()  
43 for { 38 for {
44 select { 39 select {
45 case <-sigs: 40 case <-sigs:
@@ -242,7 +242,6 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord @@ -242,7 +242,6 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
242 for i := range orderBestshop.Goods { 242 for i := range orderBestshop.Goods {
243 good := domain.NewOrderGood() 243 good := domain.NewOrderGood()
244 orderBestshop.Goods[i].CopyToOrderGood(&good) 244 orderBestshop.Goods[i].CopyToOrderGood(&good)
245 - good.OrderId = orderbase.Id  
246 good.CompanyId = partnerData.CompanyId 245 good.CompanyId = partnerData.CompanyId
247 good.Compute() 246 good.Compute()
248 good.CurrentBonusStatus.WartPayPartnerBonus(&good) 247 good.CurrentBonusStatus.WartPayPartnerBonus(&good)
@@ -257,6 +256,9 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord @@ -257,6 +256,9 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
257 e := fmt.Sprintf("添加order_base数据失败%s", err) 256 e := fmt.Sprintf("添加order_base数据失败%s", err)
258 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 257 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
259 } 258 }
  259 + for i := range ordergoods {
  260 + ordergoods[i].OrderId = orderbase.Id
  261 + }
260 // 添加goods 262 // 添加goods
261 err = orderGoodRepository.Save(ordergoods) 263 err = orderGoodRepository.Save(ordergoods)
262 if err != nil { 264 if err != nil {
1 -package produce  
2 -  
3 -import (  
4 - "fmt"  
5 - "strconv"  
6 - "time"  
7 -  
8 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/consumer/configs"  
9 -  
10 - "github.com/Shopify/sarama"  
11 - "github.com/astaxie/beego/logs"  
12 -)  
13 -  
14 -// var (  
15 -// producer sarama.SyncProducer  
16 -// )  
17 -  
18 -func produce(topic string, key string, content string) error {  
19 - var (  
20 - producer sarama.SyncProducer  
21 - )  
22 - logs.Info("init kafka producer, it may take a few seconds to init the connection\n")  
23 - var err error  
24 - mqConfig := sarama.NewConfig()  
25 - mqConfig.Producer.Return.Successes = true  
26 - mqConfig.Version = sarama.V0_10_2_1  
27 - if err = mqConfig.Validate(); err != nil {  
28 - msg := fmt.Sprintf("Kafka producer config invalidate. config: %v. err: %v", configs.Cfg, err)  
29 - logs.Info(msg)  
30 - panic(msg)  
31 - }  
32 -  
33 - producer, err = sarama.NewSyncProducer(configs.Cfg.Servers, mqConfig)  
34 - if err != nil {  
35 - msg := fmt.Sprintf("Kafak producer create fail. err: %v", err)  
36 - logs.Info(msg)  
37 - panic(msg)  
38 - }  
39 - msg := &sarama.ProducerMessage{  
40 - Topic: topic,  
41 - Key: sarama.StringEncoder(key),  
42 - Value: sarama.StringEncoder(content),  
43 - Timestamp: time.Now(),  
44 - }  
45 -  
46 - _, _, err = producer.SendMessage(msg)  
47 - if err != nil {  
48 - msg := fmt.Sprintf("Send Error topic: %v. key: %v. content: %v", topic, key, content)  
49 - logs.Info(msg)  
50 - return err  
51 - }  
52 - logs.Info("Send OK topic:%s key:%s value:%s\n", topic, key, content)  
53 - return nil  
54 -}  
55 -  
56 -func Producer() error {  
57 - key := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)  
58 - value := "this is a new kafka message123456!"  
59 - err := produce("topic_test", key, value)  
60 - if err != nil {  
61 - logs.Info("producer err:%s \n", err)  
62 - return err  
63 - }  
64 - return nil  
65 -}  
1 -package consumer  
2 -  
3 -// import (  
4 -// "encoding/json"  
5 -// "fmt"  
6 -  
7 -// "github.com/Shopify/sarama"  
8 -// "github.com/astaxie/beego/logs"  
9 -// syncOrderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/syncOrder/command"  
10 -// syncOrderSrv "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/syncOrder/service"  
11 -// )  
12 -  
13 -// //SyncBestshopOrder 同步  
14 -// func SyncBestshopOrder(message *sarama.ConsumerMessage) error {  
15 -// logs.Info("Done Message claimed: timestamp = %v, topic = %s offset = %v value = %v \n",  
16 -// message.Timestamp, message.Topic, message.Offset, string(message.Value))  
17 -// var (  
18 -// cmd syncOrderCmd.CreateOrderFromBestshop  
19 -// err error  
20 -// )  
21 -// err = json.Unmarshal(message.Value, &cmd)  
22 -// if err != nil {  
23 -// return fmt.Errorf("[Consumer][SyncBestshopOrder] 解析kafka数据失败;%s", err)  
24 -// }  
25 -// if cmd.PartnerId <= 0 {  
26 -// logs.Info("[Consumer][SyncBestshopOrder] PartnerId<=0 ,不处理消息")  
27 -// return nil  
28 -// }  
29 -// srv := syncOrderSrv.NewOrderInfoService(nil)  
30 -// err = srv.SyncOrderFromBestshop(cmd)  
31 -// if err != nil {  
32 -// e := fmt.Errorf("[Consumer][SyncBestshopOrder] %s", err)  
33 -// return e  
34 -// }  
35 -// return err  
36 -// }