本次提交包含以下核心变更: 1. 新增按钮级权限控制框架与前端权限校验 2. 新增工位管理、工艺流程、巡检终端等核心业务模块 3. 完善用户体系,支持工位终端专属登录权限 4. 新增文件上传下载、报表查询等配套功能 5. 修复多系统兼容性与交互体验问题 6. 完成所有文档与配置项的规范化更新
101 lines
3.1 KiB
Go
101 lines
3.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bj_power_mes/common/httpx"
|
|
"bj_power_mes/internal/logic"
|
|
"bj_power_mes/internal/svc"
|
|
)
|
|
|
|
// ListProcessFlowsHandler GET /process-flows?processCode=
|
|
func ListProcessFlowsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
code := atoiDefault(r.URL.Query().Get("processCode"), 0)
|
|
data, err := logic.New(svcCtx).ListFlows(r.Context(), code)
|
|
if err != nil {
|
|
httpx.Fail(w, 2201, err.Error())
|
|
return
|
|
}
|
|
httpx.Ok(w, data)
|
|
}
|
|
}
|
|
|
|
// SaveProcessFlowHandler POST /process-flows(新建或更新工艺流程,含步骤模板)
|
|
func SaveProcessFlowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req logic.FlowReq
|
|
if err := httpx.ParseJSON(r, &req); err != nil {
|
|
httpx.BadRequest(w, "请求体解析失败")
|
|
return
|
|
}
|
|
if err := logic.New(svcCtx).SaveFlow(r.Context(), req, operator(r, "")); err != nil {
|
|
httpx.Fail(w, 2202, err.Error())
|
|
return
|
|
}
|
|
httpx.OkMessage(w, "工艺流程已保存", nil)
|
|
}
|
|
}
|
|
|
|
// DeleteProcessFlowHandler DELETE /process-flows/:id
|
|
func DeleteProcessFlowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if err := logic.New(svcCtx).DeleteFlow(r.Context(), pathId(r), operator(r, "")); err != nil {
|
|
httpx.Fail(w, 2203, err.Error())
|
|
return
|
|
}
|
|
httpx.OkMessage(w, "工艺流程已删除", nil)
|
|
}
|
|
}
|
|
|
|
// UploadPdfHandler POST /process-flows/upload(工艺图纸PDF上传,返回文件名)
|
|
func UploadPdfHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
|
httpx.BadRequest(w, "上传文件过大或格式错误")
|
|
return
|
|
}
|
|
name, err := saveUploadFile(r, "file", svcCtx.Config.Upload.Dir)
|
|
if err != nil {
|
|
httpx.Fail(w, 2204, "文件保存失败:"+err.Error())
|
|
return
|
|
}
|
|
httpx.Ok(w, map[string]any{"filename": name, "url": "/api/v1/files/" + name})
|
|
}
|
|
}
|
|
|
|
// FileDownloadHandler JWT 保护的文件下载(MES 前端展示 PDF/照片)
|
|
func FileDownloadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
serveUploadFile(w, r, svcCtx.Config.Upload.Dir, r.URL.Query().Get("name"))
|
|
}
|
|
}
|
|
|
|
// ListStationsHandler GET /stations
|
|
func ListStationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
data, err := logic.New(svcCtx).ListStations(r.Context())
|
|
if err != nil {
|
|
httpx.Fail(w, 2205, err.Error())
|
|
return
|
|
}
|
|
httpx.Ok(w, data)
|
|
}
|
|
}
|
|
|
|
// SaveStationHandler POST /stations(工位绑定工艺流程图)
|
|
func SaveStationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req logic.StationReq
|
|
if err := httpx.ParseJSON(r, &req); err != nil {
|
|
httpx.BadRequest(w, "请求体解析失败")
|
|
return
|
|
}
|
|
if err := logic.New(svcCtx).SaveStation(r.Context(), req, operator(r, "")); err != nil {
|
|
httpx.Fail(w, 2206, err.Error())
|
|
return
|
|
}
|
|
httpx.OkMessage(w, "工位绑定已保存", nil)
|
|
}
|
|
}
|