jiangshuai
2023-09-21 eae7648dfc2085a849401f9e49de184002f1cece
1.出入库一部分代码
5个文件已修改
35 ■■■■■ 已修改文件
controllers/operation.go 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation_details.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/operation.go 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/operation.go
@@ -5,7 +5,6 @@
    "fmt"
    "github.com/gin-gonic/gin"
    "github.com/shopspring/decimal"
    "github.com/spf13/cast"
    "gorm.io/gorm"
    "strconv"
    "wms/constvar"
@@ -170,15 +169,9 @@
// @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 {
@@ -201,15 +194,14 @@
        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(&params).Association("Details").Replace(params.Details); err != nil {
            return err
        }
        if err := models.NewOperationSearch().SetOrm(tx).SetID(params.Id).Save(&params); err != nil {
            return err
        }
models/operation.go
@@ -15,6 +15,7 @@
        Number          string                   `json:"number" gorm:"type:varchar(255)"`                                 //单号
        SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                           //源单号
        OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"`         //作业类型id
        OperationTypeName string                   `json:"operationTypeName" gorm:"type:varchar(127);comment:作业类型名称"`       //作业类型名称
        Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`                  //状态
        FromLocationID  int                      `json:"fromLocationId"   gorm:"type:int;not null;comment:源位置id"`         //源位置id
        FromLocation    Location                 `json:"fromLocation"     gorm:"foreignKey:FromLocationID;references:Id"` //源位置
@@ -93,8 +94,8 @@
func (slf *OperationSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Operation{})
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Order != "" {
        db = db.Order(slf.Order)
models/operation_details.go
@@ -76,8 +76,8 @@
func (slf *OperationDetailsSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&OperationDetails{})
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Order != "" {
request/operation.go
@@ -10,6 +10,7 @@
    Number          string                   `json:"number" gorm:"column:number;type:varchar(255)"`           //单号
    SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //源单号
    OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id
    OperationTypeName string                   `json:"operationTypeName" gorm:"type:varchar(127);comment:作业类型名称"` //作业类型名称
    Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`          //状态
    FromLocationId  int                      `json:"fromLocationId"   gorm:"type:int;not null;comment:源位置id"` //源位置id
    ToLocationId    int                      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"` //目标位置id
@@ -32,7 +33,7 @@
    OperationId int             `json:"OperationId" gorm:"type:int;not null;comment:操作记录id"`        //操作id
    ProductId   string          `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"`   //产品id
    ProductName string          `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"` //产品名称
    Quantity    decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:数量"`     //数量
    Amount      decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:数量"`       //数量
    Unit        string          `json:"unit" gorm:"type:varchar(31);comment:单位"`
}
@@ -46,6 +47,7 @@
    Number          string                   `json:"number" gorm:"column:number;type:varchar(255)"`           //单号
    SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //源单号
    OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id
    OperationTypeName string                   `json:"operationTypeName" gorm:"type:varchar(127);comment:作业类型名称"` //作业类型名称
    Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`          //状态
    FromLocationId  int                      `json:"fromLocationId"   gorm:"type:int;not null;comment:源位置id"` //源位置id
    ToLocationId    int                      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"` //目标位置id
router/router.go
@@ -79,9 +79,9 @@
    {
        operationAPI.GET("operation", operationController.List)
        operationAPI.POST("operation", operationController.Add)
        operationAPI.PUT("operation/:id", operationController.Update)
        operationAPI.POST("update", operationController.Update)
        operationAPI.DELETE("operation/:id", operationController.Delete)
        operationAPI.PUT("Finish/:id", operationController.Finish)
        operationAPI.PUT("finish/:id", operationController.Finish)
    }
    //产品