Commit aeab8f3a by 孙龙
parents 9d1d18b2 e0c310f4
#供应链的同步
sync_bigtv_statistics 同步erp的每日统计至shuju库
go run ./cmd/bigtv/sync_bigtv_statistics/main.go -config=./config/dev/ -logdir = ./logs/
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"net/http" "net/http"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
) )
...@@ -44,13 +45,13 @@ func main() { ...@@ -44,13 +45,13 @@ func main() {
runtime.GOMAXPROCS(2) runtime.GOMAXPROCS(2)
currentDate = time.Now().Format("2006-01-02") currentDate = time.Now().Format("2006-01-02")
//currentDate := "2021-05-06"
//请求数据 //请求数据
currentUnix = time.Now().Unix() currentUnix = time.Now().Unix()
timeLocal,_ := time.LoadLocation("Local") timeLocal,_ := time.LoadLocation("Local")
timeStart,_ = time.ParseInLocation("2006-01-02",currentDate,timeLocal) timeStart,_ = time.ParseInLocation("2006-01-02",currentDate,timeLocal)
//获取当前时间 //获取当前时间
fmt.Println(currentDate) fmt.Println(currentDate)
...@@ -64,6 +65,13 @@ func main() { ...@@ -64,6 +65,13 @@ func main() {
wg.Wait() wg.Wait()
} }
func main_back() {
sqlDb := scm_data_dao.GetDashboardDb()
sqlDb.Exec("delete from lie_btv_daily_order_transaction where `datetime` = '2021-05-31'")
sqlDb.Exec("delete from lie_btv_daily_top_order where `datetime` = '2021-05-31'")
sqlDb.Exec("delete from lie_btv_daily_top_search where `datetime` = '2021-05-31'")
}
func GetTotalStatistic() { func GetTotalStatistic() {
...@@ -72,14 +80,14 @@ func GetTotalStatistic() { ...@@ -72,14 +80,14 @@ func GetTotalStatistic() {
jsonStr := RequestTableInfo("totalStatistic") jsonStr := RequestTableInfo("totalStatistic")
//{"data": [{"materialQty": 0, "materialCount": 0, "materialTotalQty": 966724502}], "returnCode": "0000", "returnMsg": "\u6210\u529f"} //{"data": [{"materialQty": 0, "materialCount": 0, "materialTotalQty": 966724502}], "returnCode": "0000", "returnMsg": "\u6210\u529f"}
fmt.Println("totalStatistic"+jsonStr)
if gjson.Get(jsonStr,"returnCode").String() != "0000" || gjson.Get(jsonStr, "data").String() == "[]" { if gjson.Get(jsonStr,"returnCode").String() != "0000" || gjson.Get(jsonStr, "data").String() == "[]" {
fmt.Println(jsonStr)
return return
} }
sqlDb := scm_data_dao.GetDashboardDb() sqlDb := scm_data_dao.GetDashboardDb()
currentSearch :=TopSearch() currentSearch := TopSearch()
for _, res := range gjson.Get(jsonStr, "data").Array() { for _, res := range gjson.Get(jsonStr, "data").Array() {
...@@ -111,14 +119,16 @@ func GetMaterialstatistic() { ...@@ -111,14 +119,16 @@ func GetMaterialstatistic() {
jsonStr := RequestTableInfo("topStatistic") jsonStr := RequestTableInfo("topStatistic")
//{"data": [], "returnCode": "0000", "returnMsg": "\u6210\u529f"} //{"data": [], "returnCode": "0000", "returnMsg": "\u6210\u529f"}
fmt.Println("topStatistic json:"+jsonStr)
if gjson.Get(jsonStr,"returnCode").String() != "0000" || gjson.Get(jsonStr, "data").String() == "[]" { if gjson.Get(jsonStr,"returnCode").String() != "0000" || gjson.Get(jsonStr, "data").String() == "[]" {
fmt.Println(jsonStr)
return return
} }
sqlDb := scm_data_dao.GetDashboardDb() sqlDb := scm_data_dao.GetDashboardDb()
i:=1
for _, res := range gjson.Get(jsonStr, "data").Array() { for _, res := range gjson.Get(jsonStr, "data").Array() {
erpKey := make(map[string]interface{}) erpKey := make(map[string]interface{})
...@@ -128,8 +138,9 @@ func GetMaterialstatistic() { ...@@ -128,8 +138,9 @@ func GetMaterialstatistic() {
}) })
//添加数据 //添加数据
_, err := sqlDb.Exec("insert into lie_btv_daily_top_order (datetime,sn,order_num)" + _, err := sqlDb.Exec("insert into lie_btv_daily_top_order (sort,datetime,sn,order_num)" +
"value(?,?,?)",currentDate,erpKey["materialName"],erpKey["materialQty"]) "value(?,?,?,?)",i,currentDate,erpKey["materialName"],erpKey["materialQty"])
i++
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
...@@ -159,6 +170,7 @@ func TopSearch()int64 { ...@@ -159,6 +170,7 @@ func TopSearch()int64 {
sqlDb := scm_data_dao.GetDashboardDb() sqlDb := scm_data_dao.GetDashboardDb()
i:=1
for _, res := range gjson.Get(jsonStr, "data").Array() { for _, res := range gjson.Get(jsonStr, "data").Array() {
erpKey := make(map[string]interface{}) erpKey := make(map[string]interface{})
...@@ -173,13 +185,13 @@ func TopSearch()int64 { ...@@ -173,13 +185,13 @@ func TopSearch()int64 {
if insertDataNum > 0{ if insertDataNum > 0{
//添加数据 //添加数据
_, err := sqlDb.Exec("insert into lie_btv_daily_top_search (datetime,sn,search_num)" + _, err := sqlDb.Exec("insert into lie_btv_daily_top_search (sort,datetime,sn,search_num)" +
"value(?,?,?)",currentDate,erpKey["goods_name"],erpKey["count"]) "value(?,?,?,?)",i,currentDate,erpKey["goods_name"],erpKey["count"])
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
} }
i++
insertDataNum-- insertDataNum--
} }
...@@ -200,7 +212,7 @@ func RequestTableInfo(requestType string)string { ...@@ -200,7 +212,7 @@ func RequestTableInfo(requestType string)string {
client := rpc.NewHTTPClient("http://119.23.228.186:50005/") client := rpc.NewHTTPClient("http://119.23.228.186:50005/")
client.UseService(&sub) client.UseService(&sub)
result,err := sub.Get_materialstatistic(`{"date":"`+currentDate+`","requestType":"`+requestType+`"}`) result,err := sub.Get_materialstatistic(`{"date":"`+strings.Replace(currentDate, "-", "", -1)+`","requestType":"`+requestType+`"}`)
if err != nil { if err != nil {
fmt.Println(requestType+"请求服务器出错"+err.Error()) fmt.Println(requestType+"请求服务器出错"+err.Error())
return "" return ""
...@@ -210,10 +222,13 @@ func RequestTableInfo(requestType string)string { ...@@ -210,10 +222,13 @@ func RequestTableInfo(requestType string)string {
return result return result
} }
func GetCurrentSku()string { func GetCurrentSku()string {
requestStr :="http://soso12.ichunt.com/search/Es/searchSku?create_time/range="+strconv.FormatInt(timeStart.Unix(),10)+","+strconv.FormatInt(currentUnix,10)+"&goods_status/condition=1" requestStr :="http://so12.ichunt.com/search/Es/searchSku?goods_status/condition=1"
fmt.Println(requestStr)
requestResult := RequestUrl(requestStr) requestResult := RequestUrl(requestStr)
fmt.Println("sku总量json"+requestResult)
return gjson.Get(requestResult,"data.total").String() return gjson.Get(requestResult,"data.total").String()
} }
......
...@@ -22,3 +22,11 @@ ShowSQL = true ...@@ -22,3 +22,11 @@ ShowSQL = true
max_idle_conn = 10 max_idle_conn = 10
table_prefix = "" table_prefix = ""
max_conn_life_time = 100 max_conn_life_time = 100
[dashboard]
dns = "dashboard:0633F@bc92af0ecf9789d@tcp(172.18.137.35:3306)/dashboard?charset=utf8&parseTime=true&loc=Asia%2FShanghai"
max_open_conn = 20
max_idle_conn = 10
table_prefix = ""
max_conn_life_time = 100
\ No newline at end of file
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