From 2b3b678a0e0156e68415aa287fdf85d05583a5b4 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期四, 21 九月 2023 15:10:08 +0800
Subject: [PATCH] 1.修改出入库列表显示异常的问题

---
 controllers/operation.go    |   18 +++---
 models/location.go          |   30 +++++-----
 models/operation.go         |   28 ++++----
 docs/swagger.yaml           |    9 +--
 request/operation.go        |    4 
 docs/docs.go                |   12 ---
 models/operation_details.go |   15 ++--
 docs/swagger.json           |   12 ---
 router/router.go            |    2 
 9 files changed, 55 insertions(+), 75 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 97ba0fd..f340d6c 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -65,9 +65,9 @@
 		if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeVendor)).First(); err != nil {
 			return err
 		} else {
-			params.FromLocationId = location.Id
+			params.FromLocationID = location.Id
 		}
-		if params.ToLocationId == 0 {
+		if params.ToLocationID == 0 {
 			return errors.New("璇烽�夋嫨鐩爣浣嶇疆")
 		}
 	}
@@ -75,17 +75,17 @@
 		if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeCustomer)).First(); err != nil {
 			return err
 		} else {
-			params.ToLocationId = location.Id
+			params.ToLocationID = location.Id
 		}
-		if params.FromLocationId == 0 {
+		if params.FromLocationID == 0 {
 			return errors.New("璇烽�夋嫨婧愪綅缃�")
 		}
 	}
 	if operationType.BaseOperationType == constvar.BaseOperationTypeInternal {
-		if params.ToLocationId == 0 {
+		if params.ToLocationID == 0 {
 			return errors.New("璇烽�夋嫨鐩爣浣嶇疆")
 		}
-		if params.FromLocationId == 0 {
+		if params.FromLocationID == 0 {
 			return errors.New("璇烽�夋嫨婧愪綅缃�")
 		}
 	}
@@ -117,7 +117,7 @@
 		if v.ProductName == "" {
 			return errors.New("浜у搧鍚嶇О寮傚父")
 		}
-		if v.Quantity.IsNegative() {
+		if v.Amount.IsNegative() {
 			return errors.New("浜у搧鏁伴噺鍑洪敊")
 		}
 	}
@@ -172,7 +172,7 @@
 // @Param     object  body request.UpdateOperation true  "鍏ュ簱淇℃伅"
 // @Param     id  path int true  "鍏ュ簱淇℃伅id"
 // @Success   200 {object} util.Response "鎴愬姛"
-// @Router    /api-wms/v1/operation/operation/{id} [post]
+// @Router    /api-wms/v1/operation/operation/{id} [put]
 func (slf OperationController) Update(c *gin.Context) {
 	id := cast.ToUint(c.Param("id"))
 	if id == 0 {
@@ -315,7 +315,7 @@
 			}
 			for _, v := range listDetails {
 				listProdtId = append(listProdtId, v.ProductId)
-				mapProdt[v.ProductId] = v.Quantity
+				mapProdt[v.ProductId] = v.Amount
 			}
 			if err := models.NewMaterialSearch().Orm.Where("id IN ?", listProdtId).Find(&listProdt).Error; err != nil {
 				return err
diff --git a/docs/docs.go b/docs/docs.go
index bc7b478..0e06838 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -565,7 +565,7 @@
             }
         },
         "/api-wms/v1/operation/operation/{id}": {
-            "post": {
+            "put": {
                 "produces": [
                     "application/json"
                 ],
@@ -1584,14 +1584,6 @@
         "models.Location": {
             "type": "object",
             "properties": {
-                "company": {
-                    "description": "鍏徃",
-                    "allOf": [
-                        {
-                            "$ref": "#/definitions/models.Company"
-                        }
-                    ]
-                },
                 "companyId": {
                     "description": "鍏徃id",
                     "type": "integer"
@@ -1635,7 +1627,7 @@
                     "type": "boolean"
                 },
                 "type": {
-                    "description": "浣嶇疆绫诲瀷",
+                    "description": "Company              Company                       ` + "`" + `json:\"company\" gorm:\"foreignKey:CompanyId\"` + "`" + `                       //鍏徃",
                     "allOf": [
                         {
                             "$ref": "#/definitions/constvar.LocationType"
diff --git a/docs/swagger.json b/docs/swagger.json
index 281bd04..e4afa48 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -553,7 +553,7 @@
             }
         },
         "/api-wms/v1/operation/operation/{id}": {
-            "post": {
+            "put": {
                 "produces": [
                     "application/json"
                 ],
@@ -1572,14 +1572,6 @@
         "models.Location": {
             "type": "object",
             "properties": {
-                "company": {
-                    "description": "鍏徃",
-                    "allOf": [
-                        {
-                            "$ref": "#/definitions/models.Company"
-                        }
-                    ]
-                },
                 "companyId": {
                     "description": "鍏徃id",
                     "type": "integer"
@@ -1623,7 +1615,7 @@
                     "type": "boolean"
                 },
                 "type": {
-                    "description": "浣嶇疆绫诲瀷",
+                    "description": "Company              Company                       `json:\"company\" gorm:\"foreignKey:CompanyId\"`                       //鍏徃",
                     "allOf": [
                         {
                             "$ref": "#/definitions/constvar.LocationType"
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 024ec46..34d9940 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -221,10 +221,6 @@
     type: object
   models.Location:
     properties:
-      company:
-        allOf:
-        - $ref: '#/definitions/models.Company'
-        description: 鍏徃
       companyId:
         description: 鍏徃id
         type: integer
@@ -257,7 +253,8 @@
       type:
         allOf:
         - $ref: '#/definitions/constvar.LocationType'
-        description: 浣嶇疆绫诲瀷
+        description: Company              Company                       `json:"company"
+          gorm:"foreignKey:CompanyId"`                       //鍏徃
       updateTime:
         type: string
     type: object
@@ -1247,7 +1244,7 @@
       summary: 鍒犻櫎鍏ュ簱/鍑哄簱淇℃伅
       tags:
       - 鍏ュ簱/鍑哄簱
-    post:
+    put:
       parameters:
       - description: 鍏ュ簱淇℃伅
         in: body
diff --git a/models/location.go b/models/location.go
index 4c0338c..19e592b 100644
--- a/models/location.go
+++ b/models/location.go
@@ -11,17 +11,17 @@
 	// Location 浣嶇疆
 	Location struct {
 		WmsModel
-		Id                   int                           `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		Name                 string                        `json:"name" gorm:"index;type:varchar(255);not null;comment:浣嶇疆鍚嶇О"` //浣嶇疆鍚嶇О
-		ParentId             string                        `json:"parentId" gorm:"type:varchar(255)"`                         //涓婄骇id
-		CompanyId            int                           `json:"companyId" gorm:"type:int"`                                 //鍏徃id
-		Company              Company                       `json:"company" gorm:"foreignKey:CompanyId"`                       //鍏徃
-		Type                 constvar.LocationType         `json:"type" gorm:"type:int(11);comment:浣嶇疆绫诲瀷"`                     //浣嶇疆绫诲瀷
-		CountFrequency       int                           `json:"countFrequency" gorm:"type:tinyint;comment:鐩樼偣棰戠巼锛堝ぉ锛�"`        //鐩樼偣棰戠巼锛堝ぉ锛�
-		IsScrapLocation      bool                          `json:"isScrapLocation" gorm:"type:tinyint;comment:鏄惁鎶ュ簾浣嶇疆"`        //鏄惁鎶ュ簾浣嶇疆
-		IsReturnLocation     bool                          `json:"isReturnLocation" gorm:"type:tinyint;comment:鏄惁閫�璐т綅缃�"`       //鏄惁閫�璐т綅缃�
-		ReplenishLocation    bool                          `json:"replenishLocation" gorm:"type:tinyint;comment:鏄惁琛ュ厖浣嶇疆"`      //鏄惁琛ュ厖浣嶇疆
-		ForceRemovalStrategy constvar.ForceRemovalStrategy `json:"forceRemovalStrategy" gorm:"type:tinyint;comment:涓嬫灦绛栫暐"`     //涓嬫灦绛栫暐
+		Id        int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		Name      string `json:"name" gorm:"index;type:varchar(255);not null;comment:浣嶇疆鍚嶇О"` //浣嶇疆鍚嶇О
+		ParentId  string `json:"parentId" gorm:"type:varchar(255)"`                         //涓婄骇id
+		CompanyId int    `json:"companyId" gorm:"type:int"`                                 //鍏徃id
+		//Company              Company                       `json:"company" gorm:"foreignKey:CompanyId"`                       //鍏徃
+		Type                 constvar.LocationType         `json:"type" gorm:"type:int(11);comment:浣嶇疆绫诲瀷"`                 //浣嶇疆绫诲瀷
+		CountFrequency       int                           `json:"countFrequency" gorm:"type:tinyint;comment:鐩樼偣棰戠巼锛堝ぉ锛�"`    //鐩樼偣棰戠巼锛堝ぉ锛�
+		IsScrapLocation      bool                          `json:"isScrapLocation" gorm:"type:tinyint;comment:鏄惁鎶ュ簾浣嶇疆"`    //鏄惁鎶ュ簾浣嶇疆
+		IsReturnLocation     bool                          `json:"isReturnLocation" gorm:"type:tinyint;comment:鏄惁閫�璐т綅缃�"`   //鏄惁閫�璐т綅缃�
+		ReplenishLocation    bool                          `json:"replenishLocation" gorm:"type:tinyint;comment:鏄惁琛ュ厖浣嶇疆"`  //鏄惁琛ュ厖浣嶇疆
+		ForceRemovalStrategy constvar.ForceRemovalStrategy `json:"forceRemovalStrategy" gorm:"type:tinyint;comment:涓嬫灦绛栫暐"` //涓嬫灦绛栫暐
 	}
 
 	LocationSearch struct {
@@ -59,8 +59,8 @@
 	return slf
 }
 
-func (slf *LocationSearch) SetID(id int) *LocationSearch {
-	slf.Id = id
+func (slf *LocationSearch) SetID(ID int) *LocationSearch {
+	slf.Id = ID
 	return slf
 }
 func (slf *LocationSearch) SetParents(ids []string) *LocationSearch {
@@ -101,8 +101,8 @@
 func (slf *LocationSearch) build() *gorm.DB {
 	var db = slf.Orm.Table(slf.TableName())
 
-	if slf.Id != 0 {
-		db = db.Where("id = ?", slf.Id)
+	if slf.ID != 0 {
+		db = db.Where("id = ?", slf.ID)
 	}
 
 	if slf.Order != "" {
diff --git a/models/operation.go b/models/operation.go
index 6b31864..60b8b5a 100644
--- a/models/operation.go
+++ b/models/operation.go
@@ -12,14 +12,14 @@
 	Operation struct {
 		WmsModel
 		Id              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		Number          string                   `json:"number" gorm:"type:varchar(255)"`                         //鍗曞彿
-		SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //婧愬崟鍙�
-		OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id
-		Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"`          //鐘舵��
-		FromLocationId  int                      `json:"fromLocationId"   gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d
-		FromLocation    Location                 `json:"fromLocation"     gorm:"foreignKey:FromLocationId"`       //婧愪綅缃�
-		ToLocationId    int                      `json:"toLocationId"    gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id
-		ToLocation      Location                 `json:"toLocation"      gorm:"foreignKey:ToLocationId"`          //鐩爣浣嶇疆
+		Number          string                   `json:"number" gorm:"type:varchar(255)"`                                 //鍗曞彿
+		SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                           //婧愬崟鍙�
+		OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"`         //浣滀笟绫诲瀷id
+		Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"`                  //鐘舵��
+		FromLocationID  int                      `json:"fromLocationId"   gorm:"type:int;not null;comment:婧愪綅缃甶d"`         //婧愪綅缃甶d
+		FromLocation    Location                 `json:"fromLocation"     gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃�
+		ToLocationID    int                      `json:"toLocationId"    gorm:"type:int;not null;comment:鐩爣浣嶇疆id"`         //鐩爣浣嶇疆id
+		ToLocation      Location                 `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"`    //鐩爣浣嶇疆
 		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:鑱旂郴浜哄鍚�"`
@@ -27,7 +27,7 @@
 		CompanyName     string                   `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"`
 		Comment         string                   `json:"comment" gorm:"type:text;comment:澶囨敞"`
 
-		Details []*OperationDetails `json:"details"`
+		Details []*OperationDetails `json:"details" gorm:"foreignKey:OperationID;references:Id"`
 
 		//Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"`
 		//TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"`
@@ -70,8 +70,8 @@
 	return slf
 }
 
-func (slf *OperationSearch) SetID(id int) *OperationSearch {
-	slf.Id = id
+func (slf *OperationSearch) SetID(ID int) *OperationSearch {
+	slf.Id = ID
 	return slf
 }
 
@@ -93,8 +93,8 @@
 func (slf *OperationSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Operation{})
 
-	if slf.Id != 0 {
-		db = db.Where("id = ?", slf.Id)
+	if slf.ID != 0 {
+		db = db.Where("id = ?", slf.ID)
 	}
 	if slf.Order != "" {
 		db = db.Order(slf.Order)
@@ -109,7 +109,7 @@
 	}
 
 	if slf.Preload {
-		db = db.Model(&Operation{}).Preload("Details")
+		db = db.Model(&Operation{}).Preload("Details").Preload("FromLocation").Preload("ToLocation")
 	}
 
 	return db
diff --git a/models/operation_details.go b/models/operation_details.go
index 270e34d..e79cbf8 100644
--- a/models/operation_details.go
+++ b/models/operation_details.go
@@ -11,12 +11,11 @@
 	// OperationDetails 鎿嶄綔鏄庣粏琛�
 	OperationDetails struct {
 		WmsModel
-
 		Id          int             `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		OperationId int             `json:"OperationId" gorm:"type:int;not null;comment:鎿嶄綔璁板綍id"`        //鎿嶄綔id
+		OperationID int             `json:"operationId" gorm:"type:int;not null;comment:鎿嶄綔璁板綍id"`        //鎿嶄綔id
 		ProductId   string          `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"`   //浜у搧id
 		ProductName string          `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
-		Quantity    decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"`     //鏁伴噺
+		Amount      decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"`       //鏁伴噺
 		Unit        string          `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`
 	}
 
@@ -54,8 +53,8 @@
 	return slf
 }
 
-func (slf *OperationDetailsSearch) SetID(id uint) *OperationDetailsSearch {
-	slf.ID = id
+func (slf *OperationDetailsSearch) SetID(ID int) *OperationDetailsSearch {
+	slf.Id = ID
 	return slf
 }
 
@@ -70,7 +69,7 @@
 }
 
 func (slf *OperationDetailsSearch) SetOperationId(operationId int) *OperationDetailsSearch {
-	slf.OperationId = operationId
+	slf.OperationID = operationId
 	return slf
 }
 
@@ -89,8 +88,8 @@
 		db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
 	}
 
-	if slf.OperationId != 0 {
-		db = db.Where("operation_id = ?", slf.OperationId)
+	if slf.OperationID != 0 {
+		db = db.Where("operation_id = ?", slf.OperationID)
 	}
 
 	return db
diff --git a/request/operation.go b/request/operation.go
index a87eeb0..2417a79 100644
--- a/request/operation.go
+++ b/request/operation.go
@@ -6,7 +6,7 @@
 )
 
 type AddOperation struct {
-	Id              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+	ID              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
 	Number          string                   `json:"number" gorm:"column:number;type:varchar(255)"`           //鍗曞彿
 	SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //婧愬崟鍙�
 	OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id
@@ -42,7 +42,7 @@
 }
 
 type UpdateOperation struct {
-	Id              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+	ID              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
 	Number          string                   `json:"number" gorm:"column:number;type:varchar(255)"`           //鍗曞彿
 	SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //婧愬崟鍙�
 	OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id
diff --git a/router/router.go b/router/router.go
index 623eab5..084dc11 100644
--- a/router/router.go
+++ b/router/router.go
@@ -79,7 +79,7 @@
 	{
 		operationAPI.GET("operation", operationController.List)
 		operationAPI.POST("operation", operationController.Add)
-		operationAPI.POST("operation/:id", operationController.Update)
+		operationAPI.PUT("operation/:id", operationController.Update)
 		operationAPI.DELETE("operation/:id", operationController.Delete)
 		operationAPI.PUT("Finish/:id", operationController.Finish)
 	}

--
Gitblit v1.8.0