From fe9a8f47ea30dbd9637c803563abd74bda46900a Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 06 五月 2024 17:24:11 +0800
Subject: [PATCH] 每月1号执行
---
models/material.go | 47 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/models/material.go b/models/material.go
index 0cb7165..fe9e42a 100644
--- a/models/material.go
+++ b/models/material.go
@@ -1,6 +1,7 @@
package models
import (
+ "encoding/json"
"fmt"
"github.com/shopspring/decimal"
"github.com/spf13/cast"
@@ -78,8 +79,9 @@
IsStorage int `gorm:"type:tinyint(1);default:1;comment:鏄惁瀛樺簱(1鏄�2鍚�)" json:"isStorage"` //鏃犲簱瀛樼殑鍦╳ms浠ュ強srm涓渶瑕佽繃婊ゆ帀
IsVirtual int `json:"isVirtual" gorm:"type:tinyint(1);default:2;comment:鏄惁铏氭嫙鐗╂枡(1鏄�2鍚�)"` //铏氭嫙鐗╂枡鍦∕RP璁$畻鏃惰烦杩囪灞傜骇鐩存帴棰嗙敤涓嬬骇鐗╂枡锛岃櫄鎷熺墿鏂欎笉鐢熸垚宸ュ崟
ReorderRuleNum int64 `json:"reorderRuleNum"`
- MoreUnit bool `json:"moreUnit" gorm:"type:tinyint(1);default:false;comment:鍚姩澶氬崟浣�"`
- MoreUnitValue string `json:"moreUnitValue" gorm:"type:varchar(255);comment:澶氬崟浣嶅��"`
+ MoreUnit *bool `json:"moreUnit" gorm:"type:tinyint(1);default:false;comment:鍚姩澶氬崟浣�"`
+ MoreUnitList []UnitItems `json:"moreUnitList" gorm:"-"`
+ MoreUnitValue string `json:"-" gorm:"type:varchar(255);comment:澶氬崟浣嶅��"`
GrossWeight decimal.Decimal `json:"grossWeight" gorm:"type:decimal(20,3);comment:姣涢噸"`
NetWeight decimal.Decimal `json:"netWeight" gorm:"type:decimal(20,3);comment:鍑�閲�"`
GrossUnit string `json:"grossUnit" gorm:"type:varchar(255);comment:姣涢噸鍗曚綅"`
@@ -107,11 +109,18 @@
Orm *gorm.DB
CategoryIds []int
Preload bool
+ Fields string
}
IdAndName struct {
Id string `json:"id"`
Name string `json:"name"`
+ }
+
+ UnitItems struct {
+ Amount decimal.Decimal `json:"amount"`
+ Unit string `json:"unit"`
+ Floating bool `json:"floating"`
}
)
@@ -128,6 +137,14 @@
} else if slf.PurchaseType != 0 { //鍏煎鏃ф暟鎹�
slf.PurchaseTypeList = append(slf.PurchaseTypeList, int(slf.PurchaseType))
}
+ if slf.MoreUnitValue != "" {
+ var arr []UnitItems
+ err := json.Unmarshal([]byte(slf.MoreUnitValue), &arr)
+ if err != nil {
+ return err
+ }
+ slf.MoreUnitList = arr
+ }
return
}
@@ -143,6 +160,13 @@
if len(slf.PurchaseTypeList) == 1 {
slf.PurchaseType = constvar.PurchaseType(slf.PurchaseTypeList[0])
}
+ }
+ if len(slf.MoreUnitList) != 0 {
+ str, err := json.Marshal(slf.MoreUnitList)
+ if err != nil {
+ return err
+ }
+ slf.MoreUnitValue = string(str)
}
return
}
@@ -235,6 +259,11 @@
return slf
}
+func (slf *MaterialSearch) SetFields(fields string) *MaterialSearch {
+ slf.Fields = fields
+ return slf
+}
+
func (slf *MaterialSearch) build() *gorm.DB {
var db = slf.Orm.Table(slf.TableName())
@@ -299,6 +328,10 @@
}
if len(slf.CategoryIds) > 0 {
db = db.Where("category_id in ?", slf.CategoryIds)
+ }
+
+ if slf.Fields != "" {
+ db = db.Select(slf.Fields)
}
if slf.Preload {
@@ -569,7 +602,7 @@
OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"`
ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"`
ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"`
- CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"`
+ CompanyID string `json:"companyID"` //鍏徃ID-瀹㈡埛
CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"`
Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"`
ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id
@@ -588,3 +621,11 @@
return nil
}
+
+func MaterialMap(records []*Material) (m map[string]*Material) {
+ m = make(map[string]*Material, len(records))
+ for _, record := range records {
+ m[record.ID] = record
+ }
+ return m
+}
--
Gitblit v1.8.0