Files
bj_power/bj_power_wms/internal/handler/dock.go
T
SunYF f35e9b5b75 docs(deployment): 更新部署手册和业务架构说明
- 更新MES和WMS服务端口配置说明
- 详细说明产线工位设备配置(扫码枪+拧紧枪)
- 明确AGV配送和接驳台的模拟模式与真实对接方案
- 更新WMS中AGV配送默认模拟模式说明
- 完善厂内物流(AGV/接驳台)的业务架构约束
- 修订临时文档为详细的项目问题和解决方案规划
2026-09-20 14:52:36 +08:00

158 lines
5.4 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"
"bj_power_wms/ent"
"bj_power_wms/ent/dock"
"bj_power_wms/internal/svc"
)
// dockRow 接驳台返回 DTO(显式 json 标签,避免依赖 ent 默认编组)。
type dockRow struct {
DockCode string `json:"dockCode"`
Name string `json:"name"`
DockType string `json:"dockType"`
StationNo int `json:"stationNo"`
HasPallet bool `json:"hasPallet"`
Status string `json:"status"`
}
// listDocksInternalHandler 返回接驳台主数据列表(dock 真源在 WMS)。
// MES 工位维护页拉取此接口填充「送达接驳台」下拉,避免写死 DOCK01..20 留后患。
func listDocksInternalHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
list, err := ctx.EntClient.Dock.Query().
Order(ent.Asc("dock_code")).All(ctx0())
if err != nil {
fail(w, http.StatusInternalServerError, "查询接驳台失败: "+err.Error())
return
}
rows := make([]dockRow, 0, len(list))
for _, d := range list {
rows = append(rows, dockRow{
DockCode: d.DockCode,
Name: d.Name,
DockType: d.DockType,
StationNo: d.StationNo,
HasPallet: d.HasPallet,
Status: d.Status,
})
}
ok(w, map[string]any{"list": rows})
}
}
// ---------- 接驳台主数据维护 ----------
// 接驳台是独立主数据:除产线工位旁,库房、缓存区等其他位置也有接驳台位。
// 类型:line=产线(绑定工位,与工位 1:1/ store=库房 / other=其他(均不绑定工位)。
// dockMaintRow 接驳台维护页返回行(显式 json,避免 ent omitempty 吞掉 hasPallet=false
type dockMaintRow struct {
ID int64 `json:"id"`
DockCode string `json:"dockCode"`
Name string `json:"name"`
DockType string `json:"dockType"`
StationNo int `json:"stationNo"`
Status string `json:"status"`
HasPallet bool `json:"hasPallet"`
PalletRef string `json:"palletRef"`
CreatedAt int64 `json:"createdAt"`
}
func dockMaintRowOf(d *ent.Dock) dockMaintRow {
return dockMaintRow{
ID: int64(d.ID),
DockCode: d.DockCode,
Name: d.Name,
DockType: d.DockType,
StationNo: d.StationNo,
Status: d.Status,
HasPallet: d.HasPallet,
PalletRef: d.PalletRef,
CreatedAt: d.CreatedAt,
}
}
// listDocksMaintHandler GET /api/docks?dockType=&dockCode=&name=&status=&page=&pageSize=
// 接驳台主数据只读分页查询(真分页在 SQL 层),编码精确/名称模糊/状态精确各自独立筛选。
func listDocksMaintHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
query := ctx.EntClient.Dock.Query()
if typ := q.Get("dockType"); typ != "" {
query = query.Where(dock.DockType(typ))
}
// 列表页禁止关键字混搜:编码精确、名称模糊、状态精确,各字段独立筛选(需求5、N)
if code := strings.TrimSpace(q.Get("dockCode")); code != "" {
query = query.Where(dock.DockCodeEqualFold(code))
}
if name := strings.TrimSpace(q.Get("name")); name != "" {
query = query.Where(dock.NameContainsFold(name))
}
if status := strings.TrimSpace(q.Get("status")); status != "" {
query = query.Where(dock.StatusEQ(status))
}
total, err := query.Count(ctx0())
if err != nil {
fail(w, http.StatusInternalServerError, "查询接驳台失败: "+err.Error())
return
}
page := atoi(q.Get("page"), 1)
size := atoi(q.Get("pageSize"), 20)
if page < 1 {
page = 1
}
if size < 1 || size > 200 {
size = 20
}
list, err := query.
Order(ent.Desc("created_at"), ent.Desc("id")).
Offset((page - 1) * size).Limit(size).All(ctx0())
if err != nil {
fail(w, http.StatusInternalServerError, "查询接驳台失败: "+err.Error())
return
}
rows := make([]dockMaintRow, 0, len(list))
for _, d := range list {
rows = append(rows, dockMaintRowOf(d))
}
ok(w, map[string]any{"list": rows, "total": total, "page": page, "pageSize": size})
}
}
// 接驳台为系统预置只读主数据(需求5):不提供新增/修改/删除,仅保留查询。
// 原 createDockHandler / updateDockHandler / deleteDockHandler / validateDock / dockReq 已彻底移除,
// 接驳台数据由 db/seed.go 种子初始化,调整由实施维护种子或数据库完成。
// stationOption 出库目标工位下拉项(需求20:目标工位可下拉选择、不允许手输)。
// 客户口径「出库工位号来自 MES 工位列表」——WMS 侧以接驳台主数据中 line 类型
// (产线接驳台与工位 1:1 绑定)为真源派生工位选项,避免前端写死 1~20。
type stationOption struct {
StationNo int `json:"stationNo"`
Name string `json:"name"`
DockCode string `json:"dockCode"`
}
// listStationOptionsHandler GET /api/outbound/stations 返回产线工位下拉选项(无权限包裹,供出库页调用)。
func listStationOptionsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
list, err := ctx.EntClient.Dock.Query().
Where(dock.DockType("line")).
Order(ent.Asc("station_no")).All(ctx0())
if err != nil {
fail(w, http.StatusInternalServerError, "查询工位失败: "+err.Error())
return
}
rows := make([]stationOption, 0, len(list))
for _, d := range list {
if d.StationNo <= 0 {
continue
}
rows = append(rows, stationOption{StationNo: d.StationNo, Name: d.Name, DockCode: d.DockCode})
}
ok(w, map[string]any{"list": rows})
}
}