本次提交覆盖多个业务模块的功能完善与体验优化:
1. **鉴权与配置调整**:
- 统一JWT滑动续签逻辑,简化Token存储,移除RefreshToken相关冗余代码
- 调整多项目配置文件中JWT过期时间为3600秒,统一会话闲置窗口
- 工位配置放开1~12限制,改为仅校验大于0
2. **术语统一替换**:全链路将"精密件"替换为"电气件",修正物料管理描述
3. **功能新增**:
- 新增工位类型、工艺路线与产线点位台账模块
- 添加工艺PDF预览面板、工位终端代理转发接口
- 新增操作日志按操作人列表筛选、工位登出日志记录
- 新增PLC移料指令与产线点位状态管理
4. **业务流程优化**:
- 调整BOM物料删除校验逻辑,优化工单备料计算
- 补充物料图号、检测单号等追溯字段
- 完善工艺流程图与工位绑定关系说明
- 优化前端页面文案与交互细节
5. **代码规范与维护**:
- 新增通用工具函数与前端静态资源
- 整理路由权限与中间件逻辑
- 修复部分接口与配置的不兼容问题
90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package handler
|
||
|
||
import (
|
||
"net/http"
|
||
"strings"
|
||
"time"
|
||
|
||
"bj_power_workstation/internal/svc"
|
||
)
|
||
|
||
func healthHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||
return func(w http.ResponseWriter, r *http.Request) {
|
||
if err := ctx.Store.Ping(); err == nil {
|
||
ok(w, map[string]any{
|
||
"status": "UP",
|
||
"time": time.Now().Format("2006-01-02 15:04:05"),
|
||
"service": "bj_power_workstation",
|
||
})
|
||
return
|
||
}
|
||
fail(w, http.StatusServiceUnavailable, "本地数据库不可用")
|
||
}
|
||
}
|
||
|
||
// loginHandler 登录代理 MES /api/internal/station/login(块1:用户体系来源于 MES)。
|
||
// 前端提交 {username, password, stationNo},MES 校验工位终端密码 + 工位权限并签发同密钥 JWT。
|
||
// 响应体原样透传({code,message,data:{accessToken,expireAt,user,stations,stationNo}})。
|
||
func loginHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||
return func(w http.ResponseWriter, r *http.Request) {
|
||
var req struct {
|
||
Username string `json:"username"`
|
||
Password string `json:"password"`
|
||
StationNo int `json:"stationNo"`
|
||
}
|
||
if err := parseJSON(r, &req); err != nil {
|
||
fail(w, http.StatusBadRequest, "参数错误")
|
||
return
|
||
}
|
||
if strings.TrimSpace(req.Username) == "" || req.Password == "" {
|
||
fail(w, http.StatusBadRequest, "用户名和密码必填")
|
||
return
|
||
}
|
||
|
||
body, _, err := ctx.Mes.Post("/api/internal/station/login", map[string]any{
|
||
"username": strings.TrimSpace(req.Username),
|
||
"password": req.Password,
|
||
"stationNo": req.StationNo,
|
||
})
|
||
if err != nil {
|
||
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
|
||
return
|
||
}
|
||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||
w.WriteHeader(http.StatusOK)
|
||
_, _ = w.Write(body)
|
||
}
|
||
}
|
||
|
||
// logoutHandler POST /api/station/logout 退出登录:转发 MES 记录"工位终端退出"操作日志。
|
||
// MES 不可达时静默忽略(日志不阻塞本地退出)。
|
||
func logoutHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||
return func(w http.ResponseWriter, r *http.Request) {
|
||
var req struct {
|
||
Username string `json:"username"`
|
||
StationNo int `json:"stationNo"`
|
||
}
|
||
_ = parseJSON(r, &req)
|
||
username := strings.TrimSpace(req.Username)
|
||
if username != "" {
|
||
no := req.StationNo
|
||
if no <= 0 {
|
||
no = ctx.Config.Station.StationNo
|
||
}
|
||
go func(u string, n int) {
|
||
_, _, _ = ctx.Mes.Post("/api/internal/station/logout", map[string]any{"username": u, "stationNo": n})
|
||
}(username, no)
|
||
}
|
||
ok(w, nil)
|
||
}
|
||
}
|
||
|
||
// configHandler GET /api/config 返回工位配置:// 固定工位号 stationNo(由 yaml 配置在启动时加载,终端不可修改)、本工位需拧紧的螺丝颗数。
|
||
func configHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||
return func(w http.ResponseWriter, r *http.Request) {
|
||
ok(w, map[string]any{
|
||
"stationNo": ctx.Config.Station.StationNo,
|
||
"screwCount": ctx.Config.Station.ScrewCount,
|
||
})
|
||
}
|
||
} |