Files
bj_power/bj_power_workstation/main.go
T
SunYF 1cc93795ce feat(mes): 添加定时同步可生产数量到WMS及BOM项相关标准字段
- 在main.go中添加定时任务每10分钟同步可生产数量到WMS系统
- 为BomItem实体添加relatedStandard字段及相关CRUD方法
- 为InspectionRecord实体添加reportNo、materialCode、materialName等字段
- 更新ent schema确保新字段的验证和默认值设置
- 添加必要的数据库迁移和字段映射逻辑
2026-09-17 12:49:07 +08:00

89 lines
2.6 KiB
Go

package main
import (
"context"
"embed"
"flag"
"fmt"
"io/fs"
"bj_power_workstation/internal/config"
"bj_power_workstation/internal/handler"
"bj_power_workstation/internal/mes"
"bj_power_workstation/internal/pdfcache"
"bj_power_workstation/internal/store"
"bj_power_workstation/internal/svc"
"bj_power_workstation/internal/syncer"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest"
)
//go:embed all:web/static
var webFS embed.FS
var configFile = flag.String("f", "etc/bj_power_workstation.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
// 工位号:由服务端配置文件加载(终端不允许修改)。0=上线位、13=下线位为虚拟工位
// (PAD 上线建档 / 下线完工),1~12 为物理装配工位;启动时强校验 >= 0(工位数以数据库/配置为准,不写死 12)。
if c.Station.StationNo < 0 {
panic(fmt.Sprintf("Station.StationNo 必须 >= 0,当前配置为 %d(请修改 yaml 后重启)", c.Station.StationNo))
}
logx.Infof("固定工位号: %d", c.Station.StationNo)
staticFS, err := fs.Sub(webFS, "web/static")
if err != nil {
panic(fmt.Sprintf("加载内嵌前端资源失败: %v", err))
}
// 本地 SQLite:拧紧数据缓存 + 离线上报队列 + 操作日志 + 内置账号
st, err := store.Open(c.Sqlite.Path)
if err != nil {
panic(fmt.Sprintf("打开本地 SQLite(%s) 失败: %v", c.Sqlite.Path, err))
}
defer st.Close()
if err := store.SeedIfEmpty(st); err != nil {
panic(fmt.Sprintf("初始化内置用户失败: %v", err))
}
rootCtx, cancel := context.WithCancel(context.Background())
defer cancel()
mc := mes.New(c.Mes.BaseURL, c.Internal.Token)
// 后台同步协程:联网时向 MES 补报未同步数据
sy := syncer.New(st, mc)
go sy.Run(rootCtx)
// 拧紧数据由「工艺步骤 + 人工拧枪」驱动:工件走到需要拧紧枪的工艺步骤时,界面聚焦拧紧输入框,
// 人工拧枪把扭矩值打入回车 → POST /api/tightening/record 落本地库并经同步器上报 MES。
// 故此处不再启动任何后台模拟拧紧数据源。
// 工艺文件 PDF 本地预缓存
pdc := pdfcache.New(c.PdfCache.Dir)
ctx := &svc.ServiceContext{
Config: c,
Store: st,
Mes: mc,
Syncer: sy,
PdfCache: pdc,
WebFS: staticFS,
}
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting bj_power_workstation server at %s:%d...\n", c.Host, c.Port)
logx.Infof("Starting bj_power_workstation server at %s:%d...", c.Host, c.Port)
server.Start()
}