From c2e727dcdfa8970f629c3e3884bd866398bf3f48 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期五, 25 八月 2023 16:31:30 +0800 Subject: [PATCH] fix --- api/v1/test/industry.go | 22 ++++++++-- model/test/request/industry.go | 4 ++ docs/swagger.yaml | 9 ++++ docs/docs.go | 13 ++++++ docs/swagger.json | 13 ++++++ service/test/industry.go | 5 ++ 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/api/v1/test/industry.go b/api/v1/test/industry.go index 6ff455e..871e889 100644 --- a/api/v1/test/industry.go +++ b/api/v1/test/industry.go @@ -94,20 +94,32 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body test.Industry true "鏇存柊Industry" +// @Param data body request.IndustryList true "鏇存柊Industry" // @Success 200 {string} string "{"success":true,"data":{},"msg":"鏇存柊鎴愬姛"}" // @Router /i/updateIndustry [put] func (iApi *IndustryApi) UpdateIndustry(c *gin.Context) { - var i test.Industry + var i testReq.IndustryList err := c.ShouldBindJSON(&i) if err != nil { response.FailWithMessage(err.Error(), c) return } - if err := iService.UpdateIndustry(i); err != nil { + + // 鍒犻櫎鎵�鏈夌浉鍏崇殑琛屼笟 + if err := iService.DeleteAll(); err != nil { global.GVA_LOG.Error("鏇存柊澶辫触!", zap.Error(err)) - response.FailWithMessage("鏇存柊澶辫触", c) - } else { + response.FailWithMessage("淇濆瓨澶辫触", c) + return + } + + for _, industry := range i.Industries { + if err := iService.CreateIndustry(&industry); err != nil { + global.GVA_LOG.Error("鏇存柊澶辫触!", zap.Error(err)) + response.FailWithMessage("淇濆瓨澶辫触", c) + } + } + + if err == nil { response.OkWithMessage("鏇存柊鎴愬姛", c) } } diff --git a/docs/docs.go b/docs/docs.go index c4ef0fd..20ba00b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -3038,7 +3038,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.Industry" + "$ref": "#/definitions/request.IndustryList" } } ], @@ -7093,6 +7093,17 @@ } } }, + "request.IndustryList": { + "type": "object", + "properties": { + "industries": { + "type": "array", + "items": { + "$ref": "#/definitions/test.Industry" + } + } + } + }, "request.InitDB": { "type": "object", "required": [ diff --git a/docs/swagger.json b/docs/swagger.json index 435228f..6de5ab8 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -3029,7 +3029,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.Industry" + "$ref": "#/definitions/request.IndustryList" } } ], @@ -7084,6 +7084,17 @@ } } }, + "request.IndustryList": { + "type": "object", + "properties": { + "industries": { + "type": "array", + "items": { + "$ref": "#/definitions/test.Industry" + } + } + } + }, "request.InitDB": { "type": "object", "required": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 99c85eb..7f15ba2 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -742,6 +742,13 @@ type: integer type: array type: object + request.IndustryList: + properties: + industries: + items: + $ref: '#/definitions/test.Industry' + type: array + type: object request.InitDB: properties: dbName: @@ -3281,7 +3288,7 @@ name: data required: true schema: - $ref: '#/definitions/test.Industry' + $ref: '#/definitions/request.IndustryList' produces: - application/json responses: diff --git a/model/test/request/industry.go b/model/test/request/industry.go index 9edfaff..3837729 100644 --- a/model/test/request/industry.go +++ b/model/test/request/industry.go @@ -12,3 +12,7 @@ EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"` request.PageInfo } + +type IndustryList struct { + Industries []test.Industry `json:"industries"` +} diff --git a/service/test/industry.go b/service/test/industry.go index 2ab2570..57add6e 100644 --- a/service/test/industry.go +++ b/service/test/industry.go @@ -65,3 +65,8 @@ err = db.Limit(limit).Offset(offset).Find(&is).Error return is, total, err } + +func (iService *IndustryService) DeleteAll() (err error) { + err = global.GVA_DB.Where("1=1").Delete(&[]test.Industry{}).Error + return err +} -- Gitblit v1.8.0