123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package main
- import (
- "fmt"
- "log"
- "time"
- fho "git.mokkon.com/sainw/fho_forward.git/client"
- )
- const (
- address = "fhogrpc-test.seinmaungengineering.com:7091"
- )
- func main() {
- client, err := fho.NewClient(address, "da910506-4bdc-4dc2-9481-58a4e3e3c8bf", "1adf4633-7e9e-4bd0-b512-7b087d9c9719")
- if err != nil {
- panic(err)
- }
- // go listenProducts(client)
- // go listenPrices(client)
- // go query(client)
- // update(client)
- updateFromFHO(client)
- select {}
- }
- 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 updateFromFHO(client *fho.FhoClient) error {
- prices, err := fho.QueryPrice(client, time.Now().Add(time.Hour*-114))
- if err != nil {
- log.Println("Error query:", err.Error())
- return err
- }
- for _, price := range prices {
- fmt.Println("Query=====>")
- printPrice(price)
- }
- _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))
- if err != nil {
- log.Println("Error query:", err.Error())
- }
- for _, product := range products {
- fmt.Println("Query=====>")
- printProduct(product)
- }
- }
- func listenProducts(client *fho.FhoClient) error {
- err := fho.ListenOnProducts(client, time.Now().Add(time.Hour*-114), func(products []*fho.Product) error {
- for _, p := range products {
- fmt.Println("Listening=====>")
- printProduct(p)
- }
- return nil
- })
- return err
- }
- func listenPrices(client *fho.FhoClient) error {
- err := fho.ListenOnPrice(client, time.Now().Add(time.Hour*-314), 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
- }
- func printProduct(p *fho.Product) {
- fmt.Printf("ID : %v\n", p.ID)
- fmt.Printf("Name : %v\n", p.Name)
- fmt.Printf("Color : %v\n", p.Color)
- 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)
- }
- 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)
- }
- }
|