style(formatter): 格式化代码中的缩进和空行

- 统一了结构体字段的对齐方式,保持一致的缩进
- 调整了 import 语句的顺序,将 fmt 移至合适位置
- 修复了多处多余的空行和空白字符
- 规范化了注释的缩进格式
- 整理了路由配置的缩进层次
- 调整了常量定义的对齐格式
This commit is contained in:
SunYF
2026-09-20 14:53:14 +08:00
parent f35e9b5b75
commit 60eacc9c4f
10 changed files with 66 additions and 62 deletions
@@ -66,16 +66,16 @@ func ImportBomHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
} }
} }
item := logic.BomItemReq{ item := logic.BomItemReq{
ProductCode: productCode, ProductCode: productCode,
BomName: bomName, BomName: bomName,
MaterialCode: materialCode, MaterialCode: materialCode,
MaterialName: trimCell(row, 3), MaterialName: trimCell(row, 3),
Spec: trimCell(row, 4), Spec: trimCell(row, 4),
Unit: trimCell(row, 5), Unit: trimCell(row, 5),
ManageMode: "2", ManageMode: "2",
ProcessCode: &pc, ProcessCode: &pc,
UnitQty: parseFloat(trimCell(row, 6)), UnitQty: parseFloat(trimCell(row, 6)),
LossRate: parseFloat(trimCell(row, 7)), LossRate: parseFloat(trimCell(row, 7)),
RelatedStandard: trimCell(row, 9), RelatedStandard: trimCell(row, 9),
} }
k := key{productCode, bomName} k := key{productCode, bomName}
@@ -357,4 +357,4 @@ func StationReceiveMaterialInternalHandler(svcCtx *svc.ServiceContext) http.Hand
} }
httpx.Ok(w, nil) httpx.Ok(w, nil)
} }
} }
+4 -4
View File
@@ -1,11 +1,11 @@
package wmsclient package wmsclient
import ( import (
"fmt"
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
@@ -186,8 +186,8 @@ func (c *Client) ProductTypePage(ctx context.Context, code, name, category, isAc
q += "&isActive=" + isActive q += "&isActive=" + isActive
} }
var data struct { var data struct {
Total int64 `json:"total"` Total int64 `json:"total"`
List []ProductTypeRow `json:"list"` List []ProductTypeRow `json:"list"`
} }
if err := c.get(ctx, q, &data); err != nil { if err := c.get(ctx, q, &data); err != nil {
return 0, nil, err return 0, nil, err
@@ -651,4 +651,4 @@ type RespError struct {
func (e *RespError) Error() string { func (e *RespError) Error() string {
return "wms call failed with status " + string(rune('0'+e.Status)) return "wms call failed with status " + string(rune('0'+e.Status))
} }
+9 -9
View File
@@ -435,15 +435,15 @@ func serveUploadFileHandler(ctx *svc.ServiceContext) http.HandlerFunc {
// diskStatusView 磁盘状态视图(供接口/页面告警条使用)。 // diskStatusView 磁盘状态视图(供接口/页面告警条使用)。
type diskStatusView struct { type diskStatusView struct {
RootDir string `json:"rootDir"` RootDir string `json:"rootDir"`
UsedPercent int `json:"usedPercent"` UsedPercent int `json:"usedPercent"`
FreeBytes uint64 `json:"freeBytes"` FreeBytes uint64 `json:"freeBytes"`
TotalBytes uint64 `json:"totalBytes"` TotalBytes uint64 `json:"totalBytes"`
WarnPercent int `json:"warnPercent"` WarnPercent int `json:"warnPercent"`
CritPercent int `json:"critPercent"` CritPercent int `json:"critPercent"`
Level string `json:"level"` // ok / warn / critical Level string `json:"level"` // ok / warn / critical
Message string `json:"message"` Message string `json:"message"`
CheckedUnix int64 `json:"checkedAt"` CheckedUnix int64 `json:"checkedAt"`
} }
// diskStatus 读取附件根目录所在磁盘剩余空间并给出告警级别。 // diskStatus 读取附件根目录所在磁盘剩余空间并给出告警级别。
+4 -4
View File
@@ -84,12 +84,12 @@ func createInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return return
} }
if req.ZoneCode == "" { if req.ZoneCode == "" {
fail(w, http.StatusBadRequest, "区域必填,请先选择入库区域") fail(w, http.StatusBadRequest, "区域必填,请先选择入库区域")
return return
} }
if req.InspectionNo == "" { if req.InspectionNo == "" {
fail(w, http.StatusBadRequest, "检测单号必填,请填写入库检报告单号") fail(w, http.StatusBadRequest, "检测单号必填,请填写入库检报告单号")
return return
} }
// 物料档案 // 物料档案
+13 -12
View File
@@ -44,11 +44,11 @@ func semiInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
Category int `json:"category"` // 2=半成品 3=成品(默认 2 Category int `json:"category"` // 2=半成品 3=成品(默认 2
OwnershipType string `json:"ownershipType"` OwnershipType string `json:"ownershipType"`
OwnershipNo string `json:"ownershipNo"` OwnershipNo string `json:"ownershipNo"`
ProductStatus string `json:"productStatus"` // 已通过/部分通过/返修(成品用) ProductStatus string `json:"productStatus"` // 已通过/部分通过/返修(成品用)
RelatedStandard string `json:"relatedStandard"` // 相关标准(试验方案号) RelatedStandard string `json:"relatedStandard"` // 相关标准(试验方案号)
TestRecordNo string `json:"testRecordNo"` // 试验记录单号 TestRecordNo string `json:"testRecordNo"` // 试验记录单号
RecordedBy string `json:"recordedBy"` // 记录员 RecordedBy string `json:"recordedBy"` // 记录员
RecordedAt int64 `json:"recordedAt"` // 记录日期(unix 秒) RecordedAt int64 `json:"recordedAt"` // 记录日期(unix 秒)
} }
if err := parseJSON(r, &req); err != nil { if err := parseJSON(r, &req); err != nil {
fail(w, http.StatusBadRequest, "参数错误") fail(w, http.StatusBadRequest, "参数错误")
@@ -119,7 +119,7 @@ func semiInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
SetNillableTestRecordNo(strPtr(req.TestRecordNo)). SetNillableTestRecordNo(strPtr(req.TestRecordNo)).
SetNillableRecordedBy(strPtr(req.RecordedBy)). SetNillableRecordedBy(strPtr(req.RecordedBy)).
SetNillableRecordedAt(int64Ptr(req.RecordedAt)). SetNillableRecordedAt(int64Ptr(req.RecordedAt)).
SetRemark(catLabel+"完工暂存回流"). SetRemark(catLabel + "完工暂存回流").
Save(ctx0()) Save(ctx0())
if err != nil { if err != nil {
fail(w, http.StatusInternalServerError, err.Error()) fail(w, http.StatusInternalServerError, err.Error())
@@ -305,11 +305,12 @@ type ledgerRow struct {
// ledgerState 备料四态判定(客户诉求 问题记录 L242-258 孙彦飞口径),优先级:未到货 > 预警 > 未齐套 > 齐套。 // ledgerState 备料四态判定(客户诉求 问题记录 L242-258 孙彦飞口径),优先级:未到货 > 预警 > 未齐套 > 齐套。
// //
// 状态定义(L253-256): // 状态定义(L253-256):
// 齐套 :可用库存 ≥ 需求总量 //
// 未齐套:0 < 可用库存 < 需求总量 // 齐套 可用库存 需求总量
// 未到货:可用库存 = 0 且 已出库 = 0 // 未齐套:0 < 可用库存 < 需求总量
// 预警 :可用库存 < 未来5天需求量(future5Qty 由 MES 按近5天日排产×单台用量推送到 material_demands // 未到货:可用库存 = 0 且 已出库 = 0
// 无推送记录时 future5Qty=0,该档不生效,退化为三态判定) // 预警 :可用库存 < 未来5天需求量(future5Qty 由 MES 按近5天日排产×单台用量推送到 material_demands
// 无推送记录时 future5Qty=0,该档不生效,退化为三态判定)
func ledgerState(avail, need, out, future5Qty int) string { func ledgerState(avail, need, out, future5Qty int) string {
if avail <= 0 && out <= 0 { if avail <= 0 && out <= 0 {
return "未到货" return "未到货"
@@ -375,7 +376,7 @@ func queryLedgerHandler(ctx *svc.ServiceContext) http.HandlerFunc {
materialCode := r.URL.Query().Get("materialCode") materialCode := r.URL.Query().Get("materialCode")
materialName := r.URL.Query().Get("materialName") materialName := r.URL.Query().Get("materialName")
status := r.URL.Query().Get("status") status := r.URL.Query().Get("status")
state := r.URL.Query().Get("state") // 四态筛选:齐套/未齐套/预警/未到货 state := r.URL.Query().Get("state") // 四态筛选:齐套/未齐套/预警/未到货
completeStart := r.URL.Query().Get("completeStart") // 完成时间起(YYYY-MM-DD completeStart := r.URL.Query().Get("completeStart") // 完成时间起(YYYY-MM-DD
completeEnd := r.URL.Query().Get("completeEnd") // 完成时间止 completeEnd := r.URL.Query().Get("completeEnd") // 完成时间止
page := atoi(r.URL.Query().Get("page"), 1) page := atoi(r.URL.Query().Get("page"), 1)
+2 -2
View File
@@ -413,8 +413,8 @@ type generalOutboundRequest struct {
OwnershipType string `json:"ownershipType"` // workorder/project/other OwnershipType string `json:"ownershipType"` // workorder/project/other
OwnershipNo string `json:"ownershipNo"` OwnershipNo string `json:"ownershipNo"`
TargetStation string `json:"targetStation"` TargetStation string `json:"targetStation"`
TargetDock string `json:"targetDock"` // 目标接驳台(叫AGV时必填) TargetDock string `json:"targetDock"` // 目标接驳台(叫AGV时必填)
NeedAgv bool `json:"needAgv"` // 是否叫AGV配送到接驳台(可选) NeedAgv bool `json:"needAgv"` // 是否叫AGV配送到接驳台(可选)
} }
// generalOutboundHandler 通用出库(手动出库,不依赖工单) // generalOutboundHandler 通用出库(手动出库,不依赖工单)
+8 -8
View File
@@ -242,12 +242,12 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
{Method: http.MethodPost, Path: "/api/internal/product-types", Handler: wrapInternal(ctx)(createProductTypeInternalHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/product-types", Handler: wrapInternal(ctx)(createProductTypeInternalHandler(ctx))},
{Method: http.MethodPut, Path: "/api/internal/product-types", Handler: wrapInternal(ctx)(updateProductTypeInternalHandler(ctx))}, {Method: http.MethodPut, Path: "/api/internal/product-types", Handler: wrapInternal(ctx)(updateProductTypeInternalHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/product-types/delete", Handler: wrapInternal(ctx)(deleteProductTypeInternalHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/product-types/delete", Handler: wrapInternal(ctx)(deleteProductTypeInternalHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/material/exists", Handler: wrapInternal(ctx)(materialExistsHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/material/exists", Handler: wrapInternal(ctx)(materialExistsHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/material/types", Handler: wrapInternal(ctx)(materialTypesHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/material/types", Handler: wrapInternal(ctx)(materialTypesHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/dock/pallet-sync", Handler: syncDockPalletHandler(ctx)}, {Method: http.MethodPost, Path: "/api/internal/dock/pallet-sync", Handler: syncDockPalletHandler(ctx)},
{Method: http.MethodPost, Path: "/api/internal/return-order", Handler: wrapInternal(ctx)(createReturnOrderInternalHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/return-order", Handler: wrapInternal(ctx)(createReturnOrderInternalHandler(ctx))},
{Method: http.MethodGet, Path: "/api/internal/docks", Handler: wrapInternal(ctx)(listDocksInternalHandler(ctx))}, {Method: http.MethodGet, Path: "/api/internal/docks", Handler: wrapInternal(ctx)(listDocksInternalHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/material/backflush", Handler: wrapInternal(ctx)(backflushInternalHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/material/backflush", Handler: wrapInternal(ctx)(backflushInternalHandler(ctx))},
}, },
) )
} }
+7 -5
View File
@@ -7,7 +7,6 @@ import (
"strings" "strings"
"time" "time"
"entgo.io/ent/dialect/sql"
"bj_power_wms/ent" "bj_power_wms/ent"
"bj_power_wms/ent/inventory" "bj_power_wms/ent/inventory"
"bj_power_wms/ent/inventorylock" "bj_power_wms/ent/inventorylock"
@@ -15,6 +14,8 @@ import (
"bj_power_wms/ent/predicate" "bj_power_wms/ent/predicate"
"bj_power_wms/ent/zone" "bj_power_wms/ent/zone"
"bj_power_wms/internal/svc" "bj_power_wms/internal/svc"
"entgo.io/ent/dialect/sql"
) )
// stockKey 库存聚合行的唯一标识(组合键)+ 明细下钻的过滤条件 // stockKey 库存聚合行的唯一标识(组合键)+ 明细下钻的过滤条件
@@ -298,7 +299,7 @@ func aggregateStock(ctx *svc.ServiceContext, a aggregateStockArgs) ([]*stockAggR
// 回答"这个物料总共有多少":总数/锁定/可用 + 质量分布(合格/未检/不合格) + 分布区域列表。 // 回答"这个物料总共有多少":总数/锁定/可用 + 质量分布(合格/未检/不合格) + 分布区域列表。
// ID 取物料主表(material)主键——聚合视图无自身实体,主表 ID 即行标识,禁止伪 id。 // ID 取物料主表(material)主键——聚合视图无自身实体,主表 ID 即行标识,禁止伪 id。
type materialAggRow struct { type materialAggRow struct {
ID int64 `json:"id"` // 物料主表 IDmaterial.id,档案缺失时为 0 ID int64 `json:"id"` // 物料主表 IDmaterial.id,档案缺失时为 0
MaterialCode string `json:"materialCode"` MaterialCode string `json:"materialCode"`
MaterialName string `json:"materialName"` MaterialName string `json:"materialName"`
Spec string `json:"spec"` Spec string `json:"spec"`
@@ -665,14 +666,15 @@ func exportStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
sendExcel(w, xlsxFilename("库存汇总"), headers, matrix) sendExcel(w, xlsxFilename("库存汇总"), headers, matrix)
} }
} }
// zoneSummRow 区域汇总行(按 区域 + 质量状态 + 类型 聚合) // zoneSummRow 区域汇总行(按 区域 + 质量状态 + 类型 聚合)
// ID/ZoneCreatedAt 取区域主表(zone)主键与创建时间——聚合视图无自身实体,主表字段即行标识,禁止伪 id。 // ID/ZoneCreatedAt 取区域主表(zone)主键与创建时间——聚合视图无自身实体,主表字段即行标识,禁止伪 id。
type zoneSummRow struct { type zoneSummRow struct {
ID int64 `json:"id"` // 区域主表 ID(zone.id,未分区时为 0 ID int64 `json:"id"` // 区域主表 ID(zone.id,未分区时为 0
ZoneCode string `json:"zoneCode"` ZoneCode string `json:"zoneCode"`
ZoneName string `json:"zoneName"` ZoneName string `json:"zoneName"`
Quality string `json:"quality"` Quality string `json:"quality"`
Type string `json:"type"` // 批次/电气件 Type string `json:"type"` // 批次/电气件
Qty int `json:"qty"` Qty int `json:"qty"`
ZoneCreatedAt int64 `json:"zoneCreatedAt"` // 区域主表创建时间(zone.created_at ZoneCreatedAt int64 `json:"zoneCreatedAt"` // 区域主表创建时间(zone.created_at
LastCreatedAt int64 `json:"lastCreatedAt"` // 组内最近一次入库时间 LastCreatedAt int64 `json:"lastCreatedAt"` // 组内最近一次入库时间
@@ -1056,7 +1058,7 @@ func itoa(n int) string {
// shortageRow 缺货预警行(安全库存 > 0 且可用量 < 安全库存) // shortageRow 缺货预警行(安全库存 > 0 且可用量 < 安全库存)
type shortageRow struct { type shortageRow struct {
ID int64 `json:"id"` // 物料主表 ID ID int64 `json:"id"` // 物料主表 ID
MaterialCode string `json:"materialCode"` MaterialCode string `json:"materialCode"`
MaterialName string `json:"materialName"` MaterialName string `json:"materialName"`
Spec string `json:"spec"` Spec string `json:"spec"`
+5 -4
View File
@@ -291,10 +291,10 @@ func createZoneNodeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
} }
type zoneNodeUpdateReq struct { type zoneNodeUpdateReq struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Remark string `json:"remark"` Remark string `json:"remark"`
Status string `json:"status"` Status string `json:"status"`
} }
// updateZoneNodeHandler 编辑节点(四级均可改名称/备注/启用停用;区域额外同步 zone_name 冗余)。 // updateZoneNodeHandler 编辑节点(四级均可改名称/备注/启用停用;区域额外同步 zone_name 冗余)。
@@ -342,6 +342,7 @@ func updateZoneNodeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
// listZonesForPicker 库位下拉(兼容 + 层级两用): // listZonesForPicker 库位下拉(兼容 + 层级两用):
// - 不带 level:返回所有启用位置号(level4)扁平结构(兼容 Outbound/Stocktake/Inventory 旧调用) // - 不带 level:返回所有启用位置号(level4)扁平结构(兼容 Outbound/Stocktake/Inventory 旧调用)
// - 带 level:返回该层级节点(用于入库页区域→货架→层→位置 级联下拉) // - 带 level:返回该层级节点(用于入库页区域→货架→层→位置 级联下拉)
//
// locKey 四级货位比较键:区域/货架忽略大小写(存量数据存在 z01/Z01 混用),层/位置原样。 // locKey 四级货位比较键:区域/货架忽略大小写(存量数据存在 z01/Z01 混用),层/位置原样。
func locKey(zoneCode, shelfNo, layerNo, positionNo string) string { func locKey(zoneCode, shelfNo, layerNo, positionNo string) string {
return strings.ToLower(strings.TrimSpace(zoneCode)) + "|" + return strings.ToLower(strings.TrimSpace(zoneCode)) + "|" +
+3 -3
View File
@@ -32,9 +32,9 @@ type Inventory struct {
// 品类(category):1=原材料 2=半成品 3=成品。与 manage_mode 正交: // 品类(category):1=原材料 2=半成品 3=成品。与 manage_mode 正交:
// manage_mode 管"怎么管"(批次数量 vs SN 单件),category 管"是什么"(原料/半成品/成品)。 // manage_mode 管"怎么管"(批次数量 vs SN 单件),category 管"是什么"(原料/半成品/成品)。
const ( const (
InvCategoryRaw = 1 InvCategoryRaw = 1
InvCategorySemi = 2 InvCategorySemi = 2
InvCategoryFinished = 3 InvCategoryFinished = 3
) )
func (Inventory) Fields() []ent.Field { func (Inventory) Fields() []ent.Field {