From c20b2d72c1f6241213f792dde44e50def6bf3510 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期五, 25 八月 2023 16:42:05 +0800 Subject: [PATCH] fix --- api/v1/test/industry.go | 5 +- service/test/supplier_type.go | 5 ++ model/test/request/supplier_type.go | 4 ++ api/v1/test/supplier_type.go | 24 ++++++++--- docs/swagger.yaml | 9 ++++ docs/docs.go | 13 ++++++ docs/swagger.json | 13 ++++++ 7 files changed, 60 insertions(+), 13 deletions(-) diff --git a/api/v1/test/industry.go b/api/v1/test/industry.go index 871e889..646ba90 100644 --- a/api/v1/test/industry.go +++ b/api/v1/test/industry.go @@ -116,12 +116,11 @@ if err := iService.CreateIndustry(&industry); err != nil { global.GVA_LOG.Error("鏇存柊澶辫触!", zap.Error(err)) response.FailWithMessage("淇濆瓨澶辫触", c) + return } } - if err == nil { - response.OkWithMessage("鏇存柊鎴愬姛", c) - } + response.OkWithMessage("鏇存柊鎴愬姛", c) } // FindIndustry 鐢╥d鏌ヨIndustry diff --git a/api/v1/test/supplier_type.go b/api/v1/test/supplier_type.go index 9cd5b4d..4733d83 100644 --- a/api/v1/test/supplier_type.go +++ b/api/v1/test/supplier_type.go @@ -94,22 +94,32 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body test.SupplierType true "鏇存柊SupplierType" +// @Param data body request.SupplierTypeList true "鏇存柊SupplierType" // @Success 200 {string} string "{"success":true,"data":{},"msg":"鏇存柊鎴愬姛"}" // @Router /st/updateSupplierType [put] func (stApi *SupplierTypeApi) UpdateSupplierType(c *gin.Context) { - var st test.SupplierType + var st testReq.SupplierTypeList err := c.ShouldBindJSON(&st) if err != nil { response.FailWithMessage(err.Error(), c) return } - if err := stService.UpdateSupplierType(st); err != nil { - global.GVA_LOG.Error("鏇存柊澶辫触!", zap.Error(err)) - response.FailWithMessage("鏇存柊澶辫触", c) - } else { - response.OkWithMessage("鏇存柊鎴愬姛", c) + + if err := stService.DeleteAll(); err != nil { + global.GVA_LOG.Error("鍒犻櫎澶辫触!", zap.Error(err)) + response.FailWithMessage("鍒犻櫎澶辫触", c) + return } + + for _, v := range st.SupplierTypes { + if err := stService.CreateSupplierType(&v); err != nil { + global.GVA_LOG.Error("鍒涘缓澶辫触!", zap.Error(err)) + response.FailWithMessage("鍒涘缓澶辫触", c) + return + } + } + + response.OkWithMessage("鏇存柊鎴愬姛", c) } // FindSupplierType 鐢╥d鏌ヨSupplierType diff --git a/docs/docs.go b/docs/docs.go index 20ba00b..58e36d4 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -4312,7 +4312,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.SupplierType" + "$ref": "#/definitions/request.SupplierTypeList" } } ], @@ -7312,6 +7312,17 @@ } } }, + "request.SupplierTypeList": { + "type": "object", + "properties": { + "supplierTypes": { + "type": "array", + "items": { + "$ref": "#/definitions/test.SupplierType" + } + } + } + }, "request.SysAuthorityBtnReq": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 6de5ab8..cd202da 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4303,7 +4303,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.SupplierType" + "$ref": "#/definitions/request.SupplierTypeList" } } ], @@ -7303,6 +7303,17 @@ } } }, + "request.SupplierTypeList": { + "type": "object", + "properties": { + "supplierTypes": { + "type": "array", + "items": { + "$ref": "#/definitions/test.SupplierType" + } + } + } + }, "request.SysAuthorityBtnReq": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 7f15ba2..83d355e 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -897,6 +897,13 @@ status: type: integer type: object + request.SupplierTypeList: + properties: + supplierTypes: + items: + $ref: '#/definitions/test.SupplierType' + type: array + type: object request.SysAuthorityBtnReq: properties: authorityId: @@ -4035,7 +4042,7 @@ name: data required: true schema: - $ref: '#/definitions/test.SupplierType' + $ref: '#/definitions/request.SupplierTypeList' produces: - application/json responses: diff --git a/model/test/request/supplier_type.go b/model/test/request/supplier_type.go index 78ac862..ace5c81 100644 --- a/model/test/request/supplier_type.go +++ b/model/test/request/supplier_type.go @@ -12,3 +12,7 @@ EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"` request.PageInfo } + +type SupplierTypeList struct { + SupplierTypes []test.SupplierType `json:"supplierTypes"` +} diff --git a/service/test/supplier_type.go b/service/test/supplier_type.go index 296c631..89c3e63 100644 --- a/service/test/supplier_type.go +++ b/service/test/supplier_type.go @@ -65,3 +65,8 @@ err = db.Limit(limit).Offset(offset).Find(&sts).Error return sts, total, err } + +func (stService *SupplierTypeService) DeleteAll() (err error) { + err = global.GVA_DB.Where("1=1").Delete(&[]test.SupplierType{}).Error + return err +} -- Gitblit v1.8.0