|
@@ -9,30 +9,65 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
- address = "fhogrpc-test.seinmaungengineering.com:7091"
|
|
|
|
- // address = "localhost:7090"
|
|
|
|
|
|
+ // address = "fhogrpc-test.seinmaungengineering.com:7091"
|
|
|
|
+ address = "localhost:7090"
|
|
)
|
|
)
|
|
|
|
|
|
-type RegionProduct struct {
|
|
|
|
- ProductID string
|
|
|
|
- Name string
|
|
|
|
- Color string
|
|
|
|
- Variant float32
|
|
|
|
|
|
+func main() {
|
|
|
|
+ // client, err := fho.NewClient(address, "da910506-4bdc-4dc2-9481-58a4e3e3c8bf", "1adf4633-7e9e-4bd0-b512-7b087d9c9719")
|
|
|
|
+ client, err := fho.NewClient(address, "bd38e9ac-210a-4e85-865c-401270c07220", "8c95f7fa-3071-427d-a27a-6f96e1d9590e")
|
|
|
|
+ if err != nil {
|
|
|
|
+ panic(err)
|
|
|
|
+ }
|
|
|
|
+ // go listenProducts(client)
|
|
|
|
+ // go listenPrices(client)
|
|
|
|
+ // go query(client)
|
|
|
|
+ // update(client)
|
|
|
|
+ updateFromFHO(client)
|
|
|
|
+
|
|
|
|
+ select {}
|
|
}
|
|
}
|
|
|
|
|
|
-func RegionProductFromMap(m map[string]interface{}) *RegionProduct {
|
|
|
|
- return &RegionProduct{ProductID: fho.ToString(m["product_id"]),
|
|
|
|
- Name: fho.ToString(m["name"]),
|
|
|
|
- Color: fho.ToString(m["color"]),
|
|
|
|
- Variant: fho.ToFloat32(m["variant"])}
|
|
|
|
|
|
+func update(client *fho.FhoClient) {
|
|
|
|
+ products := make([]*fho.PriceChangeHistoryProduct, 0)
|
|
|
|
+ products = append(products, &fho.PriceChangeHistoryProduct{ID: "127", ProductID: "id0001", Name: "92", Color: "2334444", Price: 1222})
|
|
|
|
+ products = append(products, &fho.PriceChangeHistoryProduct{ID: "128", ProductID: "id0002", Name: "95", Color: "2989834", Price: 1333})
|
|
|
|
+ products = append(products, &fho.PriceChangeHistoryProduct{ID: "129", ProductID: "id0003", Name: "Diesel", Color: "2989834", Price: 1444})
|
|
|
|
+ products = append(products, &fho.PriceChangeHistoryProduct{ID: "120", ProductID: "id0004", Name: "Premium", Color: "2989834", Price: 1555})
|
|
|
|
+ t := time.Now()
|
|
|
|
+ history := fho.PriceChangeHistory{ID: "1111113", PriceChangeTime: t.Format(fho.DATETIME_FROM_ISO_FORMAT),
|
|
|
|
+ Status: "Successful", PriceChangeHistoryProducts: products}
|
|
|
|
+
|
|
|
|
+ err := fho.UpdatePriceHisotry(client, &history)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("Error query:", err.Error())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-func main() {
|
|
|
|
- client, err := fho.NewClient(address, "da910506-4bdc-4dc2-9481-58a4e3e3c8bf", "1adf4633-7e9e-4bd0-b512-7b087d9c9719")
|
|
|
|
- // client, err := fho.NewClient(address, "bd38e9ac-210a-4e85-865c-401270c07220", "8c95f7fa-3071-427d-a27a-6f96e1d9590e")
|
|
|
|
|
|
+
|
|
|
|
+func updateFromFHO(client *fho.FhoClient) error {
|
|
|
|
+ prices, err := fho.QueryPrice(client, time.Now().Add(time.Hour*-114))
|
|
if err != nil {
|
|
if err != nil {
|
|
- panic(err)
|
|
|
|
|
|
+ log.Println("Error query:", err.Error())
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ for _, price := range prices {
|
|
|
|
+ fmt.Println("Query=====>")
|
|
|
|
+ printPrice(price)
|
|
}
|
|
}
|
|
- go listenProducts(client)
|
|
|
|
|
|
+ _price := prices[0]
|
|
|
|
+
|
|
|
|
+ t := time.Now()
|
|
|
|
+ history := fho.PriceChangeHistory{ID: "1111114", PriceChangeTime: t.Format(fho.DATETIME_FROM_ISO_FORMAT),
|
|
|
|
+ PriceScheduleID: _price.ID, Status: "Successful"}
|
|
|
|
+
|
|
|
|
+ err = fho.UpdatePriceHisotry(client, &history)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("Error updatePriceHisotry:", err.Error())
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func query(client *fho.FhoClient) {
|
|
products, err := fho.QueryProducts(client, time.Now().Add(time.Hour*-114))
|
|
products, err := fho.QueryProducts(client, time.Now().Add(time.Hour*-114))
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Println("Error query:", err.Error())
|
|
log.Println("Error query:", err.Error())
|
|
@@ -41,16 +76,30 @@ func main() {
|
|
fmt.Println("Query=====>")
|
|
fmt.Println("Query=====>")
|
|
printProduct(product)
|
|
printProduct(product)
|
|
}
|
|
}
|
|
- select {}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func listenProducts(client *fho.FhoClient) error {
|
|
func listenProducts(client *fho.FhoClient) error {
|
|
- err := fho.ListenOnProducts(client, time.Now().Add(time.Hour*-114), func(products []*fho.Product) {
|
|
|
|
|
|
+ err := fho.ListenOnProducts(client, time.Now().Add(time.Hour*-114), func(products []*fho.Product) error {
|
|
for _, p := range products {
|
|
for _, p := range products {
|
|
fmt.Println("Listening=====>")
|
|
fmt.Println("Listening=====>")
|
|
printProduct(p)
|
|
printProduct(p)
|
|
}
|
|
}
|
|
|
|
+ return nil
|
|
|
|
+ })
|
|
|
|
+ return err
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func listenPrices(client *fho.FhoClient) error {
|
|
|
|
+ err := fho.ListenOnPrice(client, time.Now().Add(time.Hour*-114), func(prices []*fho.PriceSchedule) error {
|
|
|
|
+ for _, p := range prices {
|
|
|
|
+ fmt.Println("Listening=====>")
|
|
|
|
+ printPrice(p)
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
})
|
|
})
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("error listenPrices:", err.Error())
|
|
|
|
+ }
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,3 +113,22 @@ func printProduct(p *fho.Product) {
|
|
fmt.Printf("IsDeleted : %v\n", p.IsDeleted)
|
|
fmt.Printf("IsDeleted : %v\n", p.IsDeleted)
|
|
fmt.Printf("LatestUpdatedTime : %v\n", p.LatestUpdatedTime)
|
|
fmt.Printf("LatestUpdatedTime : %v\n", p.LatestUpdatedTime)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func printPrice(p *fho.PriceSchedule) {
|
|
|
|
+ fmt.Printf("ID : %v\n", p.ID)
|
|
|
|
+ fmt.Printf("Date : %v\n", p.Date)
|
|
|
|
+ fmt.Printf("AfterShiftChange : %v\n", p.AfterShiftChange)
|
|
|
|
+
|
|
|
|
+ fmt.Printf("IsCreated : %v\n", p.IsCreated)
|
|
|
|
+ fmt.Printf("IsUpdated : %v\n", p.IsUpdated)
|
|
|
|
+ fmt.Printf("IsDeleted : %v\n", p.IsDeleted)
|
|
|
|
+ fmt.Printf("LatestUpdatedTime : %v\n", p.LatestUpdatedTime)
|
|
|
|
+
|
|
|
|
+ fmt.Printf("Products -------------------\n")
|
|
|
|
+ for _, prd := range p.PriceScheduleProducts {
|
|
|
|
+ fmt.Printf("prd.ProductID : %v\n", prd.ProductID)
|
|
|
|
+ fmt.Printf("prd.Name : %v\n", prd.Name)
|
|
|
|
+ fmt.Printf("prd.Color : %v\n", prd.Color)
|
|
|
|
+ fmt.Printf("prd.Price : %v\n", prd.Price)
|
|
|
|
+ }
|
|
|
|
+}
|