package repository

import (
	"path"
	"strings"
	"testData/global"
	"testData/model"
)

func SaiMeiKe() {
	// 赛美科
	var fileTexts []*model.FileText
	global.PostGreSQL.
		Where("factory = ?", "saimeike").Find(&fileTexts)
	for _, fileText := range fileTexts {
		//fileText.Name = strings.ToLower(fileText.Name)
		//if path.Ext(fileText.Name) != ".csv" && path.Ext(fileText.Name) != ".xls" && path.Ext(fileText.Name) != ".xlsx" {
		//	continue
		//}
		if strings.ToLower(path.Ext(fileText.Name)) != ".csv" &&
			strings.ToLower(path.Ext(fileText.Name)) != ".xls" && strings.ToLower(path.Ext(fileText.Name)) != ".xlsx" {
			continue
		}
		var step string
		if len(fileText.Name) > 8 {
			if fileText.Name[len(fileText.Name)-7:] == "cp1.csv" {
				step = "CP1"
			} else if fileText.Name[len(fileText.Name)-7:] == "cp2.csv" {
				step = "CP2"
			}
		}
		messages := strings.Split(fileText.Name, "_")
		if len(messages) >= 3 {
			if strings.Contains(messages[2], "r") {
				step = "RT"
			} else if strings.Contains(messages[2], "t") {
				step = "FT"
			}
		}
		if step == "" {
			continue
		}
		HandleSTS8200Excel(fileText, step)
	}
}
