SJA工艺
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8 KiB

3 years ago
  1. package lab
  2. import (
  3. "LAPP_SJA_ME/utils"
  4. "LAPP_SJA_ME/web/models"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "log"
  9. "regexp"
  10. "time"
  11. )
  12. // 将项目的SEQ文件解析并存储到表中
  13. func LandProjectSeqMessage()(err error){
  14. for {
  15. var(
  16. rd []os.FileInfo
  17. fi os.FileInfo
  18. edi_file string
  19. matched bool
  20. lab *models.LAB
  21. )
  22. filepath := utils.EnsureDir("doc")
  23. fmt.Printf("doc文件目录:%v",filepath)
  24. if rd, err = ioutil.ReadDir(filepath + "/inbox"); err != nil {
  25. fmt.Printf("inbox文件目录:%v",filepath)
  26. return
  27. }
  28. fmt.Println("===========解析监听中!!!====================>")
  29. for _, fi = range rd {
  30. if fi.IsDir() {
  31. continue
  32. }
  33. edi_file = filepath + "/inbox" + "/" + fi.Name()
  34. // 判断文件的合规性
  35. if matched, err = regexp.MatchString("BMW", fi.Name()); err != nil {
  36. log.Printf("Failed to match EDI file name: %s due to: %v", fi.Name(), err)
  37. return
  38. }
  39. if !matched {
  40. log.Printf("The specified EDI file: %s doesn't match the required name specification!", fi.Name())
  41. os.Rename(edi_file, filepath+"/errbox"+"/"+fi.Name())
  42. return
  43. }
  44. // 解析SEQ文件到字典
  45. lab = &models.LAB{}
  46. if err = models.ParseLabEdi(edi_file, lab); err != nil {
  47. log.Printf("Failed to parse due to: %v", err)
  48. os.Rename(edi_file, filepath+"/errbox"+"/"+fi.Name())
  49. return
  50. }
  51. // 保存SEQ字典到SEQ的临时缓存表
  52. tab := new(models.PlnForecastLanding)
  53. tab.Finr = 100
  54. tab.Adddate = utils.TimeFormat(time.Now(),"yyyyMMdd")
  55. err = tab.SaveParseResult(fi.Name(), lab)
  56. if err != nil {
  57. log.Printf("Failed to save SEQ parse result due to: %v", err)
  58. return
  59. }
  60. // 将文件移到outbox
  61. os.Rename(edi_file, filepath+"/outbox"+"/"+fi.Name())
  62. }
  63. time.Sleep(10*time.Second)
  64. }
  65. }