// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
|
|
package archive
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"leit.com/leit_seat_aps/common"
|
|
"leit.com/leit_seat_aps/config"
|
|
"leit.com/leit_seat_aps/db"
|
|
"leit.com/leit_seat_aps/glog"
|
|
"strings"
|
|
"time"
|
|
"context"
|
|
)
|
|
|
|
type CustOrders struct {
|
|
Projnr string //项目号
|
|
Custordernr string //客户订单号
|
|
Oemordernr string //Oemordernr订单号
|
|
Oemseq string //oem订单号
|
|
Calloffnr string //oem订单号
|
|
Finr int //工厂编号
|
|
}
|
|
|
|
//定义一个调度任务通道,相当于仓库
|
|
var CustOrderChan = make(chan CustOrders, 10)
|
|
|
|
/******************************************************************************
|
|
*
|
|
* @Function Name :
|
|
*-----------------------------------------------------------------------------
|
|
*
|
|
* @Description :数据备份,逻辑:运用生产者和消费者模型,导入到备份数据库
|
|
*
|
|
* @Function Parameters:
|
|
*
|
|
* @Return Value :
|
|
*
|
|
* @Author : Lou Wenzhi
|
|
*
|
|
* @Date : 2021/3/17 9:22
|
|
*
|
|
******************************************************************************/
|
|
|
|
func ArchiveData(conf *config.EnvConfig) {
|
|
//创建继承Baxkground的子节点Context
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
go CustConsume(ctx)
|
|
|
|
//生产者:每次处理10条数据
|
|
CustProduct(conf)
|
|
}
|
|
|
|
//生产者
|
|
func CustProduct(conf *config.EnvConfig) {
|
|
for {
|
|
var (
|
|
err error
|
|
oneWeek time.Time
|
|
archive db.Pln_custorder_archive
|
|
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(timeEnd) || now.Before(timeStart) {
|
|
time.Sleep(60 * time.Second)
|
|
continue
|
|
}
|
|
//查询缓存记录表
|
|
cust, err := archive.SelectAll()
|
|
if err != nil {
|
|
glog.InfoExtln("调度生成终止", "cust is error:", err)
|
|
glog.InfoExtln("调度生成终止", "cust is error!")
|
|
return
|
|
}
|
|
for _, v := range cust {
|
|
custorders = append(custorders, v.Custordernr)
|
|
}
|
|
e := db.G_DbEngine
|
|
data := make([]CustOrders, 0)
|
|
|
|
//获取一个月前的字符串
|
|
if common.ValueIsEmpty(conf.Day) {
|
|
oneWeek = time.Now().AddDate(0, -1, 0)
|
|
} else {
|
|
fmt.Printf("conf.Day is :%v", conf.Day)
|
|
oneWeek = time.Now().AddDate(0, 0, -conf.Day)
|
|
}
|
|
|
|
oneWeekStr := common.TimeFormat(oneWeek, "yyyyMMddHHmmss")
|
|
|
|
/********
|
|
联查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
|
|
}
|
|
fmt.Println("程序执行中!")
|
|
if len(data) == 0 {
|
|
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
|
|
glog.InfoExtln("infoShip", "workOrders:", vv.Workordernr)
|
|
glog.InfoExtln("infoShip", "Status:", vv.Status)
|
|
break
|
|
}
|
|
if vv.Shippable != 1 {
|
|
glog.InfoExtln("infoShip", "workOrders:", vv.Workordernr)
|
|
glog.InfoExtln("infoShip", "Shippable:", vv.Shippable)
|
|
isOk = false
|
|
break
|
|
}
|
|
if vv.Packstatus != 1 {
|
|
isOk = false
|
|
glog.InfoExtln("infoShip", "workOrders:", vv.Workordernr)
|
|
glog.InfoExtln("infoShip", "Packstatus:", vv.Packstatus)
|
|
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 {
|
|
glog.InfoExtln("infoShip", "workOrders:", vv.Workordernr)
|
|
glog.InfoExtln("infoShip", "err:", err)
|
|
glog.InfoExtln("infoShip", "ok:", ok)
|
|
isOk = false
|
|
break
|
|
}
|
|
if infoShip.Status < common.CO_STATUS_CLOSED {
|
|
glog.InfoExtln("infoShip", "workOrders:", vv.Workordernr)
|
|
glog.InfoExtln("infoShip", "infoShip.Status:", infoShip.Status)
|
|
isOk = false
|
|
break
|
|
}
|
|
}
|
|
if !isOk {
|
|
glog.InfoExtln("infoShip", "Custordernr:", v.Custordernr)
|
|
//验证不通过
|
|
continue
|
|
}
|
|
common.TrimStruct(&v, v)
|
|
one := db.Pln_custorder_archive{}
|
|
one.Finr = db.G_FINR
|
|
one.Custordernr = v.Custordernr
|
|
one.Releaseflag = 1
|
|
one.Lastuser = "archive"
|
|
one.Lastmodif = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
one.Credatuz = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
err = one.Add()
|
|
if err != nil {
|
|
glog.InfoExtln("archive数据Pln_custorder_archive", "err:", err.Error())
|
|
}
|
|
CustOrderChan <- v
|
|
}
|
|
}
|
|
|
|
time.Sleep(60 * time.Second)
|
|
}
|
|
|
|
}
|
|
|
|
//消费者
|
|
func CustConsume(ctx context.Context) {
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case task, ok := <-CustOrderChan:
|
|
if !ok {
|
|
glog.InfoExtln("调度生成终止", "Consume is not ok!")
|
|
return //停机退出
|
|
}
|
|
//备份客户订单表(pln_custorder)
|
|
go Archive_Pln_custorder(task)
|
|
//备份(pln_custorder_ver)
|
|
go Archive_Pln_custorder_ver(task)
|
|
//备份(pln_custorder_ver_partlst)
|
|
go Archive_Pln_custorder_ver_partlst(task)
|
|
//备份(pln_custorder_partlst)
|
|
go Archive_Pln_custorder_partlst(task)
|
|
//备份(pln_custorder_atcodlst)
|
|
go Archive_Pln_custorder_atcodlst(task)
|
|
//备份(pln_custorder_supplygroup_partlst)
|
|
go Archive_Pln_custorder_supplygroup_partlst(task)
|
|
//备份(pln_custorder_carmodelver)
|
|
//go Archive_Pln_custorder_carmodelver(task)
|
|
//备份(pln_custorder_errorlst)
|
|
go Archive_Pln_custorder_errorlst(task)
|
|
//备份(pln_seqdata_landing)
|
|
//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
|
|
err := archive.Del()
|
|
if err != nil {
|
|
glog.InfoExtln("archive数据Pln_custorder_archive", "err:", err.Error())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//备份客户订单表(pln_custorder)
|
|
func Archive_Pln_custorder(custorder CustOrders) {
|
|
//查询数据
|
|
var err error
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
var data db.Pln_custorder
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
ok, err := e.Table("pln_custorder").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Get(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder"
|
|
InfoLog.Tablename = "pln_custorder"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
//导出数据
|
|
if ok {
|
|
_, err = s.Table("pln_custorder").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder", "err:", err.Error())
|
|
return
|
|
}
|
|
}
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Delete(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_custorder_ver)
|
|
func Archive_Pln_custorder_ver(custorder CustOrders) {
|
|
//查询数据
|
|
var err error
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
var data db.Pln_custorder_ver
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
ok, err := e.Table("pln_custorder_ver").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Get(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_ver", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder_ver"
|
|
InfoLog.Tablename = "pln_custorder_ver"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
//导出数据
|
|
if ok {
|
|
_, err = s.Table("pln_custorder_ver").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_ver", "err:", err.Error())
|
|
return
|
|
}
|
|
}
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder_ver").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Delete(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_ver", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_custorder_ver_partlst)
|
|
func Archive_Pln_custorder_ver_partlst(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
del db.Pln_custorder_ver_partlst
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_custorder_ver_partlst, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_custorder_ver_partlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Find(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_ver_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder_ver_partlst"
|
|
InfoLog.Tablename = "pln_custorder_ver_partlst"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
//导出数据
|
|
_, err = s.Table("pln_custorder_ver_partlst").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_ver_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder_ver_partlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Delete(&del)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_ver_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_ver_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_custorder_partlst)
|
|
func Archive_Pln_custorder_partlst(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
del db.Pln_custorder_partlst
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_custorder_partlst, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_custorder_partlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Find(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder_partlst"
|
|
InfoLog.Tablename = "pln_custorder_partlst"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
|
|
//导出数据
|
|
_, err = s.Table("pln_custorder_partlst").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder_partlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Delete(&del)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_custorder_atcodlst)
|
|
func Archive_Pln_custorder_atcodlst(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
del db.Pln_custorder_atcodlst
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_custorder_atcodlst, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_custorder_atcodlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Find(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_atcodlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder_atcodlst"
|
|
InfoLog.Tablename = "pln_custorder_atcodlst"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
|
|
//导出数据
|
|
_, err = s.Table("pln_custorder_atcodlst").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_atcodlst", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder_atcodlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Delete(&del)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_atcodlst", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_custorder_supplygroup_partlst)
|
|
func Archive_Pln_custorder_supplygroup_partlst(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
del db.Pln_custorder_supplygroup_partlst
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_custorder_supplygroup_partlst, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_custorder_supplygroup_partlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Find(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_supplygroup_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_supplygroup_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_supplygroup_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_supplygroup_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder_supplygroup_partlst"
|
|
InfoLog.Tablename = "pln_custorder_supplygroup_partlst"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
|
|
//导出数据
|
|
_, err = s.Table("pln_custorder_supplygroup_partlst").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_supplygroup_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_supplygroup_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder_supplygroup_partlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Delete(&del)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_supplygroup_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_supplygroup_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_custorder_carmodelver)
|
|
func Archive_Pln_custorder_carmodelver(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
del db.Pln_custorder_carmodelver
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_custorder_carmodelver, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_custorder_carmodelver").Where(" finr = ? and oemordernr = ?", db.G_FINR, custorder.Oemordernr).Find(&data)
|
|
glog.InfoExtln("archive数据pln_custorder_carmodelver", "数据长度:", len(data))
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_carmodelver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_carmodelver", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_carmodelver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_carmodelver", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder_carmodelver"
|
|
InfoLog.Tablename = "pln_custorder_carmodelver"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
|
|
//导出数据
|
|
_, err = s.Table("pln_custorder_carmodelver").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_carmodelver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_carmodelver", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder_carmodelver").Where(" finr = ? and oemordernr = ?", db.G_FINR, custorder.Oemordernr).Delete(&del)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_carmodelver"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_carmodelver", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_custorder_errorlst)
|
|
func Archive_Pln_custorder_errorlst(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
del db.Pln_custorder_errorlst
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_custorder_errorlst, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_custorder_errorlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Find(&data)
|
|
glog.InfoExtln("archive数据pln_custorder_errorlst", "数据长度:", len(data))
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_errorlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_errorlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_errorlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_errorlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_custorder_errorlst"
|
|
InfoLog.Tablename = "pln_custorder_errorlst"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
|
|
//导出数据
|
|
_, err = s.Table("pln_custorder_errorlst").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_errorlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_errorlst", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_custorder_errorlst").Where(" finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Delete(&del)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_custorder_errorlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_custorder_errorlst", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_seqdata_landing)
|
|
func Archive_Pln_seqdata_landing(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
del db.Pln_seqdata_landing
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_seqdata_landing, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_seqdata_landing").Where(" finr = ? and oemordernr = ?", db.G_FINR, custorder.Oemordernr).Find(&data)
|
|
glog.InfoExtln("archive数据Pln_seqdata_landing", "数据长度:", len(data))
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_seqdata_landing"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_seqdata_landing", "err:", err.Error())
|
|
return
|
|
}
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_seqdata_landing"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_seqdata_landing", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Pln_seqdata_landing"
|
|
InfoLog.Tablename = "pln_seqdata_landing"
|
|
InfoLog.Pkname = custorder.Custordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
|
|
//导出数据
|
|
_, err = s.Table("pln_seqdata_landing").Insert(&data)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_seqdata_landing"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_seqdata_landing", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_seqdata_landing").Where(" finr = ? and oemordernr = ?", db.G_FINR, custorder.Oemordernr).Delete(&del)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_seqdata_landing"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_seqdata_landing", "err:", err.Error())
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//备份(pln_workorder)
|
|
func Archive_Pln_workorder(custorder CustOrders) {
|
|
//查询数据
|
|
var (
|
|
err error
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Pln_workorder, 0)
|
|
//查询出客户订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("pln_workorder").Where("finr = ? and custordernr = ?", db.G_FINR, custorder.Custordernr).Find(&data)
|
|
glog.InfoExtln("archive数据pln_workorder", "数据长度:", len(data))
|
|
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
|
|
}
|
|
|
|
for _, v := range data {
|
|
partlst := make([]db.Pln_workorder_partlst, 0)
|
|
atcodlst := make([]db.Pln_workorder_atcodlst, 0)
|
|
var delpartlst db.Pln_workorder_partlst
|
|
var delatcodlst db.Pln_workorder_atcodlst
|
|
|
|
//转义为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_workorder"
|
|
InfoLog.Tablename = "pln_workorder"
|
|
InfoLog.Pkname = v.Workordernr
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
|
|
//导出数据
|
|
_, err = s.Table("pln_workorder").Insert(&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
|
|
}
|
|
|
|
//错误记录
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_workorder").Where(" finr = ? and workordernr = ?", db.G_FINR, v.Workordernr).Delete(&db.Pln_workorder{})
|
|
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
|
|
}
|
|
|
|
//查询(pln_workorder_partlst)
|
|
err = e.Table("pln_workorder_partlst").Where("finr = ? and workordernr = ?", db.G_FINR, v.Workordernr).Find(&partlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_workorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
//转义为json
|
|
jsondata, err = json.Marshal(&partlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_workorder_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog1 := new(db.TableDataInfoLog)
|
|
InfoLog1.Servername = "Archive_Pln_workorder"
|
|
InfoLog1.Tablename = "pln_workorder_partlst"
|
|
InfoLog1.Pkname = custorder.Custordernr
|
|
InfoLog1.Message = string(jsondata)
|
|
InfoLog1.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog1.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("pln_workorder_partlst").Insert(&partlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_workorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_workorder_partlst").Where("finr = ? and workordernr = ?", db.G_FINR, v.Workordernr).Delete(&delpartlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_partlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_workorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//查询(pln_workorder_atcodlst)
|
|
err = e.Table("pln_workorder_atcodlst").Where("finr = ? and workordernr = ?", db.G_FINR, v.Workordernr).Find(&atcodlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_workorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
//转义为json
|
|
jsondata, err = json.Marshal(&atcodlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_workorder_partlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog2 := new(db.TableDataInfoLog)
|
|
InfoLog2.Servername = "Archive_Pln_workorder"
|
|
InfoLog2.Tablename = "pln_workorder_atcodlst"
|
|
InfoLog2.Pkname = custorder.Custordernr
|
|
InfoLog2.Message = string(jsondata)
|
|
InfoLog2.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog2.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("pln_workorder_atcodlst").Insert(&atcodlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_workorder_atcodlst").Where("finr = ? and workordernr = ?", db.G_FINR, v.Workordernr).Delete(&delatcodlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_workorder_atcodlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
continue
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//备份:Jit_shiporder
|
|
func ArchiveJit_shiporder(conf *config.EnvConfig) {
|
|
for {
|
|
if !conf.Shiptog {
|
|
fmt.Println("stop ArchiveJit_shiporder!")
|
|
time.Sleep(1 * time.Hour)
|
|
continue
|
|
}
|
|
//停机时间
|
|
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(timeEnd) || now.Before(timeStart) {
|
|
time.Sleep(60 * time.Second)
|
|
continue
|
|
}
|
|
|
|
var (
|
|
err error
|
|
oneWeek time.Time
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
|
|
data := make([]db.Jit_shiporder, 0)
|
|
//获取七天前的字符串
|
|
if common.ValueIsEmpty(conf.Day) {
|
|
oneWeek = time.Now().AddDate(0, 0, -30)
|
|
} else {
|
|
oneWeek = time.Now().AddDate(0, 0, -(conf.Day + 30))
|
|
}
|
|
oneWeekStr := common.TimeFormat(oneWeek, "yyyyMMddHHmmss")
|
|
//查询出订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("jit_shiporder").Where("status = ? and credatuz <= ?", common.CO_STATUS_CLOSED, oneWeekStr).Desc("credatuz").Limit(10).Find(&data)
|
|
if err != nil {
|
|
glog.InfoExtln("调度生成终止", "err : ", err)
|
|
return
|
|
}
|
|
for _, v := range data {
|
|
|
|
packlst := make([]db.Jit_packorder, 0)
|
|
//判断对应的包装单是否全部导出
|
|
err = e.Table("jit_packorder").Join("INNER","jit_shiporder_datalst","jit_packorder.finr = jit_shiporder_datalst.finr and jit_packorder.packorderid = jit_shiporder_datalst.packorderid").Where("jit_shiporder_datalst.finr = ? and jit_shiporder_datalst.shiporderid = ?", db.G_FINR, v.Shiporderid).Find(&packlst)
|
|
if len(packlst) > 0{
|
|
glog.InfoExtln("archive数据jit_packorder", "Jit_packorder:","对应的包装单没有全部导出!",v.Shiporderid)
|
|
continue
|
|
}
|
|
itemlst := make([]db.Jit_shiporder_itemlst, 0)
|
|
datalst := make([]db.Jit_shiporder_datalst, 0)
|
|
var delitemlst db.Jit_shiporder_itemlst
|
|
var deldatalst db.Jit_shiporder_datalst
|
|
var deldata db.Jit_shiporder
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&v)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据Jit_shiporder", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_Jit_shiporder"
|
|
InfoLog.Tablename = "jit_shiporder"
|
|
InfoLog.Pkname = v.Shiporderid
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("jit_shiporder").Insert(&v)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("jit_shiporder").Where("finr = ? and shiporderid = ?", db.G_FINR, v.Shiporderid).Delete(&deldata)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//查询(pln_workorder_partlst)
|
|
err = e.Table("jit_shiporder_itemlst").Where("finr = ? and shiporderid = ?", db.G_FINR, v.Shiporderid).Find(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
//转义为json
|
|
jsonitemlst, err := json.Marshal(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder_itemlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog1 := new(db.TableDataInfoLog)
|
|
InfoLog1.Servername = "Archive_Jit_shiporder_itemlst"
|
|
InfoLog1.Tablename = "jit_shiporder_itemlst"
|
|
InfoLog1.Pkname = v.Shiporderid
|
|
InfoLog1.Message = string(jsonitemlst)
|
|
InfoLog1.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog1.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("jit_shiporder_itemlst").Insert(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("jit_shiporder_itemlst").Where("finr = ? and shiporderid = ?", db.G_FINR, v.Shiporderid).Delete(&delitemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//查询(pln_workorder_atcodlst)
|
|
err = e.Table("jit_shiporder_datalst").Where("finr = ? and shiporderid = ?", db.G_FINR, v.Shiporderid).Find(&datalst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_datalst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder_datalst", "err:", err.Error())
|
|
continue
|
|
}
|
|
//转义为json
|
|
jsondata, err = json.Marshal(&datalst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_datalst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_shiporder_datalst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog2 := new(db.TableDataInfoLog)
|
|
InfoLog2.Servername = "Archive_Jit_shiporder_datalst"
|
|
InfoLog2.Tablename = "jit_shiporder_datalst"
|
|
InfoLog2.Pkname = v.Shiporderid
|
|
InfoLog2.Message = string(jsondata)
|
|
InfoLog2.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog2.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("jit_shiporder_datalst").Insert(&datalst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_datalst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("jit_shiporder_datalst").Where("finr = ? and shiporderid = ?", db.G_FINR, v.Shiporderid).Delete(&deldatalst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_shiporder_datalst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
continue
|
|
}
|
|
|
|
}
|
|
time.Sleep(60 * time.Second)
|
|
}
|
|
}
|
|
|
|
//备份:pln_pickorder
|
|
func ArchivePln_pickorder(conf *config.EnvConfig) {
|
|
for {
|
|
var (
|
|
err error
|
|
oneWeek time.Time
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
|
|
data := make([]db.Pln_pickorder, 0)
|
|
//获取七天前的字符串
|
|
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条
|
|
err = e.Table("pln_pickorder").Where("status = ? and credatuz <= ?", common.CO_STATUS_CLOSED, oneWeekStr).Desc("credatuz").Limit(10).Find(&data)
|
|
if err != nil {
|
|
glog.InfoExtln("调度生成终止", "err : ", err)
|
|
return
|
|
}
|
|
if len(data) == 0 {
|
|
time.Sleep(60 * time.Second)
|
|
continue
|
|
}
|
|
for _, v := range data {
|
|
itemlst := make([]db.Pln_pickorder_itemlst, 0)
|
|
var delitemlst db.Pln_pickorder_itemlst
|
|
var deldata db.Pln_pickorder
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&v)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_pickorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_pickorder", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_pln_pickorder"
|
|
InfoLog.Tablename = "pln_pickorder"
|
|
InfoLog.Pkname = v.Pickorderid
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("pln_pickorder").Insert(&v)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_pickorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_pickorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_pickorder").Where("finr = ? and pickorderid = ?", db.G_FINR, v.Pickorderid).Delete(&deldata)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_pickorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_pickorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//查询(pln_pickorder_itemlst)
|
|
err = e.Table("pln_pickorder_itemlst").Where("finr = ? and pickorderid = ?", db.G_FINR, v.Pickorderid).Find(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_pickorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_pickorder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
//转义为json
|
|
jsonitemlst, err := json.Marshal(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_pickorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_pickorder_itemlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog1 := new(db.TableDataInfoLog)
|
|
InfoLog1.Servername = "Archive_Pln_pickorder_itemlst"
|
|
InfoLog1.Tablename = "pln_pickorder_itemlst"
|
|
InfoLog1.Pkname = v.Pickorderid
|
|
InfoLog1.Message = string(jsonitemlst)
|
|
InfoLog1.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog1.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("pln_pickorder_itemlst").Insert(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_pickorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_pickorder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("pln_pickorder_itemlst").Where("finr = ? and pickorderid = ?", db.G_FINR, v.Pickorderid).Delete(&delitemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "pln_pickorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据pln_pickorder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
}
|
|
time.Sleep(60 * time.Second)
|
|
}
|
|
}
|
|
|
|
//备份:jit_packorder
|
|
func ArchiveJit_packorder(conf *config.EnvConfig) {
|
|
for {
|
|
if !conf.Packtog {
|
|
fmt.Println("stop ArchiveJit_packorder!")
|
|
time.Sleep(1 * time.Hour)
|
|
continue
|
|
}
|
|
//停机时间
|
|
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(timeEnd) || now.Before(timeStart) {
|
|
time.Sleep(60 * time.Second)
|
|
continue
|
|
}
|
|
|
|
var (
|
|
err error
|
|
oneWeek time.Time
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Jit_packorder, 0)
|
|
//获取七天前的字符串
|
|
if common.ValueIsEmpty(conf.Day) {
|
|
oneWeek = time.Now().AddDate(0, 0, -30)
|
|
} else {
|
|
oneWeek = time.Now().AddDate(0, 0, -(conf.Day + 30))
|
|
}
|
|
|
|
oneWeekStr := common.TimeFormat(oneWeek, "yyyyMMddHHmmss")
|
|
//查询出订单状态是80,并且是七天前的客户订单的信息,每次查询10条
|
|
err = e.Table("jit_packorder").Where("status = ? and credatuz <= ?", common.CO_STATUS_CLOSED, oneWeekStr).Desc("credatuz").Limit(10).Find(&data)
|
|
if err != nil {
|
|
glog.InfoExtln("调度生成终止", "err : ", err)
|
|
return
|
|
}
|
|
if len(data) == 0 {
|
|
time.Sleep(60 * time.Second)
|
|
continue
|
|
}
|
|
for _, v := range data {
|
|
|
|
wolst := make([]db.Pln_workorder, 0)
|
|
//判断对应的工单是否全部导出
|
|
err = e.Table("pln_workorder").Join("INNER","jit_packorder_itemlst","pln_workorder.finr = jit_packorder_itemlst.finr and pln_workorder.workordernr = jit_packorder_itemlst.workordernr").Where("jit_packorder_itemlst.finr = ? and jit_packorder_itemlst.packorderid = ?", db.G_FINR, v.Packorderid).Find(&wolst)
|
|
if len(wolst) > 0{
|
|
glog.InfoExtln("archive数据jit_packorder", "pln_workorder:","对应的工单没有全部导出!",v.Packorderid)
|
|
continue
|
|
}
|
|
|
|
itemlst := make([]db.Jit_packorder_itemlst, 0)
|
|
var delitemlst db.Jit_packorder_itemlst
|
|
var deldata db.Jit_shiporder
|
|
//转义为json
|
|
jsondata, err := json.Marshal(&v)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_packorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_packorder", "err:", err.Error())
|
|
return
|
|
}
|
|
|
|
//备份数据
|
|
InfoLog := new(db.TableDataInfoLog)
|
|
InfoLog.Servername = "Archive_jit_packorder"
|
|
InfoLog.Tablename = "jit_packorder"
|
|
InfoLog.Pkname = v.Packorderid
|
|
InfoLog.Message = string(jsondata)
|
|
InfoLog.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("jit_packorder").Insert(&v)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_packorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_packorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("jit_packorder").Where("finr = ? and packorderid = ?", db.G_FINR, v.Packorderid).Delete(&deldata)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_packorder"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_packorder", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//查询(jit_packorder_itemlst)
|
|
err = e.Table("jit_packorder_itemlst").Where("finr = ? and packorderid = ?", db.G_FINR, v.Packorderid).Find(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_packorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_packorder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
//转义为json
|
|
jsonitemlst, err := json.Marshal(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_packorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_packorder_itemlst", "err:", err.Error())
|
|
return
|
|
}
|
|
//备份数据
|
|
InfoLog1 := new(db.TableDataInfoLog)
|
|
InfoLog1.Servername = "Archive_Jit_packorder_itemlst"
|
|
InfoLog1.Tablename = "jit_packorder_itemlst"
|
|
InfoLog1.Pkname = v.Packorderid
|
|
InfoLog1.Message = string(jsonitemlst)
|
|
InfoLog1.Createtime = common.TimeFormat(time.Now(), "yyyyMMddHHmmss")
|
|
InfoLog1.InsertRecord()
|
|
//导出
|
|
_, err = s.Table("jit_packorder_itemlst").Insert(&itemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_packorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_packorder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
//删除数据
|
|
_, err = e.Table("jit_packorder_itemlst").Where("finr = ? and packorderid = ?", db.G_FINR, v.Packorderid).Delete(&delitemlst)
|
|
if err != nil {
|
|
info := new(db.Pln_custorder_archive_error)
|
|
info.Tablename = "jit_packorder_itemlst"
|
|
info.Errorinfo = err.Error()
|
|
info.Add()
|
|
glog.InfoExtln("archive数据jit_packorder_itemlst", "err:", err.Error())
|
|
continue
|
|
}
|
|
|
|
}
|
|
time.Sleep(60 * time.Second)
|
|
}
|
|
}
|
|
|
|
//删除一个礼拜前的打印消息
|
|
func DelPrinterInfo(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()
|
|
fmt.Println(timeStart)
|
|
fmt.Println(timeEnd)
|
|
if now.After(timeEnd) || now.Before(timeStart) {
|
|
fmt.Println("the time is not start!")
|
|
time.Sleep(60 * time.Second)
|
|
continue
|
|
}
|
|
fmt.Println("start capy data!")
|
|
var (
|
|
err error
|
|
oneWeek time.Time
|
|
)
|
|
e := db.G_DbEngine
|
|
s := db.G_DbSalve
|
|
data := make([]db.Printheadtab, 0)
|
|
//获取七天前的字符串
|
|
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")
|
|
fmt.Println()
|
|
fmt.Printf("备份时间:%v", oneWeekStr)
|
|
fmt.Println()
|
|
//查询出订单状态是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 {
|
|
//转义为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 strings.TrimSpace(v.Printobjtype) == conf.Printobjtype {
|
|
//备份数据
|
|
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
|
|
}
|
|
itemlst := make([]db.Printdetailtab, 0)
|
|
//查询(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()
|
|
//导出
|
|
for _, vv := range itemlst {
|
|
_, err = s.Table("printdetailtab").Insert(&vv)
|
|
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
|
|
}
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
time.Sleep(10 * time.Second)
|
|
}
|
|
|
|
}
|
|
|
|
//备份(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 calloffnr = ?", db.G_FINR, custorder.Calloffnr).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
|
|
}
|
|
}
|
|
|
|
}
|