Commit 5c153e3f by Joneq

完成所有的开发

parent 8790642e
Showing with 103 additions and 10 deletions
......@@ -7,7 +7,10 @@ import (
"github.com/ichunt2019/cfg/lib"
"github.com/tidwall/gjson"
"golang-asynctask/app/dao/scm_data_dao"
"io/ioutil"
"net/http"
"runtime"
"strconv"
"sync"
"time"
)
......@@ -15,6 +18,8 @@ import (
var (
wg sync.WaitGroup
currentDate string
timeStart time.Time
currentUnix int64
)
func init(){
......@@ -39,7 +44,12 @@ func main() {
runtime.GOMAXPROCS(2)
currentDate = time.Now().Format("2006-01-02")
currentDate := "20210506"
//currentDate := "2021-05-06"
//请求数据
currentUnix = time.Now().Unix()
timeLocal,_ := time.LoadLocation("Local")
timeStart,_ = time.ParseInLocation("2006-01-02",currentDate,timeLocal)
//获取当前时间
fmt.Println(currentDate)
......@@ -47,19 +57,19 @@ func main() {
wg.Add(2)
//指统计指定日期前20条物料记录
go getMaterialstatistic()
go GetMaterialstatistic()
//返回历史物数量以及当日物料统计数量
go getTotalStatistic()
go GetTotalStatistic()
wg.Wait()
}
func getTotalStatistic() {
func GetTotalStatistic() {
defer wg.Done()
jsonStr := requestTableInfo("totalStatistic")
jsonStr := RequestTableInfo("totalStatistic")
//{"data": [{"materialQty": 0, "materialCount": 0, "materialTotalQty": 966724502}], "returnCode": "0000", "returnMsg": "\u6210\u529f"}
if gjson.Get(jsonStr,"returnCode").String() != "0000" || gjson.Get(jsonStr, "data").String() == "[]" {
......@@ -69,6 +79,8 @@ func getTotalStatistic() {
sqlDb := scm_data_dao.GetDashboardDb()
currentSearch :=TopSearch()
for _, res := range gjson.Get(jsonStr, "data").Array() {
erpKey := make(map[string]interface{})
......@@ -78,9 +90,12 @@ func getTotalStatistic() {
return true
})
//获取当前日元器件型号搜索量
//添加数据
_, err := sqlDb.Exec("insert into lie_btv_daily_order_transaction (datetime,daily_ic_num,daily_ic_sn_num,history_ic_search_xinum)" +
"value(?,?,?,?)",currentDate,erpKey["materialQty"],erpKey["materialCount"],erpKey["materialTotalQty"])
_, err := sqlDb.Exec("insert into lie_btv_daily_order_transaction (datetime,daily_ic_num,daily_ic_sn_num,history_ic_search_xinum,current_sku_sum,daily_ic_search_num,daily_ic_search_xinum)" +
"value(?,?,?,?,?,?,?)",currentDate,erpKey["materialQty"],erpKey["materialCount"],erpKey["materialTotalQty"],GetCurrentSku(),currentSearch,currentSearch)
if err != nil {
fmt.Println("getTotalStatistic_sql_"+err.Error())
......@@ -89,11 +104,11 @@ func getTotalStatistic() {
}
func getMaterialstatistic() {
func GetMaterialstatistic() {
defer wg.Done()
jsonStr := requestTableInfo("topStatistic")
jsonStr := RequestTableInfo("topStatistic")
//{"data": [], "returnCode": "0000", "returnMsg": "\u6210\u529f"}
if gjson.Get(jsonStr,"returnCode").String() != "0000" || gjson.Get(jsonStr, "data").String() == "[]" {
......@@ -122,9 +137,59 @@ func getMaterialstatistic() {
}
//获取搜索数据 request example http://so12.ichunt.com/search/SearchLog/aggs?start_time=1621785600&end_time=1621871999&limit=2
// start_time 开始时间戳
// end_time 结束时间戳
// limit 显示前几条
func TopSearch()int64 {
//获取前两百条数据
requestUrl := "http://so12.ichunt.com/search/SearchLog/aggs?start_time="+strconv.FormatInt(timeStart.Unix(),10)+"&end_time="+strconv.FormatInt(currentUnix,10)+"&limit=200"
//requestUrl = "http://so12.ichunt.com/search/SearchLog/aggs?start_time=1621785600&end_time=1621871999&limit=200"
jsonStr := RequestUrl(requestUrl)
//{"error_code":0,"error_msg":"","data":[{"goods_name":"1N5408","count":20},{"goods_name":"OPA356AQDBVRQ1","count":19}]}
if gjson.Get(jsonStr,"error_code").String() != "0"{
fmt.Println("获取搜索数据失败",jsonStr)
return 0
}
insertDataNum := 20
var allNum int64
sqlDb := scm_data_dao.GetDashboardDb()
for _, res := range gjson.Get(jsonStr, "data").Array() {
erpKey := make(map[string]interface{})
res.ForEach(func(key, value gjson.Result) bool {
erpKey[key.String()] = value.String()
if key.String() == "count" {
allNum +=value.Int()
}
return true
})
if insertDataNum > 0{
//添加数据
_, err := sqlDb.Exec("insert into lie_btv_daily_top_search (datetime,sn,search_num)" +
"value(?,?,?)",currentDate,erpKey["goods_name"],erpKey["count"])
if err != nil {
fmt.Println(err)
}
}
insertDataNum--
}
return allNum
}
//获取表信息,返回byte
//request example //http://119.23.228.186:50005/ getCustomsDockingData {"tableName":"SYS_OPERATE_LOG","bizDate":"2021-05-07"}
func requestTableInfo(requestType string)string {
func RequestTableInfo(requestType string)string {
type Sub struct {
......@@ -143,4 +208,31 @@ func requestTableInfo(requestType string)string {
//json字符串
return result
}
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"
requestResult := RequestUrl(requestStr)
return gjson.Get(requestResult,"data.total").String()
}
func RequestUrl(url string)string {
//获取sku数量 http://soso12.ichunt.com/search/Es/searchSku?create_time/range=1620379867,1621489319&goods_status/condition=1
///{"error_code":0,"error_msg":"","data":{"total":"1765","scroll_id":null,"goods_id":[]}}
//获取当日搜索前二十
res, err :=http.Get(url)
if err != nil {
return ""
}
robots, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return ""
}
return string(robots)
}
\ 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