From 12b03fcb2bc0dd9591f4c4007633b33be1458e5e Mon Sep 17 00:00:00 2001 From: jh_peng Date: Tue, 11 Mar 2025 14:21:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E6=9E=90=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=20=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E7=94=9F=E6=88=90PBI=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/test.data/import.go | 10 ++++++++++ repository/test.data/import.go | 25 ++++++++++++++++++++++++- router/import.go | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/api/test.data/import.go b/api/test.data/import.go index db93406..436c8b6 100644 --- a/api/test.data/import.go +++ b/api/test.data/import.go @@ -138,3 +138,13 @@ func (D *ImportService) ImportFinalReportCommit(c *gin.Context) { test_data.ImportFinalReport(&r) response.Ok(c) } + +// @Tags 数据分析平台-导入文件 +// @Summary 初始化PBI +// @Security ApiKeyAuth +// @Produce application/json +// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}" +// @Router /testData/import/initPBI [get] +func (D *ImportService) InitNewPBI(c *gin.Context) { + response.OkWithData(test_data.InitNewPBI(), c) +} diff --git a/repository/test.data/import.go b/repository/test.data/import.go index 56e910f..91f34a2 100644 --- a/repository/test.data/import.go +++ b/repository/test.data/import.go @@ -1,6 +1,12 @@ package test_data import ( + "errors" + "gitee.com/golang-module/carbon/v2" + "github.com/shopspring/decimal" + "gorm.io/gorm" + "strings" + "testData/global" "testData/model" reader2 "testData/repository/report_reader" "testData/request" @@ -31,5 +37,22 @@ func ImportFinalReport(r *request.ImportFinalReport) { reader2.CPYuChengReportReader(r.FilePath) } } - +} + +func InitNewPBI() string { + pbiStart := carbon.Now().Format("Ymd") + var newHandler *model.FileHandled + var pbi string + if errors.Is(global.PostGreSQL.Where("pbi LIKE ?", pbiStart+"%").Order("pbi desc").First(&newHandler).Error, gorm.ErrRecordNotFound) { + after, _ := strings.CutPrefix(newHandler.PBI, pbiStart) + afterDecimal, _ := decimal.NewFromString(after) + pbiSuffix := afterDecimal.Add(decimal.NewFromInt(1)).String() + if len(pbiSuffix) < 4 { + pbiSuffix = strings.Repeat("0", 4-len(pbiSuffix)) + pbiSuffix + } + pbi = pbiStart + pbiSuffix + } else { + return pbiStart + "0001" + } + return pbi } diff --git a/router/import.go b/router/import.go index 21d2159..1dbe787 100644 --- a/router/import.go +++ b/router/import.go @@ -12,5 +12,6 @@ func InitImportRouter(R *gin.RouterGroup) { importGroup.POST("testFile", importService.ImportTestFile) importGroup.POST("finalReport", importService.ImportFinalReport) importGroup.POST("finalReport/commit", importService.ImportFinalReportCommit) + importGroup.GET("initPBI", importService.InitNewPBI) } }