From af9de292b0489391ad1ac350b5b8526de322f572 Mon Sep 17 00:00:00 2001 From: jh_peng Date: Thu, 17 Oct 2024 18:15:23 +0800 Subject: [PATCH] =?UTF-8?q?V0=20=E5=9B=BE=E8=A1=A8=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E8=8E=B7=E5=8F=96(=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E4=B8=89=E4=B8=AA=E6=9C=88=E6=96=87=E4=BB=B6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/test.data/chart.selection.go | 13 +++++++---- repository/test.data/chart.selection.go | 30 ++++++++++++++++--------- request/chart.selection.go | 1 + router/chart.selection.go | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/api/test.data/chart.selection.go b/api/test.data/chart.selection.go index 7c9bb6f..b8fb413 100644 --- a/api/test.data/chart.selection.go +++ b/api/test.data/chart.selection.go @@ -22,12 +22,17 @@ func InitChartSelectionService() *ChartSelectionService { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param step query string true "工序" +// @Param data body request.ChartSelection true "查询参数" // @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}" -// @Router /testData/chart/productSelection [get] +// @Router /testData/chart/productSelection [post] func (S *ChartSelectionService) ProductSelection(c *gin.Context) { - step := c.Query("step") - response.OkWithData(test_data.ProductSelection(step), c) + r := request.ChartSelection{} + _ = c.ShouldBind(&r) + if msg, ok := utils.ValidateInfo2CN(r); !ok { + response.FailWithMessage(msg, c) + return + } + response.OkWithData(test_data.ProductSelection(&r), c) } // @Tags 数据分析平台 diff --git a/repository/test.data/chart.selection.go b/repository/test.data/chart.selection.go index 5e86cf4..ce957c0 100644 --- a/repository/test.data/chart.selection.go +++ b/repository/test.data/chart.selection.go @@ -1,32 +1,40 @@ package test_data import ( - "strings" + "gitee.com/golang-module/carbon/v2" "testData/global" "testData/model" "testData/request" ) -func ProductSelection(step string) []string { +func ProductSelection(r *request.ChartSelection) []string { + now := carbon.Now() + startDate := now.SubMonths(12).Format("Y-m-d") var products []string - if strings.Contains(step, "FT") { - global.PostGreSQL.Model(&model.FTList{}).Group("product").Select("product").Find(&products) - } else if strings.Contains(step, "CP") { - global.PostGreSQL.Model(&model.CPList{}).Group("product").Select("product").Find(&products) - } + global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND created_at BETWEEN Date(?) AND Date(?)", + r.Step, startDate, now.Format("Y-m-d")).Group("product").Select("product").Find(&products) + //if strings.Contains(r.Step, "FT") { + // global.PostGreSQL.Model(&model.FTList{}).Group("product").Select("product").Find(&products) + //} else if strings.Contains(r.Step, "CP") { + // global.PostGreSQL.Model(&model.CPList{}).Group("product").Select("product").Find(&products) + //} return products } func LotSelection(r *request.ChartSelection) []string { + now := carbon.Now() + startDate := now.SubMonths(12).Format("Y-m-d") var lots []string - global.PostGreSQL.Model(&model.FileHandled{}).Where("product = ? AND created_at BETWEEN Date(?) AND Date(?)", - r.Product, r.StartDate, r.EndDate).Group("lot").Select("lot").Find(&lots) + global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND created_at BETWEEN Date(?) AND Date(?)", + r.Step, r.Product, startDate, now.Format("Y-m-d")).Group("lot").Select("lot").Find(&lots) return lots } func PBISelection(r *request.ChartSelection) []string { + now := carbon.Now() + startDate := now.SubMonths(12).Format("Y-m-d") var pbis []string - global.PostGreSQL.Model(&model.FileHandled{}).Where("product = ? AND lot = ? AND created_at BETWEEN Date(?) AND Date(?)", - r.Product, r.Lot, r.StartDate, r.EndDate).Group("pbi").Select("pbi").Find(&pbis) + global.PostGreSQL.Model(&model.FileHandled{}).Where("step = ? AND product = ? AND lot = ? AND created_at BETWEEN Date(?) AND Date(?)", + r.Step, r.Product, r.Lot, startDate, now.Format("Y-m-d")).Group("pbi").Select("pbi").Find(&pbis) return pbis } diff --git a/request/chart.selection.go b/request/chart.selection.go index d16ca10..c18240d 100644 --- a/request/chart.selection.go +++ b/request/chart.selection.go @@ -5,4 +5,5 @@ type ChartSelection struct { EndDate string `json:"end_date"` Product string `json:"product"` Lot string `json:"lot"` + Step string `json:"step"` } diff --git a/router/chart.selection.go b/router/chart.selection.go index 3e5a990..0fc2fef 100644 --- a/router/chart.selection.go +++ b/router/chart.selection.go @@ -9,7 +9,7 @@ func InitChartSelectionRouter(R *gin.RouterGroup) { chartSelectionService := test_data.InitChartSelectionService() chartSelectionGroup := R.Group("chart") { - chartSelectionGroup.GET("productSelection", chartSelectionService.ProductSelection) + chartSelectionGroup.POST("productSelection", chartSelectionService.ProductSelection) chartSelectionGroup.POST("lotSelection", chartSelectionService.LotSelection) chartSelectionGroup.POST("pbiSelection", chartSelectionService.PBISelection) }