From 8d3f2400195b0ae746e51ed4871e2b0ab621c928 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 06 五月 2024 17:24:11 +0800
Subject: [PATCH] 增加月度统计手动执行接口
---
controllers/report_forms_controller.go | 103 ++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 85 insertions(+), 18 deletions(-)
diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go
index 4f3bc71..7c48974 100644
--- a/controllers/report_forms_controller.go
+++ b/controllers/report_forms_controller.go
@@ -11,6 +11,7 @@
"wms/request"
"wms/response"
"wms/service"
+ "wms/task"
)
type ReportFormsController struct {
@@ -32,9 +33,33 @@
// @Router /api-wms/v1/forms/getInventoryForms [post]
func (slf ReportFormsController) GetInventoryForms(c *gin.Context) {
var params request.GetInventoryForms
- if err := c.BindJSON(¶ms); err != nil {
+ err := c.BindJSON(¶ms)
+ if err != nil {
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
return
+ }
+ locationIds := make([]int, 0)
+ productIds := make([]string, 0)
+ productAmounts := make([]*models.LocationProductAmount, 0)
+ if params.WarehouseCode != "" {
+ locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浠撳簱浣嶇疆澶辫触")
+ return
+ }
+
+ for _, location := range locations {
+ locationIds = append(locationIds, location.Id)
+ }
+ productAmounts, err = models.NewLocationProductAmountSearch().SetLocationIds(locationIds).SetQuery("amount > 0").Find()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触")
+ return
+ }
+ for _, amount := range productAmounts {
+ productIds = append(productIds, amount.ProductId)
+ }
+
}
//鏌ヨ浜у搧
search := models.NewMaterialSearch()
@@ -46,6 +71,9 @@
}
if params.KeyWord != "" {
search.Orm.Where("material.name like ?", "%"+params.KeyWord+"%").Or("wms_product_category.name like ?", "%"+params.KeyWord+"%")
+ }
+ if len(productIds) > 0 {
+ search.Orm.Where("material.id in (?)", productIds)
}
var (
materials = make([]*models.Material, 0)
@@ -63,24 +91,16 @@
return
}
- locations, err := models.NewLocationSearch().SetJointName(params.WarehouseCode).FindNotTotal()
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浠撳簱浣嶇疆澶辫触")
- return
- }
- locationIds := make([]int, 0)
- for _, location := range locations {
- locationIds = append(locationIds, location.Id)
- }
//鏌ヨ鍦ㄥ簱鏁伴噺
- productIds := make([]string, 0)
- for _, material := range materials {
- productIds = append(productIds, material.ID)
- }
- productAmounts, err := models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find()
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触")
- return
+ if len(productIds) == 0 {
+ for _, material := range materials {
+ productIds = append(productIds, material.ID)
+ }
+ productAmounts, err = models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触")
+ return
+ }
}
//鏌ヨ鍑哄叆搴撳氨缁暟閲�
@@ -351,3 +371,50 @@
util.ResponseFormatList(c, code.Success, result, int(total))
}
+
+// MonthStats
+// @Tags 鎶ヨ〃
+// @Summary 鏈堝害缁熻搴撳瓨鎶ヨ〃
+// @Produce application/json
+// @Param object body request.GetMonthStats true "鏌ヨ鍙傛暟"
+// @Param Authorization header string true "token"
+// @Success 200 {object} util.ResponseList{data=[]models.MonthStats} "鎴愬姛"
+// @Router /api-wms/v1/forms/monthStats [post]
+func (slf ReportFormsController) MonthStats(c *gin.Context) {
+ var params request.GetMonthStats
+ if err := c.BindJSON(¶ms); err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ return
+ }
+
+ list, total, err := models.NewMonthStatsSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetDate(params.Date).Find()
+ if err != nil {
+ util.ResponseFormat(c, code.InternalError, "鏌ヨ澶辫触")
+ return
+ }
+
+ util.ResponseFormatList(c, code.Success, list, int(total))
+}
+
+// DoMonthStats
+// @Tags 鎶ヨ〃
+// @Summary 鎵嬪姩璺戞湀搴︾粺璁″簱瀛樻姤琛�
+// @Produce application/json
+// @Param object body request.DoMonthStats true "鏌ヨ鍙傛暟"
+// @Param Authorization header string true "token"
+// @Success 200 {object} util.ResponseList{data=[]models.MonthStats} "鎴愬姛"
+// @Router /api-wms/v1/forms/doMonthStats [post]
+func (slf ReportFormsController) DoMonthStats(c *gin.Context) {
+ var params request.DoMonthStats
+ if err := c.BindJSON(¶ms); err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
+ return
+ }
+
+ if params.Token != constvar.DoMonthStatsToken {
+ return
+ }
+
+ task.MonthStats()
+ util.ResponseFormat(c, code.Success, nil)
+}
--
Gitblit v1.8.0