| | |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "wms/constvar" |
| | |
| | | // @Summary 修改入库/出库信息 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateOperation true "入库信息" |
| | | // @Param id path int true "入库信息id" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/operation/operation/{id} [put] |
| | | // @Router /api-wms/v1/operation/update [post] |
| | | func (slf OperationController) Update(c *gin.Context) { |
| | | id := cast.ToUint(c.Param("id")) |
| | | if id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "空的记录id") |
| | | return |
| | | } |
| | | var reqParams request.UpdateOperation |
| | | var params models.Operation |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | fmt.Printf("%+v\n", *reqParams.Details[0]) |
| | | fmt.Printf("%+v\n", *reqParams.Details[1]) |
| | | fmt.Println("===============================================") |
| | | fmt.Printf("%+v\n", *params.Details[0]) |
| | | fmt.Printf("%+v\n", *params.Details[1]) |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(params.Id).Delete(); err != nil { |
| | | return err |
| | | } |
| | | operationSearch := models.NewOperationSearch().SetOrm(tx) |
| | | if err := operationSearch.Orm.Model(¶ms).Association("Details").Replace(params.Details); err != nil { |
| | | return err |
| | | } |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(params.Id).Save(¶ms); err != nil { |
| | | return err |
| | | } |