Parcourir la source

轨迹数据推送

baishaojie il y a 1 an
Parent
commit
33a82455f5
43 fichiers modifiés avec 719 ajouts et 126 suppressions
  1. BIN
      TMRWatchComm
  2. BIN
      TMRWatchComm.zip
  3. BIN
      __debug_bin.exe
  4. 14 9
      conf/app.ini
  5. BIN
      dist-tmr2024-03-27-02.zip
  6. BIN
      dist-tmr2024-03-27-02/dist/favicon.ico
  7. 0 0
      dist-tmr2024-03-27-02/dist/index.html
  8. 0 0
      dist-tmr2024-03-27-02/dist/static/css/app.d2391c4a.css
  9. 0 0
      dist-tmr2024-03-27-02/dist/static/css/chunk-elementUI.c1c3b808.css
  10. 0 0
      dist-tmr2024-03-27-02/dist/static/css/chunk-libs.1664ae71.css
  11. BIN
      dist-tmr2024-03-27-02/dist/static/fonts/element-icons.535877f5.woff
  12. BIN
      dist-tmr2024-03-27-02/dist/static/fonts/element-icons.732389de.ttf
  13. BIN
      dist-tmr2024-03-27-02/dist/static/img/404.a57b6f31.png
  14. BIN
      dist-tmr2024-03-27-02/dist/static/img/404_cloud.0f4bc32b.png
  15. 28 0
      dist-tmr2024-03-27-02/dist/static/img/iconfont.7d9f8392.svg
  16. BIN
      dist-tmr2024-03-27-02/dist/static/img/logo.afed751a.png
  17. BIN
      dist-tmr2024-03-27-02/dist/static/img/logo1.0121925c.png
  18. BIN
      dist-tmr2024-03-27-02/dist/static/img/logo_u3.3c77f543.png
  19. BIN
      dist-tmr2024-03-27-02/dist/static/img/nlogin-bg1.77301f56.jpg
  20. BIN
      dist-tmr2024-03-27-02/dist/static/img/row-bg3.b3be7548.png
  21. BIN
      dist-tmr2024-03-27-02/dist/static/img/topBg.69ecd1e1.png
  22. 0 0
      dist-tmr2024-03-27-02/dist/static/js/app.b89e761e.js
  23. 0 0
      dist-tmr2024-03-27-02/dist/static/js/chunk-218b9b2f.443d0c85.js
  24. 0 0
      dist-tmr2024-03-27-02/dist/static/js/chunk-52ecc0ac.ba542cb9.js
  25. 0 0
      dist-tmr2024-03-27-02/dist/static/js/chunk-5c4dc4a9.9bfbd7f4.js
  26. 0 0
      dist-tmr2024-03-27-02/dist/static/js/chunk-b702d234.fadfa57f.js
  27. 0 0
      dist-tmr2024-03-27-02/dist/static/js/chunk-elementUI.c961dc79.js
  28. 0 0
      dist-tmr2024-03-27-02/dist/static/js/chunk-libs.95bc46fa.js
  29. 0 0
      dist/index.html
  30. 0 0
      dist/static/css/app.d2391c4a.css
  31. 0 0
      dist/static/js/app.b89e761e.js
  32. 0 0
      dist/static/js/app.efd6406b.js
  33. 0 0
      dist/static/js/chunk-libs.95bc46fa.js
  34. 6 5
      http/handle/api/chart.go
  35. 6 0
      http/handle/api/grfdApi.go
  36. 81 60
      http/handle/api/mqtt.go
  37. 353 16
      http/handle/api/ops.go
  38. 1 1
      http/handle/api/pusher.go
  39. 153 3
      http/handle/api/report.go
  40. 45 13
      http/handle/api/scheduled.go
  41. 24 19
      http/handle/gm/udservice.go
  42. 8 0
      http/routers/app_api.go
  43. BIN
      uploads.zip

BIN
TMRWatchComm


BIN
TMRWatchComm.zip


BIN
__debug_bin.exe


+ 14 - 9
conf/app.ini

@@ -73,7 +73,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo 
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306 
-Name = sfmc1
+Name = sfmc
 TablePrefix =
 
 ShowXormlog = false
@@ -83,7 +83,7 @@ CacheApiSql = false
 
 [sqlserver]
 #Host = "sqlserver://sa:Password@@localhost?database=SysData&connection+timeout=30"
-##张北乐源
+##张北乐源 
 Host = 
 User = 
 Password = 
@@ -91,11 +91,12 @@ Name =
 
 
 [yyn]
-FarmId = ""
-ProductKey = ""
-DeviceName = ""
-DeviceSecret = ""
-HeartBeat = ""
+FarmId = "1830004623"
+ProductKey = "k03txxLKFae"
+DeviceName = "4623_p_breed"
+DeviceSecret = "d06ababb2b10ba25bca3041e35ac604d"
+HeartBeat = "18300046234623_p_breed"
+
 
 [comm]
 PortName =
@@ -106,6 +107,10 @@ ParityMode = 0    #PARITY_NONE  0	PARITY_ODD  1	PARITY_EVEN  2
 InterCharacterTimeout = 100
 MinimumReadSize = 0
 
-
-
+; product_key =k03txxLKFae device_name =4623_p_breed 
+; device_secret =d06ababb2b10ba25bca3041e35ac604d
+;  host = iot-010a5xth.mqtt.iothub.aliyuncs.com 
+;  farmId=1830004623 
+;  heartBeat=18300046234623_p_breed 
+;  TopicName=/k03txxLKFae/4623_p_breed/user/heatwatch/tmrBreed/post
 

BIN
dist-tmr2024-03-27-02.zip


BIN
dist-tmr2024-03-27-02/dist/favicon.ico


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/index.html


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/css/app.d2391c4a.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/css/chunk-elementUI.c1c3b808.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/css/chunk-libs.1664ae71.css


BIN
dist-tmr2024-03-27-02/dist/static/fonts/element-icons.535877f5.woff


BIN
dist-tmr2024-03-27-02/dist/static/fonts/element-icons.732389de.ttf


BIN
dist-tmr2024-03-27-02/dist/static/img/404.a57b6f31.png


BIN
dist-tmr2024-03-27-02/dist/static/img/404_cloud.0f4bc32b.png


Fichier diff supprimé car celui-ci est trop grand
+ 28 - 0
dist-tmr2024-03-27-02/dist/static/img/iconfont.7d9f8392.svg


BIN
dist-tmr2024-03-27-02/dist/static/img/logo.afed751a.png


BIN
dist-tmr2024-03-27-02/dist/static/img/logo1.0121925c.png


BIN
dist-tmr2024-03-27-02/dist/static/img/logo_u3.3c77f543.png


BIN
dist-tmr2024-03-27-02/dist/static/img/nlogin-bg1.77301f56.jpg


BIN
dist-tmr2024-03-27-02/dist/static/img/row-bg3.b3be7548.png


BIN
dist-tmr2024-03-27-02/dist/static/img/topBg.69ecd1e1.png


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/js/app.b89e761e.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/js/chunk-218b9b2f.443d0c85.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/js/chunk-52ecc0ac.ba542cb9.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/js/chunk-5c4dc4a9.9bfbd7f4.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/js/chunk-b702d234.fadfa57f.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/js/chunk-elementUI.c961dc79.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist-tmr2024-03-27-02/dist/static/js/chunk-libs.95bc46fa.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist/index.html


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist/static/css/app.d2391c4a.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist/static/js/app.b89e761e.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist/static/js/app.efd6406b.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist/static/js/chunk-libs.95bc46fa.js


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

@@ -1526,13 +1526,14 @@ func GetAccuracyAllLS(c *gin.Context) {
 	startDate := parammaps.Get("startTime").ValueStr()
 	endDate := parammaps.Get("stopTime").ValueStr()
 	pastureId := parammaps.Get("pastureid").ValueStr()
+	ftId := parammaps.Get("ftId").ValueStr()
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
 	var sqlStr = `SELECT concat(de.fname,'-',d.times,'班') 名称,de.fname,%s 日期, 
 	IFNULL(DATE_FORMAT(de.intime,'%%H.%%i'),'')   准确率  --  撒料时间
 	FROM downloadedplan d right JOIN downloadplandtl2 de ON  d.pastureid = de.pastureid and d.id=de.pid 
-	WHERE d.mydate  BETWEEN ? AND ?  AND  d.pastureid=?  AND d.lpplantype  IN (0,1,2,5) AND de.type = 0
+	WHERE d.mydate  BETWEEN ? AND ?  AND  d.pastureid=?  AND d.lpplantype  IN (0,1,2,5) AND de.type = 0    and (? ='' or   FIND_IN_SET(d.tempid ,?))
 	-- 加上就是不含取消操作
 	-- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 )) 
 	GROUP BY d.times,日期,de.fname
@@ -1544,7 +1545,7 @@ func GetAccuracyAllLS(c *gin.Context) {
 		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m-%d') ")
 
 		// sqlStr += "  GROUP BY 日期 "
-		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
+		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, ftId, ftId).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -1565,7 +1566,7 @@ func GetAccuracyAllLS(c *gin.Context) {
 		sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
 
 		// sqlStr += "  GROUP BY 日期 "
-		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
+		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, ftId, ftId).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -1581,7 +1582,7 @@ func GetAccuracyAllLS(c *gin.Context) {
 		// end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
 		// endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
 
-		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
+		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, ftId, ftId).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -1589,7 +1590,7 @@ func GetAccuracyAllLS(c *gin.Context) {
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	if status == "1" {
+	if status == "0" {
 		queryData, _ := getAccuracy(data, "2006-01-02")
 		appG.Response(http.StatusOK, e.SUCCESS, queryData)
 	} else {

+ 6 - 0
http/handle/api/grfdApi.go

@@ -147,6 +147,12 @@ func GetDormBar(pastureid string) error {
 				}
 				//首先将所有栏舍禁用
 
+				_, err = tx.Exec("update bar set bname = ? where bcode = ?",
+					penName, penId)
+				if err != nil {
+					return err
+				}
+
 				_, err = tx.Exec("insert into bar(id,pastureid,bcode,backup1,backup2,bname,enable) "+
 					" values(?,?,?,?,?,?,1)"+
 					" ON DUPLICATE KEY UPDATE bcode=?,backup2=?,enable=if(enable = 2,0,1)",

+ 81 - 60
http/handle/api/mqtt.go

@@ -19,6 +19,7 @@ import (
 
 	"github.com/astaxie/beego/logs"
 	MQTT "github.com/eclipse/paho.mqtt.golang"
+	mqtt "github.com/eclipse/paho.mqtt.golang"
 	"github.com/robfig/cron"
 )
 
@@ -27,16 +28,16 @@ func InitMqttClient() {
 		c, pubTopic := MqttClient()
 		deviceHeartbeat(c, pubTopic)
 
-		mqttCron := cron.New()
-		mqttCron.AddFunc("10 06 * * *", func() {
-			feedtempletPush(c, pubTopic)
-			stirPush(c, pubTopic)
-			dustingPush(c, pubTopic)
-			equipmentAccuracyPush(c, pubTopic)
-			finishedWeightPush(c, pubTopic)
-			CompletedTrainNumberPush(c, pubTopic)
-		})
-		mqttCron.Start()
+		// mqttCron := cron.New()
+		// mqttCron.AddFunc("10 06 * * *", func() {
+		// feedtempletPush(c, pubTopic)
+		stirPush(c, pubTopic)
+		dustingPush(c, pubTopic)
+		// equipmentAccuracyPush(c, pubTopic)
+		// finishedWeightPush(c, pubTopic)
+		// CompletedTrainNumberPush(c, pubTopic)
+		// })
+		// mqttCron.Start()
 	}
 
 }
@@ -53,17 +54,23 @@ func MqttClient() (MQTT.Client, string) {
 	var deviceName string = setting.YynserverSetting.DeviceName
 	var deviceSecret string = setting.YynserverSetting.DeviceSecret
 
+	// FarmId = "1830004623"
+	// ProductKey = "k03txxLKFae"
+	// DeviceName = "4623_p_breed"
+	// DeviceSecret = "d06ababb2b10ba25bca3041e35ac604d"
+	// HeartBeat = "18300046234623_p_breed"
+
 	// set timestamp, clientid, subscribe topic and publish topic
 	var timeStamp string = strconv.FormatInt(time.Now().UnixNano(), 10)
-	var clientId string = "go_device_id_0001"
+	var clientId string = "go1708496085"
 	var subTopic string = "/" + productKey + "/" + deviceName + "/user/heatwatch/tmrBreed/get"
 	var pubTopic string = "/" + productKey + "/" + deviceName + "/user/heatwatch/tmrBreed/post"
 
 	// set the login broker url
 	var raw_broker bytes.Buffer
-	raw_broker.WriteString("tls://")
-	raw_broker.WriteString(productKey)
-	raw_broker.WriteString(".iot-as-mqtt.cn-shanghai.aliyuncs.com:1883")
+	raw_broker.WriteString("tcp://")
+	// raw_broker.WriteString(productKey)
+	raw_broker.WriteString("iot-010a5xth.mqtt.iothub.aliyuncs.com:1883")
 	opts := MQTT.NewClientOptions().AddBroker(raw_broker.String())
 
 	// calculate the login auth info, and set it into the connection options
@@ -82,39 +89,15 @@ func MqttClient() (MQTT.Client, string) {
 		}
 	}
 
-	// create and start a client using the above ClientOptions
-	c := MQTT.NewClient(opts)
-	if token := c.Connect(); token.Wait() && token.Error() != nil {
-		logging.Error("mqtt Connect err: ", token.Error())
+	c := mqtt.NewClient(opts)
 
+	if token := c.Connect(); token.Wait() && token.Error() != nil {
+		fmt.Println(token.Error())
+		os.Exit(1)
 	}
-	fmt.Print("Connect aliyun IoT Cloud Sucess\n")
-
-	// if token := c.Subscribe(subTopic, 0, feedHeatwatch); token.Wait() && token.Error() != nil {
-	// 	fmt.Println(token.Error())
-	// 	os.Exit(1)
-	// }
-	// subscribe to subTopic("/a1Zd7n5yTt8/deng/user/get") and request messages to be delivered
-
-	// fmt.Println("Subscribe topic "+subTopic+" success\n", c.IsConnected())
 
-	// publish 5 messages to pubTopic("/a1Zd7n5yTt8/deng/user/update")
-	// for i := 0; i < 50; i++ {
-	// 	fmt.Println("publish msg:", i)
-	// 	text := fmt.Sprintf("ABC #%d", i)
-	// 	token := c.Publish(pubTopic, 0, false, text)
-	// 	fmt.Println("publish msg: ", text)
-	// 	token.Wait()
-
-	// 	time.Sleep(2 * time.Second)
-	// }
-	// unsubscribe from subTopic("/a1Zd7n5yTt8/deng/user/get")
-	// if token := c.Unsubscribe(subTopic); token.Wait() && token.Error() != nil {
-	// 	fmt.Println(token.Error())
-	// 	os.Exit(1)
-	// }
+	fmt.Print("Connect aliyun IoT Cloud Sucess\n")
 
-	// c.Disconnect(250)
 	return c, pubTopic
 }
 
@@ -191,9 +174,26 @@ func feedtempletPush(c MQTT.Client, pubTopic string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	dataList, err := tx.SQL(`select f.id  as recipeId , f.tname recipeName,ft.id ingId,ft.fname ingName,ft.fweight  afQty,
-	ft.sort mixNo,fd.allowratio allowableError ,fd.fclass ingType, ft.fweight * ( fd.dry /100 )  dmQty,null recipeCost 
-	 from feedtemplet  f   join ftdetail ft  on ft.ftid = f.id  join feed fd on fd.id = ft.fid	
+	dataList, err := tx.SQL(`SELECT 
+	f.id AS recipeId,
+	f.tname recipeName,
+	ft.id ingId,
+	ifnull(fd.fname,fdy.fname) ingName,
+	if(fd.fname is not null, ft.fweight,fty.fweight) afQty,
+	ft.sort mixNo,
+	ifnull(fd.allowratio,fdy.allowratio) allowableError,
+	ifnull(fd.fclass,fdy.fclass) ingType,
+		if(fd.fname is not null,ft.fweight * ( fd.dry / 100 ), fty.fweight * ( fdy.dry / 100 )) dmQty,
+	NULL recipeCost 
+FROM
+	feedtemplet f
+	JOIN ftdetail ft ON ft.ftid = f.id
+	 left JOIN feed fd ON fd.id = ft.fid
+	 left join feedtemplet fy  on fy.id = ft.preftid
+ left join ftdetail fty on fty.ftid = fy.id
+ left JOIN feed fdy ON fdy.id = fty.fid
+	 
+
 	`).Query().List()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
@@ -215,7 +215,7 @@ func feedtempletPush(c MQTT.Client, pubTopic string) {
 		// c.Publish(pubTopic, 2, false, pushStr)
 		token := c.Publish(pubTopic, 2, false, pushStr)
 		fmt.Println("publish msg: ", pushStr, token.Error())
-		// token.Wait()
+		token.Wait()
 		// time.Sleep(2 * time.Second)
 	}
 }
@@ -287,11 +287,13 @@ func dustingPush(c MQTT.Client, pubTopic string) {
 	d2.lweight expWeight,
 	d2.actualweightminus actualWeight,
 	d2.begintime startTime,
-	d2.intime endTime
+	d2.intime endTime,ifnull(driver.drivername,'')tmrName
 FROM
 	downloadedplan d
 	JOIN downloadplandtl2 d2 ON d2.pid = d.id
 	JOIN bar b ON b.id = d2.fbarid 
+	join tmr t on t.id = d.tmrid 
+	left join driver on driver.drivercode = t.eqcode
 WHERE
 	DATE_FORMAT( d.mydate ,'%Y-%m-%d' ) = DATE_FORMAT(subdate(now(),1) ,'%Y-%m-%d' )`).Query().List()
 	if err != nil {
@@ -333,8 +335,8 @@ func deviceHeartbeat(c MQTT.Client, pubTopic string) {
 	device := cron.New()
 	device.AddFunc(spec1, func() {
 		token := c.Publish(pubTopic, 2, false, pushStr)
-		fmt.Println("publish msg: ", pushStr, token.Error())
-		// token.Wait()
+		fmt.Println("publish msg: ", pushStr, token.Error(), time.Now())
+		token.Wait()
 	})
 	// }
 	device.Start()
@@ -346,9 +348,19 @@ func equipmentAccuracyPush(c MQTT.Client, pubTopic string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	dataList, err := tx.SQL(`select t.tname tname,1-abs(sum(d1.actualweightminus)- sum(d1.lweight))/sum(d1.lweight) rate ,d.mydate rateDate  from downloadedplan d join downloadplandtl1 d1 on d1.pid = d.id  join tmr t on t.datacaptureno = d.datacaptureno 
-	where DATE_FORMAT( d.mydate ,'%Y-%m-%d' ) = DATE_FORMAT(subdate(now(),1) ,'%Y-%m-%d' )
-	 group by d.datacaptureno`).Query().List()
+	dataList, err := tx.SQL(`SELECT
+	t.tname tname,
+	1-abs (
+	sum( d1.actualweightminus )- sum( d1.lweight ))/ sum( d1.lweight ) rate,
+	d.mydate rateDate 
+FROM
+	downloadedplan d
+	JOIN downloadplandtl1 d1 ON d1.pid = d.id
+	JOIN tmr t ON t.datacaptureno = d.datacaptureno 
+WHERE
+	DATE_FORMAT( d.mydate, '%Y-%m-%d' ) = DATE_FORMAT( subdate( now(), 1 ), '%Y-%m-%d' )   and d.lpplantype in(0,1)
+GROUP BY
+	d.datacaptureno`).Query().List()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -378,9 +390,19 @@ func finishedWeightPush(c MQTT.Client, pubTopic string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	dataList, err := tx.SQL(`select  sum(d1.actualweightminus) CompleteWeught,sum(d1.lweight) planWeight,d.mydate weightDate 
-	 from downloadedplan d join downloadplandtl1 d1 on d1.pid = d.id  join tmr t on t.datacaptureno = d.datacaptureno 
-	where DATE_FORMAT( d.mydate ,'%Y-%m-%d' ) = DATE_FORMAT(subdate(now(),1),'%Y-%m-%d' )`).Query().List()
+	dataList, err := tx.SQL(`SELECT
+	sum( d1.actualweightminus ) CompleteWeught,
+	sum( d1.lweight ) planWeight,
+	d.mydate weightDate 
+FROM
+	downloadedplan d
+	JOIN downloadplandtl1 d1 ON d1.pid = d.id
+	JOIN tmr t ON t.datacaptureno = d.datacaptureno 
+WHERE
+	DATE_FORMAT( d.mydate, '%Y-%m-%d' ) = DATE_FORMAT(
+		subdate( now(), 1 ),
+	'%Y-%m-%d' 
+	)   and lpplantype in(0,1)`).Query().List()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -410,10 +432,9 @@ func CompletedTrainNumberPush(c MQTT.Client, pubTopic string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	dataList, err := tx.SQL(`select (select count(1) from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  DATE_FORMAT(subdate(now(),1),'%Y-%m-%d' )  )  planCar, 
-	(select count(1) from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  DATE_FORMAT(subdate(now(),1),'%Y-%m-%d' ) and iscompleted = 1 ) CompleteCar ,
-	DATE_FORMAT(subdate(now(),1),'%Y-%m-%d' ) carDate
-	`).Query().List()
+	dataList, err := tx.SQL(`	select (select count(1) from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  DATE_FORMAT(subdate(now(),1),'%Y-%m-%d' ) and lpplantype in(0,1) )  planCar, 
+	(select count(1) from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  DATE_FORMAT(subdate(now(),1),'%Y-%m-%d' ) and iscompleted = 1 and lpplantype in(0,1)) CompleteCar ,
+	DATE_FORMAT(subdate(now(),1),'%Y-%m-%d' ) carDate`).Query().List()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return

+ 353 - 16
http/handle/api/ops.go

@@ -705,6 +705,7 @@ func GetReportform(c *gin.Context) {
 	pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
 	parammaps := fsion.Get("parammaps")
 	typea := parammaps.Get("typea").ValueDefaultInt(0) //0 全部  1 理论, 2实际
+	mode := parammaps.Get("mode").ValueDefaultInt(0)
 	logging.Info("GetReportform ", c.Keys, sqlnamestr, parammaps)
 	tx := restful.Engine.NewSession()
 	err := tx.Begin()
@@ -724,7 +725,7 @@ func GetReportform(c *gin.Context) {
 		}
 	}()
 
-	queryData, err := praseReportform(sqlnamestr, parammaps, tx, checked, offset, pagecount, typea)
+	queryData, err := praseReportform(sqlnamestr, parammaps, tx, checked, offset, pagecount, typea, mode)
 	if err != nil {
 		appG.Response(http.StatusOK, e.ERROR, err.Error())
 	} else {
@@ -1144,15 +1145,15 @@ func GetRJSBData(c *gin.Context) {
 				arr, _ := tx.SQL(sql1, s_params1...).QueryString() //获取
 				queryData.(map[string]interface{})["list"].([]map[string]interface{})[index]["arrList"] = arr
 			}
-			// var wg sync.WaitGroup
-			// for _, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
-			// 	wg.Add(1)
-			// 	go func(value map[string]interface{}) {
-			// 		defer wg.Done()
-			// 		_, err = tx.SQL(`update downloadedplan set  havebutton = 1 where id = ? and pastureid = ? `, value["projuctid"], value["pastureid"]).Execute()
-			// 	}(value)
-			// }
-			// wg.Wait()
+			var wg sync.WaitGroup
+			for _, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {
+				wg.Add(1)
+				go func(value map[string]interface{}) {
+					defer wg.Done()
+					_, err = tx.SQL(`update downloadedplan set  artificial = 2 where id = ? and pastureid = ? `, value["projuctid"], value["pastureid"]).Execute()
+				}(value)
+			}
+			wg.Wait()
 			appG.Response(http.StatusOK, e.SUCCESS, queryData)
 		}
 	} else {
@@ -1203,7 +1204,8 @@ func PostRJSBData(c *gin.Context) {
 	if err != nil {
 		logging.Error("PostRJSBData  err: ", err)
 		msg := geterrmsg(err.Error())
-		appG.Response(http.StatusOK, e.ERROR, msg)
+		// appG.Response(http.StatusOK, e.ERROR, msg)
+		appG.Response(http.StatusOK, e.SUCCESS, msg)
 		return
 	}
 
@@ -1327,6 +1329,11 @@ func PostRJSBDatas(c *gin.Context) {
 			return
 		}
 		parammaps := fsion.Get("parammaps")
+		ID := parammaps.Get("ID").ValueStr()
+		if ID == "" {
+			continue
+		}
+
 		s_params := make([]interface{}, 0)
 		paramslist := strings.Split(p, ",")
 		if len(paramslist) > 0 && p != "" {
@@ -1339,7 +1346,8 @@ func PostRJSBDatas(c *gin.Context) {
 		if err != nil {
 			logging.Error("PostRJSBData  err: ", err)
 			msg := geterrmsg(err.Error())
-			appG.Response(http.StatusOK, e.ERROR, msg)
+			// appG.Response(http.StatusOK, e.ERROR, msg)
+			appG.Response(http.StatusOK, e.SUCCESS, msg)
 			return
 		}
 
@@ -5718,7 +5726,7 @@ join lpplan lpp on lpp.id = lppland.lppid  where lppland.barname = ? and lppland
 					for _, history1 := range historyList {
 						if history1["createdate"].(string) == nextcreatedate && history1["id"].(int64) == history["id"].(int64) &&
 							history1["times"].(int64) == history["times"].(int64) {
-							data[fmt.Sprintf("a%d", times[history["times"]])] = fmt.Sprintf("%v/%v", data[fmt.Sprintf("a%d", times[history["times"]])], history["lweight"])
+							data[fmt.Sprintf("a%d", times[history["times"]])] = fmt.Sprintf("%v/%v", history1["lweight"], history["lweight"])
 							break
 							// exist = true
 						}
@@ -6715,6 +6723,19 @@ func UpdateDailyData(c *gin.Context) {
 
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
+
+	count, err := tx.SQL(`select  count(1)  from  downloadedplan where pid in(select  pid from  downloadedplan where id= ? )  and havebutton = 1   and mydate = ?`, pid, date).Count()
+	if err != nil {
+		logs.Error("UpdateDailyData-error-0:", err)
+		appG.Response(http.StatusOK, e.ERROR, fmt.Sprintf("该计划已开始执行,禁止修改!"))
+		return
+	}
+
+	if count > 0 {
+		appG.Response(http.StatusOK, e.ERROR, fmt.Sprintf("该计划已开始执行,禁止修改!"))
+		return
+	}
+
 	tx.Begin()
 
 	if location == 0 {
@@ -7007,7 +7028,7 @@ func UpdateDailyData(c *gin.Context) {
 
 	}
 
-	err := tx.Commit()
+	err = tx.Commit()
 	if err != nil {
 		logs.Error("UpdateDailyData-error-20:", err)
 		tx.Rollback()
@@ -8521,8 +8542,27 @@ func checkPlan(tx *xorm.Session, fasion map[string]interface{}, CommonParamMap m
 	data := fasion["parammaps"].(map[string]interface{})
 	plancount, err := tx.Table("downloadedplan").Where(" mydate  = ? ", data["startTime"]).Where(" havebutton = 0 ").Where(" lpplantype in(0,1,2) ").Count()
 	fmt.Println(err)
-	plancount1, err := tx.SQL(`select count(1) from (select d.id from downloadedplan d join  downloadplandtl1 d1 on d1.pid = d.id  
-		join downloadplandtl1_exec d1e on d1e.pid = d.id join downloadplandtl2 d2 on d2.pid = d.id  where d.mydate = ? and d.havebutton = 0 and lpplantype in(0,1,2) group by d.id )d `,
+	plancount1, err := tx.SQL(`SELECT
+	count( 1 ) 
+FROM
+	(
+	SELECT
+		d.id 
+	FROM
+		downloadedplan d
+		JOIN downloadplandtl1 d1 ON d1.pid = d.id
+		JOIN downloadplandtl1_exec d1e ON d1e.pid = d.id
+		JOIN downloadplandtl2 d2 ON d2.pid = d.id 
+	WHERE
+		d.mydate = ?
+		AND d.havebutton = 0 
+		AND lpplantype IN ( 0, 1, 2 ) 
+		AND ( SELECT count( 1 ) FROM downloadplandtl2 dd2 WHERE dd2.pid = d.id ) = 
+		( SELECT count( 1 ) FROM downloadplandtl2 dd2   WHERE dd2.pid = d.pid  and (select count(1) from downloadplandtl2  where pid = dd2.pid  and fname = dd2.fname   ) = 1 )
+	GROUP BY
+	d.id 
+	) d 
+	 `,
 		data["startTime"]).Count()
 	fmt.Println(err)
 	if plancount != plancount1 && number < 10 {
@@ -8531,3 +8571,300 @@ func checkPlan(tx *xorm.Session, fasion map[string]interface{}, CommonParamMap m
 		checkPlan(tx, fasion, CommonParamMap, ParamMap, number)
 	}
 }
+
+func EditPlanSort(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsions := gofasion.NewFasion(string(dataByte))
+	planIdStr := fsions.Get("planId").ValueStr()
+	mydate := fsions.Get("mydate").ValueStr()
+	sort := fsions.Get("sort").ValueStr()
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	tx.Begin()
+
+	type downloadedplan struct {
+		Id   int64 `xorm:"id"`
+		Sort int   `xorm:"sort"`
+		Pid  int64 `xorm:"pid"`
+	}
+	planInfo := new(downloadedplan)
+	err := tx.SQL(`select d.id,d.sort,d.pid from downloadedplan d   where d.id = ? `, planIdStr).GetFirst(planInfo).Error
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败!"+err.Error())
+		tx.Rollback()
+		return
+	}
+	sort1, _ := strconv.Atoi(sort)
+	if sort1 == planInfo.Sort {
+		appG.Response(http.StatusOK, e.ERROR, "计划顺序一致修改失败!")
+		tx.Rollback()
+		return
+	}
+
+	count1, err := tx.SQL(` select count(1) from downloadedplan  where pid =  (select pid from downloadedplan  where sort = ? and mydate = ? )  and mydate = ?    `, sort, mydate, mydate).Count()
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败!"+err.Error())
+		tx.Rollback()
+		return
+	}
+
+	if count1 == 0 {
+		tx.Rollback()
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "您所排序的数值不存在!")
+		return
+	}
+
+	count, err := tx.SQL(` select count(1) from downloadedplan  where pid =  (select pid from downloadedplan  where sort = ? and mydate = ? )  and havebutton = 1  and mydate = ?    `, sort, mydate, mydate).Count()
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败!"+err.Error())
+		tx.Rollback()
+		return
+	}
+
+	if count > 0 {
+		tx.Rollback()
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败,该计划已执行!")
+		return
+	}
+
+	if planInfo.Sort > sort1 {
+		minSortList, err := tx.SQL(`select min(d.sort) sort from downloadedplan d   where d.mydate = ?  and d.pid = (select pid from downloadedplan  where sort = ? and mydate = ? ) `, mydate, sort, mydate).QueryString()
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败!"+err.Error())
+			tx.Rollback()
+			return
+		}
+		var minSort, pidCount int
+		for _, sort := range minSortList {
+			minSort, _ = strconv.Atoi(sort["sort"])
+		}
+
+		planList := make([]*downloadedplan, 0)
+		err = tx.SQL(`select id,d.sort sort,d.pid from downloadedplan d   where d.mydate = ? and  sort >= ? order by sort`, mydate, minSort).Find(&planList)
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败!"+err.Error())
+			tx.Rollback()
+			return
+		}
+
+		planPid := planInfo.Pid
+		planList1 := make([]*downloadedplan, 0)
+		planList2 := make([]*downloadedplan, 0)
+
+		for _, plan := range planList {
+			if plan.Pid == planPid {
+				pidCount++
+				planList1 = append(planList1, plan)
+			} else {
+				planList2 = append(planList2, plan)
+			}
+		}
+		planList1 = append(planList1, planList2...)
+
+		for i, plan := range planList1 {
+			_, err := tx.Exec(` update downloadedplan set sort = ? where id = ? `, minSort+i, plan.Id)
+			if err != nil {
+				logs.Error(err)
+				appG.Response(http.StatusOK, e.ERROR, "修改计划顺序失败!"+err.Error())
+				tx.Rollback()
+				return
+			}
+		}
+	} else {
+		maxSortList, err := tx.SQL(`select max(d.sort) sort from downloadedplan d   where d.mydate = ?  and d.pid = (select pid from downloadedplan  where sort = ? and mydate = ? ) `, mydate, sort, mydate).QueryString()
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败!"+err.Error())
+			tx.Rollback()
+			return
+		}
+		var maxSort int
+		for _, sort := range maxSortList {
+			maxSort, _ = strconv.Atoi(sort["sort"])
+		}
+
+		planList := make([]*downloadedplan, 0)
+		err = tx.SQL(`select id,d.sort sort,d.pid from downloadedplan d   where d.mydate = ? and  sort <= ? order by sort`, mydate, maxSort).Find(&planList)
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, "调整计划顺序失败!"+err.Error())
+			tx.Rollback()
+			return
+		}
+
+		planPid := planInfo.Pid
+		planList1 := make([]*downloadedplan, 0)
+		planList2 := make([]*downloadedplan, 0)
+
+		for _, plan := range planList {
+			if plan.Pid == planPid {
+				// pidCount++
+				planList1 = append(planList1, plan)
+			} else {
+				planList2 = append(planList2, plan)
+			}
+		}
+		planList2 = append(planList2, planList1...)
+
+		for i, plan := range planList2 {
+			_, err := tx.Exec(` update downloadedplan set sort = ? where id = ? `, i+1, plan.Id)
+			if err != nil {
+				logs.Error(err)
+				appG.Response(http.StatusOK, e.ERROR, "修改计划顺序失败!"+err.Error())
+				tx.Rollback()
+				return
+			}
+		}
+	}
+
+	err = tx.Commit()
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "修改计划顺序失败!"+err.Error())
+		tx.Rollback()
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, "ok")
+}
+
+func EditDownloadedplanArtificial(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsions := gofasion.NewFasion(string(dataByte))
+	planIdStr := fsions.Get("planId").ValueStr()
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	tx.Begin()
+
+	planIdList := strings.Split(planIdStr, ",")
+
+	for _, planId := range planIdList {
+		_, err := tx.Exec(` update downloadedplan set artificial = 1 ,havebutton = 1,iscompleted = 1  where id = ?  and havebutton != 1`, planId)
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, "修改计划状态失败!"+err.Error())
+			tx.Rollback()
+			return
+		}
+	}
+
+	err := tx.Commit()
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, "修改计划状态失败!"+err.Error())
+		tx.Rollback()
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, "ok")
+}
+
+type PlanRFID struct {
+	RFID    string `json:"RFID"`
+	Lweight string `json:"lweight"`
+	Gear    string `json:"gear"`
+	Speed   string `json:"speed"`
+}
+
+func GetPlanRFID(c *gin.Context) {
+	appG := app.Gin{C: c}
+	RFIDStr := c.Query("RFID")
+
+	planRFIDList := make([]*PlanRFID, 0)
+	planRFIDList = append(planRFIDList, &PlanRFID{
+		RFID:    RFIDStr,
+		Lweight: "1411.1",
+		Gear:    "1",
+		Speed:   "10",
+	})
+
+	planRFIDList = append(planRFIDList, &PlanRFID{
+		RFID:    RFIDStr,
+		Lweight: "1322.1",
+		Gear:    "1",
+		Speed:   "10",
+	})
+	planRFIDList = append(planRFIDList, &PlanRFID{
+		RFID:    RFIDStr,
+		Lweight: "1904.1",
+		Gear:    "1",
+		Speed:   "10",
+	})
+	planRFIDList = append(planRFIDList, &PlanRFID{
+		RFID:    RFIDStr,
+		Lweight: "1870.1",
+		Gear:    "1",
+		Speed:   "10",
+	})
+	planRFIDList = append(planRFIDList, &PlanRFID{
+		RFID:    RFIDStr,
+		Lweight: "2041.1",
+		Gear:    "1",
+		Speed:   "10",
+	})
+	appG.Response(http.StatusOK, e.SUCCESS, planRFIDList)
+}
+
+type tmrEquipmentMuster struct {
+	A string
+	N string
+}
+
+func GetTmrEquipmentMuster(c *gin.Context) {
+	appG := app.Gin{C: c}
+	id := c.Query("id")
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	dataList, err := tx.SQL(`  select *  from tmr_equipment_muster where pid = ?  `, id).QueryString()
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, err.Error())
+
+		return
+	}
+
+	tmrEquipmentMusterList := make([]*tmrEquipmentMuster, 0)
+
+	for _, data := range dataList {
+		json.Unmarshal([]byte(data["gptjson"]), &tmrEquipmentMusterList)
+		for _, g := range tmrEquipmentMusterList {
+			a, _ := strconv.ParseFloat(g.A, 64)
+			n, _ := strconv.ParseFloat(g.N, 64)
+			a1, n1 := ddmmtoddd(a, n)
+			g.A = fmt.Sprintf("%f", a1)
+			g.N = fmt.Sprintf("%f", n1)
+		}
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, tmrEquipmentMusterList)
+}
+
+func ddmmtoddd(lng, lat float64) (float64, float64) {
+	// 计算度
+	lngDegree := int(lng / 100)
+	latDegree := int(lat / 100)
+
+	// 计算分
+	lngMinute := lng - float64(lngDegree*100)
+	latMinute := lat - float64(latDegree*100)
+
+	// 转换为度.dddd格式
+	newLng := float64(lngDegree) + lngMinute/60.0
+	newLat := float64(latDegree) + latMinute/60.0
+
+	return newLng, newLat
+}

+ 1 - 1
http/handle/api/pusher.go

@@ -89,7 +89,7 @@ func GetPusherList(c *gin.Context) {
 		tmr.Date = fmt.Sprintf("%s %s", date, tmr.Date)
 		var barNameList []string
 		for _, bar := range barList {
-			barNameList = append(barNameList, bar.BName+"→")
+			barNameList = append(barNameList, bar.BName)
 		}
 		tmr.BarName = strings.Join(barNameList, ",")
 	}

+ 153 - 3
http/handle/api/report.go

@@ -3,6 +3,7 @@ package api
 import (
 	"encoding/json"
 	"fmt"
+	"math"
 	"sort"
 	"strconv"
 	"strings"
@@ -15,7 +16,7 @@ import (
 )
 
 //包含报表模块前端需要的各种数据格式转换
-func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session, checked string, offset, count, typea int) (queryData map[string]interface{}, err error) {
+func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session, checked string, offset, count, typea, mode int) (queryData map[string]interface{}, err error) {
 
 	sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
 	s_params := make([]interface{}, 0)
@@ -41,6 +42,7 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 	}
 	queryList2, err := tx.SQL(sql2, s_params2...).Query().List()
 	var feednamesort []string
+	var feedcodelist []string
 	if len(queryList2) > 0 {
 		for i := 0; i < len(queryList2); i++ {
 			feednamesort = append(feednamesort, queryList2[i]["fname"].(string))
@@ -59,7 +61,7 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 		}
 	}
 	// var queryList3 []map[string]interface{}
-	// queryList3 = make([]map[string]interface{}, 0)
+	feedDataList := make([]map[string]interface{}, 0)
 	var feednamesort3 []string
 	if sql3 != "" {
 		queryList3, err := tx.SQL(sql3, s_params3...).Query().List()
@@ -70,7 +72,9 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 		if len(queryList3) > 0 {
 			for z := 0; z < len(queryList3); z++ {
 				feednamesort3 = append(feednamesort3, queryList3[z]["feedname"].(string))
+				feedcodelist = append(feedcodelist, queryList3[z]["feedcode"].(string))
 			}
+			feedDataList = append(feedDataList, queryList3...)
 		}
 	}
 
@@ -125,7 +129,13 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 			}
 		}
 		queryListSum, _ := tx.SQL(sql1, s_params1...).Query().List()
-		queryData, err = getAccuracyV4(queryList, queryListSum, checked, feednamesort3, typea)
+		if mode == 0 {
+			queryData, err = getAccuracyV4(queryList, queryListSum, checked, feednamesort3, typea)
+		} else {
+			queryData, _ = getAccuracyV41(queryList, queryListSum, checked, feednamesort3, typea, feedDataList)
+		}
+		queryData["feedcode"] = feedcodelist
+
 	case "getPriceAn":
 		queryData, err = getAccuracyV5(queryList)
 	case "getJT1Accu":
@@ -1255,3 +1265,143 @@ func GetprocessAnalysisTB(parammaps *gofasion.Fasion, tx *xorm.Session, quertDat
 	query1["realWandT"] = realWandT
 	return query1, nil
 }
+
+type Columns struct {
+	Prop  string `json:"prop"`
+	Label string `json:"label"`
+}
+
+func getAccuracyV41(queryList []map[string]interface{}, queryListSum []map[string]interface{}, checked string, feednamesort3 []string, typea int, feednameCodes []map[string]interface{}) (map[string]interface{}, error) {
+	columns := make([]*Columns, 0)
+	columns = append(columns, &Columns{
+		Prop:  "A",
+		Label: "饲料编码",
+	})
+	columns = append(columns, &Columns{
+		Prop:  "B",
+		Label: "饲料名称",
+	})
+
+	label := "类别"
+
+	// column1 := new(Columns)
+
+	columns1 := make([]*Columns, 0)
+	dataList := make([]map[string]interface{}, 0)
+
+	for i := 0; i < len(queryList); i++ {
+		label = queryList[i]["typestr"].(string)
+		exist1 := false
+		for _, data := range dataList {
+			if data["B"].(string) == queryList[i]["feedname"].(string) {
+				exist1 = true
+			}
+		}
+
+		if !exist1 {
+			data1 := make(map[string]interface{}, 0)
+			data2 := make(map[string]interface{}, 0)
+			for _, v := range feednameCodes {
+				if v["feedname"].(string) == queryList[i]["feedname"].(string) {
+					data1["A"] = v["feedcode"]
+					data2["A"] = v["feedcode"]
+					break
+				}
+			}
+			data1["B"] = queryList[i]["feedname"]
+			data1["C"] = "理论"
+			// data1[queryList[i]["fname"].(string)] = 0
+			dataList = append(dataList, data1)
+			data2["B"] = queryList[i]["feedname"]
+			data2["C"] = "实际"
+			// data2[queryList[i]["fname"].(string)] = 0
+			dataList = append(dataList, data2)
+		}
+
+		column := new(Columns)
+		column.Prop = queryList[i]["fname"].(string)
+		column.Label = queryList[i]["fname"].(string)
+
+		exist := false
+		for _, c := range columns1 {
+			if c.Prop == queryList[i]["fname"].(string) {
+				exist = true
+			}
+		}
+		if exist {
+			continue
+		}
+		columns1 = append(columns1, column)
+	}
+
+	for _, data := range dataList {
+		for _, c := range columns1 {
+			data[c.Prop] = 0
+		}
+	}
+
+	data1 := make(map[string]interface{}, 0)
+	data2 := make(map[string]interface{}, 0)
+	data1["B"] = "合计"
+	data1["C"] = "理论"
+	data2["B"] = "合计"
+	data2["C"] = "实际"
+
+	for _, c := range columns1 {
+		if c.Prop != "合计" {
+			data1[c.Prop] = 0.0
+			data2[c.Prop] = 0.0
+		}
+	}
+
+	columns = append(columns, &Columns{
+		Prop:  "C",
+		Label: label,
+	})
+
+	columns = append(columns, columns1...)
+	for _, data := range dataList {
+		for i := 0; i < len(queryList); i++ {
+			if queryList[i]["feedname"].(string) == data["B"] {
+				if data["C"].(string) == "理论" {
+					f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", queryList[i]["lweight"]), 64)
+					data[queryList[i]["fname"].(string)] = Round(f1, 2)
+				} else {
+					if queryList[i]["actualweightminus"] == nil {
+						data[queryList[i]["fname"].(string)] = 0.0
+					} else {
+						f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", queryList[i]["actualweightminus"]), 64)
+						data[queryList[i]["fname"].(string)] = Round(f1, 2)
+					}
+				}
+			}
+		}
+	}
+
+	for _, data := range dataList {
+		for _, c := range columns1 {
+			if c.Prop != "合计" {
+				if data["C"].(string) == "理论" {
+					f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", data1[c.Prop]), 64)
+					f2, _ := strconv.ParseFloat(fmt.Sprintf("%v", data[c.Prop]), 64)
+					data1[c.Prop] = Round(f1+f2, 2)
+				} else {
+					f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", data2[c.Prop]), 64)
+					f2, _ := strconv.ParseFloat(fmt.Sprintf("%v", data[c.Prop]), 64)
+					data2[c.Prop] = Round(f1+f2, 2)
+				}
+			}
+		}
+	}
+	dataList = append(dataList, data1)
+	dataList = append(dataList, data2)
+
+	respData := make(map[string]interface{})
+	respData["data"] = dataList
+	respData["columns"] = columns
+	return respData, nil
+}
+
+func Round(number float64, size int) float64 {
+	return math.Round(number*100) / 100
+}

+ 45 - 13
http/handle/api/scheduled.go

@@ -15,6 +15,7 @@ import (
 	"time"
 
 	"tmr-watch/conf/setting"
+	"tmr-watch/http/handle/gm"
 	"tmr-watch/http/handle/restful"
 	"tmr-watch/pkg/app"
 	"tmr-watch/pkg/e"
@@ -129,20 +130,20 @@ func CronScheduled(ctx context.Context) {
 		}
 	})
 	dayCron.Start()
-
+	// udFeedSync(pastureinfo)
 	// //圣牧自动同步前天有进行中的任务
-	manualUdData(pastureinfo)
-
-	// xdmy := cron.New()
-	// err = xdmy.AddFunc("0 10 4 * * *", func() {
-	// 	//现代牧业sap同步
-	// 	// sap.SyncMaterialOutbound()
-	// 	// 光明ud同步
-	// 	fmt.Println(time.Now())
-	// 	gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
-	// })
-	// xdmy.Start()
-
+	// 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)
+	})
+	xdmy.Start()
+	// InitMqttClient()
 }
 
 type ScheduledInfo struct {
@@ -657,6 +658,7 @@ func (h *ScheduledDown) SyncFeed(pastureid string, feedList []interface{}) {
 		insertSql := `insert into feed(id,pastureid,feedcode,fname,fclassid,fclass,dry)VALUES(?,?,?,?,?,?,?) 
 		ON DUPLICATE KEY UPDATE fname = ? ,dry = ? `
 		_, err = tx.SQL(insertSql, ids, pastureid, feedcode, fname, fclassid, fclass, dry, fname, dry).Execute()
+		fmt.Println(feedcode, fname, fclassid)
 		if err != nil {
 			tx.Rollback()
 			logs.Error("syncFeed-error-5:", err)
@@ -1130,6 +1132,7 @@ func manualUdData(pastureinfo *udPastureInfo) {
 	c3 := cron.New()
 	c3.AddFunc("59 23 * * *", func() {
 		udFeedpSync(pastureinfo)
+		udFeedSync(pastureinfo)
 	})
 	c3.Start()
 
@@ -1799,3 +1802,32 @@ func UdFeedpSync(c *gin.Context) {
 	appG.Response(http.StatusOK, e.SUCCESS, true)
 	// return
 }
+
+func udFeedSync(pastureinfo *udPastureInfo) error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	downList := make([]*ScheduledDownInfo, 0)
+	down := tx.Table("scheduled_down")
+
+	down.Where("company = ? ", "ud")
+	down.Where("methods = ? ", "SyncFeed")
+	err := down.Find(&downList)
+	if err != nil {
+		log.Println("UpdateDown-error-1: ", err)
+		return err
+	}
+
+	for _, item := range downList {
+		list := httpGetMC(item.Addres, item.Targetdata)
+		if item.Methods != "" {
+			s := ScheduledDown{}
+			value := reflect.ValueOf(&s)
+			f := value.MethodByName(item.Methods)
+			f.Call([]reflect.Value{reflect.ValueOf(pastureinfo.Pastureid), reflect.ValueOf(list)})
+
+		}
+
+	}
+	return nil
+}

+ 24 - 19
http/handle/gm/udservice.go

@@ -20,13 +20,13 @@ import (
 // "../../../routers/restful"
 // http://172.16.86.95:8080/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=ef275fb06fd847d88422517773e5a616&method=downloadpen
 func GmUdSync(pastureId, farmId string) {
-	UdBarSync(pastureId, farmId)
-	UdFeedSync(pastureId, farmId)
-
+	UdMaterialIssuePush(pastureId, farmId, "")
 	UdFeedtempletPush(pastureId, farmId, "")
 	UdUtirPush(pastureId, farmId, "")
 	UdBarFeedRemainPush(pastureId, farmId, "")
-	UdMaterialIssuePush(pastureId, farmId, "")
+
+	UdBarSync(pastureId, farmId)
+	UdFeedSync(pastureId, farmId)
 }
 
 func UdBarSync(pastureId, farmId string) {
@@ -49,11 +49,13 @@ func UdBarSync(pastureId, farmId string) {
 			barname := bar["barname"].(string)
 			count, _ := tx.Table("bar").Where("pastureId = ? ", pastureId).Count()
 			barExist, _ := tx.SQL(` select count(1) from bar where bcode = ? `, bar["barcode"]).Exist()
-			tx.Exec(`insert into bar(pastureid,bcode,bname,sort)values(?,?,?,?)   ON DUPLICATE KEY UPDATE  bname = ? `, pastureId, bar["barcode"], barname, count+1, barname)
-			_, _ = tx.Exec(`insert into feedp(pastureid,barid,barname,softccount,ccount,udcode,udname)values(?,(select id from bar where bcode=  ? and pastureId = ? ),?,?,?,?,?)
-		 ON DUPLICATE KEY UPDATE  softccount = ? , udcode =? ,udname =?`,
-				pastureId, bar["barcode"], pastureId, barname, bar["cowcount"], bar["cowcount"], bar["barcode"], barname, bar["cowcount"], bar["barcode"], barname)
-			fmt.Println(bar["barcode"], barname)
+			_, err := tx.Exec(`insert into bar(pastureid,bcode,bname,sort)values(?,?,?,?)   ON DUPLICATE KEY UPDATE  bname = ?,udname = ?  `, pastureId, bar["barcode"], barname, count+1, barname, barname)
+			_, err = tx.Exec(`insert into feedp(pastureid,barid,barname,softccount,ccount)values(?,(select id from bar where bcode=  concat(?) and pastureId = ? ),?,?,?)
+		 ON DUPLICATE KEY UPDATE  softccount = ?  `,
+				//  tx.Exec(`update bar  `, pastureId, bar["barcode"], barname, count+1, barname, barname)
+
+				pastureId, bar["barcode"], pastureId, barname, bar["cowcount"], bar["cowcount"], bar["cowcount"])
+			fmt.Println(bar["barcode"], barname, bar["cowcount"], pastureId, err)
 			if !barExist {
 				tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
 					pastureId, bar["barcode"], 1, barname)
@@ -164,24 +166,26 @@ func UdUtirPush(pastureId, farmId, date string) error {
 		now = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
 	}
 
-	dataList, err := tx.SQL(`select date_format(d1.date,'%Y-%m-%d')  loadDate,d.times loadShift,d.datacaptureno  tmrNo,ft.tcode recipeId,ft.ccname recipeName,if(d1.feedcode = -1 ,d1.fid,f.feedcode) ingId,ifnull(ifnull(f.udname,f.fname),d1.fname)  ingName,
+	dataList, err := tx.SQL(`select date_format(d1.date,'%Y-%m-%d')  dropDate,d.times loadShift,d.datacaptureno  tmrNo,ft.tcode recipeId,ft.ccname recipeName,if(d1.feedcode = -1 ,d1.fid,f.feedcode) ingId,ifnull(f.fname,ftd.fname)  ingName,
 	ifnull(ifnull(fc.fcname,(select fcname from feedclass fc1 join feed f1 on f1.fclassid = fc1.id where f1.id =ftd.fid )),'饲料') ingType,
-	ifnull(f.dry * d1.actualweightminus,0)  dmPct,d1.sort mixNo,ifnull(d1.feedallowratio,0) allowableError ,ifnull(d1.lweight,'') expWeight,ifnull(d1.actualweightminus,'') actualWeight,
+	ifnull(f.dry * d1.actualweightminus,0)  dmPct,d1.sort mixNo,ifnull(d1.feedallowratio,0) allowableError , if(f.fname is not null, ifnull(d1.lweight,''),	ifnull(ftd.fweight / (select sum(fweight)  from ftdetaildate  where  date =  d1.date and ftid = d1.fid ) *  d1.lweight,"") )  expWeight,
+	
+	if(f.fname is not null, ifnull(d1.actualweightminus,''),	ifnull(ftd.fweight / (select sum(fweight)  from ftdetaildate  where  date =  d1.date and ftid = d1.fid ) *  d1.actualweightminus,"") ) actualWeight,
 	DATE_FORMAT(IFNULL((SELECT MAX(intime) FROM downloadplandtl1 d2 
 WHERE  d1.pid=d2.pid AND d1.pastureid = d2.pastureid AND d2.intime<d1.intime)
 , (SELECT MAX(intime) FROM downloadedplan d2 
 WHERE  d1.date=d2.mydate AND d1.pastureid = d2.pastureid AND d2.id=d1.pid)
 ), '%Y-%m-%d %H:%i:%s') 
    startTime  ,
-	 date_format(d1.intime,'%Y-%m-%d %H:%i:%s')   endTime, d.tmrtname tmrName , d.pid id ,ifnull(ftd.sort,"") premixFeedSort ,
-	ifnull( (select id from feed where id = ftd.fid),"") premixFeedId,ifnull(ftd.fname,"")  premixFeedName,
-	ifnull(ftd.fweight / (select sum(fweight)  from ftdetaildate  where  date =  d1.date and ftid = d1.fid ) *  d1.actualweightminus,"") premixFeedWeight
+	 date_format(d1.intime,'%Y-%m-%d %H:%i:%s')   endTime, driver.drivername tmrName ,d1.feedallowratio allowable_error
 	from downloadplandtl1  d1 join  downloadedplan d on d.id = d1.pid
 	left join feedtempletdate ft  on ft.id = d.tempid  and ft.date = d1.date
 	left join feed f on f.feedcode  = d1.feedcode
 	left join feedclass fc on fc.id = f.fclassid
 	left join ftdetaildate  ftd  on  ftd.date =  d1.date and ftd.ftid = d1.fid
-	where d1.date = ?  and d.havebutton = 1`, now).Query().List()
+	join tmr t on t.id = d.tmrid 
+	left driver on driver.drivercode = t.eqcode
+	where d1.date = DATE_FORMAT(subdate(now(),1) ,'%Y-%m-%d' ) and d.havebutton = 1 and d1.type = 0 `, now).Query().List()
 	if err != nil {
 		logging.Error(err)
 		return err
@@ -222,7 +226,7 @@ func UdMaterialIssuePush(pastureId, farmId, date string) error {
 	}
 
 	dataList, err := tx.SQL(`SELECT  d1.sort feedSort, ifnull(f.feedcode,d1.fid) feedId,ifnull(ifnull(f.udname,f.fname),d1.fname) feedName,
-	d.id,IFNULL(ft.tcode,d2.feedtempletid ) recipeId,IFNULL(ft.tcode,d2.feedtempletid ) feedtempletId,ft.tname feedtempletName ,
+	d.id,IFNULL(ft.tcode,d2.feedtempletid ) recipeId,IFNULL(ft.tcode,d2.feedtempletid ) feedtempletId,ifnull(ft.tname,d.templetName) feedtempletName ,
 	IFNULL(d.templetName,d2.feedtempletName ) recipeName,
 	date_format(d.mydate,'%Y-%m-%d') as dropDate,ifnull((select sort from downloadedplan where pid=d.pid and lpplanType !=d.lpplanType and mydate=d.mydate),d.sort) as tmrNo,
 	d.Times as dropShift,ifnull(b.bcode,b.id) as penId,b.bname as penName,fp.CCOUNT as cowCount, d2.SORT as feedingNo,
@@ -252,7 +256,7 @@ d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) F
 	
 	 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 = ftd.version  AND ftd2.ftid = d1.fid  ))
-	),''),'')
+	),''),'0')
   premixFeedWeight
 	
 	from  downloadedplan d
@@ -263,8 +267,9 @@ d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) F
 	LEFT JOIN feedp fp on d2.FBarID=fp.barid
 	left join bar b on fp.barid = b.id and d.pastureid = b.pastureid
 	left join feed f   on f.feedcode  = d1.feedcode
-	left JOIN feedtempletdate ft on d.tempid=ft.id and  ft.date =  d1.date           
-		left join ftdetaildate  ftd  on  ftd.date =  d1.date and ftd.ftid = d1.fid
+	left JOIN feedtempletdate ft on d.tempid=ft.id and  ft.date =  d1.date   and d.tversion = ft.version           
+	left join feedtempletdate  ft1 on   d1.feedcode = '-1'  and ft1.date = d1.date and ft1.id = d1.fid 
+	left join ftdetaildate  ftd  on  ftd.date =  d1.date and ftd.ftid = d1.fid AND d1.feedcode = '-1'  and ftd.version = ft1.version
 
 	where d.mydate= date_format(?,'%Y-%m-%d')  and d2.type = 0   and d.havebutton = 1  and d.pastureid = ?  and d1.fname is not null  order by tmrno   `, now, now, pastureId).Query().List()
 	if err != nil {

+ 8 - 0
http/routers/app_api.go

@@ -226,6 +226,11 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 
 			apiV1.POST("/feedtemplet/del", api.DelFeedTemplet)
 
+			apiV1.POST("/plan/sort/edit", api.EditPlanSort)
+			//日执行计划修改为完成
+			apiV1.POST("/plan/artificial/edit", api.EditDownloadedplanArtificial)
+
+			apiV1.GET("/equipment/muster", api.GetTmrEquipmentMuster)
 		}
 
 		//不需要登录验证的接口
@@ -242,6 +247,9 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 			apiV3.GET("/pusher/list", api.GetPusherList)
 			apiV3.POST("/pusher/edit", api.EditPusherGPS)
 
+			//羊圈通过RFID 需要传输的值:
+			apiV3.GET("/plan/rfid", api.GetPlanRFID)
+
 		}
 
 		apiV4 := s.Group("/customreport") // restful  接口 tablename 是 表名字

BIN
uploads.zip


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff