| | |
| | | // @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) |
| | | } |
| | | } |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Industry" |
| | | "$ref": "#/definitions/request.IndustryList" |
| | | } |
| | | } |
| | | ], |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.IndustryList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "industries": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/test.Industry" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.InitDB": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/test.Industry" |
| | | "$ref": "#/definitions/request.IndustryList" |
| | | } |
| | | } |
| | | ], |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.IndustryList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "industries": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/test.Industry" |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "request.InitDB": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | type: integer |
| | | type: array |
| | | type: object |
| | | request.IndustryList: |
| | | properties: |
| | | industries: |
| | | items: |
| | | $ref: '#/definitions/test.Industry' |
| | | type: array |
| | | type: object |
| | | request.InitDB: |
| | | properties: |
| | | dbName: |
| | |
| | | name: data |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/test.Industry' |
| | | $ref: '#/definitions/request.IndustryList' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | |
| | | EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"` |
| | | request.PageInfo |
| | | } |
| | | |
| | | type IndustryList struct { |
| | | Industries []test.Industry `json:"industries"` |
| | | } |
| | |
| | | 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 |
| | | } |