diff --git a/archive/archive.go b/archive/archive.go index d3a1e46..7be7a75 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -57,10 +57,10 @@ func CustProduct(conf *config.EnvConfig) { err error oneWeek time.Time archive db.Pln_custorder_archive - num int custorders []string oemorders []string ) + //时间控制 //查询缓存记录表 cust, err := archive.SelectAll() @@ -74,41 +74,25 @@ func CustProduct(conf *config.EnvConfig) { } e := db.G_DbEngine data := make([]CustOrders, 0) - oemdataG38 := make([]CustOrders, 0) - oemdataG18 := make([]CustOrders, 0) - //获取七天前的字符串 + + //获取一个月前的字符串 if common.ValueIsEmpty(conf.Day) { - oneWeek = time.Now().AddDate(0, 0, -14) + oneWeek = time.Now().AddDate(0, -1, 0) } else { fmt.Printf("conf.Day is :%v", conf.Day) oneWeek = time.Now().AddDate(0, 0, -conf.Day) } - if common.ValueIsEmpty(conf.Num) { - num = 1000 - } else { - num = conf.Num - } + oneWeekStr := common.TimeFormat(oneWeek, "yyyyMMddHHmmss") - //第一步:查询最近一千条的oemseq;预留G38 - err = e.Table("pln_custorder").Distinct("oemseq").Select("oemseq").Where("finr = ? and status = ? and projnr = ?", db.G_FINR, common.CO_STATUS_CLOSED, "G38").Asc("oemseq").Limit(num).Find(&oemdataG38) - if err != nil { - glog.InfoExtln("调度生成终止", "err : ", err) - return - } - for _, v := range oemdataG38 { - oemorders = append(oemorders, v.Oemseq) - } - //第一步:查询最近一千条的oemseq;预留G18 - err = e.Table("pln_custorder").Distinct("oemseq").Select("oemseq").Where("finr = ? and status = ? and projnr = ?", db.G_FINR, common.CO_STATUS_CLOSED, "G18").Asc("pln_custorder.oemseq").Limit(num).Find(&oemdataG18) - if err != nil { - glog.InfoExtln("调度生成终止", "err : ", err) - return - } - for _, v := range oemdataG18 { - oemorders = append(oemorders, v.Oemseq) - } - //状态必须都是80,时间是14天以前的客户订单(并且预留1000个oemseq订单) - err = e.Table("pln_custorder").Join("INNER", "pln_calloffdata_landing", "pln_calloffdata_landing.finr = pln_custorder.finr and pln_calloffdata_landing.calloffnr = pln_custorder.calloffnr").NotIn("pln_custorder.oemordernr", oemorders).NotIn("pln_custorder.custordernr", custorders).Where("pln_custorder.status = ? and pln_custorder.calloffswet <= ? and pln_calloffdata_landing.parsed = ?", common.CO_STATUS_CLOSED, oneWeekStr, 1).Desc("pln_custorder.oemseq").Limit(10).Find(&data) + + /******** + 联查pln_custorder ,me_project, pln_calloffdata_landing + 导出条件: + 1)pln_custorder的状态必须是80 + 2)me_project的状态必须是激活状态 + 3)pln_calloffdata_landing的状态 parsed = 1, swet < 当前时间-1个月 + **************/ + err = e.Table("pln_custorder").Join("INNER", "me_project", "pln_custorder.finr = me_project.finr and pln_custorder.projnr = me_project.projectid").Join("INNER", "pln_calloffdata_landing", "pln_calloffdata_landing.finr = pln_custorder.finr and pln_calloffdata_landing.calloffnr = pln_custorder.calloffnr").NotIn("pln_custorder.oemordernr", oemorders).NotIn("pln_custorder.custordernr", custorders).Where("pln_custorder.status = ? and pln_calloffdata_landing.swet <= ? and pln_calloffdata_landing.parsed = ? and me_project.enabled = ?", common.CO_STATUS_CLOSED, oneWeekStr, 1, 1).Desc("pln_custorder.oemseq").Limit(10).Find(&data) if err != nil { glog.InfoExtln("调度生成终止", "err : ", err) return @@ -118,8 +102,60 @@ func CustProduct(conf *config.EnvConfig) { time.Sleep(60 * time.Second) continue } else { + //插入缓存表 for _, v := range data { + /******* + 检查这些客户订单的pln_workorder是否已发运,检查方式: + + 1) 只检查pln_workorder.shippable = 1的工单 + + 2) 工单状态是否 >= 80 + + 3) Pln_workorder.packstatus = 1 ,它的包装单状态 >= 80( 通过 jit_packorder_itemlst查询wo的包装单号), 包装单的发运单状态 >= 80(通过jit_shiporder_datalst查询包装单的发运单号) + + 4) Pln_custorder.status >= 80 + + 以上条件满足则往下备份 + ******/ + workOrders := make([]db.Pln_workorder, 0) + err = e.Table("pln_workorder").Where("finr = ? and custordernr = ?", db.G_FINR, v.Custordernr).Find(&workOrders) + if err != nil { + continue + } + + isOk := true + for _, vv := range workOrders { + + if vv.Status < common.CO_STATUS_CLOSED { + isOk = false + break + } + if vv.Shippable != 1 { + isOk = false + break + } + if vv.Packstatus != 1 { + isOk = false + break + } + + //( 通过 jit_packorder_itemlst查询wo的包装单号), 包装单的发运单状态 >= 80(通过jit_shiporder_datalst查询包装单的发运单号) + infoShip := db.Jit_shiporder_datalst{} + ok, err := e.Table("jit_shiporder_datalst").Join("INNER", "jit_packorder_itemlst", "jit_packorder_itemlst.finr = jit_shiporder_datalst.finr and jit_packorder_itemlst.packorderid = jit_shiporder_datalst.packorderid").Where("jit_packorder_itemlst.finr =? and jit_packorder_itemlst.workordernr = ?", db.G_FINR, vv.Workordernr).Get(&infoShip) + if !ok || err != nil { + isOk = false + break + } + if infoShip.Status < common.CO_STATUS_CLOSED { + isOk = false + break + } + } + if !isOk { + //验证不通过 + continue + } common.TrimStruct(&v, v) one := db.Pln_custorder_archive{} one.Finr = db.G_FINR @@ -135,6 +171,7 @@ func CustProduct(conf *config.EnvConfig) { CustOrderChan <- v } } + time.Sleep(60 * time.Second) } @@ -171,6 +208,8 @@ func CustConsume(ctx context.Context) { //go Archive_Pln_seqdata_landing(task) //备份(pln_workorder) go Archive_Pln_workorder(task) + //备份Pln_calloffdata_landing + go Archive_Pln_calloffdata_landing(task) //删除缓存表 archive := new(db.Pln_custorder_archive) archive.Custordernr = task.Custordernr @@ -1374,3 +1413,205 @@ func ArchiveJit_packorder(conf *config.EnvConfig) { time.Sleep(60 * time.Second) } } + +//删除一个礼拜前的打印消息 +func DelPrinterInfo() { + tick := time.Tick(10 * time.Second) + for { + select { + case <-tick: + var ( + err error + oneWeek time.Time + ) + e := db.G_DbEngine + s := db.G_DbSalve + data := make([]db.Printheadtab, 0) + //获取七天前的字符串 + oneWeek = time.Now().AddDate(0, 0, -7) + + oneWeekStr := common.TimeFormat(oneWeek, "yyyyMMddHHmmss") + //查询出订单状态是80,并且是七天前的客户订单的信息,每次查询10条 + + //查询status = 'C' ,并且是七天前的数据 + err = e.Table("printheadtab").Where("finr = ? and status = ? and credatuz < ?", db.G_FINR, "C", oneWeekStr).Limit(50).Find(&data) + if err != nil { + return + } + + if len(data) == 0 { + time.Sleep(60 * time.Second) + continue + } + for _, v := range data { + itemlst := make([]db.Printdetailtab, 0) + //转义为json + jsondata, err := json.Marshal(&v) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "printheadtab" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据printheadtab", "err:", err.Error()) + return + } + //判断是否需要备份 + if v.Printobjtype == "BBAASN" { + //备份数据 + InfoLog := new(db.TableDataInfoLog) + InfoLog.Servername = "Archive_printheadtab" + InfoLog.Tablename = "printheadtab" + InfoLog.Pkname = v.Printheadid + InfoLog.Message = string(jsondata) + InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss") + InfoLog.InsertRecord() + //导出 + _, err = s.Table("printheadtab").Insert(&v) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "printheadtab" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据printheadtab", "err:", err.Error()) + continue + } + + //查询(printdetailtab) + err = e.Table("printdetailtab").Where("finr = ? and printheadid = ?", db.G_FINR, v.Printheadid).Find(&itemlst) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "printdetailtab" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据printdetailtab", "err:", err.Error()) + continue + } + //转义为json + jsonitemlst, err := json.Marshal(&itemlst) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "printdetailtab" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据printdetailtab", "err:", err.Error()) + return + } + //备份数据 + InfoLog1 := new(db.TableDataInfoLog) + InfoLog1.Servername = "Archive_printdetailtab" + InfoLog1.Tablename = "printdetailtab" + InfoLog1.Pkname = v.Printheadid + InfoLog1.Message = string(jsonitemlst) + InfoLog1.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss") + InfoLog1.InsertRecord() + //导出 + _, err = s.Table("printdetailtab").Insert(&itemlst) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "printdetailtab" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据printdetailtab", "err:", err.Error()) + continue + } + + } + + //删除数据 + _, err = e.Table("printheadtab").Where("finr = ? and printheadid = ?", db.G_FINR, v.Printheadid).Delete(&db.Printheadtab{}) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "printheadtab" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据printheadtab", "err:", err.Error()) + continue + } + + //删除数据 + _, err = e.Table("printdetailtab").Where("finr = ? and printheadid = ?", db.G_FINR, v.Printheadid).Delete(&db.Printdetailtab{}) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "printdetailtab" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据printdetailtab", "err:", err.Error()) + continue + } + + } + + + } + } +} + + + +//备份(pln_calloffdata_landing) +func Archive_Pln_calloffdata_landing(custorder CustOrders) { + //查询数据 + var ( + err error + ) + e := db.G_DbEngine + s := db.G_DbSalve + data := make([]db.Pln_calloffdata_landing, 0) + //查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条 + err = e.Table("pln_calloffdata_landing").Where("finr = ? and oemordernr = ?", db.G_FINR, custorder.Oemordernr).Find(&data) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "pln_calloffdata_landing" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据pln_calloffdata_landing", "err:", err.Error()) + return + } + + for _, v := range data { + + //转义为json + jsondata, err := json.Marshal(&v) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "pln_workorder" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据pln_workorder", "err:", err.Error()) + return + } + //备份数据 + InfoLog := new(db.TableDataInfoLog) + InfoLog.Servername = "Archive_pln_calloffdata_landing" + InfoLog.Tablename = "pln_calloffdata_landing" + InfoLog.Pkname = common.ValueToString(v.Calloffnr,"") + InfoLog.Message = string(jsondata) + InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss") + InfoLog.InsertRecord() + + //导出数据 + _, err = s.Table("pln_calloffdata_landing").Insert(&v) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "pln_calloffdata_landing" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据pln_calloffdata_landing", "err:", err.Error()) + return + } + + //错误记录 + + //删除数据 + _, err = e.Table("pln_calloffdata_landing").Where(" finr = ? and calloffnr = ?", db.G_FINR, v.Calloffnr).Delete(&db.Pln_calloffdata_landing{}) + if err != nil { + info := new(db.Pln_custorder_archive_error) + info.Tablename = "pln_calloffdata_landing" + info.Errorinfo = err.Error() + info.Add() + glog.InfoExtln("archive数据pln_calloffdata_landing", "err:", err.Error()) + return + } + } + +} \ No newline at end of file diff --git a/cmd/archive/main.go b/cmd/archive/main.go index ffde77e..08a2733 100644 --- a/cmd/archive/main.go +++ b/cmd/archive/main.go @@ -115,5 +115,8 @@ func imain() { go archive.ArchiveData(conf) //go archive.ArchivePln_pickorder(conf) go archive.ArchiveJit_shiporder(conf) + //备份打印表 + go archive.DelPrinterInfo() + archive.ArchiveJit_packorder(conf) }