feat&refactor: 2026-09-22 半成品业务模型重构与功能完善
- 重构半成品流转逻辑:进度权威源改为 workpiece.currentStationNo,新增 completedText 快照字段,废除 doneProcessCodes - 清理物料品类中半成品类型,存量数据幂等清理,调整物料管理方式文案为批次/序列号 - 新增日排产状态专用更新接口,修复工单工艺校验逻辑 - 新增物料档案代理接口、深路径文件下载接口 - 优化前端界面文案与工位选择逻辑,补充追溯页半成品流转展示 - 调整WMS端物料品类校验与入库接口契约 - 新增/更新数据库表结构与实体类代码
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// DailyPlanStatusHandler POST /daily-plans/:id/status 日排产启用/停用专用状态接口。
|
||||
// body: {"status":"PENDING"|"CONFIRMED"};只更新 status 字段(启用前校验工单已下发),
|
||||
// 前端此前误用 PUT /daily-plans/{id} 会 405,且全量保存会覆盖分产量。
|
||||
func DailyPlanStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
id := pathID(r)
|
||||
if err := logic.New(svcCtx).SetDailyPlanStatus(r.Context(), id, req.Status, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3012, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "操作成功", nil)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// ListMaterialsHandler GET /api/v1/materials 物料档案(代理 WMS GET /api/internal/materials)。
|
||||
// WMS 是物料主数据源(item_type=1原材料/2半成品/3成品/4其他),MES 管理端经 JWT 接口只读代理。
|
||||
// 响应 [{code,name,spec,unit,manageMode}],manageMode "1"=批次(结构件)/"2"=序列号(电气件),
|
||||
// 与 WMS manage_mode 口径一致(参考 wmsclient.MaterialRow.ManageMode)。
|
||||
// WMS 不可达/异常时返回空列表(前端自行降级),不报错。
|
||||
func ListMaterialsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
list := []map[string]string{}
|
||||
_, rows, err := svcCtx.Wms.MaterialPage(r.Context(), "", "", "", 0, 0, 1, 1000)
|
||||
if err == nil {
|
||||
for _, m := range rows {
|
||||
list = append(list, map[string]string{
|
||||
"code": m.Code,
|
||||
"name": m.Name,
|
||||
"spec": m.Spec,
|
||||
"unit": m.Unit,
|
||||
"manageMode": strconv.Itoa(m.ManageMode),
|
||||
})
|
||||
}
|
||||
}
|
||||
httpx.Ok(w, list)
|
||||
}
|
||||
}
|
||||
@@ -128,11 +128,12 @@ func OnlineWorkpieceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).OnlineWorkpiece(r.Context(), req, operator(r, r.URL.Query().Get("operator"))); err != nil {
|
||||
if msg, err := logic.New(svcCtx).OnlineWorkpiece(r.Context(), req, operator(r, r.URL.Query().Get("operator"))); err != nil {
|
||||
httpx.Fail(w, 2007, err.Error())
|
||||
return
|
||||
} else {
|
||||
httpx.OkMessage(w, msg, nil)
|
||||
}
|
||||
httpx.OkMessage(w, "进线登记成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,12 @@ func OnlineWorkpieceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).OnlineWorkpiece(r.Context(), req, operator(r, "")); err != nil {
|
||||
if msg, err := logic.New(svcCtx).OnlineWorkpiece(r.Context(), req, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3301, err.Error())
|
||||
return
|
||||
} else {
|
||||
httpx.OkMessage(w, msg, nil)
|
||||
}
|
||||
httpx.OkMessage(w, "进线登记成功", nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +172,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodPut, Path: "/daily-plans", Handler: production.SaveDailyPlanHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/daily-plans", Handler: production.ListDailyPlansHandler(serverCtx)},
|
||||
{Method: http.MethodDelete, Path: "/daily-plans/:id", Handler: production.DeleteDailyPlanHandler(serverCtx)},
|
||||
// 日排产启用/停用专用状态接口(body {"status":"PENDING"|"CONFIRMED"}):
|
||||
// 只改 status 列,避免前端此前误用 PUT /daily-plans/{id}(405)或全量保存覆盖分产量
|
||||
{Method: http.MethodPost, Path: "/daily-plans/:id/status", Handler: production.DailyPlanStatusHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/daily-plans/suggest-docks", Handler: production.SuggestedDockCodesHandler(serverCtx)},
|
||||
|
||||
{Method: http.MethodPut, Path: "/bom", Handler: production.SaveBomHandler(serverCtx)},
|
||||
@@ -182,6 +185,8 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
|
||||
{Method: http.MethodPost, Path: "/material-requests/generate", Handler: production.GenerateMaterialHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/material-requests", Handler: production.ListMaterialRequestsHandler(serverCtx)},
|
||||
// 物料档案(代理 WMS /api/internal/materials,WMS 是物料主数据源;WMS 不可达返回空列表)
|
||||
{Method: http.MethodGet, Path: "/materials", Handler: production.ListMaterialsHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/material-requests/receive", Handler: production.ReceiveMaterialRequestHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/material-requests/auto-outbound", Handler: production.AutoOutboundHandler(serverCtx)},
|
||||
// 配送进度(只读聚合:WMS 台账四段量 + MES 已接料 → 在途/线边)
|
||||
@@ -239,6 +244,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodPost, Path: "/process-flows/status", Handler: SetFlowStatusHandler(serverCtx)},
|
||||
{Method: http.MethodDelete, Path: "/process-flows/:id", Handler: DeleteProcessFlowHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/process-flows/upload", Handler: UploadPdfHandler(serverCtx)},
|
||||
// 统一存储深路径文件 URL(年/月/日/文件类型/uuid.ext,如 /api/v1/files/2026/09/22/PROCESS_PDF/xxx.pdf),
|
||||
// 上传接口返回的 url 即此格式,未注册前直接访问 404
|
||||
{Method: http.MethodGet, Path: "/files/:y/:m/:d/:t/:f", Handler: FileDeepPathHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/stations", Handler: ListStationsHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/stations", Handler: SaveStationHandler(serverCtx)},
|
||||
{Method: http.MethodDelete, Path: "/stations/:id", Handler: DeleteStationHandler(serverCtx)},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -118,7 +118,7 @@ func StationTaskInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// StationReportInternalHandler 工位终端工序报工(写工序实绩 + 步骤考核)
|
||||
// StationReportInternalHandler 工位终端工艺报工(写工位实绩 + 步骤考核)
|
||||
func StationReportInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req logic.ReportProcessReq
|
||||
@@ -159,15 +159,14 @@ func FileDownloadInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// StationCheckinInternalHandler 工位终端暂存退库(半成品入库,块4/5)
|
||||
// 记录已完成工序后按半成品 INBOUND 流转,并通知 WMS 入库。
|
||||
// 进度由 MES 服务端自取(workpiece.currentStationNo),按半成品 INBOUND 流转并通知 WMS 入库。
|
||||
func StationCheckinInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
ProcessCode int `json:"processCode"`
|
||||
Operator string `json:"operator"`
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
@@ -177,19 +176,14 @@ func StationCheckinInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
httpx.BadRequest(w, "缺少 sn")
|
||||
return
|
||||
}
|
||||
doneCodes := []int{}
|
||||
if req.ProcessCode > 0 {
|
||||
doneCodes = append(doneCodes, req.ProcessCode)
|
||||
}
|
||||
op := req.Operator
|
||||
if op == "" {
|
||||
op = operator(r, "")
|
||||
}
|
||||
if err := logic.New(svcCtx).SemiFlow(r.Context(), logic.SemiReq{
|
||||
Sn: req.Sn,
|
||||
OrderNo: req.OrderNo,
|
||||
DoneProcessCodes: doneCodes,
|
||||
Action: "INBOUND",
|
||||
Sn: req.Sn,
|
||||
OrderNo: req.OrderNo,
|
||||
Action: "INBOUND",
|
||||
}, op); err != nil {
|
||||
httpx.Fail(w, 2106, err.Error())
|
||||
return
|
||||
@@ -198,7 +192,6 @@ func StationCheckinInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// PerformanceExportHandler GET /performance/export 绩效报表导出(一个 xlsx 三个 sheet:按人/按工位/明细)
|
||||
// 执行全项目统一导出时间硬规则:起止必填(默认近3个月)、间隔≤1年
|
||||
func PerformanceExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
@@ -260,7 +253,6 @@ func PerformanceExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// normalizeExportRange MES 侧导出时间硬规则(与 WMS 同一套):
|
||||
// ① 起止都空 → 默认近 3 个月;② 只传一个 → 报错;③ 间隔 > 1 年 → 报错;④ 结束早于起始 → 报错。
|
||||
func normalizeExportRange(startDate, endDate string) (string, string, error) {
|
||||
|
||||
@@ -261,6 +261,9 @@ func serveUploadFile(w http.ResponseWriter, r *http.Request, dir, name string) {
|
||||
ct = "application/vnd.ms-excel"
|
||||
}
|
||||
w.Header().Set("Content-Type", ct)
|
||||
// 统一强制下载(Content-Disposition: attachment):文件名按 RFC 5987 编码(中文安全),
|
||||
// 浏览器直接下载不预览;<img>/<iframe> 内嵌展示不受此头影响
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+url.PathEscape(filepath.Base(abs)))
|
||||
http.ServeContent(w, r, filepath.Base(abs), time.Time{}, f)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user