| | |
| | | "wms/models" |
| | | "wms/pkg/logx" |
| | | "wms/pkg/mysqlx" |
| | | "wms/pkg/structx" |
| | | "wms/request" |
| | | ) |
| | | |
| | |
| | | } |
| | | util.ResponseFormatList(c, code.Success, dicts, int(total)) |
| | | } |
| | | |
| | | // SaveUnitDict |
| | | // |
| | | // @Tags 数据字典 |
| | | // @Summary 更新计量单位字典 |
| | | // @Produce application/json |
| | | // @Param object body request.SaveUnitDict true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/product/saveUnitDict [post] |
| | | func (slf ProductController) SaveUnitDict(c *gin.Context) { |
| | | var reqParams request.SaveUnitDict |
| | | var params []*models.UnitDict |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams.Data, ¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误") |
| | | return |
| | | } |
| | | |
| | | for i, v := range params { |
| | | if len(v.Name) == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "名称为空") |
| | | return |
| | | } |
| | | v.Sort = i + 1 |
| | | } |
| | | |
| | | err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | err := models.NewUnitDictSearch().SetOrm(tx).Delete() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | err = models.NewUnitDictSearch().SetOrm(tx).CreateBatch(params) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | return nil |
| | | }) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "删除失败") |
| | | return |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |