baishaojie 1 жил өмнө
parent
commit
e5082c03af

BIN
tmrgo → TMRWatchComm


BIN
TMRWatchComm.zip


BIN
__debug_bin.exe


+ 3 - 3
conf/app.ini

@@ -48,8 +48,8 @@ Type = mysql
 User = root
 Password = root
 #Host = 8.130.17.8:3306
-Host = 192.168.1.93:3326
-#Host = 127.0.0.1:3316
+#Host = 192.168.1.93:3326
+Host = 127.0.0.1:3316
 #Name = haiyuan
 #Password = root
 #Password = root
@@ -73,7 +73,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = yq2
+Name = tmrwatch2
 TablePrefix =
 
 ShowXormlog = false

+ 132 - 0
http/handle/api/surplus.go

@@ -0,0 +1,132 @@
+package api
+
+import (
+	"fmt"
+	"io/ioutil"
+	"log"
+	"net/http"
+	"time"
+	"tmr-watch/conf/setting"
+	"tmr-watch/http/handle/restful"
+	"tmr-watch/pkg/app"
+	"tmr-watch/pkg/e"
+	"tmr-watch/pkg/logging"
+
+	"github.com/Anderson-Lu/gofasion/gofasion"
+	"github.com/gin-gonic/gin"
+)
+
+type surplus struct {
+	Id        int64  `xorm:"id" json:"id"`
+	PastureId int64  `xorm:"pastureId" json:"pastureId"`
+	Surplus   string `xorm:"surplus" json:"surplus"`
+}
+
+func AddSurplus(c *gin.Context) {
+	appG := app.Gin{C: c}
+	s := new(surplus)
+	if err := c.ShouldBind(&s); err != nil {
+		appG.Response(500, e.ERROR, "数据格式不正确!")
+		return
+	}
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	tx.Begin()
+
+	if s.Id > 0 {
+		_, err := tx.Exec(` update surplus set surplus = ?  where id = ? `, s.Surplus, s.Id)
+		if err != nil {
+			log.Println("AddSurplus-error-5: ", err)
+			tx.Rollback()
+			appG.Response(http.StatusOK, e.ERROR, err)
+			return
+		}
+		_, err = tx.Exec(` update feed set feedcode = ?, fname = ? where backup3 = ? `, s.Surplus+"_剩料", s.Surplus+"_剩料", fmt.Sprintf("%d", s.Id))
+		if err != nil {
+			log.Println("AddSurplus-error-6: ", err)
+			tx.Rollback()
+			appG.Response(http.StatusOK, e.ERROR, err)
+			return
+		}
+		appG.Response(http.StatusOK, e.SUCCESS, true)
+		return
+	}
+	_, err := tx.Table("surplus").Insert(s)
+	if err != nil {
+		log.Println("AddSurplus-error-2: ", err)
+		tx.Rollback()
+		appG.Response(http.StatusOK, e.ERROR, err)
+		return
+	}
+
+	s1 := new(surplus)
+	err = tx.Table("surplus").Where(" pastureId = ? ", s.PastureId).Where(" surplus = ? ", s.Surplus).GetFirst(s1).Error
+	if err != nil {
+		log.Println("AddSurplus-error-3: ", err)
+		tx.Rollback()
+		appG.Response(http.StatusOK, e.ERROR, err)
+		return
+	}
+
+	ids, err := setting.SnowIds.NextId()
+	if err != nil {
+		ids = time.Now().UnixNano()
+		logging.Info("create SnowIds err", err)
+	}
+	_, err = tx.Exec(`insert into feed(id,pastureid,feedcode,fname,fclass,fclassid,backup3)values(?,?,?,?,?,(select id from feedclass where pastureid = ? and fcname = ? ),?)`,
+		ids, s.PastureId, s.Surplus+"_剩料", s.Surplus+"_剩料", "剩料", s.PastureId, "剩料", s1.Id)
+	if err != nil {
+		log.Println("AddSurplus-error-4: ", err)
+		tx.Rollback()
+		appG.Response(http.StatusOK, e.ERROR, err)
+		return
+	}
+
+	err = tx.Commit()
+	if err != nil {
+		log.Println("AddSurplus-error-7: ", err)
+		appG.Response(http.StatusOK, e.ERROR, err)
+		tx.Rollback()
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}
+
+func DelSurplus(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsions := gofasion.NewFasion(string(dataByte))
+	id := fsions.Get("id").ValueStr()
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	tx.Begin()
+
+	_, err := tx.Exec(` delete from surplus where id = ?  `, id)
+	if err != nil {
+		log.Println("DelSurplus-error-1: ", err)
+		tx.Rollback()
+		appG.Response(http.StatusOK, e.ERROR, err)
+		return
+	}
+	_, err = tx.Exec(` delete from feed where backup3 = ?  `, id)
+	if err != nil {
+		log.Println("DelSurplus-error-2: ", err)
+		tx.Rollback()
+		appG.Response(http.StatusOK, e.ERROR, err)
+		return
+	}
+
+	err = tx.Commit()
+	if err != nil {
+		log.Println("DelSurplus-error-2: ", err)
+		appG.Response(http.StatusOK, e.ERROR, err)
+		tx.Rollback()
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}

+ 4 - 4
http/handle/yc/yc.go

@@ -36,8 +36,8 @@ func YqCron() {
 		return
 	}
 
-	token := getToken()
-	syncBar(token, pastureinfo.Pastureid)
+	// token := getToken()
+	// syncBar(token, pastureinfo.Pastureid)
 
 	c := cron.New()
 	c.AddFunc("0 0 1 * * *", func() {
@@ -49,6 +49,7 @@ func YqCron() {
 		YcUtirPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcMaterialIssuePush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcBarFeedRemainPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
+		syncBar(token, pastureinfo.Pastureid)
 	})
 
 	c.AddFunc("0 0 6 * * *", func() {
@@ -91,6 +92,7 @@ func YqCron() {
 		YcUtirPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcMaterialIssuePush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcBarFeedRemainPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
+		syncBar(token, pastureinfo.Pastureid)
 	})
 
 	duetimecst2, _ := time.ParseInLocation("15:04:05", "00:05:00", time.Local)
@@ -572,11 +574,9 @@ func syncBar(token, pastureid string) {
 	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()
 

+ 6 - 4
http/handle/yq/yq.go

@@ -36,7 +36,8 @@ func YqCron() {
 		return
 	}
 
-	// token := getToken()
+	token := getToken()
+	syncBar(token, pastureinfo.Pastureid)
 	c := cron.New()
 	c.AddFunc("0 0 1 * * *", func() {
 		token := getToken()
@@ -47,6 +48,7 @@ func YqCron() {
 		YcUtirPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcMaterialIssuePush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcBarFeedRemainPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
+		syncBar(token, pastureinfo.Pastureid)
 	})
 
 	c.AddFunc("0 0 6 * * *", func() {
@@ -132,7 +134,7 @@ func getToken() string {
 	apiKey := "3c6bbff8cf1e496eb8eb9025cd8537fh"
 	secretKey := "26b5d9f63b6142de8f102afb1aa2eb7g"
 
-	req, err := http.NewRequest("POST", "https://test.vmuyun.com/base-server/outSide/token", nil)
+	req, err := http.NewRequest("POST", "https://vmuyun.com/base-server/outSide/token", nil)
 	if err != nil {
 		logs.Error(err)
 	}
@@ -169,7 +171,7 @@ func getToken() string {
 func postPush(data string, msgtype int, tx *xorm.Session, pastureId, token string) {
 
 	// jsonStr, _ := json.Marshal(data)
-	url := "https://test.vmuyun.com/project-server/openApi/feeding/pushData"
+	url := "https://vmuyun.com/project-server/openApi/feeding/pushData"
 	req, err := http.NewRequest("POST", url, strings.NewReader((data)))
 	if err != nil {
 		logs.Error(err)
@@ -553,7 +555,7 @@ func YcMaterialIssuePush(pastureId, farmId, date, token string) error {
 }
 
 func syncBar(token, pastureid string) {
-	req, err := http.NewRequest("GET", "https://test.vmuyun.com/project-server/openApi/feeding/penList", nil)
+	req, err := http.NewRequest("GET", "https://vmuyun.com/project-server/openApi/feeding/penList", nil)
 	if err != nil {
 		logs.Error(err)
 		// return nil