feat: 完成区域管理、装箱功能优化与接口标准化
- 新增区域状态字段与增删改查接口,支持区域启用/停用 - 重构实体字段JSON标签为camelCase格式统一接口规范 - 优化入库、盘点、装箱流程的交互与提示文案 - 新增装箱管理功能,支持合同号关联与装箱编辑 - 调整前端菜单与帮助文档适配业务场景变更
This commit is contained in:
@@ -21,7 +21,7 @@ func createZoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if req.ZoneCode == "" || req.ZoneName == "" {
|
||||
fail(w, http.StatusBadRequest, "zoneCode 和 zoneName 必填")
|
||||
fail(w, http.StatusBadRequest, "区域编码和区域名称必填")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ func createZoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
SetZoneCode(req.ZoneCode).
|
||||
SetZoneName(req.ZoneName).
|
||||
SetNillableDescription(strPtr(req.Description)).
|
||||
SetStatus("启用").
|
||||
Save(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
@@ -50,10 +51,82 @@ func createZoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// listZonesHandler 区域列表
|
||||
// updateZoneHandler 编辑区域
|
||||
func updateZoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
ID int `json:"id"`
|
||||
ZoneCode string `json:"zoneCode"`
|
||||
ZoneName string `json:"zoneName"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
if err := parseJSON(r, &req); err != nil || req.ID <= 0 {
|
||||
fail(w, http.StatusBadRequest, "参数错误")
|
||||
return
|
||||
}
|
||||
if req.ZoneName == "" {
|
||||
fail(w, http.StatusBadRequest, "区域名称必填")
|
||||
return
|
||||
}
|
||||
upd := ctx.EntClient.Zone.UpdateOneID(req.ID).SetZoneName(req.ZoneName)
|
||||
if req.ZoneCode != "" {
|
||||
upd.SetZoneCode(req.ZoneCode)
|
||||
}
|
||||
upd.SetNillableDescription(strPtr(req.Description))
|
||||
z, err := upd.Save(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, "更新区域失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
ok(w, z)
|
||||
}
|
||||
}
|
||||
|
||||
// listZonesHandler 区域列表(分页 + 关键字)
|
||||
func listZonesHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := ctx.EntClient.Zone.Query().Order(ent.Desc("id")).All(ctx0())
|
||||
page := atoi(r.URL.Query().Get("page"), 1)
|
||||
pageSize := atoi(r.URL.Query().Get("pageSize"), 20)
|
||||
keyword := r.URL.Query().Get("keyword")
|
||||
|
||||
q := ctx.EntClient.Zone.Query()
|
||||
if keyword != "" {
|
||||
q = q.Where(
|
||||
zone.Or(
|
||||
zone.ZoneCodeContains(keyword),
|
||||
zone.ZoneNameContains(keyword),
|
||||
),
|
||||
)
|
||||
}
|
||||
total, err := q.Count(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
list, err := q.Order(ent.Desc("id")).
|
||||
Offset((page - 1) * pageSize).
|
||||
Limit(pageSize).
|
||||
All(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
ok(w, map[string]any{
|
||||
"total": total,
|
||||
"list": list,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// listZonesForPicker 区域下拉列表(不分页,仅启用)
|
||||
func listZonesForPicker(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := ctx.EntClient.Zone.Query().
|
||||
Where(zone.StatusEQ("启用")).
|
||||
Order(ent.Asc("id")).
|
||||
All(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user