From 50d488d3df805ccb4ab7984a40ff74bda9b21a40 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 28 十一月 2023 09:57:42 +0800
Subject: [PATCH] 报工保存生产进度
---
model/procedures.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/model/procedures.go b/model/procedures.go
index 4c93059..d30f5a9 100644
--- a/model/procedures.go
+++ b/model/procedures.go
@@ -12,14 +12,17 @@
type (
Procedures struct {
gorm.Model
- WorkOrderID string `gorm:"index;type:varchar(191);not null" json:"-"`
- OrderID string `gorm:"index;type:varchar(191);not null" json:"-"`
+ ProductProcedureID string `gorm:"index;type:varchar(191);" json:"productProcedureID"` //浜у搧宸ュ簭id
+ WorkOrderID string `gorm:"index;type:varchar(191);" json:"-"`
+ OrderID string `gorm:"index;type:varchar(191);" json:"-"`
DeviceID string `gorm:"index;type:varchar(191)" json:"deviceId"`
ProcedureID string `gorm:"index;type:varchar(191)" json:"procedureId"`
Channel int32 `gorm:"index;" json:"channel"` //閫氶亾
ProcessModelNumber string `gorm:"index;" json:"processModelNumber"` //宸ヨ壓妯″瀷缂栧彿
StartTime int64 `json:"startTime"`
EndTime int64 `json:"endTime"`
+ RealStartTime int64 `json:"realStartTime"`
+ RealEndTime int64 `json:"realEndTime"`
Status ProcedureStatus
ProcedureData string `json:"-"` //common.ProductProcedure json涓�
ProceduresInfo common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure 瀵硅薄
@@ -32,11 +35,15 @@
PageSize int
Orm *gorm.DB
Preload bool
+ StartTimeMin int64
StartTimeMax int64
EndTimeMin int64
+ EndTimeMax int64
StatusNot ProcedureStatus
ProcedureIds []string
Channels []int32
+ Offset int
+ Limit int
}
)
@@ -79,6 +86,11 @@
return slf
}
+func (slf *ProceduresSearch) SetOffset(offset, limit int) *ProceduresSearch {
+ slf.Offset, slf.Limit = offset, limit
+ return slf
+}
+
func (slf *ProceduresSearch) SetOrder(order string) *ProceduresSearch {
slf.Order = order
return slf
@@ -94,6 +106,11 @@
return slf
}
+func (slf *ProceduresSearch) SetStartTimeMin(ts int64) *ProceduresSearch {
+ slf.StartTimeMin = ts
+ return slf
+}
+
func (slf *ProceduresSearch) SetStartTimeMax(ts int64) *ProceduresSearch {
slf.StartTimeMax = ts
return slf
@@ -101,6 +118,11 @@
func (slf *ProceduresSearch) SetEndTimeMin(ts int64) *ProceduresSearch {
slf.EndTimeMin = ts
+ return slf
+}
+
+func (slf *ProceduresSearch) SetEndTimeMax(ts int64) *ProceduresSearch {
+ slf.EndTimeMax = ts
return slf
}
@@ -139,6 +161,11 @@
return slf
}
+func (slf *ProceduresSearch) SetChannel(channel int32) *ProceduresSearch {
+ slf.Channel = channel
+ return slf
+}
+
func (slf *ProceduresSearch) build() *gorm.DB {
var db = slf.Orm.Model(&Procedures{})
@@ -166,8 +193,16 @@
db = db.Where("start_time <= ?", slf.StartTimeMax)
}
+ if slf.StartTimeMin != 0 {
+ db = db.Where("start_time >= ?", slf.StartTimeMin)
+ }
+
if slf.EndTimeMin != 0 {
db = db.Where("end_time > ?", slf.EndTimeMin)
+ }
+
+ if slf.EndTimeMax != 0 {
+ db = db.Where("end_time < ?", slf.EndTimeMax)
}
if slf.Status != 0 {
@@ -207,11 +242,11 @@
// CreateBatch 鎵归噺鎻掑叆
func (slf *ProceduresSearch) CreateBatch(records []*Procedures) error {
var db = slf.build()
-
- if err := db.Create(&records).Error; err != nil {
- return fmt.Errorf("create batch err: %v, records: %+v", err, records)
+ for _, record := range records {
+ if err := db.Create(record).Error; err != nil {
+ return fmt.Errorf("create batch err: %v, records: %+v", err, records)
+ }
}
-
return nil
}
@@ -301,6 +336,11 @@
if slf.PageNum*slf.PageSize > 0 {
db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
}
+
+ if slf.Limit > 0 {
+ db = db.Offset(slf.Offset).Limit(slf.Limit)
+ }
+
if err := db.Find(&records).Error; err != nil {
return records, total, fmt.Errorf("find records err: %v", err)
}
--
Gitblit v1.8.0