Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS
# Conflicts:
# docs/docs.go
# docs/swagger.json
# docs/swagger.yaml
| | |
| | | |
| | | import ( |
| | | "errors" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | |
| | | //检查明细部分 |
| | | for _, v := range params.Details { |
| | | if v.ProductId == "" { |
| | | return errors.New("productID为0") |
| | | return errors.New("productID为空") |
| | | } |
| | | if v.ProductName == "" { |
| | | return errors.New("产品名称异常") |
| | |
| | | // @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/operation/{id} [post] |
| | | func (slf OperationController) Update(c *gin.Context) { |
| | | id := cast.ToUint(c.Param("id")) |
| | | if id == 0 { |
| | |
| | | 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 |
| | |
| | | util.ResponseFormat(c, code.RequestError, "该出入库信息无法完成") |
| | | return |
| | | } |
| | | //operationType, err := models.NewOperationTypeSearch().SetID(uint(operation.OperationTypeId)).First() |
| | | //if err != nil { |
| | | // util.ResponseFormat(c, code.RequestError, err.Error()) |
| | | // return |
| | | //} |
| | | //if operationType.BaseOperationType == constvar.BaseOperationTypeIncoming { |
| | | // if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeVendor)).First(); err != nil { |
| | | // return err |
| | | // } else { |
| | | // params.FromLocationId = location.Id |
| | | // } |
| | | // if params.ToLocationId == 0 { |
| | | // return errors.New("请选择目标位置") |
| | | // } |
| | | //} |
| | | operationType, err := models.NewOperationTypeSearch().SetID(uint(operation.OperationTypeId)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err.Error()) |
| | | return |
| | | } |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | |
| | | if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Update(&models.Operation{Status: constvar.OperationStatus_Finish}); err != nil { |
| | | return err |
| | | } |
| | | if operationType.BaseOperationType == constvar.BaseOperationTypeIncoming { |
| | | if err := models.NewMaterialSearch().Orm.Exec("update material INNER JOIN wms_operation_details on wms_operation_details.product_id=material.id INNER JOIN wms_operation on wms_operation.id=wms_operation_details.operation_id set material.amount=material.amount + wms_operation_details.quantity where wms_operation.id=?", id).Error; err != nil { |
| | | return err |
| | | } |
| | | } else if operationType.BaseOperationType == constvar.BaseOperationTypeOutgoing { |
| | | var listProdtId []string |
| | | var listProdt []*models.Material |
| | | mapProdt := make(map[string]decimal.Decimal) |
| | | listDetails, err := models.NewOperationDetailsSearch().SetOperationId(operation.Id).FindAll() |
| | | if err != nil { |
| | | return err |
| | | } |
| | | for _, v := range listDetails { |
| | | listProdtId = append(listProdtId, v.ProductId) |
| | | mapProdt[v.ProductId] = v.Quantity |
| | | } |
| | | if err := models.NewMaterialSearch().Orm.Where("id IN ?", listProdtId).Find(&listProdt).Error; err != nil { |
| | | return err |
| | | } |
| | | for _, v := range listProdt { |
| | | if value, ok := mapProdt[v.ID]; !ok { |
| | | return errors.New("产品种类异常") |
| | | } else { |
| | | if v.Amount.LessThan(value) { |
| | | return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Name, v.Amount.String(), value.String())) |
| | | } |
| | | } |
| | | } |
| | | if err := models.NewMaterialSearch().Orm.Exec("update material INNER JOIN wms_operation_details on wms_operation_details.product_id=material.id INNER JOIN wms_operation on wms_operation.id=wms_operation_details.operation_id set material.amount=material.amount - wms_operation_details.quantity where wms_operation.id=?", id).Error; err != nil { |
| | | return err |
| | | } |
| | | } |
| | | return nil |
| | | }); err != nil { |
| | | util.ResponseFormat(c, code.RequestError, err.Error()) |
| | |
| | | } |
| | | }, |
| | | "/api-wms/v1/operation/operation/{id}": { |
| | | "put": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | |
| | | "type": "object", |
| | | "properties": { |
| | | "comment": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | |
| | | "request.OperationDetails": { |
| | | "type": "object", |
| | | "properties": { |
| | | "OperationId": { |
| | | "description": "操作id", |
| | | "type": "integer" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | | "type": "string" |
| | | }, |
| | | "productName": { |
| | | "description": "产品名称", |
| | |
| | | "request.UpdateOperation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "carrierID": { |
| | | "description": "承运商ID-非必填", |
| | | "type": "integer" |
| | | }, |
| | | "carrierName": { |
| | | "description": "承运商名称-非必填", |
| | | "comment": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "tracking": { |
| | | "description": "追踪参考-非必填", |
| | | "type": "string" |
| | | }, |
| | | "transferWeight": { |
| | | "description": "物流重量(kg)-非必填", |
| | | "type": "number" |
| | | }, |
| | | "weight": { |
| | | "description": "重量(kg)-非必填", |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | |
| | | Description: "", |
| | | InfoInstanceName: "swagger", |
| | | SwaggerTemplate: docTemplate, |
| | | LeftDelim: "{{", |
| | | RightDelim: "}}", |
| | | } |
| | | |
| | | func init() { |
| | |
| | | } |
| | | }, |
| | | "/api-wms/v1/operation/operation/{id}": { |
| | | "put": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | |
| | | "type": "object", |
| | | "properties": { |
| | | "comment": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | |
| | | "request.OperationDetails": { |
| | | "type": "object", |
| | | "properties": { |
| | | "OperationId": { |
| | | "description": "操作id", |
| | | "type": "integer" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | | "type": "string" |
| | | }, |
| | | "productName": { |
| | | "description": "产品名称", |
| | |
| | | "request.UpdateOperation": { |
| | | "type": "object", |
| | | "properties": { |
| | | "carrierID": { |
| | | "description": "承运商ID-非必填", |
| | | "type": "integer" |
| | | }, |
| | | "carrierName": { |
| | | "description": "承运商名称-非必填", |
| | | "comment": { |
| | | "description": "备注", |
| | | "type": "string" |
| | | }, |
| | | "companyID": { |
| | |
| | | "toLocationId": { |
| | | "description": "目标位置id", |
| | | "type": "integer" |
| | | }, |
| | | "tracking": { |
| | | "description": "追踪参考-非必填", |
| | | "type": "string" |
| | | }, |
| | | "transferWeight": { |
| | | "description": "物流重量(kg)-非必填", |
| | | "type": "number" |
| | | }, |
| | | "weight": { |
| | | "description": "重量(kg)-非必填", |
| | | "type": "number" |
| | | } |
| | | } |
| | | }, |
| | |
| | | request.AddOperation: |
| | | properties: |
| | | comment: |
| | | description: 备注 |
| | | type: string |
| | | companyID: |
| | | description: 公司ID-客户 |
| | |
| | | type: object |
| | | request.OperationDetails: |
| | | properties: |
| | | OperationId: |
| | | description: 操作id |
| | | type: integer |
| | | productId: |
| | | description: 产品id |
| | | type: integer |
| | | type: string |
| | | productName: |
| | | description: 产品名称 |
| | | type: string |
| | |
| | | type: object |
| | | request.UpdateOperation: |
| | | properties: |
| | | carrierID: |
| | | description: 承运商ID-非必填 |
| | | type: integer |
| | | carrierName: |
| | | description: 承运商名称-非必填 |
| | | comment: |
| | | description: 备注 |
| | | type: string |
| | | companyID: |
| | | description: 公司ID-客户 |
| | |
| | | toLocationId: |
| | | description: 目标位置id |
| | | type: integer |
| | | tracking: |
| | | description: 追踪参考-非必填 |
| | | type: string |
| | | transferWeight: |
| | | description: 物流重量(kg)-非必填 |
| | | type: number |
| | | weight: |
| | | description: 重量(kg)-非必填 |
| | | type: number |
| | | type: object |
| | | request.UpdateOperationType: |
| | | properties: |
| | |
| | | summary: 删除入库/出库信息 |
| | | tags: |
| | | - 入库/出库 |
| | | put: |
| | | post: |
| | | parameters: |
| | | - description: 入库信息 |
| | | in: body |
| | |
| | | |
| | | func (slf *OperationDetailsSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&OperationDetails{}).Error |
| | | return db.Unscoped().Delete(&OperationDetails{}).Error |
| | | } |
| | | |
| | | func (slf *OperationDetailsSearch) First() (*OperationDetails, error) { |
| | |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *OperationDetailsSearch) FindAll() ([]*OperationDetails, error) { |
| | | var ( |
| | | records = make([]*OperationDetails, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | | return records, nil |
| | | } |
| | |
| | | ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` //联系人姓名-非必填 |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` //公司ID-客户 |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称"` //公司名称-客户名称 |
| | | Comment string `json:"comment" gorm:"type:text;comment:备注"` |
| | | Comment string `json:"comment" gorm:"type:text;comment:备注"` //备注 |
| | | |
| | | //Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` //重量(kg)-非必填 |
| | | //TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` //物流重量(kg)-非必填 |
| | |
| | | } |
| | | |
| | | type OperationDetails struct { |
| | | ProductId int `json:"productId" gorm:"type:int;not null;comment:产品id"` //产品id |
| | | 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:数量"` //数量 |
| | | Unit string `json:"unit" gorm:"type:varchar(31);comment:单位"` |
| | |
| | | ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:目标位置id"` //目标位置id |
| | | OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"` //安排日期 |
| | | Details []*OperationDetails `json:"details"` |
| | | CarrierID int `json:"carrierID" gorm:"type:int;comment:承运商ID"` //承运商ID-非必填 |
| | | CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"` //承运商名称-非必填 |
| | | Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` //追踪参考-非必填 |
| | | ContacterID int `json:"contacterID" gorm:"type:int;comment:联系人ID"` //联系人ID-非必填 |
| | | ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"` //联系人姓名-非必填 |
| | | Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` //重量(kg)-非必填 |
| | | TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` //物流重量(kg)-非必填 |
| | | CompanyID int `json:"companyID" gorm:"type:int;comment:公司ID"` //公司ID-客户 |
| | | CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:公司名称"` //公司名称-客户名称 |
| | | Comment string `json:"comment" gorm:"type:text;comment:备注"` //备注 |
| | | |
| | | //CarrierID int `json:"carrierID" gorm:"type:int;comment:承运商ID"` //承运商ID-非必填 |
| | | //CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"` //承运商名称-非必填 |
| | | //Tracking string `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"` //追踪参考-非必填 |
| | | //Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"` //重量(kg)-非必填 |
| | | //TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"` //物流重量(kg)-非必填 |
| | | } |
| | |
| | | { |
| | | operationAPI.GET("operation", operationController.List) |
| | | operationAPI.POST("operation", operationController.Add) |
| | | operationAPI.PUT("operation/:id", operationController.Update) |
| | | operationAPI.POST("operation/:id", operationController.Update) |
| | | operationAPI.DELETE("operation/:id", operationController.Delete) |
| | | operationAPI.PUT("Finish/:id", operationController.Finish) |
| | | } |