SJA APS后端代码
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.

157 lines
4.7 KiB

  1. package calloff
  2. import (
  3. "github.com/go-xorm/xorm"
  4. "leit.com/leit_seat_aps/common"
  5. "leit.com/leit_seat_aps/db"
  6. "leit.com/leit_seat_aps/service"
  7. "path/filepath"
  8. "strconv"
  9. "time"
  10. )
  11. // Calloff 解析的数据对象
  12. type BL_Calloff struct {
  13. Custordernr string // 系统内部客户订单号
  14. Oemordernr string // 客户订单号
  15. Calloffnr int
  16. Seqmode int
  17. Checksequence int
  18. Projnr string
  19. Partfamilyid string
  20. Msgtime string // 消息时间
  21. Swet string // 上线装配时间
  22. Consigneeplant int
  23. Consigneecompany int
  24. Consumecompany int
  25. Consumeplant int
  26. Unloadingplace string
  27. Vehicleidset string
  28. Vehicleid string
  29. Edifile string
  30. Calloffsortnr int
  31. Handlestatus string
  32. Cflandtab db.Pln_calloffdata_landing
  33. }
  34. // Calloff 缓存数据对象定义
  35. type CalloffLandData struct {
  36. Projnr string // 项目号
  37. Edifile string // EDI 文件名
  38. Bl_CalloffDict map[string]BL_Calloff // 解析的Calloff对象
  39. cflandtablst []db.Pln_calloffdata_landing // 发运版本消息
  40. }
  41. // 加载Calloff文件并将文件中的发运数据解析到字典
  42. func (cfld *CalloffLandData) ReadCalloffData(calloff_file string) (err error) {
  43. var (
  44. calloff CALLOFF
  45. bl_cf BL_Calloff
  46. seq SEQ
  47. ediFile string
  48. )
  49. // 解析EDI文件
  50. calloff = CALLOFF{}
  51. if err = ParseCalloffEdi(calloff_file, &calloff); err != nil {
  52. return
  53. }
  54. // PrintCalloffEdi(&calloff)
  55. // 获取SEQ文件名
  56. _, ediFile = filepath.Split(calloff_file)
  57. // 初始化
  58. cfld.Bl_CalloffDict = make(map[string]BL_Calloff)
  59. // 遍历
  60. for _, seq = range calloff.SeqList {
  61. bl_cf = BL_Calloff{}
  62. bl_cf.Calloffnr, _ = strconv.Atoi(calloff.RffCF.CallOffNum)
  63. bl_cf.Checksequence, _ = strconv.Atoi(calloff.Bgm.CheckSequence)
  64. bl_cf.Partfamilyid = calloff.RffPF.PartFamily
  65. bl_cf.Projnr = cfld.Projnr
  66. bl_cf.Msgtime = common.Date(calloff.DtmMsg.MsgTime.Unix(), "YYYYMMDDHHmmss")
  67. bl_cf.Swet = common.Date(calloff.DtmDelivery.MsgTime.Unix(), "YYYYMMDDHHmmss")
  68. bl_cf.Consigneecompany = calloff.Nad.ConsigneeCompany
  69. bl_cf.Consigneeplant = calloff.Nad.ConsigneePlant
  70. bl_cf.Consumecompany = calloff.Loc.ConsumeCompany
  71. bl_cf.Consumeplant = calloff.Loc.ConsumePlant
  72. bl_cf.Unloadingplace = calloff.Loc.UnloadingPlace
  73. bl_cf.Seqmode = seq.SeqType
  74. bl_cf.Oemordernr = seq.Gir.CustOrderNr
  75. bl_cf.Vehicleidset = seq.Gir.VehicleIdSet
  76. bl_cf.Vehicleid = seq.Gir.VehicleId
  77. bl_cf.Edifile = ediFile
  78. cfld.Bl_CalloffDict[bl_cf.Oemordernr] = bl_cf
  79. }
  80. return
  81. }
  82. // 保存SEQ解析数据
  83. func (cfld *CalloffLandData) SaveCalloffData() (err error) {
  84. var (
  85. bl_cf BL_Calloff
  86. cflandtab db.Pln_calloffdata_landing
  87. session *xorm.Session
  88. calloffsortnr string
  89. flag bool
  90. )
  91. session = db.G_DbEngine.NewSession()
  92. defer session.Close()
  93. flag = true
  94. // 遍历每一条CALLOFF信息,检查是否存在,如果存在则更新它
  95. for _, bl_cf = range cfld.Bl_CalloffDict {
  96. // 新建
  97. cflandtab = db.Pln_calloffdata_landing{}
  98. cflandtab.Finr = db.G_FINR
  99. cflandtab.Oemordernr = bl_cf.Oemordernr
  100. cflandtab.Partfamilyid = bl_cf.Partfamilyid
  101. if calloffsortnr, err = service.SN_GetNextSnrBySession("SORTNR", session); err != nil {
  102. return
  103. }
  104. cflandtab.Calloffsortnr = common.ValueToInt(calloffsortnr, 0)
  105. cflandtab.Calloffnr = bl_cf.Calloffnr
  106. cflandtab.Projnr = bl_cf.Projnr
  107. cflandtab.Seqmode = bl_cf.Seqmode
  108. cflandtab.Swet = bl_cf.Swet
  109. cflandtab.Msgtime = bl_cf.Msgtime
  110. cflandtab.Checksequence = bl_cf.Checksequence
  111. cflandtab.Consigneecompany = bl_cf.Consigneecompany
  112. cflandtab.Consigneeplant = bl_cf.Consigneeplant
  113. cflandtab.Consumecompany = bl_cf.Consumecompany
  114. cflandtab.Consumeplant = bl_cf.Consumeplant
  115. cflandtab.Unloadingplace = bl_cf.Unloadingplace
  116. cflandtab.Vehicleidset = bl_cf.Vehicleidset
  117. cflandtab.Vehicleid = bl_cf.Vehicleid
  118. cflandtab.Parsed = 0 // 默认未解析
  119. cflandtab.Edifile = bl_cf.Edifile
  120. cflandtab.Handlestatus = "IT"
  121. cflandtab.Lastuser = "service"
  122. cflandtab.Credatuz = common.Date(time.Now().Unix(), "YYYYMMDDHHmmss")
  123. if _, err = session.Insert(cflandtab); err != nil {
  124. cferror := db.Pln_calloff_errorlst{}
  125. cferror.Finr = db.G_FINR
  126. cferror.Calloffnr = cflandtab.Calloffnr
  127. cferror.Errortype = common.CALLOFF_CHECK_SEQUENCE
  128. cferror.Consumeplant = cflandtab.Consumeplant
  129. cferror.Partfamilyid = cflandtab.Partfamilyid
  130. cferror.Oemordernr = cflandtab.Oemordernr
  131. cferror.Errorstatus = "O"
  132. cferror.Errorinfo = err.Error()
  133. cferror.Lastmodif = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
  134. cferror.Credatuz = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
  135. cferror.Add()
  136. flag = false
  137. break
  138. }
  139. }
  140. if flag {
  141. session.Commit()
  142. } else {
  143. session.Rollback()
  144. }
  145. return
  146. }