V0 图表参数选项获取(最近三个月文件)

This commit is contained in:
jh_peng 2024-10-17 18:15:23 +08:00
parent d81d1a1946
commit af9de292b0
4 changed files with 30 additions and 16 deletions

View File

@ -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 数据分析平台

View File

@ -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
}

View File

@ -5,4 +5,5 @@ type ChartSelection struct {
EndDate string `json:"end_date"`
Product string `json:"product"`
Lot string `json:"lot"`
Step string `json:"step"`
}

View File

@ -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)
}