Files
bj_power/bj_power_workstation/internal/handler/auth.go
T
SunYF 4ec6784629 feat: 完成MES工位终端系统全量功能迭代
本次提交包含以下核心变更:
1. 新增按钮级权限控制框架与前端权限校验
2. 新增工位管理、工艺流程、巡检终端等核心业务模块
3. 完善用户体系,支持工位终端专属登录权限
4. 新增文件上传下载、报表查询等配套功能
5. 修复多系统兼容性与交互体验问题
6. 完成所有文档与配置项的规范化更新
2026-08-31 08:06:55 +08:00

71 lines
2.2 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/auth"
"bj_power_workstation/internal/svc"
"golang.org/x/crypto/bcrypt"
)
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)
}
}
// configHandler GET /api/config 返回工位配置:
// 固定工位号 stationNoStation.Code 为空则前端可自选 1~12)、本工位需拧紧的螺丝颗数。
func configHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ok(w, map[string]any{
"stationNo": atoi(ctx.Config.Station.Code, 0),
"screwCount": ctx.Config.Station.ScrewCount,
})
}
}