Files
bj_power/bj_power_mes/internal/config/config.go
T

102 lines
4.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import (
"bj_power_mes/common/logx"
"bj_power_mes/internal/db"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/rest"
)
// Config 全局配置
type Config struct {
rest.RestConf // 自带 Host/Port 等
Database db.DatabaseConf
Redis RedisConfWrapper
Auth AuthConf
Internal InternalConf
Cli CliConf
Logger logx.LogConf
Wms WmsConf
Plc PlcConf
Agv AgvConf
Upload UploadConf
Scanner ScannerConf
}
// ScannerConf 扫码中间件(键盘 HID 注入)开关配置。
// 默认关闭;需用时在 yaml 设 Enabled: true 并重启。若 MES 与 WMS 同机且都开,7757 谁先启动谁监听,后到的只记日志。
type ScannerConf struct {
Enabled bool `json:",default=false"`
}
type RedisConfWrapper struct {
redis.RedisConf
}
// AuthConf 鉴权配置:JWT Secret / 有效期
// 只保留滑动续签:AccessExpire = 会话闲置窗口
type AuthConf struct {
// AccessSecret 必须由 yaml 提供,禁止编译期默认密钥(防默认密钥被绕过)
AccessSecret string `json:"AccessSecret"`
AccessExpire int64 `json:",default=3600"` // 会话闲置窗口(秒),滑动续签下 = 距最后请求多久后需重登
}
// InternalConf 内部服务间鉴权
type InternalConf struct {
// Token 必须由 yaml 提供,禁止编译期默认密钥(防空 token 绕过内部接口鉴权)
Token string `json:"Token"`
}
// CliConf 命令行敏感操作门禁密码(与管理员账号密码保持一致,改密时自动同步)
type CliConf struct {
// AdminPassword 必须由 yaml 提供,禁止编译期默认密钥(migrate/reset-all/seed 高危门禁)
AdminPassword string `json:"AdminPassword"`
}
// WmsConf WMS 内部服务地址
type WmsConf struct {
BaseURL string `json:",default="`
// Token 必须由 yaml 提供,禁止编译期默认密钥
Token string `json:"Token"`
}
// PlcConf PLC 对接配置(mock 时不用)。
// 真读:48 位块(MB895..MB900,6 字节)覆盖产线点位信号;布局见 internal/plc/tcp.go 顶部注释。
type PlcConf struct {
Enable bool `json:",default=false"`
Host string `json:",default=127.0.0.1"`
Port int `json:",default=102"`
Rack int `json:",default=0"` // S7 机架号(1200=0,300=0)
Slot int `json:",default=1"` // S7 槽号(1200=1,300=2)
// DoneByte/DoneBit 工艺完成信号位(PLC 完成上一条下发后置位,MES 读此位决定是否下发下一条)。
// 待现场 PLC 点位表确认;未配置时 QueryDone 安全返回 false(不下发下一条,不误进)。
DoneByte int `json:",default=-1"`
DoneBit int `json:",default=-1"`
}
// AgvConf 海康 AGV(RCS-Lite V1.5) 调度系统对接(2026-10-17 由 RCS-2000 改为 RCS-Lite 1.5)。
// RCS-Lite 无签名鉴权;未配置 BaseURL 或 EnableMock=true 时,使用 mock 客户端(模拟下发成功/到位),便于离线联调。
type AgvConf struct {
EnableMock bool `json:",default=true"` // 是否模拟(未接真实 RCS-Lite 前保持 true)
BaseURL string `json:",default=http://127.0.0.1:8182/rCMS/services/rest/hikRpcService"` // RCS-Lite 服务地址(含 /rCMS/services/rest/hikRpcService,默认端口 8182)
CarrierCode string `json:",default=DEFAULT"` // 默认载具/托盘编号(选填,下发时作为 podCode)
MapCode string `json:",default="` // 地图编号(选填,RCS-Lite 多地图场景使用)
Priority string `json:",default=1"` // 任务优先级(字符串 1-127,默认 1)
}
// UploadConf 附件统一存储配置。
// Dir 即附件根目录(相对服务启动目录或绝对路径),落盘结构:Dir/年/月/日/<文件类型>/<uuid>.<ext>。
type UploadConf struct {
Dir string `json:",default=uploads"`
MaxMB int64 `json:",default=20"` // 单文件默认上限(MB)
// 按文件类型覆盖上限(字节),键为大写枚举,如 PROCESS_PDF: 52428800
MaxSize map[string]int64 `json:",optional"`
// 本地保留年数(检验记录质量追溯保留期,期内禁删)
LocalRetentionYears int `json:",default=1"`
// 磁盘空间监控:每天 DiskCheckHour 点检测一次
DiskWarnPercent int `json:",default=20"` // 剩余低于该百分比告警
DiskCriticalPercent int `json:",default=10"` // 剩余低于该百分比提示清理
DiskCheckHour int `json:",default=7"` // 每天检测时刻(0~23)
}