diff --git a/archive/archive.go b/archive/archive.go index 7be7a75..0d13f12 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -8,6 +8,7 @@ import ( "leit.com/leit_seat_aps/config" "leit.com/leit_seat_aps/db" "leit.com/leit_seat_aps/glog" + "strings" "time" "context" ) @@ -60,8 +61,26 @@ func CustProduct(conf *config.EnvConfig) { custorders []string oemorders []string ) - //时间控制 - + //停机时间 + stime := "yyyy-MM-dd 02:00:00" + if !common.ValueIsEmpty(conf.Begtime){ + stime = conf.Begtime + } + etime := "yyyy-MM-dd 03:00:00" + if !common.ValueIsEmpty(conf.Endtime){ + etime = conf.Endtime + } + stime = common.TimeFormat(time.Now(), stime) + etime = common.TimeFormat(time.Now(), etime) + timeLayout := "2006-01-02 15:04:05" + loc, _ := time.LoadLocation("Local") + timeStart, _ := time.ParseInLocation(timeLayout, stime, loc) + timeEnd, _ := time.ParseInLocation(timeLayout, etime, loc) + now := time.Now() + if now.After(timeStart) && now.Before(timeEnd) { + time.Sleep(60 * time.Second) + continue + } //查询缓存记录表 cust, err := archive.SelectAll() if err != nil { @@ -977,6 +996,28 @@ func Archive_Pln_workorder(custorder CustOrders) { //备份:Jit_shiporder func ArchiveJit_shiporder(conf *config.EnvConfig) { for { + + //停机时间 + stime := "yyyy-MM-dd 02:00:00" + if !common.ValueIsEmpty(conf.Begtime){ + stime = conf.Begtime + } + etime := "yyyy-MM-dd 03:00:00" + if !common.ValueIsEmpty(conf.Endtime){ + etime = conf.Endtime + } + stime = common.TimeFormat(time.Now(), stime) + etime = common.TimeFormat(time.Now(), etime) + timeLayout := "2006-01-02 15:04:05" + loc, _ := time.LoadLocation("Local") + timeStart, _ := time.ParseInLocation(timeLayout, stime, loc) + timeEnd, _ := time.ParseInLocation(timeLayout, etime, loc) + now := time.Now() + if now.After(timeStart) && now.Before(timeEnd) { + time.Sleep(60 * time.Second) + continue + } + var ( err error oneWeek time.Time @@ -1289,6 +1330,28 @@ func ArchivePln_pickorder(conf *config.EnvConfig) { //备份:jit_packorder func ArchiveJit_packorder(conf *config.EnvConfig) { for { + + //停机时间 + stime := "yyyy-MM-dd 02:00:00" + if !common.ValueIsEmpty(conf.Begtime){ + stime = conf.Begtime + } + etime := "yyyy-MM-dd 03:00:00" + if !common.ValueIsEmpty(conf.Endtime){ + etime = conf.Endtime + } + stime = common.TimeFormat(time.Now(), stime) + etime = common.TimeFormat(time.Now(), etime) + timeLayout := "2006-01-02 15:04:05" + loc, _ := time.LoadLocation("Local") + timeStart, _ := time.ParseInLocation(timeLayout, stime, loc) + timeEnd, _ := time.ParseInLocation(timeLayout, etime, loc) + now := time.Now() + if now.After(timeStart) && now.Before(timeEnd) { + time.Sleep(60 * time.Second) + continue + } + var ( err error oneWeek time.Time @@ -1415,11 +1478,34 @@ func ArchiveJit_packorder(conf *config.EnvConfig) { } //删除一个礼拜前的打印消息 -func DelPrinterInfo() { +func DelPrinterInfo(conf *config.EnvConfig) { tick := time.Tick(10 * time.Second) for { select { case <-tick: + stime := "yyyy-MM-dd 02:00:00" + if !common.ValueIsEmpty(conf.Begtime){ + stime = conf.Begtime + } + etime := "yyyy-MM-dd 03:00:00" + if !common.ValueIsEmpty(conf.Endtime){ + etime = conf.Endtime + } + stime = common.TimeFormat(time.Now(), stime) + etime = common.TimeFormat(time.Now(), etime) + //停机时间 + timeLayout := "2006-01-02 15:04:05" + loc, _ := time.LoadLocation("Local") + timeStart, _ := time.ParseInLocation(timeLayout, stime, loc) + timeEnd, _ := time.ParseInLocation(timeLayout, etime, loc) + now := time.Now() + fmt.Println(timeStart) + fmt.Println(timeEnd) + if now.After(timeStart) && now.Before(timeEnd) { + time.Sleep(60 * time.Second) + continue + } + var ( err error oneWeek time.Time @@ -1428,7 +1514,11 @@ func DelPrinterInfo() { s := db.G_DbSalve data := make([]db.Printheadtab, 0) //获取七天前的字符串 - oneWeek = time.Now().AddDate(0, 0, -7) + if common.ValueIsEmpty(conf.Day) { + oneWeek = time.Now().AddDate(0, 0, -14) + } else { + oneWeek = time.Now().AddDate(0, 0, -conf.Day) + } oneWeekStr := common.TimeFormat(oneWeek, "yyyyMMddHHmmss") //查询出订单状态是80,并且是七天前的客户订单的信息,每次查询10条 @@ -1444,7 +1534,6 @@ func DelPrinterInfo() { continue } for _, v := range data { - itemlst := make([]db.Printdetailtab, 0) //转义为json jsondata, err := json.Marshal(&v) if err != nil { @@ -1456,7 +1545,7 @@ func DelPrinterInfo() { return } //判断是否需要备份 - if v.Printobjtype == "BBAASN" { + if strings.TrimSpace(v.Printobjtype) == conf.Printobjtype { //备份数据 InfoLog := new(db.TableDataInfoLog) InfoLog.Servername = "Archive_printheadtab" @@ -1475,7 +1564,7 @@ func DelPrinterInfo() { glog.InfoExtln("archive数据printheadtab", "err:", err.Error()) continue } - + itemlst := make([]db.Printdetailtab, 0) //查询(printdetailtab) err = e.Table("printdetailtab").Where("finr = ? and printheadid = ?", db.G_FINR, v.Printheadid).Find(&itemlst) if err != nil { diff --git a/cmd/archive/main.go b/cmd/archive/main.go index 08a2733..dcf5c21 100644 --- a/cmd/archive/main.go +++ b/cmd/archive/main.go @@ -116,7 +116,7 @@ func imain() { //go archive.ArchivePln_pickorder(conf) go archive.ArchiveJit_shiporder(conf) //备份打印表 - go archive.DelPrinterInfo() + go archive.DelPrinterInfo(conf) archive.ArchiveJit_packorder(conf) } diff --git a/config/config.go b/config/config.go index c9852b4..d0302b2 100644 --- a/config/config.go +++ b/config/config.go @@ -30,6 +30,9 @@ type EnvConfig struct { Outbox string `yaml:"outbox"` Day int `yaml:"day"` Num int `yaml:"num"` + Printobjtype string `yaml:"printobjtype"` + Begtime string `yaml:"begtime"` + Endtime string `yaml:"endtime"` } //read yaml config diff --git a/config/config.yaml b/config/config.yaml index 5cad714..26a95e6 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -4,7 +4,7 @@ server: localhost ip: 127.0.0.1 #ip: 192.168.3.22 user: sa -password: 123456 +password: Leit2020 dbname: SJA_APS port: 1433 @@ -14,7 +14,7 @@ salveserver: localhost salveip: 127.0.0.1 #ip: 192.168.3.22 salveuser: sa -salvepassword: 123456 +salvepassword: Leit2020 salvedbname: SJA_APS_ARCHIVE salveport: 1433 @@ -31,4 +31,10 @@ readtaskinterval: 5 printertype: N,L,E inbox: Template\\Inbox outbox: Template\\Outbox -day:7 \ No newline at end of file +# 间隔时间 +day: 7 +# 备份类型 +printobjtype: "BBAASN" +# 锁定区间 +begtime: "yyyy-MM-dd 02:00:00" +endtime: "yyyy-MM-dd 03:00:00" \ No newline at end of file