main.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "time"
  6. fho "git.mokkon.com/sainw/fho_forward.git/client"
  7. )
  8. const (
  9. address = "fhogrpc-test.seinmaungengineering.com:7091"
  10. )
  11. func main() {
  12. client, err := fho.NewClient(address, "da910506-4bdc-4dc2-9481-58a4e3e3c8bf", "1adf4633-7e9e-4bd0-b512-7b087d9c9719")
  13. if err != nil {
  14. panic(err)
  15. }
  16. // go listenProducts(client)
  17. // go listenPrices(client)
  18. // go query(client)
  19. // update(client)
  20. updateFromFHO(client)
  21. select {}
  22. }
  23. func update(client *fho.FhoClient) {
  24. products := make([]*fho.PriceChangeHistoryProduct, 0)
  25. products = append(products, &fho.PriceChangeHistoryProduct{ID: "127", ProductID: "id0001", Name: "92", Color: "2334444", Price: 1222})
  26. products = append(products, &fho.PriceChangeHistoryProduct{ID: "128", ProductID: "id0002", Name: "95", Color: "2989834", Price: 1333})
  27. products = append(products, &fho.PriceChangeHistoryProduct{ID: "129", ProductID: "id0003", Name: "Diesel", Color: "2989834", Price: 1444})
  28. products = append(products, &fho.PriceChangeHistoryProduct{ID: "120", ProductID: "id0004", Name: "Premium", Color: "2989834", Price: 1555})
  29. t := time.Now()
  30. history := fho.PriceChangeHistory{ID: "1111113", PriceChangeTime: t.Format(fho.DATETIME_FROM_ISO_FORMAT),
  31. Status: "Successful", PriceChangeHistoryProducts: products}
  32. err := fho.UpdatePriceHisotry(client, &history)
  33. if err != nil {
  34. log.Println("Error query:", err.Error())
  35. }
  36. }
  37. func updateFromFHO(client *fho.FhoClient) error {
  38. prices, err := fho.QueryPrice(client, time.Now().Add(time.Hour*-114))
  39. if err != nil {
  40. log.Println("Error query:", err.Error())
  41. return err
  42. }
  43. for _, price := range prices {
  44. fmt.Println("Query=====>")
  45. printPrice(price)
  46. }
  47. _price := prices[0]
  48. t := time.Now()
  49. history := fho.PriceChangeHistory{ID: "1111114", PriceChangeTime: t.Format(fho.DATETIME_FROM_ISO_FORMAT),
  50. PriceScheduleID: _price.ID, Status: "Successful"}
  51. err = fho.UpdatePriceHisotry(client, &history)
  52. if err != nil {
  53. log.Println("Error updatePriceHisotry:", err.Error())
  54. }
  55. return nil
  56. }
  57. func query(client *fho.FhoClient) {
  58. products, err := fho.QueryProducts(client, time.Now().Add(time.Hour*-114))
  59. if err != nil {
  60. log.Println("Error query:", err.Error())
  61. }
  62. for _, product := range products {
  63. fmt.Println("Query=====>")
  64. printProduct(product)
  65. }
  66. }
  67. func listenProducts(client *fho.FhoClient) error {
  68. err := fho.ListenOnProducts(client, time.Now().Add(time.Hour*-114), func(products []*fho.Product) error {
  69. for _, p := range products {
  70. fmt.Println("Listening=====>")
  71. printProduct(p)
  72. }
  73. return nil
  74. })
  75. return err
  76. }
  77. func listenPrices(client *fho.FhoClient) error {
  78. err := fho.ListenOnPrice(client, time.Now().Add(time.Hour*-314), func(prices []*fho.PriceSchedule) error {
  79. for _, p := range prices {
  80. fmt.Println("Listening=====>")
  81. printPrice(p)
  82. }
  83. return nil
  84. })
  85. if err != nil {
  86. log.Println("error listenPrices:", err.Error())
  87. }
  88. return err
  89. }
  90. func printProduct(p *fho.Product) {
  91. fmt.Printf("ID : %v\n", p.ID)
  92. fmt.Printf("Name : %v\n", p.Name)
  93. fmt.Printf("Color : %v\n", p.Color)
  94. fmt.Printf("IsCreated : %v\n", p.IsCreated)
  95. fmt.Printf("IsUpdated : %v\n", p.IsUpdated)
  96. fmt.Printf("IsDeleted : %v\n", p.IsDeleted)
  97. fmt.Printf("LatestUpdatedTime : %v\n", p.LatestUpdatedTime)
  98. }
  99. func printPrice(p *fho.PriceSchedule) {
  100. fmt.Printf("ID : %v\n", p.ID)
  101. fmt.Printf("Date : %v\n", p.Date)
  102. fmt.Printf("AfterShiftChange : %v\n", p.AfterShiftChange)
  103. fmt.Printf("IsCreated : %v\n", p.IsCreated)
  104. fmt.Printf("IsUpdated : %v\n", p.IsUpdated)
  105. fmt.Printf("IsDeleted : %v\n", p.IsDeleted)
  106. fmt.Printf("LatestUpdatedTime : %v\n", p.LatestUpdatedTime)
  107. fmt.Printf("Products -------------------\n")
  108. for _, prd := range p.PriceScheduleProducts {
  109. fmt.Printf("prd.ProductID : %v\n", prd.ProductID)
  110. fmt.Printf("prd.Name : %v\n", prd.Name)
  111. fmt.Printf("prd.Color : %v\n", prd.Color)
  112. fmt.Printf("prd.Price : %v\n", prd.Price)
  113. }
  114. }