V0 导入测试文件、测试厂选项

This commit is contained in:
jh_peng 2024-10-12 17:16:09 +08:00
parent 604699048e
commit 055fabba11
12 changed files with 119 additions and 12 deletions

28
api/erp/test.data.go Normal file
View File

@ -0,0 +1,28 @@
package erp
import (
"github.com/gin-gonic/gin"
"testData/model/response"
"testData/repository/erp"
)
type ITestDataService interface {
}
type TestDataService struct{}
func InitTestDataService() *TestDataService {
return &TestDataService{}
}
// @Tags 数据分析平台
// @Summary 测试文件导入-测试厂选项
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// -// @Param data body request.QuerySelection true "查询参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/import/testFile/factorySelection [get]
func (S *TestDataService) FactorySelection(c *gin.Context) {
response.OkWithData(erp.GetFactorySelections(), c)
}

View File

@ -2,6 +2,7 @@ package test_data
import (
"github.com/gin-gonic/gin"
"mime/multipart"
"os"
"path/filepath"
"strings"
@ -36,7 +37,11 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) {
response.FailWithMessage(err.Error(), c)
return
}
files := form.File["file"]
filesMap := form.File
var files []*multipart.FileHeader
for _, v := range filesMap {
files = append(files, v...)
}
if len(form.Value["pbi"]) < 1 {
response.FailWithMessage("缺少PBI名称", c)
return
@ -57,11 +62,22 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) {
return
}
factory := form.Value["factory"][0]
var subBatch string
if len(form.Value["sub_batch"]) < 1 {
response.FailWithMessage("缺少子批次", c)
subBatch = ""
} else {
subBatch = form.Value["sub_batch"][0]
}
if len(form.Value["step"]) < 1 {
response.FailWithMessage("缺少工序", c)
return
}
subBatch := form.Value["sub_batch"][0]
var waferID string
if len(form.Value["wafer_id"]) < 1 {
waferID = ""
} else {
waferID = form.Value["wafer_id"][0]
}
if len(form.Value["step"]) < 1 {
response.FailWithMessage("缺少工序", c)
return
@ -79,7 +95,7 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) {
fileTexts := make([]*model.FileText, 0)
for _, file := range files {
suffix := file.Filename[strings.LastIndex(file.Filename, "."):]
fileName := time.Now().Format("20060102150405") + suffix
fileName := file.Filename[:strings.LastIndex(file.Filename, ".")] + time.Now().Format("20060102150405") + suffix
os.MkdirAll("/testData/siyuanUpload", os.ModePerm)
filePath := filepath.Join("/testData/siyuanUpload", fileName)
if err = c.SaveUploadedFile(file, filePath); err != nil {
@ -94,6 +110,7 @@ func (D *UploadService) UploadAnswerFile(c *gin.Context) {
PBI: pbi,
Lot: lot,
SubBatch: subBatch,
WaferID: waferID,
})
}

View File

@ -32,6 +32,8 @@ func InitRouter() *gin.Engine {
router.InitWarningRouter(testData)
router.InitFinalReportExcelRouter(testData)
router.InitImportRouter(testData)
router.InitTestDataERPRouter(testData)
}
testDataUpload := r.Group("testData")
testDataUploadService := testdata.InitUpload()

View File

@ -1593,3 +1593,18 @@
2024-10-11 14:50:17 INFO | 192.168.0.172 | 200 | 3.3515ms | POST | 未登录 | /testData/upload
2024-10-11 14:50:17 INFO | 192.168.0.172 | 200 | 16.5018ms | POST | 未登录 | /testData/upload
2024-10-11 15:00:15 INFO | 192.168.0.172 | 200 | 9m25.648566s | POST | 未登录 | /testData/upload
2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 1.2534ms | POST | 未登录 | /testData/upload
2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 0s | POST | 未登录 | /testData/upload
2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 540.4µs | POST | 未登录 | /testData/upload
2024-10-12 10:05:41 INFO | 192.168.0.172 | 200 | 3.1513ms | POST | 未登录 | /testData/upload
2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 24.0818ms | POST | 未登录 | /testData/upload
2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 33.3799ms | POST | 未登录 | /testData/upload
2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 39.0893ms | POST | 未登录 | /testData/upload
2024-10-12 10:05:58 INFO | 192.168.0.172 | 200 | 37.9752ms | POST | 未登录 | /testData/upload
2024-10-12 10:17:20 INFO | 192.168.0.172 | 200 | 1m53.7931364s | POST | 未登录 | /testData/upload
2024-10-12 10:18:05 INFO | 192.168.0.172 | 200 | 31.1169547s | POST | 未登录 | /testData/upload
2024-10-12 10:22:49 INFO | 192.168.0.172 | 200 | 4m11.2095059s | POST | 未登录 | /testData/upload
2024-10-12 10:23:19 INFO | 192.168.0.172 | 200 | 19.8354639s | POST | 未登录 | /testData/upload
2024-10-12 10:24:07 INFO | 192.168.0.172 | 200 | 34.1357627s | POST | 未登录 | /testData/upload
2024-10-12 10:25:24 INFO | 192.168.0.172 | 200 | 9.8706437s | POST | 未登录 | /testData/upload
2024-10-12 11:07:57 INFO | 192.168.0.172 | 200 | 3.6585071s | POST | 未登录 | /testData/upload

View File

@ -109,6 +109,7 @@ func (RvvFile) TableName() string { return "rvv_file" }
type PmcFile struct {
Pmc01 string `json:"pmc01"` // 厂商编号
Pmc02 string `json:"pmc02"` // 厂商类型
Pmc03 string `json:"pmc03"` // 厂商名称
}

View File

@ -18,7 +18,8 @@ type FileText struct {
ProductName string `json:"product_name"`
PBI string `json:"pbi"`
Lot string `json:"lot" gorm:"comment:批次号"`
SubBatch string `json:"sub_batch" gorm:"子批次"`
SubBatch string `json:"sub_batch" gorm:"comment:子批次"`
WaferID string `json:"wafer_id" gorm:"comment:片号"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"-"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

View File

@ -184,6 +184,9 @@ func MT737(summary, dataLog *model.FileText, step string) {
log.Println("创建文件失败:", err)
return
}
if summary.WaferID != "" {
waferID = summary.WaferID
}
if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) {
global.PostGreSQL.Create(&model.FileHandled{
Name: fileName,

View File

@ -269,6 +269,9 @@ func HandleSTS8200Excel(fileText *model.FileText, step string) {
log.Println("创建文件失败:", err)
return
}
if fileText.WaferID != "" {
waferID = fileText.WaferID
}
if errors.Is(global.PostGreSQL.Where("name = ?", fileName).First(&fileHandled).Error, gorm.ErrRecordNotFound) {
global.PostGreSQL.Create(&model.FileHandled{
Name: fileName,

View File

@ -205,6 +205,9 @@ func HandlerTQT601Excel(fileText *model.FileText, step string) {
}
details["lot"] = fileText.Name[start+1 : end]
}
if fileText.Lot != "" {
details["lot"] = fileText.Lot
}
testProgram := details["TestProgram"]
fileName := details["product"] + "_" + details["lot"] + "_" + details["Test_Code"] + ".csv"
utils.MakeDir("/testData/test")
@ -225,8 +228,11 @@ func HandlerTQT601Excel(fileText *model.FileText, step string) {
Path: filePath,
Size: "",
Factory: fileText.Factory,
PBI: fileText.PBI,
Product: details["product"],
Step: details["Test_Code"],
//Lot: fileText.Lot,
SubBatch: fileText.SubBatch,
Lot: details["lot"],
TestMachineModel: "TQT601",
TestMachine: details["TesterNO."],
@ -234,6 +240,7 @@ func HandlerTQT601Excel(fileText *model.FileText, step string) {
BeginningTime: details["Beginning Time"],
EndingTime: details["Ending Time"],
TitleInfo: string(titleInfo),
WaferID: fileText.WaferID,
})
}
}

12
repository/erp/erp.go Normal file
View File

@ -0,0 +1,12 @@
package erp
import (
"testData/global"
"testData/model"
)
func GetFactorySelections() []string {
var factories []string
global.Oracle.Model(&model.PmcFile{}).Where("pmc02 IN ?", []string{"AB", "CPFT", "FT"}).Select("pmc03").Find(&factories)
return factories
}

View File

@ -2,6 +2,7 @@ package test_data
import (
"errors"
"sort"
"testData/model"
"testData/repository"
)
@ -10,6 +11,9 @@ func HandleUploadFiles(fileTexts []*model.FileText, step, machine string) error
if step == "" {
return errors.New("未输入工序")
}
sort.Slice(fileTexts, func(i, j int) bool {
return fileTexts[i].Name < fileTexts[j].Name
})
if machine == "STS8200" {
for _, fileText := range fileTexts {
repository.HandleSTS8200Excel(fileText, step)
@ -20,7 +24,7 @@ func HandleUploadFiles(fileTexts []*model.FileText, step, machine string) error
}
} else if machine == "MT737" {
for i := 0; i < len(fileTexts)/2; i++ {
repository.MT737(fileTexts[2*i], fileTexts[2*i+1], step)
repository.MT737(fileTexts[2*i+1], fileTexts[2*i], step)
}
}
return nil

14
router/erp.go Normal file
View File

@ -0,0 +1,14 @@
package router
import (
"github.com/gin-gonic/gin"
test_data "testData/api/erp"
)
func InitTestDataERPRouter(R *gin.RouterGroup) {
testDataService := test_data.InitTestDataService()
testDataGroup := R.Group("")
{
testDataGroup.GET("import/testFile/factorySelection", testDataService.FactorySelection)
}
}