453 lines
19 KiB
Go
453 lines
19 KiB
Go
package logic
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"errors"
|
||
"net/http"
|
||
"strings"
|
||
"time"
|
||
|
||
"bj_power_mes/ent"
|
||
"bj_power_mes/ent/inspectionrecord"
|
||
"bj_power_mes/ent/material"
|
||
"bj_power_mes/ent/workpiece"
|
||
"bj_power_mes/internal/wmsclient"
|
||
)
|
||
|
||
// FlexStr 兼容客户端把数字字段传成 number 或 string(前端 stationNo 用数字,
|
||
// 标准 JSON 反序列化进 string 会报错 → 400 请求体解析失败)
|
||
type FlexStr string
|
||
|
||
func (f *FlexStr) UnmarshalJSON(b []byte) error {
|
||
s := strings.TrimSpace(string(b))
|
||
s = strings.Trim(s, `"`)
|
||
if s == "null" {
|
||
s = ""
|
||
}
|
||
*f = FlexStr(s)
|
||
return nil
|
||
}
|
||
|
||
// InspectionReq 巡检记录请求(PAD 巡检终端,块8)
|
||
type InspectionReq struct {
|
||
Category string `json:"category"` // CHECKIN/POINT/PROCESS/DONE/ALARM
|
||
StationNo FlexStr `json:"stationNo"`
|
||
Shift string `json:"shift"` // 早/中/晚
|
||
OrderNo string `json:"orderNo"` // 工单号
|
||
Sn string `json:"sn"` // 工件SN
|
||
Result string `json:"result"` // OK/NG
|
||
Items []string `json:"items"` // 点检项/异常类型
|
||
Photo string `json:"photo"` // 拍照文件名
|
||
Remark string `json:"remark"` // 文字描述/签字
|
||
Operator string `json:"operator"` // 操作人
|
||
// P0-4 过程巡检按步骤维度
|
||
ProcessCode int `json:"processCode"` // 所属工位号
|
||
StepId int `json:"stepId"` // 工艺步骤ID
|
||
StepName string `json:"stepName"` // 工艺步骤名称
|
||
MeasuredValue string `json:"measuredValue"` // 实测值
|
||
// 质量检验(过程检/完工检/来料检)扩展字段
|
||
ReportNo string `json:"reportNo"` // 报检单号
|
||
MaterialCode string `json:"materialCode"` // 物料编码(图号)
|
||
MaterialName string `json:"materialName"` // 物料名称
|
||
Manufacturer string `json:"manufacturer"` // 生产厂家
|
||
InspectionNo string `json:"inspectionNo"` // 检验单号
|
||
AttachmentIds string `json:"attachmentIds"` // 附件ID,逗号分隔
|
||
DisposalType string `json:"disposalType"` // 处置类型 退货/返修/退换/报废
|
||
DisposalRemark string `json:"disposalRemark"` // 处置说明
|
||
// 判不合格联动 WMS 在库处置的定位字段(可空=不联动):
|
||
// 序列号=是(sn_mode=1)填 SN、序列号=否(sn_mode=2)填批次号;
|
||
// 定位口径由后端按物料档案 sn_mode 判定(SN=按序列号定位 / 批次=按批次定位)
|
||
BatchSn string `json:"batchSn"`
|
||
ReturnTrackingNo string `json:"returnTrackingNo"` // 退货运单号(退货/退换处置必填)
|
||
// 完工检(FINAL)扩展:产成品入库随回流 WMS(选填,其他类别存了也无害)
|
||
RelatedStandard string `json:"relatedStandard"` // 相关标准/试验方案号
|
||
TestRecordNo string `json:"testRecordNo"` // 试验记录单号
|
||
}
|
||
|
||
// wmsDisposalType MES 中文处置方式 → WMS 内部处置枚举(RETURN/REWORK/SCRAP);
|
||
// 无法映射返回空串(不联动 WMS,仅留痕)。
|
||
func wmsDisposalType(v string) string {
|
||
switch v {
|
||
case "退货", "退换":
|
||
return "RETURN"
|
||
case "返修":
|
||
return "REWORK"
|
||
case "报废":
|
||
return "SCRAP"
|
||
}
|
||
return ""
|
||
}
|
||
|
||
// CreateInspection 提交巡检记录;ALARM 类型同时触发看板报警(SSE + 清缓存)。
|
||
// 质量检验(过程检/完工检)判不合格且填了批次号/SN 时,联动 WMS 在库处置:
|
||
// 检验留痕优先——WMS 调用失败不阻断保存,仅在返回信息中提示「库存联动失败: 原因」。
|
||
func (s *Service) CreateInspection(ctx context.Context, req InspectionReq, operator string) (string, error) {
|
||
if req.Category == "" {
|
||
return "", errors.New("记录类型必填")
|
||
}
|
||
category := req.Category
|
||
// PROCESS 为 PAD 巡检终端「过程巡检」专用;MES 车间质检「过程检」用 QC_PROCESS 隔离,
|
||
// 避免同枚举导致两个列表互混、统计口径乱(P1-8)。
|
||
if !oneOf(category, "CHECKIN", "POINT", "PROCESS", "DONE", "ALARM", "INCOMING", "FINAL", "QC_PROCESS") {
|
||
return "", errors.New("记录类型不合法")
|
||
}
|
||
result := req.Result
|
||
if result == "" {
|
||
result = "OK"
|
||
}
|
||
if req.Operator == "" {
|
||
req.Operator = operator
|
||
}
|
||
create := s.ctx.EntClient.InspectionRecord.Create().
|
||
SetCategory(category).
|
||
SetStationNo(string(req.StationNo)).
|
||
SetShift(req.Shift).
|
||
SetOrderNo(req.OrderNo).
|
||
SetSn(req.Sn).
|
||
SetResult(result).
|
||
SetItems(req.Items).
|
||
SetPhoto(req.Photo).
|
||
SetRemark(req.Remark).
|
||
SetOperator(req.Operator).
|
||
SetProcessCode(req.ProcessCode).
|
||
SetStepId(req.StepId).
|
||
SetStepName(req.StepName).
|
||
SetMeasuredValue(req.MeasuredValue)
|
||
if req.ReportNo != "" {
|
||
create.SetReportNo(req.ReportNo)
|
||
}
|
||
if req.MaterialCode != "" {
|
||
create.SetMaterialCode(req.MaterialCode)
|
||
}
|
||
if req.MaterialName != "" {
|
||
create.SetMaterialName(req.MaterialName)
|
||
}
|
||
if req.Manufacturer != "" {
|
||
create.SetManufacturer(req.Manufacturer)
|
||
}
|
||
if req.InspectionNo != "" {
|
||
create.SetInspectionNo(req.InspectionNo)
|
||
}
|
||
if req.AttachmentIds != "" {
|
||
create.SetAttachmentIds(req.AttachmentIds)
|
||
}
|
||
if req.DisposalType != "" {
|
||
create.SetDisposalType(req.DisposalType)
|
||
}
|
||
if req.DisposalRemark != "" {
|
||
create.SetDisposalRemark(req.DisposalRemark)
|
||
}
|
||
if req.BatchSn != "" {
|
||
create.SetBatchSn(req.BatchSn)
|
||
}
|
||
if req.RelatedStandard != "" {
|
||
create.SetRelatedStandard(req.RelatedStandard)
|
||
}
|
||
if req.TestRecordNo != "" {
|
||
create.SetTestRecordNo(req.TestRecordNo)
|
||
}
|
||
rec, err := create.Save(ctx)
|
||
if err != nil {
|
||
return "", err
|
||
}
|
||
s.ctx.EventLog.Write(ctx, "inspection."+category, req.OrderNo, req.Operator, "inspection_record",
|
||
req.Sn, "巡检终端提交", map[string]any{"category": category, "stationNo": string(req.StationNo), "result": result})
|
||
|
||
// 判不合格 → 联动 WMS 在库处置(缺口 B):
|
||
// 前提:结论 NG + 已选可映射的处置方式 + 物料编码与批次号/SN 齐全;
|
||
// 定位口径由后端按物料档案 sn_mode 判定:序列号=是按 SN(material_code+序列号)、序列号=否按批次(material_code+批次号)。
|
||
// WMS 调用失败不阻断检验留痕,返回信息提示「库存联动失败」,并写事件日志便于追溯。
|
||
msg := "巡检记录已提交"
|
||
if result == "NG" && req.MaterialCode != "" && req.BatchSn != "" {
|
||
if dt := wmsDisposalType(req.DisposalType); dt != "" {
|
||
snMode := 2
|
||
if m, err := s.ctx.EntClient.Material.Query().Where(material.CodeEQ(req.MaterialCode)).First(ctx); err == nil {
|
||
snMode = m.SnMode
|
||
}
|
||
wreq := wmsclient.DisposeInventoryReq{
|
||
MaterialCode: req.MaterialCode,
|
||
DisposalType: dt,
|
||
ReturnTrackingNo: req.ReturnTrackingNo,
|
||
Remark: req.DisposalRemark,
|
||
Operator: req.Operator,
|
||
}
|
||
if snMode == 1 {
|
||
wreq.Sn = req.BatchSn
|
||
} else {
|
||
wreq.BatchNo = req.BatchSn
|
||
}
|
||
if err := s.ctx.Wms.DisposeInventory(ctx, wreq); err != nil {
|
||
msg = "检验记录已保存;库存联动失败: " + err.Error()
|
||
s.ctx.EventLog.Write(ctx, "inspection.wms_dispose_failed", req.OrderNo, req.Operator,
|
||
"inspection_record", req.Sn, "库存联动失败 "+err.Error(),
|
||
map[string]any{"materialCode": req.MaterialCode, "batchSn": req.BatchSn,
|
||
"disposalType": dt, "snMode": snMode})
|
||
} else {
|
||
msg = "检验记录已保存,已联动 WMS 在库处置(" + req.DisposalType + ")"
|
||
s.ctx.EventLog.Write(ctx, "inspection.wms_disposed", req.OrderNo, req.Operator,
|
||
"inspection_record", req.Sn, "已联动 WMS 在库处置 "+dt,
|
||
map[string]any{"materialCode": req.MaterialCode, "batchSn": req.BatchSn,
|
||
"disposalType": dt, "snMode": snMode})
|
||
}
|
||
}
|
||
}
|
||
|
||
// B2.3 检验不合格 → 触发 inspection_ng 预警(事件触发型,enabled 即命中,忽略阈值):
|
||
// 仅结论 NG 时触发;走 Evaluate 经 alert_rule(enabled) 门控,与拧紧/库存/超期预警同一框架。
|
||
if result == "NG" {
|
||
s.Evaluate(ctx, "inspection_ng", 1, "检验不合格",
|
||
"检验记录不合格:类型="+category+" SN="+req.Sn+" 工位"+string(req.StationNo),
|
||
"inspection_record", req.Sn, req.OrderNo)
|
||
}
|
||
|
||
// 完工检(FINAL)结论触发成品回流入库(方案A:完工检合格才入库,完工确认仅代表生产完成):
|
||
// 已通过→入库(合格)、部分通过→入库(合格)、不合格/报废→不入库待返修;
|
||
// WMS 调用结果以提示透出,不阻断检验留痕(与上方库存联动同降级策略)。
|
||
if category == "FINAL" {
|
||
msg = s.finishedInspectionInbound(ctx, rec, req, result, msg)
|
||
}
|
||
|
||
if category == "ALARM" {
|
||
// 触发看板报警:SSE 推送 + 使 Redis 看板报警缓存失效
|
||
alarmJSON, _ := json.Marshal(map[string]any{
|
||
"level": "CRITICAL",
|
||
"type": "inspection_alarm",
|
||
"message": "巡检异常上报:" + req.Remark,
|
||
"station": string(req.StationNo),
|
||
"time": time.Now().Format("2006-01-02 15:04:05"),
|
||
})
|
||
if s.ctx.SSE != nil {
|
||
s.ctx.SSE.Publish("dashboard.alarm", string(alarmJSON))
|
||
}
|
||
if s.ctx.RedisClient != nil {
|
||
_, _ = s.ctx.RedisClient.Del("dashboard:alarms")
|
||
}
|
||
}
|
||
s.notifyDashboard()
|
||
return msg, nil
|
||
}
|
||
|
||
// ListInspections 查询巡检记录(不分页,供内部/导出用,封顶 1000)
|
||
func (s *Service) ListInspections(ctx context.Context, category, operator, from, to string) ([]*ent.InspectionRecord, error) {
|
||
rows, _, err := s.ListInspectionsPaged(ctx, category, operator, from, to, "", "", "", "", "", 1, 1000)
|
||
return rows, err
|
||
}
|
||
|
||
// ListInspectionsPaged 分页查询巡检记录,返回 {rows, total};排序 id desc 最新置顶
|
||
// orderNo/stationNo:2026-09-08 补充筛选(大小写不敏感)
|
||
// materialCode/materialName/reportNo:质量检验模糊查询(Item H,每框内模糊、多框取交集)
|
||
func (s *Service) ListInspectionsPaged(ctx context.Context, category, operator, from, to, orderNo, stationNo, materialCode, materialName, reportNo string, page, pageSize int) ([]*ent.InspectionRecord, int, error) {
|
||
q := s.ctx.EntClient.InspectionRecord.Query()
|
||
if category != "" {
|
||
q = q.Where(inspectionrecord.Category(category))
|
||
}
|
||
if orderNo != "" {
|
||
q = q.Where(inspectionrecord.OrderNoEqualFold(orderNo))
|
||
}
|
||
if stationNo != "" {
|
||
q = q.Where(inspectionrecord.StationNoEqualFold(stationNo))
|
||
}
|
||
if materialCode != "" {
|
||
q = q.Where(inspectionrecord.MaterialCodeContainsFold(materialCode))
|
||
}
|
||
if materialName != "" {
|
||
q = q.Where(inspectionrecord.MaterialNameContainsFold(materialName))
|
||
}
|
||
if reportNo != "" {
|
||
q = q.Where(inspectionrecord.ReportNoContainsFold(reportNo))
|
||
}
|
||
if operator != "" {
|
||
q = q.Where(inspectionrecord.Operator(operator))
|
||
}
|
||
if from != "" {
|
||
if f, err := time.Parse("2006-01-02", from); err == nil {
|
||
q = q.Where(inspectionrecord.CreatedAtGTE(f))
|
||
}
|
||
}
|
||
if to != "" {
|
||
if t, err := time.Parse("2006-01-02", to); err == nil {
|
||
q = q.Where(inspectionrecord.CreatedAtLT(t.Add(24 * time.Hour)))
|
||
}
|
||
}
|
||
total, err := q.Count(ctx)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
rows, err := q.Order(ent.Desc(inspectionrecord.FieldID)).
|
||
Offset((page - 1) * pageSize).Limit(pageSize).All(ctx)
|
||
return rows, total, err
|
||
}
|
||
|
||
func oneOf(v string, items ...string) bool {
|
||
for _, it := range items {
|
||
if v == it {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
// GetInspectionRecord 按 id 查询一条检验记录(质量检验处置/不合格单用)
|
||
func (s *Service) GetInspectionRecord(ctx context.Context, id int) (*ent.InspectionRecord, error) {
|
||
if id <= 0 {
|
||
return nil, errors.New("缺少 id")
|
||
}
|
||
rec, err := s.ctx.EntClient.InspectionRecord.Get(ctx, id)
|
||
if err != nil {
|
||
return nil, errors.New("检验记录不存在")
|
||
}
|
||
return rec, nil
|
||
}
|
||
|
||
// SetInspectionDisposal 质量检验处置:区分 退货/返修/退换/报废,写处置说明。
|
||
func (s *Service) SetInspectionDisposal(ctx context.Context, id int, disposalType, disposalRemark, operator string) (string, error) {
|
||
if id <= 0 {
|
||
return "", errors.New("缺少 id")
|
||
}
|
||
if !oneOf(disposalType, "退货", "返修", "退换", "报废") {
|
||
return "", errors.New("处置类型仅支持 退货/返修/退换/报废")
|
||
}
|
||
rec, err := s.ctx.EntClient.InspectionRecord.Get(ctx, id)
|
||
if err != nil {
|
||
return "", errors.New("检验记录不存在")
|
||
}
|
||
_, err = s.ctx.EntClient.InspectionRecord.UpdateOneID(id).
|
||
SetDisposalType(disposalType).SetDisposalRemark(disposalRemark).Save(ctx)
|
||
if err != nil {
|
||
return "", err
|
||
}
|
||
s.ctx.EventLog.Write(ctx, "inspection.disposal", rec.OrderNo, operator, "inspection_record", rec.Sn,
|
||
"质量检验处置 "+disposalType, map[string]any{"id": id, "remark": disposalRemark})
|
||
return "处置已记录", nil
|
||
}
|
||
|
||
// finishedInspectionInbound 完工检记录保存后按结论触发成品回流入库(方案A定稿)。
|
||
// 结论映射:OK=已通过→入库(qualityStatus=合格);PARTIAL=部分通过→入库(qualityStatus=合格,
|
||
// 由 WMS 侧按 productStatus 映射);NG(含报废处置)→不入库,仅记事件日志待返修/报废。
|
||
// 归属三字段照 semi.go workpieceWorkOrder 继承模式取自工单;
|
||
// relatedStandard/testRecordNo:取自完工检记录(录入弹窗选填),随成品回流 WMS。
|
||
// WMS 409(SN 防重,返修后复检重复入库)转成「已入库勿重复」友好提示;其余失败仅提示不阻断留痕。
|
||
func (s *Service) finishedInspectionInbound(ctx context.Context, rec *ent.InspectionRecord, req InspectionReq, result, msg string) string {
|
||
productStatus := ""
|
||
switch result {
|
||
case "OK":
|
||
productStatus = "已通过"
|
||
case "PARTIAL":
|
||
productStatus = "部分通过"
|
||
}
|
||
if productStatus == "" {
|
||
// 不合格(含处置=报废/退货/退换):不入库,留痕待返修/报废
|
||
note := "成品" + rec.Sn + "完工检不合格,未入库,待返修/报废"
|
||
if req.DisposalType == "报废" {
|
||
note = "成品" + rec.Sn + "完工检报废,未入库"
|
||
}
|
||
s.ctx.EventLog.Write(ctx, "wms.finished.not_inbound", rec.OrderNo, rec.Operator, "inspection_record", rec.Sn,
|
||
note, map[string]any{"reportNo": rec.ReportNo, "result": result, "disposalType": req.DisposalType})
|
||
return msg
|
||
}
|
||
// 成品 SN:优先工件SN栏,缺省回退批次号/SN 栏(序列号=是该栏填的即 SN)
|
||
sn := strings.TrimSpace(req.Sn)
|
||
if sn == "" {
|
||
sn = strings.TrimSpace(req.BatchSn)
|
||
}
|
||
if sn == "" {
|
||
s.ctx.EventLog.Write(ctx, "wms.finished.inbound_skipped", rec.OrderNo, rec.Operator, "inspection_record", "",
|
||
"完工检合格但未填成品SN,未触发WMS入库,请人工补录", map[string]any{"reportNo": rec.ReportNo, "productStatus": productStatus})
|
||
return "检验记录已保存;未填成品SN,未自动入WMS库"
|
||
}
|
||
wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(sn)).First(ctx)
|
||
if err != nil {
|
||
s.ctx.EventLog.Write(ctx, "wms.finished.inbound_skipped", rec.OrderNo, rec.Operator, "inspection_record", sn,
|
||
"完工检合格但成品SN未匹配到工件,未触发WMS入库,请人工核查", map[string]any{"reportNo": rec.ReportNo, "productStatus": productStatus})
|
||
return "检验记录已保存;成品SN未匹配到工件,未自动入WMS库"
|
||
}
|
||
wo := s.workpieceWorkOrder(ctx, wp)
|
||
if wo == nil {
|
||
s.ctx.EventLog.Write(ctx, "wms.finished.inbound_failed", wp.OrderNo, rec.Operator, "workpiece", wp.Sn,
|
||
"完工检合格但成品回流WMS入库失败:工单不存在", map[string]any{"error": "work order not found"})
|
||
return "检验记录已保存;WMS 入库失败:工件所属工单不存在"
|
||
}
|
||
// 质量状态落库值:合格类(已通过/部分通过)统一传「合格」。
|
||
// 不传「已通过/部分通过」等非库存枚举值(WMS 库存质量状态仅认 合格/不合格/未检/待退)。
|
||
qualityStatusForWMS := "合格"
|
||
if wmsErr := s.ctx.Wms.FinishedInbound(ctx, wmsclient.FinishedPayload{
|
||
ProductCode: wo.ProductCode, ProductName: wo.ProductName, Sn: wp.Sn, OrderNo: wp.OrderNo,
|
||
Operator: rec.Operator, ProductStatus: productStatus, QualityStatus: qualityStatusForWMS,
|
||
RelatedStandard: rec.RelatedStandard, TestRecordNo: rec.TestRecordNo,
|
||
OwnershipType: wo.OwnershipType, OwnershipNo: wo.ContractNo, ProductWorkNo: wo.WorkOrderNo,
|
||
}); wmsErr != nil {
|
||
var re *wmsclient.RespError
|
||
if errors.As(wmsErr, &re) && re.Status == http.StatusConflict {
|
||
s.ctx.EventLog.Write(ctx, "wms.finished.duplicate", wp.OrderNo, rec.Operator, "workpiece", wp.Sn,
|
||
"完工检合格,但WMS提示成品SN已入库(防重拦截),请勿重复入库", map[string]any{"productCode": wo.ProductCode, "productStatus": productStatus})
|
||
return "检验记录已保存;该成品已入WMS库,请勿重复入库"
|
||
}
|
||
s.ctx.EventLog.Write(ctx, "wms.finished.inbound_failed", wp.OrderNo, rec.Operator, "workpiece", wp.Sn,
|
||
"完工检合格但成品回流WMS入库失败(库存未入,请人工补录)",
|
||
map[string]any{"error": wmsErr.Error(), "productCode": wo.ProductCode, "productStatus": productStatus})
|
||
return "检验记录已保存;WMS 入库失败: " + wmsErr.Error()
|
||
}
|
||
s.ctx.EventLog.Write(ctx, "wms.finished.inbound", wp.OrderNo, rec.Operator, "workpiece", wp.Sn,
|
||
"完工检"+productStatus+",成品已回流WMS入库", map[string]any{
|
||
"reportNo": rec.ReportNo, "productCode": wo.ProductCode, "productStatus": productStatus,
|
||
"relatedStandard": rec.RelatedStandard, "testRecordNo": rec.TestRecordNo,
|
||
"ownershipType": wo.OwnershipType, "ownershipNo": wo.ContractNo, "productWorkNo": wo.WorkOrderNo})
|
||
return msg + ";成品已回流WMS入库(" + productStatus + ")"
|
||
}
|
||
|
||
// FinishedPendingItem 待完工检成品行(完工确认后尚无对应完工检记录的成品 SN)
|
||
type FinishedPendingItem struct {
|
||
Sn string `json:"sn"`
|
||
OrderNo string `json:"orderNo"`
|
||
ProductCode string `json:"productCode"`
|
||
ProductName string `json:"productName"`
|
||
DoneAt string `json:"doneAt"`
|
||
}
|
||
|
||
// FinishedPendingList 待完工检成品:workpiece status=DONE 且 inspection_record(category=FINAL)
|
||
// 中无以该 SN 为工件SN 的记录,按完工时间倒序只读分页,供质检页完工检页签查看待检清单。
|
||
// 依据检验记录的 sn 字段排除(完工检录入必须填成品SN);历史 sn 为空的记录不参与排除。
|
||
func (s *Service) FinishedPendingList(ctx context.Context, page, pageSize int) ([]FinishedPendingItem, int, error) {
|
||
inspected, err := s.ctx.EntClient.InspectionRecord.Query().
|
||
Where(inspectionrecord.Category("FINAL"), inspectionrecord.SnNEQ("")).
|
||
Select(inspectionrecord.FieldSn).Strings(ctx)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
q := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Status("DONE"))
|
||
if len(inspected) > 0 {
|
||
q = q.Where(workpiece.Not(workpiece.SnIn(inspected...)))
|
||
}
|
||
if page < 1 {
|
||
page = 1
|
||
}
|
||
if pageSize < 1 {
|
||
pageSize = 20
|
||
}
|
||
total, err := q.Count(ctx)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
list, err := q.Order(ent.Desc(workpiece.FieldDoneAt)).
|
||
Offset((page - 1) * pageSize).Limit(pageSize).All(ctx)
|
||
if err != nil {
|
||
return nil, 0, err
|
||
}
|
||
out := make([]FinishedPendingItem, 0, len(list))
|
||
for _, wp := range list {
|
||
code, name := "", ""
|
||
if wo := s.workpieceWorkOrder(ctx, wp); wo != nil {
|
||
code, name = wo.ProductCode, wo.ProductName
|
||
}
|
||
doneAt := ""
|
||
if wp.DoneAt != nil {
|
||
doneAt = wp.DoneAt.Format("2006-01-02 15:04:05")
|
||
}
|
||
out = append(out, FinishedPendingItem{
|
||
Sn: wp.Sn, OrderNo: wp.OrderNo, ProductCode: code, ProductName: name, DoneAt: doneAt,
|
||
})
|
||
}
|
||
return out, total, nil
|
||
}
|