From 3f4f2d033f63296ad7e80415cfe2af41f136bfc0 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期一, 13 十一月 2023 11:18:53 +0800
Subject: [PATCH] 修改文件服务器端口号

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

diff --git a/models/material.go b/models/material.go
index 0b46d57..69c33d0 100644
--- a/models/material.go
+++ b/models/material.go
@@ -67,9 +67,11 @@
 		//HSCode                  string                     `gorm:"type:varchar(255);comment:HS缂栫爜" json:"HSCode"`                    //HS缂栫爜
 		//OriginCountryId         int                        `gorm:"type:int(11);comment:鍘熶骇鍦癷d" json:"originCountryId"`               //鍘熶骇鍦癷d
 		//OriginCountryName       string                     `gorm:"type:varchar(255);comment:鍘熶骇鍦板悕绉�" json:"originCountryName"`        //鍘熶骇鍦板悕绉�
-		InStorageExplain        string `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"`          //鍏ュ簱璇存槑
-		OutStorageExplain       string `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"`         //鍑哄簱璇存槑
-		InternalTransferExplain string `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑
+		InStorageExplain        string        `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"`          //鍏ュ簱璇存槑
+		OutStorageExplain       string        `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"`         //鍑哄簱璇存槑
+		InternalTransferExplain string        `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑
+		AttachmentList          []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"`
+		AttachmentIDs           []uint        `json:"attachmentIDs" gorm:"-"`
 	}
 
 	MaterialSearch struct {
@@ -83,6 +85,7 @@
 		Ids         []string
 		Orm         *gorm.DB
 		CategoryIds []int
+		Preload     bool
 	}
 
 	IdAndName struct {
@@ -174,6 +177,11 @@
 //	return slf
 //}
 
+func (slf *MaterialSearch) SetPreload(preload bool) *MaterialSearch {
+	slf.Preload = preload
+	return slf
+}
+
 func (slf *MaterialSearch) build() *gorm.DB {
 	var db = slf.Orm.Table(slf.TableName())
 
@@ -238,6 +246,10 @@
 	}
 	if len(slf.CategoryIds) > 0 {
 		db = db.Where("category_id in ?", slf.CategoryIds)
+	}
+
+	if slf.Preload {
+		db = db.Preload("AttachmentList")
 	}
 
 	return db
@@ -329,7 +341,7 @@
 		db      = slf.build()
 	)
 
-	if err := db.Count(&total).Error; err != nil {
+	if err := db.Model(&Material{}).Count(&total).Error; err != nil {
 		return records, total, fmt.Errorf("find count err: %v", err)
 	}
 	if slf.PageNum*slf.PageSize > 0 {

--
Gitblit v1.8.0