From 2716487d13f3521adeb25a48aa07a89f885d32c7 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期一, 09 十月 2023 09:36:08 +0800 Subject: [PATCH] 仓库功能修改 --- controllers/location_product_amount.go | 78 +++++++++++++++++++++++++++----------- 1 files changed, 55 insertions(+), 23 deletions(-) diff --git a/controllers/location_product_amount.go b/controllers/location_product_amount.go index 2d76187..8d44349 100644 --- a/controllers/location_product_amount.go +++ b/controllers/location_product_amount.go @@ -12,6 +12,7 @@ "wms/extend/util" "wms/models" "wms/request" + "wms/response" ) type LocationProductAmountController struct { @@ -41,6 +42,7 @@ search.Orm = search.Orm. Table("wms_location_product_amount"). Select(` + wms_location_product_amount.id as location_product_amount_id, wms_location.id as location_id, wms_location.name as location_name, material.id as product_id, @@ -49,14 +51,13 @@ material.unit, wms_location_product_amount.create_date, wms_operation_details.amount as adjust_amount, - wms_operation.id as operation_id`). + wms_operation.id as operation_id, + wms_operation.status`). InnerJoins("inner join wms_location_product on wms_location_product.id=wms_location_product_amount.location_product_id"). + InnerJoins("inner join material on material.id=wms_location_product.product_id"). InnerJoins("inner join wms_location on wms_location.id=wms_location_product.location_id"). - InnerJoins("inner join wms_operation_details on wms_operation_details.product_id=wms_location_product.product_id"). - InnerJoins("inner join material on material.id=wms_operation_details.product_id"). - InnerJoins("inner join wms_operation on wms_operation.id=wms_operation_details.operation_id"). - Where("wms_operation.base_operation_type=?", constvar.BaseOperationTypeAdjust) - + Joins("left join wms_operation_details on wms_operation_details.product_id=wms_location_product.product_id"). + Joins("left join wms_operation on wms_operation.id=wms_operation_details.operation_id and wms_operation.base_operation_type=? and wms_operation.status=?", constvar.BaseOperationTypeAdjust, constvar.OperationStatus_Ready) var ( records = make([]*models.LocationProductAmountWithOperation, 0) total int64 @@ -70,12 +71,14 @@ if params.Page*params.PageSize > 0 { search.Orm = search.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize) } - if err := search.Orm.Find(&records).Error; err != nil { + if err := search.Orm.Order("wms_operation.created_at desc").Find(&records).Error; err != nil { util.ResponseFormat(c, code.RequestError, fmt.Errorf("find count err: %v", err)) return } for k, v := range records { - records[k].DifferenceAmount = v.Amount.Sub(v.AdjustAmount) + if v.OperationId != 0 { + records[k].DifferenceAmount = v.Amount.Add(v.AdjustAmount) + } } util.ResponseFormatListWithPage(c, code.Success, records, int(total), params.Page, params.PageSize) } @@ -121,6 +124,11 @@ util.ResponseFormat(c, code.RequestError, "涓嶅瓨鍦ㄨ涓婃灦瑙勫垯锛屾棤娉曡繘琛屽簱瀛樼洏鐐�") return } + existAmount, err := models.NewLocationProductAmountSearch().SetLocationProductId(locProduct.Id).First() + if err != nil { + util.ResponseFormat(c, code.RequestError, err.Error()) + return + } location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeAdjust)).First() if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) @@ -128,11 +136,15 @@ } //reqParams.AdjustAmount = reqParams.Amount.Sub(reqParams.DifferenceAmount) reqParams.AdjustAmount = reqParams.DifferenceAmount.Sub(reqParams.Amount) - locAmount := models.LocationProductAmount{ - LocationProductId: locProduct.Id, - Amount: decimal.NewFromInt(0), - CreateDate: time.Now().Format("2006-01-02 15:04:05"), + var locAmount models.LocationProductAmount + if existAmount.Id == 0 { + locAmount = models.LocationProductAmount{ + LocationProductId: locProduct.Id, + Amount: decimal.NewFromInt(0), + CreateDate: time.Now().Format("2006-01-02 15:04:05"), + } } + detail := &models.OperationDetails{ ProductId: reqParams.ProductId, Amount: reqParams.AdjustAmount, @@ -148,20 +160,14 @@ ToLocationID: reqParams.LocationId, } - //if reqParams.AdjustAmount.GreaterThanOrEqual(decimal.NewFromInt(0)) { - // operation.FromLocationID = Location.Id - // operation.ToLocationID = reqParams.LocationId - //} else { - // operation.FromLocationID = reqParams.LocationId - // operation.ToLocationID = Location.Id - //} - if err := models.WithTransaction(func(tx *gorm.DB) error { if err := models.NewOperationSearch().SetOrm(tx).Create(&operation); err != nil { return err } - if err := models.NewLocationProductAmountSearch().SetOrm(tx).Create(&locAmount); err != nil { - return err + if existAmount.Id == 0 { + if err := models.NewLocationProductAmountSearch().SetOrm(tx).Create(&locAmount); err != nil { + return err + } } return nil }); err != nil { @@ -172,7 +178,33 @@ util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛") } -// Add +// GetRuleList +// @Tags 搴撳瓨鐩樼偣 +// @Summary 鑾峰彇涓婃灦瑙勫垯 +// @Produce application/json +// @Param object body request.GetRuleList true "鏌ヨ淇℃伅" +// @Success 200 {object} util.ResponseList{data=[]response.RuleList} "鎴愬姛" +// @Router /api-wms/v1/locationProductAmount/getRuleList [post] +func (slf LocationProductAmountController) GetRuleList(c *gin.Context) { + var params request.GetRuleList + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + list, err := models.NewLocationProductSearch().SetProductId(params.ProductId).SetLocationId(params.LocationId).Find() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + var ruleList response.RuleList + for _, l := range list { + ruleList.LocationList = append(ruleList.LocationList, l.Location) + ruleList.ProductList = append(ruleList.ProductList, l.Product) + } + util.ResponseFormat(c, code.Success, ruleList) +} + +// Update // @Tags 搴撳瓨鐩樼偣 // @Summary 淇敼搴撳瓨鐩樼偣淇℃伅 // @Produce application/json -- Gitblit v1.8.0