提交
This commit is contained in:
@@ -1049,9 +1049,24 @@ func materialCodesByManageMode(ctx *svc.ServiceContext, manageMode int) []string
|
||||
return codes
|
||||
}
|
||||
|
||||
// inboundNosByType 取符合入库类型的入库单号集合(待检清单按入库类型过滤用,B1)。
|
||||
func inboundNosByType(ctx *svc.ServiceContext, inboundType string) ([]string, error) {
|
||||
orders, err := ctx.EntClient.InboundOrder.Query().Where(inboundorder.InboundTypeEQ(inboundType)).All(ctx0())
|
||||
// inboundNosByType 取符合入库类型/入库时间范围的入库单号集合(待检清单按入库类型/时间过滤用,B1)。
|
||||
// inboundType 为空表示不限类型;dateFrom/dateTo 为 YYYY-MM-DD,空表示不限(含止日当天)。
|
||||
func inboundNosByType(ctx *svc.ServiceContext, inboundType, dateFrom, dateTo string) ([]string, error) {
|
||||
oq := ctx.EntClient.InboundOrder.Query()
|
||||
if inboundType != "" {
|
||||
oq = oq.Where(inboundorder.InboundTypeEQ(inboundType))
|
||||
}
|
||||
if dateFrom != "" {
|
||||
if t, err := time.ParseInLocation("2006-01-02", dateFrom, time.Local); err == nil {
|
||||
oq = oq.Where(inboundorder.CreatedAtGTE(t.Unix()))
|
||||
}
|
||||
}
|
||||
if dateTo != "" {
|
||||
if t, err := time.ParseInLocation("2006-01-02", dateTo, time.Local); err == nil {
|
||||
oq = oq.Where(inboundorder.CreatedAtLTE(t.Add(24 * time.Hour).Unix()))
|
||||
}
|
||||
}
|
||||
orders, err := oq.All(ctx0())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1074,6 +1089,7 @@ type pendingInspectionRow struct {
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
MatManageMode int `json:"matManageMode"` // 物料档案类型(1结构件/2电气件/3其他)
|
||||
SnMode int `json:"snMode"` // 物料序列号设置(1=是/2=否/0未选择),待检清单展示用
|
||||
UnInspectedQty int `json:"unInspectedQty"` // 未检数量(结构件=数量求和;电气件=SN 行数)
|
||||
DetailsTotal int `json:"detailsTotal"` // 未检批次数/SN 总数(抽屉分页拉明细)
|
||||
InboundTime int64 `json:"inboundTime"`
|
||||
@@ -1084,13 +1100,17 @@ type pendingInspectionRow struct {
|
||||
// 按入库单为主行分组(展开看该单下批次/SN 明细),支持 物料/入库类型/目标类型(targetType=sn_mode 维度)/类型(manageMode) 筛选。
|
||||
// targetType 仍按物料 sn_mode 落 BATCH/SN/OTHER(兼容旧参数);manageMode 按物料 manage_mode 维度(1结构件/2电气件/3其他)过滤,两者正交可叠加。
|
||||
// 勾选带入录入页时,归属/入库类型/物料一并从入库单与库存行回填(§E1/E2)。
|
||||
// GET /api/inspection/pending?materialCode=&inboundType=&targetType=&manageMode=&page=&pageSize=
|
||||
// GET /api/inspection/pending?materialCode=&inboundNo=&materialName=&inboundType=&dateFrom=&dateTo=&targetType=&manageMode=&page=&pageSize=
|
||||
func pendingInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
materialCode := r.URL.Query().Get("materialCode")
|
||||
inboundType := r.URL.Query().Get("inboundType") // purchase/semi/finished/return/other
|
||||
targetType := r.URL.Query().Get("targetType") // BATCH(序列号=否)/SN(序列号=是)/OTHER(其他),按物料 sn_mode 维度
|
||||
manageMode := r.URL.Query().Get("manageMode") // 1结构件/2电气件/3其他,按物料 manage_mode 维度(类型维度,与 targetType 正交,可叠加)
|
||||
inboundNo := r.URL.Query().Get("inboundNo") // 入库单号(模糊)
|
||||
materialName := r.URL.Query().Get("materialName") // 物料名称(模糊)
|
||||
inboundType := r.URL.Query().Get("inboundType") // purchase/semi/finished/return/other
|
||||
dateFrom := r.URL.Query().Get("dateFrom") // 入库时间起 YYYY-MM-DD
|
||||
dateTo := r.URL.Query().Get("dateTo") // 入库时间止 YYYY-MM-DD
|
||||
targetType := r.URL.Query().Get("targetType") // BATCH(序列号=否)/SN(序列号=是)/OTHER(其他),按物料 sn_mode 维度
|
||||
manageMode := r.URL.Query().Get("manageMode") // 1结构件/2电气件/3其他,按物料 manage_mode 维度(类型维度,与 targetType 正交,可叠加)
|
||||
page := atoi(r.URL.Query().Get("page"), 1)
|
||||
pageSize := atoi(r.URL.Query().Get("pageSize"), 20)
|
||||
|
||||
@@ -1099,6 +1119,26 @@ func pendingInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
if materialCode != "" {
|
||||
q = q.Where(inventory.MaterialCodeContainsFold(materialCode))
|
||||
}
|
||||
if inboundNo != "" {
|
||||
q = q.Where(inventory.InboundNoContainsFold(inboundNo))
|
||||
}
|
||||
if materialName != "" {
|
||||
// 物料名称在 material 表:先按名称取编码集再 IN,避免逐行 join
|
||||
mats, err := ctx.EntClient.Material.Query().Where(material.NameContainsFold(materialName)).All(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
if len(mats) == 0 {
|
||||
ok(w, map[string]any{"list": []any{}, "total": 0})
|
||||
return
|
||||
}
|
||||
codes := make([]string, 0, len(mats))
|
||||
for _, m := range mats {
|
||||
codes = append(codes, m.Code)
|
||||
}
|
||||
q = q.Where(inventory.MaterialCodeIn(codes...))
|
||||
}
|
||||
switch targetType {
|
||||
case "BATCH":
|
||||
q = q.Where(inventory.SnModeEQ(snModeBatch))
|
||||
@@ -1123,10 +1163,14 @@ func pendingInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
q = q.Where(inventory.MaterialCodeIn(codes...))
|
||||
}
|
||||
if inboundType != "" {
|
||||
// 入库类型在 inbound_orders 表,先取符合 inbound_type 的 inbound_no 集再 IN
|
||||
nos, err := inboundNosByType(ctx, inboundType)
|
||||
if err != nil || len(nos) == 0 {
|
||||
if inboundType != "" || dateFrom != "" || dateTo != "" {
|
||||
// 入库类型/入库时间都在 inbound_orders 表,合并为一次查询取单号集再 IN
|
||||
nos, err := inboundNosByType(ctx, inboundType, dateFrom, dateTo)
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
if len(nos) == 0 {
|
||||
ok(w, map[string]any{"list": []any{}, "total": 0})
|
||||
return
|
||||
}
|
||||
@@ -1198,6 +1242,7 @@ func pendingInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
MaterialCode: inv.MaterialCode,
|
||||
MaterialName: matName[inv.MaterialCode],
|
||||
MatManageMode: matManageMode[inv.MaterialCode],
|
||||
SnMode: inv.SnMode,
|
||||
InspectionNo: strOrEmptyInspectionNo(o),
|
||||
}
|
||||
group[key] = g
|
||||
|
||||
Reference in New Issue
Block a user