package calloff import ( "github.com/go-xorm/xorm" "leit.com/leit_seat_aps/common" "leit.com/leit_seat_aps/db" "leit.com/leit_seat_aps/service" "path/filepath" "strconv" "time" ) // Calloff 解析的数据对象 type BL_Calloff struct { Custordernr string // 系统内部客户订单号 Oemordernr string // 客户订单号 Calloffnr int Seqmode int Checksequence int Projnr string Partfamilyid string Msgtime string // 消息时间 Swet string // 上线装配时间 Consigneeplant int Consigneecompany int Consumecompany int Consumeplant int Unloadingplace string Vehicleidset string Vehicleid string Edifile string Calloffsortnr int Handlestatus string Cflandtab db.Pln_calloffdata_landing } // Calloff 缓存数据对象定义 type CalloffLandData struct { Projnr string // 项目号 Edifile string // EDI 文件名 Bl_CalloffDict map[string]BL_Calloff // 解析的Calloff对象 cflandtablst []db.Pln_calloffdata_landing // 发运版本消息 } // 加载Calloff文件并将文件中的发运数据解析到字典 func (cfld *CalloffLandData) ReadCalloffData(calloff_file string) (err error) { var ( calloff CALLOFF bl_cf BL_Calloff seq SEQ ediFile string ) // 解析EDI文件 calloff = CALLOFF{} if err = ParseCalloffEdi(calloff_file, &calloff); err != nil { return } // PrintCalloffEdi(&calloff) // 获取SEQ文件名 _, ediFile = filepath.Split(calloff_file) // 初始化 cfld.Bl_CalloffDict = make(map[string]BL_Calloff) // 遍历 for _, seq = range calloff.SeqList { bl_cf = BL_Calloff{} bl_cf.Calloffnr, _ = strconv.Atoi(calloff.RffCF.CallOffNum) bl_cf.Checksequence, _ = strconv.Atoi(calloff.Bgm.CheckSequence) bl_cf.Partfamilyid = calloff.RffPF.PartFamily bl_cf.Projnr = cfld.Projnr bl_cf.Msgtime = common.Date(calloff.DtmMsg.MsgTime.Unix(), "YYYYMMDDHHmmss") bl_cf.Swet = common.Date(calloff.DtmDelivery.MsgTime.Unix(), "YYYYMMDDHHmmss") bl_cf.Consigneecompany = calloff.Nad.ConsigneeCompany bl_cf.Consigneeplant = calloff.Nad.ConsigneePlant bl_cf.Consumecompany = calloff.Loc.ConsumeCompany bl_cf.Consumeplant = calloff.Loc.ConsumePlant bl_cf.Unloadingplace = calloff.Loc.UnloadingPlace bl_cf.Seqmode = seq.SeqType bl_cf.Oemordernr = seq.Gir.CustOrderNr bl_cf.Vehicleidset = seq.Gir.VehicleIdSet bl_cf.Vehicleid = seq.Gir.VehicleId bl_cf.Edifile = ediFile cfld.Bl_CalloffDict[bl_cf.Oemordernr] = bl_cf } return } // 保存SEQ解析数据 func (cfld *CalloffLandData) SaveCalloffData() (err error) { var ( bl_cf BL_Calloff cflandtab db.Pln_calloffdata_landing session *xorm.Session calloffsortnr string flag bool ) session = db.G_DbEngine.NewSession() defer session.Close() flag = true // 遍历每一条CALLOFF信息,检查是否存在,如果存在则更新它 for _, bl_cf = range cfld.Bl_CalloffDict { // 新建 cflandtab = db.Pln_calloffdata_landing{} cflandtab.Finr = db.G_FINR cflandtab.Oemordernr = bl_cf.Oemordernr cflandtab.Partfamilyid = bl_cf.Partfamilyid if calloffsortnr, err = service.SN_GetNextSnrBySession("SORTNR", session); err != nil { return } cflandtab.Calloffsortnr = common.ValueToInt(calloffsortnr, 0) cflandtab.Calloffnr = bl_cf.Calloffnr cflandtab.Projnr = bl_cf.Projnr cflandtab.Seqmode = bl_cf.Seqmode cflandtab.Swet = bl_cf.Swet cflandtab.Msgtime = bl_cf.Msgtime cflandtab.Checksequence = bl_cf.Checksequence cflandtab.Consigneecompany = bl_cf.Consigneecompany cflandtab.Consigneeplant = bl_cf.Consigneeplant cflandtab.Consumecompany = bl_cf.Consumecompany cflandtab.Consumeplant = bl_cf.Consumeplant cflandtab.Unloadingplace = bl_cf.Unloadingplace cflandtab.Vehicleidset = bl_cf.Vehicleidset cflandtab.Vehicleid = bl_cf.Vehicleid cflandtab.Parsed = 0 // 默认未解析 cflandtab.Edifile = bl_cf.Edifile cflandtab.Handlestatus = "IT" cflandtab.Lastuser = "service" cflandtab.Credatuz = common.Date(time.Now().Unix(), "YYYYMMDDHHmmss") if _, err = session.Insert(cflandtab); err != nil { cferror := db.Pln_calloff_errorlst{} cferror.Finr = db.G_FINR cferror.Calloffnr = cflandtab.Calloffnr cferror.Errortype = common.CALLOFF_CHECK_SEQUENCE cferror.Consumeplant = cflandtab.Consumeplant cferror.Partfamilyid = cflandtab.Partfamilyid cferror.Oemordernr = cflandtab.Oemordernr cferror.Errorstatus = "O" cferror.Errorinfo = err.Error() cferror.Lastmodif = common.TimeFormat(time.Now(), "yyyyMMddHHmmss") cferror.Credatuz = common.TimeFormat(time.Now(), "yyyyMMddHHmmss") cferror.Add() flag = false break } } if flag { session.Commit() } else { session.Rollback() } return }