From 115bd9b51f5d8eade4658f844de37516486c60e7 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期六, 18 十一月 2023 17:25:25 +0800
Subject: [PATCH] crm获取aps项目模块信息

---
 model/collectionProjection.go |   48 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/model/collectionProjection.go b/model/collectionProjection.go
index c289864..6275bb2 100644
--- a/model/collectionProjection.go
+++ b/model/collectionProjection.go
@@ -11,18 +11,19 @@
 		SaleChanceId              int     `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"`
 		Creator                   int     `json:"creator" gorm:"column:creator;type:int(11);comment:鍒涘缓浜�"`
 		Modifier                  int     `json:"modifier" gorm:"column:modifier;type:int(11);comment:淇敼浜�"`
-		EstimatedCollectionDate   string  `json:"estimated_collection_date" gorm:"column:estimated_collection_date;type:datetime;comment:棰勮鏀舵鏃ユ湡"`
+		EstimatedCollectionDate   *string `json:"estimated_collection_date" gorm:"column:estimated_collection_date;type:datetime;comment:棰勮鏀舵鏃ユ湡"`
 		EstimatedCollectionAmount float64 `json:"estimated_collection_amount" gorm:"column:estimated_collection_amount;type:decimal(10,2);comment:棰勮鏀舵閲戦"`
-		gorm.Model
+		gormModel
 	}
 
 	CollectionProjectionSearch struct {
 		CollectionProjection
 
-		Orm      *gorm.DB
-		OrderBy  string
-		PageNum  int
-		PageSize int
+		Orm       *gorm.DB
+		SearchMap map[string]interface{}
+		OrderBy   string
+		PageNum   int
+		PageSize  int
 	}
 )
 
@@ -40,6 +41,21 @@
 	var db = slf.Orm.Model(&CollectionProjection{})
 	if slf.Id != 0 {
 		db = db.Where("id = ?", slf.Id)
+	}
+
+	if len(slf.SearchMap) > 0 {
+		for key, value := range slf.SearchMap {
+			switch v := value.(type) {
+			case string:
+				if key == "estimated_collection_date" {
+					db = db.Where(key+" = ?", v)
+				}
+			case int:
+				if key == "client_id" || key == "sale_chance_id" {
+					db = db.Where(key+" = ?", v)
+				}
+			}
+		}
 	}
 
 	return db
@@ -63,10 +79,19 @@
 	return
 }
 
-func (slf *CollectionProjectionSearch) Find() (record CollectionProjection, err error) {
+func (slf *CollectionProjectionSearch) Find() (int64, error, []*CollectionProjection) {
 	var db = slf.build()
-	err = db.First(&record).Error
-	return
+	var records = make([]*CollectionProjection, 0)
+	var total int64
+	if err := db.Count(&total).Error; err != nil {
+		return total, err, records
+	}
+	if slf.PageNum > 0 && slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+
+	err := db.Find(&records).Error
+	return total, err, records
 }
 
 func (slf *CollectionProjectionSearch) SetID(id int) *CollectionProjectionSearch {
@@ -83,3 +108,8 @@
 	slf.PageNum, slf.PageSize = page, size
 	return slf
 }
+
+func (slf *CollectionProjectionSearch) SetSearchMap(data map[string]interface{}) *CollectionProjectionSearch {
+	slf.SearchMap = data
+	return slf
+}

--
Gitblit v1.8.0