1. 新增跨平台磁盘空间监控能力,每日7点自动检测附件目录剩余空间,触发阈值告警 2. 重构附件存储方案为年/月/日/文件类型分层结构,统一MES与WMS的附件管理逻辑 3. 对齐物料档案与入库单的质量状态校验规则,仅合格品计入库存与出库 4. 实现入库单作废功能与区域库位的多级父子结构管理 5. 删除物料简称字段,补充规格型号与单位必填项,统一系统数据口径 6. 新增附件中心与磁盘状态查询接口,完善权限控制与操作日志
155 lines
5.4 KiB
Go
155 lines
5.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bj_power_mes/common/httpx"
|
|
"bj_power_mes/internal/logic"
|
|
"bj_power_mes/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/rest/pathvar"
|
|
)
|
|
|
|
// ListProcessFlowsHandler GET /process-flows?stationNo=
|
|
func ListProcessFlowsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
stationNo := atoiDefault(r.URL.Query().Get("stationNo"), 0)
|
|
page := atoiDefault(r.URL.Query().Get("page"), 0)
|
|
pageSize := atoiDefault(r.URL.Query().Get("pageSize"), 20)
|
|
data, err := logic.New(svcCtx).ListFlows(r.Context(), stationNo, page, pageSize)
|
|
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
|
|
}
|
|
res, err := saveTypedUpload(r, "file", svcCtx.Config.Upload.Dir, "process_flow", FileTypeProcessPDF,
|
|
uploadMaxBytes(svcCtx.Config.Upload.MaxSize, svcCtx.Config.Upload.MaxMB, FileTypeProcessPDF))
|
|
if err != nil {
|
|
httpx.Fail(w, 2204, "文件保存失败:"+err.Error())
|
|
return
|
|
}
|
|
httpx.Ok(w, map[string]any{"filename": res.RelPath, "url": "/api/v1/files/" + res.RelPath})
|
|
}
|
|
}
|
|
|
|
// 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"))
|
|
}
|
|
}
|
|
|
|
// FilePathHandler GET /files/:date/:name —— 路径式文件 URL(巡检拍照上传返回的
|
|
// url 形如 /api/v1/files/2026-09-07/xxx.png,此前无此路由导致照片 404)
|
|
func FilePathHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
vars := pathvar.Vars(r)
|
|
serveUploadFile(w, r, svcCtx.Config.Upload.Dir, vars["date"]+"/"+vars["name"])
|
|
}
|
|
}
|
|
|
|
// FileDeepPathHandler GET /files/:y/:m/:d/:t/:f —— 统一存储格式的路径式 URL
|
|
// (年/月/日/文件类型/uuid.ext)。go-zero 路由不支持多段通配,故按固定 5 段显式声明。
|
|
func FileDeepPathHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
vars := pathvar.Vars(r)
|
|
rel := vars["y"] + "/" + vars["m"] + "/" + vars["d"] + "/" + vars["t"] + "/" + vars["f"]
|
|
serveUploadFile(w, r, svcCtx.Config.Upload.Dir, rel)
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
// DeleteStationHandler DELETE /stations/:id(删除工位:内置工位不允许删除)
|
|
func DeleteStationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if err := logic.New(svcCtx).DeleteStation(r.Context(), pathId(r), operator(r, "")); err != nil {
|
|
httpx.Fail(w, 2208, err.Error())
|
|
return
|
|
}
|
|
httpx.OkMessage(w, "工位已删除", nil)
|
|
}
|
|
}
|
|
|
|
// SetFlowStatusHandler POST /process-flows/status(工艺流程启用/停用)
|
|
func SetFlowStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
var req struct {
|
|
Id int `json:"id"`
|
|
Status string `json:"status"`
|
|
}
|
|
if err := httpx.ParseJSON(r, &req); err != nil {
|
|
httpx.BadRequest(w, "请求体解析失败")
|
|
return
|
|
}
|
|
if err := logic.New(svcCtx).SetFlowStatus(r.Context(), req.Id, req.Status, operator(r, "")); err != nil {
|
|
httpx.Fail(w, 2207, err.Error())
|
|
return
|
|
}
|
|
httpx.OkMessage(w, "操作成功", nil)
|
|
}
|
|
}
|