From 0f7dbc99a9e0c0678d458e2f8f60df52f7fdb3d1 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 29 二月 2024 20:14:00 +0800
Subject: [PATCH] 添加纤度登记接口支持修改纤度登记

---
 controllers/fineness.go         |   20 ++
 models/fineness.go              |   21 +-
 controllers/request/fineness.go |   26 ++-
 docs/swagger.yaml               |   75 ++++++++++
 docs/docs.go                    |  113 +++++++++++++++
 docs/swagger.json               |  113 +++++++++++++++
 models/fineness_item.go         |    9 +
 7 files changed, 339 insertions(+), 38 deletions(-)

diff --git a/controllers/fineness.go b/controllers/fineness.go
index f3ad5f9..6760b3b 100644
--- a/controllers/fineness.go
+++ b/controllers/fineness.go
@@ -2,6 +2,7 @@
 
 import (
 	"github.com/gin-gonic/gin"
+	"gorm.io/gorm"
 	"silkserver/controllers/request"
 	"silkserver/extend/code"
 	"silkserver/extend/util"
@@ -35,12 +36,23 @@
 		util.ResponseFormat(c, code.RequestParamError, err.Error())
 		return
 	}
-	if err := models.NewFinenessRegisterSearch().Create(&params); err != nil {
-		util.ResponseFormat(c, code.SaveFail, "鎻掑叆澶辫触")
-		return
+	err := models.WithTransaction(func(db *gorm.DB) error {
+		search := models.NewFinenessRegisterSearch().SetOrm(db)
+
+		if params.ID != 0 {
+			if err := models.NewFinenessItemSearch().SetOrm(db).SetFinenessRegisterID(params.ID).Delete(); err != nil {
+				return err
+			}
+			return search.Save(&params)
+		} else {
+			return search.Create(&params)
+		}
+	})
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触")
 	}
 
-	util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
+	util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛")
 }
 
 func (slf FinenessController) ParamsCheck(params models.FinenessRegister) (err error) {
diff --git a/controllers/request/fineness.go b/controllers/request/fineness.go
index 6005044..e8121f9 100644
--- a/controllers/request/fineness.go
+++ b/controllers/request/fineness.go
@@ -1,18 +1,22 @@
 package request
 
-import "github.com/shopspring/decimal"
+import (
+	"github.com/shopspring/decimal"
+)
 
 type AddFinenessRegister struct {
-	Number        string         `gorm:"type:varchar(255);not null;comment:缂栧彿" json:"number"`        //缂栧彿
-	FinishDate    string         `gorm:"type:varchar(255);not null;comment:钀戒笣鏃堕棿" json:"finishDate"`  //钀戒笣鏃堕棿
-	Workshop      string         `gorm:"type:varchar(255);not null;comment:杞﹂棿" json:"name"`          //杞﹂棿
-	WorkshopGroup string         `gorm:"type:varchar(255);not null;comment:杞︾粍" json:"workshopGroup"` //杞︾粍
-	Market        string         `gorm:"type:varchar(255);not null;comment:搴勫彛" json:"market"`        //搴勫彛
-	Spec          string         `gorm:"type:varchar(255);not null;comment:瑙勬牸" json:"spec"`          //瑙勬牸
-	StartCircle   uint8          `gorm:"type:varchar(255);not null;comment:寮�濮嬪洖鏁�" json:"startCircle"` //寮�濮嬪洖鏁�
-	EndCircle     uint8          `gorm:"type:varchar(255);not null;comment:缁撴潫鍥炴暟" json:"endCircle"`   //缁撴潫鍥炴暟
-	FinenessList  []FinenessItem `json:"finenessList"`
-	Sum           FinenessItem   `json:"sum"`
+	ID            uint            `json:"id"`                                                             //id 娣诲姞鏃朵紶0
+	Number        string          `gorm:"type:varchar(255);not null;comment:缂栧彿" json:"number"`          //缂栧彿
+	FinishDate    string          `gorm:"type:varchar(255);not null;comment:钀戒笣鏃堕棿" json:"finishDate"`  //钀戒笣鏃堕棿
+	Workshop      string          `gorm:"type:varchar(255);not null;comment:杞﹂棿" json:"name"`            //杞﹂棿
+	WorkshopGroup string          `gorm:"type:varchar(255);not null;comment:杞︾粍" json:"workshopGroup"`   //杞︾粍
+	Market        string          `gorm:"type:varchar(255);not null;comment:搴勫彛" json:"market"`          //搴勫彛
+	Spec          string          `gorm:"type:varchar(255);not null;comment:瑙勬牸" json:"spec"`            //瑙勬牸
+	StartCircle   uint8           `gorm:"type:varchar(255);not null;comment:寮�濮嬪洖鏁�" json:"startCircle"` //寮�濮嬪洖鏁�
+	EndCircle     uint8           `gorm:"type:varchar(255);not null;comment:缁撴潫鍥炴暟" json:"endCircle"`   //缁撴潫鍥炴暟
+	FinenessList  []FinenessItem  `json:"finenessList"`
+	SumFineness   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:鍚堣绾ゅ害" json:"sumFineness"`
+	SumQuantity   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:鍚堣鏁伴噺" json:"sumQuantity"`
 }
 
 type FinenessItem struct {
diff --git a/docs/docs.go b/docs/docs.go
index 3c028fe..b085057 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -313,6 +313,66 @@
                     }
                 }
             }
+        },
+        "/api-jl/v1/system/getPriceStandardList": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "绯荤粺璁剧疆/鐢熶笣瀹氫环鏍囧噯"
+                ],
+                "summary": "鑾峰彇鐢熶笣瀹氫环鏍囧噯",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.RawSilkPriceStandard"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api-jl/v1/system/savePriceStandard": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "绯荤粺璁剧疆/鐢熶笣瀹氫环鏍囧噯"
+                ],
+                "summary": "淇濆瓨鐢熶笣瀹氫环鏍囧噯",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.RawSilkPriceStandard"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
         }
     },
     "definitions": {
@@ -464,11 +524,49 @@
                     "description": "寮�濮嬪洖鏁�",
                     "type": "integer"
                 },
+                "sumFineness": {
+                    "type": "number"
+                },
+                "sumQuantity": {
+                    "type": "number"
+                },
                 "updatedAt": {
                     "type": "string"
                 },
                 "workshopGroup": {
                     "description": "杞︾粍",
+                    "type": "string"
+                }
+            }
+        },
+        "models.RawSilkPriceStandard": {
+            "type": "object",
+            "properties": {
+                "createdAt": {
+                    "type": "string"
+                },
+                "deletedAt": {
+                    "$ref": "#/definitions/gorm.DeletedAt"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "marketNumber": {
+                    "type": "string"
+                },
+                "notes": {
+                    "type": "string"
+                },
+                "payStandard": {
+                    "type": "number"
+                },
+                "rawSilkGradeNumber": {
+                    "type": "string"
+                },
+                "unit": {
+                    "type": "string"
+                },
+                "updatedAt": {
                     "type": "string"
                 }
             }
@@ -515,6 +613,10 @@
                     "description": "钀戒笣鏃堕棿",
                     "type": "string"
                 },
+                "id": {
+                    "description": "id 娣诲姞鏃朵紶0",
+                    "type": "integer"
+                },
                 "market": {
                     "description": "搴勫彛",
                     "type": "string"
@@ -535,8 +637,11 @@
                     "description": "寮�濮嬪洖鏁�",
                     "type": "integer"
                 },
-                "sum": {
-                    "$ref": "#/definitions/request.FinenessItem"
+                "sumFineness": {
+                    "type": "number"
+                },
+                "sumQuantity": {
+                    "type": "number"
                 },
                 "workshopGroup": {
                     "description": "杞︾粍",
@@ -617,9 +722,7 @@
                 "pageSize": {
                     "type": "integer"
                 },
-                "total": {
-                    "type": "integer"
-                }
+                "total": {}
             }
         }
     }
diff --git a/docs/swagger.json b/docs/swagger.json
index 5c8d3f8..f41e17b 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -301,6 +301,66 @@
                     }
                 }
             }
+        },
+        "/api-jl/v1/system/getPriceStandardList": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "绯荤粺璁剧疆/鐢熶笣瀹氫环鏍囧噯"
+                ],
+                "summary": "鑾峰彇鐢熶笣瀹氫环鏍囧噯",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.RawSilkPriceStandard"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api-jl/v1/system/savePriceStandard": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "绯荤粺璁剧疆/鐢熶笣瀹氫环鏍囧噯"
+                ],
+                "summary": "淇濆瓨鐢熶笣瀹氫环鏍囧噯",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.RawSilkPriceStandard"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
         }
     },
     "definitions": {
@@ -452,11 +512,49 @@
                     "description": "寮�濮嬪洖鏁�",
                     "type": "integer"
                 },
+                "sumFineness": {
+                    "type": "number"
+                },
+                "sumQuantity": {
+                    "type": "number"
+                },
                 "updatedAt": {
                     "type": "string"
                 },
                 "workshopGroup": {
                     "description": "杞︾粍",
+                    "type": "string"
+                }
+            }
+        },
+        "models.RawSilkPriceStandard": {
+            "type": "object",
+            "properties": {
+                "createdAt": {
+                    "type": "string"
+                },
+                "deletedAt": {
+                    "$ref": "#/definitions/gorm.DeletedAt"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "marketNumber": {
+                    "type": "string"
+                },
+                "notes": {
+                    "type": "string"
+                },
+                "payStandard": {
+                    "type": "number"
+                },
+                "rawSilkGradeNumber": {
+                    "type": "string"
+                },
+                "unit": {
+                    "type": "string"
+                },
+                "updatedAt": {
                     "type": "string"
                 }
             }
@@ -503,6 +601,10 @@
                     "description": "钀戒笣鏃堕棿",
                     "type": "string"
                 },
+                "id": {
+                    "description": "id 娣诲姞鏃朵紶0",
+                    "type": "integer"
+                },
                 "market": {
                     "description": "搴勫彛",
                     "type": "string"
@@ -523,8 +625,11 @@
                     "description": "寮�濮嬪洖鏁�",
                     "type": "integer"
                 },
-                "sum": {
-                    "$ref": "#/definitions/request.FinenessItem"
+                "sumFineness": {
+                    "type": "number"
+                },
+                "sumQuantity": {
+                    "type": "number"
                 },
                 "workshopGroup": {
                     "description": "杞︾粍",
@@ -605,9 +710,7 @@
                 "pageSize": {
                     "type": "integer"
                 },
-                "total": {
-                    "type": "integer"
-                }
+                "total": {}
             }
         }
     }
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index d4f5dd8..5a82bcc 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -102,10 +102,35 @@
       startCircle:
         description: 寮�濮嬪洖鏁�
         type: integer
+      sumFineness:
+        type: number
+      sumQuantity:
+        type: number
       updatedAt:
         type: string
       workshopGroup:
         description: 杞︾粍
+        type: string
+    type: object
+  models.RawSilkPriceStandard:
+    properties:
+      createdAt:
+        type: string
+      deletedAt:
+        $ref: '#/definitions/gorm.DeletedAt'
+      id:
+        type: integer
+      marketNumber:
+        type: string
+      notes:
+        type: string
+      payStandard:
+        type: number
+      rawSilkGradeNumber:
+        type: string
+      unit:
+        type: string
+      updatedAt:
         type: string
     type: object
   request.AddDict:
@@ -136,6 +161,9 @@
       finishDate:
         description: 钀戒笣鏃堕棿
         type: string
+      id:
+        description: id 娣诲姞鏃朵紶0
+        type: integer
       market:
         description: 搴勫彛
         type: string
@@ -151,8 +179,10 @@
       startCircle:
         description: 寮�濮嬪洖鏁�
         type: integer
-      sum:
-        $ref: '#/definitions/request.FinenessItem'
+      sumFineness:
+        type: number
+      sumQuantity:
+        type: number
       workshopGroup:
         description: 杞︾粍
         type: string
@@ -205,8 +235,7 @@
         type: integer
       pageSize:
         type: integer
-      total:
-        type: integer
+      total: {}
     type: object
 info:
   contact: {}
@@ -398,4 +427,42 @@
       summary: 鍒犻櫎瀛楀吀
       tags:
       - 绯荤粺璁剧疆/瀛楀吀
+  /api-jl/v1/system/getPriceStandardList:
+    get:
+      parameters:
+      - description: 鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/models.RawSilkPriceStandard'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 鑾峰彇鐢熶笣瀹氫环鏍囧噯
+      tags:
+      - 绯荤粺璁剧疆/鐢熶笣瀹氫环鏍囧噯
+  /api-jl/v1/system/savePriceStandard:
+    post:
+      parameters:
+      - description: 鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/models.RawSilkPriceStandard'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 淇濆瓨鐢熶笣瀹氫环鏍囧噯
+      tags:
+      - 绯荤粺璁剧疆/鐢熶笣瀹氫环鏍囧噯
 swagger: "2.0"
diff --git a/models/fineness.go b/models/fineness.go
index 44b018d..e8e7238 100644
--- a/models/fineness.go
+++ b/models/fineness.go
@@ -2,6 +2,7 @@
 
 import (
 	"fmt"
+	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
 	"silkserver/pkg/mysqlx"
 )
@@ -10,15 +11,17 @@
 	// FinenessRegister 绾ゅ害鐧昏
 	FinenessRegister struct {
 		gorm.Model
-		Number        string         `gorm:"type:varchar(255);not null;comment:缂栧彿" json:"number"`        //缂栧彿
-		FinishDate    string         `gorm:"type:varchar(255);not null;comment:钀戒笣鏃堕棿" json:"finishDate"`  //钀戒笣鏃堕棿
-		Workshop      string         `gorm:"type:varchar(255);not null;comment:杞﹂棿" json:"name"`          //杞﹂棿
-		WorkshopGroup string         `gorm:"type:varchar(255);not null;comment:杞︾粍" json:"workshopGroup"` //杞︾粍
-		Market        string         `gorm:"type:varchar(255);not null;comment:搴勫彛" json:"market"`        //搴勫彛
-		Spec          string         `gorm:"type:varchar(255);not null;comment:瑙勬牸" json:"spec"`          //瑙勬牸
-		StartCircle   uint8          `gorm:"type:varchar(255);not null;comment:寮�濮嬪洖鏁�" json:"startCircle"` //寮�濮嬪洖鏁�
-		EndCircle     uint8          `gorm:"type:varchar(255);not null;comment:缁撴潫鍥炴暟" json:"endCircle"`   //缁撴潫鍥炴暟
-		FinenessList  []FinenessItem `gorm:"foreignkey:FinenessRegisterID;references:ID" json:"finenessList"`
+		Number        string          `gorm:"type:varchar(255);not null;comment:缂栧彿" json:"number"`        //缂栧彿
+		FinishDate    string          `gorm:"type:varchar(255);not null;comment:钀戒笣鏃堕棿" json:"finishDate"`  //钀戒笣鏃堕棿
+		Workshop      string          `gorm:"type:varchar(255);not null;comment:杞﹂棿" json:"name"`          //杞﹂棿
+		WorkshopGroup string          `gorm:"type:varchar(255);not null;comment:杞︾粍" json:"workshopGroup"` //杞︾粍
+		Market        string          `gorm:"type:varchar(255);not null;comment:搴勫彛" json:"market"`        //搴勫彛
+		Spec          string          `gorm:"type:varchar(255);not null;comment:瑙勬牸" json:"spec"`          //瑙勬牸
+		StartCircle   uint8           `gorm:"type:varchar(255);not null;comment:寮�濮嬪洖鏁�" json:"startCircle"` //寮�濮嬪洖鏁�
+		EndCircle     uint8           `gorm:"type:varchar(255);not null;comment:缁撴潫鍥炴暟" json:"endCircle"`   //缁撴潫鍥炴暟
+		FinenessList  []FinenessItem  `gorm:"foreignkey:FinenessRegisterID;references:ID" json:"finenessList"`
+		SumFineness   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:鍚堣绾ゅ害" json:"sumFineness"`
+		SumQuantity   decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:鍚堣鏁伴噺" json:"sumQuantity"`
 	}
 	FinenessRegisterSearch struct {
 		FinenessRegister
diff --git a/models/fineness_item.go b/models/fineness_item.go
index 13995ee..2db1931 100644
--- a/models/fineness_item.go
+++ b/models/fineness_item.go
@@ -55,6 +55,11 @@
 	return slf
 }
 
+func (slf *FinenessItemSearch) SetFinenessRegisterID(id uint) *FinenessItemSearch {
+	slf.FinenessRegisterID = id
+	return slf
+}
+
 func (slf *FinenessItemSearch) build() *gorm.DB {
 	var db = slf.Orm.Table(slf.TableName())
 
@@ -66,6 +71,10 @@
 		db = db.Order(slf.Order)
 	}
 
+	if slf.FinenessRegisterID != 0 {
+		db = db.Where("fineness_register_id = ?", slf.FinenessRegisterID)
+	}
+
 	return db
 }
 

--
Gitblit v1.8.0