From 5208dce1708d415b39f4caffa5f23c83a7070199 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期四, 18 四月 2024 14:44:30 +0800
Subject: [PATCH] 修改字段类型

---
 models/material.go |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/models/material.go b/models/material.go
index 5c03da9..b14fcba 100644
--- a/models/material.go
+++ b/models/material.go
@@ -109,6 +109,7 @@
 		Orm         *gorm.DB
 		CategoryIds []int
 		Preload     bool
+		Fields      string
 	}
 
 	IdAndName struct {
@@ -258,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())
 
@@ -322,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 {
@@ -592,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
@@ -611,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