fix
wangpengfei
2023-08-25 c2e727dcdfa8970f629c3e3884bd866398bf3f48
fix

Batch Update Industry
6个文件已修改
66 ■■■■ 已修改文件
api/v1/test/industry.go 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/request/industry.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/test/industry.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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)
    }
}
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": [
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": [
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:
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"`
}
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
}