2026-09-19 07:50:21 +08:00
|
|
|
|
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,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-20 14:52:36 +08:00
|
|
|
|
// listDocksMaintHandler GET /api/docks?dockType=&dockCode=&name=&status=&page=&pageSize=
|
|
|
|
|
|
// 接驳台主数据只读分页查询(真分页在 SQL 层),编码精确/名称模糊/状态精确各自独立筛选。
|
2026-09-19 07:50:21 +08:00
|
|
|
|
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))
|
|
|
|
|
|
}
|
2026-09-20 14:52:36 +08:00
|
|
|
|
// 列表页禁止关键字混搜:编码精确、名称模糊、状态精确,各字段独立筛选(需求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))
|
2026-09-19 07:50:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
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})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-20 14:52:36 +08:00
|
|
|
|
// 接驳台为系统预置只读主数据(需求5):不提供新增/修改/删除,仅保留查询。
|
|
|
|
|
|
// 原 createDockHandler / updateDockHandler / deleteDockHandler / validateDock / dockReq 已彻底移除,
|
|
|
|
|
|
// 接驳台数据由 db/seed.go 种子初始化,调整由实施维护种子或数据库完成。
|
2026-09-19 07:50:21 +08:00
|
|
|
|
|
2026-09-20 14:52:36 +08:00
|
|
|
|
// stationOption 出库目标工位下拉项(需求20:目标工位可下拉选择、不允许手输)。
|
|
|
|
|
|
// 客户口径「出库工位号来自 MES 工位列表」——WMS 侧以接驳台主数据中 line 类型
|
|
|
|
|
|
// (产线接驳台与工位 1:1 绑定)为真源派生工位选项,避免前端写死 1~20。
|
|
|
|
|
|
type stationOption struct {
|
|
|
|
|
|
StationNo int `json:"stationNo"`
|
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
|
DockCode string `json:"dockCode"`
|
2026-09-19 07:50:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-20 14:52:36 +08:00
|
|
|
|
// listStationOptionsHandler GET /api/outbound/stations 返回产线工位下拉选项(无权限包裹,供出库页调用)。
|
|
|
|
|
|
func listStationOptionsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
2026-09-19 07:50:21 +08:00
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
2026-09-20 14:52:36 +08:00
|
|
|
|
list, err := ctx.EntClient.Dock.Query().
|
|
|
|
|
|
Where(dock.DockType("line")).
|
|
|
|
|
|
Order(ent.Asc("station_no")).All(ctx0())
|
2026-09-19 07:50:21 +08:00
|
|
|
|
if err != nil {
|
2026-09-20 14:52:36 +08:00
|
|
|
|
fail(w, http.StatusInternalServerError, "查询工位失败: "+err.Error())
|
2026-09-19 07:50:21 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-09-20 14:52:36 +08:00
|
|
|
|
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})
|
2026-09-19 07:50:21 +08:00
|
|
|
|
}
|
2026-09-20 14:52:36 +08:00
|
|
|
|
ok(w, map[string]any{"list": rows})
|
2026-09-19 07:50:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|