From 2bfc37cbc679ceb5cef3b714e93ce4ebf55f9512 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期三, 08 十一月 2023 17:24:58 +0800 Subject: [PATCH] 修改缩略图尺寸 config文件覆盖修复 --- controllers/operation.go | 235 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 200 insertions(+), 35 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index c53ead6..5bd16ef 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -1,11 +1,13 @@ package controllers import ( + "encoding/json" "errors" "fmt" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" "gorm.io/gorm" + "os" "sort" "strconv" "time" @@ -13,6 +15,7 @@ "wms/extend/code" "wms/extend/util" "wms/models" + "wms/opa" "wms/pkg/logx" "wms/pkg/structx" "wms/request" @@ -71,7 +74,7 @@ } func CheckDetailsRepeat(details []*models.OperationDetails) bool { - detailIDs := []string{} + var detailIDs []string var tempID string for _, v := range details { detailIDs = append(detailIDs, v.ProductId) @@ -346,7 +349,7 @@ } if operation.BaseOperationType == constvar.BaseOperationTypeIncoming { - operationInputs := []*models.Operation{} + var operationInputs []*models.Operation for k, v := range listProdt { value, ok := mapProdt[v.ID] if !ok { @@ -362,11 +365,12 @@ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return err } + if err == nil { operationTransfer := &models.Operation{ Number: operation.Number, SourceNumber: operation.SourceNumber, - OperationTypeId: operation.OperationTypeId, + OperationTypeId: 0, OperationTypeName: operation.OperationTypeName, Status: constvar.OperationStatus_Finish, FromLocationID: locationRule.AreaId, @@ -377,22 +381,12 @@ CompanyID: operation.CompanyID, CompanyName: operation.CompanyName, Comment: operation.Comment, - BaseOperationType: operation.BaseOperationType, + BaseOperationType: constvar.BaseOperationTypeInternal, Details: []*models.OperationDetails{ - &models.OperationDetails{ + { ProductId: v.ID, Amount: value, }, - }, - } - operationTransfer.Id = 0 - operationTransfer.FromLocationID = locationRule.AreaId - operationTransfer.ToLocationID = locationRule.LocationId - operationTransfer.Status = constvar.OperationStatus_Finish - operationTransfer.Details = []*models.OperationDetails{ - &models.OperationDetails{ - ProductId: v.ID, - Amount: value, }, } operationInputs = append(operationInputs, operationTransfer) @@ -417,20 +411,70 @@ 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() + locationRule, err = models.NewLocationProductSearch().SetProductCategoryId(v.CategoryId).SetAreaId(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 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 + } } } } @@ -448,8 +492,20 @@ if !ok { return errors.New("浜у搧绉嶇被寮傚父") } - if v.Amount.LessThan(value) { - return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String())) + //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 { @@ -471,7 +527,9 @@ } } } + if operation.BaseOperationType == constvar.BaseOperationTypeInternal { + var operationInputs []*models.Operation for _, v := range listProdt { value, ok := mapProdt[v.ID] if !ok { @@ -496,15 +554,122 @@ return err } - toLocAmount, res := models.NewLocationProductAmountSearch(). - SetProductId(v.ID). - SetLocationId(operation.ToLocationID). - FirstRes() - if res.Error != nil { + locationRule, err := models.NewLocationProductSearch().SetProductId(v.ID).SetAreaId(operation.ToLocationID).First() + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return err } - toLocAmount.Amount = toLocAmount.Amount.Add(value) - if err := models.NewLocationProductAmountSearch().SetID(toLocAmount.Id).Update(toLocAmount); err != nil { + + 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 } } -- Gitblit v1.8.0