feat: 实现工位终端滑动续签机制,强化安全与身份追溯

- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期
- 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度
- 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题
- 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险
- 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件
- 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
This commit is contained in:
SunYF
2026-10-06 19:36:22 +08:00
parent f1cf57e9b2
commit 756d978900
71 changed files with 2417 additions and 556 deletions
+35 -5
View File
@@ -5,9 +5,11 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/handler/production"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
@@ -81,6 +83,24 @@ func StationLogoutInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// StationRefreshTokenInternalHandler 工位终端滑动续签(内部接口,X-API-TOKEN 保护):
// 校验当前工位登录态 Bearer 有效后原样重签新 JWT(延长有效期),由工位终端 Go 后端节流代理调用。
func StationRefreshTokenInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
authz := r.Header.Get("Authorization")
if !strings.HasPrefix(authz, "Bearer ") {
httpx.FailHTTP(w, http.StatusUnauthorized, "缺少工位登录凭证,请重新登录")
return
}
data, err := logic.New(svcCtx).StationRefreshToken(strings.TrimPrefix(authz, "Bearer "))
if err != nil {
httpx.Fail(w, 2107, err.Error())
return
}
httpx.Ok(w, data)
}
}
// StationChangePasswordInternalHandler 工位终端修改自己的工位终端密码
func StationChangePasswordInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@@ -137,7 +157,19 @@ func StationReportInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
httpx.BadRequest(w, "请求体解析失败")
return
}
if err := logic.New(svcCtx).ReportProcess(r.Context(), req, operator(r, "")); err != nil {
// 方案 B(#11/#14):优先取工位登录态可信身份;未携带(MES 前端虚拟工位路径)回退 JWT 登录账号。
recOpId, derr := production.StationOpIdInt(r)
if derr != nil {
httpx.Fail(w, 2104, derr.Error())
return
}
recOpName := production.StationOp(r, req.Operator)
if v := r.Header.Get("X-Station-No"); v != "" {
if n, e := strconv.Atoi(v); e == nil && n > 0 {
req.StationNo = n
}
}
if err := logic.New(svcCtx).ReportProcess(r.Context(), req, recOpName, recOpId); err != nil {
httpx.Fail(w, 2104, err.Error())
return
}
@@ -187,10 +219,8 @@ func StationCheckinInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
httpx.BadRequest(w, "缺少 sn")
return
}
op := req.Operator
if op == "" {
op = operator(r, "")
}
production.LogImpersonation(svcCtx, r, req.Operator, "/api/internal/station/checkin")
op := production.StationOp(r, req.Operator)
if err := logic.New(svcCtx).SemiFlow(r.Context(), logic.SemiReq{
Sn: req.Sn,
OrderNo: req.OrderNo,