From 7d1b46b246613585acda03a2148db76ebea79de1 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期四, 18 四月 2024 18:16:17 +0800
Subject: [PATCH] 物料字段类型修改
---
proto/purchase_wms/server.go | 81 ++++++++++++++++++++++++++++++++++++++--
1 files changed, 76 insertions(+), 5 deletions(-)
diff --git a/proto/purchase_wms/server.go b/proto/purchase_wms/server.go
index 173e7db..5d1da59 100644
--- a/proto/purchase_wms/server.go
+++ b/proto/purchase_wms/server.go
@@ -2,8 +2,11 @@
import (
"context"
+ "errors"
"github.com/shopspring/decimal"
+ "gorm.io/gorm"
"strconv"
+ "strings"
"time"
"wms/constvar"
"wms/models"
@@ -22,7 +25,11 @@
operation.Number = strconv.FormatInt(time.Now().Unix(), 10)
operation.Status = constvar.OperationStatus_Ready
operation.CompanyName = req.SupplierName
- warehouse, err := models.NewWarehouseSearch().First()
+ operation.CompanyID = strconv.FormatInt(req.SupplierId, 10)
+ operation.Source = req.Source
+ operation.OperationSource = constvar.OperationSource(req.OperationSource)
+ operation.SalesDetailsNumber = req.SalesDetailsNumber
+ warehouse, err := models.NewWarehouseSearch().SetName(req.WarehouseName).First()
if err != nil {
return nil, err
}
@@ -36,19 +43,83 @@
if err != nil {
return nil, err
}
- operation.ToLocationID = location.Id
first, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeVendor)).First()
if err != nil {
return nil, err
}
- operation.FromLocationID = first.Id
+ operation.LocationID = location.Id
operation.BaseOperationType = constvar.BaseOperationTypeIncoming
for _, product := range req.Product {
var detail models.OperationDetails
detail.ProductId = product.Id
detail.Amount = decimal.NewFromInt(product.Amount)
+ detail.FromLocationID = first.Id
+ detail.ToLocationID = location.Id
details = append(details, &detail)
}
- err = models.NewOperationSearch().Create(&operation)
- return new(PurchaseToWmsResponse), err
+ err = models.WithTransaction(func(db *gorm.DB) error {
+ err := models.NewOperationSearch().SetOrm(db).Create(&operation)
+ if err != nil {
+ return err
+ }
+ for _, detail := range details {
+ detail.OperationID = operation.Id
+ }
+ err = models.NewOperationDetailsSearch().SetOrm(db).CreateBatch(details)
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ resp := new(PurchaseToWmsResponse)
+ resp.Warehouse = warehouse.Name
+ return resp, nil
+}
+
+func (s *Server) SrmGetWarehouseInfo(c context.Context, req *SrmGetWarehouseInfoRequest) (*SrmGetWarehouseInfoResponse, error) {
+ warehouses, err := models.NewWarehouseSearch().FindNotTotal()
+ resp := new(SrmGetWarehouseInfoResponse)
+ if err != nil {
+ return resp, err
+ }
+ for _, warehouse := range warehouses {
+ var info SrmWarehouseInfo
+ info.Name = warehouse.Name
+ info.Address = warehouse.Address
+ info.Principal = warehouse.Contacts
+ resp.Info = append(resp.Info, &info)
+ }
+ return resp, nil
+}
+
+func (s *Server) SrmGetOperationInfo(c context.Context, req *SrmGetOperationInfoRequest) (*SrmGetOperationInfoResponse, error) {
+ if req.Number == "" && req.SalesDetailsNumber == "" && req.OperationSource == 0 {
+ return nil, errors.New("鍙傛暟缂哄け")
+ }
+ operations, err := models.NewOperationSearch().SetSourceNumber(req.Number).
+ SetOperationSource(constvar.OperationSource(req.OperationSource)).
+ SetSalesDetailsNumber(req.SalesDetailsNumber).
+ SetPreload(true).FindNotTotal()
+ if err != nil {
+ return nil, err
+ }
+ srm := make([]*SrmOperation, 0)
+ for _, operation := range operations {
+ var so SrmOperation
+ so.Number = operation.Number
+ index := strings.LastIndex(operation.OperationTypeName, "-")
+ so.WarehouseName = operation.OperationTypeName[:index]
+ so.Status = int64(operation.Status)
+ so.OverTime = operation.CreateTime
+ for _, detail := range operation.Details {
+ s := so
+ s.ProductId = detail.ProductId
+ s.Amount = detail.Amount.IntPart()
+ s.ProductName = detail.Product.Name
+ srm = append(srm, &s)
+ }
+ }
+ var resp = new(SrmGetOperationInfoResponse)
+ resp.Operations = srm
+ return resp, nil
}
--
Gitblit v1.8.0