From 090680391d6c9d51e31d30319ab6d35cc937aaf3 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 09 八月 2023 14:42:26 +0800
Subject: [PATCH] 服务合同列表增加关联内容返回

---
 model/serviceContract.go   |   75 ++++---
 api/v1/serviceContract.go  |  352 +++++++++++++++++++-------------------
 docs/swagger.yaml          |   16 +
 docs/docs.go               |   23 ++
 service/serviceContract.go |    6 
 docs/swagger.json          |   23 ++
 6 files changed, 273 insertions(+), 222 deletions(-)

diff --git a/api/v1/serviceContract.go b/api/v1/serviceContract.go
index 38b78f2..7ab6147 100644
--- a/api/v1/serviceContract.go
+++ b/api/v1/serviceContract.go
@@ -1,176 +1,176 @@
-package v1
-
-import (
-	"aps_crm/model"
-	"aps_crm/model/request"
-	"aps_crm/model/response"
-	"aps_crm/pkg/contextx"
-	"aps_crm/pkg/ecode"
-	"github.com/gin-gonic/gin"
-)
-
-type ServiceContractApi struct{}
-
-// Add
-//
-//	@Tags		ServiceContract
-//	@Summary	娣诲姞鏈嶅姟鍚堝悓
-//	@Produce	application/json
-//	@Param		object	body		request.AddServiceContract	true	"鏌ヨ鍙傛暟"
-//	@Success	200		{object}	contextx.Response{}
-//	@Router		/api/serviceContract/add [post]
-func (s *ServiceContractApi) Add(c *gin.Context) {
-	var params request.AddServiceContract
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	errCode, serviceContract := checkServiceContractParams(params.ServiceContract)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	errCode = serviceContractService.AddServiceContract(&serviceContract)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.Ok()
-}
-
-// Delete
-//
-//	@Tags		ServiceContract
-//	@Summary	鍒犻櫎鏈嶅姟鍚堝悓
-//	@Produce	application/json
-//	@Param		object	body		request.DeleteserviceContract true	"鏌ヨ鍙傛暟"
-//	@Success	200	{object}	contextx.Response{}
-//	@Router		/api/serviceContract/delete [delete]
-func (s *ServiceContractApi) Delete(c *gin.Context) {
-	var params request.DeleteserviceContract
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	errCode := serviceContractService.DeleteServiceContract(params.Ids)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.Ok()
-}
-
-// Update
-//
-//	@Tags		ServiceContract
-//	@Summary	鏇存柊鏈嶅姟鍚堝悓
-//	@Produce	application/json
-//	@Param		object	body		request.UpdateServiceContract	true	"鏌ヨ鍙傛暟"
-//	@Success	200		{object}	contextx.Response{}
-//	@Router		/api/serviceContract/update [put]
-func (s *ServiceContractApi) Update(c *gin.Context) {
-	var params request.UpdateServiceContract
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	errCode, serviceContract := checkServiceContractParams(params.ServiceContract)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	serviceContract.Id = params.Id
-
-	errCode = serviceContractService.UpdateServiceContract(&serviceContract)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.Ok()
-}
-
-// check params
-func checkServiceContractParams(serviceContract request.ServiceContract) (errCode int, result model.ServiceContract) {
-	//if serviceContract.SignTime == "" {
-	//	return ecode.InvalidParams, result
-	//}
-	//
-	//if serviceContract.Number == "" {
-	//	return ecode.InvalidParams, result
-	//}
-	//
-	//if serviceContract.MemberId <= 0 {
-	//	return ecode.InvalidParams, result
-	//}
-
-	t, err := checkTimeFormat(serviceContract.SignTime)
-	if err != nil {
-		return ecode.InvalidParams, result
-	}
-
-	result.SignTime = t
-
-	t, err = checkTimeFormat(serviceContract.StartTime)
-	if err != nil {
-		return ecode.InvalidParams, result
-	}
-
-	result.StartTime = t
-
-	t, err = checkTimeFormat(serviceContract.EndTime)
-	if err != nil {
-		return ecode.InvalidParams, result
-	}
-
-	result.EndTime = t
-
-	result.Number = serviceContract.Number
-	result.MemberId = serviceContract.MemberId
-	result.Remark = serviceContract.Remark
-	result.ClientId = serviceContract.ClientId
-	result.ContactId = serviceContract.ContactId
-	result.SaleChanceId = serviceContract.SaleChanceId
-	result.QuotationId = serviceContract.QuotationId
-	result.ServiceContractTypeId = serviceContract.TypeId
-	result.ServiceContractStatusId = serviceContract.StatusId
-	result.ServiceTimes = serviceContract.ServiceTimes
-	result.Terms = serviceContract.Terms
-	result.Products = serviceContract.Products
-
-	return ecode.OK, result
-}
-
-// List
-//
-// @Tags		ServiceContract
-// @Summary	鐢熸垚璁″垝鍒楄〃
-// @Produce	application/json
-// @Param		object	body		request.GetServiceContractList	true	"鍙傛暟"
-// @Success	200		{object}	contextx.Response{data=response.ServiceContractsResponse}
-// @Router		/api/serviceContract/list [post]
-func (con *ServiceContractApi) List(c *gin.Context) {
-	var params request.GetServiceContractList
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.OkWithDetailed(response.ServiceContractsResponse{
-		List:  serviceContracts,
-		Count: int(total),
-	})
-}
+package v1
+
+import (
+	"aps_crm/model"
+	"aps_crm/model/request"
+	"aps_crm/model/response"
+	"aps_crm/pkg/contextx"
+	"aps_crm/pkg/ecode"
+	"github.com/gin-gonic/gin"
+)
+
+type ServiceContractApi struct{}
+
+// Add
+//
+//	@Tags		ServiceContract
+//	@Summary	娣诲姞鏈嶅姟鍚堝悓
+//	@Produce	application/json
+//	@Param		object	body		request.AddServiceContract	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/serviceContract/add [post]
+func (s *ServiceContractApi) Add(c *gin.Context) {
+	var params request.AddServiceContract
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode, serviceContract := checkServiceContractParams(params.ServiceContract)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	errCode = serviceContractService.AddServiceContract(&serviceContract)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Delete
+//
+//	@Tags		ServiceContract
+//	@Summary	鍒犻櫎鏈嶅姟鍚堝悓
+//	@Produce	application/json
+//	@Param		object	body		request.DeleteserviceContract true	"鏌ヨ鍙傛暟"
+//	@Success	200	{object}	contextx.Response{}
+//	@Router		/api/serviceContract/delete [delete]
+func (s *ServiceContractApi) Delete(c *gin.Context) {
+	var params request.DeleteserviceContract
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode := serviceContractService.DeleteServiceContract(params.Ids)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Update
+//
+//	@Tags		ServiceContract
+//	@Summary	鏇存柊鏈嶅姟鍚堝悓
+//	@Produce	application/json
+//	@Param		object	body		request.UpdateServiceContract	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/serviceContract/update [put]
+func (s *ServiceContractApi) Update(c *gin.Context) {
+	var params request.UpdateServiceContract
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode, serviceContract := checkServiceContractParams(params.ServiceContract)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	serviceContract.Id = params.Id
+
+	errCode = serviceContractService.UpdateServiceContract(&serviceContract)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// check params
+func checkServiceContractParams(serviceContract request.ServiceContract) (errCode int, result model.ServiceContract) {
+	//if serviceContract.SignTime == "" {
+	//	return ecode.InvalidParams, result
+	//}
+	//
+	//if serviceContract.Number == "" {
+	//	return ecode.InvalidParams, result
+	//}
+	//
+	//if serviceContract.MemberId <= 0 {
+	//	return ecode.InvalidParams, result
+	//}
+
+	t, err := checkTimeFormat(serviceContract.SignTime)
+	if err != nil {
+		return ecode.InvalidParams, result
+	}
+
+	result.SignTime = t
+
+	t, err = checkTimeFormat(serviceContract.StartTime)
+	if err != nil {
+		return ecode.InvalidParams, result
+	}
+
+	result.StartTime = t
+
+	t, err = checkTimeFormat(serviceContract.EndTime)
+	if err != nil {
+		return ecode.InvalidParams, result
+	}
+
+	result.EndTime = t
+
+	result.Number = serviceContract.Number
+	result.MemberId = serviceContract.MemberId
+	result.Remark = serviceContract.Remark
+	result.ClientId = serviceContract.ClientId
+	result.ContactId = serviceContract.ContactId
+	result.SaleChanceId = serviceContract.SaleChanceId
+	result.QuotationId = serviceContract.QuotationId
+	result.ServiceContractTypeId = serviceContract.TypeId
+	result.ServiceContractStatusId = serviceContract.StatusId
+	result.ServiceTimes = serviceContract.ServiceTimes
+	result.Terms = serviceContract.Terms
+	result.Products = serviceContract.Products
+
+	return ecode.OK, result
+}
+
+// List
+//
+// @Tags   ServiceContract
+// @Summary	鏈嶅姟鍚堝悓鍒楄〃
+// @Produce	application/json
+// @Param		object	body		request.GetServiceContractList	true	"鍙傛暟"
+// @Success	200		{object}	contextx.Response{data=response.ServiceContractsResponse}
+// @Router		/api/serviceContract/list [post]
+func (con *ServiceContractApi) List(c *gin.Context) {
+	var params request.GetServiceContractList
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	serviceContracts, total, errCode := serviceContractService.GetServiceContractList(params.Page, params.PageSize, params.QueryClass, params.KeywordType, params.Keyword)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.OkWithDetailed(response.ServiceContractsResponse{
+		List:  serviceContracts,
+		Count: int(total),
+	})
+}
diff --git a/docs/docs.go b/docs/docs.go
index 9be43ac..cce75ae 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -7642,7 +7642,7 @@
                 "tags": [
                     "ServiceContract"
                 ],
-                "summary": "鐢熸垚璁″垝鍒楄〃",
+                "summary": "鏈嶅姟鍚堝悓鍒楄〃",
                 "parameters": [
                     {
                         "description": "鍙傛暟",
@@ -11366,6 +11366,9 @@
         "model.ServiceContract": {
             "type": "object",
             "properties": {
+                "SaleChance": {
+                    "$ref": "#/definitions/model.SaleChance"
+                },
                 "amountInvoiced": {
                     "description": "宸插紑绁ㄩ噾棰�",
                     "type": "number"
@@ -11382,9 +11385,6 @@
                     "type": "integer"
                 },
                 "contactId": {
-                    "type": "integer"
-                },
-                "contractId": {
                     "type": "integer"
                 },
                 "endTime": {
@@ -11405,6 +11405,9 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotation": {
+                    "$ref": "#/definitions/model.Quotation"
+                },
                 "quotationId": {
                     "type": "integer"
                 },
@@ -11414,9 +11417,21 @@
                 "saleChanceId": {
                     "type": "integer"
                 },
+                "salesDetails": {
+                    "$ref": "#/definitions/model.SalesDetails"
+                },
+                "salesDetailsId": {
+                    "type": "integer"
+                },
+                "serviceContractStatus": {
+                    "$ref": "#/definitions/model.ServiceContractStatus"
+                },
                 "serviceContractStatusId": {
                     "type": "integer"
                 },
+                "serviceContractType": {
+                    "$ref": "#/definitions/model.ServiceContractType"
+                },
                 "serviceContractTypeId": {
                     "type": "integer"
                 },
diff --git a/docs/swagger.json b/docs/swagger.json
index ab6def1..fc4f0c6 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -7630,7 +7630,7 @@
                 "tags": [
                     "ServiceContract"
                 ],
-                "summary": "鐢熸垚璁″垝鍒楄〃",
+                "summary": "鏈嶅姟鍚堝悓鍒楄〃",
                 "parameters": [
                     {
                         "description": "鍙傛暟",
@@ -11354,6 +11354,9 @@
         "model.ServiceContract": {
             "type": "object",
             "properties": {
+                "SaleChance": {
+                    "$ref": "#/definitions/model.SaleChance"
+                },
                 "amountInvoiced": {
                     "description": "宸插紑绁ㄩ噾棰�",
                     "type": "number"
@@ -11370,9 +11373,6 @@
                     "type": "integer"
                 },
                 "contactId": {
-                    "type": "integer"
-                },
-                "contractId": {
                     "type": "integer"
                 },
                 "endTime": {
@@ -11393,6 +11393,9 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotation": {
+                    "$ref": "#/definitions/model.Quotation"
+                },
                 "quotationId": {
                     "type": "integer"
                 },
@@ -11402,9 +11405,21 @@
                 "saleChanceId": {
                     "type": "integer"
                 },
+                "salesDetails": {
+                    "$ref": "#/definitions/model.SalesDetails"
+                },
+                "salesDetailsId": {
+                    "type": "integer"
+                },
+                "serviceContractStatus": {
+                    "$ref": "#/definitions/model.ServiceContractStatus"
+                },
                 "serviceContractStatusId": {
                     "type": "integer"
                 },
+                "serviceContractType": {
+                    "$ref": "#/definitions/model.ServiceContractType"
+                },
                 "serviceContractTypeId": {
                     "type": "integer"
                 },
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 9c4a623..fcc473d 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1271,6 +1271,8 @@
     type: object
   model.ServiceContract:
     properties:
+      SaleChance:
+        $ref: '#/definitions/model.SaleChance'
       amountInvoiced:
         description: 宸插紑绁ㄩ噾棰�
         type: number
@@ -1284,8 +1286,6 @@
         type: integer
       contactId:
         type: integer
-      contractId:
-        type: integer
       endTime:
         type: string
       id:
@@ -1298,14 +1298,24 @@
         items:
           $ref: '#/definitions/model.Product'
         type: array
+      quotation:
+        $ref: '#/definitions/model.Quotation'
       quotationId:
         type: integer
       remark:
         type: string
       saleChanceId:
         type: integer
+      salesDetails:
+        $ref: '#/definitions/model.SalesDetails'
+      salesDetailsId:
+        type: integer
+      serviceContractStatus:
+        $ref: '#/definitions/model.ServiceContractStatus'
       serviceContractStatusId:
         type: integer
+      serviceContractType:
+        $ref: '#/definitions/model.ServiceContractType'
       serviceContractTypeId:
         type: integer
       serviceTimes:
@@ -10002,7 +10012,7 @@
                 data:
                   $ref: '#/definitions/response.ServiceContractsResponse'
               type: object
-      summary: 鐢熸垚璁″垝鍒楄〃
+      summary: 鏈嶅姟鍚堝悓鍒楄〃
       tags:
       - ServiceContract
   /api/serviceContract/update:
diff --git a/model/serviceContract.go b/model/serviceContract.go
index 5c5a497..ef16fbe 100644
--- a/model/serviceContract.go
+++ b/model/serviceContract.go
@@ -11,26 +11,31 @@
 
 type (
 	ServiceContract struct {
-		Id                      int             `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		ClientId                int             `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
-		Number                  string          `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"`
-		MemberId                int             `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
-		ContactId               int             `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
-		SaleChanceId            int             `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
-		ContractId              int             `json:"contractId" gorm:"column:contract_id;type:int;comment:鍚堝悓id"`
-		QuotationId             int             `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
-		ServiceContractTypeId   int             `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:鍚堝悓绫诲瀷id"`
-		SignTime                time.Time       `json:"signTime" gorm:"column:sign_time;type:datetime;comment:绛剧害鏃堕棿"`
-		StartTime               time.Time       `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"`
-		EndTime                 time.Time       `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"`
-		ServiceContractStatusId int             `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:鍚堝悓鐘舵�乮d"`
-		ServiceTimes            int             `json:"serviceTimes" gorm:"column:service_times;type:int;comment:鏈嶅姟娆℃暟"`
-		Terms                   string          `json:"terms" gorm:"column:terms;type:text;comment:鏉℃"`
-		Remark                  string          `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
-		AmountReceivable        decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 搴旀敹閲戦
-		AmountReceived          decimal.Decimal `gorm:"amount_received" json:"amountReceived"`     // 宸叉敹閲戦
-		AmountInvoiced          decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"`     // 宸插紑绁ㄩ噾棰�
-		Products                []Product       `json:"products" gorm:"many2many:serviceContract_product;"`
+		Id                      int                   `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		ClientId                int                   `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+		Number                  string                `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"`
+		MemberId                int                   `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+		ContactId               int                   `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
+		SaleChanceId            int                   `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
+		SaleChance              SaleChance            `json:"SaleChance" gorm:"foreignKey:SaleChanceId"`
+		SalesDetailsId          int                   `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:鍚堝悓璁㈠崟id"`
+		SalesDetails            SalesDetails          `json:"salesDetails" gorm:"foreignKey:SalesDetailsId"`
+		QuotationId             int                   `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
+		Quotation               Quotation             `json:"quotation" gorm:"foreignKey:QuotationId"`
+		ServiceContractTypeId   int                   `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:鍚堝悓绫诲瀷id"`
+		ServiceContractType     ServiceContractType   `json:"serviceContractType" gorm:"foreignKey:ServiceContractTypeId"`
+		SignTime                time.Time             `json:"signTime" gorm:"column:sign_time;type:datetime;comment:绛剧害鏃堕棿"`
+		StartTime               time.Time             `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"`
+		EndTime                 time.Time             `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"`
+		ServiceContractStatusId int                   `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:鍚堝悓鐘舵�乮d"`
+		ServiceContractStatus   ServiceContractStatus `json:"serviceContractStatus" gorm:"foreignKey:ServiceContractStatusId"`
+		ServiceTimes            int                   `json:"serviceTimes" gorm:"column:service_times;type:int;comment:鏈嶅姟娆℃暟"`
+		Terms                   string                `json:"terms" gorm:"column:terms;type:text;comment:鏉℃"`
+		Remark                  string                `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
+		AmountReceivable        decimal.Decimal       `gorm:"amount_receivable" json:"amountReceivable"` // 搴旀敹閲戦
+		AmountReceived          decimal.Decimal       `gorm:"amount_received" json:"amountReceived"`     // 宸叉敹閲戦
+		AmountInvoiced          decimal.Decimal       `gorm:"amount_invoiced" json:"amountInvoiced"`     // 宸插紑绁ㄩ噾棰�
+		Products                []Product             `json:"products" gorm:"many2many:service_contract_product;"`
 		gorm.Model              `json:"-"`
 	}
 
@@ -44,6 +49,7 @@
 		OrderBy     string
 		PageNum     int
 		PageSize    int
+		Preload     bool
 	}
 )
 
@@ -97,6 +103,15 @@
 		//todo
 
 	}
+	if slf.Preload {
+		db = db.
+			Preload("SaleChance").
+			Preload("SalesDetails").
+			Preload("Quotation").
+			Preload("ServiceContractType").
+			Preload("ServiceContractStatus").
+			Preload("Products")
+	}
 
 	return db
 }
@@ -116,14 +131,7 @@
 	return db.Delete(&ServiceContract{}).Error
 }
 
-func (slf *ServiceContractSearch) Find() (*ServiceContract, error) {
-	var db = slf.build()
-	var record = &ServiceContract{}
-	err := db.First(record).Error
-	return record, err
-}
-
-func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, int64, error) {
+func (slf *ServiceContractSearch) Find() ([]*ServiceContract, int64, error) {
 	var db = slf.build()
 	var records = make([]*ServiceContract, 0)
 	var total int64
@@ -134,11 +142,7 @@
 		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
 	}
 
-	if slf.PageNum > 0 && slf.PageSize > 0 {
-		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
-	}
-
-	err := db.Preload("Products").Find(&records).Error
+	err := db.Find(&records).Error
 	return records, total, err
 }
 
@@ -176,6 +180,11 @@
 	return slf
 }
 
+func (slf *ServiceContractSearch) SetPreload(preload bool) *ServiceContractSearch {
+	slf.Preload = preload
+	return slf
+}
+
 func (slf *ServiceContractSearch) UpdateByMap(upMap map[string]interface{}) error {
 	var (
 		db = slf.build()
diff --git a/service/serviceContract.go b/service/serviceContract.go
index 45907c8..664382f 100644
--- a/service/serviceContract.go
+++ b/service/serviceContract.go
@@ -19,7 +19,7 @@
 
 func (SContractService) UpdateServiceContract(serviceContract *model.ServiceContract) int {
 	// check serviceContract exist
-	_, err := model.NewServiceContractSearch().SetId(serviceContract.Id).Find()
+	_, err := model.NewServiceContractSearch().SetId(serviceContract.Id).First()
 	if err != nil {
 		return ecode.SContractNotExist
 	}
@@ -56,7 +56,9 @@
 		SetKeyword(keyword).
 		SetKeywordType(keywordType).
 		SetQueryClass(queryClass).
-		SetPage(page, pageSize).FindAll()
+		SetPage(page, pageSize).
+		SetPreload(true).
+		Find()
 	if err != nil {
 		return nil, 0, ecode.SContractListErr
 	}

--
Gitblit v1.8.0