From 98961b50ca71608110e0156e7dfb30c8e1c46a27 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期五, 10 十一月 2023 16:06:18 +0800
Subject: [PATCH] 注释修改
---
controllers/operation.go | 754 +++++++++++++++++++++++++++--------------------------
docs/swagger.yaml | 11
docs/docs.go | 15 +
docs/swagger.json | 15 +
4 files changed, 420 insertions(+), 375 deletions(-)
diff --git a/controllers/operation.go b/controllers/operation.go
index 5d29310..a541b4d 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -1,11 +1,15 @@
package controllers
import (
+ "encoding/json"
"errors"
+ "fmt"
"github.com/gin-gonic/gin"
+ "github.com/shopspring/decimal"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"gorm.io/gorm"
+ "os"
"sort"
"strconv"
"time"
@@ -14,6 +18,7 @@
"wms/extend/code"
"wms/extend/util"
"wms/models"
+ "wms/opa"
"wms/pkg/logx"
"wms/pkg/structx"
"wms/proto/product_inventory"
@@ -307,381 +312,380 @@
// @Success 200 {object} util.Response "鎴愬姛"
// @Router /api-wms/v1/operation/finish/{id} [put]
func (slf OperationController) Finish(c *gin.Context) {
- //id, err := strconv.Atoi(c.Param("id"))
- //if err != nil {
- // util.ResponseFormat(c, code.RequestParamError, "閿欒鐨刬d鍊�")
- // return
- //}
- //if id == 0 {
- // util.ResponseFormat(c, code.RequestParamError, "id涓�0")
- // return
- //}
- //operation, err := models.NewOperationSearch().SetPreload(true).SetID(id).First()
- //if err != nil {
- // util.ResponseFormat(c, code.RequestParamError, "鏈壘鍒扮浉鍏冲嚭鍏ュ簱淇℃伅:"+err.Error())
- // return
- //}
- //if operation.Status != constvar.OperationStatus_Ready {
- // util.ResponseFormat(c, code.RequestError, "璇ュ嚭鍏ュ簱淇℃伅鏃犳硶瀹屾垚")
- // 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
- // }
- //
- // 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.Amount
- // }
- //
- // if err := models.NewMaterialSearch().Orm.Where("id IN ?", listProdtId).Find(&listProdt).Error; err != nil {
- // return err
- // }
- //
- // if operation.BaseOperationType == constvar.BaseOperationTypeIncoming {
- // var operationInputs []*models.Operation
- // for k, v := range listProdt {
- // value, ok := mapProdt[v.ID]
- // if !ok {
- // return errors.New("浜у搧绉嶇被寮傚父")
- // }
- //
- // listProdt[k].Amount = listProdt[k].Amount.Add(value)
- // if err := tx.Save(listProdt[k]).Error; err != nil {
- // return err
- // }
- //
- // locationRule, err := models.NewLocationProductSearch().SetProductId(v.ID).SetAreaId(operation.ToLocationID).First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- //
- // if err == nil {
- // operationTransfer := &models.Operation{
- // Number: operation.Number,
- // SourceNumber: operation.SourceNumber,
- // OperationTypeId: 0,
- // OperationTypeName: operation.OperationTypeName,
- // Status: constvar.OperationStatus_Finish,
- // FromLocationID: locationRule.AreaId,
- // ToLocationID: locationRule.LocationId,
- // OperationDate: operation.OperationDate,
- // ContacterID: operation.ContacterID,
- // ContacterName: operation.ContacterName,
- // CompanyID: operation.CompanyID,
- // CompanyName: operation.CompanyName,
- // Comment: operation.Comment,
- // BaseOperationType: constvar.BaseOperationTypeInternal,
- // Details: []*models.OperationDetails{
- // {
- // ProductId: v.ID,
- // Amount: value,
- // },
- // },
- // }
- // operationInputs = append(operationInputs, operationTransfer)
- //
- // //if err := tx.Create(&operationTransfer).Error; err != nil {
- // // return err
- // //}
- //
- // //TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
- // locAmount, err := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(locationRule.LocationId).
- // First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // locAmount.LocationId = locationRule.LocationId
- // locAmount.ProductId = v.ID
- // locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
- // locAmount.Amount = locAmount.Amount.Add(value)
- // if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
- // return res.Error
- // }
- // } else {
- // locationRule, err = models.NewLocationProductSearch().SetProductCategoryId(v.CategoryId).SetAreaId(operation.ToLocationID).First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // if err == nil {
- // operationTransfer := &models.Operation{
- // Number: operation.Number,
- // SourceNumber: operation.SourceNumber,
- // OperationTypeId: 0,
- // OperationTypeName: operation.OperationTypeName,
- // Status: constvar.OperationStatus_Finish,
- // FromLocationID: locationRule.AreaId,
- // ToLocationID: locationRule.LocationId,
- // OperationDate: operation.OperationDate,
- // ContacterID: operation.ContacterID,
- // ContacterName: operation.ContacterName,
- // CompanyID: operation.CompanyID,
- // CompanyName: operation.CompanyName,
- // Comment: operation.Comment,
- // BaseOperationType: constvar.BaseOperationTypeInternal,
- // Details: []*models.OperationDetails{
- // {
- // ProductId: v.ID,
- // Amount: value,
- // },
- // },
- // }
- // operationInputs = append(operationInputs, operationTransfer)
- //
- // //if err := tx.Create(&operationTransfer).Error; err != nil {
- // // return err
- // //}
- //
- // //TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
- // locAmount, err := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(locationRule.LocationId).
- // First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // locAmount.LocationId = locationRule.LocationId
- // locAmount.ProductId = v.ID
- // locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
- // locAmount.Amount = locAmount.Amount.Add(value)
- // if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
- // return res.Error
- // }
- // } else {
- // //TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
- // locAmount, err := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(operation.ToLocationID).
- // First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // locAmount.LocationId = operation.ToLocationID
- // locAmount.ProductId = v.ID
- // locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
- // locAmount.Amount = locAmount.Amount.Add(value)
- // if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
- // return res.Error
- // }
- // }
- // }
- // }
- // if len(operationInputs) > 0 {
- // if err := tx.Create(&operationInputs).Error; err != nil {
- // return err
- // }
- // }
- //
- // }
- //
- // if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing {
- // for k, v := range listProdt {
- // value, ok := mapProdt[v.ID]
- // if !ok {
- // return errors.New("浜у搧绉嶇被寮傚父")
- // }
- // //todo 婕旂ず娴嬭瘯鏁版嵁
- // data, err := os.ReadFile("conf/input.json")
- // if err != nil {
- // return errors.New("鏂囦欢璇诲彇澶辫触")
- // }
- // m := make(map[string]interface{})
- // err = json.Unmarshal(data, &m)
- // if err != nil {
- // return errors.New("鏍煎紡杞崲澶辫触")
- // }
- // if opa.OpaCheck(c, m, "operation") {
- // if v.Amount.LessThan(value) {
- // return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
- // }
- // }
- // listProdt[k].Amount = listProdt[k].Amount.Sub(value)
- // if err := tx.Save(listProdt[k]).Error; err != nil {
- // return err
- // }
- // locAmount, res := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(operation.ToLocationID).
- // FirstRes()
- // if res.Error != nil {
- // return err
- // }
- // if locAmount.Amount.LessThan(value) {
- // return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
- // }
- // locAmount.Amount = locAmount.Amount.Sub(value)
- // if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil {
- // return err
- // }
- // }
- // }
- //
- // if operation.BaseOperationType == constvar.BaseOperationTypeInternal {
- // var operationInputs []*models.Operation
- // for _, v := range listProdt {
- // value, ok := mapProdt[v.ID]
- // if !ok {
- // return errors.New("浜у搧绉嶇被寮傚父")
- // }
- // //listProdt[k].Amount = listProdt[k].Amount.Add(value)
- // //if err := tx.Save(listProdt[k]).Error; err != nil {
- // // return err
- // //}
- // fromLocAmount, res := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(operation.FromLocationID).
- // FirstRes()
- // if res.Error != nil {
- // return err
- // }
- // if fromLocAmount.Amount.LessThan(value) {
- // return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,璋冩嫧锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愯皟鎷ㄦ搷浣�", v.Name, v.Amount.String(), value.String()))
- // }
- // fromLocAmount.Amount = fromLocAmount.Amount.Sub(value)
- // if err := models.NewLocationProductAmountSearch().SetID(fromLocAmount.Id).Update(fromLocAmount); err != nil {
- // return err
- // }
- //
- // locationRule, err := models.NewLocationProductSearch().SetProductId(v.ID).SetAreaId(operation.ToLocationID).First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- //
- // if err == nil {
- // operationTransfer := &models.Operation{
- // Number: operation.Number,
- // SourceNumber: operation.SourceNumber,
- // OperationTypeId: 0,
- // OperationTypeName: operation.OperationTypeName,
- // Status: constvar.OperationStatus_Finish,
- // FromLocationID: locationRule.AreaId,
- // ToLocationID: locationRule.LocationId,
- // OperationDate: operation.OperationDate,
- // ContacterID: operation.ContacterID,
- // ContacterName: operation.ContacterName,
- // CompanyID: operation.CompanyID,
- // CompanyName: operation.CompanyName,
- // Comment: operation.Comment,
- // BaseOperationType: constvar.BaseOperationTypeInternal,
- // Details: []*models.OperationDetails{
- // {
- // ProductId: v.ID,
- // Amount: value,
- // },
- // },
- // }
- // operationInputs = append(operationInputs, operationTransfer)
- //
- // //if err := tx.Create(&operationTransfer).Error; err != nil {
- // // return err
- // //}
- //
- // locAmount, err := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(locationRule.LocationId).
- // First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // locAmount.LocationId = locationRule.LocationId
- // locAmount.ProductId = v.ID
- // locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
- // locAmount.Amount = locAmount.Amount.Add(value)
- // if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
- // return res.Error
- // }
- // } else {
- // locationRule, err = models.NewLocationProductSearch().SetProductCategoryId(v.CategoryId).SetAreaId(operation.ToLocationID).First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // if err == nil {
- // operationTransfer := &models.Operation{
- // Number: operation.Number,
- // SourceNumber: operation.SourceNumber,
- // OperationTypeId: 0,
- // OperationTypeName: operation.OperationTypeName,
- // Status: constvar.OperationStatus_Finish,
- // FromLocationID: locationRule.AreaId,
- // ToLocationID: locationRule.LocationId,
- // OperationDate: operation.OperationDate,
- // ContacterID: operation.ContacterID,
- // ContacterName: operation.ContacterName,
- // CompanyID: operation.CompanyID,
- // CompanyName: operation.CompanyName,
- // Comment: operation.Comment,
- // BaseOperationType: constvar.BaseOperationTypeInternal,
- // Details: []*models.OperationDetails{
- // {
- // ProductId: v.ID,
- // Amount: value,
- // },
- // },
- // }
- // operationInputs = append(operationInputs, operationTransfer)
- //
- // //if err := tx.Create(&operationTransfer).Error; err != nil {
- // // return err
- // //}
- //
- // locAmount, err := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(locationRule.LocationId).
- // First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // locAmount.LocationId = locationRule.LocationId
- // locAmount.ProductId = v.ID
- // locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
- // locAmount.Amount = locAmount.Amount.Add(value)
- // if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
- // return res.Error
- // }
- // } else {
- // locAmount, err := models.NewLocationProductAmountSearch().
- // SetProductId(v.ID).
- // SetLocationId(operation.ToLocationID).
- // First()
- // if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
- // return err
- // }
- // locAmount.LocationId = operation.ToLocationID
- // locAmount.ProductId = v.ID
- // locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
- // locAmount.Amount = locAmount.Amount.Add(value)
- // if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
- // return res.Error
- // }
- // }
- // }
- // }
- // if len(operationInputs) > 0 {
- // if err := tx.Create(&operationInputs).Error; err != nil {
- // return err
- // }
- // }
- // }
- // return nil
- //}); err != nil {
- // util.ResponseFormat(c, code.RequestError, err.Error())
- // return
- //}
- //if operation.SourceNumber != "" {
- // go UpdateSalesDetailStatus(c, operation.SourceNumber)
- //}
- UpdateSalesDetailStatus(c, c.Param("id"))
+ id, err := strconv.Atoi(c.Param("id"))
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "閿欒鐨刬d鍊�")
+ return
+ }
+ if id == 0 {
+ util.ResponseFormat(c, code.RequestParamError, "id涓�0")
+ return
+ }
+ operation, err := models.NewOperationSearch().SetPreload(true).SetID(id).First()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏈壘鍒扮浉鍏冲嚭鍏ュ簱淇℃伅:"+err.Error())
+ return
+ }
+ if operation.Status != constvar.OperationStatus_Ready {
+ util.ResponseFormat(c, code.RequestError, "璇ュ嚭鍏ュ簱淇℃伅鏃犳硶瀹屾垚")
+ 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
+ }
+
+ 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.Amount
+ }
+
+ if err := models.NewMaterialSearch().Orm.Where("id IN ?", listProdtId).Find(&listProdt).Error; err != nil {
+ return err
+ }
+
+ if operation.BaseOperationType == constvar.BaseOperationTypeIncoming {
+ var operationInputs []*models.Operation
+ for k, v := range listProdt {
+ value, ok := mapProdt[v.ID]
+ if !ok {
+ return errors.New("浜у搧绉嶇被寮傚父")
+ }
+
+ listProdt[k].Amount = listProdt[k].Amount.Add(value)
+ if err := tx.Save(listProdt[k]).Error; err != nil {
+ return err
+ }
+
+ locationRule, err := models.NewLocationProductSearch().SetProductId(v.ID).SetAreaId(operation.ToLocationID).First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+
+ if err == nil {
+ operationTransfer := &models.Operation{
+ Number: operation.Number,
+ SourceNumber: operation.SourceNumber,
+ OperationTypeId: 0,
+ OperationTypeName: operation.OperationTypeName,
+ Status: constvar.OperationStatus_Finish,
+ FromLocationID: locationRule.AreaId,
+ ToLocationID: locationRule.LocationId,
+ OperationDate: operation.OperationDate,
+ ContacterID: operation.ContacterID,
+ ContacterName: operation.ContacterName,
+ CompanyID: operation.CompanyID,
+ CompanyName: operation.CompanyName,
+ Comment: operation.Comment,
+ BaseOperationType: constvar.BaseOperationTypeInternal,
+ Details: []*models.OperationDetails{
+ {
+ ProductId: v.ID,
+ Amount: value,
+ },
+ },
+ }
+ operationInputs = append(operationInputs, operationTransfer)
+
+ //if err := tx.Create(&operationTransfer).Error; err != nil {
+ // return err
+ //}
+
+ //TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
+ locAmount, err := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(locationRule.LocationId).
+ First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ locAmount.LocationId = locationRule.LocationId
+ locAmount.ProductId = v.ID
+ locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
+ locAmount.Amount = locAmount.Amount.Add(value)
+ if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
+ return res.Error
+ }
+ } else {
+ locationRule, err = models.NewLocationProductSearch().SetProductCategoryId(v.CategoryId).SetAreaId(operation.ToLocationID).First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ if err == nil {
+ operationTransfer := &models.Operation{
+ Number: operation.Number,
+ SourceNumber: operation.SourceNumber,
+ OperationTypeId: 0,
+ OperationTypeName: operation.OperationTypeName,
+ Status: constvar.OperationStatus_Finish,
+ FromLocationID: locationRule.AreaId,
+ ToLocationID: locationRule.LocationId,
+ OperationDate: operation.OperationDate,
+ ContacterID: operation.ContacterID,
+ ContacterName: operation.ContacterName,
+ CompanyID: operation.CompanyID,
+ CompanyName: operation.CompanyName,
+ Comment: operation.Comment,
+ BaseOperationType: constvar.BaseOperationTypeInternal,
+ Details: []*models.OperationDetails{
+ {
+ ProductId: v.ID,
+ Amount: value,
+ },
+ },
+ }
+ operationInputs = append(operationInputs, operationTransfer)
+
+ //if err := tx.Create(&operationTransfer).Error; err != nil {
+ // return err
+ //}
+
+ //TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
+ locAmount, err := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(locationRule.LocationId).
+ First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ locAmount.LocationId = locationRule.LocationId
+ locAmount.ProductId = v.ID
+ locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
+ locAmount.Amount = locAmount.Amount.Add(value)
+ if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
+ return res.Error
+ }
+ } else {
+ //TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
+ locAmount, err := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(operation.ToLocationID).
+ First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ locAmount.LocationId = operation.ToLocationID
+ locAmount.ProductId = v.ID
+ locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
+ locAmount.Amount = locAmount.Amount.Add(value)
+ if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
+ return res.Error
+ }
+ }
+ }
+ }
+ if len(operationInputs) > 0 {
+ if err := tx.Create(&operationInputs).Error; err != nil {
+ return err
+ }
+ }
+
+ }
+
+ if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing {
+ for k, v := range listProdt {
+ value, ok := mapProdt[v.ID]
+ if !ok {
+ return errors.New("浜у搧绉嶇被寮傚父")
+ }
+ //todo 婕旂ず娴嬭瘯鏁版嵁
+ data, err := os.ReadFile("conf/input.json")
+ if err != nil {
+ return errors.New("鏂囦欢璇诲彇澶辫触")
+ }
+ m := make(map[string]interface{})
+ err = json.Unmarshal(data, &m)
+ if err != nil {
+ return errors.New("鏍煎紡杞崲澶辫触")
+ }
+ if opa.OpaCheck(c, m, "operation") {
+ if v.Amount.LessThan(value) {
+ return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
+ }
+ }
+ listProdt[k].Amount = listProdt[k].Amount.Sub(value)
+ if err := tx.Save(listProdt[k]).Error; err != nil {
+ return err
+ }
+ locAmount, res := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(operation.ToLocationID).
+ FirstRes()
+ if res.Error != nil {
+ return err
+ }
+ if locAmount.Amount.LessThan(value) {
+ return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String()))
+ }
+ locAmount.Amount = locAmount.Amount.Sub(value)
+ if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil {
+ return err
+ }
+ }
+ }
+
+ if operation.BaseOperationType == constvar.BaseOperationTypeInternal {
+ var operationInputs []*models.Operation
+ for _, v := range listProdt {
+ value, ok := mapProdt[v.ID]
+ if !ok {
+ return errors.New("浜у搧绉嶇被寮傚父")
+ }
+ //listProdt[k].Amount = listProdt[k].Amount.Add(value)
+ //if err := tx.Save(listProdt[k]).Error; err != nil {
+ // return err
+ //}
+ fromLocAmount, res := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(operation.FromLocationID).
+ FirstRes()
+ if res.Error != nil {
+ return err
+ }
+ if fromLocAmount.Amount.LessThan(value) {
+ return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,璋冩嫧锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愯皟鎷ㄦ搷浣�", v.Name, v.Amount.String(), value.String()))
+ }
+ fromLocAmount.Amount = fromLocAmount.Amount.Sub(value)
+ if err := models.NewLocationProductAmountSearch().SetID(fromLocAmount.Id).Update(fromLocAmount); err != nil {
+ return err
+ }
+
+ locationRule, err := models.NewLocationProductSearch().SetProductId(v.ID).SetAreaId(operation.ToLocationID).First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+
+ if err == nil {
+ operationTransfer := &models.Operation{
+ Number: operation.Number,
+ SourceNumber: operation.SourceNumber,
+ OperationTypeId: 0,
+ OperationTypeName: operation.OperationTypeName,
+ Status: constvar.OperationStatus_Finish,
+ FromLocationID: locationRule.AreaId,
+ ToLocationID: locationRule.LocationId,
+ OperationDate: operation.OperationDate,
+ ContacterID: operation.ContacterID,
+ ContacterName: operation.ContacterName,
+ CompanyID: operation.CompanyID,
+ CompanyName: operation.CompanyName,
+ Comment: operation.Comment,
+ BaseOperationType: constvar.BaseOperationTypeInternal,
+ Details: []*models.OperationDetails{
+ {
+ ProductId: v.ID,
+ Amount: value,
+ },
+ },
+ }
+ operationInputs = append(operationInputs, operationTransfer)
+
+ //if err := tx.Create(&operationTransfer).Error; err != nil {
+ // return err
+ //}
+
+ locAmount, err := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(locationRule.LocationId).
+ First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ locAmount.LocationId = locationRule.LocationId
+ locAmount.ProductId = v.ID
+ locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
+ locAmount.Amount = locAmount.Amount.Add(value)
+ if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
+ return res.Error
+ }
+ } else {
+ locationRule, err = models.NewLocationProductSearch().SetProductCategoryId(v.CategoryId).SetAreaId(operation.ToLocationID).First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ if err == nil {
+ operationTransfer := &models.Operation{
+ Number: operation.Number,
+ SourceNumber: operation.SourceNumber,
+ OperationTypeId: 0,
+ OperationTypeName: operation.OperationTypeName,
+ Status: constvar.OperationStatus_Finish,
+ FromLocationID: locationRule.AreaId,
+ ToLocationID: locationRule.LocationId,
+ OperationDate: operation.OperationDate,
+ ContacterID: operation.ContacterID,
+ ContacterName: operation.ContacterName,
+ CompanyID: operation.CompanyID,
+ CompanyName: operation.CompanyName,
+ Comment: operation.Comment,
+ BaseOperationType: constvar.BaseOperationTypeInternal,
+ Details: []*models.OperationDetails{
+ {
+ ProductId: v.ID,
+ Amount: value,
+ },
+ },
+ }
+ operationInputs = append(operationInputs, operationTransfer)
+
+ //if err := tx.Create(&operationTransfer).Error; err != nil {
+ // return err
+ //}
+
+ locAmount, err := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(locationRule.LocationId).
+ First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ locAmount.LocationId = locationRule.LocationId
+ locAmount.ProductId = v.ID
+ locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
+ locAmount.Amount = locAmount.Amount.Add(value)
+ if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
+ return res.Error
+ }
+ } else {
+ locAmount, err := models.NewLocationProductAmountSearch().
+ SetProductId(v.ID).
+ SetLocationId(operation.ToLocationID).
+ First()
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ return err
+ }
+ locAmount.LocationId = operation.ToLocationID
+ locAmount.ProductId = v.ID
+ locAmount.CreateDate = time.Now().Format("2006-01-02 15:04:05")
+ locAmount.Amount = locAmount.Amount.Add(value)
+ if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
+ return res.Error
+ }
+ }
+ }
+ }
+ if len(operationInputs) > 0 {
+ if err := tx.Create(&operationInputs).Error; err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+ }); err != nil {
+ util.ResponseFormat(c, code.RequestError, err.Error())
+ return
+ }
+ if operation.SourceNumber != "" {
+ go UpdateSalesDetailStatus(c, operation.SourceNumber)
+ }
util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛")
}
diff --git a/docs/docs.go b/docs/docs.go
index 31880ec..a25619b 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -3996,6 +3996,13 @@
"id": {
"type": "integer"
},
+ "logisticCompanyId": {
+ "type": "string"
+ },
+ "logisticWeight": {
+ "description": "鐗╂祦閲嶉噺",
+ "type": "number"
+ },
"number": {
"description": "鍗曞彿",
"type": "string"
@@ -4027,6 +4034,14 @@
"toLocationId": {
"description": "鐩爣浣嶇疆id",
"type": "integer"
+ },
+ "waybillNumber": {
+ "description": "杩愬崟鍙�",
+ "type": "string"
+ },
+ "weight": {
+ "description": "閲嶉噺",
+ "type": "number"
}
}
},
diff --git a/docs/swagger.json b/docs/swagger.json
index a3b9b1e..58a7953 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -3984,6 +3984,13 @@
"id": {
"type": "integer"
},
+ "logisticCompanyId": {
+ "type": "string"
+ },
+ "logisticWeight": {
+ "description": "鐗╂祦閲嶉噺",
+ "type": "number"
+ },
"number": {
"description": "鍗曞彿",
"type": "string"
@@ -4015,6 +4022,14 @@
"toLocationId": {
"description": "鐩爣浣嶇疆id",
"type": "integer"
+ },
+ "waybillNumber": {
+ "description": "杩愬崟鍙�",
+ "type": "string"
+ },
+ "weight": {
+ "description": "閲嶉噺",
+ "type": "number"
}
}
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index b36a994..00a3b09 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1267,6 +1267,11 @@
type: integer
id:
type: integer
+ logisticCompanyId:
+ type: string
+ logisticWeight:
+ description: 鐗╂祦閲嶉噺
+ type: number
number:
description: 鍗曞彿
type: string
@@ -1289,6 +1294,12 @@
toLocationId:
description: 鐩爣浣嶇疆id
type: integer
+ waybillNumber:
+ description: 杩愬崟鍙�
+ type: string
+ weight:
+ description: 閲嶉噺
+ type: number
type: object
request.UpdateOperationType:
properties:
--
Gitblit v1.8.0