From b28a7f52e8df5889572f86a9422c62c10334f70c Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期一, 25 九月 2023 10:17:49 +0800
Subject: [PATCH] 1.修改出入库模块的新增、修改、列表,operation_details不再保存产品名称和单位,改为读取material 2.修改报废模块的新增,修改、列表,不再使用productName和unit字段

---
 controllers/product_controller.go |   20 ++--
 controllers/operation.go          |    6 
 models/operation.go               |    2 
 request/product_request.go        |   28 +++---
 docs/swagger.yaml                 |   31 ++-----
 request/operation.go              |   11 +-
 docs/docs.go                      |   41 +++-------
 models/operation_details.go       |   13 +-
 docs/swagger.json                 |   41 +++-------
 9 files changed, 79 insertions(+), 114 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 9d6fa9b..872fb4c 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -115,9 +115,9 @@
 		if v.ProductId == "" {
 			return errors.New("productID涓虹┖")
 		}
-		if v.ProductName == "" {
-			return errors.New("浜у搧鍚嶇О寮傚父")
-		}
+		//if v.ProductName == "" {
+		//	return errors.New("浜у搧鍚嶇О寮傚父")
+		//}
 		if v.Amount.IsNegative() {
 			return errors.New("浜у搧鏁伴噺鍑洪敊")
 		}
diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index ca6f24e..ab762ae 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -343,10 +343,10 @@
 		return
 	}
 	detail := &models.OperationDetails{
-		ProductId:   params.ProductId,
-		ProductName: params.ProductName,
-		Amount:      params.Amount,
-		Unit:        params.Unit,
+		ProductId: params.ProductId,
+		//ProductName: params.ProductName,
+		Amount: params.Amount,
+		//Unit:        params.Unit,
 	}
 	operation := models.Operation{
 		Number:          strconv.FormatInt(time.Now().Unix(), 10),
@@ -384,7 +384,9 @@
 		return
 	}
 
-	db := models.NewOperationSearch().Orm.Table("wms_operation").Select("wms_operation.id,wms_operation.number,wms_operation.source_number,wms_operation.status,wms_operation.from_location_id,wms_operation.to_location_id,wms_operation.operation_date,wms_operation.contacter_id,wms_operation.contacter_name,wms_operation.company_id,wms_operation.company_name,wms_operation.comment,wms_operation_details.product_id,wms_operation_details.product_name,wms_operation_details.unit,wms_operation_details.amount").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id")
+	//db := models.NewOperationSearch().Orm.Table("wms_operation").Select("wms_operation.id,wms_operation.number,wms_operation.source_number,wms_operation.status,wms_operation.from_location_id,wms_operation.to_location_id,wms_operation.operation_date,wms_operation.contacter_id,wms_operation.contacter_name,wms_operation.company_id,wms_operation.company_name,wms_operation.comment,wms_operation_details.product_id,wms_operation_details.product_name,wms_operation_details.unit,wms_operation_details.amount").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id")
+
+	db := models.NewOperationSearch().Orm.Table("wms_operation").Select("wms_operation.id,wms_operation.number,wms_operation.source_number,wms_operation.status,wms_operation.from_location_id,wms_operation.to_location_id,wms_operation.operation_date,wms_operation.contacter_id,wms_operation.contacter_name,wms_operation.company_id,wms_operation.company_name,wms_operation.comment,wms_operation_details.product_id,material.name as product_name,material.unit,wms_operation_details.amount").InnerJoins("inner join wms_operation_details on wms_operation_details.operation_id=wms_operation.id").InnerJoins("inner join material on material.id=wms_operation_details.product_id")
 
 	if params.SourceNumber != "" {
 		db = db.Where("wms_operation.source_number like ?", fmt.Sprintf("%%%v%%", params.SourceNumber))
@@ -515,10 +517,10 @@
 		return
 	}
 	detail := &models.OperationDetails{
-		ProductId:   params.ProductId,
-		ProductName: params.ProductName,
-		Amount:      params.Amount,
-		Unit:        params.Unit,
+		ProductId: params.ProductId,
+		//ProductName: params.ProductName,
+		Amount: params.Amount,
+		//Unit:        params.Unit,
 	}
 	operation := models.Operation{
 		Id:              params.Id,
diff --git a/docs/docs.go b/docs/docs.go
index 3d921fd..20489c0 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -2118,7 +2118,7 @@
             "type": "object",
             "properties": {
                 "amount": {
-                    "description": "鏁伴噺",
+                    "description": "ProductName string          ` + "`" + `json:\"productName\" gorm:\"type:varchar(255);not null;comment:浜у搧鍚嶇О\"` + "`" + ` //浜у搧鍚嶇О",
                     "type": "number"
                 },
                 "createTime": {
@@ -2131,15 +2131,16 @@
                     "description": "鎿嶄綔id",
                     "type": "integer"
                 },
+                "product": {
+                    "description": "Unit        string          ` + "`" + `json:\"unit\" gorm:\"type:varchar(31);comment:鍗曚綅\"` + "`" + `                    //鍗曚綅",
+                    "allOf": [
+                        {
+                            "$ref": "#/definitions/models.Material"
+                        }
+                    ]
+                },
                 "productId": {
                     "description": "浜у搧id",
-                    "type": "string"
-                },
-                "productName": {
-                    "description": "浜у搧鍚嶇О",
-                    "type": "string"
-                },
-                "unit": {
                     "type": "string"
                 },
                 "updateTime": {
@@ -2430,6 +2431,7 @@
             "type": "object",
             "properties": {
                 "amount": {
+                    "description": "ProductName    string          ` + "`" + `json:\"productName\"` + "`" + `",
                     "type": "number"
                 },
                 "fromLocationId": {
@@ -2438,17 +2440,11 @@
                 "productId": {
                     "type": "string"
                 },
-                "productName": {
-                    "type": "string"
-                },
                 "sourceNumber": {
                     "type": "string"
                 },
                 "toLocationId": {
                     "type": "integer"
-                },
-                "unit": {
-                    "type": "string"
                 }
             }
         },
@@ -2690,18 +2686,11 @@
                     "type": "integer"
                 },
                 "amount": {
-                    "description": "鏁伴噺",
+                    "description": "ProductName string          ` + "`" + `json:\"productName\" gorm:\"type:varchar(255);not null;comment:浜у搧鍚嶇О\"` + "`" + ` //浜у搧鍚嶇О",
                     "type": "number"
                 },
                 "productId": {
                     "description": "浜у搧id",
-                    "type": "string"
-                },
-                "productName": {
-                    "description": "浜у搧鍚嶇О",
-                    "type": "string"
-                },
-                "unit": {
                     "type": "string"
                 }
             }
@@ -2803,6 +2792,7 @@
             "type": "object",
             "properties": {
                 "amount": {
+                    "description": "ProductName    string                   ` + "`" + `json:\"productName\"` + "`" + `",
                     "type": "number"
                 },
                 "fromLocationId": {
@@ -2812,15 +2802,13 @@
                     "type": "integer"
                 },
                 "number": {
+                    "description": "Unit           string                   ` + "`" + `json:\"unit\"` + "`" + `",
                     "type": "string"
                 },
                 "operationDate": {
                     "type": "string"
                 },
                 "productId": {
-                    "type": "string"
-                },
-                "productName": {
                     "type": "string"
                 },
                 "sourceNumber": {
@@ -2831,9 +2819,6 @@
                 },
                 "toLocationId": {
                     "type": "integer"
-                },
-                "unit": {
-                    "type": "string"
                 }
             }
         },
diff --git a/docs/swagger.json b/docs/swagger.json
index a8ff32a..9c6e3e4 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -2106,7 +2106,7 @@
             "type": "object",
             "properties": {
                 "amount": {
-                    "description": "鏁伴噺",
+                    "description": "ProductName string          `json:\"productName\" gorm:\"type:varchar(255);not null;comment:浜у搧鍚嶇О\"` //浜у搧鍚嶇О",
                     "type": "number"
                 },
                 "createTime": {
@@ -2119,15 +2119,16 @@
                     "description": "鎿嶄綔id",
                     "type": "integer"
                 },
+                "product": {
+                    "description": "Unit        string          `json:\"unit\" gorm:\"type:varchar(31);comment:鍗曚綅\"`                    //鍗曚綅",
+                    "allOf": [
+                        {
+                            "$ref": "#/definitions/models.Material"
+                        }
+                    ]
+                },
                 "productId": {
                     "description": "浜у搧id",
-                    "type": "string"
-                },
-                "productName": {
-                    "description": "浜у搧鍚嶇О",
-                    "type": "string"
-                },
-                "unit": {
                     "type": "string"
                 },
                 "updateTime": {
@@ -2418,6 +2419,7 @@
             "type": "object",
             "properties": {
                 "amount": {
+                    "description": "ProductName    string          `json:\"productName\"`",
                     "type": "number"
                 },
                 "fromLocationId": {
@@ -2426,17 +2428,11 @@
                 "productId": {
                     "type": "string"
                 },
-                "productName": {
-                    "type": "string"
-                },
                 "sourceNumber": {
                     "type": "string"
                 },
                 "toLocationId": {
                     "type": "integer"
-                },
-                "unit": {
-                    "type": "string"
                 }
             }
         },
@@ -2678,18 +2674,11 @@
                     "type": "integer"
                 },
                 "amount": {
-                    "description": "鏁伴噺",
+                    "description": "ProductName string          `json:\"productName\" gorm:\"type:varchar(255);not null;comment:浜у搧鍚嶇О\"` //浜у搧鍚嶇О",
                     "type": "number"
                 },
                 "productId": {
                     "description": "浜у搧id",
-                    "type": "string"
-                },
-                "productName": {
-                    "description": "浜у搧鍚嶇О",
-                    "type": "string"
-                },
-                "unit": {
                     "type": "string"
                 }
             }
@@ -2791,6 +2780,7 @@
             "type": "object",
             "properties": {
                 "amount": {
+                    "description": "ProductName    string                   `json:\"productName\"`",
                     "type": "number"
                 },
                 "fromLocationId": {
@@ -2800,15 +2790,13 @@
                     "type": "integer"
                 },
                 "number": {
+                    "description": "Unit           string                   `json:\"unit\"`",
                     "type": "string"
                 },
                 "operationDate": {
                     "type": "string"
                 },
                 "productId": {
-                    "type": "string"
-                },
-                "productName": {
                     "type": "string"
                 },
                 "sourceNumber": {
@@ -2819,9 +2807,6 @@
                 },
                 "toLocationId": {
                     "type": "integer"
-                },
-                "unit": {
-                    "type": "string"
                 }
             }
         },
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index f0f0d6e..0e09a58 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -478,7 +478,8 @@
   models.OperationDetails:
     properties:
       amount:
-        description: 鏁伴噺
+        description: ProductName string          `json:"productName" gorm:"type:varchar(255);not
+          null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
         type: number
       createTime:
         type: string
@@ -487,13 +488,12 @@
       operationId:
         description: 鎿嶄綔id
         type: integer
+      product:
+        allOf:
+        - $ref: '#/definitions/models.Material'
+        description: Unit        string          `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`                    //鍗曚綅
       productId:
         description: 浜у搧id
-        type: string
-      productName:
-        description: 浜у搧鍚嶇О
-        type: string
-      unit:
         type: string
       updateTime:
         type: string
@@ -684,19 +684,16 @@
   request.AddDisuse:
     properties:
       amount:
+        description: ProductName    string          `json:"productName"`
         type: number
       fromLocationId:
         type: integer
       productId:
         type: string
-      productName:
-        type: string
       sourceNumber:
         type: string
       toLocationId:
         type: integer
-      unit:
-        type: string
     type: object
   request.AddOperation:
     properties:
@@ -863,15 +860,11 @@
         description: 鎿嶄綔id
         type: integer
       amount:
-        description: 鏁伴噺
+        description: ProductName string          `json:"productName" gorm:"type:varchar(255);not
+          null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
         type: number
       productId:
         description: 浜у搧id
-        type: string
-      productName:
-        description: 浜у搧鍚嶇О
-        type: string
-      unit:
         type: string
     type: object
   request.OperationList:
@@ -941,18 +934,18 @@
   request.UpdateDisuse:
     properties:
       amount:
+        description: ProductName    string                   `json:"productName"`
         type: number
       fromLocationId:
         type: integer
       id:
         type: integer
       number:
+        description: Unit           string                   `json:"unit"`
         type: string
       operationDate:
         type: string
       productId:
-        type: string
-      productName:
         type: string
       sourceNumber:
         type: string
@@ -960,8 +953,6 @@
         $ref: '#/definitions/constvar.OperationStatus'
       toLocationId:
         type: integer
-      unit:
-        type: string
     type: object
   request.UpdateOperation:
     properties:
diff --git a/models/operation.go b/models/operation.go
index b0d64d4..7f17d4a 100644
--- a/models/operation.go
+++ b/models/operation.go
@@ -134,7 +134,7 @@
 	}
 
 	if slf.Preload {
-		db = db.Model(&Operation{}).Preload("Details").Preload("FromLocation").Preload("ToLocation")
+		db = db.Model(&Operation{}).Preload("Details").Preload("Details.Product").Preload("FromLocation").Preload("ToLocation")
 	}
 
 	if slf.Disuse {
diff --git a/models/operation_details.go b/models/operation_details.go
index 18e8cfd..32e8f9a 100644
--- a/models/operation_details.go
+++ b/models/operation_details.go
@@ -11,12 +11,13 @@
 	// 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
-		ProductId   string          `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"`   //浜у搧id
-		ProductName string          `json:"productName" gorm:"type:varchar(255);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:鍗曚綅"`
+		Id          int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		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:浜у搧鍚嶇О"` //浜у搧鍚嶇О
+		Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺
+		//Unit        string          `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`                    //鍗曚綅
+		Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"`
 	}
 
 	OperationDetailsSearch struct {
diff --git a/request/operation.go b/request/operation.go
index 9e730f2..5f17078 100644
--- a/request/operation.go
+++ b/request/operation.go
@@ -30,11 +30,12 @@
 }
 
 type OperationDetails struct {
-	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:浜у搧鍚嶇О"` //浜у搧鍚嶇О
-	Amount      decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"`       //鏁伴噺
-	Unit        string          `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`
+	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:浜у搧鍚嶇О"` //浜у搧鍚嶇О
+	Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺
+	//Unit        string          `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`                    //鍗曚綅
+	//Product models.Material `json:"product" gorm:"foreignKey:ProductId;references:ID"`
 }
 
 type OperationList struct {
diff --git a/request/product_request.go b/request/product_request.go
index 0f16f7b..2101529 100644
--- a/request/product_request.go
+++ b/request/product_request.go
@@ -16,13 +16,13 @@
 }
 
 type AddDisuse struct {
-	ProductId      string          `json:"productId"`
-	ProductName    string          `json:"productName"`
+	ProductId string `json:"productId"`
+	//ProductName    string          `json:"productName"`
 	Amount         decimal.Decimal `json:"amount"`
 	FromLocationId int             `json:"fromLocationId"`
 	ToLocationId   int             `json:"toLocationId"`
 	SourceNumber   string          `json:"sourceNumber"`
-	Unit           string          `json:"unit"`
+	//Unit           string          `json:"unit"`
 }
 
 type QueryDisuseList struct {
@@ -32,15 +32,15 @@
 }
 
 type UpdateDisuse struct {
-	Id             int                      `json:"id"`
-	ProductId      string                   `json:"productId"`
-	ProductName    string                   `json:"productName"`
-	Amount         decimal.Decimal          `json:"amount"`
-	FromLocationId int                      `json:"fromLocationId"`
-	ToLocationId   int                      `json:"toLocationId"`
-	SourceNumber   string                   `json:"sourceNumber"`
-	Unit           string                   `json:"unit"`
-	Number         string                   `json:"number"`
-	Status         constvar.OperationStatus `json:"status"`
-	OperationDate  string                   `json:"operationDate"`
+	Id        int    `json:"id"`
+	ProductId string `json:"productId"`
+	//ProductName    string                   `json:"productName"`
+	Amount         decimal.Decimal `json:"amount"`
+	FromLocationId int             `json:"fromLocationId"`
+	ToLocationId   int             `json:"toLocationId"`
+	SourceNumber   string          `json:"sourceNumber"`
+	//Unit           string                   `json:"unit"`
+	Number        string                   `json:"number"`
+	Status        constvar.OperationStatus `json:"status"`
+	OperationDate string                   `json:"operationDate"`
 }

--
Gitblit v1.8.0