Files
bj_power/bj_power_workstation/internal/handler/auth.go
T
SunYF c33acab9c8 feat: 解耦管理类型与SN管理方式,新增sn_mode字段实现全链路SN管理标准化
本次重构将原manage_mode字段拆分为独立的分类维度(manage_mode)和SN管理维度(sn_mode),实现全链路(MES/WMS/工位终端)的SN管理行为统一依据:
1. 新增sn_mode字段,定义1=序列号件、2=批次件、0=未选择,替代原manage_mode的SN判断逻辑
2. 移除冗余的manage_mode字段在多个实体中的使用,统一使用sn_mode决定业务行为
3. 新增工位接驳台配置,服务端固定接驳台,前端不可修改,确保AGV送达准确性
4. 优化检验记录导出,新增装配物料绑定明细,满足客户追溯需求
5. 修正前端提示文本,统一使用序列号件/批次件表述,与后端逻辑对齐
2026-09-30 17:33:11 +08:00

91 lines
2.8 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 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、固定接驳台 dock
// (均由 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,
"dock": ctx.Config.Station.Dock,
})
}
}