package seq
|
|
|
|
import (
|
|
"github.com/go-xorm/xorm"
|
|
"leit.com/leit_seat_aps/common"
|
|
"leit.com/leit_seat_aps/db"
|
|
"log"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
// SEQ 解析的数据对象
|
|
type BL_Seq struct {
|
|
Custordernr string // 系统内部客户订单号
|
|
Oemordernr string // 客户订单号
|
|
Projnr string // 项目号
|
|
SeqType int // 3=新建;1=变更;2=取消
|
|
Edifile string // EDI 文件名
|
|
Vin string // 车身号
|
|
Swet string // 交付时间
|
|
Oemseq string // 排序号(10位)
|
|
Partfamilyid string // 零件族
|
|
Assemblyline string // 客户装配线
|
|
Unloadingpoint string // 客户卸货点
|
|
Seqdatatab db.Pln_seqdata_landing
|
|
}
|
|
|
|
// SEQ 缓存数据对象定义
|
|
type SeqLandData struct {
|
|
Projnr string // 项目号
|
|
Edifile string // EDI 文件名
|
|
Bl_SeqDict map[string]BL_Seq // 解析的SEQ订单对象
|
|
Seqlandtab []db.Pln_seqdata_landing // 排序版本消息
|
|
}
|
|
|
|
// 加载SEQ文件并将文件中的客户订单数据解析到客户订单字典
|
|
func (bls *SeqLandData) ReadSeqData(seq_file string) (err error) {
|
|
var (
|
|
sequence SEQUENCE
|
|
seq SEQ
|
|
bl_seq BL_Seq
|
|
ediFile string
|
|
)
|
|
|
|
// 解析EDI文件
|
|
sequence = SEQUENCE{}
|
|
if err = ParseSeqEdi(seq_file, &sequence); err != nil {
|
|
log.Printf("Failed to load SEQ file: %s due to: %v", seq_file, err)
|
|
return
|
|
}
|
|
// PrintSeqEdi(&sequence)
|
|
|
|
// 获取SEQ文件名
|
|
_, ediFile = filepath.Split(seq_file)
|
|
|
|
// 初始化
|
|
bls.Bl_SeqDict = make(map[string]BL_Seq)
|
|
|
|
// 遍历
|
|
for _, seq = range sequence.SeqList {
|
|
bl_seq = BL_Seq{}
|
|
bl_seq.Oemordernr = seq.Gir.CustOrderNr
|
|
bl_seq.SeqType = seq.SeqType
|
|
bl_seq.Edifile = ediFile
|
|
bl_seq.Projnr = bls.Projnr
|
|
bl_seq.Oemseq = seq.SeqNum
|
|
bl_seq.Vin = seq.Gir.Vin
|
|
bl_seq.Partfamilyid = sequence.Ftx.PartFamily
|
|
bl_seq.Assemblyline = seq.Loc44.AssemblyLine
|
|
bl_seq.Unloadingpoint = seq.Loc83.UnloadingPoint
|
|
bl_seq.Swet = common.Date(seq.Dtm.MsgTime.Unix(), "YYYYMMDDHHmmss")
|
|
bls.Bl_SeqDict[bl_seq.Oemordernr] = bl_seq
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 保存SEQ解析数据
|
|
func (bls *SeqLandData) SaveSeqData() (err error) {
|
|
var (
|
|
bl_seq BL_Seq
|
|
version int
|
|
seqlandtab db.Pln_seqdata_landing
|
|
session *xorm.Session
|
|
flag bool
|
|
)
|
|
// 遍历每一条SEQ信息,检查是否存在,如果存在则更新它
|
|
session = db.G_DbEngine.NewSession()
|
|
defer session.Close()
|
|
flag = true
|
|
for _, bl_seq = range bls.Bl_SeqDict {
|
|
// 新建
|
|
seqlandtab = db.Pln_seqdata_landing{}
|
|
seqlandtab.Finr = db.G_FINR
|
|
seqlandtab.Oemordernr = bl_seq.Oemordernr
|
|
seqlandtab.Vin = bl_seq.Vin
|
|
seqlandtab.Partfamilyid = bl_seq.Partfamilyid
|
|
seqlandtab.Projnr = bl_seq.Projnr
|
|
// 基于OEM订单号和零件组获取SEQ数据最新版本号
|
|
if version, err = seqlandtab.GetLatestVersionBySession(session); err != nil {
|
|
flag = false
|
|
break
|
|
}
|
|
seqlandtab.Version = version + 1
|
|
seqlandtab.Seqmode = bl_seq.SeqType
|
|
seqlandtab.Oemseq= common.ValueToFloat(bl_seq.Oemseq,0.0)
|
|
if seqlandtab.Oemseq <= 0 {
|
|
seqlandtab.Oemseq = 9999999999
|
|
}
|
|
seqlandtab.Swet = bl_seq.Swet
|
|
|
|
seqlandtab.Assemblyline = bl_seq.Assemblyline
|
|
seqlandtab.Unloadingpoint = bl_seq.Unloadingpoint
|
|
seqlandtab.Parsed = 0 // 默认未解析
|
|
seqlandtab.Edifile = bl_seq.Edifile
|
|
seqlandtab.Lastuser = "service"
|
|
seqlandtab.Credatuz = common.Date(time.Now().Unix(), "YYYYMMDDHHmmss")
|
|
if _, err = session.Insert(seqlandtab); err != nil {
|
|
flag = false
|
|
break
|
|
}
|
|
}
|
|
if flag {
|
|
session.Commit()
|
|
} else {
|
|
session.Rollback()
|
|
}
|
|
|
|
return
|
|
}
|