瀏覽代碼

圣牧剩料更新

baishaojie 1 月之前
父節點
當前提交
764e7156da
共有 44 個文件被更改,包括 928 次插入352 次删除
  1. 二進制
      TMRWatchComm
  2. 二進制
      TMRWatchComm.zip
  3. 11 11
      conf/app.ini
  4. 二進制
      dist-250407.zip
  5. 二進制
      dist/favicon.ico
  6. 9 0
      dist/index.html
  7. 0 0
      dist/static/css/app.169ec13b.css
  8. 0 0
      dist/static/css/chunk-elementUI.c1c3b808.css
  9. 0 0
      dist/static/css/chunk-libs.f403b559.css
  10. 二進制
      dist/static/fonts/element-icons.535877f5.woff
  11. 二進制
      dist/static/fonts/element-icons.732389de.ttf
  12. 二進制
      dist/static/img/404.a57b6f31.png
  13. 二進制
      dist/static/img/404_cloud.0f4bc32b.png
  14. 二進制
      dist/static/img/guiji2.9dc0addf.jpeg
  15. 28 0
      dist/static/img/iconfont.0ddaba12.svg
  16. 二進制
      dist/static/img/logo.afed751a.png
  17. 二進制
      dist/static/img/logo1.0121925c.png
  18. 二進制
      dist/static/img/logo_u3.3c77f543.png
  19. 二進制
      dist/static/img/nlogin-bg1.77301f56.jpg
  20. 二進制
      dist/static/img/row-bg3.b3be7548.png
  21. 二進制
      dist/static/img/topBg.69ecd1e1.png
  22. 0 0
      dist/static/js/app.4b080aed.js
  23. 0 0
      dist/static/js/chunk-4be30289.2369f77e.js
  24. 0 0
      dist/static/js/chunk-52ecc0ac.f4213a5d.js
  25. 0 0
      dist/static/js/chunk-5c4dc4a9.a3c8a5fd.js
  26. 0 0
      dist/static/js/chunk-b702d234.8e626f6f.js
  27. 0 0
      dist/static/js/chunk-elementUI.c961dc79.js
  28. 0 0
      dist/static/js/chunk-libs.1fd1a346.js
  29. 2 2
      http/handle/api/mqtt.go
  30. 414 279
      http/handle/api/ops.go
  31. 25 11
      http/handle/api/report.go
  32. 6 5
      http/handle/api/scheduled.go
  33. 15 6
      http/handle/api/spillage.go
  34. 20 20
      http/handle/jpud/udservice.go
  35. 53 13
      http/handle/sap/sap.go
  36. 220 0
      http/handle/ymy/ymy.go
  37. 2 1
      http/routers/app_api.go
  38. 二進制
      mlxy.zip
  39. 20 0
      models/wasteuse.go
  40. 94 0
      models/ymy.go
  41. 9 4
      update.sql
  42. 二進制
      uploads.zip
  43. 二進制
      uploads/file/导入导出模板/栏舍生产/Dry Matter Formula Import Template.xlsx
  44. 二進制
      uploads/file/导入导出模板/栏舍生产/Dry Matter Formula Import Template11111111111.xlsx

二進制
TMRWatchComm


二進制
TMRWatchComm.zip


+ 11 - 11
conf/app.ini

@@ -21,7 +21,7 @@ TimeFormat = 20060102-150405
 #debug or release
 #RunMode = debuggit 
 RunMode = release
-HttpPort = 8082
+HttpPort = 8081
 ReadTimeout = 60
 WriteTimeout = 60
 NoAuth = 1
@@ -37,7 +37,7 @@ KeyPath = conf/ssl.key
 ServerName = tmrgo
 DisplayName = tmrgo
 Description = tmrgo
-UDForwardingSvc = "http://127.0.0.1"
+UDForwardingSvc = "http://192.168.8.250"
 
 # 对接
 GRFD = 1
@@ -51,8 +51,8 @@ User = root
 #Password = root
 #Password = kepaiteng!QAZ
 #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 = root
 Password = root
 #Password = root
@@ -76,7 +76,7 @@ Password = root
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = tmrwatch2
+Name = nxzwnk
 TablePrefix =
 
 ShowXormlog = false
@@ -93,13 +93,12 @@ Password =
 Name = 
 
 [yyn]
-FarmId = "1830002642"
+#蓝浩
+FarmId = "1830004776"
 ProductKey = "k03txxLKFae"
-DeviceName = "02642_p_breed"
-DeviceSecret = "c5968fc9ebd6bdaa7c27c441cfb9faf9"
-HeartBeat = "Tmr183000264202642_p_breed"
-
-; YynSecret = "1724910379067346d6352"
+DeviceName = "04776_p_breed"
+DeviceSecret = "e1fdb50556b13afe896e738fdcb25bf3"
+HeartBeat = "Tmr183000477604776_p_breed"
 
 
 
@@ -112,3 +111,4 @@ StopBits = 1
 ParityMode = 0    #PARITY_NONE  0	PARITY_ODD  1	PARITY_EVEN  2
 InterCharacterTimeout = 100
 MinimumReadSize = 0
+

二進制
dist-250407.zip


二進制
dist/favicon.ico


文件差異過大導致無法顯示
+ 9 - 0
dist/index.html


文件差異過大導致無法顯示
+ 0 - 0
dist/static/css/app.169ec13b.css


文件差異過大導致無法顯示
+ 0 - 0
dist/static/css/chunk-elementUI.c1c3b808.css


文件差異過大導致無法顯示
+ 0 - 0
dist/static/css/chunk-libs.f403b559.css


二進制
dist/static/fonts/element-icons.535877f5.woff


二進制
dist/static/fonts/element-icons.732389de.ttf


二進制
dist/static/img/404.a57b6f31.png


二進制
dist/static/img/404_cloud.0f4bc32b.png


二進制
dist/static/img/guiji2.9dc0addf.jpeg


文件差異過大導致無法顯示
+ 28 - 0
dist/static/img/iconfont.0ddaba12.svg


二進制
dist/static/img/logo.afed751a.png


二進制
dist/static/img/logo1.0121925c.png


二進制
dist/static/img/logo_u3.3c77f543.png


二進制
dist/static/img/nlogin-bg1.77301f56.jpg


二進制
dist/static/img/row-bg3.b3be7548.png


二進制
dist/static/img/topBg.69ecd1e1.png


文件差異過大導致無法顯示
+ 0 - 0
dist/static/js/app.4b080aed.js


文件差異過大導致無法顯示
+ 0 - 0
dist/static/js/chunk-4be30289.2369f77e.js


文件差異過大導致無法顯示
+ 0 - 0
dist/static/js/chunk-52ecc0ac.f4213a5d.js


文件差異過大導致無法顯示
+ 0 - 0
dist/static/js/chunk-5c4dc4a9.a3c8a5fd.js


文件差異過大導致無法顯示
+ 0 - 0
dist/static/js/chunk-b702d234.8e626f6f.js


文件差異過大導致無法顯示
+ 0 - 0
dist/static/js/chunk-elementUI.c961dc79.js


文件差異過大導致無法顯示
+ 0 - 0
dist/static/js/chunk-libs.1fd1a346.js


+ 2 - 2
http/handle/api/mqtt.go

@@ -35,10 +35,10 @@ var pubTopic string
 func InitMqttClient() {
 	if setting.YynserverSetting.FarmId != "" {
 		c, pubTopic = MqttClient()
-		// deviceHeartbeat(c, pubTopic)
+		deviceHeartbeat(c, pubTopic)
 		// GetFeedDataFromApi()
 		// getBarDataFromApi()
-		// i := 95
+		// i := 50
 		// for {
 		// 	i--
 		// 	if i == 0 {

+ 414 - 279
http/handle/api/ops.go

@@ -18,7 +18,6 @@ import (
 	"sync"
 	"time"
 	"tmr-watch/conf/setting"
-	"tmr-watch/http/handle/gm"
 	"tmr-watch/http/handle/jpud"
 	"tmr-watch/http/handle/restful"
 	"tmr-watch/models"
@@ -1118,6 +1117,11 @@ func GetRJSBData(c *gin.Context) {
 
 	//STR :=Httppostdata("http://192.168.1.104:8081/authdata/GetDataBySqlIN","POST",string(dataByte),tx)
 
+	_, err = tx.SQL(`update tmr set xianfeng = (select id from downloadedplan  where lpplantype = 5 and mydate = date_format(now() ,'%Y-%m-%d')   and havebutton = 1 and  iscompleted = 0 )  
+	where id = (select tmrid   from  downloadedplan  d  where d.pid =  (select pid from downloadedplan where lpplantype = 5 and mydate = 
+	date_format(now() ,'%Y-%m-%d')  and havebutton = 1 and iscompleted= 0 )     and mydate = date_format(now() ,'%Y-%m-%d') 	
+	and lpplantype in(0,1)) `).Execute()
+
 	sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
 	sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr1, tx)
 	if sql != "" {
@@ -1170,6 +1174,7 @@ func GetRJSBData(c *gin.Context) {
 			wg.Wait()
 			appG.Response(http.StatusOK, e.SUCCESS, queryData)
 		}
+		fmt.Println("先锋获取数据:", time.Now(), queryData)
 	} else {
 		appG.Response(http.StatusOK, e.SUCCESS, nil)
 	}
@@ -1329,7 +1334,7 @@ func PostRJSBDatas(c *gin.Context) {
 	dataByte, _ := ioutil.ReadAll(c.Request.Body)
 	fsions := gofasion.NewFasion(string(dataByte)).Array()
 	logging.Info("PostRJSBDatas  err: ", string(dataByte))
-	fmt.Println(string(dataByte))
+	fmt.Println("先锋回传数据:", time.Now(), string(dataByte))
 
 	tx := restful.Engine.NewSession()
 	err := tx.Begin()
@@ -1372,23 +1377,7 @@ func PostRJSBDatas(c *gin.Context) {
 			}
 		}
 
-		// 		ALTER TABLE `tmr`
-		// ADD COLUMN `concentrate` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0 未回传 1 已回传' AFTER `appoint`
-		projuctid := parammaps.Get("projuctid").ValueStr()
-		_, err = tx.SQL(`update tmr set concentrate = (select d.id   from  downloadedplan  d  
-			where d.pid = (select pid from downloadedplan where id = ?)  and mydate =(select mydate from downloadedplan where id = ?) 
-			and lpplantype in(0,1))  where id = (select tmrid   from  downloadedplan  d  
-			where d.pid = (select pid from downloadedplan where id = ?)  and mydate =(select mydate from downloadedplan where id = ?) 
-			and lpplantype in(0,1)) `, projuctid, projuctid, projuctid, projuctid).Execute()
-		if err != nil {
-			logging.Error("PostRJSBData-0  err: ", err)
-			msg := geterrmsg(err.Error())
-			// appG.Response(http.StatusOK, e.ERROR, msg)
-			appG.Response(http.StatusOK, e.SUCCESS, msg)
-			return
-		}
-
-		_, err = tx.SQL(sql, s_params...).Execute()
+		_, err := tx.SQL(sql, s_params...).Execute()
 		if err != nil {
 			logging.Error("PostRJSBData  err: ", err)
 			msg := geterrmsg(err.Error())
@@ -1480,6 +1469,28 @@ func PostRJSBDatas(c *gin.Context) {
 			appG.Response(http.StatusOK, e.ERROR, msg)
 			return
 		}
+
+		// 		ALTER TABLE `tmr`
+		// ADD COLUMN `concentrate` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0 未回传 1 已回传' AFTER `appoint`
+		projuctid := parammaps.Get("projuctid").ValueStr()
+		_, err = tx.SQL(`update tmr set xianfeng = 0, concentrate = (select d.id   from  downloadedplan  d  
+			where d.pid = (select pid from downloadedplan where id = ?)  and mydate =(select mydate from downloadedplan where id = ?) 
+			and lpplantype in(0,1))  where id = (select tmrid   from  downloadedplan  d  
+			where d.pid = (select pid from downloadedplan where id = ?)  and mydate =(select mydate from downloadedplan where id = ?) 
+			and lpplantype in(0,1)) and ( select count(1) from downloadedplan  where id = ?  and iscompleted = 0 ) = 0 `,
+			projuctid, projuctid, projuctid, projuctid, projuctid).Execute()
+		if err != nil {
+			logging.Error("PostRJSBData-0  err: ", err)
+			msg := geterrmsg(err.Error())
+			// appG.Response(http.StatusOK, e.ERROR, msg)
+			appG.Response(http.StatusOK, e.SUCCESS, msg)
+			return
+		}
+		count, _ := tx.SQL(`select count(1) from downloadedplan  where id = ?  and iscompleted = 0`, projuctid).Count()
+		if count == 0 {
+			fmt.Println(projuctid, "先锋回传计划已完成", count, err)
+		}
+
 	}
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
@@ -3063,8 +3074,8 @@ func UpdateFTdetail(c *gin.Context) {
 	tempCommon := make(map[string]interface{})
 	tempval := make([]map[string]interface{}, 0)
 	fTChange := make(map[string]interface{}, 0)
-	fpdOldDataList := make([]map[string]interface{}, 0)
-	fpdDataList := make([]map[string]interface{}, 0)
+	// fpdOldDataList := make([]map[string]interface{}, 0)
+	// fpdDataList := make([]map[string]interface{}, 0)
 
 	fsion := gofasion.NewFasion(string(dataByte))
 	// parammaps := fsion.Get("parammaps")
@@ -3133,14 +3144,14 @@ func UpdateFTdetail(c *gin.Context) {
 			tempCommon = v
 		}
 
-		fpdOldDataList, err = tx.SQL(`select * from (SELECT TRIM(id) id,times,tratio,ifnull(ROUND(ptsrate*weight,2)-ptsuse,0) 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,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
-		WHERE fpdetail.pastureid = ?   and (ptid = ? or ptsid = ?)
-		UNION
-		SELECT TRIM(id) id,times,tratio,ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,0) 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,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
-		WHERE fpdetail.pastureid = ?   and (ptid = ? or ptsid = ?)) t
-		order by t.barname,t.times`, parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"], parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"]).Query().List()
+		// fpdOldDataList, err = tx.SQL(`select * from (SELECT TRIM(id) id,times,tratio,ifnull(ROUND(ptsrate*weight,2)-ptsuse,0) 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,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
+		// WHERE fpdetail.pastureid = ?   and (ptid = ? or ptsid = ?)
+		// UNION
+		// SELECT TRIM(id) id,times,tratio,ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,0) 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,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
+		// WHERE fpdetail.pastureid = ?   and (ptid = ? or ptsid = ?)) t
+		// order by t.barname,t.times`, parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"], parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"]).Query().List()
 
 		if err == nil {
 			if tempv, exists := c.Get("jwt_username"); exists {
@@ -3214,38 +3225,52 @@ func UpdateFTdetail(c *gin.Context) {
 				WHERE fp.pastureid = ? AND fp.ptsfid =?`, parammaps["pastureid"], parammaps["ftid"]).Execute()
 		}
 
-		fpdDataList, err = tx.SQL(`select * from (SELECT TRIM(id) id,times,tratio,ifnull(ROUND(ptsrate*weight,2)-ptsuse,0) weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(ptsid ) ptsid ,
-		(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
-		WHERE fpdetail.pastureid = ?    and (ptid = ? or ptsid = ?)
-		UNION
-		SELECT TRIM(id) id,times,tratio,ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,0) weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(ptsid ) ptsid ,
-		(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
-		WHERE fpdetail.pastureid = ?  and (ptid = ? or ptsid = ?)) t
-		order by t.barname,t.times`, parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"], parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"]).Query().List()
-
-		lpplanList := make([]*lpplanStruct, 0)
-		err = tx.SQL(`select id,times,maxweight  from lpplan where pastureid = ? and ftid = ? order by  sort desc`, parammaps["pastureid"], parammaps["ftid"]).Find(&lpplanList)
-		if err != nil {
-			logs.Error(err, 1)
-			return
-		}
+		values1, _ := tx.SQL(`select b.bname barname,	ifnull(ccount,0) ccount,ifnull(ratio,0) ratio,ftname,ptsfname,
+		ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 1 ),0) as '1' ,
+		ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 2
+			),0) as '2' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 3
+			),0) as '3' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 4
+			),0) as '4' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 5
+			),0) as '5' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 6
+			),0) as '6'   from feedp fp join bar b on b.id = fp.barid
+			join feedtemplet  ft on ft.id = fp.ftid  where ft.id = ?`, parammaps["ftid"]).QueryString()
+		// fmt.Println(ftId)
+		FpdBatchEditGrfd(fmt.Sprintf("%v", parammaps["pastureid"]), values1)
+
+		// 		fpdDataList, err = tx.SQL(`select * from (SELECT TRIM(id) id,times,tratio,ifnull(ROUND(ptsrate*weight,2)-ptsuse,0) weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(ptsid ) ptsid ,
+		// 		(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
+		// 		WHERE fpdetail.pastureid = ?    and (ptid = ? or ptsid = ?)
+		// 		UNION
+		// 		SELECT TRIM(id) id,times,tratio,ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,0) weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(ptsid ) ptsid ,
+		// 		(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
+		// 		WHERE fpdetail.pastureid = ?  and (ptid = ? or ptsid = ?)) t
+		// 		order by t.barname,t.times`, parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"], parammaps["pastureid"], parammaps["ftid"], parammaps["ftid"]).Query().List()
+
+		// 		lpplanList := make([]*lpplanStruct, 0)
+		// 		err = tx.SQL(`select id,times,if((SELECT inforvalue FROM sysopt WHERE inforname = 'tmrOrVolume' AND pastureid =lpplan.pastureid ) = 0 ,
+		// ifnull((select maxstirfeed from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),100000),(select ifnull(volume,0)  from tmr where id  = lpplan.tmrid ) *
+		// (select ifnull(volume,0) from feedtemplet where id = lpplan.ftid)   ) maxweight  from lpplan where pastureid = ? and ftid = ? order by  sort desc`, parammaps["pastureid"], parammaps["ftid"]).Find(&lpplanList)
+		// 		if err != nil {
+		// 			logs.Error(err, 1)
+		// 			return
+		// 		}
 
-		lppidlist := []string{}
-		for _, lpp := range lpplanList {
-			lppidlist = append(lppidlist, strconv.FormatInt(lpp.Id, 10))
-		}
-		if len(lppidlist) <= 0 {
-			appG.Response(http.StatusOK, e.SUCCESS, true)
-			return
-		}
-		lpplandtl1AllList := make([]*lpplandtl1, 0)
-		err = tx.SQL(fmt.Sprintf(`select id,lppid,barid,fpdid,lweight from lpplandtl1 where pastureid = ? and lppid in (%s) 
-						 order by sort desc`, strings.Join(lppidlist, ",")), parammaps["pastureid"]).Find(&lpplandtl1AllList)
-		if err != nil {
-			// tx.Rollback()
-			logs.Error(err, 2, parammaps["pastureid"])
-			return
-		}
+		// 		lppidlist := []string{}
+		// 		for _, lpp := range lpplanList {
+		// 			lppidlist = append(lppidlist, strconv.FormatInt(lpp.Id, 10))
+		// 		}
+		// 		if len(lppidlist) <= 0 {
+		// 			appG.Response(http.StatusOK, e.SUCCESS, true)
+		// 			return
+		// 		}
+		// 		lpplandtl1AllList := make([]*lpplandtl1, 0)
+		// 		err = tx.SQL(fmt.Sprintf(`select id,lppid,barid,fpdid,lweight from lpplandtl1 where pastureid = ? and lppid in (%s)
+		// 						 order by sort desc`, strings.Join(lppidlist, ",")), parammaps["pastureid"]).Find(&lpplandtl1AllList)
+		// 		if err != nil {
+		// 			// tx.Rollback()
+		// 			logs.Error(err, 2, parammaps["pastureid"])
+		// 			return
+		// 		}
 
 		// 		for _, lpp := range lpplandtl1AllList {
 		// 	_, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  )
@@ -3263,143 +3288,143 @@ func UpdateFTdetail(c *gin.Context) {
 		// 		return
 		// 	}
 		// }
-		var wg sync.WaitGroup
-		for _, old := range fpdOldDataList {
-			for _, fpd := range fpdDataList {
-				wg.Add(1)
-				go func(old, fpd map[string]interface{}) {
-					updateLppandList := make([]*lpplandtl1, 0)
-					defer wg.Done()
-					if fpd["id"].(string) == old["id"].(string) && fpd["fttype"].(int64) == old["fttype"].(int64) &&
-						fpd["weight"].(string) != old["weight"].(string) && fpd["times"].(int64) == old["times"].(int64) {
-
-						weight, _ := strconv.ParseFloat(fpd["weight"].(string), 64)
-						oldweight, _ := strconv.ParseFloat(old["weight"].(string), 64)
-						// if weight > oldweight {
-						// 	return
-						// }
-
-						var w float64
-						var status int
-
-						if weight < oldweight {
-							if weight >= 0 {
-								return
-							}
-							w = weight
-							status = 0
-						} else {
-							if oldweight > 0 {
-								return
-							}
-							w = weight
-							status = 1
-						}
-						// fweight = w
-						for _, lpp := range lpplanList {
-							var fweight float64
-							var lweight float64
-							lpplandtl1List := make([]*lpplandtl1, 0)
-							fpdid, _ := strconv.ParseInt(fpd["id"].(string), 10, 64)
-							for _, lppland := range lpplandtl1AllList {
-								if lppland.Lppid == lpp.Id && lppland.Fpdid == fpdid {
-									lpplandtl1List = append(lpplandtl1List, lppland)
-								}
-							}
-							if len(lpplandtl1List) == 0 {
-								continue
-							}
-							for _, lppland := range lpplandtl1List {
-								lweight += lppland.Lweight
-							}
-
-							if status == 0 {
-								if lweight <= 0 {
-									continue
-								}
-							} else {
-								if lpp.Maxweight <= lweight {
-									continue
-								}
-							}
-
-							for _, lppland := range lpplandtl1List {
-
-								if fpdid == lppland.Fpdid {
-
-									if status == 1 {
-										// if w <= lppland.Lweight {
-										if lpp.Maxweight <= lweight {
-											continue
-										}
-										if w+lweight <= lpp.Maxweight {
-											lppland.Lweight += w
-											lweight += w
-											fweight += w
-											w = 0
-										} else {
-											w = w - (lpp.Maxweight - lweight)
-											n := (lpp.Maxweight - lweight)
-											lppland.Lweight = lppland.Lweight + n
-											lweight += n
-											fweight += n
-
-										}
-									} else {
-										if lppland.Lweight == 0 {
-											continue
-										}
-										if w+lppland.Lweight >= 0 {
-											lppland.Lweight = lppland.Lweight + w
-											lweight = lweight + w
-											fweight = fweight + w
-											w = 0
-										} else {
-											w = w + lppland.Lweight
-											lweight = lweight - lppland.Lweight
-											fweight = fweight - lppland.Lweight
-											lppland.Lweight = 0
-										}
-
-									}
-									updateLppandList = append(updateLppandList, lppland)
-									break
-								}
-							}
-
-							_, err = tx.SQL(`UPDATE fpdetail SET ptuse=IF(?=1,IF(ptuse+? <0,0,ptuse+?),ptuse),
-						ptsuse=IF(?=0,IF(ptsuse+?<0,0,ptsuse+?),ptsuse)
-						WHERE pastureid=? AND id=?`, parammaps["type"], fweight, fweight, parammaps["type"], fweight, fweight, parammaps["pastureid"], fpd["id"]).Execute()
-							if err != nil {
-								// tx.Rollback()
-								logs.Error(err, 4, parammaps["type"], fweight, fweight, parammaps["type"], fweight, fweight, parammaps["pastureid"], fpd["id"])
-								return
-							}
-
-							for _, lppland := range updateLppandList {
-
-								fmt.Println(lppland.Lweight, lppland.Id, parammaps["pastureid"], status)
-								_, err = tx.SQL(`update lpplandtl1  set Lweight = ?  where id = ? and pastureid = ?`, lppland.Lweight, lppland.Id, parammaps["pastureid"]).Execute()
-								if err != nil {
-									fmt.Println(lppland.Lweight, lppland.Id, parammaps["pastureid"], status)
-									// tx.Rollback()
-									logs.Error(err, 3)
-									return
-								}
-								// defer wg.Done()
-							}
-							updateLppandList = []*lpplandtl1{}
-							if w == 0 {
-								break
-							}
-						}
-
-					}
-				}(old, fpd)
-			}
+		// var wg sync.WaitGroup
+		// for _, old := range fpdOldDataList {
+		// 	for _, fpd := range fpdDataList {
+		// 		wg.Add(1)
+		// 		go func(old, fpd map[string]interface{}) {
+		// 			updateLppandList := make([]*lpplandtl1, 0)
+		// 			defer wg.Done()
+		// 			if fpd["id"].(string) == old["id"].(string) && fpd["fttype"].(int64) == old["fttype"].(int64) &&
+		// 				fpd["weight"].(string) != old["weight"].(string) && fpd["times"].(int64) == old["times"].(int64) {
+
+		// 				weight, _ := strconv.ParseFloat(fpd["weight"].(string), 64)
+		// 				oldweight, _ := strconv.ParseFloat(old["weight"].(string), 64)
+		// 				// if weight > oldweight {
+		// 				// 	return
+		// 				// }
+
+		// 				var w float64
+		// 				var status int
+
+		// 				if weight < oldweight {
+		// 					if weight >= 0 {
+		// 						return
+		// 					}
+		// 					w = weight
+		// 					status = 0
+		// 				} else {
+		// 					if oldweight > 0 {
+		// 						return
+		// 					}
+		// 					w = weight
+		// 					status = 1
+		// 				}
+		// 				// fweight = w
+		// 				for _, lpp := range lpplanList {
+		// 					var fweight float64
+		// 					var lweight float64
+		// 					lpplandtl1List := make([]*lpplandtl1, 0)
+		// 					fpdid, _ := strconv.ParseInt(fpd["id"].(string), 10, 64)
+		// 					for _, lppland := range lpplandtl1AllList {
+		// 						if lppland.Lppid == lpp.Id && lppland.Fpdid == fpdid {
+		// 							lpplandtl1List = append(lpplandtl1List, lppland)
+		// 						}
+		// 					}
+		// 					if len(lpplandtl1List) == 0 {
+		// 						continue
+		// 					}
+		// 					for _, lppland := range lpplandtl1List {
+		// 						lweight += lppland.Lweight
+		// 					}
+
+		// 					if status == 0 {
+		// 						if lweight <= 0 {
+		// 							continue
+		// 						}
+		// 					} else {
+		// 						if lpp.Maxweight <= lweight {
+		// 							continue
+		// 						}
+		// 					}
+
+		// 					for _, lppland := range lpplandtl1List {
+
+		// 						if fpdid == lppland.Fpdid {
+
+		// 							if status == 1 {
+		// 								// if w <= lppland.Lweight {
+		// 								if lpp.Maxweight <= lweight {
+		// 									continue
+		// 								}
+		// 								if w+lweight <= lpp.Maxweight {
+		// 									lppland.Lweight += w
+		// 									lweight += w
+		// 									fweight += w
+		// 									w = 0
+		// 								} else {
+		// 									w = w - (lpp.Maxweight - lweight)
+		// 									n := (lpp.Maxweight - lweight)
+		// 									lppland.Lweight = lppland.Lweight + n
+		// 									lweight += n
+		// 									fweight += n
+
+		// 								}
+		// 							} else {
+		// 								if lppland.Lweight == 0 {
+		// 									continue
+		// 								}
+		// 								if w+lppland.Lweight >= 0 {
+		// 									lppland.Lweight = lppland.Lweight + w
+		// 									lweight = lweight + w
+		// 									fweight = fweight + w
+		// 									w = 0
+		// 								} else {
+		// 									w = w + lppland.Lweight
+		// 									lweight = lweight - lppland.Lweight
+		// 									fweight = fweight - lppland.Lweight
+		// 									lppland.Lweight = 0
+		// 								}
+
+		// 							}
+		// 							updateLppandList = append(updateLppandList, lppland)
+		// 							break
+		// 						}
+		// 					}
+
+		// 					_, err = tx.SQL(`UPDATE fpdetail SET ptuse=IF(?=1,IF(ptuse+? <0,0,ptuse+?),ptuse),
+		// 				ptsuse=IF(?=0,IF(ptsuse+?<0,0,ptsuse+?),ptsuse)
+		// 				WHERE pastureid=? AND id=?`, parammaps["type"], fweight, fweight, parammaps["type"], fweight, fweight, parammaps["pastureid"], fpd["id"]).Execute()
+		// 					if err != nil {
+		// 						// tx.Rollback()
+		// 						logs.Error(err, 4, parammaps["type"], fweight, fweight, parammaps["type"], fweight, fweight, parammaps["pastureid"], fpd["id"])
+		// 						return
+		// 					}
+
+		// 					for _, lppland := range updateLppandList {
+
+		// 						fmt.Println(lppland.Lweight, lppland.Id, parammaps["pastureid"], status)
+		// 						_, err = tx.SQL(`update lpplandtl1  set Lweight = ?  where id = ? and pastureid = ?`, lppland.Lweight, lppland.Id, parammaps["pastureid"]).Execute()
+		// 						if err != nil {
+		// 							fmt.Println(lppland.Lweight, lppland.Id, parammaps["pastureid"], status)
+		// 							// tx.Rollback()
+		// 							logs.Error(err, 3)
+		// 							return
+		// 						}
+		// 						// defer wg.Done()
+		// 					}
+		// 					updateLppandList = []*lpplandtl1{}
+		// 					if w == 0 {
+		// 						break
+		// 					}
+		// 				}
+
+		// 			}
+		// 		}(old, fpd)
+		// 	}
 
-		}
-		wg.Wait()
+		// }
+		// wg.Wait()
 	}
 	newFpdDataList, err := tx.SQL(` select *  from fpdetail where ptid = ? or  ptsid = ? `, parammaps["ftid"], parammaps["ftid"]).Query().List()
 	if err != nil {
@@ -3616,26 +3641,26 @@ func UpdateFpdetailBar(c *gin.Context) {
 		ftmap["ptsid"] = list.Get("ptsid").ValueStr()
 		// fmt.Println(ftmap)
 
-		count, err := tx.SQL(` select count(1) from lpplandtl1 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ? and times = ?  )
-		and find_in_set(barid,(select barid from feedp where id = ?  ))  and lweight > 0 `, pastureid, pastureid, ftmap["times"], id).Count()
-		if count == 1 {
-			_, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  and times = ? )
-			and find_in_set(barid,(select barid from feedp where id = ? )) `, pastureid, pastureid, ftmap["times"], id).Execute()
-			if err != nil {
-				tx.Rollback()
-				logs.Error(err)
-				appG.Response(http.StatusInternalServerError, e.ERROR, err)
-				return
-			}
-			_, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
-			WHERE pastureid=?  and find_in_set(barid,(select barid from feedp where id = ? )  )   and times = ?    `, pastureid, id, ftmap["times"]).Execute()
-			if err != nil {
-				tx.Rollback()
-				logs.Error(err)
-				appG.Response(http.StatusInternalServerError, e.ERROR, err)
-				return
-			}
-		}
+		// count, err := tx.SQL(` select count(1) from lpplandtl1 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ? and times = ?  )
+		// and find_in_set(barid,(select barid from feedp where id = ?  ))  and lweight > 0 `, pastureid, pastureid, ftmap["times"], id).Count()
+		// if count == 1 {
+		// 	_, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  and times = ? )
+		// 	and find_in_set(barid,(select barid from feedp where id = ? )) `, pastureid, pastureid, ftmap["times"], id).Execute()
+		// 	if err != nil {
+		// 		tx.Rollback()
+		// 		logs.Error(err)
+		// 		appG.Response(http.StatusInternalServerError, e.ERROR, err)
+		// 		return
+		// 	}
+		// 	_, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
+		// 	WHERE pastureid=?  and find_in_set(barid,(select barid from feedp where id = ? )  )   and times = ?    `, pastureid, id, ftmap["times"]).Execute()
+		// 	if err != nil {
+		// 		tx.Rollback()
+		// 		logs.Error(err)
+		// 		appG.Response(http.StatusInternalServerError, e.ERROR, err)
+		// 		return
+		// 	}
+		// }
 
 		fpdDataList, err := tx.SQL(`
 			SELECT TRIM(id) id,times,tratio,ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,"") weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(ifnull(ptsid,-1) ) ptsid ,
@@ -3657,7 +3682,9 @@ func UpdateFpdetailBar(c *gin.Context) {
 				var fweight float64
 				var lweight float64
 				lpplandtl1List := make([]*lpplandtlInfo, 0)
-				err = tx.SQL(`select lppland.*,t.maxstirfeed maxweight from lpplan lpp
+				err = tx.SQL(`select lppland.*,if((SELECT inforvalue FROM sysopt WHERE inforname = 'tmrOrVolume' AND pastureid =lpp.pastureid ) = 0 ,
+				 t.maxstirfeed,(select ifnull(volume,0)  from tmr where id  = lpp.tmrid ) * 	 
+(select ifnull(volume,0) from feedtemplet where id = lpp.ftid)  )  maxweight from lpplan lpp
 					join lpplandtl1 lppland on lpp.id = lppland.lppid
 					join tmr  t on t.id = lpp.tmrid
 					where lppland.fpdid =?
@@ -4412,9 +4439,8 @@ func FpdImportExcel(c *gin.Context) {
 						}
 					}
 				}
-
+				fmt.Println(outentry["栏舍名称"])
 				if !errExist {
-
 					dataexcel := make(map[string]interface{}, 0)
 					if _, ok := outentry["栏舍名称"]; ok {
 						dataexcel["barname"] = outentry["栏舍名称"]
@@ -4433,25 +4459,56 @@ func FpdImportExcel(c *gin.Context) {
 					}
 					if _, ok := outentry["第一班比例(%)"]; ok {
 						dataexcel["1"] = outentry["第一班比例(%)"]
+						if fmt.Sprintf("%v", dataexcel["1"]) == "" {
+							dataexcel["1"] = 0
+						}
+					} else {
+						dataexcel["1"] = 0
 					}
+
 					if _, ok := outentry["第二班比例(%)"]; ok {
 						dataexcel["2"] = outentry["第二班比例(%)"]
+						if fmt.Sprintf("%v", dataexcel["2"]) == "" {
+							dataexcel["2"] = 0
+						}
+					} else {
+						dataexcel["2"] = 0
 					}
 
 					if _, ok := outentry["第三班比例(%)"]; ok {
 						dataexcel["3"] = outentry["第三班比例(%)"]
+						if fmt.Sprintf("%v", dataexcel["3"]) == "" {
+							dataexcel["3"] = 0
+						}
+					} else {
+						dataexcel["3"] = 0
 					}
 
 					if _, ok := outentry["第四班比例(%)"]; ok {
 						dataexcel["4"] = outentry["第四班比例(%)"]
+						if fmt.Sprintf("%v", dataexcel["4"]) == "" {
+							dataexcel["4"] = 0
+						}
+					} else {
+						dataexcel["4"] = 0
 					}
 
 					if _, ok := outentry["第五班比例(%)"]; ok {
 						dataexcel["5"] = outentry["第五班比例(%)"]
+						if fmt.Sprintf("%v", dataexcel["5"]) == "" {
+							dataexcel["5"] = 0
+						}
+					} else {
+						dataexcel["5"] = 0
 					}
 
 					if _, ok := outentry["第六班比例(%)"]; ok {
 						dataexcel["6"] = outentry["第六班比例(%)"]
+						if fmt.Sprintf("%v", dataexcel["6"]) == "" {
+							dataexcel["6"] = 0
+						}
+					} else {
+						dataexcel["6"] = 0
 					}
 
 					dataWeight := new(models.FpdetailEdit)
@@ -4459,7 +4516,6 @@ func FpdImportExcel(c *gin.Context) {
 					if _, ok := outentry["第一班重量"]; ok {
 						// dataWeightMap["weight1"] = outentry["第一班重量"]
 						dataWeight.Weight1, _ = strconv.ParseFloat(fmt.Sprintf("%v", outentry["第一班重量"]), 64)
-
 					}
 					if _, ok := outentry["第二班重量"]; ok {
 						// dataWeightMap["weight2"] = outentry["第二班重量"]
@@ -4490,6 +4546,14 @@ func FpdImportExcel(c *gin.Context) {
 					// dataWeightByte, _ := json.Marshal(dataWeightMap)
 					// err = json1.Unmarshal(dataWeightByte, &dataWeight)
 					// fmt.Println(err)
+					if fmt.Sprintf("%v", dataexcel["ccount"]) == "0" {
+						dataWeight.Weight1 = 0
+						dataWeight.Weight2 = 0
+						dataWeight.Weight3 = 0
+						dataWeight.Weight4 = 0
+						dataWeight.Weight5 = 0
+						dataWeight.Weight6 = 0
+					}
 					weight := dataWeight.Weight1 + dataWeight.Weight2 + dataWeight.Weight3 + dataWeight.Weight4 + dataWeight.Weight5 + dataWeight.Weight6
 					if weight > 0 {
 						existbar, err := tx.SQL(` select id from  bar where bname = ?  and pastureid = ?  `, dataexcel["barname"], pastureid).Exist()
@@ -5092,26 +5156,26 @@ func FpdImportExcel(c *gin.Context) {
 		}
 
 		for barname, v := range dataList {
-			for _, v1 := range v {
-				count, err := tx.SQL(` select count(1) from lpplandtl1 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ? and times = ?  ) 
-			and find_in_set(barid,(select barid from feedp where barname = ? ))  and lweight > 0 `, pastureid, pastureid, v1.Times, barname).Count()
-				if count == 1 {
-					_, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  and times = ?    ) 
-	 and find_in_set(barid,(select barid from feedp where barname = ? )) `, pastureid, pastureid, v1.Times, barname).Execute()
-					if err != nil {
-						logs.Error(err)
-						appG.Response(http.StatusInternalServerError, e.ERROR, err)
-						return
-					}
-					_, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
-	 WHERE pastureid=?  and find_in_set(barid,(select barid from feedp where barname = ? )  )  and times= ?  `, pastureid, barname, v1.Times).Execute()
-					if err != nil {
-						logs.Error(err)
-						appG.Response(http.StatusInternalServerError, e.ERROR, err)
-						return
-					}
-				}
-			}
+			// 		for _, v1 := range v {
+			// 			count, err := tx.SQL(` select count(1) from lpplandtl1 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ? and times = ?  )
+			// 		and find_in_set(barid,(select barid from feedp where barname = ? ))  and lweight > 0 `, pastureid, pastureid, v1.Times, barname).Count()
+			// 			if count == 1 {
+			// 				_, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  and times = ?    )
+			//  and find_in_set(barid,(select barid from feedp where barname = ? )) `, pastureid, pastureid, v1.Times, barname).Execute()
+			// 				if err != nil {
+			// 					logs.Error(err)
+			// 					appG.Response(http.StatusInternalServerError, e.ERROR, err)
+			// 					return
+			// 				}
+			// 				_, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
+			//  WHERE pastureid=?  and find_in_set(barid,(select barid from feedp where barname = ? )  )  and times= ?  `, pastureid, barname, v1.Times).Execute()
+			// 				if err != nil {
+			// 					logs.Error(err)
+			// 					appG.Response(http.StatusInternalServerError, e.ERROR, err)
+			// 					return
+			// 				}
+			// 			}
+			// 		}
 			updateFpdetailByBar(pastureid, barname, v)
 		}
 	} else {
@@ -5319,8 +5383,8 @@ func FpdImportExcel(c *gin.Context) {
 						dataexcel["4"] = outentry["Fourth Shift Ratio(%)"]
 					}
 
-					if _, ok := outentry["Fifth shift Ratio(%)"]; ok {
-						dataexcel["5"] = outentry["Fifth shift Ratio(%)"]
+					if _, ok := outentry["Fifth Shift Ratio(%)"]; ok {
+						dataexcel["5"] = outentry["Fifth Shift Ratio(%)"]
 					}
 
 					if _, ok := outentry["Sixth shift Ratio(%)"]; ok {
@@ -5771,7 +5835,8 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 				var fweight float64
 				var lweight float64
 				lpplandtl1List := make([]*lpplandtlInfo, 0)
-				err = tx.SQL(`select lppland.*,t.maxstirfeed  maxweight from lpplan lpp
+				err = tx.SQL(`select lppland.*,if((SELECT inforvalue FROM sysopt WHERE inforname = 'tmrOrVolume' AND pastureid =lpp.pastureid ) = 0 ,
+ t.maxstirfeed,t.volume * (select ifnull(volume,0) from feedtemplet where id = lpp.ftid)   )  maxweight from lpplan lpp
 					join lpplandtl1 lppland on lpp.id = lppland.lppid  
 					join tmr t on t.id = lpp.tmrid
 					where lppland.fpdid =?
@@ -8925,20 +8990,20 @@ func FpdBatchEdit(c *gin.Context) {
 			continue
 		}
 
-		_, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  )
-		and find_in_set(barid,(select barid from feedp where barname = ? )) `, pastureid, pastureid, dataexcel["barname"]).Execute()
-		if err != nil {
-			logs.Error(err)
-			appG.Response(http.StatusInternalServerError, e.ERROR, err)
-			return
-		}
-		_, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
-		WHERE pastureid=?  and find_in_set(barid,(select barid from feedp where barname = ? )  )   `, pastureid, dataexcel["barname"]).Execute()
-		if err != nil {
-			logs.Error(err)
-			appG.Response(http.StatusInternalServerError, e.ERROR, err)
-			return
-		}
+		// _, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  )
+		// and find_in_set(barid,(select barid from feedp where barname = ? )) `, pastureid, pastureid, dataexcel["barname"]).Execute()
+		// if err != nil {
+		// 	logs.Error(err)
+		// 	appG.Response(http.StatusInternalServerError, e.ERROR, err)
+		// 	return
+		// }
+		// _, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
+		// WHERE pastureid=?  and find_in_set(barid,(select barid from feedp where barname = ? )  )   `, pastureid, dataexcel["barname"]).Execute()
+		// if err != nil {
+		// 	logs.Error(err)
+		// 	appG.Response(http.StatusInternalServerError, e.ERROR, err)
+		// 	return
+		// }
 
 		dataexcel["1"] = barFsions.Get("times1").ValueStr()
 		dataexcel["2"] = barFsions.Get("times2").ValueStr()
@@ -9249,7 +9314,7 @@ func UdFeedSync(c *gin.Context) {
 	}
 
 	// gm.UdFeedSync(pastureid, pastureinfo.Werks)
-	// jpud.UdBarSync(pastureid, pastureinfo.Werks)
+	jpud.UdBarSync(pastureid, pastureinfo.Werks)
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
 
@@ -9270,8 +9335,8 @@ func UdFeedtempletPush(c *gin.Context) {
 		return
 	}
 
-	gm.UdFeedtempletPush(pastureid, pastureinfo.Werks, date)
-
+	// gm.UdFeedtempletPush(pastureid, pastureinfo.Werks, date)
+	jpud.UdFeedtempletPush(pastureid, pastureinfo.Werks, date)
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
 
@@ -9292,8 +9357,8 @@ func UdUtirPush(c *gin.Context) {
 		return
 	}
 
-	gm.UdUtirPush(pastureid, pastureinfo.Werks, date)
-
+	// gm.UdUtirPush(pastureid, pastureinfo.Werks, date)
+	jpud.UdUtirPush(pastureid, pastureinfo.Werks, date)
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
 
@@ -9314,8 +9379,8 @@ func UdBarFeedRemainPush(c *gin.Context) {
 		return
 	}
 
-	gm.UdBarFeedRemainPush(pastureid, pastureinfo.Werks, date)
-
+	// gm.UdBarFeedRemainPush(pastureid, pastureinfo.Werks, date)
+	jpud.UdBarFeedRemainPush(pastureid, pastureinfo.Werks, date)
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
 
@@ -9335,8 +9400,8 @@ func UdMaterialIssuePush(c *gin.Context) {
 		return
 	}
 
-	gm.UdMaterialIssuePush(pastureid, pastureinfo.Werks, date)
-
+	// gm.UdMaterialIssuePush(pastureid, pastureinfo.Werks, date)
+	jpud.UdMaterialIssuePush(pastureid, pastureinfo.Werks, date)
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
 
@@ -11360,6 +11425,8 @@ func FtImportExcel(c *gin.Context) {
 	}
 	tx := restful.Engine.NewSession()
 	ftNameList := make(map[string]interface{})
+
+	var ftNames []interface{}
 	for i, row := range rows {
 		if i > 0 {
 
@@ -11483,7 +11550,6 @@ func FtImportExcel(c *gin.Context) {
 					}
 
 					outentry["input"] = inputdata
-					fmt.Println(sql, s_params)
 					returnmsgmap1, err := tx.SQL(sql, s_params...).Query().List()
 
 					if err != nil {
@@ -11521,18 +11587,7 @@ func FtImportExcel(c *gin.Context) {
 					}
 				}
 			}
-
-			values1, _ := tx.SQL(`select b.bname barname,	ifnull(ccount,0) ccount,ifnull(ratio,0) ratio,ftname,ptsfname,
-				ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 1 ),0) as '1' ,
-				ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 2
-					),0) as '2' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 3
-					),0) as '3' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 4
-					),0) as '4' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 5
-					),0) as '5' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 6
-					),0) as '6'   from feedp fp join bar b on b.id = fp.barid
-					join feedtemplet  ft on ft.id = fp.ftid  where ft.tname = ?`, outentry["配方名称"]).QueryString()
-			FpdBatchEditGrfd(pastureid, values1)
-
+			ftNames = append(ftNames, outentry["配方名称"])
 			switch {
 			case err != nil:
 				if tx != nil {
@@ -11552,9 +11607,89 @@ func FtImportExcel(c *gin.Context) {
 			isdone = true
 		}
 	}
+
+	go ftSync(ftNames, pastureid)
+
 	data := make(map[string]interface{})
 	data["result"] = queryData
 	data["success"] = ok
 	data["err_count"] = error
 	appG.Response(http.StatusOK, e.SUCCESS, data)
 }
+
+func ftSync(ftNameList []interface{}, pastureId string) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	for _, ftName := range ftNameList {
+		values1, _ := tx.SQL(`select b.bname barname,	ifnull(ccount,0) ccount,ifnull(ratio,0) ratio,ftname,ptsfname,
+				ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 1 ),0) as '1' ,
+				ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 2
+					),0) as '2' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 3
+					),0) as '3' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 4
+					),0) as '4' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 5
+					),0) as '5' ,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 6
+					),0) as '6'   from feedp fp join bar b on b.id = fp.barid
+					join feedtemplet  ft on ft.id = fp.ftid  where ft.tname = ?`, ftName).QueryString()
+		FpdBatchEditGrfd(pastureId, values1)
+	}
+
+}
+
+func CopyFeedtemplet(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	pastureid := fsion.Get("pastureid").ValueStr()
+	newName := fsion.Get("newName").ValueStr()
+	id := fsion.Get("id").ValueStr()
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	count, err := tx.SQL(` select count(1) from feedtemplet where tname = ? `, newName).Count()
+	if err != nil {
+		appG.Response(http.StatusOK, e.ERROR, err)
+		return
+	}
+	if count > 0 {
+		appG.Response(http.StatusOK, e.ERROR, "配方名称重复!")
+		return
+	}
+
+	type ftCode struct {
+		Tcode string `xorm:"tcode"`
+	}
+	code := new(ftCode)
+	err = tx.SQL(`select if(left((select max(tcode) from feedtemplet where pastureid = ?),8) = 
+	(select DATE_FORMAT(now(),"%Y%m%d")),(select max(tcode)+1 from feedtemplet where pastureid = ?),
+	(select concat(DATE_FORMAT(now(),"%Y%m%d"),"001"))) tcode`, pastureid, pastureid).GetFirst(code).Error
+	if err != nil {
+		appG.Response(http.StatusOK, e.ERROR, err)
+		return
+	}
+	if code.Tcode == "" {
+		appG.Response(http.StatusOK, e.ERROR, "配方编码生产失败!")
+		return
+	}
+
+	_, err = tx.Exec(`INSERT INTO feedtemplet(pastureid,tname,tcode,tcolor,ccid,ccname,fttype,fttypeid,source,
+	remark,enable,sort,volume,autozone) 
+	select pastureid,?,?,tcolor,ccid,ccname,fttype,fttypeid,source,
+	remark,enable,sort,volume,autozone from feedtemplet  where id = ? `, newName, code.Tcode, id)
+	if err != nil {
+		appG.Response(http.StatusOK, e.ERROR, fmt.Sprintf("配方生成失败 %v", err))
+		return
+	}
+
+	_, err = tx.Exec(`insert into ftdetail(pastureid,ftid,fid,fname,lweight,fweight, islockcount,isfg, sort,feedgroup,preftid, autosecond, 
+	autosecondname,splitftpreid, deviation, is_modify, is_show, shutdown,is_surplus, dry)
+select pastureid,(select id from feedtemplet where tcode = ? ),fid,fname,lweight,fweight, islockcount,isfg, sort,feedgroup,preftid, autosecond,
+ autosecondname,splitftpreid, deviation, is_modify, is_show, shutdown,is_surplus, dry 
+ from ftdetail where ftid = ? `, code.Tcode, id)
+	if err != nil {
+		appG.Response(http.StatusOK, e.ERROR, fmt.Sprintf("配方生成失败 %v", err))
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}

+ 25 - 11
http/handle/api/report.go

@@ -135,9 +135,9 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 			queryData, _ = getAccuracyV41(queryList, queryListSum, checked, feednamesort3, typea, feedDataList)
 		}
 		queryData["feedcode"] = feedcodelist
-		
+
 	case "getPriceAn":
-		queryData, err = getAccuracyV5(queryList)
+		queryData, err = getAccuracyV5(queryList, typea)
 	case "getJT1Accu":
 		queryData, err = getAccuracyV6(queryList) //固定维度 牧场
 	case "judgenurFT":
@@ -858,7 +858,7 @@ func getAccuracyV6(queryList []map[string]interface{}) (map[string]interface{},
 	queryData["data"] = queryList
 	return queryData, nil
 }
-func getAccuracyV5(queryList []map[string]interface{}) (map[string]interface{}, error) {
+func getAccuracyV5(queryList []map[string]interface{}, typea int) (map[string]interface{}, error) {
 	queryData := make(map[string]interface{})
 	chartData := make(map[string]interface{})
 	datamap1 := make(map[string]interface{})
@@ -942,15 +942,29 @@ func getAccuracyV5(queryList []map[string]interface{}) (map[string]interface{},
 		}
 		if queryList[i]["fname"] == temstr {
 			datamap2["label"] = queryList[i]["feedname"]
-			datamap2child["label"] = "理论"
-			datamap2child["prop"] = "a" + strconv.Itoa(a)
-			data3 = append(data3, datamap2child)
-			datamap2child = make(map[string]interface{})
 
-			datamap2child["label"] = "实际"
-			datamap2child["prop"] = "a" + strconv.Itoa(a+1)
-			data3 = append(data3, datamap2child)
-			datamap2child = make(map[string]interface{})
+			if typea == 0 || typea == 1 {
+				datamap2child["label"] = "理论"
+				datamap2child["prop"] = "a" + strconv.Itoa(a)
+				data3 = append(data3, datamap2child)
+				datamap2child = make(map[string]interface{})
+			}
+			if typea == 0 || typea == 2 {
+				datamap2child["label"] = "实际"
+				datamap2child["prop"] = "a" + strconv.Itoa(a+1)
+				data3 = append(data3, datamap2child)
+				datamap2child = make(map[string]interface{})
+			}
+
+			// datamap2child["label"] = "理论"
+			// datamap2child["prop"] = "a" + strconv.Itoa(a)
+			// data3 = append(data3, datamap2child)
+			// datamap2child = make(map[string]interface{})
+
+			// datamap2child["label"] = "实际"
+			// datamap2child["prop"] = "a" + strconv.Itoa(a+1)
+			// data3 = append(data3, datamap2child)
+			// datamap2child = make(map[string]interface{})
 
 			datamap2["children"] = data3
 			data2 = append(data2, datamap2)

+ 6 - 5
http/handle/api/scheduled.go

@@ -138,7 +138,7 @@ func CronScheduled(ctx context.Context) {
 	// jpud.UdBarSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// jpud.UdFeedSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// xdmy := cron.New()
-	// err = xdmy.AddFunc("0 30 6 * * *", func() {
+	// err = xdmy.AddFunc("0 05 7 * * *", func() {
 	// 	// 	// 	// 	//现代牧业sap同步
 	// 	// sap.SyncMaterialOutbound()
 	// 	// sap.SyncSurplusOutbound()
@@ -149,7 +149,7 @@ func CronScheduled(ctx context.Context) {
 	// 	jpud.JPUDUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// })
 	// xdmy.Start()
-	// InitMqttClient()
+	InitMqttClient()
 	// yq.YqCron()
 	//新希望配方同步定时任务
 
@@ -164,8 +164,9 @@ func CronScheduled(ctx context.Context) {
 
 	// })
 	// xxw.Start()
-	// XxwFeedtemplet(pastureinfo.Pastureid)
-	// XxwFeedtemplet(pastureinfo.Pastureid)
+
+	// ymy.YmySyncFeed(pastureinfo.Werks, pastureinfo.Pastureid)
+
 }
 
 type ScheduledInfo struct {
@@ -1088,7 +1089,7 @@ func manualUdData(pastureinfo *udPastureInfo) {
 	up := tx.Table("scheduled_up")
 
 	up.Where("company = ? ", "ud")
-	up.Where("datatype in (3,4)")
+	up.Where("datatype in (3,4,1)")
 	up.Where("automatic = 1")
 	err = up.Find(&upList)
 	if err != nil {

+ 15 - 6
http/handle/api/spillage.go

@@ -875,7 +875,9 @@ func GetSpillage(c *gin.Context) {
 	inner join  fpdetail
 	on  lpplandtl1.fpdid= fpdetail.id and lpplandtl1.pastureid = fpdetail.pastureid
 	 WHERE lpplandtl1.lppid=lpplan.id and lpplandtl1.pastureid =lpplan.pastureid ),2),0) sumweight ,
-	ifnull((select maxstirfeed from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),100000) maxweight,
+if((SELECT inforvalue FROM sysopt WHERE inforname = 'tmrOrVolume' AND lpplan.pastureid =lpplan.pastureid ) = 0 ,
+ifnull((select maxstirfeed from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),100000),round((select ifnull(volume,0)  from tmr where id  = lpplan.tmrid ) * 	 
+(select ifnull(volume,0) from feedtemplet where id = lpplan.ftid),2)   ) maxweight,
 	TRIM(ftid) ftid,
 	TRIM(id) id,
 	TRIM(id) lppid,
@@ -884,7 +886,10 @@ func GetSpillage(c *gin.Context) {
 	 (ifnull((select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUnder'),0)/100 *ifnull((select volume from tmr where id  = lpplan.tmrid ),0)) minVolume, 
 	ifnull((select volume from feedtemplet where id = lpplan.ftid ),0) ftvolume,
 	(select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUpper') tmrUpper,
-(select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUnder') tmrUnder
+(select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUnder') tmrUnder,
+ifnull((select maxstirfeed from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),100000) tmrWeight,
+ifnull(round((select ifnull(volume,0)  from tmr where id  = lpplan.tmrid ) * 	 
+(select ifnull(volume,0) from feedtemplet where id = lpplan.ftid),2),0 ) volumeWeight
 	FROM
 	  lpplan
 	WHERE pastureid = ?   and times <= (SELECT sysopt.inforvalue  FROM sysopt 
@@ -1441,7 +1446,9 @@ GROUP BY fpd.ptsid`
 		lpplan.times,display,begintime,
 		(select tname from feedtemplet where pastureid =lpplan.pastureid and id = lpplan.ftid ) ftname,sumcowcount,
 		IFNULL(round((SELECT SUM(lpplandtl1.lweight) FROM lpplandtl1date  lpplandtl1 WHERE lpplandtl1.lppid=lpplan.id and lpplandtl1.date= ?),2),0) sumweight ,
-		maxweight,
+		if((SELECT inforvalue FROM sysopt WHERE inforname = 'tmrOrVolume' AND lpplan.pastureid =lpplan.pastureid ) = 0 ,
+maxweight,(select ifnull(volume,0)  from tmr where id  = lpplan.tmrid ) * 	 
+(select ifnull(volume,0) from feedtemplet where id = lpplan.ftid)   ) maxweight,
 		TRIM(ftid) ftid,
 		TRIM(lpplan.id) id,
 		TRIM(lpplan.id) lppid,
@@ -1452,13 +1459,15 @@ GROUP BY fpd.ptsid`
 		(ifnull((select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUnder'),0)/100 *ifnull((select volume from tmr where id  = lpplan.tmrid ),0)) minVolume, 
 	   ifnull((select volume from feedtemplet where id = lpplan.ftid ),0) ftvolume,
 	   (select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUpper') tmrUpper,
-   (select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUnder') tmrUnder
+   (select inforvalue from sysopt  where pastureid = lpplan.pastureid  and inforname = 'tmrUnder') tmrUnder,
+   ifnull(round((select ifnull(volume,0)  from tmr where id  = lpplan.tmrid ) * 	 
+(select ifnull(volume,0) from feedtemplet where id = lpplan.ftid) ,2),0) volumeWeight,maxweight tmrWeight
+
 		FROM
 		  lpplandate lpplan
 			left join downloadedplan dpl on dpl.pid = lpplan.id  and  DATE_FORMAT(dpl.mydate,'%Y-%m-%e') = lpplan.date
 		WHERE lpplan.pastureid = ?  and lpplan.date = ? and lpplan.times <= (SELECT sysopt.inforvalue  FROM sysopt 
-		 WHERE sysopt.pastureid= lpplan.pastureid  AND sysopt.inforname='times') 
-		`
+		 WHERE sysopt.pastureid= lpplan.pastureid  AND sysopt.inforname='times') `
 
 		arrsql := `SELECT
 		trim(lpplandtl1.lppid) lppid,lweight,

+ 20 - 20
http/handle/jpud/udservice.go

@@ -19,7 +19,7 @@ import (
 
 // "../../../pkg/setting"
 // "../../../routers/restful"
-// http://46.137.227.57:8380/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=ef275fb06fd847d88422517773e5a616&method=downloadpen
+// https://fnhbdairyfarmlive.fn.com.my:8380/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=ef275fb06fd847d88422517773e5a616&method=downloadpen
 func JPUDUdSync(pastureId, farmId string) {
 	// 撒料
 	UdMaterialIssuePush(pastureId, farmId, "")
@@ -55,7 +55,7 @@ func JPUDUdSync(pastureId, farmId string) {
 }
 
 func UdBarSync(pastureId, farmId string) {
-	url := fmt.Sprintf("http://46.137.227.57:8380/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=%s&method=downloadpen", farmId)
+	url := fmt.Sprintf("https://fnhbdairyfarmlive.fn.com.my:8380/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=%s&method=downloadpen", farmId)
 	barByte := getPull(url)
 	fmt.Println(string(barByte))
 	barMap := make([]interface{}, 0)
@@ -100,7 +100,7 @@ func UdBarSync(pastureId, farmId string) {
 }
 
 func UdFeedSync(pastureId, farmId string) {
-	url := fmt.Sprintf("http://46.137.227.57:8380/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=%s&method=downloadmaterial", farmId)
+	url := fmt.Sprintf("https://fnhbdairyfarmlive.fn.com.my:8380/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=%s&method=downloadmaterial", farmId)
 	feedByte := getPull(url)
 	fmt.Println(string(feedByte))
 	tx := restful.Engine.NewSession()
@@ -157,20 +157,20 @@ func getPull(url string) []byte {
 	forwardingReq := new(ForwardingReq)
 	forwardingReq.Url = url
 	forwardingReq.Method = "GET"
-	// jsonStr, _ := json.Marshal(forwardingReq)
+	jsonStr, _ := json.Marshal(forwardingReq)
 
-	req, err := http.NewRequest("GET", url, nil)
-	if err != nil {
-		logs.Error(err)
-		// return nil
-	}
-
-	// req, err := http.NewRequest("POST", setting.ServerSetting.UDForwardingSvc+":8080/forwarding", bytes.NewBuffer(jsonStr))
+	// req, err := http.NewRequest("GET", url, nil)
 	// if err != nil {
 	// 	logs.Error(err)
 	// 	// return nil
 	// }
 
+	req, err := http.NewRequest("POST", setting.ServerSetting.UDForwardingSvc+":8080/forwarding", bytes.NewBuffer(jsonStr))
+	if err != nil {
+		logs.Error(err)
+		// return nil
+	}
+
 	req.Header.Set("Content-Type", "application/json")
 	// client := &http.Client{}
 	tr := &http.Transport{
@@ -482,17 +482,17 @@ type Headers struct {
 func postPush(data string, msgtype int, tx *xorm.Session, pastureId string) {
 
 	forwardingReq := new(ForwardingReq)
-	forwardingReq.Url = "http://46.137.227.57:8380/copartner_uploads/"
+	forwardingReq.Url = "https://fnhbdairyfarmlive.fn.com.my:8380/copartner_uploads/"
 	forwardingReq.Method = "POST"
 	forwardingReq.Body = data
-	// jsonStr, _ := json.Marshal(forwardingReq)
-	// fmt.Println(setting.ServerSetting.UDForwardingSvc)
-	// req, err := http.NewRequest("POST", setting.ServerSetting.UDForwardingSvc+":8080/forwarding", bytes.NewBuffer(jsonStr))
-	req, err := http.NewRequest("POST", forwardingReq.Url, bytes.NewBuffer([]byte(data)))
-	if err != nil {
-		logs.Error(err)
-		// return nil
-	}
+	jsonStr, _ := json.Marshal(forwardingReq)
+	fmt.Println(setting.ServerSetting.UDForwardingSvc)
+	req, err := http.NewRequest("POST", setting.ServerSetting.UDForwardingSvc+":8080/forwarding", bytes.NewBuffer(jsonStr))
+	// req, err := http.NewRequest("POST", forwardingReq.Url, bytes.NewBuffer([]byte(data)))
+	// if err != nil {
+	// 	logs.Error(err)
+	// 	// return nil
+	// }
 
 	req.Header.Set("Content-Type", "application/json")
 	// client := &http.Client{}

+ 53 - 13
http/handle/sap/sap.go

@@ -10,6 +10,7 @@ import (
 
 	"tmr-watch/conf/setting"
 	"tmr-watch/http/handle/restful"
+	"tmr-watch/models"
 	"tmr-watch/pkg/app"
 	"tmr-watch/pkg/e"
 
@@ -154,6 +155,20 @@ func SurplusOutbound(c *gin.Context) {
 	appG.Response(http.StatusOK, e.SUCCESS, true)
 }
 
+type feedPlanRecord struct {
+	CHSNO   string  `xorm:"'CHSNO' varchar(50)" json:"CHSNO"`       // 栏位SAP编码
+	CHSTX   string  `xorm:"'CHSTX' varchar(100)" json:"CHSTX"`      // 栏位名称
+	FCWTS   string  `xorm:"'FCWTS' varchar(20)" json:"FCWTS"`       // 牛群分类
+	LGORT   string  `xorm:"'LGORT' varchar(50)" json:"LGORT"`       // SAP库存地点
+	MAKTX   string  `xorm:"'MAKTX' varchar(100)" json:"MAKTX"`      // 饲料名称
+	MATNR   string  `xorm:"'MATNR' varchar(50)" json:"MATNR"`       // SAP物料编号
+	MENGE   float64 `xorm:"'MENGE' decimal(18,4)" json:"MENGE"`     // 实际用量
+	ZEILE   int     `xorm:"'ZEILE' int" json:"ZEILE"`               // 行号
+	Lweight float64 `xorm:"'lweight' decimal(18,4)" json:"lweight"` // 理论用量
+	FeedId  int64   `xorm:"'feedId' int" json:"feedId"`
+	BarId   int64   `xorm:"'fbarid' int" json:"fbarid"`
+}
+
 func materialOutbound(pastureId, date string) error {
 
 	tx := restful.Engine.NewSession()
@@ -164,8 +179,8 @@ func materialOutbound(pastureId, date string) error {
 		logs.Error(err)
 		return err
 	}
-
-	dataList, err := tx.SQL(`			SELECT 
+	dataList := make([]*feedPlanRecord, 0)
+	err = tx.SQL(`	SELECT  tem.feedId,tem.fbarid,
 	tem.sort ZEILE,
 	tem.feedname MAKTX,
 	sum(ifnull(ROUND(if(tem.lweight<0,0,tem.lweight),(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid =? )),0))lweight,
@@ -173,7 +188,7 @@ func materialOutbound(pastureId, date string) error {
 	,tem.bname CHSTX,tem.sapcode CHSNO,tem.cattle FCWTS,tem.MATNR,tem.sapGoods LGORT
 
 	 FROM (
-	(SELECT 
+	(SELECT  f.id feedId,
 	d2.type,d2.fbarid,
 	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
 	SUM(
@@ -210,7 +225,7 @@ func materialOutbound(pastureId, date string) error {
 	
 	UNION
 	
-		(SELECT 
+		(SELECT  f.id feedId,
 	d2.type,d2.fbarid,
 	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
 	SUM(
@@ -248,11 +263,36 @@ left join feed f on f.id = ftd.fid
 	
 	) tem
     GROUP BY tem.fbarid,tem.feedname 
-	ORDER BY tem.d2sort,tem.feedname   `, pastureId, pastureId, pastureId, date, pastureId, date).Query().List()
+	ORDER BY tem.d2sort,tem.feedname   `, pastureId, pastureId, pastureId, date, pastureId, date).Find(&dataList)
 	if err != nil {
 		logs.Error(err)
 		return err
 	}
+	wasteUseList := make([]*models.WasteUse, 0)
+
+	err = tx.Table("wasteuse").Select("id,ftid,ftname,times,date,(select feedId from surplus  where id = wasteuse.surplusId ) surplusId,surplus,pastureId,weight,barid,barname").Where("date = ? ", date).Where("pastureId = ? ", pastureId).Find(&wasteUseList)
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+	for _, wasteUse := range wasteUseList {
+		for _, data := range dataList {
+			if data.FeedId == wasteUse.SurplusId && data.BarId == wasteUse.Barid {
+				newWeight := data.MENGE - wasteUse.Weight
+
+				if newWeight < 0 {
+					wasteUse.Weight = wasteUse.Weight - data.MENGE
+					data.MENGE = 0
+				} else {
+					data.MENGE = newWeight
+					wasteUse.Weight = 0
+				}
+			}
+			if wasteUse.Weight <= 0 {
+				break
+			}
+		}
+	}
 
 	data := `{
 		"DEST": {
@@ -579,24 +619,24 @@ func leftoverEntry(pastureId, date string) error {
 	}
 	// now, _ := time.ParseInLocation("2006-01-02", date, time.Local)
 
-	dataList, err := tx.SQL(`  SELECT
+	dataList, err := tx.SQL(`   SELECT
 	p.werks WERKS,
-	DATE_FORMAT( b.remaindate, '%Y%m%d' ) BUDAT,
+	DATE_FORMAT( b.date, '%Y%m%d' ) BUDAT,
 	ft.cattle FCWTS,
 	bar.sapCode CHSNO,
-	b.barname CHSTX,
+	bar.bname CHSTX,
 	 '11.01.01.01.000094' MATNR,
 	'系统剩料' MAKTX,
-  b.remain  MENGE ,"KG" MEINS,ztbar.sapCode ZCHSNO,ztbar.bname ZCHSTX
+  b.weight  MENGE ,"KG" MEINS,ztbar.sapCode ZCHSNO,ztbar.bname ZCHSTX
 FROM
-	barfeedremain b
+	wasteuse b
 	JOIN pasture p ON b.pastureid = p.pastureid
-	JOIN feedpdate fp ON fp.date = b.remaindate 
+	JOIN feedpdate fp ON fp.date = b.date 
 	AND fp.barid = b.barid
 	JOIN bar ON bar.id = b.barid
 	JOIN feedtemplet ft ON ft.id = fp.ftid
-	left join bar ztbar on ztbar.id  = b.useinbarid
-	where  DATE_FORMAT( b.remaindate, '%Y-%m-%d' ) = ? and b.pastureid = ?  `, date, pastureId).Query().List()
+	left join bar ztbar on ztbar.id  = b.barid
+	where  DATE_FORMAT( b.date, '%Y-%m-%d' ) = ?  and b.pastureid = ?  `, date, pastureId).Query().List()
 	if err != nil {
 		logs.Error(err)
 		return err

+ 220 - 0
http/handle/ymy/ymy.go

@@ -0,0 +1,220 @@
+package ymy
+
+import (
+	"bytes"
+	"crypto/tls"
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"time"
+	"tmr-watch/conf/setting"
+	"tmr-watch/http/handle/restful"
+	"tmr-watch/models"
+	"tmr-watch/pkg/logging"
+
+	"github.com/astaxie/beego/logs"
+	"github.com/xormplus/xorm"
+)
+
+func YmyCron() {
+	// pastureinfo := new(udPastureInfo)
+	// err := tx.SQL(`select column_default  as pastureid   from    information_schema.COLUMNS
+	// WHERE table_name = 'recweight' AND table_schema = ? AND column_name = 'pastureid'`, setting.DatabaseSetting.Name).GetFirst(pastureinfo).Error
+	// if err != nil {
+	// 	logs.Error(err)
+	// 	return err
+	// }
+}
+
+func YmySyncBar(farmId, pastureId string) {
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	reqJson := `{
+	"methodKey": "getFeedPenList",
+	"param": {
+	    "farmId": "%s",
+	    "parlorType": "CPT"
+	},
+	"platform": "CPT",
+	"regCode": "cpt180511",
+	"secret": "67a74fd5748054ac67b6fc433e9249b0"}`
+
+	barPull("http://dairy.yimucloud.com/dairy/external/api", fmt.Sprintf(reqJson, farmId), 3, tx, pastureId)
+}
+
+func barPull(url, data string, msgtype int, tx *xorm.Session, pastureId string) {
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(data)))
+	if err != nil {
+		logs.Error(err)
+	}
+
+	req.Header.Set("Content-Type", "application/json")
+	// client := &http.Client{}
+	tr := &http.Transport{
+		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+	}
+	client := &http.Client{Transport: tr}
+
+	resp, err := client.Do(req)
+	if err != nil {
+		logs.Error(err)
+		return
+	}
+	defer resp.Body.Close()
+	body, _ := ioutil.ReadAll(resp.Body)
+
+	respData := new(models.BarResponse)
+	json.Unmarshal(body, &respData)
+
+	tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
+		values(?,?,?,?,?,now(),?,now(),?)`, pastureId, data, string(body), "", "", msgtype, url)
+
+	for _, v := range respData.Result {
+		count, _ := tx.Table("bar").Where("pastureId = ? ", pastureId).Count()
+		tx.Exec(`insert into bar(pastureid,bcode,bname,sort)values(?,?,?,?)   ON DUPLICATE KEY UPDATE  bname = ?  `, pastureId, v.PenId, v.PenName, count+1, v.PenName)
+	}
+}
+
+func YmySyncFeed(farmId, pastureId string) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	reqJson := `{
+  "data":{
+    "page": "0",
+    "size": "1000",
+    "modifiedAfter":"2025-01-01 00:00:00",
+    "MATERIAL_BASIC_CLASSIFICATION_CODE":"",
+    "MATERIAL_CODE": ""
+  }}`
+
+	// reqJson = fmt.Sprintf(reqJson, time.Now().Format("2006-01-02 15:04:05"))
+	feedPull("http://113.250.182.238:9000/ierp/kapi/v2/iscb/route/script_cusapi_deepexi_material_query", reqJson, 2, tx, pastureId, getApiToken())
+}
+
+type udPastureInfo struct {
+	Token      string `xorm:"token"`
+	Pastureid  string `xorm:"pastureid"`
+	Werks      string `xorm:"werks"`
+	UpdateDate string `xorm:"updatedate"`
+}
+
+func getApiToken() string {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	pastureinfo := new(udPastureInfo)
+	err := tx.SQL(`SELECT (SELECT pastureid FROM pasture WHERE pastureid = column_default)  pastureid,
+    IF( TIMESTAMPDIFF(MINUTE,
+            (SELECT updatedate FROM pasture WHERE pastureid = column_default), 
+            NOW()
+        ) > 60,  -- 110分钟 = 1小时50分钟
+        '',        -- 超过时间返回空字符串
+        (SELECT token FROM pasture WHERE pastureid = column_default)   -- 否则返回 pastureid
+    ) AS token,
+    (SELECT werks FROM pasture WHERE pastureid = column_default) AS werks,
+    DATE_FORMAT(
+        (SELECT updatedate FROM pasture WHERE pastureid = column_default),
+        '%Y-%m-%d %H:%i:%s'
+    ) AS updatedate
+FROM information_schema.COLUMNS
+WHERE table_name = 'recweight' 
+AND table_schema = ?
+AND column_name = 'pastureid' `, setting.DatabaseSetting.Name).GetFirst(pastureinfo).Error
+	if err != nil {
+		logs.Error(err)
+		return pastureinfo.Token
+	}
+
+	if pastureinfo.Token != "" {
+		return pastureinfo.Token
+	}
+	reqJson := `{
+    "client_id": "Cosmic_deepexi_user",
+    "client_secret": "Cosmic_zkm_deepexi_openapi@user01",
+    "username": "dipujiekouyonghu",
+    "accountId": "2174058657413595136",
+    "nonce": "a42c1a91-56ad-4c6d-95d1-40bcb8b5ec89",
+    "timestamp": "%s",
+    "language": "zh_CN"
+}`
+	reqJson = fmt.Sprintf(reqJson, time.Now().Format("2006-01-02 15:04:05"))
+	req, err := http.NewRequest("POST", "http://113.250.182.238:9000/ierp/kapi/oauth2/getToken", bytes.NewBuffer([]byte(reqJson)))
+	if err != nil {
+		logs.Error(err)
+	}
+
+	req.Header.Set("Content-Type", "application/json")
+	tr := &http.Transport{
+		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+	}
+	client := &http.Client{Transport: tr}
+
+	resp, err := client.Do(req)
+	if err != nil {
+		logs.Error(err)
+		return pastureinfo.Token
+	}
+	defer resp.Body.Close()
+	body, _ := ioutil.ReadAll(resp.Body)
+	fmt.Println(string(body))
+	token := new(models.TokenResponse)
+	json.Unmarshal(body, &token)
+	tx.Exec(" update pasture set token = ?,updatedate = now()  where pastureid = ?  ", token.Data.AccessToken, pastureinfo.Pastureid)
+
+	return token.Data.AccessToken
+}
+
+func feedPull(url, data string, msgtype int, tx *xorm.Session, pastureId, token string) {
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(data)))
+	if err != nil {
+		logs.Error(err)
+	}
+
+	req.Header.Set("Content-Type", "application/json")
+	req.Header.Set("access_token", token)
+	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))
+
+	feedData := new(models.FeedResponse)
+	json.Unmarshal(body, &feedData)
+	for _, v := range feedData.Data.Content {
+		feedname := v.MaterialName
+		feedcode := v.MaterialCode
+		feedClassExist, err := tx.Table("feedclass").Where("fccode = ? ", v.MaterialClassification).Where(" pastureId = ? ", pastureId).Exist()
+		fmt.Println(err)
+		if !feedClassExist {
+			count, _ := tx.Table("feedclass").Where("pastureId = ? ", pastureId).Count()
+			ids, err := setting.SnowIds.NextId()
+			if err != nil {
+				ids = time.Now().UnixNano()
+			}
+			_, err = tx.Exec(`insert into feedclass(id,pastureId,fcname,fccode,bigfeedclassname,sort,bigfeedclassid) values(?,?,?,?,?,?,?)`,
+				ids, pastureId, v.MaterialClassification, v.MaterialClassification, v.MaterialClassification, count+1, ids)
+			fmt.Println(err)
+		}
+
+		ids, err := setting.SnowIds.NextId()
+		if err != nil {
+			ids = time.Now().UnixNano()
+			logging.Info("create SnowIds err", err)
+		}
+		tx.Exec(`insert into feed(id,pastureId,feedcode,udname,fclassid,fclass,fname) values(?,?,?,?,(select id from feedclass where fccode = ? and pastureId = ? ),?,if(char_length(?) > 7, left(?,7),?) )
+		ON DUPLICATE KEY UPDATE udname = ? ,fclassid = (select id from feedclass where fccode = ? and pastureId = ? ) ,fclass = ?`,
+			ids, pastureId, feedcode, feedname, v.MaterialClassification, pastureId, v.MaterialClassification, feedname, feedname, feedname, feedname,
+			v.MaterialClassification, pastureId, v.MaterialClassification)
+	}
+	tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
+		values(?,?,?,?,?,now(),?,now(),?)`, pastureId, data, string(body), "", "", msgtype, url)
+}

+ 2 - 1
http/routers/app_api.go

@@ -253,11 +253,12 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 			// 云养牛撒料上传
 			apiV1.POST("/dusting/yyn/upload", api.LabourDustingPush)
 
-			apiV1.POST("/xdmy/sap/wasteuse", sap.Wasteuse)
+			apiV1.POST("/xdmy/sap/wasteuse", sap.LeftoverEntry)
 			apiV1.POST("/xdmy/sap/leftoverEntry", sap.LeftoverEntry)
 			apiV1.POST("/process/excel", api.ProcessExcel)
 			apiV1.POST("/FtImportExcel", api.FtImportExcel)
 
+			apiV1.POST("/feedtemplet/copy", api.CopyFeedtemplet)
 		}
 
 		//不需要登录验证的接口

二進制
mlxy.zip


+ 20 - 0
models/wasteuse.go

@@ -0,0 +1,20 @@
+package models
+
+type WasteUse struct {
+	Id        int64   `xorm:"bigint not null pk autoincr 'id'" json:"id"` // 主键ID
+	Ftid      int64   `xorm:"bigint 'ftid'" json:"ftid"`                  // 配方ID
+	Ftname    string  `xorm:"varchar(255) 'ftname'" json:"ftname"`        // 配方名称
+	Times     int8    `xorm:"tinyint(1) 'times'" json:"times"`            // 班次
+	Date      string 	 `xorm:"date 'date'" json:"date"`                    // 日期
+	SurplusId int64   `xorm:"bigint 'surplusId'" json:"surplusId"`        // 剩料ID
+	Surplus   string  `xorm:"varchar(40) 'surplus'" json:"surplus"`       // 剩料配置
+	PastureId int     `xorm:"int 'pastureId'" json:"pastureId"`           // 牧场ID
+	Weight    float64 `xorm:"decimal(12,2) 'weight'" json:"weight"`       // 重量
+	Barid     int64   `xorm:"bigint 'barid'" json:"barid"`                // 栏位ID
+	Barname   string  `xorm:"varchar(50) 'barname'" json:"barname"`       // 栏位名称
+}
+
+// 设置表名
+func (WasteUse) TableName() string {
+	return "wasteuse"
+}

+ 94 - 0
models/ymy.go

@@ -0,0 +1,94 @@
+package models
+
+type BarInfo struct {
+	PenName string `json:"penName"`
+	PenType string `json:"penType"`
+	PenId   string `json:"penId"`
+	AddDate string `json:"addDate"`
+	UpdDate string `json:"updDate"`
+}
+
+type BarResponse struct {
+	Success   bool        `json:"success"`
+	Msg       string      `json:"msg"`
+	MsgId     int         `json:"msgId"`
+	Result    []*BarInfo  `json:"result"`
+	Data      interface{} `json:"data"`
+	Timestamp int64       `json:"timestamp"`
+}
+
+type FeedResponse struct {
+	Code    int          `json:"code"`
+	Message string       `json:"message"`
+	Data    FeedSyncData `json:"data"`
+}
+
+type FeedSyncData struct {
+	Number           int  `json:"number"`
+	Total            int  `json:"total"`
+	Last             bool `json:"last"`
+	NumberOfElements int  `json:"numberOfElements"`
+	Size             int  `json:"size"`
+	TotalPages       int  `json:"totalPages"`
+	// Pageable         Pageable      `json:"pageable"`
+	// Sort             Sort          `json:"sort"`
+	Content       []*ContentItem `json:"content"`
+	First         bool           `json:"first"`
+	TotalElements int            `json:"totalElements"`
+}
+
+type ContentItem struct {
+	PurchaseUnitPrice               string                    `json:"PURCHASE_UNIT_PRICE"`
+	DataSource                      string                    `json:"DATA_SOURCE"`
+	State                           string                    `json:"STATE"`
+	Specification                   string                    `json:"SPECIFICATION"`
+	TYMATERIALCLASSIFICATIONCODE    string                    `json:"TY_MATERIAL_CLASSIFICATION_CODE"`
+	MaterialMeasurementUnitInfo     []MaterialMeasurementUnit `json:"MATERIAL_MEASUREMENT_UNIT_INFO"`
+	Origin                          string                    `json:"ORIGIN"`
+	WarehousingTolerance            string                    `json:"WAREHOUSING_TOLERANCE"`
+	MaterialBasicClassificationCode string                    `json:"MATERIAL_BASIC_CLASSIFICATION_CODE"`
+	ProductImageData                string                    `json:"PRODUCT_IMAGE_DATA"`
+	UnitWeight                      string                    `json:"UNIT_WEIGHT"`
+	UnitVolumn                      string                    `json:"UNIT_VOLUMN"`
+	MaterialName                    string                    `json:"MATERIAL_NAME"`
+	MnemonicCode                    string                    `json:"MNEMONIC_CODE"`
+	TonWeightRatio                  string                    `json:"TON_WEIGHT_RATIO"`
+	MaterialAbbreviation            string                    `json:"MATERIAL_ABBREVIATION"`
+	TYMATERIALCODE                  string                    `json:"TY_MATERIAL_CODE"`
+	ShelfLifeDays                   string                    `json:"SHELF_LIFE_DAYS"`
+	Model                           string                    `json:"MODEL"`
+	Manufacturer                    string                    `json:"MANUFACTURER"`
+	Brand                           string                    `json:"BRAND"`
+	MinPCKQQTY                      string                    `json:"MINPCKQQTY"`
+	TYMATERIALCLASSIFICATIONNAME    string                    `json:"TY_MATERIAL_CLASSIFICATION_NAME"`
+	ProductLine                     string                    `json:"PRODUCT_LINE"`
+	TaxRate                         string                    `json:"TAX_RATE"`
+	MaterialClassification          string                    `json:"MATERIAL_CLASSIFICATION"`
+	CostPrice                       string                    `json:"COST_PRICE"`
+	MaterialCode                    string                    `json:"MATERIAL_CODE"`
+	SystemPush                      string                    `json:"SYSTEM_PUSH"`
+}
+
+type MaterialMeasurementUnit struct {
+	Convert           string `json:"CONVERT"`
+	BarCode           string `json:"BAR_CODE"`
+	MeasurementName   string `json:"MEASUREMENT_NAME"`
+	MeasurementCode   string `json:"MEASUREMENT_CODE"`
+	IsMeasurementUnit string `json:"IS_MEASUREMENT_UNIT"`
+}
+
+type TokenResponse struct {
+	Data struct {
+		AccessToken      string  `json:"access_token"`
+		TokenType        string  `json:"token_type"`
+		RefreshToken     string  `json:"refresh_token"`
+		Scope            string  `json:"scope"`
+		ExpiresIn        int     `json:"expires_in"`
+		IDToken          *string `json:"id_token"`
+		IDTokenExpiresIn *int    `json:"id_token_expires_in"`
+		Language         string  `json:"language"`
+	} `json:"data"`
+	ErrorCode string `json:"errorCode"`
+	Message   string `json:"message"`
+	Status    bool   `json:"status"`
+}

+ 9 - 4
update.sql

@@ -392,10 +392,15 @@ ALTER TABLE `barfeedremain`
 ADD COLUMN `useinbar` varchar(50) NULL AFTER `useinbarid`;
 
 
-ALTER TABLE `ftdetail` 
-ADD COLUMN `dry` varchar(30) NULL COMMENT '干物质,默认取饲料那边' AFTER `is_surplus`;
+  ALTER TABLE `ftdetail` 
+  ADD COLUMN `dry` varchar(30) NULL COMMENT '干物质,默认取饲料那边' AFTER `is_surplus`;
+
+
 
+  ALTER TABLE `ftdetaildate` 
+  ADD COLUMN `dry` varchar(30) NULL COMMENT '干物质' AFTER `deviation`;
 
 
-ALTER TABLE `ftdetaildate` 
-ADD COLUMN `dry` varchar(30) NULL COMMENT '干物质' AFTER `deviation`;
+  ALTER TABLE pasture
+ADD COLUMN `token` varchar(200) NULL AFTER `werks`,
+ADD COLUMN `updatedate` datetime NULL AFTER `token`

二進制
uploads.zip


二進制
uploads/file/导入导出模板/栏舍生产/Dry Matter Formula Import Template.xlsx


二進制
uploads/file/导入导出模板/栏舍生产/Dry Matter Formula Import Template11111111111.xlsx


部分文件因文件數量過多而無法顯示