From 30eaec8c41e167b0d5527dbcc987fba222f31b93 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期五, 25 八月 2023 20:16:27 +0800 Subject: [PATCH] 连接plc5秒超时 --- model/procedures.go | 44 ++++++++++++++++++++++++++------------------ 1 files changed, 26 insertions(+), 18 deletions(-) diff --git a/model/procedures.go b/model/procedures.go index 245f2e4..a1fb11b 100644 --- a/model/procedures.go +++ b/model/procedures.go @@ -1,7 +1,7 @@ package model import ( - "apsClient/model/request" + "apsClient/model/common" "apsClient/pkg/logx" "apsClient/pkg/sqlitex" "encoding/json" @@ -12,11 +12,14 @@ type ( Procedures struct { gorm.Model `json:"-"` - ID int `gorm:"primarykey"` - OrderID string `gorm:"index;type:varchar(191);not null;comment:璁㈠崟ID" json:"-"` - Status ProcedureStatus `json:"-"` - ProcedureData string `json:"-"` //request.ProductProcedure json涓� - ProceduresInfo request.ProductProcedure `json:"procedure" gorm:"-"` //request.ProductProcedure 瀵硅薄 + 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 { @@ -26,7 +29,7 @@ PageSize int Orm *gorm.DB Preload bool - StartTimeMin int64 + StartTimeMax int64 } ) @@ -40,14 +43,15 @@ func (slf *Procedures) TableName() string { return "procedures" } -func (slf *Procedures) AfterFind() { - var proceduresInfo request.ProductProcedure +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 + return err } slf.ProceduresInfo = proceduresInfo + return nil } func NewProceduresSearch(db *gorm.DB) *ProceduresSearch { @@ -72,12 +76,12 @@ return slf } -func (slf *ProceduresSearch) SetOrderId(orderId string) *ProceduresSearch { - slf.OrderID = orderId +func (slf *ProceduresSearch) SetWorkOrderId(orderId string) *ProceduresSearch { + slf.WorkOrderID = orderId return slf } -func (slf *ProceduresSearch) SetStartTimeMin(ts int64) *ProceduresSearch { - slf.StartTimeMin = ts +func (slf *ProceduresSearch) SetStartTimeMax(ts int64) *ProceduresSearch { + slf.StartTimeMax = ts return slf } @@ -103,16 +107,20 @@ db = db.Order(slf.Order) } - if slf.OrderID != "" { - db = db.Where("order_id = ?", slf.OrderID) + 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.StartTimeMin != 0 { - db = db.Where("start_time >= ?", slf.StartTimeMin) + if slf.StartTimeMax != 0 { + db = db.Where("start_time <= ?", slf.StartTimeMax) } if slf.Status != 0 { -- Gitblit v1.8.0