|
@@ -551,3 +551,38 @@ func YcMaterialIssuePush(pastureId, farmId, date, token string) error {
|
|
|
fmt.Println(reqJson)
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func syncBar(token, pastureid string) {
|
|
|
+ req, err := http.NewRequest("GET", "https://test.vmuyun.com/project-server/openApi/feeding/penList", nil)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ // return nil
|
|
|
+ }
|
|
|
+ req.Header.Set("Authorization", token)
|
|
|
+ req.Header.Set("Content-Type", "application/json")
|
|
|
+ client := &http.Client{}
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ body, _ := ioutil.ReadAll(resp.Body)
|
|
|
+ // fmt.Println(string(body)
|
|
|
+ data := make(map[string]interface{}, 0)
|
|
|
+ json.Unmarshal(body, &data)
|
|
|
+ dataList := data["data"].([]interface{})
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ for _, item := range dataList {
|
|
|
+ arg := item.(map[string]interface{})
|
|
|
+ fmt.Println(arg)
|
|
|
+ _, err := tx.Exec(` insert into bar(pen,bname,bcode,pastureid)values(?,?,?,?) ON DUPLICATE KEY UPDATE pen = ? `, arg["districtName"],
|
|
|
+ fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), pastureid, arg["houseName"])
|
|
|
+ fmt.Println(err)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|