package repository

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

// ChangDian 长电
func ChangDian() {
	var fileTexts []*model.FileText
	global.PostGreSQL.
		Where("factory = ?", "changdian").
		Where("name LIKE ? OR name LIKE ?", "%FT%", "%RT%").Find(&fileTexts)
	for _, fileText := range fileTexts {
		if path.Ext(fileText.Name) == ".xls" {
			continue
		}
		if strings.Contains(fileText.Name, "FT_MT") || strings.Contains(fileText.Name, "FT_EQC") ||
			strings.Contains(fileText.Name, "FT_GU") || strings.Contains(fileText.Name, "FT_VT") ||
			strings.Contains(fileText.Name, "FT_ET") {
			continue
		}
		file, err := os.Open(fileText.Path)
		if err != nil {
			log.Println(err)
		}
		var step string
		if strings.Contains(fileText.Name, "RT") {
			step = "RT"
		} else {
			step = "FT"
		}
		HandleSTS8200Excel(fileText, step)
		file.Close()
	}
}
