Browse Source

圣牧更新

baishaojie 10 months ago
parent
commit
4f4bfe59ea

BIN
__debug_bin.exe → KPTAdmin64.exe


+ 6 - 6
conf/app.ini

@@ -21,7 +21,7 @@ TimeFormat = 20060102-150405
 #debug or release
 #RunMode = debuggit 
 RunMode = release
-HttpPort = 8081
+HttpPort = 80
 ReadTimeout = 60
 WriteTimeout = 60
 NoAuth = 1
@@ -73,7 +73,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = yq
+Name = bmsm8
 TablePrefix =
 
 ShowXormlog = false
@@ -91,11 +91,11 @@ Name =
 
 
 [yyn]
-FarmId = "1830004623"
+FarmId = "1830004776"
 ProductKey = "k03txxLKFae"
-DeviceName = "4623_p_breed"
-DeviceSecret = "d06ababb2b10ba25bca3041e35ac604d"
-HeartBeat = "18300046234623_p_breed"
+DeviceName = "04776_p_breed"
+DeviceSecret = "e1fdb50556b13afe896e738fdcb25bf3"
+HeartBeat = "Tmr183000477604776_p_breed"
 
 
 [comm]

BIN
dist(1).zip


BIN
dist(1)/dist/favicon.ico


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


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/css/app.005b8c7f.css


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/css/chunk-elementUI.c1c3b808.css


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/css/chunk-libs.f403b559.css


BIN
dist(1)/dist/static/fonts/element-icons.535877f5.woff


BIN
dist(1)/dist/static/fonts/element-icons.732389de.ttf


BIN
dist(1)/dist/static/img/404.a57b6f31.png


BIN
dist(1)/dist/static/img/404_cloud.0f4bc32b.png


File diff suppressed because it is too large
+ 0 - 28
dist(1)/dist/static/img/iconfont.7d9f8392.svg


BIN
dist(1)/dist/static/img/logo.afed751a.png


BIN
dist(1)/dist/static/img/logo1.0121925c.png


BIN
dist(1)/dist/static/img/logo_u3.3c77f543.png


BIN
dist(1)/dist/static/img/nlogin-bg1.77301f56.jpg


BIN
dist(1)/dist/static/img/row-bg3.b3be7548.png


BIN
dist(1)/dist/static/img/topBg.69ecd1e1.png


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/js/app.a193431d.js


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/js/chunk-218b9b2f.443d0c85.js


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/js/chunk-52ecc0ac.ba542cb9.js


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/js/chunk-5c4dc4a9.9bfbd7f4.js


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/js/chunk-b702d234.fadfa57f.js


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/js/chunk-elementUI.c961dc79.js


File diff suppressed because it is too large
+ 0 - 0
dist(1)/dist/static/js/chunk-libs.90e56fea.js


+ 95 - 76
http/handle/api/mqtt.go

@@ -28,16 +28,25 @@ func InitMqttClient() {
 		c, pubTopic := MqttClient()
 		deviceHeartbeat(c, pubTopic)
 
-		// mqttCron := cron.New()
-		// mqttCron.AddFunc("10 06 * * *", func() {
+		// now := time.Now().AddDate(0, 0, -5).Format("2006-01-02")
+		// stirPush(c, pubTopic, now)
+		// dustingPush(c, pubTopic, now)
+		// equipmentAccuracyPush(c, pubTopic, now)
+		// finishedWeightPush(c, pubTopic, now)
 		// feedtempletPush(c, pubTopic)
-		stirPush(c, pubTopic)
-		dustingPush(c, pubTopic)
-		// equipmentAccuracyPush(c, pubTopic)
-		// finishedWeightPush(c, pubTopic)
-		// CompletedTrainNumberPush(c, pubTopic)
-		// })
-		// mqttCron.Start()
+		// CompletedTrainNumberPush(c, pubTopic, now)
+
+		mqttCron := cron.New()
+		mqttCron.AddFunc("10 06 * * *", func() {
+			now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+			stirPush(c, pubTopic, now)
+			dustingPush(c, pubTopic, now)
+			equipmentAccuracyPush(c, pubTopic, now)
+			finishedWeightPush(c, pubTopic, now)
+			feedtempletPush(c, pubTopic)
+			CompletedTrainNumberPush(c, pubTopic, now)
+		})
+		mqttCron.Start()
 	}
 
 }
@@ -54,22 +63,22 @@ 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"
+	// 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
 
-	// set timestamp, clientid, subscribe topic and publish topic
 	var timeStamp string = strconv.FormatInt(time.Now().UnixNano(), 10)
-	var clientId string = "go1708496085"
+	var clientId string = "go" + setting.YynserverSetting.FarmId
 	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("tcp://")
-	// raw_broker.WriteString(productKey)
 	raw_broker.WriteString("iot-010a5xth.mqtt.iothub.aliyuncs.com:1883")
 	opts := MQTT.NewClientOptions().AddBroker(raw_broker.String())
 
@@ -184,7 +193,7 @@ func feedtempletPush(c MQTT.Client, pubTopic string) {
 	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 
+	'' recipeCost 
 FROM
 	feedtemplet f
 	JOIN ftdetail ft ON ft.ftid = f.id
@@ -194,7 +203,7 @@ FROM
  left JOIN feed fdy ON fdy.id = fty.fid
 	 
 
-	`).Query().List()
+	`).QueryString()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -203,7 +212,7 @@ FROM
 	pushStr := `{
 		"apiId": "getKPTData", 
 		"param": {
-		"farmId": %s, 
+		"farmId": "%s", 
 				  "method":"getfeedtempletinfo",
 				  "rowCount": "1",
 		"resultData":%s
@@ -215,38 +224,41 @@ FROM
 		// 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)
 	}
 }
 
-func stirPush(c MQTT.Client, pubTopic string) {
+func stirPush(c MQTT.Client, pubTopic, date string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
 	dataList, err := tx.SQL(`SELECT
-	d.mydate dropDate,
-	d.projname tmrNo,
+	DATE_FORMAT(d.mydate,'%Y-%m-%d')  loadDate,
+	d.sort tmrNo,
 	d.times loadShift,
 	d.tempid recipeId,
 	d.templetname recipeName,
 	f.feedcode ingId,
 	d1.fname ingName,
-	f.fclass ingType,
+	12 ingType,
 	f.dry dmPct,
 	d1.sort mixNo,
-	d1.feedallowratio allowableError,
+	d1.feedallowratio allowable_error,
 	d1.lweight expWeight,
 	d1.actualweightminus actualWeight,
-	d1.begintime startTime,
-	d1.intime endTime 
+	 	if((select  count(1) from downloadplandtl1  where pid = d.id and sort < d1.sort order by sort desc) >0 ,(select  DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadplandtl1  where pid = d.id and sort < d1.sort order by sort desc limit 1),DATE_FORMAT(d.intime,'%Y-%m-%d %H:%i:%s')  )   startTime,
+	 DATE_FORMAT(d1.intime,'%Y-%m-%d %H:%i:%s')  endTime ,	ifnull(if(d.driverId !=0 ,(select drivername from driver where id = d.driverId),(SELECT dr.driver FROM dutyrecord dr 
+	WHERE dr.pastureid = d.pastureid AND dr.eqid = d.tmrid and dr.times= d.times  AND dr.operatetime <=d.mydate 
+	ORDER BY dr.operatetime DESC LIMIT 1)),'')tmrName 
 FROM
 	downloadedplan d
 	JOIN downloadplandtl1 d1 ON d1.pid = d.id
 	JOIN feed f ON f.feedcode = d1.feedcode 
 	AND f.pastureid = d.pastureid 
 WHERE
-	DATE_FORMAT( d.mydate ,'%Y-%m-%d' ) = DATE_FORMAT(subdate(now(),1) ,'%Y-%m-%d' )`).Query().List()
+	DATE_FORMAT( d.mydate ,'%Y-%m-%d' ) = ?
+	`, date).QueryString()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -255,16 +267,17 @@ WHERE
 	pushStr := `{
 		"apiId": "getKPTData", 
 	   "param": {
-	   "farmId": %s, 
+	   "farmId":  "%s", 
 				 "method":"uploadadddata",
-				"rowCount": "1",
+				"rowCount": "%d",
 	   "resultData":%s
 		}
 	   }`
 	if len(dataList) > 0 {
 		b, _ := json.Marshal(dataList)
-		pushStr = fmt.Sprintf(pushStr, setting.YynserverSetting.FarmId, string(b))
+		pushStr = fmt.Sprintf(pushStr, setting.YynserverSetting.FarmId, len(dataList), string(b))
 		token := c.Publish(pubTopic, 2, false, pushStr)
+
 		fmt.Println("publish msg: ", pushStr, token.Error())
 		// token.Wait()
 		// time.Sleep(2 * time.Second)
@@ -272,30 +285,34 @@ WHERE
 }
 
 // 撒料信息
-func dustingPush(c MQTT.Client, pubTopic string) {
+func dustingPush(c MQTT.Client, pubTopic, date string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
 	dataList, err := tx.SQL(`SELECT
-	d.mydate dropDate,
-	d.projname tmrNo,
-	d.times loadShift,
-  d2.fbarid  penId,
-  b.bcode penName,
-	d2.cowcount cowCount,
-	d2.sort feedingNo,
-	d2.lweight expWeight,
-	d2.actualweightminus actualWeight,
-	d2.begintime startTime,
-	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()
+	ifnull(if(d.driverId !=0 ,(select drivername from driver where id = d.driverId),(SELECT dr.driver FROM dutyrecord dr 
+	WHERE dr.pastureid = d.pastureid AND dr.eqid = d.tmrid and dr.times= d.times  AND dr.operatetime <=d.mydate 
+	ORDER BY dr.operatetime DESC LIMIT 1)),'')tmrName ,
+		DATE_FORMAT(d.mydate,'%Y-%m-%d')   dropDate,
+		d.sort tmrNo,
+		d.times dropShift,
+	  d2.fbarid  penId,
+	  b.bname penName,
+		fp.ccount cowCount,
+		d2.sort feedingNo,
+		d2.lweight expWeight,
+		d2.actualweightminus actualWeight,
+		if((select  count(1) from downloadplandtl2  where pid = d.id and sort < d2.sort order by sort desc) >0 ,(select  DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadplandtl2  where pid = d.id and sort < d2.sort order by sort desc limit 1),  (select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadplandtl1  where pid = d.id order by sort desc limit 1) )  startTime,
+		  DATE_FORMAT(d2.intime,'%Y-%m-%d %H:%i:%s') endTime
+	FROM
+		downloadedplan d
+		JOIN downloadplandtl2 d2 ON d2.pid = d.id
+		JOIN bar b ON b.id = d2.fbarid 
+		join feedp fp on fp.barid = b.id
+		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).QueryString()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -304,15 +321,15 @@ WHERE
 	pushStr := `{
 		"apiId": "getKPTData", 
 		"param": {
-		"farmId": %s, 
+		"farmId":  "%s", 
 				  "method":"uploaddiliverdata",
-				  "rowCount": "1",
+				  "rowCount": "%d",
 		"resultData":%s
 		 }
 		}`
 	if len(dataList) > 0 {
 		b, _ := json.Marshal(dataList)
-		pushStr = fmt.Sprintf(pushStr, setting.YynserverSetting.FarmId, string(b))
+		pushStr = fmt.Sprintf(pushStr, setting.YynserverSetting.FarmId, len(dataList), string(b))
 		token := c.Publish(pubTopic, 2, false, pushStr)
 		fmt.Println("publish msg: ", pushStr, token.Error())
 		// token.Wait()
@@ -336,7 +353,7 @@ func deviceHeartbeat(c MQTT.Client, pubTopic string) {
 	device.AddFunc(spec1, func() {
 		token := c.Publish(pubTopic, 2, false, pushStr)
 		fmt.Println("publish msg: ", pushStr, token.Error(), time.Now())
-		token.Wait()
+		// token.Wait()
 	})
 	// }
 	device.Start()
@@ -344,23 +361,24 @@ func deviceHeartbeat(c MQTT.Client, pubTopic string) {
 }
 
 // 准确率
-func equipmentAccuracyPush(c MQTT.Client, pubTopic string) {
+func equipmentAccuracyPush(c MQTT.Client, pubTopic, date string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
 	dataList, err := tx.SQL(`SELECT
-	t.tname tname,
+	t.tname Name,
 	1-abs (
-	sum( d1.actualweightminus )- sum( d1.lweight ))/ sum( d1.lweight ) rate,
-	d.mydate rateDate 
+	sum( d1.actualweightminus )- sum( d1.lweight ))/ sum( d1.lweight ) Rate,
+	d.mydate RateDate ,  DATE_FORMAT(d.intime,'%Y-%m-%d %H:%i:%s') startTime,
+	(select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s')  from downloadplandtl2  where pid = d.id  order by sort desc limit 1) endTime
 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)
+	DATE_FORMAT( d.mydate, '%Y-%m-%d' ) = ?   and d.lpplantype in(0,1)
 GROUP BY
-	d.datacaptureno`).Query().List()
+	d.datacaptureno`, date).QueryString()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -370,7 +388,7 @@ GROUP BY
 		"apiId": "getKPTData",
 		"param": {
 			"resultData": %s,
-			"farmId": %s,         
+			"farmId":  "%s",        
 			"method": "uploadrate",          
 			"rowCount": %d                  
 		}
@@ -386,23 +404,21 @@ GROUP BY
 }
 
 // 完成重量
-func finishedWeightPush(c MQTT.Client, pubTopic string) {
+func finishedWeightPush(c MQTT.Client, pubTopic, date string) {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
 	dataList, err := tx.SQL(`SELECT
-	sum( d1.actualweightminus ) CompleteWeught,
+	sum( d1.actualweightminus ) completeWeight,
 	sum( d1.lweight ) planWeight,
-	d.mydate weightDate 
+	d.mydate weightDate ,  DATE_FORMAT(d.intime,'%Y-%m-%d %H:%i:%s') startTime,
+	(select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s')  from downloadedplan  where mydate = d.mydate and intime is not null order by sort desc limit 1) endTime
 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()
+	DATE_FORMAT( d.mydate, '%Y-%m-%d' ) =  ?   and lpplantype in(0,1)`, date).QueryString()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -412,7 +428,7 @@ WHERE
 		"apiId": "getKPTData",
 		"param": {
 			"resultData": %s,
-			"farmId": %s,          
+			"farmId": "%s",          
 			"method": "uploadweight",
 			"rowCount": "1"                 
 		}
@@ -428,13 +444,16 @@ WHERE
 }
 
 // 完成车次
-func CompletedTrainNumberPush(c MQTT.Client, pubTopic string) {
+func CompletedTrainNumberPush(c MQTT.Client, pubTopic, date 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' ) 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()
+	dataList, err := tx.SQL(`	select (select count(1) from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  ? and lpplantype in(0,1) )  planCar, 
+	(select count(1) from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  ? and iscompleted = 1 and lpplantype in(0,1)) CompleteCar ,
+	? carDate,
+	(select   DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s')  from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  ? and iscompleted = 1 and lpplantype in(0,1)  order by intime asc limit 1 ) startTime,
+		(select   DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s')  from downloadedplan  where  DATE_FORMAT(mydate ,'%Y-%m-%d' ) =  ? and iscompleted = 1 and lpplantype in(0,1) and intime is not null order by intime desc limit 1 ) endTime
+	`, date, date, date, date, date).QueryString()
 	if err != nil {
 		logs.Error("feedtempletPush-error-1:", err)
 		return
@@ -444,7 +463,7 @@ func CompletedTrainNumberPush(c MQTT.Client, pubTopic string) {
 		"apiId": "getKPTData",
 		"param": {
 			"resultData": %s,
-			"farmId": %s,       
+			"farmId":  "%s",      
 			"method": "uploadcarnumber",
 			"rowCount": "1"             
 		}

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

@@ -134,12 +134,12 @@ 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 30 8 * * *", func() {
+	// 	// 	//现代牧业sap同步
+	// 	// sap.SyncMaterialOutbound()
+	// 	// 	// 光明ud同步
+	// 	// 	fmt.Println(time.Now())
+	// 	gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// })
 	// xdmy.Start()
 	// InitMqttClient()

+ 5 - 5
http/handle/gm/udservice.go

@@ -20,12 +20,12 @@ 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) {
-	// UdMaterialIssuePush(pastureId, farmId, "")
-	// UdFeedtempletPush(pastureId, farmId, "")
-	// UdUtirPush(pastureId, farmId, "")
-	// UdBarFeedRemainPush(pastureId, farmId, "")
+	UdMaterialIssuePush(pastureId, farmId, "")
+	UdFeedtempletPush(pastureId, farmId, "")
+	UdUtirPush(pastureId, farmId, "")
+	UdBarFeedRemainPush(pastureId, farmId, "")
 
-	// UdBarSync(pastureId, farmId)
+	UdBarSync(pastureId, farmId)
 	UdFeedSync(pastureId, farmId)
 }
 

BIN
uploads.zip


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