|
|
- package lab
-
- import (
- "LAPP_SJA_ME/utils"
- "LAPP_SJA_ME/web/models"
- "fmt"
- "io/ioutil"
- "os"
- "log"
- "regexp"
- "time"
- )
-
- // 将项目的SEQ文件解析并存储到表中
- func LandProjectSeqMessage()(err error){
- for {
- var(
- rd []os.FileInfo
- fi os.FileInfo
- edi_file string
- matched bool
- lab *models.LAB
- )
- filepath := utils.EnsureDir("doc")
- fmt.Printf("doc文件目录:%v",filepath)
- if rd, err = ioutil.ReadDir(filepath + "/inbox"); err != nil {
- fmt.Printf("inbox文件目录:%v",filepath)
- return
- }
- fmt.Println("===========解析监听中!!!====================>")
- for _, fi = range rd {
- if fi.IsDir() {
- continue
- }
-
- edi_file = filepath + "/inbox" + "/" + fi.Name()
-
- // 判断文件的合规性
- if matched, err = regexp.MatchString("BMW", fi.Name()); err != nil {
- log.Printf("Failed to match EDI file name: %s due to: %v", fi.Name(), err)
- return
- }
- if !matched {
- log.Printf("The specified EDI file: %s doesn't match the required name specification!", fi.Name())
- os.Rename(edi_file, filepath+"/errbox"+"/"+fi.Name())
- return
- }
-
- // 解析SEQ文件到字典
- lab = &models.LAB{}
- if err = models.ParseLabEdi(edi_file, lab); err != nil {
- log.Printf("Failed to parse due to: %v", err)
- os.Rename(edi_file, filepath+"/errbox"+"/"+fi.Name())
- return
- }
-
- // 保存SEQ字典到SEQ的临时缓存表
- tab := new(models.PlnForecastLanding)
- tab.Finr = 100
- tab.Adddate = utils.TimeFormat(time.Now(),"yyyyMMdd")
- err = tab.SaveParseResult(fi.Name(), lab)
- if err != nil {
- log.Printf("Failed to save SEQ parse result due to: %v", err)
- return
- }
-
- // 将文件移到outbox
- os.Rename(edi_file, filepath+"/outbox"+"/"+fi.Name())
- }
- time.Sleep(10*time.Second)
- }
- }
|