From 89ce2bc6b71ea331c219c295074a289d09c808af Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 13 七月 2023 16:06:34 +0800 Subject: [PATCH] 修改车间代码的查询方式,返回正确的车间代码 --- config/config.go | 48 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 37 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 80b5711..fbeb267 100644 --- a/config/config.go +++ b/config/config.go @@ -9,24 +9,49 @@ ) 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 + 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"` // 鍚屾鐨勬椂闂撮棿闅�, 鍗曚綅/绉� + Debug bool `json:"debug"` // 鏈湴璋冭瘯, 鍙栨湰鍦版暟鎹� } 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.InventoryTopic = "aps.factory.erp.inventory" + Options.SqlQueryTopic = "aps.factory.erp.k3resource" + Options.SqlReplyTopic = "aps.factory.erp.k3reply" + Options.CSTQueryTopic = "aps.factory.erp.cstApply" + Options.CSTReplyTopic = "aps.factory.erp.cstReply" + Options.SyncInterval = 60 + Options.Debug = false } func Load() { if !pathExists(configPath) { + DefaultConfig() SaveConfig() } else { file, _ := os.Open(configPath) @@ -35,8 +60,6 @@ fd := json.NewDecoder(file) fd.Decode(&Options) - - fmt.Printf("%v\n", Options) } } @@ -44,8 +67,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