From 9d296a1c658c19c6faa51dfef31d025e59a480cb Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 02 七月 2024 12:02:45 +0800
Subject: [PATCH] 按仓库统计月度报表下载接口
---
controllers/location_product.go | 98 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 84 insertions(+), 14 deletions(-)
diff --git a/controllers/location_product.go b/controllers/location_product.go
index 07d012b..6089724 100644
--- a/controllers/location_product.go
+++ b/controllers/location_product.go
@@ -1,8 +1,11 @@
package controllers
import (
+ "errors"
"github.com/gin-gonic/gin"
+ "gorm.io/gorm"
"strconv"
+ "wms/constvar"
"wms/extend/code"
"wms/extend/util"
"wms/models"
@@ -40,14 +43,44 @@
util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浣嶇疆")
return
}
- if params.ProductId == "" {
- util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧")
+
+ if params.RuleType != constvar.RuleType_Product && params.RuleType != constvar.RuleType_ProductCategory {
+ util.ResponseFormat(c, code.RequestParamError, "ruleType寮傚父")
return
}
- if params.ProductCategoryID == 0 {
- util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧绫诲埆")
- return
+
+ if params.RuleType == constvar.RuleType_Product {
+ if params.ProductId == "" {
+ util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧")
+ return
+ }
+ if _, err := models.NewLocationProductSearch().SetProductId(params.ProductId).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil {
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ } else {
+ util.ResponseFormat(c, code.RequestParamError, "宸插瓨鍦ㄨ涓婂瑙勫垯锛岃鍕块噸澶嶆坊鍔�")
+ return
+ }
}
+
+ if params.RuleType == constvar.RuleType_ProductCategory {
+ if params.ProductCategoryID == 0 {
+ util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧绫诲埆")
+ return
+ }
+ if _, err := models.NewLocationProductSearch().SetProductCategoryId(params.ProductCategoryID).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil {
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ } else {
+ util.ResponseFormat(c, code.RequestParamError, "宸插瓨鍦ㄨ涓婂瑙勫垯锛岃鍕块噸澶嶆坊鍔�")
+ return
+ }
+ }
+
if err := models.NewLocationProductSearch().Create(¶ms); err != nil {
logx.Errorf("Operation create err: %v", err)
util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error())
@@ -64,18 +97,26 @@
// @Success 200 {object} util.Response "鎴愬姛"
// @Router /api-wms/v1/locationProduct/list [post]
func (slf LocationProductController) List(c *gin.Context) {
- var params request.PageInfo
+ var params request.QueryLocationProductConditon
if err := c.BindJSON(¶ms); err != nil {
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�:"+err.Error())
return
}
- if params.Check() {
+ if !params.Check() {
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟寮傚父")
return
}
search := models.NewLocationProductSearch()
search.SetPage(params.Page, params.PageSize)
+
+ if params.ProductId != "" {
+ search = search.SetProductId(params.ProductId)
+ }
+
+ if params.ProductCategoryId != 0 {
+ search = search.SetProductCategoryId(params.ProductCategoryId)
+ }
list, total, err := search.SetPreload(true).SetOrder("created_at desc").FindByPage()
if err != nil {
util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触:"+err.Error())
@@ -89,7 +130,7 @@
// @Tags 涓婃灦瑙勫垯
// @Summary 淇敼涓婃灦瑙勫垯
// @Produce application/json
-// @Param object body request.UpdateLocationProduct true "鍏ュ簱淇℃伅"
+// @Param object body request.UpdateLocationProduct true "淇敼鍙傛暟"
// @Success 200 {object} util.Response "鎴愬姛"
// @Router /api-wms/v1/locationProduct/update [post]
func (slf LocationProductController) Update(c *gin.Context) {
@@ -115,14 +156,44 @@
util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浣嶇疆")
return
}
- if params.ProductId == "" {
- util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧")
+
+ if params.RuleType != constvar.RuleType_Product && params.RuleType != constvar.RuleType_ProductCategory {
+ util.ResponseFormat(c, code.RequestParamError, "ruleType寮傚父")
return
}
- if params.ProductCategoryID == 0 {
- util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧绫诲埆")
- return
+
+ if params.RuleType == constvar.RuleType_Product {
+ if params.ProductId == "" {
+ util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧")
+ return
+ }
+ if rule, err := models.NewLocationProductSearch().SetProductId(params.ProductId).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil {
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ } else if params.Id != rule.Id {
+ util.ResponseFormat(c, code.RequestParamError, "宸插瓨鍦ㄨ涓婂瑙勫垯锛岃鍕块噸澶嶆坊鍔�")
+ return
+ }
}
+
+ if params.RuleType == constvar.RuleType_ProductCategory {
+ if params.ProductCategoryID == 0 {
+ util.ResponseFormat(c, code.RequestParamError, "璇烽�夋嫨浜у搧绫诲埆")
+ return
+ }
+ if rule, err := models.NewLocationProductSearch().SetProductCategoryId(params.ProductCategoryID).SetLocationId(params.LocationId).SetAreaId(params.AreaId).First(); err != nil {
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ } else if params.Id != rule.Id {
+ util.ResponseFormat(c, code.RequestParamError, "宸插瓨鍦ㄨ涓婂瑙勫垯锛岃鍕块噸澶嶆坊鍔�")
+ return
+ }
+ }
+
if err := models.NewLocationProductSearch().SetID(params.Id).Update(¶ms); err != nil {
logx.Errorf("LocationProduct update err: %v", err)
util.ResponseFormat(c, code.SaveFail, "淇敼澶辫触锛�"+err.Error())
@@ -150,7 +221,6 @@
util.ResponseFormat(c, code.RequestParamError, "id涓�0")
return
}
- //TODO:姝ゅ鍙兘闇�瑕佸鍔犻檺鍒讹紝濡傛灉璇ヤ笂鏋惰鍒欏鏋滃凡缁忎骇鐢熶簡搴撳瓨鏁伴噺锛屽垹闄や細閫犳垚搴撳瓨鏌ヤ笉鍒扮殑褰卞搷
if err := models.NewLocationProductSearch().SetID(id).Delete(); err != nil {
logx.Errorf("LocationProduct delete err: %v", err)
util.ResponseFormat(c, code.SaveFail, "鍒犻櫎澶辫触锛�"+err.Error())
--
Gitblit v1.8.0