From 302c591ca77dd4fb2b6e373d9912b91ee88f89f5 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 23 八月 2023 12:58:56 +0800
Subject: [PATCH] 下发工艺参数时使用nsq获取工艺参数
---
model/procedures.go | 88 +++++++++++++++++++++++++++++++++++--------
1 files changed, 71 insertions(+), 17 deletions(-)
diff --git a/model/procedures.go b/model/procedures.go
index 1dfc611..a1fb11b 100644
--- a/model/procedures.go
+++ b/model/procedures.go
@@ -1,39 +1,57 @@
package model
import (
+ "apsClient/model/common"
+ "apsClient/pkg/logx"
"apsClient/pkg/sqlitex"
+ "encoding/json"
"fmt"
"gorm.io/gorm"
)
type (
Procedures struct {
- gorm.Model `json:"-"`
- Id int `json:"id"`
- ProcedureId string `json:"orderId"`
- ProcedureName string `json:"product"`
- DeviceId string `json:"deviceId"`
- StartTime string `json:"startTime"`
- EndTime string `json:"endTime"`
- WorkHours string `json:"workHours"`
- InputMaterialsId int `json:"-"`
- InputMaterials *Materials `json:"inputMaterials" gorm:"foreignKey:InputMaterialsId"`
- OutputMaterialsId int `json:"-"`
- OutputMaterials *Materials `json:"outputMaterials" gorm:"foreignKey:InputMaterialsId"`
+ gorm.Model `json:"-"`
+ ID int `gorm:"primarykey"`
+ WorkOrderID string `gorm:"index;type:varchar(191);not null;comment:宸ュ崟ID" json:"-"`
+ OrderID string `gorm:"index;type:varchar(191);not null;comment:璁㈠崟ID" json:"-"`
+ StartTime int64 `gorm:"comment:璁″垝寮�濮嬫椂闂�" json:"startTime"`
+ EndTime int64 `gorm:"comment:璁″垝缁撴潫鏃堕棿" json:"endTime"`
+ Status ProcedureStatus
+ ProcedureData string `json:"-"` //common.ProductProcedure json涓�
+ ProceduresInfo common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure 瀵硅薄
}
ProceduresSearch struct {
Procedures
- Order string
- PageNum int
- PageSize int
- Orm *gorm.DB
- Preload bool
+ Order string
+ PageNum int
+ PageSize int
+ Orm *gorm.DB
+ Preload bool
+ StartTimeMax int64
}
+)
+
+type ProcedureStatus int
+
+const (
+ ProcedureStatusUnFinished ProcedureStatus = 1
+ ProcedureStatusFinished ProcedureStatus = 2
)
func (slf *Procedures) TableName() string {
return "procedures"
+}
+func (slf *Procedures) AfterFind(db *gorm.DB) error {
+ var proceduresInfo common.ProductProcedure
+ err := json.Unmarshal([]byte(slf.ProcedureData), &proceduresInfo)
+ if err != nil {
+ logx.Errorf("AfterFind Unmarshal err: %v", err.Error())
+ return err
+ }
+ slf.ProceduresInfo = proceduresInfo
+ return nil
}
func NewProceduresSearch(db *gorm.DB) *ProceduresSearch {
@@ -58,6 +76,25 @@
return slf
}
+func (slf *ProceduresSearch) SetWorkOrderId(orderId string) *ProceduresSearch {
+ slf.WorkOrderID = orderId
+ return slf
+}
+func (slf *ProceduresSearch) SetStartTimeMax(ts int64) *ProceduresSearch {
+ slf.StartTimeMax = ts
+ return slf
+}
+
+func (slf *ProceduresSearch) SetId(id int) *ProceduresSearch {
+ slf.ID = id
+ return slf
+}
+
+func (slf *ProceduresSearch) SetStatus(status ProcedureStatus) *ProceduresSearch {
+ slf.Status = status
+ return slf
+}
+
func (slf *ProceduresSearch) SetPreload(preload bool) *ProceduresSearch {
slf.Preload = preload
return slf
@@ -69,10 +106,27 @@
if slf.Order != "" {
db = db.Order(slf.Order)
}
+
+ if slf.ID != 0 {
+ db = db.Where("id = ?", slf.ID)
+ }
+
+ if slf.WorkOrderID != "" {
+ db = db.Where("work_order_id = ?", slf.WorkOrderID)
+ }
+
if slf.Preload {
db = db.Preload("InputMaterials").Preload("OutputMaterials")
}
+ if slf.StartTimeMax != 0 {
+ db = db.Where("start_time <= ?", slf.StartTimeMax)
+ }
+
+ if slf.Status != 0 {
+ db = db.Where("status = ?", slf.Status)
+ }
+
return db
}
--
Gitblit v1.8.0