Commit 74f662ea by Joneq

同步线上一年的数据

parent 28ec9d33
Showing with 25 additions and 11 deletions
...@@ -17,12 +17,15 @@ var ( ...@@ -17,12 +17,15 @@ var (
//需要同步的的表 //需要同步的的表
syncTable = []string{ syncTable = []string{
"Ent_balance_sheet","Ent_cash_flow", "Ent_balance_sheet","Ent_cash_flow",
"Ent_profit","Gathering_Account", "Ent_profit", "Purchase_Order","SYS_OPERATE_LOG",
"HK_Customs_Declaration","Payment_Account",
"Purchase_Order","Sales_Order",
"SYS_OPERATE_LOG",
} }
//"Ent_balance_sheet","Ent_cash_flow",
//"Ent_profit","Gathering_Account",
//"HK_Customs_Declaration","Payment_Account",
//"Purchase_Order","Sales_Order",
//"SYS_OPERATE_LOG",
wg sync.WaitGroup wg sync.WaitGroup
) )
...@@ -46,15 +49,23 @@ func init(){ ...@@ -46,15 +49,23 @@ func init(){
func main() { func main() {
//获取当天时间 //获取当天时间
var currentDate = time.Now().Format("2006-01-02") //var currentDate = time.Now().Format("2006-01-02")
//循环获取表名,然后获取表内当天信息,并且存入mysql,协程处理 //循环获取表名,然后获取表内当天信息,并且存入mysql,协程处理
for _,v := range syncTable {
wg.Add(1)
go handleCurrentTable(v,currentDate)
}
wg.Wait() var startTime int64 = 1577808000
var nowtime = time.Now().Unix()
for startTime < nowtime {
currentDate := time.Unix(startTime,0).Format("2006-01-02")
for _,v := range syncTable {
//wg.Add(1)
handleCurrentTable(v,currentDate)
}
startTime+=86400
}
//wg.Wait()
} }
...@@ -63,7 +74,7 @@ func main() { ...@@ -63,7 +74,7 @@ func main() {
//处理当前的这个表任务 //处理当前的这个表任务
func handleCurrentTable(tableName,currentDate string) { func handleCurrentTable(tableName,currentDate string) {
defer wg.Done() //defer wg.Done()
fmt.Println(currentDate+"开始同步"+tableName) fmt.Println(currentDate+"开始同步"+tableName)
currentJson := requestTableInfo(tableName,currentDate) currentJson := requestTableInfo(tableName,currentDate)
...@@ -104,6 +115,9 @@ func handleCurrentTable(tableName,currentDate string) { ...@@ -104,6 +115,9 @@ func handleCurrentTable(tableName,currentDate string) {
if currentNum != "" && tableName != "SYS_OPERATE_LOG" { if currentNum != "" && tableName != "SYS_OPERATE_LOG" {
sqlDb.Exec("delete from "+tableName+" where number = ?",currentNum) sqlDb.Exec("delete from "+tableName+" where number = ?",currentNum)
} }
currentKey+="data_sync_time,"
valueString += "?,"
currentString = append(currentString,time.Now().Format("2006-01-02"))
currentString[0] = `INSERT INTO `+tableName+` (`+currentKey[:len(currentKey)-1]+`)VALUES (`+valueString[:len(valueString)-1]+`)` currentString[0] = `INSERT INTO `+tableName+` (`+currentKey[:len(currentKey)-1]+`)VALUES (`+valueString[:len(valueString)-1]+`)`
_, err := sqlDb.Exec(currentString...) _, err := sqlDb.Exec(currentString...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment