From 1873461012c99801f364bd07fae2c218d245048e Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期一, 11 九月 2023 19:42:39 +0800 Subject: [PATCH] 修复bom第一启动时的全量上报 --- config/config.go | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 40 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 80b5711..ed0f042 100644 --- a/config/config.go +++ b/config/config.go @@ -9,24 +9,52 @@ ) type Config struct { - WebPort string `json:"web_port"` - SqlAddr string `json:"sql_addr"` - SqlDBName string `json:"sql_db_name"` - SqlUsername string `json:"sql_username"` - SqlPassword string `json:"sql_password"` + WebPort string `json:"web_port"` // 鏈湴web鏈嶅姟缁戝畾鎺ュ彛 + SqlAddr string `json:"sql_addr"` // 鏁版嵁搴搃p鍦板潃, 涓嶅姞绔彛鍙�, 榛樿浣跨敤1433绔彛 + SqlDBName string `json:"sql_db_name"` // 鏁版嵁搴撳悕绉� + SqlUsername string `json:"sql_username"` // 鏁版嵁搴撶敤鎴� + SqlPassword string `json:"sql_password"` // 鏁版嵁搴撳瘑鐮� + NsqServer string `json:"nsq_server"` // nsq TCP鏈嶅姟绔湴鍧� + NsqWebApi string `json:"nsq_webapi"` // nsq HTTP鎺ュ彛鍦板潃 + OrderTopic string `json:"order_topic"` // 璁㈠崟涓婃姤鐨則opic + BomTopic string `json:"bom_topic"` // bom涓婃姤鐨則opic + BomQueryTopic string `json:"bom_query_topic"` // bom涓婃姤鐨則opic + InventoryTopic string `json:"inventory_topic"` // 搴撳瓨涓婃姤鐨則opic + SqlQueryTopic string `json:"query_topic"` // 閲戣澏鏌ヨ鎺ュ彛鐨則opic + SqlReplyTopic string `json:"reply_topic"` // 閲戣澏鍝嶅簲鏌ヨ鎺ュ彛鐨則opic + CSTWebApi string `json:"cst_webapi"` // 鐢熶骇浠诲姟鍗曟彁浜ゅ湴鍧� + CSTQueryTopic string `json:"cst_query_topic"` // 鎻愪氦鐢熶骇浠诲姟鍗曚富棰� + CSTReplyTopic string `json:"cst_reply_topic"` // 鍝嶅簲鐢熶骇浠诲姟鍗曚富棰� + SyncInterval int `json:"interval"` // 鍚屾鐨勬椂闂撮棿闅�, 鍗曚綅/绉� } const configPath = "config.json" var Options Config -// Init is an exported method that takes the environment starts the viper -// (external lib) and returns the configuration struct. -func init() { +func DefaultConfig() { + Options.WebPort = "10210" + Options.SqlAddr = "127.0.0.1" + Options.SqlDBName = "dbname" + Options.SqlUsername = "sa" + Options.SqlPassword = "123456" + Options.NsqServer = "fai365.com:4150" + Options.NsqWebApi = "http://121.31.232.83:9080/api/nsq/pub?topic=your_topic" + Options.OrderTopic = "aps.factory.erp.seorder" + Options.BomTopic = "aps.factory.erp.icBom" + Options.BomQueryTopic = "aps.factory.erp.icBomQuery" + Options.InventoryTopic = "aps.factory.erp.inventory" + Options.SqlQueryTopic = "aps.factory.erp.k3resource" + Options.SqlReplyTopic = "aps.factory.erp.k3reply" + Options.CSTWebApi = "http://localhost/cst/local_post.ashx" + Options.CSTQueryTopic = "aps.factory.erp.cstApply" + Options.CSTReplyTopic = "aps.factory.erp.cstReply" + Options.SyncInterval = 60 } func Load() { if !pathExists(configPath) { + DefaultConfig() SaveConfig() } else { file, _ := os.Open(configPath) @@ -35,8 +63,6 @@ fd := json.NewDecoder(file) fd.Decode(&Options) - - fmt.Printf("%v\n", Options) } } @@ -44,8 +70,11 @@ b, err := json.Marshal(Options) if err == nil { var out bytes.Buffer + err = json.Indent(&out, b, "", " ") - ioutil.WriteFile(configPath, out.Bytes(), 0644) + if err == nil { + err = ioutil.WriteFile(configPath, out.Bytes(), 0644) + } } return err -- Gitblit v1.8.0