copy 完删除数据
This commit is contained in:
parent
d8b1f08464
commit
07624c818d
|
|
@ -10,7 +10,8 @@ import (
|
||||||
|
|
||||||
func copyOrders(db *gorm.DB, timeNow time.Time) {
|
func copyOrders(db *gorm.DB, timeNow time.Time) {
|
||||||
order := &data.Orders{}
|
order := &data.Orders{}
|
||||||
db.Model(order).Where("create_time < ?", timeNow.Format("2006-01-02 15:04:05")).Order("create_time asc").First(order)
|
start := timeNow.Format("2006-01-02 15:04:05")
|
||||||
|
db.Debug().Where("create_time < ?", timeNow.Format("2006-01-02 15:04:05")).Order("create_time asc").First(order)
|
||||||
|
|
||||||
parse, err := time.Parse("2006-01-02T15:04:05Z07:00", order.CreateTime)
|
parse, err := time.Parse("2006-01-02T15:04:05Z07:00", order.CreateTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -18,11 +19,11 @@ func copyOrders(db *gorm.DB, timeNow time.Time) {
|
||||||
}
|
}
|
||||||
format := parse.Format("2006-01-02 15:04:05")
|
format := parse.Format("2006-01-02 15:04:05")
|
||||||
fmt.Println("copy orders from:", format)
|
fmt.Println("copy orders from:", format)
|
||||||
db.Debug().Where("create_time >= ?", format).Delete(&data.OrdersCopy1{})
|
db.Debug().Where("create_time >= ?", start).Delete(&data.OrdersCopy1{})
|
||||||
|
|
||||||
_execOrders(db, timeNow.Format("2006-01-02 15:04:05"), 0)
|
_execOrders(db, timeNow.Format("2006-01-02 15:04:05"), 0)
|
||||||
|
|
||||||
db.Debug().Where("create_time < ?", format).Delete(&data.Orders{})
|
db.Debug().Where("create_time < ?", start).Delete(&data.Orders{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func _execOrders(db *gorm.DB, timeNow string, index int) {
|
func _execOrders(db *gorm.DB, timeNow string, index int) {
|
||||||
|
|
@ -49,6 +50,7 @@ func _execOrders(db *gorm.DB, timeNow string, index int) {
|
||||||
|
|
||||||
func copyPayDetails(db *gorm.DB, timeNow time.Time) {
|
func copyPayDetails(db *gorm.DB, timeNow time.Time) {
|
||||||
detail := &data.PayDetails{}
|
detail := &data.PayDetails{}
|
||||||
|
start := timeNow.Format("2006-01-02 15:04:05")
|
||||||
db.Model(detail).Where("create_time < ?", timeNow.Format("2006-01-02 15:04:05")).Order("create_time asc").First(detail)
|
db.Model(detail).Where("create_time < ?", timeNow.Format("2006-01-02 15:04:05")).Order("create_time asc").First(detail)
|
||||||
|
|
||||||
parse, err := time.Parse("2006-01-02T15:04:05Z07:00", detail.CreateTime)
|
parse, err := time.Parse("2006-01-02T15:04:05Z07:00", detail.CreateTime)
|
||||||
|
|
@ -57,11 +59,11 @@ func copyPayDetails(db *gorm.DB, timeNow time.Time) {
|
||||||
}
|
}
|
||||||
format := parse.Format("2006-01-02 15:04:05")
|
format := parse.Format("2006-01-02 15:04:05")
|
||||||
fmt.Println("copy pay_details from:", format)
|
fmt.Println("copy pay_details from:", format)
|
||||||
db.Debug().Where("create_time >= ?", format).Delete(&data.PayDetailsCopy1{})
|
db.Debug().Where("create_time >= ?", start).Delete(&data.PayDetailsCopy1{})
|
||||||
|
|
||||||
_execPayDetails(db, timeNow.Format("2006-01-02 15:04:05"), 0)
|
_execPayDetails(db, timeNow.Format("2006-01-02 15:04:05"), 0)
|
||||||
|
|
||||||
db.Debug().Where("create_time < ?", format).Delete(&data.PayDetails{})
|
db.Debug().Where("create_time < ?", start).Delete(&data.PayDetails{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func _execPayDetails(db *gorm.DB, timeNow string, index int) {
|
func _execPayDetails(db *gorm.DB, timeNow string, index int) {
|
||||||
|
|
@ -88,6 +90,7 @@ func _execPayDetails(db *gorm.DB, timeNow string, index int) {
|
||||||
|
|
||||||
func copyUserMoneyDetails(db *gorm.DB, timeNow time.Time) {
|
func copyUserMoneyDetails(db *gorm.DB, timeNow time.Time) {
|
||||||
detail := &data.UserMoneyDetails{}
|
detail := &data.UserMoneyDetails{}
|
||||||
|
start := timeNow.Format("2006-01-02 15:04:05")
|
||||||
db.Model(detail).Where("create_time < ?", timeNow.Format("2006-01-02 15:04:05")).Order("create_time asc").First(detail)
|
db.Model(detail).Where("create_time < ?", timeNow.Format("2006-01-02 15:04:05")).Order("create_time asc").First(detail)
|
||||||
|
|
||||||
parse, err := time.Parse("2006-01-02T15:04:05Z07:00", detail.CreateTime)
|
parse, err := time.Parse("2006-01-02T15:04:05Z07:00", detail.CreateTime)
|
||||||
|
|
@ -96,11 +99,11 @@ func copyUserMoneyDetails(db *gorm.DB, timeNow time.Time) {
|
||||||
}
|
}
|
||||||
format := parse.Format("2006-01-02 15:04:05")
|
format := parse.Format("2006-01-02 15:04:05")
|
||||||
fmt.Println("copy pay_details from:", format)
|
fmt.Println("copy pay_details from:", format)
|
||||||
db.Debug().Where("create_time >= ?", format).Delete(&data.UserMoneyDetailsCopy1{})
|
db.Debug().Where("create_time >= ?", start).Delete(&data.UserMoneyDetailsCopy1{})
|
||||||
|
|
||||||
_execUserMoneyDetails(db, timeNow.Format("2006-01-02 15:04:05"), 0)
|
_execUserMoneyDetails(db, timeNow.Format("2006-01-02 15:04:05"), 0)
|
||||||
|
|
||||||
db.Debug().Where("create_time < ?", format).Delete(&data.UserMoneyDetails{})
|
db.Debug().Where("create_time < ?", start).Delete(&data.UserMoneyDetails{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func _execUserMoneyDetails(db *gorm.DB, timeNow string, index int) {
|
func _execUserMoneyDetails(db *gorm.DB, timeNow string, index int) {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ func CopyData() {
|
||||||
format := timeNow.Format("2006-01-02")
|
format := timeNow.Format("2006-01-02")
|
||||||
parse, _ := time.Parse("2006-01-02", format)
|
parse, _ := time.Parse("2006-01-02", format)
|
||||||
|
|
||||||
|
fmt.Println("Copy data from", parse)
|
||||||
|
|
||||||
for _, db := range dbList {
|
for _, db := range dbList {
|
||||||
copyOrders(db, parse)
|
copyOrders(db, parse)
|
||||||
copyPayDetails(db, parse)
|
copyPayDetails(db, parse)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
env: dev
|
env: prod
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
host: rm-gc712o11yndj78x6a6o.mysql.cn-chengdu.rds.aliyuncs.com
|
host: rm-gc712o11yndj78x6a6o.mysql.cn-chengdu.rds.aliyuncs.com
|
||||||
|
|
|
||||||
29
main.go
29
main.go
|
|
@ -1,27 +1,26 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/robfig/cron/v3"
|
|
||||||
"time"
|
"time"
|
||||||
"video_data_copy/db"
|
"video_data_copy/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c := cron.New()
|
|
||||||
_, err := c.AddFunc("0 4 * * *", func() {
|
|
||||||
fmt.Println("定时任务开始执行")
|
|
||||||
_startCopyData()
|
_startCopyData()
|
||||||
})
|
//c := cron.New()
|
||||||
if err != nil {
|
//_, err := c.AddFunc("0 4 * * *", func() {
|
||||||
fmt.Printf("添加定时任务出错: %v\n", err)
|
// fmt.Println("定时任务开始执行")
|
||||||
return
|
// _startCopyData()
|
||||||
}
|
//})
|
||||||
|
//if err != nil {
|
||||||
fmt.Println("定时任务启动成功")
|
// fmt.Printf("添加定时任务出错: %v\n", err)
|
||||||
c.Start()
|
// return
|
||||||
|
//}
|
||||||
select {}
|
//
|
||||||
|
//fmt.Println("定时任务启动成功")
|
||||||
|
//c.Start()
|
||||||
|
//
|
||||||
|
//select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _startCopyData() {
|
func _startCopyData() {
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue