From 2555d29866a25b8ea13a3003ea4833b5fd464d91 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 08 四月 2024 16:12:06 +0800 Subject: [PATCH] 纤度检验接口完善 --- models/fineness_check_item.go | 4 service/fineness.go | 9 + controllers/fineness.go | 49 ++----- docs/swagger.yaml | 66 ++++++++++ docs/docs.go | 91 ++++++++++++++ docs/swagger.json | 91 ++++++++++++++ 6 files changed, 267 insertions(+), 43 deletions(-) diff --git a/controllers/fineness.go b/controllers/fineness.go index be6f107..b675bcf 100644 --- a/controllers/fineness.go +++ b/controllers/fineness.go @@ -194,7 +194,7 @@ // @Summary 绾ゅ害妫�楠岃鎯� // @Produce application/json // @Param id path string true "瀛楀吀淇℃伅" -// @Success 200 {object} util.ResponseList{data=models.FinenessCheck} "鎴愬姛" +// @Success 200 {object} util.ResponseList{data=response.FinenessCheckInfo} "鎴愬姛" // @Router /api-jl/v1/fineness/check/{id} [get] func (slf FinenessController) CheckInfo(c *gin.Context) { idStr := c.Param("id") @@ -222,7 +222,7 @@ return } - util.ResponseFormat(c, code.Success, info) + util.ResponseFormat(c, code.Success, resp) } // CheckDelete @@ -270,54 +270,33 @@ // @Tags 绾ゅ害妫�楠� // @Summary 绾ゅ害妫�楠屼慨鏀� // @Produce application/json -// @Param object body request.AddFinenessRegister true "瀛楀吀淇℃伅" +// @Param object body models.FinenessCheck true "瀛楀吀淇℃伅" // @Success 200 {object} util.Response "鎴愬姛" // @Router /api-jl/v1/fineness/check [post] func (slf FinenessController) CheckEdit(c *gin.Context) { - var reqParams request.AddFinenessRegister - var params models.FinenessRegister - if err := c.BindJSON(&reqParams); err != nil { + var params models.FinenessCheck + if err := c.BindJSON(¶ms); err != nil { util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") return } - if err := structx.AssignTo(reqParams, ¶ms); err != nil { - util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲閿欒") - return - } - if err := slf.ParamsCheck(params); err != nil { - util.ResponseFormat(c, code.RequestParamError, err.Error()) - return - } - - check, err := models.NewFinenessCheckSearch().SetID(params.ID).First() + _, err := models.NewFinenessCheckSearch().SetID(params.ID).First() if err != nil { util.ResponseFormat(c, code.RequestParamError, "妫�楠岃褰曚笉瀛樺湪") return } - err = models.WithTransaction(func(db *gorm.DB) error { - search := models.NewFinenessRegisterSearch().SetOrm(db) - - if params.ID != 0 { - if err := models.NewFinenessCheckItemSearch().SetOrm(db).SetFinenessRegisterID(check.FinenessRegisterID).Delete(); err != nil { - return err - } - return search.Save(¶ms) - } else { - return search.Create(¶ms) - } - }) + err = service.FinenessReCheck(¶ms) if err != nil { - util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触") - } - - err = service.FinenessCheck(¶ms) - if err != nil { - logx.Errorf("service.FinenessCheck err:%v, finenessRegister:%+v", err, params) - util.ResponseFormat(c, code.RequestParamError, "鐢熸垚妫�楠岃〃澶辫触") + logx.Errorf("service.FinenessReCheck err:%v, finenessCheck:%+v", err, params) + util.ResponseFormat(c, code.RequestParamError, "妫�楠屽け璐�") return } + err = models.NewFinenessCheckSearch().Save(¶ms) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触") + return + } util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛") } diff --git a/docs/docs.go b/docs/docs.go index 8a98a74..ad2a8c8 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -83,7 +83,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.AddFinenessRegister" + "$ref": "#/definitions/models.FinenessCheck" } } ], @@ -127,7 +127,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/models.FinenessCheck" + "$ref": "#/definitions/response.FinenessCheckInfo" } } } @@ -956,6 +956,66 @@ } } }, + "models.FinenessCheckItem": { + "type": "object", + "properties": { + "cleanliness": { + "description": "娓呮磥搴�", + "type": "number" + }, + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "deviation": { + "description": "鍋忓樊", + "type": "number" + }, + "finenessGrade": { + "description": "绾ゅ害绛夌骇", + "type": "string" + }, + "finenessRegisterID": { + "description": "绾ゅ害鐧昏琛↖D", + "type": "integer" + }, + "finenessRoundingItems": { + "description": "绾ゅ害鍒楄〃", + "type": "array", + "items": { + "$ref": "#/definitions/models.FinenessRoundingItem" + } + }, + "id": { + "type": "integer" + }, + "position": { + "description": "FinenessCheckID uint ` + "`" + `gorm:\"not null;comment:绾ゅ害妫�楠岃〃ID\" json:\"finenessCheckID\"` + "`" + ` //绾ゅ害妫�楠岃〃ID", + "type": "integer" + }, + "purity": { + "description": "娲佸噣搴�", + "type": "number" + }, + "remark": { + "description": "澶囨敞", + "type": "string" + }, + "totalDeviation": { + "description": "鎬诲樊", + "type": "number" + }, + "twiceChange": { + "description": "浜屽害鍙樺寲", + "type": "number" + }, + "updatedAt": { + "type": "string" + } + } + }, "models.FinenessItem": { "type": "object", "properties": { @@ -1049,6 +1109,19 @@ }, "workshopGroup": { "description": "杞︾粍", + "type": "integer" + } + } + }, + "models.FinenessRoundingItem": { + "type": "object", + "properties": { + "fineness": { + "description": "绾ゅ害", + "type": "number" + }, + "quantity": { + "description": "鏁伴噺", "type": "integer" } } @@ -1338,6 +1411,20 @@ } } }, + "response.FinenessCheckInfo": { + "type": "object", + "properties": { + "info": { + "$ref": "#/definitions/models.FinenessCheck" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/models.FinenessCheckItem" + } + } + } + }, "response.RankStandard": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 768a2d3..535c5b4 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -71,7 +71,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.AddFinenessRegister" + "$ref": "#/definitions/models.FinenessCheck" } } ], @@ -115,7 +115,7 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/models.FinenessCheck" + "$ref": "#/definitions/response.FinenessCheckInfo" } } } @@ -944,6 +944,66 @@ } } }, + "models.FinenessCheckItem": { + "type": "object", + "properties": { + "cleanliness": { + "description": "娓呮磥搴�", + "type": "number" + }, + "createdAt": { + "type": "string" + }, + "deletedAt": { + "$ref": "#/definitions/gorm.DeletedAt" + }, + "deviation": { + "description": "鍋忓樊", + "type": "number" + }, + "finenessGrade": { + "description": "绾ゅ害绛夌骇", + "type": "string" + }, + "finenessRegisterID": { + "description": "绾ゅ害鐧昏琛↖D", + "type": "integer" + }, + "finenessRoundingItems": { + "description": "绾ゅ害鍒楄〃", + "type": "array", + "items": { + "$ref": "#/definitions/models.FinenessRoundingItem" + } + }, + "id": { + "type": "integer" + }, + "position": { + "description": "FinenessCheckID uint `gorm:\"not null;comment:绾ゅ害妫�楠岃〃ID\" json:\"finenessCheckID\"` //绾ゅ害妫�楠岃〃ID", + "type": "integer" + }, + "purity": { + "description": "娲佸噣搴�", + "type": "number" + }, + "remark": { + "description": "澶囨敞", + "type": "string" + }, + "totalDeviation": { + "description": "鎬诲樊", + "type": "number" + }, + "twiceChange": { + "description": "浜屽害鍙樺寲", + "type": "number" + }, + "updatedAt": { + "type": "string" + } + } + }, "models.FinenessItem": { "type": "object", "properties": { @@ -1037,6 +1097,19 @@ }, "workshopGroup": { "description": "杞︾粍", + "type": "integer" + } + } + }, + "models.FinenessRoundingItem": { + "type": "object", + "properties": { + "fineness": { + "description": "绾ゅ害", + "type": "number" + }, + "quantity": { + "description": "鏁伴噺", "type": "integer" } } @@ -1326,6 +1399,20 @@ } } }, + "response.FinenessCheckInfo": { + "type": "object", + "properties": { + "info": { + "$ref": "#/definitions/models.FinenessCheck" + }, + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/models.FinenessCheckItem" + } + } + } + }, "response.RankStandard": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e1f5ffd..94be12b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -130,6 +130,50 @@ updatedAt: type: string type: object + models.FinenessCheckItem: + properties: + cleanliness: + description: 娓呮磥搴� + type: number + createdAt: + type: string + deletedAt: + $ref: '#/definitions/gorm.DeletedAt' + deviation: + description: 鍋忓樊 + type: number + finenessGrade: + description: 绾ゅ害绛夌骇 + type: string + finenessRegisterID: + description: 绾ゅ害鐧昏琛↖D + type: integer + finenessRoundingItems: + description: 绾ゅ害鍒楄〃 + items: + $ref: '#/definitions/models.FinenessRoundingItem' + type: array + id: + type: integer + position: + description: FinenessCheckID uint `gorm:"not null;comment:绾ゅ害妫�楠岃〃ID" + json:"finenessCheckID"` //绾ゅ害妫�楠岃〃ID + type: integer + purity: + description: 娲佸噣搴� + type: number + remark: + description: 澶囨敞 + type: string + totalDeviation: + description: 鎬诲樊 + type: number + twiceChange: + description: 浜屽害鍙樺寲 + type: number + updatedAt: + type: string + type: object models.FinenessItem: properties: createdAt: @@ -196,6 +240,15 @@ type: string workshopGroup: description: 杞︾粍 + type: integer + type: object + models.FinenessRoundingItem: + properties: + fineness: + description: 绾ゅ害 + type: number + quantity: + description: 鏁伴噺 type: integer type: object models.RawSilkPriceStandard: @@ -392,6 +445,15 @@ description: 绛夌骇鍊� type: number type: object + response.FinenessCheckInfo: + properties: + info: + $ref: '#/definitions/models.FinenessCheck' + items: + items: + $ref: '#/definitions/models.FinenessCheckItem' + type: array + type: object response.RankStandard: properties: checkItem: @@ -483,7 +545,7 @@ name: object required: true schema: - $ref: '#/definitions/request.AddFinenessRegister' + $ref: '#/definitions/models.FinenessCheck' produces: - application/json responses: @@ -529,7 +591,7 @@ - $ref: '#/definitions/util.ResponseList' - properties: data: - $ref: '#/definitions/models.FinenessCheck' + $ref: '#/definitions/response.FinenessCheckInfo' type: object summary: 绾ゅ害妫�楠岃鎯� tags: diff --git a/models/fineness_check_item.go b/models/fineness_check_item.go index 778f74a..80e4217 100644 --- a/models/fineness_check_item.go +++ b/models/fineness_check_item.go @@ -14,8 +14,8 @@ gorm.Model FinenessRegisterID uint `gorm:"not null;comment:绾ゅ害鐧昏琛↖D" json:"finenessRegisterID"` //绾ゅ害鐧昏琛↖D //FinenessCheckID uint `gorm:"not null;comment:绾ゅ害妫�楠岃〃ID" json:"finenessCheckID"` //绾ゅ害妫�楠岃〃ID - Position int `json:"position"` //杞﹀彿 - FinenessRoundingItems []*FinenessRoundingItem `json:"finenessRoundingItems" gorm:"-"` + Position int `json:"position"` //杞﹀彿 + FinenessRoundingItems []*FinenessRoundingItem `json:"finenessRoundingItems" gorm:"-"` //绾ゅ害鍒楄〃 FinenessRounding string `json:"-"` Deviation decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:鍋忓樊" json:"deviation"` //鍋忓樊 TotalDeviation decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:鎬诲樊" json:"totalDeviation"` //鎬诲樊 diff --git a/service/fineness.go b/service/fineness.go index 95039f3..863c71f 100644 --- a/service/fineness.go +++ b/service/fineness.go @@ -202,3 +202,12 @@ result = float32(math.Round(float64(result)*10) / 10) return result } + +func FinenessReCheck(finenessCheck *models.FinenessCheck) (err error) { + standardMap, err := GetSilkRankStandard() + if err != nil { + return err + } + finenessCheck.FinenessGrade = CalcFinenessGrade(finenessCheck.Deviation, finenessCheck.TotalDeviation, finenessCheck.Cleanliness, finenessCheck.Purity, finenessCheck.TwiceChange, standardMap) + return +} -- Gitblit v1.8.0