baishaojie hai 1 ano
pai
achega
737e975a48
Modificáronse 73 ficheiros con 909 adicións e 248 borrados
  1. 9 1
      11111.sql
  2. BIN=BIN
      TMRWatchComm
  3. BIN=BIN
      TMRWatchComm.zip
  4. 9 6
      conf/app.ini
  5. BIN=BIN
      dist-tmr-20240726.zip
  6. BIN=BIN
      dist-tmr-20240726/dist/favicon.ico
  7. 0 0
      dist-tmr-20240726/dist/index.html
  8. 0 0
      dist-tmr-20240726/dist/static/css/app.f3bb49e8.css
  9. 0 0
      dist-tmr-20240726/dist/static/css/chunk-elementUI.c1c3b808.css
  10. 0 0
      dist-tmr-20240726/dist/static/css/chunk-libs.f403b559.css
  11. BIN=BIN
      dist-tmr-20240726/dist/static/fonts/element-icons.535877f5.woff
  12. BIN=BIN
      dist-tmr-20240726/dist/static/fonts/element-icons.732389de.ttf
  13. BIN=BIN
      dist-tmr-20240726/dist/static/img/404.a57b6f31.png
  14. BIN=BIN
      dist-tmr-20240726/dist/static/img/404_cloud.0f4bc32b.png
  15. BIN=BIN
      dist-tmr-20240726/dist/static/img/guiji2.9dc0addf.jpeg
  16. 28 0
      dist-tmr-20240726/dist/static/img/iconfont.0ddaba12.svg
  17. BIN=BIN
      dist-tmr-20240726/dist/static/img/logo.afed751a.png
  18. BIN=BIN
      dist-tmr-20240726/dist/static/img/logo1.0121925c.png
  19. BIN=BIN
      dist-tmr-20240726/dist/static/img/logo_u3.3c77f543.png
  20. BIN=BIN
      dist-tmr-20240726/dist/static/img/nlogin-bg1.77301f56.jpg
  21. BIN=BIN
      dist-tmr-20240726/dist/static/img/row-bg3.b3be7548.png
  22. BIN=BIN
      dist-tmr-20240726/dist/static/img/topBg.69ecd1e1.png
  23. 0 0
      dist-tmr-20240726/dist/static/js/app.d0378b28.js
  24. 0 0
      dist-tmr-20240726/dist/static/js/chunk-4ab5740d.fd41fff9.js
  25. 0 0
      dist-tmr-20240726/dist/static/js/chunk-52ecc0ac.6e6c1552.js
  26. 0 0
      dist-tmr-20240726/dist/static/js/chunk-5c4dc4a9.8801e0b1.js
  27. 0 0
      dist-tmr-20240726/dist/static/js/chunk-b702d234.4563c788.js
  28. 0 0
      dist-tmr-20240726/dist/static/js/chunk-elementUI.c961dc79.js
  29. 0 0
      dist-tmr-20240726/dist/static/js/chunk-libs.2172166f.js
  30. BIN=BIN
      dist-tmr-肉牛-20240726-1.zip
  31. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/favicon.ico
  32. 0 0
      dist-tmr-肉牛-20240726-1/dist/index.html
  33. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/css/app.f3fc20f1.css
  34. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/css/chunk-elementUI.c1c3b808.css
  35. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/css/chunk-libs.1664ae71.css
  36. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/fonts/element-icons.535877f5.woff
  37. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/fonts/element-icons.732389de.ttf
  38. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/404.a57b6f31.png
  39. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/404_cloud.0f4bc32b.png
  40. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/btn2.de90fd6d.png
  41. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/center_bg1.690da89a.png
  42. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/center_bg2.e477a3e9.png
  43. 28 0
      dist-tmr-肉牛-20240726-1/dist/static/img/iconfont.0ddaba12.svg
  44. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/login_bg1.c50e72f6.png
  45. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/login_bg2.73eb2ddc.png
  46. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/logo1.4aaac8e0.png
  47. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/logo1.e7208fde.png
  48. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/logo2.22a9a311.png
  49. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/logo_u3.46875a04.png
  50. BIN=BIN
      dist-tmr-肉牛-20240726-1/dist/static/img/topBg.d21a9f50.png
  51. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/js/app.145b7be3.js
  52. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/js/chunk-218b9b2f.443d0c85.js
  53. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/js/chunk-52ecc0ac.fb113243.js
  54. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/js/chunk-5c4dc4a9.b8eedd10.js
  55. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/js/chunk-b702d234.640724c3.js
  56. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/js/chunk-elementUI.c961dc79.js
  57. 0 0
      dist-tmr-肉牛-20240726-1/dist/static/js/chunk-libs.c399c5fe.js
  58. 0 0
      dist/index.html
  59. 0 0
      dist/static/css/app.f3bb49e8.css
  60. 0 0
      dist/static/js/app.d0378b28.js
  61. 0 0
      dist/static/js/app.ff8699cf.js
  62. 0 0
      dist/static/js/chunk-libs.2172166f.js
  63. 88 23
      http/handle/api/grfdApi.go
  64. 16 16
      http/handle/api/mqtt.go
  65. 309 108
      http/handle/api/ops.go
  66. 249 67
      http/handle/api/scheduled.go
  67. 4 4
      http/handle/api/spillage.go
  68. 7 0
      http/handle/api/upload.go
  69. 139 20
      http/handle/sap/sap.go
  70. 2 2
      http/handle/yq/yq.go
  71. 3 0
      http/routers/app_api.go
  72. 18 1
      update.sql
  73. BIN=BIN
      uploads.zip

+ 9 - 1
11111.sql

@@ -784,4 +784,12 @@ ADD COLUMN   `appoint` int(11) DEFAULT NULL COMMENT '撒料车指定搅拌车';
 
      
      	  ALTER TABLE pasture	
-   ADD COLUMN  `werks` varchar(255) DEFAULT NULL;
+   ADD COLUMN  `werks` varchar(255) DEFAULT NULL;
+
+
+
+
+   DELETE fp
+FROM feedp fp
+LEFT JOIN bar b ON fp.barid = b.id
+WHERE b.id IS NULL;

BIN=BIN
TMRWatchComm


BIN=BIN
TMRWatchComm.zip


+ 9 - 6
conf/app.ini

@@ -21,7 +21,7 @@ TimeFormat = 20060102-150405
 #debug or release
 #RunMode = debuggit 
 RunMode = release
-HttpPort = 80
+HttpPort = 8081
 ReadTimeout = 60
 WriteTimeout = 60
 NoAuth = 1
@@ -75,7 +75,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = tmrwatch5
+Name = tmrwatch
 TablePrefix =
 
 ShowXormlog = false
@@ -92,11 +92,14 @@ Password =
 Name = 
 
 [yyn]
-FarmId = "1830002083"
+FarmId = "1830002644"
 ProductKey = "k03txxLKFae"
-DeviceName = "02083_p_breed"
-DeviceSecret = "018fe8318a1151fa44e6507b7b46ce7a"
-HeartBeat = "Tmr183000208302083_p_breed"
+DeviceName = "02644_p_breed"
+DeviceSecret = "e1e95a40758027c3a097d0bc5f3990e7"
+HeartBeat = "Tmr183000264402644_p_breed"
+
+
+
 
 
 [comm]

BIN=BIN
dist-tmr-20240726.zip


BIN=BIN
dist-tmr-20240726/dist/favicon.ico


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/index.html


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/css/app.f3bb49e8.css


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/css/chunk-elementUI.c1c3b808.css


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/css/chunk-libs.f403b559.css


BIN=BIN
dist-tmr-20240726/dist/static/fonts/element-icons.535877f5.woff


BIN=BIN
dist-tmr-20240726/dist/static/fonts/element-icons.732389de.ttf


BIN=BIN
dist-tmr-20240726/dist/static/img/404.a57b6f31.png


BIN=BIN
dist-tmr-20240726/dist/static/img/404_cloud.0f4bc32b.png


BIN=BIN
dist-tmr-20240726/dist/static/img/guiji2.9dc0addf.jpeg


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 28 - 0
dist-tmr-20240726/dist/static/img/iconfont.0ddaba12.svg


BIN=BIN
dist-tmr-20240726/dist/static/img/logo.afed751a.png


BIN=BIN
dist-tmr-20240726/dist/static/img/logo1.0121925c.png


BIN=BIN
dist-tmr-20240726/dist/static/img/logo_u3.3c77f543.png


BIN=BIN
dist-tmr-20240726/dist/static/img/nlogin-bg1.77301f56.jpg


BIN=BIN
dist-tmr-20240726/dist/static/img/row-bg3.b3be7548.png


BIN=BIN
dist-tmr-20240726/dist/static/img/topBg.69ecd1e1.png


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/js/app.d0378b28.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/js/chunk-4ab5740d.fd41fff9.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/js/chunk-52ecc0ac.6e6c1552.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/js/chunk-5c4dc4a9.8801e0b1.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/js/chunk-b702d234.4563c788.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/js/chunk-elementUI.c961dc79.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-20240726/dist/static/js/chunk-libs.2172166f.js


BIN=BIN
dist-tmr-肉牛-20240726-1.zip


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/favicon.ico


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/index.html


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/css/app.f3fc20f1.css


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/css/chunk-elementUI.c1c3b808.css


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/css/chunk-libs.1664ae71.css


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/fonts/element-icons.535877f5.woff


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/fonts/element-icons.732389de.ttf


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/404.a57b6f31.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/404_cloud.0f4bc32b.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/btn2.de90fd6d.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/center_bg1.690da89a.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/center_bg2.e477a3e9.png


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 28 - 0
dist-tmr-肉牛-20240726-1/dist/static/img/iconfont.0ddaba12.svg


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/login_bg1.c50e72f6.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/login_bg2.73eb2ddc.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/logo1.4aaac8e0.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/logo1.e7208fde.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/logo2.22a9a311.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/logo_u3.46875a04.png


BIN=BIN
dist-tmr-肉牛-20240726-1/dist/static/img/topBg.d21a9f50.png


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/js/app.145b7be3.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/js/chunk-218b9b2f.443d0c85.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/js/chunk-52ecc0ac.fb113243.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/js/chunk-5c4dc4a9.b8eedd10.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/js/chunk-b702d234.640724c3.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/js/chunk-elementUI.c961dc79.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist-tmr-肉牛-20240726-1/dist/static/js/chunk-libs.c399c5fe.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/index.html


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/static/css/app.f3bb49e8.css


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/static/js/app.d0378b28.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/static/js/app.ff8699cf.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/static/js/chunk-libs.2172166f.js


+ 88 - 23
http/handle/api/grfdApi.go

@@ -47,22 +47,25 @@ func GetDorm(c *gin.Context) {
 		appG.Response(http.StatusOK, e.ERROR, "牲畜类别同步失败:"+err.Error())
 		return
 	}
-	err = GetDormBar(pastureid) // 栏舍
-	if err != nil {
-		appG.Response(http.StatusOK, e.ERROR, "栏舍同步失败:"+err.Error())
-		return
-	}
+
 	err = GetMaterial(pastureid) //饲料
 	if err != nil {
 		appG.Response(http.StatusOK, e.ERROR, "饲料同步失败:"+err.Error())
 		return
 	}
+
 	err = GetFormula(pastureid) // 配方
 	if err != nil {
 		appG.Response(http.StatusOK, e.ERROR, "配方同步失败:"+err.Error())
 		return
 	}
 
+	err = GetDormBar(pastureid) // 栏舍
+	if err != nil {
+		appG.Response(http.StatusOK, e.ERROR, "栏舍同步失败:"+err.Error())
+		return
+	}
+
 	appG.Response(http.StatusOK, e.SUCCESS, nil)
 
 }
@@ -88,6 +91,7 @@ func GetDormBar(pastureid string) error {
 			// 开启事务
 			tx := restful.Engine.NewSession()
 			err := tx.Begin()
+
 			defer func() {
 				switch {
 				case err != nil:
@@ -104,6 +108,8 @@ func GetDormBar(pastureid string) error {
 					tx.Close()
 				}
 			}()
+
+			penNameList := []string{}
 			//feedpData := feedpData[:10]
 			// 根据上次修改时间判断是否进行更新
 			valuesMap, _ := tx.SQL("SELECT ifnull(backup2,'-1')backup2,bname  FROM bar WHERE  pastureid = ?", pastureid).QueryString()
@@ -195,30 +201,53 @@ func GetDormBar(pastureid string) error {
 						return err
 					}
 					_, err = tx.Exec(`								UPDATE fpdetail fpd
-					INNER JOIN feedp fp  
+					INNER JOIN feedp fp
 					ON fpd.barid = fp.barid AND fpd.pastureid = fp.pastureid
-					SET 
+					SET
 					fpd.ccountradio =fp.ratio,
 					fpd.cowcount =fp.ccount,
 					fpd.weight = fp.feedweight*fpd.tratio/100,
-					ptsrate=fp.supplyweight/(fp.feedweight)
+					ptsrate=ifnull(fp.supplyweight/(fp.feedweight),0)
 					WHERE fp.pastureid = ? AND fp.barid =(SELECT id FROM bar WHERE pastureid=? AND bname=?)`, pastureid, pastureid, penName)
 					if err != nil {
 						return err
 					}
-					_, err = tx.Exec("call updateLPPbyFPChange((select id from bar where pastureid=? and bname=?),?)", pastureid, penName, pastureid)
-					if err != nil {
-						return err
-					}
+					// _, err = tx.Exec("call updateLPPbyFPChange((select id from bar where pastureid=? and bname=?),?)", pastureid, penName, pastureid)
+					// if err != nil {
+					// 	return err
+					// }
+
+					penNameList = append(penNameList, penName)
+					// wg.Add(1)
+
+					// values1, err := 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 b.bname  = ?  and b.pastureid = ? `, penName, pastureid).QueryString()
+					// fmt.Println(err)
+
+					// go func(values2 []map[string]string, pastureid string) {
+					// 	defer wg.Done()
+					// FpdBatchEditGrfd(pastureid, values1)
+
+					// }(values1, pastureid)
 				}
 
 			}
 
+			// wg.Wait()
 			_, err = tx.Exec("update bar set enable = 0 where pastureid = ? and enable = 2",
 				pastureid)
 			if err != nil {
 				return err
 			}
+			go barSync(penNameList, pastureid)
 		}
 
 	}
@@ -226,6 +255,25 @@ func GetDormBar(pastureid string) error {
 
 }
 
+func barSync(penNameList []string, pastureId string) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	for _, penName := range penNameList {
+		values1, err := 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 b.bname  = ?  and b.pastureid = ? `, penName, pastureId).QueryString()
+		fmt.Println(err)
+		FpdBatchEditGrfd(pastureId, values1)
+	}
+}
+
 func GetMaterial(pastureid string) error {
 	data := util.Send_Message1("{\"farmId\":4090}", setting.ServerSetting.GRFDURL+"/grfd-cow/api/tmr/getMaterial")
 	if data != nil {
@@ -496,6 +544,9 @@ func GetFormula(pastureid string) error {
 					mixNo := val.MixNo
 					allowableError := val.AllowableError
 					autosecond := val.Autosecond
+					if fodderWeight == "0" {
+						continue
+					}
 
 					tx.Exec("update feed set allowratio=if(?='',allowratio,?) where pastureid=? and fname=? ", allowableError, allowableError, pastureid, fName)
 
@@ -523,11 +574,23 @@ func GetFormula(pastureid string) error {
 						logging.Info(err)
 						return err
 					}
-					_, err = tx.Exec("call updateFPbyFTChange((select id from feedtemplet where pastureid=? and tname=? limit 1),?,(select fttypeid from feedtemplet where pastureid=? and tname=? limit 1),1)", pastureid, ftName, pastureid, pastureid, ftName)
-					if err != nil {
-						return err
-					}
-				}
+					// _, err = tx.Exec("call updateFPbyFTChange((select id from feedtemplet where pastureid=? and tname=? limit 1),?,(select fttypeid from feedtemplet where pastureid=? and tname=? limit 1),1)", pastureid, ftName, pastureid, pastureid, ftName)
+					// if err != nil {
+					// 	return err
+					// }
+				}
+
+				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.tcode = ?`, ftId).QueryString()
+				fmt.Println(ftId)
+				FpdBatchEditGrfd(pastureid, values1)
 			}
 		}
 
@@ -630,15 +693,17 @@ func AddOtherDevice() {
 			postData := make(map[string]string)
 			postData["formData"] = string(jsonStr)
 
-			err := util.PostWithFormData("POST", setting.ServerSetting.GRFDURL+"/grfd-cow/api/tmr/addOtherDevice", &postData)
+			_, err := tx.Exec(`update downloadedplan set isuse=1 where  pastureid =(SELECT column_default  FROM information_schema.COLUMNS WHERE table_name = 'recweight' 
+							AND table_schema = 'tmrwatch2' AND column_name = 'pastureid') and pid  =? and mydate = ? `, queryIdList[i]["did"], queryIdList[i]["mydate"])
+			if err != nil {
+				logging.Error("update downloadedplan err:", err)
+			}
+
+			err = util.PostWithFormData("POST", setting.ServerSetting.GRFDURL+"/grfd-cow/api/tmr/addOtherDevice", &postData)
 			if (err != nil) && (strings.Contains(err.Error(), "ID已存在") == false) {
 				logging.Error("AddOtherDevice err:", err)
 			} else {
-				_, err = tx.Exec(`update downloadedplan set isuse=1 where  pastureid =(SELECT column_default  FROM information_schema.COLUMNS WHERE table_name = 'recweight' 
-							AND table_schema = 'tmrwatch2' AND column_name = 'pastureid') and pid  =? and mydate = ? `, queryIdList[i]["did"], queryIdList[i]["mydate"])
-				if err != nil {
-					logging.Error("update downloadedplan err:", err)
-				}
+
 			}
 		}
 	}

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

@@ -36,22 +36,22 @@ func InitMqttClient() {
 		c, pubTopic = MqttClient()
 		deviceHeartbeat(c, pubTopic)
 
-		// i := 19
-		// for {
-		// 	i--
-		// 	if i == 0 {
-		// 		break
-		// 	}
-		// // now := time.Now().AddDate(0, 0, -i).Format("2006-01-02")
-		// now := "2024-05-23"
-		// fmt.Println(now, time.Now())
-		// stirPush(c, pubTopic, now)
-		// dustingPush(c, pubTopic, now)
-		// equipmentAccuracyPush(c, pubTopic, now)
-		// finishedWeightPush(c, pubTopic, now)
-		// feedtempletPush(c, pubTopic)
-		// CompletedTrainNumberPush(c, pubTopic, now)
-		// // }
+		i := 31
+		for {
+			i--
+			if i == 0 {
+				break
+			}
+			now := time.Now().AddDate(0, 0, -i).Format("2006-01-02")
+			// now := "2024-05-23"
+			fmt.Println(now, time.Now())
+			stirPush(c, pubTopic, now)
+			// dustingPush(c, pubTopic, now)
+			// equipmentAccuracyPush(c, pubTopic, now)
+			// finishedWeightPush(c, pubTopic, now)
+			// feedtempletPush(c, pubTopic)
+			// CompletedTrainNumberPush(c, pubTopic, now)
+		}
 		// now := "2024-05-01"
 		// stirPush(c, pubTopic, now)
 		// dustingPush(c, pubTopic, now)

+ 309 - 108
http/handle/api/ops.go

@@ -5506,112 +5506,7 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 
 		}
 	}
-	// for _, data := range dataList {
-	// 	fttype := -1
-	// 	if data.Ptid != -1 {
-	// 		fttype = 1
-	// 	}
-
-	// 	var fweight float64
-	// 	var lweight float64
-	// 	lpplandtl1List := make([]*lpplandtlInfo, 0)
-	// 	err := tx.SQL(`select lppland.*,lpp.maxweight from lpplan lpp
-	// 				join lpplandtl1 lppland on lpp.id = lppland.lppid  where lppland.fpdid =?
-	// 				and lppland.fttype = ? and lpp.pastureid = ?  and lpp.times  = ? order by lpp.sort desc `,
-	// 		data.Id, fttype, pastureid, data.Times).Find(&lpplandtl1List)
-	// 	if err != nil {
-	// 		tx.Rollback()
-	// 		logs.Error(err)
-	// 		return err
-	// 	}
-
-	// 	weight := data.Fweight
-	// 	// weight, _ := strconv.ParseFloat(fpd["weight"].(string), 64)
-
-	// 	var w float64
-	// 	var status int
-	// 	if data.New < data.Old {
-	// 		if weight >= 0 {
-	// 			continue
-	// 		}
-	// 		w = weight
-	// 		status = 0
-	// 	} else {
-	// 		// if weight-(data.New-data.Old) > 0 {
-	// 		// 	continue
-	// 		// }
-	// 		w = data.New - data.Old
-	// 		status = 1
-	// 	}
-	// 	for _, lppland := range lpplandtl1List {
-	// 		var lppdata lpplandtlInfo
-	// 		tx.SQL(`select sum(lweight) as lweight from lpplandtl1 lpp  where lppid = ? and  lpp.pastureid = ? `,
-	// 			lppland.Lppid, pastureid).GetFirst(&lppdata)
-	// 		if err != nil {
-	// 			tx.Rollback()
-	// 			logs.Error(err)
-	// 			return err
-	// 		}
-	// 		lweight = lppdata.Lweight
-	// 		if status == 1 {
-	// 			// if w <= lppland.Lweight {
-	// 			if lppland.Maxweight <= lweight {
-	// 				continue
-	// 			}
-	// 			if w+lweight <= lppland.Maxweight {
-	// 				lppland.Lweight += w
-	// 				lweight += w
-	// 				fweight += w
-	// 				w = 0
-	// 			} else {
-
-	// 				w = w - (lppland.Maxweight - lweight)
-	// 				n := (lppland.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
-	// 			}
-
-	// 		}
-
-	// 		_, err = tx.SQL(`update lpplandtl1  set Lweight = ?  where id = ? and pastureid = ?`, lppland.Lweight, lppland.Id, pastureid).Execute()
-	// 		if err != nil {
-	// 			tx.Rollback()
-	// 			logs.Error(err)
-	// 			return err
-	// 		}
-	// 		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=?`, fttype, fweight, fweight, fttype, fweight, fweight, pastureid, data.Id).Execute()
-	// 	if err != nil {
-	// 		tx.Rollback()
-	// 		logs.Error(err)
-	// 		return err
-	// 	}
-	// 	// if w == 0 {
-	// 	// 	break
-	// 	// }
-	// 	// }
 
-	// }
 	err = tx.Commit()
 	if err != nil {
 		logs.Error(err)
@@ -9519,12 +9414,15 @@ func EditDownloadedplanExecWeight(c *gin.Context) {
 	pid := fsions.Get("pid").ValueStr()
 	sort := fsions.Get("sort").ValueStr()
 	weight := fsions.Get("weight").ValueStr()
+	userId := fsions.Get("userId").ValueStr()
 
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 	tx.Begin()
 
-	_, err := tx.Exec(` update downloadplandtl1_exec set actualweight = ? where pid = ?  and sort = ? `, weight, pid, sort)
+	_, err := tx.Exec(` insert into downloadplandtl1_update(pid,sort,lastweight,weight,userId,createdate)
+	values(?,?,(select actualweightminus from downloadplandtl1_exec where pid = ? and sort = ?  ),?,?,now()) `,
+		pid, sort, pid, sort, weight, userId)
 	if err != nil {
 		logs.Error(err)
 		appG.Response(http.StatusOK, e.ERROR, "修改计划重量失败!"+err.Error())
@@ -9532,7 +9430,15 @@ func EditDownloadedplanExecWeight(c *gin.Context) {
 		return
 	}
 
-	_, err = tx.Exec(` update downloadplandtl1 set actualweight = lweight / (select sum(lweight) from downloadplandtl1 where pid = ? and sort = ? ) * ?  where pid = ?  and sort = ? `, pid, sort, weight, pid, sort)
+	_, err = tx.Exec(` update downloadplandtl1_exec set actualweightminus = ? where pid = ?  and sort = ? `, weight, pid, sort)
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "修改计划重量失败!"+err.Error())
+		tx.Rollback()
+		return
+	}
+
+	_, err = tx.Exec(` update downloadplandtl1 set actualweightminus = lweight / (select sum(lweight) from downloadplandtl1 where pid = ? and sort = ? ) * ?  where pid = ?  and sort = ? `, pid, sort, weight, pid, sort)
 	if err != nil {
 		logs.Error(err)
 		appG.Response(http.StatusOK, e.ERROR, "修改计划重量失败!"+err.Error())
@@ -9558,12 +9464,23 @@ func EditDownloadplandtl2Weight(c *gin.Context) {
 	pid := fsions.Get("pid").ValueStr()
 	sort := fsions.Get("sort").ValueStr()
 	weight := fsions.Get("weight").ValueStr()
+	userId := fsions.Get("userId").ValueStr()
 
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 	tx.Begin()
 
-	_, err := tx.Exec(` update downloadplandtl2 set actualweight = ? where pid = ?  and sort = ? `, weight, pid, sort)
+	_, err := tx.Exec(` insert into downloadplandtl2_update(pid,sort,lastweight,weight,userId,createdate)
+	values(?,?,(select actualweightminus from downloadplandtl2 where pid = ? and sort = ?  ),?,?,now()) `,
+		pid, sort, pid, sort, weight, userId)
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "修改计划重量失败!"+err.Error())
+		tx.Rollback()
+		return
+	}
+
+	_, err = tx.Exec(` update downloadplandtl2 set actualweightminus = ? where pid = ?  and sort = ? `, weight, pid, sort)
 	if err != nil {
 		logs.Error(err)
 		appG.Response(http.StatusOK, e.ERROR, "修改计划重量失败!"+err.Error())
@@ -9809,3 +9726,287 @@ func EditLanguage(c *gin.Context) {
 
 	appG.Response(http.StatusOK, e.SUCCESS, true)
 }
+
+func FpdBatchEditGrfd(pastureid string, barList []map[string]string) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	oldFpdList, err := tx.SQL(` select  ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,"") fweight,fpd.id,fpd.barname,fpd.weight,fpd.times,fp.ftweight,fp.supplyweight  from fpdetail fpd
+	join feedp fp on fp.barid = fpd.barid and fpd.pastureid = fp.pastureid where fpd.pastureid = ?`, pastureid).Query().List()
+	if err != nil {
+		// appG.Response(http.StatusInternalServerError, e.ERROR, false)
+		return
+	}
+
+	for _, dataexcel := range barList {
+
+		// dataexcel := make(map[string]interface{}, 0)
+		// dataexcel["barname"] = barFsions.Get("barname").ValueStr()
+		// dataexcel["ccount"] = barFsions.Get("ccount").ValueStr()
+		// dataexcel["ratio"] = barFsions.Get("ratio").ValueStr()
+		// dataexcel["ftname"] = barFsions.Get("ftname").ValueStr()
+		// dataexcel["ptsfname"] = barFsions.Get("ptsfname").ValueStr()
+		_, 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)
+			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)
+			return
+		}
+		if dataexcel["ftname"] == "" || dataexcel["ccount"] == "0" || dataexcel["ratio"] == "0" {
+			continue
+		}
+		// dataexcel["1"] = barFsions.Get("times1").ValueStr()
+		// dataexcel["2"] = barFsions.Get("times2").ValueStr()
+		// dataexcel["3"] = barFsions.Get("times3").ValueStr()
+		// dataexcel["4"] = barFsions.Get("times4").ValueStr()
+		// dataexcel["5"] = barFsions.Get("times5").ValueStr()
+		// dataexcel["6"] = barFsions.Get("times6").ValueStr()
+
+		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)
+			return
+		}
+		if !ftexist {
+			fmt.Println(dataexcel["barname"], pastureid, dataexcel["ftname"])
+			tx.SQL(` delete from lpplandtl1 where barname = ? and pastureid = ?  `, dataexcel["barname"], pastureid).Exist()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+			tx.SQL(`  update fpdetail set ptuse = 0  where  barname = ? and pastureid = ?   `, dataexcel["barname"], pastureid).Exist()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+
+		exist, err := tx.SQL(` select id from  feedp where barname = ?  and pastureid = ?  `, dataexcel["barname"], pastureid).Exist()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+		if !exist {
+			_, err := tx.SQL(` insert into  feedp(pastureid,barid,barname,ccount)values(?,(select id from bar where  bname = ? and pastureid = ? ),?,?) `,
+				pastureid, dataexcel["barname"], pastureid, dataexcel["barname"], 0).Execute()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+
+		var feedpargs []interface{}
+		upFeedpSql := `update  feedp set ccount = ? ,ratio = ? ,ccountratio = ?*(?*0.01)  `
+		feedpargs = append(feedpargs, dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"])
+		if _, ok := dataexcel["ftname"]; ok {
+			feedpargs = append(feedpargs, dataexcel["ftname"], pastureid, dataexcel["ftname"])
+			upFeedpSql += ` , ftid = (select id from feedtemplet where tname = ? and pastureid = ? ),ftname = ? `
+
+			upFeedpSql += `,ftweight = (select sum(fweight) fweight from ftdetail 
+	where  ftid = (select  id from feedtemplet  where tname = ? and pastureid = ?  )) *  (?*(?*0.01)) `
+			feedpargs = append(feedpargs, dataexcel["ftname"], pastureid, dataexcel["ccount"], dataexcel["ratio"])
+		} else {
+			upFeedpSql += ` , ftid = -1,ftname = '' ,ftweight = 0 `
+		}
+
+		if _, ok := dataexcel["ptsfname"]; ok {
+			feedpargs = append(feedpargs, dataexcel["ptsfname"], pastureid, dataexcel["ptsfname"])
+			upFeedpSql += ` , ptsfid = (select id from feedtemplet where tname = ? and pastureid = ? ),ptsfname = ? `
+
+			upFeedpSql += `,supplyweight = ifnull((select sum(fweight) fweight from ftdetail 
+	where  ftid = (select  id from feedtemplet  where tname = ? and pastureid = ?  )) *  (?*(?*0.01)),0)`
+			feedpargs = append(feedpargs, dataexcel["ptsfname"], pastureid, dataexcel["ccount"], dataexcel["ratio"])
+		} else {
+			upFeedpSql += ` , ptsfid = -1,ptsfname = '',supplyweight = 0  `
+		}
+		upFeedpSql += " where barname = ?  and pastureid = ?  "
+		feedpargs = append(feedpargs, dataexcel["barname"], pastureid)
+		_, err = tx.SQL(upFeedpSql, feedpargs...).Execute()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+
+		exist1, err := tx.SQL(` select id from  fpdetail where barname = ?  and pastureid = ? and times = 1 `, dataexcel["barname"], pastureid).Exist()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+
+		if !exist1 {
+			_, err := tx.SQL(` insert into  fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where  bname = ? and pastureid = ? ),?,1,0,0,0,-1,-1) `,
+				pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+		exist2, err := tx.SQL(` select id from  fpdetail where barname = ?  and pastureid = ? and times = 2 `, dataexcel["barname"], pastureid).Exist()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+		if !exist2 {
+			_, err = tx.SQL(` insert into  fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where  bname = ? and pastureid = ? ),?,2,0,0,0,-1,-1) `,
+				pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+
+		exist3, err := tx.SQL(` select id from  fpdetail where barname = ?  and pastureid = ? and times =3 `, dataexcel["barname"], pastureid).Exist()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+		if !exist3 {
+			_, err = tx.SQL(` insert into  fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where  bname = ? and pastureid = ? ),?,3,0,0,0,-1,-1) `,
+				pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+		exist4, err := tx.SQL(` select id from  fpdetail where barname = ?  and pastureid = ? and times = 4 `, dataexcel["barname"], pastureid).Exist()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+		if !exist4 {
+			_, err = tx.SQL(` insert into  fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where  bname = ? and pastureid = ? ),?,4,0,0,0,-1,-1) `,
+				pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+		exist5, err := tx.SQL(` select id from  fpdetail where barname = ?  and pastureid = ? and times = 5 `, dataexcel["barname"], pastureid).Exist()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+		if !exist5 {
+			_, err = tx.SQL(` insert into  fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where  bname = ? and pastureid = ? ),?,5,0,0,0,-1,-1) `,
+				pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+		exist6, err := tx.SQL(` select id from  fpdetail where barname = ?  and pastureid = ? and times = 6 `, dataexcel["barname"], pastureid).Exist()
+		if err != nil {
+			logs.Error(err)
+			return
+		}
+		if !exist6 {
+			_, err = tx.SQL(` insert into  fpdetail(pastureid,barid,barname,times,ptuse,ptsuse,ptsrate,ptsid,ptid)values(?,(select id from bar where  bname = ? and pastureid = ? ),?,6,0,0,0,-1,-1) `,
+				pastureid, dataexcel["barname"], pastureid, dataexcel["barname"]).Execute()
+			if err != nil {
+				logs.Error(err)
+				return
+			}
+		}
+
+		upFpdSql := ` update fpdetail set  tratio = ? ,weight = (? *0.01) * ((select sum(fweight) fweight from ftdetail 
+	where  ftid = (select  id from feedtemplet  where tname = ? and pastureid = ?  )) *  (?*(?*0.01))) ,cowcount = ? ,
+	ccountradio= ?,ptid= (select id from feedtemplet where tname = ? and pastureid = ? )   where barname = ?
+	and pastureid = ? and times = ?`
+		var fpdargs1 []interface{}
+		fpdargs1 = append(fpdargs1, dataexcel["1"], dataexcel["1"], dataexcel["ftname"], pastureid,
+			dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
+			dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 1)
+		_, err = tx.SQL(upFpdSql, fpdargs1...).Execute()
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+
+		var fpdargs2 []interface{}
+		fpdargs2 = append(fpdargs2, dataexcel["2"], dataexcel["2"], dataexcel["ftname"], pastureid,
+			dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
+			dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 2)
+		_, err = tx.SQL(upFpdSql, fpdargs2...).Execute()
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		var fpdargs3 []interface{}
+		fpdargs3 = append(fpdargs3, dataexcel["3"], dataexcel["3"], dataexcel["ftname"], pastureid,
+			dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
+			dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 3)
+		_, err = tx.SQL(upFpdSql, fpdargs3...).Execute()
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		var fpdargs4 []interface{}
+		fpdargs4 = append(fpdargs4, dataexcel["4"], dataexcel["4"], dataexcel["ftname"], pastureid,
+			dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
+			dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 4)
+		_, err = tx.SQL(upFpdSql, fpdargs4...).Execute()
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+
+		var fpdargs5 []interface{}
+		fpdargs5 = append(fpdargs5, dataexcel["5"], dataexcel["5"], dataexcel["ftname"], pastureid,
+			dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
+			dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 5)
+		_, err = tx.SQL(upFpdSql, fpdargs5...).Execute()
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+
+		var fpdargs6 []interface{}
+		fpdargs6 = append(fpdargs6, dataexcel["6"], dataexcel["6"], dataexcel["ftname"], pastureid,
+			dataexcel["ccount"], dataexcel["ratio"], dataexcel["ccount"], dataexcel["ratio"],
+			dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 6)
+		_, err = tx.SQL(upFpdSql, fpdargs6...).Execute()
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		// _, err = tx.SQL(`call updateLPPbyFPChange(?,( select id from feedp where barname = ?  and pastureid = ?))`, pastureid, dataexcel["barname"], pastureid).Execute()
+
+		newList, err := tx.SQL(` select  ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,"") fweight,id,ptid,weight,times from fpdetail where barname = ? and  pastureid = ? `, dataexcel["barname"], pastureid).Query().List()
+		if err != nil {
+			return
+		}
+		// oldFpdList, err := tx.SQL(` select  fpd.id,fpd.barname,fpd.weight,fpd.times,fp.ftweight,fp.supplyweight  from fpdetail fpd
+		// join feedp fp on fp.barid = fpd.barid and fpd.pastureid = fp.pastureid where fpd.pastureid = ?`, pastureid).Query().List()
+		upFpdetailList := make([]*upFpdetail, 0)
+		for _, newfpd := range newList {
+			for _, oldfpd := range oldFpdList {
+				if oldfpd["id"].(int64) == newfpd["id"].(int64) {
+					var oldweight, newweight float64
+					if oldfpd["weight"] != nil {
+						oldweight, _ = strconv.ParseFloat(oldfpd["weight"].(string), 64)
+					}
+					if newfpd["weight"] != nil {
+						newweight, _ = strconv.ParseFloat(newfpd["weight"].(string), 64)
+					}
+					fweight, _ := strconv.ParseFloat(newfpd["fweight"].(string), 64)
+					upFpdetailList = append(upFpdetailList, &upFpdetail{
+						Old:     oldweight,
+						New:     newweight,
+						Times:   newfpd["times"].(int64),
+						Ptid:    newfpd["ptid"].(int64),
+						Fweight: fweight,
+						Id:      oldfpd["id"].(int64),
+					})
+					break
+				}
+			}
+		}
+		updateFpdetailByBar(pastureid, dataexcel["barname"], upFpdetailList)
+	}
+}

+ 249 - 67
http/handle/api/scheduled.go

@@ -134,20 +134,33 @@ func CronScheduled(ctx context.Context) {
 	// manualUdData(pastureinfo)
 	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// xdmy := cron.New()
-	// err = xdmy.AddFunc("0 30 4 * * *", func() {
-	// 	// 	// 	//现代牧业sap同步
-	// 	// sap.SyncMaterialOutbound()
-	// 	// 	// 	// 光明ud同步
-	// 	// 	// 	fmt.Println(time.Now())
-	// 	gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
-	// })
-	// err = xdmy.AddFunc("0 10 17 * * *", func() {
+	// err = xdmy.AddFunc("0 30 6 * * *", func() {
+	// 	// 	// 	// 	//现代牧业sap同步
+	// 	sap.SyncMaterialOutbound()
 	// 	sap.SyncSurplusOutbound()
-	// })
+	// 	// 	// 	// 	// 光明ud同步
+	// 	// 	// 	fmt.Println(time.Now())
+	// 	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
+	// 	// })
+	// 	// err = xdmy.AddFunc("0 10 17 * * *", func() {
 
+	// })
 	// xdmy.Start()
 	// InitMqttClient()
 	// yq.YqCron()
+
+	//新希望配方同步定时任务
+
+	// duetimecst4, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
+	// duetimecst5, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
+	// spec2 := fmt.Sprintf("@every %v", duetimecst4.Sub(duetimecst5))
+
+	// xxw := cron.New()
+	// xxw.AddFunc(spec2, func() {
+	// 	XxwFeedtemplet(pastureinfo.Pastureid)
+	// })
+	// xxw.Start()
+	// XxwFeedtemplet(pastureinfo.Pastureid)
 }
 
 type ScheduledInfo struct {
@@ -1050,76 +1063,76 @@ func processAnalysisEarlyWarning(target []string, pastureId string, serviceId in
 }
 
 func manualUdData(pastureinfo *udPastureInfo) {
-	c := cron.New()
-	c.AddFunc("10 06 * * *", func() {
-		tx := restful.Engine.NewSession()
-		defer tx.Close()
-		now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
-		// now := "2023-02-22"
-		dataList, err := tx.SQL(" select id  from downloadedplan where mydate = ? ", now).QueryString()
-		if err != nil {
-			logging.Error("manualUdData-error-1:", err)
-			return
-		}
-		var idList []string
-		for _, data := range dataList {
-			idList = append(idList, data["id"])
-		}
+	// 	c := cron.New()
+	// 	c.AddFunc("10 06 * * *", func() {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	// now := "2023-02-22"
+	dataList, err := tx.SQL(" select id  from downloadedplan where mydate = ? ", now).QueryString()
+	if err != nil {
+		logging.Error("manualUdData-error-1:", err)
+		return
+	}
+	var idList []string
+	for _, data := range dataList {
+		idList = append(idList, data["id"])
+	}
 
-		upList := make([]*ScheduledUpInfo, 0)
-		up := tx.Table("scheduled_up")
+	upList := make([]*ScheduledUpInfo, 0)
+	up := tx.Table("scheduled_up")
 
-		up.Where("company = ? ", "ud")
-		up.Where("datatype in (3,4)")
-		up.Where("automatic = 1")
-		err = up.Find(&upList)
-		if err != nil {
-			logging.Error("manualUdData-error-2: ", err)
-			return
-		}
+	up.Where("company = ? ", "ud")
+	up.Where("datatype in (3,4)")
+	up.Where("automatic = 1")
+	err = up.Find(&upList)
+	if err != nil {
+		logging.Error("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)
-					}
+	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()
+			}
+			data, err := tx.SQL(item.Datasql, args...).Query().List()
+			if err != nil {
+				logging.Error("manualUdData-error-3: ", err)
+				continue
+			}
+			if len(data) > 0 {
+				databyte, err := json.Marshal(data)
 				if err != nil {
-					logging.Error("manualUdData-error-3: ", err)
+					logging.Error("manualUdData-error-4: ", err)
+					continue
+				}
+				exist, err := tx.SQL(`select * from saplog where pastureId = ? and msgtype = ? and date_format(dataDate ,'%Y-%m-%d') = ?  `,
+					pastureinfo.Pastureid, item.Datatype, now).Exist()
+				if exist {
 					continue
 				}
-				if len(data) > 0 {
-					databyte, err := json.Marshal(data)
-					if err != nil {
-						logging.Error("manualUdData-error-4: ", err)
-						continue
-					}
-					exist, err := tx.SQL(`select * from saplog where pastureId = ? and msgtype = ? and date_format(dataDate ,'%Y-%m-%d') = ?  `,
-						pastureinfo.Pastureid, item.Datatype, now).Exist()
-					if exist {
-						continue
-					}
 
-					tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
+				tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
 					values(?,?,?,?,?,now(),?,?,?)`, pastureinfo.Pastureid, string(databyte), "", "", "", item.Datatype, now, "https://wdc.unidairy.cn/copartner_uploads/")
 
-					var method string
-					UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)), method)
-				}
-				// }
+				var method string
+				UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)), method)
 			}
+			// }
 		}
-	})
-	c.Start()
+	}
+	// })
+	// c.Start()
 
 	c1 := cron.New()
 	c1.AddFunc("01 18 * * *", func() {
@@ -1835,3 +1848,172 @@ func udFeedSync(pastureinfo *udPastureInfo) error {
 	}
 	return nil
 }
+
+func XxwFeedtemplet(pastureId string) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	count, _ := tx.SQL(`select count(1) from  notice where content = 'xxwFeedtemplet'  and status = 1 `).Count()
+	fmt.Println(count)
+	// count = 1
+	// pastureId = "1725428057"
+	if count == 1 {
+
+		ftList, err := tx.SQL(` SELECT
+    IFNULL(recipeId, '') AS recipeId,
+    IFNULL(fodderId, '') AS fodderId,
+	   sum(IFNULL(autoWeight, ''))  AS autoWeight,
+    IFNULL(fodderName, '') AS fodderName,
+	  IFNULL(orderNum, '') AS orderNum,
+    IFNULL(mergerFodderId, '') AS mergerFodderId,
+    IFNULL(mergerFodderName, '') AS mergerFodderName
+FROM
+    xxw_feedtemplet  group by  recipeId,mergerFodderId`).QueryString()
+		if err != nil {
+			log.Println("XxwFeedtemplet-error-1: ", err)
+			return
+		}
+
+		dataList, err := tx.SQL(` SELECT
+    IFNULL(recipeId, '') AS recipeId,
+    IFNULL(fodderId, '') AS fodderId,
+    IFNULL(fodderName, '') AS fodderName,
+    IFNULL(autoWeight, '') AS autoWeight,
+    IFNULL(orderNum, '') AS orderNum,
+    IFNULL(mergerFodderId, '') AS mergerFodderId,
+    IFNULL(mergerFodderName, '') AS mergerFodderName
+FROM
+    xxw_feedtemplet `).QueryString()
+		if err != nil {
+			log.Println("XxwFeedtemplet-error-1: ", err)
+			return
+		}
+
+		// for _, item := range ftList {
+		tx.Exec(` delete  from ftdetail `)
+		// }
+
+		for _, item := range ftList {
+			ids, err := setting.SnowIds.NextId()
+			if err != nil {
+				ids = time.Now().UnixNano()
+				logging.Info("create SnowIds err", err)
+			}
+
+			if item["mergerFodderId"] == "" {
+				_, err = tx.Exec("insert into feedtemplet(id,pastureid,ccid,tcode,tname,fttypeid,fttype,xxwTempletCode)  "+
+					"values(?,?,(select id from cowclass where pastureid = ? limit 1),?,?,1,'饲喂配方',?) "+
+					" ON DUPLICATE KEY UPDATE owner ='丰顿下发' ", ids, pastureId, pastureId, item["recipeId"], item["recipeId"], item["recipeId"])
+				if err != nil {
+					log.Println("XxwFeedtemplet-error-2: ", err)
+					return
+				}
+			}
+			// if item["mergerFodderId"] == "" {
+			// 	_, err = tx.Exec("insert into feedtemplet(id,pastureid,ccid,tcode,tname,fttypeid,fttype,xxwTempletCode)  "+
+			// 		"values(?,?,(select id from cowclass where pastureid = ? limit 1),?,?,1,'饲喂配方',?) "+
+			// 		" ON DUPLICATE KEY UPDATE owner ='丰顿下发' ", ids, pastureId, pastureId, item["recipeId"], item["recipeId"], item["recipeId"])
+			// 	if err != nil {
+			// 		log.Println("XxwFeedtemplet-error-2: ", err)
+			// 		return
+			// 	}
+			// } else {
+			// 	_, err = tx.Exec(`insert into feedtemplet(id,tcode,pastureid,ccid,tname,fttypeid,fttype,xxwTempletCode)
+			// 		values(?,	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"))),?,(select id from cowclass where pastureid = ? limit 1),?,2,'预混配方',?)
+			// 		 ON DUPLICATE KEY UPDATE owner ='丰顿下发' `, ids, pastureId,pastureId,pastureId, pastureId,
+			// 		item["mergerFodderName"]+item["recipeId"], item["mergerFodderId"])
+			// 	if err != nil {
+			// 		log.Println("XxwFeedtemplet-error-3: ", err)
+			// 		return
+			// 	}
+
+			// 	tx.Exec(` update feedtemplet f set ccname = (select classname from cowclass  where id = f.ccid ) where xxwTempletCode = ? `, item["mergerFodderId"])
+
+			// 	ids, err := setting.SnowIds.NextId()
+			// 	if err != nil {
+			// 		ids = time.Now().UnixNano()
+			// 		logging.Info("create SnowIds err", err)
+			// 	}
+			// 	_, err = tx.Exec(`insert into ftdetail(id,pastureid,ftid,fid,fname,fweight,sort,autosecond,autosecondname,feedgroup,preftid,version)
+			//  values(?,?,(select id from feedtemplet where pastureid=? and xxwTempletCode=? limit 1),
+			// 	(select id from feedtemplet where pastureid=? and xxwTempletCode=? limit 1)   ,?,?,?,0,'',?,
+			// 	(select id from feedtemplet where pastureid=? and xxwTempletCode =? limit 1),
+			// 	(select version from feedtemplet where pastureid=? and xxwTempletCode=? limit 1)) `,
+			// 		ids, pastureId, pastureId, item["recipeId"], pastureId, item["mergerFodderId"], item["mergerFodderName"]+item["recipeId"], item["autoWeight"],
+			// 		item["orderNum"], item["mergerFodderName"], pastureId, item["mergerFodderId"], pastureId, item["recipeId"])
+			// 	if err != nil {
+			// 		log.Println("XxwFeedtemplet-error-4: ", err)
+			// 		return
+			// 	}
+
+			// }
+		}
+
+		for _, item := range dataList {
+			ids, err := setting.SnowIds.NextId()
+			if err != nil {
+				ids = time.Now().UnixNano()
+				logging.Info("create SnowIds err", err)
+			}
+
+			if item["mergerFodderId"] == "" {
+				_, err = tx.Exec("insert into ftdetail(id,pastureid,ftid,fid,fname,fweight,sort,autosecond,autosecondname,feedgroup,version)  "+
+					" values(?,?,(select id from feedtemplet where pastureid=? and xxwTempletCode=? limit 1),"+
+					" (select id from feed where pastureid=? and xxwFeedCode=? limit 1)   ,?,?,?,0,'',?,(select version from feedtemplet where pastureid=? and xxwTempletCode=? limit 1)) ",
+					ids, pastureId, pastureId, item["recipeId"], pastureId, item["fodderId"], item["fodderName"], item["autoWeight"],
+					item["orderNum"], item["fodderName"], pastureId, item["recipeId"])
+				if err != nil {
+					log.Println(item)
+					log.Println("XxwFeedtemplet-error-5: ", err)
+					return
+				}
+
+			} else {
+				// _, err = tx.Exec("insert into ftdetail(id,pastureid,ftid,fid,fname,fweight,sort,autosecond,autosecondname,feedgroup,version)  "+
+				// 	" values(?,?,(select id from feedtemplet where pastureid=? and xxwTempletCode=? limit 1),"+
+				// 	" (select id from feed where pastureid=? and xxwFeedCode=? limit 1)   ,?,?,?,0,'',?,(select version from feedtemplet where pastureid=? and xxwTempletCode=? limit 1))   ON DUPLICATE KEY UPDATE pastureid = ?  ",
+				// 	ids, pastureId, pastureId, item["mergerFodderId"], pastureId, item["fodderId"], item["fodderName"], item["autoWeight"],
+				// 	item["orderNum"], item["fodderName"], pastureId, item["mergerFodderId"], pastureId)
+				// if err != nil {
+				// 	log.Println("XxwFeedtemplet-error-6: ", err)
+				// 	return
+				// }
+				_, err = tx.Exec("insert into ftdetail(id,pastureid,ftid,fid,fname,fweight,sort,autosecond,autosecondname,feedgroup,version)  "+
+					" values(?,?,(select id from feedtemplet where pastureid=? and xxwTempletCode=? limit 1),"+
+					" (select id from feed where pastureid=? and xxwFeedCode=? limit 1)   ,?,?,?,0,'',?,(select version from feedtemplet where pastureid=? and xxwTempletCode=? limit 1)) ",
+					ids, pastureId, pastureId, item["recipeId"], pastureId, item["fodderId"], item["fodderName"], item["autoWeight"],
+					item["orderNum"], item["mergerFodderName"], pastureId, item["recipeId"])
+				if err != nil {
+					log.Println("XxwFeedtemplet-error-5: ", err)
+					return
+				}
+			}
+
+		}
+
+		feedingList, err := tx.SQL(` SELECT
+    IFNULL(recipeId, '') AS recipeId
+	
+FROM
+    xxw_feedtemplet  group by  recipeId`).QueryString()
+		if err != nil {
+			log.Println("XxwFeedtemplet-error-1: ", err)
+			return
+		}
+
+		tx.Exec(` UPDATE notice SET status = 0 WHERE content = 'xxwFeedtemplet' `)
+		for _, feeding := range feedingList {
+			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.xxwTempletCode = ?`, feeding["recipeId"]).QueryString()
+			fmt.Println(feeding["recipeId"])
+			FpdBatchEditGrfd(pastureId, values1)
+		}
+	}
+}

+ 4 - 4
http/handle/api/spillage.go

@@ -800,12 +800,12 @@ func GetSpillage(c *gin.Context) {
 		ftDetailList, err := tx.SQL(`SELECT TRIM(id) id,times,tratio,ROUND(ifnull(ptsrate,0)*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,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
 	WHERE fpdetail.pastureid = ?  AND times=? AND  ptsuse< ROUND(ifnull(ptsrate,0)*weight,2)  
-	and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid) is not null
+	and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid and enable = 1) is not null
 	UNION
 	SELECT TRIM(id) id,times,tratio,ROUND((1-ifnull(ptsrate,0))*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,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
 	WHERE fpdetail.pastureid = ?  AND times=? AND ptuse<ROUND((1-ifnull(ptsrate,0))*weight,2)
-	and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid) is not null
+	and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid and enable = 1) is not null
 	ORDER BY  barid`, pastureid, times, pastureid, times).Query().List()
 		if err != nil {
 			log.Println("GetSpillage-error-2: ", err)
@@ -1364,12 +1364,12 @@ GROUP BY fpd.ptsid`
 		ftDetailList, err := tx.SQL(`SELECT TRIM(id) id,times,tratio,ROUND(ifnull(ptsrate,0)*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,cowcount,ccountradio, 1 isfill  FROM fpdetaildate fpdetail
 		WHERE fpdetail.pastureid = ?  AND times=? AND  ptsuse< ROUND(ifnull(ptsrate,0)*weight,2) and fpdetail.date = ?
-		and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid ) is not null
+		and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid and enable = 1) is not null
 		UNION
 		SELECT TRIM(id) id,times,tratio,ROUND((1-ifnull(ptsrate,0))*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,cowcount,ccountradio, 0 isfill  FROM fpdetaildate fpdetail
 		WHERE fpdetail.pastureid = ? AND times=? AND ptuse<ROUND((1-ifnull(ptsrate,0))*weight,2) and fpdetail.date = ?
-		and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid) is not null
+		and (select id from bar where id = fpdetail.barid and pastureid =  fpdetail.pastureid and enable = 1) is not null
 		ORDER BY  barid`, pastureid, times, date, pastureid, times, date).Query().List()
 		if err != nil {
 			log.Println("GetSpillageDay-error-2: ", err)

+ 7 - 0
http/handle/api/upload.go

@@ -812,6 +812,9 @@ func GetBarfeedremainExcel(c *gin.Context) {
 	cell.SetStyle(style1)
 	cell = row.AddCell()
 
+	cell.SetValue("转投栏舍")
+	cell.SetStyle(style)
+	cell = row.AddCell()
 	// cell.SetValue("")
 	// cell.SetStyle(style1)
 	// cell = row.AddCell()
@@ -867,6 +870,10 @@ func GetBarfeedremainExcel(c *gin.Context) {
 			cell.SetStyle(style1)
 			cell = row.AddCell()
 
+			// cell.SetValue("")
+			// cell.SetStyle(style1)
+			// cell = row.AddCell()
+
 			cell.SetValue(`注:1,红色为必填项,以上为示例数据,导入时请及时删除!
 			2,由于excel兼容性的问题,收集时间/原剩料所属时间,提交时会出现兼容性错误,需要在收集时间/原剩料所属时间的表头右击鼠标,设置单元格格式 选择“文本”格式 `)
 			cell.SetStyle(style1)

+ 139 - 20
http/handle/sap/sap.go

@@ -153,13 +153,13 @@ func materialOutbound(pastureId, date string) error {
 	dataList, err := tx.SQL(`			SELECT 
 	tem.sort ZEILE,
 	tem.feedname MAKTX,
-	ifnull(ROUND(if(tem.lweight<0,0,tem.lweight),(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid =? )),0)lweight,
-	ifnull(ROUND(tem.actualweightminus,(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid = ?)),0) MENGE
+	sum(ifnull(ROUND(if(tem.lweight<0,0,tem.lweight),(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid =? )),0))lweight,
+	sum(ifnull(ROUND(tem.actualweightminus,(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid = ?)),0)) MENGE
 	,tem.bname CHSTX,tem.sapcode CHSNO,tem.cattle FCWTS,tem.MATNR,tem.sapGoods LGORT
 
 	 FROM (
 	(SELECT 
-	d2.type,
+	d2.type,d2.fbarid,
 	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
 	SUM(
 	  d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
@@ -172,9 +172,9 @@ func materialOutbound(pastureId, date string) error {
 	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid and ftd2.date= ftp.date )),
 		
 		 d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
-	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid ))
+	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid  and ftd2.date= ftp.date ))
 		)
-	 )actualweightminus,b.sort as d2sort,b.bname,b.sapcode, b.cattlecode ,f.sapCode MATNR,f.sapGoods ,(select cattle from feedtemplet where id = d.tempid) cattle
+	 )actualweightminus,b.sort as d2sort,b.bname,b.sapcode, b.cattlecode ,f.c MATNR,f.sapGoods ,(select cattle from feedtemplet where id = d.tempid) cattle
 	 
 	 FROM 
 	downloadedplan d
@@ -196,7 +196,7 @@ func materialOutbound(pastureId, date string) error {
 	UNION
 	
 		(SELECT 
-	d2.type,
+	d2.type,d2.fbarid,
 	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
 	SUM(
 	  d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
@@ -206,7 +206,7 @@ func materialOutbound(pastureId, date string) error {
 		  SUM(
  if ( (SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)  > 0 ,
   d2.actualweightminus/(SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
-  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid )),
+  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.date = d1.date AND ftd2.version = ftd1.version and ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid )),
 	
 	 d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
   d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE  ftd2.date = d1.date AND ftd2.version = ftd1.version and ftd1.id = ftd2.ftid  ))
@@ -232,7 +232,7 @@ left join feed f on f.id = ftd.fid
 	HAVING d2.type = 0  order by b.sort,d2.fbarid)
 	
 	) tem
-	
+    GROUP BY tem.fbarid,tem.feedname 
 	ORDER BY tem.d2sort,tem.feedname   `, pastureId, pastureId, pastureId, date, pastureId, date).Query().List()
 	if err != nil {
 		logs.Error(err)
@@ -241,7 +241,7 @@ left join feed f on f.id = ftd.fid
 
 	data := `{
 		"DEST": {
-		  "DEST_ID": "DFEED",
+		  "DEST_ID": "TMRWATCH",
 		  "BUSS_TP": "MM016"
 		},
 		"DATA": {
@@ -262,14 +262,15 @@ left join feed f on f.id = ftd.fid
 
 func postPush(url, data string, msgtype int, tx *xorm.Session, pastureId string) (interface{}, bool) {
 	var jsonStr = []byte(data)
+	fmt.Println(string(jsonStr))
 	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
 	if err != nil {
 		logs.Error(err)
 		// return nil
 	}
 
-	// req.SetBasicAuth("zinf_TMR", "zinf_TMR@1234")  测试线密码
-	req.SetBasicAuth("zinf_TMR", "$C2Cj$\\Uv#")
+	req.SetBasicAuth("zinf_TMR", "zinf_TMR@1234") //测试线密码
+	// req.SetBasicAuth("zinf_TMR", "$C2Cj$\\Uv#")
 	req.Header.Set("Content-Type", "application/json")
 	client := &http.Client{}
 	resp, err := client.Do(req)
@@ -283,7 +284,7 @@ func postPush(url, data string, msgtype int, tx *xorm.Session, pastureId string)
 	var respData map[string]interface{}
 	tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
 	values(?,?,?,?,?,now(),?,now(),?)`, pastureId, data, string(body), "", "", msgtype, url)
-
+	fmt.Println(string(body))
 	err = json.Unmarshal(body, &respData)
 	if err != nil {
 		logs.Error(err)
@@ -376,17 +377,17 @@ func surplusOutbound(pastureId, date string) error {
 	}
 	now, _ := time.ParseInLocation("2006-01-02", date, time.Local)
 
-	dataList, err := tx.SQL(`SELECT 
+	dataList, err := tx.SQL(` SELECT 
 	tem.sort ZEILE,
 	tem.feedname MAKTX,
-	ifnull(ROUND(if(tem.lweight<0,0,tem.lweight),(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid =? )),0)lweight,
-	ifnull(ROUND(tem.actualweightminus,(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid = ?)),0) MENGE
+	sum(ifnull(ROUND(if(tem.lweight<0,0,tem.lweight),(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid =? )),0))lweight,
+	sum(ifnull(ROUND(tem.actualweightminus,(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid = ?)),0)) MENGE
 	,tem.bname CHSTX,tem.sapcode CHSNO,tem.cattle FCWTS,(select  inforvalue from sysopt  where inforname="excess" and pastureid = ?) MATNR,tem.sapGoods LGORT,
 	? WERKS , ? BUDAT
 
 	 FROM (
 	(SELECT 
-	d2.type,
+	d2.type,d2.fbarid,
 	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
 	SUM(
 	  d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
@@ -399,7 +400,7 @@ func surplusOutbound(pastureId, date string) error {
 	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid and ftd2.date= ftp.date )),
 		
 		 d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
-	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid ))
+	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid and ftd2.date= ftp.date ))
 		)
 	 )actualweightminus,b.sort as d2sort,b.bname,b.sapcode, b.cattlecode ,f.sapGoods ,(select cattle from feedtemplet where id = d.tempid) cattle
 	 
@@ -423,7 +424,7 @@ func surplusOutbound(pastureId, date string) error {
 	UNION
 	
 		(SELECT 
-	d2.type,
+	d2.type,d2.fbarid,
 	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
 	SUM(
 	  d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
@@ -459,7 +460,8 @@ left join feed f on f.id = ftd.fid
 	HAVING d2.type = 0  order by b.sort,d2.fbarid)
 	
 	) tem
-	ORDER BY tem.d2sort,tem.feedname     `, pastureId, pastureId, pastureId, pastureinfo.Werks, now.Format("20060102"), pastureId, date, pastureId, date).Query().List()
+	 	GROUP BY tem.fbarid,tem.feedname 
+	ORDER BY tem.d2sort,tem.feedname  `, pastureId, pastureId, pastureId, pastureinfo.Werks, now.Format("20060102"), pastureId, date, pastureId, date).Query().List()
 	if err != nil {
 		logs.Error(err)
 		return err
@@ -467,7 +469,7 @@ left join feed f on f.id = ftd.fid
 
 	data := `{
 		"DEST": {
-		  "DEST_ID": "DFEED",
+		  "DEST_ID": "TMRWATCH",
 		  "BUSS_TP": "MM016"
 		},
 		"DATA":  %s
@@ -480,3 +482,120 @@ left join feed f on f.id = ftd.fid
 	postPush(url, data, 0, tx, pastureId)
 	return nil
 }
+
+//剩料使用
+func Wasteuse(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	pastureId := fsion.Get("pastureId").ValueStr()
+	date := fsion.Get("date").ValueStr()
+
+	wasteuse(pastureId, date)
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}
+
+func LeftoverEntry(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	pastureId := fsion.Get("pastureId").ValueStr()
+	date := fsion.Get("date").ValueStr()
+
+	leftoverEntry(pastureId, date)
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}
+
+//剩料使用
+func wasteuse(pastureId, date string) error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	pastureinfo := new(udPastureInfo)
+	err := tx.SQL(`select * from pasture where pastureid = ?`, pastureId).GetFirst(pastureinfo).Error
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+	now, _ := time.ParseInLocation("2006-01-02", date, time.Local)
+
+	dataList, err := tx.SQL(`select  ftd.cattle FCWTS,
+b.sapCode CHSNO ,b.bname CHSTX, '11.01.01.01.000094' MATNR,'系统剩料' MAKTX,w.weight MENGE,'' MEINS
+from  wasteuse w join feedtemplet ftd on ftd.id = w.ftid   join bar b on b.id = w.barid 
+where w.date = ? and  b.pastureid = ? `, date, pastureId).Query().List()
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+
+	data := `{
+		"DEST": {
+		  "DEST_ID": "TMRWATCH",
+		  "BUSS_TP": "MM016"
+		},
+		"DATA": {
+		  "BUDAT": "%s",
+		  "WERKS": "%s",
+		  "ITEMS": %s
+		}
+	  }`
+
+	for i, data := range dataList {
+		data["ZEILE"] = i
+	}
+	databyte, _ := json.Marshal(dataList)
+
+	// now, _ := time.ParseInLocation("2006-01-02", date, time.Local)
+
+	data = fmt.Sprintf(data, now.Format("20060102"), pastureinfo.Werks, string(databyte))
+	url := "http://192.168.61.117/SAPQ0/Feed/MM016/StockOut"
+	postPush(url, data, 0, tx, pastureId)
+
+	return nil
+}
+
+func leftoverEntry(pastureId, date string) error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	pastureinfo := new(udPastureInfo)
+	err := tx.SQL(`select * from pasture where pastureid = ?`, pastureId).GetFirst(pastureinfo).Error
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+	// now, _ := time.ParseInLocation("2006-01-02", date, time.Local)
+
+	dataList, err := tx.SQL(`  SELECT
+	p.werks WERKS,
+	DATE_FORMAT( b.remaindate, '%Y%m%d' ) BUDAT,
+	ft.cattle FCWTS,
+	bar.sapCode CHSNO,
+	b.barname CHSTX,
+	 '11.01.01.01.000094' MATNR,
+	'系统剩料' MAKTX,
+  b.remain  MENGE ,"KG" MEINS,ztbar.sapCode ZCHSNO,ztbar.bname ZCHSTX
+FROM
+	barfeedremain b
+	JOIN pasture p ON b.pastureid = p.pastureid
+	JOIN feedpdate fp ON fp.date = b.remaindate 
+	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()
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+
+	for i, data := range dataList {
+		data["ZEILE"] = i
+	}
+
+	data := `{"DEST": {"DEST_ID": "TMRWATCH","BUSS_TP": "MM032"},"DATA": %s} `
+	databyte, _ := json.Marshal(dataList)
+
+	data = fmt.Sprintf(data, string(databyte))
+	url := "http://192.168.61.117/SAPQ0/Feed/MM032/LeftoverEntry"
+	postPush(url, data, 0, tx, pastureId)
+	return nil
+}

+ 2 - 2
http/handle/yq/yq.go

@@ -37,8 +37,8 @@ func YqCron() {
 		return
 	}
 
-	token := getToken()
-	syncBar(token, pastureinfo.Pastureid, pastureinfo.Werks)
+	// token := getToken()
+	// syncBar(token, pastureinfo.Pastureid, pastureinfo.Werks)
 	c := cron.New()
 	c.AddFunc("0 0 1 * * *", func() {
 		token := getToken()

+ 3 - 0
http/routers/app_api.go

@@ -249,6 +249,9 @@ 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/leftoverEntry", sap.LeftoverEntry)
+
 		}
 
 		//不需要登录验证的接口

+ 18 - 1
update.sql

@@ -372,4 +372,21 @@ INSERT INTO sysopt (`id`, `pastureid`, `inforname`, `inforvalue`)
 
 INSERT INTO sysopt (`id`, `pastureid`, `inforname`, `inforvalue`)
  VALUES (3029240269385600832,(select column_default  as pastureid from    information_schema.COLUMNS
-	WHERE table_name = 'recweight' AND table_schema = 'tmrwatch2' AND column_name = 'pastureid'), 'YynSync', '1');
+	WHERE table_name = 'recweight' AND table_schema = 'tmrwatch2' AND column_name = 'pastureid'), 'YynSync', '1');
+
+
+  ALTER TABLE `tmrwatch2`.`cowclass` 
+ALTER TABLE `tmrwatch2`.`cowclass` 
+ADD COLUMN `xxwcode` varchar(255) NULL AFTER `group_id`;
+DROP INDEX `cowclass_name`,
+ADD UNIQUE INDEX `cowclass_name`(`pastureid` ASC, `classname` ASC, `xxwcode`) USING BTREE
+
+
+alter table feedp add COLUMN   `xxwBarCode` varchar(255) DEFAULT NULL;
+
+
+ALTER TABLE `barfeedremain` 
+ADD COLUMN `useinbarid` bigint NULL COMMENT '转投栏舍' AFTER `dry`;
+
+ALTER TABLE `barfeedremain` 
+ADD COLUMN `useinbar` varchar(50) NULL AFTER `useinbarid`;

BIN=BIN
uploads.zip


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio