feat: 五项目业务实现并对接完成
- MES(B): 工单/BOM/备料/工序字典/PLC下发/拧紧/扫码报工/半成品/AGV/追溯逻辑,WMS与海康RCS客户端,看板Redis缓存API(概览/设备/进度/报警/趋势)+SSE - WMS(C): JWT滑动续签、Excel导入、盘点、内部API、种子数据、独立Postgres配置 - WMS客户端(E): Go网关8891反向代理+内嵌Vue3十页 - 工位终端(D): SQLite本地缓存+模拟拧紧源+内嵌Vue3页面 - Dashboard(A): 看板数据改接MES内部缓存API,SSE实时刷新+vite代理 - 清理各项目球形磨遗留代码,新增部署手册.md
This commit is contained in:
@@ -1,44 +1,41 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
// AuthConfig JWT 登录鉴权配置
|
||||
// 注意:go-zero conf 仅识别 json 标签(yaml/toml 文件统一转为 JSON 后按此映射)
|
||||
type AuthConfig struct {
|
||||
AccessSecret string `json:",default=bj-power-ws-secret-2026"`
|
||||
AccessExpire int64 `json:",default=1800"` // 有效期(秒)
|
||||
}
|
||||
|
||||
// MesConfig MES 服务地址(内部 API)
|
||||
type MesConfig struct {
|
||||
BaseURL string `json:",default=http://127.0.0.1:8888"`
|
||||
}
|
||||
|
||||
// InternalConfig 项目间内部 API 写死 token(X-API-TOKEN)
|
||||
type InternalConfig struct {
|
||||
Token string `json:",default=bj-power-internal-2026"`
|
||||
}
|
||||
|
||||
// SimConfig 内置模拟拧紧枪数据源开关
|
||||
type SimConfig struct {
|
||||
Enable bool `json:",default=true"`
|
||||
}
|
||||
|
||||
// SqliteConfig 本地 SQLite 缓存库
|
||||
type SqliteConfig struct {
|
||||
Path string `json:",default=workstation.db"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
APIURL string `json:"api_url"`
|
||||
SerialPort string `json:"serial_port"`
|
||||
BaudRate int `json:"baud_rate"`
|
||||
DisplayUnit string `json:"display_unit"`
|
||||
}
|
||||
|
||||
func Load(path string) (Config, error) {
|
||||
cfg := Config{
|
||||
APIURL: "http://localhost:8888",
|
||||
SerialPort: "COM7",
|
||||
BaudRate: 115200,
|
||||
DisplayUnit: "mm",
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if err := cfg.Save(path); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (c Config) Save(path string) error {
|
||||
data, err := json.MarshalIndent(c, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, 0644)
|
||||
rest.RestConf
|
||||
Auth AuthConfig `json:",optional"`
|
||||
Mes MesConfig `json:",optional"`
|
||||
Internal InternalConfig `json:",optional"`
|
||||
Sim SimConfig `json:",optional"`
|
||||
Sqlite SqliteConfig `json:",optional"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user