baishaojie 2 anni fa
parent
commit
36ecae01c1
52 ha cambiato i file con 420 aggiunte e 137 eliminazioni
  1. BIN
      KPTAdmin64.exe
  2. BIN
      KPTAdmin64.zip
  3. BIN
      TMRWatchComm
  4. 2 0
      bar.sql
  5. 4 4
      conf/app.ini
  6. BIN
      dist.zip
  7. 0 0
      dist/index.html
  8. 0 0
      dist/static/css/app.f149de2b.css
  9. 0 0
      dist/static/css/chunk-elementUI.f92cd1c5.css
  10. 0 0
      dist/static/img/iconfont.7d9f8392.svg
  11. 0 0
      dist/static/js/app.8a3d01f3.js
  12. 0 0
      dist/static/js/app.aba0701a.js
  13. 0 0
      dist/static/js/chunk-52ecc0ac.a7dca219.js
  14. 0 0
      dist/static/js/chunk-5c4dc4a9.a119f214.js
  15. 0 0
      dist/static/js/chunk-7085d3cc.df62b750.js
  16. 0 0
      dist/static/js/chunk-b702d234.66ccaac4.js
  17. 0 0
      dist/static/js/chunk-elementUI.60d920b6.js
  18. 0 0
      dist/static/js/chunk-libs.bc9e1339.js
  19. BIN
      dist现代牧业.zip
  20. BIN
      dist现代牧业/dist/favicon.ico
  21. 0 0
      dist现代牧业/dist/index.html
  22. 0 0
      dist现代牧业/dist/static/css/app.427dfb3b.css
  23. 0 0
      dist现代牧业/dist/static/css/chunk-elementUI.5dea96f6.css
  24. 0 0
      dist现代牧业/dist/static/css/chunk-libs.1664ae71.css
  25. BIN
      dist现代牧业/dist/static/fonts/element-icons.535877f5.woff
  26. BIN
      dist现代牧业/dist/static/fonts/element-icons.732389de.ttf
  27. BIN
      dist现代牧业/dist/static/img/404.a57b6f31.png
  28. BIN
      dist现代牧业/dist/static/img/404_cloud.0f4bc32b.png
  29. 28 0
      dist现代牧业/dist/static/img/iconfont.0ddaba12.svg
  30. BIN
      dist现代牧业/dist/static/img/logo.afed751a.png
  31. BIN
      dist现代牧业/dist/static/img/logo1.0121925c.png
  32. BIN
      dist现代牧业/dist/static/img/logo_u3.3c77f543.png
  33. BIN
      dist现代牧业/dist/static/img/nlogin-bg1.77301f56.jpg
  34. BIN
      dist现代牧业/dist/static/img/row-bg3.b3be7548.png
  35. BIN
      dist现代牧业/dist/static/img/topBg.69ecd1e1.png
  36. 0 0
      dist现代牧业/dist/static/js/app.b1003d4f.js
  37. 0 0
      dist现代牧业/dist/static/js/chunk-52ecc0ac.98e5f964.js
  38. 0 0
      dist现代牧业/dist/static/js/chunk-5c4dc4a9.eb511b2a.js
  39. 0 0
      dist现代牧业/dist/static/js/chunk-b702d234.0ec8f519.js
  40. 0 0
      dist现代牧业/dist/static/js/chunk-cf83d4b8.b3f7b120.js
  41. 0 0
      dist现代牧业/dist/static/js/chunk-elementUI.a8f15e3f.js
  42. 0 0
      dist现代牧业/dist/static/js/chunk-libs.011550ed.js
  43. 4 3
      middleware/jwt/jwt.go
  44. 93 12
      routers/api/db.go
  45. 114 52
      routers/api/material.go
  46. 46 12
      routers/api/sap/sap.go
  47. 50 20
      routers/api/scheduled.go
  48. 3 25
      routers/api/spillage.go
  49. 65 2
      routers/api/user.go
  50. 11 7
      routers/router.go
  51. BIN
      tmrgo.zip
  52. 0 0
      update.220802.sql

BIN
KPTAdmin64.exe


BIN
KPTAdmin64.zip


BIN
TMRWatchComm


+ 2 - 0
bar.sql

@@ -0,0 +1,2 @@
+ALTER TABLE `bar` 
+ADD COLUMN `jmp` tinyint NULL DEFAULT 0 AFTER `backup2`

+ 4 - 4
conf/app.ini

@@ -45,11 +45,11 @@ GRFDURL = http://120.48.30.31:88
 [database]
 Type = mysql
 User = root
-#Password = root
-#Host = 192.168.1.93:3326
-Host = 127.0.0.1:3316
-Name = tmrwatch2
 Password = root
+Host = 192.168.1.93:3326
+#Host = 127.0.0.1:3316
+Name = tmrwatch3
+Password = root 
 #Password = root
 #Password = kptzhu@163.com
 #Host = 192.168.1.50:3326

BIN
dist.zip


File diff suppressed because it is too large
+ 0 - 0
dist/index.html


File diff suppressed because it is too large
+ 0 - 0
dist/static/css/app.f149de2b.css


File diff suppressed because it is too large
+ 0 - 0
dist/static/css/chunk-elementUI.f92cd1c5.css


+ 0 - 0
dist/static/img/iconfont.0ddaba12.svg → dist/static/img/iconfont.7d9f8392.svg


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/app.8a3d01f3.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/app.aba0701a.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-52ecc0ac.a7dca219.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-5c4dc4a9.a119f214.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-7085d3cc.df62b750.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-b702d234.66ccaac4.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-elementUI.60d920b6.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-libs.bc9e1339.js


BIN
dist现代牧业.zip


BIN
dist现代牧业/dist/favicon.ico


File diff suppressed because it is too large
+ 0 - 0
dist现代牧业/dist/index.html


File diff suppressed because it is too large
+ 0 - 0
dist现代牧业/dist/static/css/app.427dfb3b.css


+ 0 - 0
dist/static/css/chunk-elementUI.5dea96f6.css → dist现代牧业/dist/static/css/chunk-elementUI.5dea96f6.css


File diff suppressed because it is too large
+ 0 - 0
dist现代牧业/dist/static/css/chunk-libs.1664ae71.css


BIN
dist现代牧业/dist/static/fonts/element-icons.535877f5.woff


BIN
dist现代牧业/dist/static/fonts/element-icons.732389de.ttf


BIN
dist现代牧业/dist/static/img/404.a57b6f31.png


BIN
dist现代牧业/dist/static/img/404_cloud.0f4bc32b.png


File diff suppressed because it is too large
+ 28 - 0
dist现代牧业/dist/static/img/iconfont.0ddaba12.svg


BIN
dist现代牧业/dist/static/img/logo.afed751a.png


BIN
dist现代牧业/dist/static/img/logo1.0121925c.png


BIN
dist现代牧业/dist/static/img/logo_u3.3c77f543.png


BIN
dist现代牧业/dist/static/img/nlogin-bg1.77301f56.jpg


BIN
dist现代牧业/dist/static/img/row-bg3.b3be7548.png


BIN
dist现代牧业/dist/static/img/topBg.69ecd1e1.png


File diff suppressed because it is too large
+ 0 - 0
dist现代牧业/dist/static/js/app.b1003d4f.js


+ 0 - 0
dist/static/js/chunk-52ecc0ac.98e5f964.js → dist现代牧业/dist/static/js/chunk-52ecc0ac.98e5f964.js


+ 0 - 0
dist/static/js/chunk-5c4dc4a9.eb511b2a.js → dist现代牧业/dist/static/js/chunk-5c4dc4a9.eb511b2a.js


+ 0 - 0
dist/static/js/chunk-b702d234.0ec8f519.js → dist现代牧业/dist/static/js/chunk-b702d234.0ec8f519.js


+ 0 - 0
dist/static/js/chunk-cf83d4b8.b3f7b120.js → dist现代牧业/dist/static/js/chunk-cf83d4b8.b3f7b120.js


+ 0 - 0
dist/static/js/chunk-elementUI.a8f15e3f.js → dist现代牧业/dist/static/js/chunk-elementUI.a8f15e3f.js


+ 0 - 0
dist/static/js/chunk-libs.011550ed.js → dist现代牧业/dist/static/js/chunk-libs.011550ed.js


+ 4 - 3
middleware/jwt/jwt.go

@@ -3,11 +3,11 @@ package jwt
 import (
 	//"strings"
 
-	"github.com/dgrijalva/jwt-go"
-	"github.com/gin-gonic/gin"
 	"../../pkg/e"
 	"../../pkg/util"
 	jwtGet "../../pkg/util"
+	"github.com/dgrijalva/jwt-go"
+	"github.com/gin-gonic/gin"
 )
 
 func JWT() gin.HandlerFunc {
@@ -49,7 +49,8 @@ func JWT() gin.HandlerFunc {
 		t, _ := jwt.Parse(token, func(*jwt.Token) (interface{}, error) {
 			return jwtGet.JwtSecret, nil
 		})
-		c.Set("jwt_username",jwtGet.GetIdFromClaims("username", t.Claims))
+		c.Set("jwt_username", jwtGet.GetIdFromClaims("username", t.Claims))
+
 		c.Next()
 	}
 }

+ 93 - 12
routers/api/db.go

@@ -3440,15 +3440,73 @@ func UpdateFpdetailBar(c *gin.Context) {
 	id := fsion.Get("id").ValueStr()
 
 	tx := restful.Engine.NewSession()
+	tx.Begin()
 
-	// oldLpplandtl1List, err := tx.SQL(` select  lppland.* from lpplandtl1  lppland    where lppland.barid = ? `, id).Query().List()
-	// if err != nil {
-	// 	logs.Error(err)
-	// 	appG.Response(http.StatusOK, e.ERROR, false)
-	// 	return
-	// }
+	fpdList, err := tx.SQL(` select  id,ifnull(ROUND((1-ptsrate)*weight,2),"") weight,ptuse  from fpdetail where pastureid = ?  and barid = ? order by times `,
+		pastureid, id).Query().List()
+	if err != nil {
+		logs.Error(err)
+	}
 
-	tx.Begin()
+	for _, fpd := range fpdList {
+
+		lpplandList, err := tx.SQL(` select  lppland.id,lppland.lweight from lpplandtl1 lppland join lpplan lpp on lpp.id = lppland.lppid 
+	where lppland.pastureid = ?  and lppland.fpdid = ? order by lpp.sort desc  `,
+			pastureid, fpd["id"]).Query().List()
+		if err != nil {
+			tx.Rollback()
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, false)
+			return
+		}
+		var lweight float64
+		for _, lppland := range lpplandList {
+			lweight1, _ := strconv.ParseFloat(lppland["lweight"].(string), 64)
+			lweight += lweight1
+		}
+
+		fpdweight, _ := strconv.ParseFloat(fpd["weight"].(string), 64)
+		ptuse, _ := strconv.ParseFloat(fpd["ptuse"].(string), 64)
+
+		if fpdweight >= ptuse && lweight == ptuse {
+			continue
+		} else {
+			if lweight <= fpdweight {
+				_, err := tx.SQL(` update fpdetail set ptuse = ?  where id = ? `, lweight, fpd["id"]).Execute()
+				if err != nil {
+					tx.Rollback()
+					logs.Error(err)
+					appG.Response(http.StatusOK, e.ERROR, false)
+					return
+				}
+			} else {
+				weight := fpdweight - lweight
+				for _, lppland := range lpplandList {
+					lpplandlweight, _ := strconv.ParseFloat(lppland["lweight"].(string), 64)
+					if weight >= lpplandlweight {
+						weight = weight - lpplandlweight
+						_, err := tx.SQL(` delete from  lppland  where id = ? `, lppland["id"]).Execute()
+						if err != nil {
+							tx.Rollback()
+							logs.Error(err)
+							appG.Response(http.StatusOK, e.ERROR, false)
+							return
+						}
+					} else {
+						_, err := tx.SQL(` update   lppland set lweight = ? where id = ? `, lppland["lweight"].(float64)-weight, lppland["id"]).Execute()
+						if err != nil {
+							tx.Rollback()
+							logs.Error(err)
+							appG.Response(http.StatusOK, e.ERROR, false)
+							return
+						}
+						weight = 0
+						break
+					}
+				}
+			}
+		}
+	}
 
 	for _, list := range fsion.Get("data").Array() {
 		ftmap := make(map[string]interface{})
@@ -3577,6 +3635,7 @@ func UpdateFpdetailBar(c *gin.Context) {
 
 		}
 	}
+
 	tx.Commit()
 
 	now := time.Now()
@@ -4300,6 +4359,27 @@ func FpdImportExcel(c *gin.Context) {
 					continue
 				}
 
+				ftexist, err := tx.SQL(` select id from  feedp where barname = ?  and pastureid = ? and ftname = ?  `, dataexcel["barname"], pastureid, dataexcel["ftname"]).Exist()
+				if err != nil {
+					logs.Error(err)
+					appG.Response(http.StatusInternalServerError, e.ERROR, false)
+					return
+				}
+				if !ftexist {
+					tx.SQL(` delete from lpplandtl1 where barname = ? and pastureid = ?  `, dataexcel["barname"], pastureid).Exist()
+					if err != nil {
+						logs.Error(err)
+						appG.Response(http.StatusInternalServerError, e.ERROR, false)
+						return
+					}
+					tx.SQL(`  update fpdetail set ptuse = 0  where  barname = ? and pastureid = ?   `, dataexcel["barname"], pastureid).Exist()
+					if err != nil {
+						logs.Error(err)
+						appG.Response(http.StatusInternalServerError, e.ERROR, false)
+						return
+					}
+				}
+
 				exist, err := tx.SQL(` select id from  feedp where barname = ?  and pastureid = ?  `, dataexcel["barname"], pastureid).Exist()
 				if err != nil {
 					logs.Error(err)
@@ -4794,6 +4874,7 @@ func DeleteSpillageAll(c *gin.Context) {
 	parammaps := fsion.Get("parammaps")
 	pastureid := parammaps.Get("pastureid").ValueStr()
 	times := parammaps.Get("times").ValueStr()
+	barid := parammaps.Get("barid").ValueStr()
 
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
@@ -4824,7 +4905,7 @@ func DeleteSpillageAll(c *gin.Context) {
 	}
 
 	tx.Begin()
-	_, err = tx.SQL(` delete  from  lpplandtl1  where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  and times = ?) `, pastureid, pastureid, times).Execute()
+	_, err = tx.SQL(` delete  from  lpplandtl1  where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  and times = ?) and find_in_set(barid,?) `, pastureid, pastureid, times, barid).Execute()
 	if err != nil {
 		tx.Rollback()
 		logs.Error(err)
@@ -4832,7 +4913,7 @@ func DeleteSpillageAll(c *gin.Context) {
 		return
 	}
 	_, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
-	WHERE pastureid=? and times = ? `, pastureid, times).Execute()
+	WHERE pastureid=? and times = ?   and find_in_set(barid,?)   `, pastureid, times, barid).Execute()
 	if err != nil {
 		tx.Rollback()
 		logs.Error(err)
@@ -5108,7 +5189,7 @@ func GetRemind(c *gin.Context) {
 	}
 
 	// pastureid = "3"
-	resp, err := http.Get(fmt.Sprintf("http://tmrwatch.cn/notice/msgtype?sys_name=tmrwatch_test&pasture_id=%s", pastureid))
+	resp, err := http.Get(fmt.Sprintf("http://tmrwatch.cn/notice/msgtype?sys_name=tmrwatch&pasture_id=%s", pastureid))
 	if err != nil {
 		logs.Error(err)
 		appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -5204,7 +5285,7 @@ func UpdateRemind(c *gin.Context) {
 	noticeMsgtype.DelayTime = parammaps.Get("delay_time").ValueInt64()
 	noticeMsgtype.Status = parammaps.Get("status").ValueInt64()
 	//TODO
-	noticeMsgtype.SysName = "tmrWatch_test"
+	noticeMsgtype.SysName = "tmrWatch"
 	userList := parammaps.Get("user").Array()
 
 	var userstr []string
@@ -5237,7 +5318,7 @@ func UpdateRemind(c *gin.Context) {
 	body, _ := ioutil.ReadAll(resp.Body)
 	fmt.Println("response Body:", string(body))
 
-	getresp, err := http.Get(fmt.Sprintf("http://tmrwatch.cn/notice/msgtype?sys_name=tmrwatch_test&pasture_id=%d&service_id=%d", noticeMsgtype.PastureId, id))
+	getresp, err := http.Get(fmt.Sprintf("http://tmrwatch.cn/notice/msgtype?sys_name=tmrwatch&pasture_id=%d&service_id=%d", noticeMsgtype.PastureId, id))
 	if err != nil {
 		logs.Error(err)
 		appG.Response(http.StatusInternalServerError, e.ERROR, err)

+ 114 - 52
routers/api/material.go

@@ -1,6 +1,7 @@
 package api
 
 import (
+	"encoding/json"
 	"io/ioutil"
 	"net/http"
 	"strconv"
@@ -107,7 +108,9 @@ func GetSubPlan(c *gin.Context) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	downloadplandtl1List, err := tx.SQL(` select DATE_FORMAT(d1.begintime, '%Y-%m-%d %H:%i:%S') as begintime, DATE_FORMAT(d1.intime, '%Y-%m-%d %H:%i:%S') as intime ,f.id as feedid,d1.fname,d1.feedcode,f.autosecond,f.autozone,d1.lweight,d1.sort,d1.buttontype,d1.actualweightminus from  downloadplandtl1 d1
+	downloadplandtl1List, err := tx.SQL(` select DATE_FORMAT(d1.begintime, '%Y-%m-%d %H:%i:%S') as begintime,
+	 DATE_FORMAT(d1.intime, '%Y-%m-%d %H:%i:%S') as intime ,f.id as feedid,d1.fname,d1.feedcode,f.autosecond,
+	f.autozone,d1.lweight,d1.sort,d1.buttontype,d1.actualweightminus,f.confirmstart,f.jmp from  downloadplandtl1 d1
 	 left join feed f 
 	on f.feedcode = d1.feedcode and f.pastureid = d1.pastureid  where d1.pid = ? and d1.pastureid = ? `, pid, pastureid).Query().List()
 	if err != nil {
@@ -115,7 +118,11 @@ func GetSubPlan(c *gin.Context) {
 		appG.Response(http.StatusInternalServerError, e.ERROR, err)
 		return
 	}
-	downloadplandtl2List, err := tx.SQL(` select  d2.sort,DATE_FORMAT(d2.begintime, '%Y-%m-%d %H:%i:%S') as begintime ,DATE_FORMAT(d2.intime, '%Y-%m-%d %H:%i:%S')  as intime  ,d2.id,d2.pid,d2.fbarid,d2.fname as fbarname,d2.lweight,d.lpplantype,d2.actualweightminus from  downloadplandtl2 d2 join downloadedplan d on d.id = d2.pid where d2.pid = ? and d2.pastureid = ? `, pid, pastureid).Query().List()
+	downloadplandtl2List, err := tx.SQL(` select  d2.sort,DATE_FORMAT(d2.begintime, '%Y-%m-%d %H:%i:%S') as begintime ,DATE_FORMAT(d2.intime, '%Y-%m-%d %H:%i:%S')  as intime 
+	 ,d2.id,d2.pid,d2.fbarid,d2.fname as fbarname,d2.lweight,d.lpplantype,d2.actualweightminus ,ifnull(b.autozone,0) as autozone,ifnull(b.autosecond,"") as  autosecond,ifnull(b.isstart,1) as isstart ,ifnull(b.jmp,0) as jmp
+	 from  downloadplandtl2 d2
+	  join downloadedplan d  on d.id = d2.pid  
+	   left join  bar b on d2.fbarid = b.id where d2.pid = ? and d2.pastureid = ? `, pid, pastureid).Query().List()
 	if err != nil {
 		logs.Error(err)
 		appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -134,8 +141,11 @@ func GetSubPlan(c *gin.Context) {
 		data["actualweightminus"] = d2item["actualweightminus"]
 		data["intime"] = d2item["intime"]
 		data["begintime"] = d2item["begintime"]
-		// flweight, _ := strconv.ParseFloat(d2item["lweight"].(string), 64)
 		data["sort"] = d2item["sort"]
+		data["autozone"] = d2item["autozone"]
+		data["autosecond"] = d2item["autosecond"]
+		data["isstart"] = d2item["isstart"]
+		data["jmp"] = d2item["jmp"]
 		d2List = append(d2List, data)
 	}
 
@@ -153,6 +163,8 @@ func GetSubPlan(c *gin.Context) {
 		d1["intime"] = d1item["intime"]
 		d1["begintime"] = d1item["begintime"]
 		d1["actualweightminus"] = d1item["actualweightminus"]
+		d1["confirmstart"] = d1item["confirmstart"]
+		d1["jmp"] = d1item["jmp"]
 		d1List = append(d1List, d1)
 	}
 
@@ -172,7 +184,8 @@ func CompletePlan(c *gin.Context) {
 	feedid := parammaps.Get("feedid").ValueStr()
 	lastactualweight := parammaps.Get("lastactualweight").ValueDefaultFloat64(0)
 	actualweightminus := parammaps.Get("actualweightminus").ValueDefaultFloat64(0)
-	tmrid := parammaps.Get("tmrid").ValueStr()
+	actualweight := parammaps.Get("actualweight").ValueDefaultFloat64(0)
+	datacaptureno := parammaps.Get("datacaptureno").ValueStr()
 	begintime := parammaps.Get("begintime").ValueStr()
 	intime := parammaps.Get("intime").ValueStr()
 	sort := parammaps.Get("sort").ValueStr()
@@ -182,17 +195,23 @@ func CompletePlan(c *gin.Context) {
 	pastureid := parammaps.Get("pastureid").ValueStr()
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
-	// begintime := ""
-	// if begintimestr != "" {
-	// 	begintime = strings.ReplaceAll("2022-08-11T13:43:34+08:00", "T", " ")[:len("2006-01-02 15:04:05")]
-	// }
+
+	_, err := tx.SQL(` update downloadedplan set  tmrid = ( select id from tmr where  datacaptureno = ? and pastureid = ?) , 
+	tmrtname = ( select eqcode from tmr where  datacaptureno = ? and pastureid = ?) where id = ? and tmrid != ( select id from tmr where  datacaptureno = ? and pastureid = ?)`,
+		datacaptureno, pastureid, datacaptureno, pastureid, pid, datacaptureno, pastureid).Execute()
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusInternalServerError, e.ERROR, err)
+		return
+	}
 
 	if lpplantype == 0 {
 
 		_, err := tx.SQL(` update downloadplandtl1 set  begintime = ? , actualweightminus = ifnull(actualweightminus,0) +? ,
-		intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ?  where pid = ?
-		and sort = ? and feedcode = (select feedcode from feed where id = ? )`,
-			begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, pid, sort, feedid).Execute()
+		intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,
+		havebuttom = 1,lastactualweight = ?  where pid = ?
+		and sort = ? and feedcode = (select feedcode from feed where id = ? ) and  (intime is null )`,
+			begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, pid, sort, feedid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -200,16 +219,9 @@ func CompletePlan(c *gin.Context) {
 		}
 
 		_, err = tx.SQL(` update downloadplandtl1_exec set begintime = ? ,actualweightminus = ifnull(actualweightminus,0)+ ? ,
-		intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ?  where pid = ?
-		and sort = ? `,
-			begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, pid, sort).Execute()
-		if err != nil {
-			logs.Error(err)
-			appG.Response(http.StatusInternalServerError, e.ERROR, err)
-			return
-		}
-
-		execExist, err := tx.SQL(` select id from downloadplandtl1_exec where pid = ? and intime is null `, pid).Exist()
+		intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ?  where pid = ?
+		and sort = ?  and  (intime is null ) `,
+			begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, pid, sort).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -237,7 +249,7 @@ func CompletePlan(c *gin.Context) {
 			actualweight := lweight / sumlweight * actualweightminus
 			last := lweight / sumlweight * lastactualweight
 			_, err := tx.SQL(` update downloadplandtl2 set actualweightminus = ifnull(actualweightminus,0)+?, actualweight = ?,
-			lastactualweight = ? , intime = ?,begintime = ? ,havebuttom = 1,buttontype = ? where id = ? `, actualweight,
+			lastactualweight = ? , intime = ?,begintime = ? ,havebuttom = 1,buttontype = ? where id = ?   and  (intime is null ) `, actualweight,
 				actualweight, last, intime, begintime, buttontype, d2["id"]).Execute()
 			if err != nil {
 				logs.Error(err)
@@ -246,8 +258,15 @@ func CompletePlan(c *gin.Context) {
 			}
 		}
 
+		execExist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and  (intime is null )  `, pid).Exist()
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusInternalServerError, e.ERROR, err)
+			return
+		}
+
 		if !execExist {
-			_, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
+			_, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ?  `, intime, pid).Execute()
 			if err != nil {
 				logs.Error(err)
 				appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -255,8 +274,9 @@ func CompletePlan(c *gin.Context) {
 			}
 		}
 
-		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl1  where pid = ? and intime is  null  order by sort limit 0,1 )  where id = ?  and pastureid = ? `,
-			pid, intime, pid, tmrid, pastureid).Execute()
+		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = 
+		(select sort from downloadplandtl1  where pid = ? and intime is  null  order by sort limit 0,1 )  where datacaptureno = ?  and pastureid = ?    `,
+			pid, intime, pid, datacaptureno, pastureid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -266,8 +286,8 @@ func CompletePlan(c *gin.Context) {
 	} else if lpplantype == 1 {
 
 		_, err := tx.SQL(` update downloadplandtl2 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
-		lastactualweight = ? , intime = ? ,begintime = ?,havebuttom = 1,buttontype = ? where id = ? `,
-			actualweightminus, actualweightminus, lastactualweight, intime, begintime, buttontype, d2id).Execute()
+		lastactualweight = ? , intime = ? ,begintime = ?,havebuttom = 1,buttontype = ? where id = ?    and  (intime is null  ) `,
+			actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, d2id).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -275,8 +295,8 @@ func CompletePlan(c *gin.Context) {
 		}
 
 		_, err = tx.SQL(` update downloadplandtl1_exec set  actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
-		lastactualweight = ? , intime = ?,begintime= ? ,havebuttom = 1,buttontype= ?  where pid = ? `,
-			actualweightminus, actualweightminus, lastactualweight, intime, begintime, buttontype, pid).Execute()
+		lastactualweight = ? , intime = ?,begintime= ? ,havebuttom = 1,buttontype= ?  where pid = ?     and  (intime is null )  `,
+			actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, pid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -284,15 +304,15 @@ func CompletePlan(c *gin.Context) {
 		}
 
 		_, err = tx.SQL(` update downloadplandtl1 set  actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
-		lastactualweight = ? , intime = ?,begintime=? ,havebuttom = 1,buttontype = ?  where pid = ? `,
-			actualweightminus, actualweightminus, lastactualweight, intime, begintime, buttontype, pid).Execute()
+		lastactualweight = ? , intime = ?,begintime=? ,havebuttom = 1,buttontype = ?  where pid = ?     and  (intime is null  )  `,
+			actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, pid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
 			return
 		}
 
-		exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null `, pid).Exist()
+		exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ?  and intime is null `, pid).Exist()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -300,7 +320,7 @@ func CompletePlan(c *gin.Context) {
 		}
 
 		if !exist {
-			_, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
+			_, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ?   `, intime, pid).Execute()
 			if err != nil {
 				logs.Error(err)
 				appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -308,8 +328,9 @@ func CompletePlan(c *gin.Context) {
 			}
 		}
 
-		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl2  where pid = ? and intime is  null  order by sort limit 0,1 )  where id = ?  and pastureid = ? `,
-			pid, intime, pid, tmrid, pastureid).Execute()
+		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl2  
+			where pid = ? and intime is  null  order by sort limit 0,1 )  where datacaptureno = ?  and pastureid = ?    `,
+			pid, intime, pid, datacaptureno, pastureid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -318,9 +339,9 @@ func CompletePlan(c *gin.Context) {
 
 	} else if lpplantype == 2 {
 		_, err := tx.SQL(` update downloadplandtl1 set  begintime = ? , actualweightminus =ifnull(actualweightminus,0)+ ? ,
-		intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ?  where pid = ?
-		and sort = ? and feedcode = (select feedcode from feed where id = ? )`,
-			begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, begintime, pid, sort, feedid).Execute()
+		intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ?  where pid = ?
+		and sort = ? and feedcode = (select feedcode from feed where id = ? )   and  (intime is null  )`,
+			begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, begintime, pid, sort, feedid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -328,17 +349,18 @@ func CompletePlan(c *gin.Context) {
 		}
 
 		_, err = tx.SQL(` update downloadplandtl1_exec set begintime = ? ,actualweightminus =ifnull(actualweightminus,0)+ ? ,
-		intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ?  where pid = ?
-		and sort = ? `,
-			begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, begintime, pid, sort).Execute()
+		intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ?  where pid = ?
+		and sort = ?   and  (intime is null )  `,
+			begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, begintime, pid, sort).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
 			return
 		}
 
-		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl1  where pid = ? and intime is  null  order by sort limit 0,1 )  where id = ?  and pastureid = ? `,
-			pid, intime, pid, tmrid, pastureid).Execute()
+		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = 
+		(select sort from downloadplandtl1  where pid = ? and intime is  null  order by sort limit 0,1 )  where datacaptureno = ?  and pastureid = ?    `,
+			pid, intime, pid, datacaptureno, pastureid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -347,15 +369,15 @@ func CompletePlan(c *gin.Context) {
 
 	} else {
 		_, err := tx.SQL(` update downloadplandtl2 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
-		lastactualweight = ? , intime = ? ,havebuttom = 1,buttontype = ?,begintime = ? where id = ? `,
-			actualweightminus, actualweightminus, lastactualweight, intime, buttontype, begintime, d2id).Execute()
+		lastactualweight = ? , intime = ? ,havebuttom = 1,buttontype = ?,begintime = ? where id = ?     and  (intime is null )  `,
+			actualweightminus, actualweight, lastactualweight, intime, buttontype, begintime, d2id).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
 			return
 		}
 
-		exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null `, pid).Exist()
+		exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null`, pid).Exist()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -363,15 +385,16 @@ func CompletePlan(c *gin.Context) {
 		}
 
 		if !exist {
-			_, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
+			_, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ?   `, intime, pid).Execute()
 			if err != nil {
 				logs.Error(err)
 				appG.Response(http.StatusInternalServerError, e.ERROR, err)
 				return
 			}
 		}
-		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl2  where pid = ? and intime is  null  order by sort limit 0,1 )  where id = ?  and pastureid = ? `,
-			pid, intime, pid, tmrid, pastureid).Execute()
+		_, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort =
+		 (select sort from downloadplandtl2  where pid = ? and intime is  null  order by sort limit 0,1 )  where datacaptureno = ?  and pastureid = ?  `,
+			pid, intime, pid, datacaptureno, pastureid).Execute()
 		if err != nil {
 			logs.Error(err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -390,21 +413,60 @@ func AddRealTimeWeight(c *gin.Context) {
 	pastureid := fsion.Get("pastureid").ValueStr()
 	weightjson := fsion.Get("weightjson").ValueStr()
 
+	// weightjson
+
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	_, err := tx.SQL(`REPLACE INTO recweightmuster (pid, pastureid, weightjson)values (?,?,?)`, pid, pastureid, weightjson).Execute()
+	dataList, err := tx.SQL(` select weightjson from recweightmuster where pid = ? and pastureid = ? `, pid, pastureid).QueryString()
 	if err != nil {
 		logs.Error("AddRealTimeWeight-error1: ", err)
 		appG.Response(http.StatusInternalServerError, e.ERROR, err)
 		return
 	}
 
+	weightList := make([]map[string]interface{}, 0)
+	if len(dataList) > 0 {
+		weight := ""
+		for _, item := range dataList {
+			weight = item["weightjson"]
+		}
+		list := make([]map[string]interface{}, 0)
+		err = json.Unmarshal([]byte(weight), &weightList)
+		if err != nil {
+			logs.Error("AddRealTimeWeight-error2: ", err)
+			appG.Response(http.StatusInternalServerError, e.ERROR, err)
+			return
+		}
+		err = json.Unmarshal([]byte(weightjson), &list)
+		if err != nil {
+			logs.Error("AddRealTimeWeight-error3: ", err)
+			appG.Response(http.StatusInternalServerError, e.ERROR, err)
+			return
+		}
+		weightList = append(weightList, list...)
+	} else {
+		json.Unmarshal([]byte(weightjson), &weightList)
+	}
+
+	weightbyte, err := json.Marshal(weightList)
+	if err != nil {
+		logs.Error("AddRealTimeWeight-error4: ", err)
+		appG.Response(http.StatusInternalServerError, e.ERROR, err)
+		return
+	}
+
+	_, err = tx.SQL(`REPLACE INTO recweightmuster (pid, pastureid, weightjson)values (?,?,?)`, pid, pastureid, string(weightbyte)).Execute()
+	if err != nil {
+		logs.Error("AddRealTimeWeight-error5: ", err)
+		appG.Response(http.StatusInternalServerError, e.ERROR, err)
+		return
+	}
+
 	appG.Response(http.StatusOK, e.SUCCESS, true)
 }
 
 func GetDownloadedplanMaterialList(c *gin.Context) {
-	// var reqInfo ReqGetDownloadedplanMaterial
 
 	appG := app.Gin{C: c}
 	dataByte, _ := ioutil.ReadAll(c.Request.Body)
@@ -430,7 +492,7 @@ func GetDownloadedplanMaterialList(c *gin.Context) {
 
 	downloadedplanInfo := make([]*downloadedplan, 0)
 	err = tx.SQL(` select  d.lpplantype,d.times,d.sort,d.times shifts,d.id,date_format(d.mydate ,'%Y-%m-%d') as mydate ,d.projname,d.datacaptureno,d.lweight,d.havebutton,d.feedpname,d.iscompleted,d.remark,d.tmrtname from downloadedplan d
-	where d.mydate = ? and d.pastureid = ? and (d.datacaptureno is null or d.datacaptureno = ?) and  d.iscompleted = 0  
+	where d.mydate = ? and d.pastureid = ? and (d.datacaptureno is null or d.datacaptureno = ?) 
 	and ( (? IN(1,2) AND d.lpplanType IN (0,1))  OR (? IN (1,3) AND d.lpplanType IN (0,2))) 
 	and if(d.lpplantype = 2,if((select count(1) from downloadplandtl1 d1 
 	where d1.pid = (select id from downloadedplan dd where dd.mydate = d.mydate 

+ 46 - 12
routers/api/sap/sap.go

@@ -9,13 +9,15 @@ import (
 	"net/http"
 	"time"
 
+	"../../../pkg/app"
+	"../../../pkg/e"
 	"../../../pkg/setting"
 	"../../../routers/restful"
 	"github.com/astaxie/beego/logs"
+	"github.com/gin-gonic/gin"
 )
 
 func SyncSapBar(ctx context.Context) {
-	// appG := app.Gin{C: c}
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
@@ -34,18 +36,13 @@ func SyncSapBar(ctx context.Context) {
 		  "TCHSTY": [ ]
 		}
 	}`
-	url := "https://app.modernfarming.cn:7443/sap/Feed/CO005/QueryCowsheds"
+	url := "http://192.168.61.117/SAPP0/Feed/CO005/QueryCowsheds"
 	data = fmt.Sprintf(data, year, year)
-	// url = fmt.Sprintf(url, "CO005")
-	// fmt.Println(url, data)
 	respmap := postPush(url, data)
-
 	if respmap != nil {
-		// fmt.Println(respmap)
 		if _, ok := respmap.(map[string]interface{})["ZTCO_001"]; ok {
 			for _, item := range respmap.(map[string]interface{})["ZTCO_001"].([]interface{}) {
 				barMap := item.(map[string]interface{})
-				fmt.Println(barMap)
 				_, err := tx.SQL(` insert into bar(pastureid,bcode,bname,sort,sapid,class,classid,scopeherd,scopeherdid)
 				values(?,?,?,(select max(sort)+1  from bar b where b.pastureid = ? ),?,( select name from barclass where pastureid = ? and code = ?),( select id from barclass where pastureid = ? and code = ?),(select name from scopeherd where code = ? ),
 				(select id from scopeherd where code = ? ))
@@ -58,7 +55,6 @@ func SyncSapBar(ctx context.Context) {
 			}
 		}
 	}
-	// appG.Response(http.StatusOK, e.SUCCESS, true)
 }
 
 type udPastureInfo struct {
@@ -66,7 +62,8 @@ type udPastureInfo struct {
 	Pastureid string `xorm:"pastureid"`
 }
 
-func MaterialOutbound(ctx context.Context) {
+func MaterialOutbound(c *gin.Context) {
+	appG := app.Gin{C: c}
 
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
@@ -92,6 +89,7 @@ left join barclass bc on bc.id = b.classid
  order by d.id `, "2022-06-24", pastureinfo.Pastureid).Query().List()
 	if err != nil {
 		logs.Error(err)
+		appG.Response(http.StatusInternalServerError, e.ERROR, false)
 		return
 	}
 
@@ -108,13 +106,13 @@ left join barclass bc on bc.id = b.classid
 	  }`
 	databyte, _ := json.Marshal(dataList)
 	data = fmt.Sprintf(data, time.Now().Format("20060102"), "0001", string(databyte))
-	fmt.Println(data)
-	url := "https://app.modernfarming.cn:7443/sap/Feed/MM016/StockOut"
+	url := "http://192.168.61.117/SAPP0/Feed/MM016/StockOut"
 	postPush(url, data)
+
+	appG.Response(http.StatusOK, e.SUCCESS, true)
 }
 
 func postPush(url, data string) interface{} {
-
 	var jsonStr = []byte(data)
 	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
 	if err != nil {
@@ -146,3 +144,39 @@ func postPush(url, data string) interface{} {
 		return nil
 	}
 }
+
+func SyncSapFeed(ctx context.Context) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	data := `{
+		"DEST": {
+			"DEST_ID": "TMRWATCH",
+			"BUSS_TP": "MM002"
+		},
+		"DATA": {
+			"BUDAT_B": "20220819",
+			"BUDAT_E": "20220819",
+			"TMTART": {
+				"MATNR": "XD01"
+				
+			},
+			"TMATKL": []
+		}
+	}`
+
+	url := "http://192.168.61.117/SAPP0/Common/MM002/QueryMaterial/"
+	respmap := postPush(url, data)
+
+	for _, item := range respmap.(map[string]interface{})["TMARA"].([]interface{}) {
+		sapMap := item.(map[string]interface{})
+		fmt.Println(sapMap)
+		_, err := tx.SQL(` replace into  feed_sap(MATNR,MTART,MATKL,MAKTX,MEINS,UMREZ,MEINH,UMREN,ZMINC,ZGUIG,LVORM,LAEDA)values(?,?,?,?,?,?,?,?,?,?,?,?)`,
+			sapMap["MATNR"], sapMap["MTART"], sapMap["MATKL"], sapMap["MAKTX"], sapMap["MEINS"], sapMap["UMREZ"], sapMap["MEINH"],
+			sapMap["UMREN"], sapMap["ZMINC"], sapMap["ZGUIG"], sapMap["LVORM"], sapMap["LAEDA"]).Execute()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+	}
+}

+ 50 - 20
routers/api/scheduled.go

@@ -414,7 +414,6 @@ func UpdatePush(ctx context.Context, tx *xorm.Session, auto bool, idList []strin
 						args = append(args, date)
 					}
 				}
-				fmt.Println(item.Datasql)
 				data, err := tx.SQL(item.Datasql, args...).Query().List()
 				if err != nil {
 					log.Println("UpdataPush-error-2: ", err)
@@ -428,7 +427,8 @@ func UpdatePush(ctx context.Context, tx *xorm.Session, auto bool, idList []strin
 					}
 					var method string
 					if item.Datatype == 4 {
-						method = "uploadnewdiliverdata"
+						continue
+						// method = "uploadnewdiliverdata"
 					}
 					UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)), method)
 				}
@@ -787,10 +787,6 @@ func wxPush(target []string, content []interface{}, pastureId string, serviceId
 	}
 
 	defer resp.Body.Close()
-
-	// body, _ := ioutil.ReadAll(resp.Body)
-	// logs.Info("response Body:", string(body), "fasong")
-
 }
 
 func UDPostPush1(data, method string) {
@@ -799,6 +795,7 @@ func UDPostPush1(data, method string) {
 	var jsonStr = []byte(data)
 	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
 
+	fmt.Println(string(jsonStr))
 	req.Header.Set("Content-Type", "application/json")
 	client := &http.Client{}
 	resp, err := client.Do(req)
@@ -987,30 +984,63 @@ func processAnalysisEarlyWarning(target []string, pastureId string, serviceId in
 
 func manualUdData(pastureinfo *udPastureInfo) {
 	c := cron.New()
-	c.AddFunc("10 02 * * *", func() {
-		// fmt.Println(time.Now())
+	c.AddFunc("10 06 * * *", func() {
 		tx := restful.Engine.NewSession()
 		defer tx.Close()
 		now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
-
-		exist, err := tx.SQL(" select id  from downloadedplan where mydate = ? and enable = 1  and iscompleted = 0 ", now).Exist()
+		dataList, err := tx.SQL(" select id  from downloadedplan where mydate = ? ", now).QueryString()
 		if err != nil {
 			logs.Error("manualUdData-error-1:", err)
 			return
 		}
+		var idList []string
+		for _, data := range dataList {
+			idList = append(idList, data["id"])
+		}
 
-		if exist {
-			dataList, err := tx.SQL(" select id  from downloadedplan where mydate = ? ", now).QueryString()
-			if err != nil {
-				logs.Error("manualUdData-error-2:", err)
-				return
-			}
-			var idList []string
-			for _, data := range dataList {
-				idList = append(idList, data["id"])
+		upList := make([]*ScheduledUpInfo, 0)
+		up := tx.Table("scheduled_up")
 
+		up.Where("company = ? ", "ud")
+		up.Where("datatype = 4")
+		up.Where("automatic = 1")
+		err = up.Find(&upList)
+		if err != nil {
+			log.Println("manualUdData-error-2: ", err)
+			return
+		}
+
+		for _, item := range upList {
+			if item.Datasql != "" {
+				if item.Datatype == 4 {
+					targetdataList := strings.Split(item.Targetdata, ",")
+					var args []interface{}
+					for _, targetdata := range targetdataList {
+						if targetdata == "pastureid" {
+							args = append(args, pastureinfo.Pastureid)
+						} else if targetdata == "idlist" {
+							item.Datasql = strings.ReplaceAll(item.Datasql, "idlist", strings.Join(idList, ","))
+						} else if targetdata == "date" {
+							args = append(args, now)
+						}
+					}
+					data, err := tx.SQL(item.Datasql, args...).Query().List()
+					if err != nil {
+						log.Println("manualUdData-error-3: ", err)
+						continue
+					}
+					if len(data) > 0 {
+						databyte, err := json.Marshal(data)
+						if err != nil {
+							log.Println("manualUdData-error-4: ", err)
+							continue
+						}
+
+						var method string
+						UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)), method)
+					}
+				}
 			}
-			UpdatePush(context.Background(), tx, true, idList, pastureinfo, "", now)
 		}
 	})
 	c.Start()

+ 3 - 25
routers/api/spillage.go

@@ -784,17 +784,6 @@ func GetSpillage(c *gin.Context) {
 	WHERE feedp.pastureid = ?  %s and  (SELECT inforvalue FROM sysopt WHERE sysopt.pastureid=feedp.pastureid AND sysopt.inforname= 'isEnableSupplyFeed') = 1
 	GROUP BY feedp.ptsfid`
 
-		// 	SELECT TRIM(id) id,times,tratio,ROUND(ptsrate*weight,2)-ptsuse weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,
-		// (select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,
-		//  ? AS background,? AS fttype,cowcount,ccountradio, 1 isfill  FROM fpdetaildate fpdetail
-		// WHERE fpdetail.pastureid = ? AND  ( fpdetail.`ptsid`=?) AND times=? AND  ptsuse< ROUND(ptsrate*weight,2) and fpdetail.date = ?
-
-		// UNION
-		// SELECT TRIM(id) id,times,tratio,ROUND((1-ptsrate)*weight,2)-ptuse weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,
-		// (select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,
-		// ? AS background,? AS fttype,cowcount,ccountradio, 0 isfill  FROM fpdetaildate fpdetail
-		// WHERE fpdetail.pastureid = ? AND  (fpdetail.`ptid`=? ) AND times=? AND ptuse<ROUND((1-ptsrate)*weight,2) and fpdetail.date = ?
-		// ORDER BY  barid
 		if ftid != 0 {
 			sqlStr = fmt.Sprintf(sqlStr, fmt.Sprintf(" and ft.id = %d ", ftid), fmt.Sprintf(" and ft.id = %d ", ftid))
 		} else {
@@ -1313,17 +1302,6 @@ func GetSpillageDay(c *gin.Context) {
 	data := make(map[string]interface{})
 
 	if refresh == 0 || refresh == 2 {
-		// 	sqlStr := `SELECT trim(feedp.pastureid) pastureid,barname,trim(barid) barid,trim(ftid) arrid,1 as type,? as times,ft.tname ftname,ft.tcolor  background,0 isfill FROM feedp
-		// 	inner join  feedtemplet ft
-		// on ft.id = feedp.ftid and  ft.pastureid=?
-		// WHERE feedp.pastureid = ?  %s
-		// GROUP BY feedp.ftid
-		// UNION
-		// SELECT trim(feedp.pastureid) pastureid,barname,barid,trim(ptsfid) arrid,0 as type,? as times,ft.tname ptsfname ,ft.tcolor  background,1 isfill  FROM feedp
-		// inner join  feedtemplet ft
-		// on ft.id = feedp.ptsfid and  ft.pastureid=?
-		// WHERE feedp.pastureid = ?  %s and  (SELECT inforvalue FROM sysopt WHERE sysopt.pastureid=feedp.pastureid AND sysopt.inforname= 'isEnableSupplyFeed') = 1
-		// GROUP BY feedp.ptsfid`
 
 		sqlStr := `	SELECT TRIM(feedp.pastureid) pastureid,feedp.barname,TRIM(feedp.barid) barid,TRIM(ft.id) arrid,1 AS type,? AS times,ft.tname ftname,ft.tcolor  background,feedp.date,0 isfill
 FROM feedpdate feedp
@@ -1350,7 +1328,7 @@ GROUP BY fpd.ptsid`
 
 		ftList, err := tx.SQL(sqlStr, times, pastureid, date, times, pastureid, date).Query().List()
 		if err != nil {
-			log.Println("GetSpillage-error-1: ", err)
+			log.Println("GetSpillageDay-error-1: ", err)
 			appG.Response(http.StatusOK, e.ERROR, nil)
 			return
 		}
@@ -1368,7 +1346,7 @@ GROUP BY fpd.ptsid`
 		and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid) is not null
 		ORDER BY  barid`, pastureid, times, date, pastureid, times, date).Query().List()
 		if err != nil {
-			log.Println("GetSpillage-error-2: ", err)
+			log.Println("GetSpillageDay-error-2: ", err)
 			appG.Response(http.StatusOK, e.ERROR, nil)
 			return
 		}
@@ -1466,7 +1444,7 @@ GROUP BY fpd.ptsid`
 		session := tx.SQL(sqlstr, args...)
 		lppList, err := session.Query().List()
 		if err != nil {
-			log.Println("GetSpillage-error-3: ", err)
+			log.Println("GetSpillageDay-error-3: ", err)
 			appG.Response(http.StatusOK, e.ERROR, nil)
 			return
 		}

+ 65 - 2
routers/api/user.go

@@ -1,10 +1,12 @@
 package api
 
 import (
+	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"net/http"
 	"strings"
+	"time"
 
 	"../../pkg/app"
 	"../../pkg/e"
@@ -217,14 +219,21 @@ func AuthImei(c *gin.Context) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	isExist, err := tx.SQL(" select id from driver where  drivername = ? and imei = ? ", reqInfo.Username, reqInfo.Imei).Exist()
+	isExist, err := tx.SQL(" select id from driver where  drivername = ? ", reqInfo.Imei).Exist()
 	if err != nil {
 		logs.Error("AuthImei-error1:", err)
 		appG.Response(http.StatusInternalServerError, e.ERROR, false)
 		return
 	}
 
-	if !isExist {
+	isTmrExist, err := tx.SQL(" select id from tmr where  imei = ? ", reqInfo.Imei).Exist()
+	if err != nil {
+		logs.Error("AuthImei-error1:", err)
+		appG.Response(http.StatusInternalServerError, e.ERROR, false)
+		return
+	}
+
+	if !isExist && !isTmrExist {
 		//appG.Response(http.StatusUnauthorized, e.ERROR_AUTH, nil)
 		appG.Response(http.StatusOK, e.ERROR_AUTH, "未注册!!!")
 		return
@@ -240,3 +249,57 @@ func AuthImei(c *gin.Context) {
 		"token": token,
 	})
 }
+
+func GetWxCode(c *gin.Context) {
+	appG := app.Gin{C: c}
+	code := c.Query("code")
+
+	url := "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=%s"
+	var appid, secret, jsCode, grantType string
+	jsCode = code
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	wxConfigList, err := tx.SQL(" select * from wx_config where system = ? ", "tmrwatch").Query().List()
+	if err != nil {
+		logs.Error("GetWxCode-error1:", err)
+		appG.Response(http.StatusInternalServerError, e.ERROR, false)
+		return
+	}
+
+	for _, wx := range wxConfigList {
+		grantType = wx["grantType"].(string)
+		appid = wx["appid"].(string)
+		secret = wx["secret"].(string)
+	}
+	url = fmt.Sprintf(url, appid, secret, jsCode, grantType)
+
+	client := &http.Client{Timeout: 5 * time.Second}
+	payload := strings.NewReader(``)
+	req, err := http.NewRequest(http.MethodGet, url, payload)
+	if err != nil {
+		appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_TOKEN, err)
+		return
+	}
+	res, err := client.Do(req)
+	if err != nil {
+		appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_TOKEN, err)
+		return
+	}
+	defer res.Body.Close()
+
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		appG.Response(http.StatusInternalServerError, e.ERROR_AUTH_TOKEN, err)
+		return
+	}
+
+	var data interface{}
+	json.Unmarshal(body, &data)
+	dataMap := data.(map[string]interface{})
+	if _, ok := dataMap["code"]; !ok {
+		dataMap["code"] = ""
+	}
+	appG.Response(http.StatusOK, e.SUCCESS, dataMap)
+}

+ 11 - 7
routers/router.go

@@ -1,35 +1,35 @@
 package routers
 
 import (
+	"context"
 	"fmt"
 
 	"../comm"
 	_ "../docs"
 	"../middleware/jwt"
-	"github.com/gin-gonic/gin"
 
-	//	"../middleware/permission"
 	"net/http"
 	"strings"
 
 	"../pkg/setting"
 	"../routers/api"
 
-	// "../routers/api/sap"
+	"../routers/api/sap"
+	"github.com/gin-contrib/gzip"
+	"github.com/gin-gonic/gin"
 	ginSwagger "github.com/swaggo/gin-swagger"
 	"github.com/swaggo/gin-swagger/swaggerFiles"
 )
 
 func InitRouter() *gin.Engine {
 	r := gin.New()
-	// go api.UDSync()
-	// go api.CronScheduled(context.TODO())
-	// go sap.SyncSapBar(context.TODO())
+	go api.CronScheduled(context.TODO())
+	// go sap.SyncSapFeed(context.TODO())
 
 	r.Use(func(c *gin.Context) {
 		fmt.Println(c.Request.URL)
 	})
-
+	r.Use(gzip.Gzip(gzip.DefaultCompression))
 	//	ginpprof.Wrap(r)
 	r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
 		// 你的自定义格式
@@ -70,6 +70,8 @@ func InitRouter() *gin.Engine {
 	eqm.POST("/login", api.Auth)
 	eqm.POST("/login/imei", api.AuthImei)
 
+	r.GET("/getData", api.GetWxCode)
+
 	r.POST("/userwxopenid/binding", api.UserWXOpenIDBinding)
 
 	// r.POST("/SyncSapBar", sap.SyncSapBar)
@@ -216,6 +218,8 @@ func InitRouter() *gin.Engine {
 		apiV1.POST("/formulaissued", api.AddFormulaIssued)
 		//盘点单添加
 		apiV1.POST("/biginventory", api.AddBigInventory)
+		//sap原料上传
+		apiV1.POST("/material/sap/upload", sap.MaterialOutbound)
 
 	}
 

BIN
tmrgo.zip


File diff suppressed because it is too large
+ 0 - 0
update.220802.sql


Some files were not shown because too many files changed in this diff