| | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/shopspring/decimal" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "strings" |
| | | "time" |
| | | "wms/conf" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | | "wms/pkg/logx" |
| | | "wms/pkg/timex" |
| | | "wms/proto/inventory_order" |
| | | "wms/request" |
| | | ) |
| | | |
| | |
| | | util.ResponseFormat(c, code.Success, "更新成功") |
| | | } |
| | | |
| | | var InventoryOrderServiceConn *grpc.ClientConn |
| | | |
| | | func InitInventoryOrderServiceConn() { |
| | | var err error |
| | | InventoryOrderServiceConn, err = grpc.Dial(conf.GrpcServerConf.ApsAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) |
| | | if err != nil { |
| | | logx.Errorf("grpc dial product service error: %v", err.Error()) |
| | | return |
| | | } |
| | | } |
| | | |
| | | func CloseInventoryOrderServiceConn() { |
| | | if InventoryOrderServiceConn != nil { |
| | | InventoryOrderServiceConn.Close() |
| | | } |
| | | } |
| | | |
| | | // OrderAgain |
| | | // @Tags 重订货规则 |
| | | // @Summary 再订一次 |
| | |
| | | var params models.ReorderRule |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | client := inventory_order.NewInventoryOrderServiceClient(InventoryOrderServiceConn) |
| | | order, err := client.CreateNewOrder(c, &inventory_order.CreateNewOrderRequest{ |
| | | OrderNumber: params.OrderNumber.IntPart(), |
| | | Unit: params.Unit, |
| | | ProductId: params.ProductId, |
| | | Customer: "WMS推送", |
| | | }) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "grpc调用失败") |
| | | return |
| | | } |
| | | location, err := models.NewLocationSearch().SetID(params.LocationId).First() |
| | |
| | | operation.FromLocationID = 1 |
| | | operation.Number = strconv.FormatInt(time.Now().Unix(), 10) |
| | | operation.ToLocationID = params.LocationId |
| | | operation.SourceNumber = order.OrderId |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | if err = models.NewOperationSearch().SetOrm(db).Create(&operation); err != nil { |