baishaojie 9 месяцев назад
Родитель
Сommit
0a1cf1b3fd
4 измененных файлов с 41 добавлено и 3 удалено
  1. BIN
      __debug_bin.exe
  2. 1 1
      conf/app.ini
  3. 2 1
      http/handle/api/scheduled.go
  4. 38 1
      http/handle/yc/yc.go

BIN
__debug_bin.exe


+ 1 - 1
conf/app.ini

@@ -73,7 +73,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = tmrwatch5
+Name = yq2
 TablePrefix =
 
 ShowXormlog = false

+ 2 - 1
http/handle/api/scheduled.go

@@ -16,6 +16,7 @@ import (
 
 	"tmr-watch/conf/setting"
 	"tmr-watch/http/handle/restful"
+	"tmr-watch/http/handle/yc"
 	"tmr-watch/pkg/app"
 	"tmr-watch/pkg/e"
 	"tmr-watch/pkg/logging"
@@ -143,7 +144,7 @@ func CronScheduled(ctx context.Context) {
 	// })
 	// xdmy.Start()
 	// InitMqttClient()
-	// yc.YqCron()
+	yc.YqCron()
 }
 
 type ScheduledInfo struct {

+ 38 - 1
http/handle/yc/yc.go

@@ -37,7 +37,8 @@ func YqCron() {
 	}
 
 	token := getToken()
-	YcBarFeedRemainPush(pastureinfo.Pastureid, pastureinfo.Werks, "2024-05-20", token)
+	syncBar(token, pastureinfo.Pastureid)
+
 	c := cron.New()
 	c.AddFunc("0 0 1 * * *", func() {
 		token := getToken()
@@ -552,3 +553,39 @@ 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)
+	}
+
+}