Browse Source

Merge branch 'feature/new-scheduled' of baishaojie/tmrgo into develop

baishaojie 11 tháng trước cách đây
mục cha
commit
5eea9ac99a
45 tập tin đã thay đổi với 1928 bổ sung478 xóa
  1. BIN
      TMRWatchComm
  2. BIN
      TMRWatchComm.zip
  3. BIN
      __debug_bin.exe
  4. 7 8
      conf/app.ini
  5. BIN
      dist-tmr-20240619.zip
  6. BIN
      dist-tmr-20240619/dist/favicon.ico
  7. 0 0
      dist-tmr-20240619/dist/index.html
  8. 0 0
      dist-tmr-20240619/dist/static/css/app.ed733f4f.css
  9. 0 0
      dist-tmr-20240619/dist/static/css/chunk-elementUI.c1c3b808.css
  10. 0 0
      dist-tmr-20240619/dist/static/css/chunk-libs.f403b559.css
  11. BIN
      dist-tmr-20240619/dist/static/fonts/element-icons.535877f5.woff
  12. BIN
      dist-tmr-20240619/dist/static/fonts/element-icons.732389de.ttf
  13. BIN
      dist-tmr-20240619/dist/static/img/404.a57b6f31.png
  14. BIN
      dist-tmr-20240619/dist/static/img/404_cloud.0f4bc32b.png
  15. BIN
      dist-tmr-20240619/dist/static/img/guiji2.9dc0addf.jpeg
  16. 0 28
      dist-tmr-20240619/dist/static/img/iconfont.0ddaba12.svg
  17. BIN
      dist-tmr-20240619/dist/static/img/logo.afed751a.png
  18. BIN
      dist-tmr-20240619/dist/static/img/logo1.0121925c.png
  19. BIN
      dist-tmr-20240619/dist/static/img/logo_u3.3c77f543.png
  20. BIN
      dist-tmr-20240619/dist/static/img/nlogin-bg1.77301f56.jpg
  21. BIN
      dist-tmr-20240619/dist/static/img/row-bg3.b3be7548.png
  22. BIN
      dist-tmr-20240619/dist/static/img/topBg.69ecd1e1.png
  23. 0 0
      dist-tmr-20240619/dist/static/js/app.bf68639d.js
  24. 0 0
      dist-tmr-20240619/dist/static/js/chunk-4ab5740d.fd41fff9.js
  25. 0 0
      dist-tmr-20240619/dist/static/js/chunk-52ecc0ac.6e6c1552.js
  26. 0 0
      dist-tmr-20240619/dist/static/js/chunk-5c4dc4a9.8801e0b1.js
  27. 0 0
      dist-tmr-20240619/dist/static/js/chunk-b702d234.4563c788.js
  28. 0 0
      dist-tmr-20240619/dist/static/js/chunk-elementUI.c961dc79.js
  29. 0 0
      dist-tmr-20240619/dist/static/js/chunk-libs.de4daf58.js
  30. 0 0
      dist/index.html
  31. 0 0
      dist/static/css/app.58e1fb81.css
  32. 0 0
      dist/static/css/app.ed733f4f.css
  33. 0 0
      dist/static/js/app.bf68639d.js
  34. 0 0
      dist/static/js/app.ff8699cf.js
  35. 31 3
      http/handle/api/mqtt.go
  36. 947 410
      http/handle/api/ops.go
  37. 198 3
      http/handle/api/report.go
  38. 51 21
      http/handle/api/spillage.go
  39. 6 1
      http/handle/api/user.go
  40. 670 3
      http/handle/yq/yq.go
  41. 6 0
      http/routers/app_api.go
  42. 11 1
      update.sql
  43. BIN
      uploads/file/导入导出模板/配方计划/Spreading.xlsx
  44. BIN
      uploads/file/导入导出模板/配方计划/配方模板导入模板.xlsx
  45. 1 0
      yapi-mock.config.json

BIN
TMRWatchComm


BIN
TMRWatchComm.zip


BIN
__debug_bin.exe


+ 7 - 8
conf/app.ini

@@ -50,8 +50,8 @@ Type = mysql
 User = root
 Password = root
 #Host = 8.130.17.8:3306
-#Host = 192.168.1.93:3326
-Host = 127.0.0.1:3316
+Host = 192.168.1.93:3326
+#Host = 127.0.0.1:3316
 #Name = haiyuan
 #Password = root
 #Password = root
@@ -75,7 +75,7 @@ Host = 127.0.0.1:3316
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = tmrwatch2
+Name = tmrwatch5
 TablePrefix =
 
 ShowXormlog = false
@@ -92,12 +92,11 @@ Password =
 Name = 
 
 [yyn]
-FarmId = "1830002644"
+FarmId = "1830002083"
 ProductKey = "k03txxLKFae"
-DeviceName = "02644_p_breed"
-DeviceSecret = "e1e95a40758027c3a097d0bc5f3990e7"
-HeartBeat = "Tmr183000264402644_p_breed"
-
+DeviceName = "02083_p_breed"
+DeviceSecret = "018fe8318a1151fa44e6507b7b46ce7a"
+HeartBeat = "Tmr183000208302083_p_breed"
 
 
 [comm]

BIN
dist-tmr-20240619.zip


BIN
dist-tmr-20240619/dist/favicon.ico


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/index.html


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/css/app.ed733f4f.css


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/css/chunk-elementUI.c1c3b808.css


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/css/chunk-libs.f403b559.css


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


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


BIN
dist-tmr-20240619/dist/static/img/404.a57b6f31.png


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


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


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 28
dist-tmr-20240619/dist/static/img/iconfont.0ddaba12.svg


BIN
dist-tmr-20240619/dist/static/img/logo.afed751a.png


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


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


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


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


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


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/js/app.bf68639d.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/js/chunk-4ab5740d.fd41fff9.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/js/chunk-52ecc0ac.6e6c1552.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/js/chunk-5c4dc4a9.8801e0b1.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/js/chunk-b702d234.4563c788.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/js/chunk-elementUI.c961dc79.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist-tmr-20240619/dist/static/js/chunk-libs.de4daf58.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.html


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/css/app.58e1fb81.css


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/css/app.ed733f4f.css


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/app.bf68639d.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/static/js/app.ff8699cf.js


+ 31 - 3
http/handle/api/mqtt.go

@@ -9,23 +9,31 @@ import (
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
+	"net/http"
 	"os"
 	"strconv"
 	"time"
 
 	"tmr-watch/conf/setting"
 	"tmr-watch/http/handle/restful"
+	"tmr-watch/pkg/app"
+	"tmr-watch/pkg/e"
 	"tmr-watch/pkg/logging"
 
+	"github.com/Anderson-Lu/gofasion/gofasion"
 	"github.com/astaxie/beego/logs"
 	MQTT "github.com/eclipse/paho.mqtt.golang"
 	mqtt "github.com/eclipse/paho.mqtt.golang"
+	"github.com/gin-gonic/gin"
 	"github.com/robfig/cron"
 )
 
+var c mqtt.Client
+var pubTopic string
+
 func InitMqttClient() {
 	if setting.YynserverSetting.FarmId != "" {
-		c, pubTopic := MqttClient()
+		c, pubTopic = MqttClient()
 		deviceHeartbeat(c, pubTopic)
 
 		// i := 19
@@ -51,8 +59,8 @@ func InitMqttClient() {
 		// finishedWeightPush(c, pubTopic, now)
 		// feedtempletPush(c, pubTopic)
 		// CompletedTrainNumberPush(c, pubTopic, now)
-		stirPush(c, pubTopic, "2024-07-01")
-		dustingPush(c, pubTopic, "2024-07-01")
+		// stirPush(c, pubTopic, "2024-07-01")
+		// dustingPush(c, pubTopic, "2024-07-01")
 		// equipmentAccuracyPush(c, pubTopic, "2024-07-01")
 		// finishedWeightPush(c, pubTopic, "2024-07-01")
 		// feedtempletPush(c, pubTopic)
@@ -520,3 +528,23 @@ func feedHeatwatch(client MQTT.Client, msg MQTT.Message) {
 		}
 	}
 }
+
+func LabourStirPush(cq *gin.Context) {
+	appG := app.Gin{C: cq}
+	dataByte, _ := ioutil.ReadAll(cq.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	date := fsion.Get("date").ValueStr()
+
+	stirPush(c, pubTopic, date)
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}
+
+func LabourDustingPush(cq *gin.Context) {
+	appG := app.Gin{C: cq}
+	dataByte, _ := ioutil.ReadAll(cq.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	date := fsion.Get("date").ValueStr()
+
+	dustingPush(c, pubTopic, date)
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 947 - 410
http/handle/api/ops.go


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

@@ -167,11 +167,23 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 			// fmt.Println(flleight)
 		}
 		flleightint, _ := strconv.Atoi(flleight)
-		if sqlnamestr == "downloadPlanTSLJD" {
-			queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort3)
+		// getAccuracyV9English
+		languageStatus := GetLanguageStatus()
+
+		if languageStatus == "0" {
+			if sqlnamestr == "downloadPlanTSLJD" {
+				queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort3)
+			} else {
+				queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort) //投料简打、累加
+			}
 		} else {
-			queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort) //投料简打、累加
+			if sqlnamestr == "downloadPlanTSLJD" {
+				queryData, err = getAccuracyV9English(queryList, sqlnamestr, flleightint, feednamesort3)
+			} else {
+				queryData, err = getAccuracyV9English(queryList, sqlnamestr, flleightint, feednamesort) //投料简打、累加
+			}
 		}
+
 	default:
 		queryData, err = nil, nil
 	}
@@ -359,6 +371,189 @@ func getAccuracyV9(queryList []map[string]interface{}, sqlnamestr string, flleig
 	queryData["data"] = queryList
 	return queryData, nil
 }
+
+func getAccuracyV9English(queryList []map[string]interface{}, sqlnamestr string, flleightint int, feednamesort []string) (map[string]interface{}, error) {
+	queryData := make(map[string]interface{})
+
+	chartData := make(map[string]interface{})
+	mapc3 := make(map[string]interface{})
+	data2 := []interface{}{}
+	data1 := []interface{}{}
+
+	mapc3["label"] = "Batch"
+	mapc3["prop"] = "projname"
+	data1 = append(data1, mapc3)
+	mapc3 = make(map[string]interface{})
+
+	mapc3["label"] = "TMR"
+	mapc3["prop"] = "tmrtname"
+	data1 = append(data1, mapc3)
+	mapc3 = make(map[string]interface{})
+	//if sqlnamestr == "downloadPlanSFJD":
+
+	//mapc3["label"] = "时间"
+	//mapc3["prop"] = "plantime"
+	//data1 = append(data1, mapc3)
+	//mapc3 = make(map[string]interface{})
+	//
+	//mapc3["label"] = "班组"
+	//mapc3["prop"] = "times"
+	//data1 = append(data1, mapc3)
+	//mapc3 = make(map[string]interface{})
+	//
+	//mapc3["label"] = "驾驶员"
+	//mapc3["prop"] = "driver"
+	//data1 = append(data1, mapc3)
+	//mapc3 = make(map[string]interface{})
+	//
+	//mapc3["label"] = "日系数比例"
+	//mapc3["prop"] = "rate"
+	//data1 = append(data1, mapc3)
+	//mapc3 = make(map[string]interface{})
+	//
+	//mapc3["label"] = "牛头数"
+	//mapc3["prop"] = "feedpcount"
+	//data1 = append(data1, mapc3)
+	//mapc3 = make(map[string]interface{})
+	//
+	//mapc3["label"] = "配方模板"
+	//mapc3["prop"] = "templetname"
+	//data1 = append(data1, mapc3)
+	//mapc3 = make(map[string]interface{})
+
+	//#######################################################################################
+	mtem := make(map[interface{}]interface{})
+	var stem, feedNames []string
+
+	for _, feed := range feednamesort {
+		feed = strings.ReplaceAll(feed, " ", "")
+		mtem[feed] = struct{}{}
+		// fmt.Println(feed)
+		stem = append(stem, feed)
+	}
+
+	for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
+		// if _, ok := mtem[queryList[i]["fname"]]; ok {
+		// 	continue
+		// }
+
+		// stem = append(stem, queryList[i]["fname"].(string))
+		// mtem[queryList[i]["fname"]] = struct{}{}
+		feedNames = append(feedNames, queryList[i]["fname"].(string))
+
+	}
+	sort.Strings(feedNames)
+	for _, feed := range feedNames {
+		if _, ok := mtem[feed]; ok {
+			continue
+		}
+		// fmt.Println(feed)
+		stem = append(stem, feed)
+		mtem[feed] = struct{}{}
+	}
+
+	stemEnd := []string{}
+	if sqlnamestr == "downloadPlanSFJD" {
+		bb := stem[len(stem)-flleightint : len(stem) : len(stem)]
+		//aa := stem[0 : len(stem)-flleightint : len(stem)]
+		stemEnd = append(stemEnd, bb...)
+		stemEnd = append(stemEnd, feednamesort...)
+		//fmt.Println(stemEnd)
+	} else {
+		stemEnd = stem
+	}
+
+	//logging.Info("导出数据 ",stemEnd )
+
+	for _, va := range stemEnd {
+		mapc3["label"] = va
+		mapc3["prop"] = va
+		data1 = append(data1, mapc3)
+		mapc3 = make(map[string]interface{})
+	}
+	if queryList[0]["sumlweight"] != nil {
+		mapc3["label"] = "Sum"
+		mapc3["prop"] = "sumlweight"
+	}
+	data1 = append(data1, mapc3)
+	mapc3 = make(map[string]interface{})
+	var tem interface{}
+	mapc2 := make(map[string]interface{})
+	for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
+
+		if i == 0 {
+			tem = queryList[i]["projname"]
+			mapc2 = queryList[i]
+			if mapc2["sumlweight"] != nil {
+				var sumlweight float64
+				sumlweight, _ = strconv.ParseFloat(mapc2["sumlweight"].(string), 64)
+				mapc2["sumlweight"] = sumlweight
+			}
+
+			for key := range mtem {
+				mapc2[xorm.String(key)] = 0
+			}
+			// var lweight float64
+			if queryList[i]["lweight"] != nil {
+				// var error errors.Error
+				lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
+				if err == nil {
+					mapc2[xorm.String(queryList[i]["fname"])] = lweight
+				} else {
+					mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
+				}
+			} else {
+				mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
+			}
+
+		}
+		if tem == queryList[i]["projname"] {
+			// var lweight float64
+			if queryList[i]["lweight"] != nil {
+				lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
+				if err == nil {
+					mapc2[xorm.String(queryList[i]["fname"])] = lweight
+				} else {
+					mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
+				}
+			} else {
+				mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
+			}
+		} else {
+			data2 = append(data2, mapc2)
+			tem = queryList[i]["projname"]
+			mapc2 = queryList[i]
+			if mapc2["sumlweight"] != nil {
+				var sumlweight float64
+				sumlweight, _ = strconv.ParseFloat(mapc2["sumlweight"].(string), 64)
+				mapc2["sumlweight"] = sumlweight
+			}
+			for key := range mtem {
+				mapc2[xorm.String(key)] = 0
+			}
+			if queryList[i]["lweight"] != nil {
+				lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
+				if err == nil {
+					mapc2[xorm.String(queryList[i]["fname"])] = lweight
+				} else {
+					mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
+				}
+			} else {
+				mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
+			}
+		}
+	}
+
+	data2 = append(data2, mapc2)
+	chartData["data1"] = data1
+	chartData["data2"] = data2
+	queryData["list"] = chartData
+	queryData["code"] = 0
+	queryData["message"] = "ok"
+	queryData["data"] = queryList
+	return queryData, nil
+}
+
 func getAccuracyV8(queryList []map[string]interface{}) (map[string]interface{}, error) {
 	queryData := make(map[string]interface{})
 	chartData := make(map[string]interface{})

+ 51 - 21
http/handle/api/spillage.go

@@ -840,20 +840,35 @@ func GetSpillage(c *gin.Context) {
 	if refresh == 0 || refresh == 1 {
 		sqlstr := `   SELECT
 		ifnull((select eqcode from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),lpplan.tmrname) tmrname,trim(tmrid) tmrid,sort,sel,times timesInt,
-		CASE times
+		if( ifnull((select inforvalue from sysopt where inforname = 'language' and lpplan.pastureId),0) = 0 ,
+		CASE
+		lpplan.times
+						WHEN 1 THEN
+						'第一班'
+						WHEN 2 THEN
+						'第二班'
+						WHEN 3 THEN
+						'第三班'
+						WHEN 4 THEN
+						'第四班'
+										WHEN 5 THEN
+						'第五班'
+						WHEN 6 THEN
+						'第六班'
+				END ,CASE  lpplan.times
 		WHEN 1 THEN
-		'第一班'
-	WHEN 2 THEN
-	'第二班'
-	WHEN 3 THEN
-	'第三班'
-	WHEN 4 THEN
-	'第四班'
-	WHEN 5 THEN
-	'第五班'
-	WHEN 6 THEN
-	'第六班'
-	END timesstr,issplit,
+		'First Shift'
+		WHEN 2 THEN
+		'Second Shift'
+		WHEN 3 THEN
+		'Third Shift'
+		WHEN 4 THEN
+		'Fourth Shift'
+		WHEN 5 THEN
+		'Five Shift'
+		WHEN 6 THEN
+		'Six Shift'
+		END ) timesstr,issplit,
 	times,display,begintime,
 	(select tname from feedtemplet where pastureid =lpplan.pastureid and id = lpplan.ftid ) ftname,sumcowcount,
 	IFNULL(round((SELECT SUM(lpplandtl1.lweight) FROM lpplandtl1
@@ -1393,20 +1408,35 @@ GROUP BY fpd.ptsid`
 		lpplan.date,
 		-- ifnull((select eqcode from tmr where pastureid =lpplan.pastureid and id = lpplan.tmrid ),lpplan.tmrname) 
 		lpplan.tmrname tmrname,trim(lpplan.tmrid) tmrid,lpplan.sort,lpplan.sel,lpplan.times timesInt,
-		CASE lpplan.times
+		if( ifnull((select inforvalue from sysopt where inforname = 'language' and lpplan.pastureId),0) = 0 ,
+		CASE
+		lpplan.times
+						WHEN 1 THEN
+						'第一班'
+						WHEN 2 THEN
+						'第二班'
+						WHEN 3 THEN
+						'第三班'
+						WHEN 4 THEN
+						'第四班'
+										WHEN 5 THEN
+						'第五班'
+						WHEN 6 THEN
+						'第六班'
+				END ,CASE  lpplan.times
 		WHEN 1 THEN
-		'第一班'
+		'First Shift'
 		WHEN 2 THEN
-		'第二班'
+		'Second Shift'
 		WHEN 3 THEN
-		'第三班'
+		'Third Shift'
 		WHEN 4 THEN
-		'第四班'
+		'Fourth Shift'
 		WHEN 5 THEN
-		'第五班'
+		'Five Shift'
 		WHEN 6 THEN
-		'第六班'
-		END timesstr,issplit,
+		'Six Shift'
+		END ) timesstr,issplit,
 		lpplan.times,display,begintime,
 		(select tname from feedtemplet where pastureid =lpplan.pastureid and id = lpplan.ftid ) ftname,sumcowcount,
 		IFNULL(round((SELECT SUM(lpplandtl1.lweight) FROM lpplandtl1date  lpplandtl1 WHERE lpplandtl1.lppid=lpplan.id and lpplandtl1.date= ?),2),0) sumweight ,

+ 6 - 1
http/handle/api/user.go

@@ -59,7 +59,12 @@ func Auth(c *gin.Context) {
 	if !isExist {
 		isExist, err = authService.MD5Check()
 		if !isExist {
-			appG.Response(http.StatusOK, e.ERROR_AUTH, "密码错误!")
+			status := GetLanguageStatus()
+			if status == "0" {
+				appG.Response(http.StatusOK, e.ERROR_AUTH, "密码错误!")
+			} else {
+				appG.Response(http.StatusOK, e.ERROR_AUTH, "Password error!")
+			}
 			return
 		}
 	}

+ 670 - 3
http/handle/yq/yq.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"strconv"
 	"strings"
 	"time"
 	"tmr-watch/conf/setting"
@@ -37,7 +38,7 @@ func YqCron() {
 	}
 
 	token := getToken()
-	fmt.Println("aaaaaaaaaaaa   ", token)
+	syncBar(token, pastureinfo.Pastureid, pastureinfo.Werks)
 	c := cron.New()
 	c.AddFunc("0 0 1 * * *", func() {
 		token := getToken()
@@ -48,6 +49,7 @@ func YqCron() {
 		YcUtirPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcMaterialIssuePush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
 		YcBarFeedRemainPush(pastureinfo.Pastureid, pastureinfo.Werks, now, token)
+		syncBar(token, pastureinfo.Pastureid, pastureinfo.Werks)
 	})
 
 	c.AddFunc("0 0 6 * * *", func() {
@@ -133,7 +135,7 @@ func getToken() string {
 	apiKey := "3c6bbff8cf1e496eb8eb9025cd8537fh"
 	secretKey := "26b5d9f63b6142de8f102afb1aa2eb7g"
 
-	req, err := http.NewRequest("POST", "https://test.vmuyun.com/base-server/outSide/token", nil)
+	req, err := http.NewRequest("POST", "https://vmuyun.com/base-server/outSide/token", nil)
 	if err != nil {
 		logs.Error(err)
 	}
@@ -170,7 +172,7 @@ func getToken() string {
 func postPush(data string, msgtype int, tx *xorm.Session, pastureId, token string) {
 
 	// jsonStr, _ := json.Marshal(data)
-	url := "https://test.vmuyun.com/project-server/openApi/feeding/pushData"
+	url := "https://vmuyun.com/project-server/openApi/feeding/pushData"
 	req, err := http.NewRequest("POST", url, strings.NewReader((data)))
 	if err != nil {
 		logs.Error(err)
@@ -552,3 +554,668 @@ func YcMaterialIssuePush(pastureId, farmId, date, token string) error {
 	fmt.Println(reqJson)
 	return nil
 }
+
+func syncBar(token, pastureid, werks string) {
+	req, err := http.NewRequest("GET", "https://vmuyun.com/project-server/openApi/feeding/penList", nil)
+	if err != nil {
+		logs.Error(err)
+		// return nil
+	}
+	req.Header.Set("Authorization", token)
+	req.Header.Set("Content-Type", "application/json")
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		logs.Error(err)
+		return
+	}
+	defer resp.Body.Close()
+
+	body, _ := ioutil.ReadAll(resp.Body)
+	data := make(map[string]interface{}, 0)
+	json.Unmarshal(body, &data)
+	dataList := data["data"].([]interface{})
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	for _, item := range dataList {
+		arg := item.(map[string]interface{})
+		fmt.Println(arg)
+		if fmt.Sprintf("%v", arg["farmId"]) == werks {
+			_, err := tx.Exec(` insert into bar(pen,bname,bcode,pastureid)values(?,?,?,?)  ON DUPLICATE KEY UPDATE  pen = ? `, arg["districtName"],
+				fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), pastureid, arg["houseName"])
+			fmt.Println(err)
+
+			// insertSql := `insert into feedp(pastureid,barname,barid,ccount)VALUES(?,?,(select id from bar where bname = ?),?)
+			// 	ON DUPLICATE KEY UPDATE ccount = ? ,barname = ?  `
+			// _, err = tx.SQL(insertSql, pastureid, fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]),
+			// 	fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"]), arg["sheepCount"], arg["sheepCount"],
+			// 	fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])).Execute()
+			// fmt.Println(err)
+			// tx.SQL(` select  from feedp where barname = ? `)
+
+			// barList := make([]*bar,0)
+			// b := new(bar)
+			// b.BarName = fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])
+			// b.Ccount = arg["sheepCount"]
+			// 	err = tx.SQL(`	select fp.barname,fp.ccount,ratio,ft.tname ftname,ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 1 ),0) times1,
+			// ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 2 ),0) times2 ,
+			// ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 3 ),0) times3 ,
+			// ifnull((select tratio from fpdetail  where barid = fp.barid  and times = 4 ),0) times4 ,
+			// ifnull((select tratio from fpdetail  where barid = fp.barid  and times =5 ),0) times5  ,
+			// ifnull((select tratio from fpdetail  where barid = fp.barid  and times =6 ),0) times6
+			//  from feedp fp  join feedtemplet ft on ft.id = fp.ftid  where ratio > 0 and fp.barname = ? `, fmt.Sprintf("%v-%v", arg["houseName"], arg["compartmentName"])).GetFirst(b).Error
+			// fmt.Println(err)
+			// fpdBatchEdit(pastureid, b)
+			// {"pastureId":"1653271339","barList":[{"barname":"14","ccount":155,"ratio":"100.00","ftname":"高产2配方",
+			// "times1":"41","times2":"25","times3":"25","times4":0,"times5":0,"times6":0}]}
+		}
+	}
+}
+
+type bar struct {
+	BarName string  `xorm:"barname"`
+	Ccount  string  `xorm:"ccount"`
+	Ratio   string  `xorm:"ratio"`
+	Ftname  string  `xorm:"ftname"`
+	Times1  float64 `xorm:"times1"`
+	Times2  float64 `xorm:"times2"`
+	Times3  float64 `xorm:"times3"`
+	Times4  float64 `xorm:"times4"`
+	Times5  float64 `xorm:"times5"`
+	Times6  float64 `xorm:"times6"`
+}
+
+func fpdBatchEdit(pastureid string, b *bar) {
+
+	// appG := app.Gin{C: c}
+	// dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	// fsions := gofasion.NewFasion(string(dataByte))
+	// barList := fsions.Get("barList").Array()
+	// pastureid := fsions.Get("pastureId").ValueStr()
+
+	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 _, barFsions := range barList {
+
+	dataexcel := make(map[string]interface{}, 0)
+	dataexcel["barname"] = b.BarName
+	dataexcel["ccount"] = b.Ccount
+	dataexcel["ratio"] = b.Ratio
+	dataexcel["ftname"] = b.Ftname
+	// dataexcel["ptsfname"] = barFsions.Get("ptsfname").ValueStr()
+	if dataexcel["ftname"] == "" || dataexcel["ccount"] == "0" || dataexcel["ratio"] == "0" {
+		return
+	}
+
+	dataexcel["1"] = b.Times1
+	dataexcel["2"] = b.Times2
+	dataexcel["3"] = b.Times3
+	dataexcel["4"] = b.Times4
+	dataexcel["5"] = b.Times5
+	dataexcel["6"] = b.Times6
+
+	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 = (select sum(fweight) fweight from ftdetail 
+	where  ftid = (select  id from feedtemplet  where tname = ? and pastureid = ?  )) *  (?*(?*0.01))`
+		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 {
+		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 {
+		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 {
+		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 {
+		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 {
+		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 {
+		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"].(string), upFpdetailList)
+}
+
+type lpplandtlInfo struct {
+	Id          int64   `xorm:"id"`
+	Pastureid   int64   `xorm:"pastureid"`
+	Lppid       int64   `xorm:"lppid"`
+	Barid       int64   `xorm:"barid"`
+	Barname     string  `xorm:"barname"`
+	Fpdid       int64   `xorm:"fpdid"`
+	Fttype      int64   `xorm:"fttype"`
+	Lweight     float64 `xorm:"lweight"`
+	Sort        int64   `xorm:"sort"`
+	Tmrid       int64   `xorm:"tmrid"`
+	Tmrname     string  `xorm:"tmrname"`
+	Cowcount    int64   `xorm:"cowcount"`
+	Ccountradio float64 `xorm:"ccountradio"`
+	Background  string  `xorm:"background"`
+	Lweighthis  float64 `xorm:"lweighthis"`
+	Maxweight   float64 `xorm:"maxweight"`
+}
+
+type upFpdetail struct {
+	Old     float64
+	New     float64
+	Times   int64
+	Ptid    int64
+	Fweight float64
+	Id      int64
+}
+
+func updateFpdetailByBar(pastureid, barname string, dataList []*upFpdetail) error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	tx.Begin()
+
+	fpdList, err := tx.SQL(` select  id,ifnull(ROUND((1-ifnull(ptsrate,0))*weight,2),"") weight,ptuse,times  from fpdetail where pastureid = ?  and barname = ? order by times `,
+		pastureid, barname).Query().List()
+	if err != nil {
+		logs.Error(err)
+	}
+
+	for _, fpd := range fpdList {
+
+		lpplandList, err := tx.SQL(` select  lppland.id,ifnull(lppland.lweight,0) lweight from lpplandtl1 lppland join lpplan lpp on lpp.id = lppland.lppid 
+where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by lpp.sort desc  `,
+			pastureid, fpd["id"], fpd["times"]).Query().List()
+		if err != nil {
+			tx.Rollback()
+			logs.Error(err)
+			return err
+		}
+		var lweight float64
+		for _, lppland := range lpplandList {
+			lweight1, _ := strconv.ParseFloat(lppland["lweight"].(string), 64)
+			lweight += lweight1
+		}
+
+		fpdweight, _ := strconv.ParseFloat(fpd["weight"].(string), 64)
+		ptuse, _ := strconv.ParseFloat(fpd["ptuse"].(string), 64)
+
+		if fpdweight >= ptuse && lweight == ptuse {
+			continue
+		} else {
+			if lweight <= fpdweight {
+				_, err := tx.SQL(` update fpdetail set ptuse = ?  where id = ? `, lweight, fpd["id"]).Execute()
+				if err != nil {
+					tx.Rollback()
+					logs.Error(err)
+					return err
+				}
+			} else {
+				weight := lweight - fpdweight
+				_, err = tx.SQL(`UPDATE fpdetail SET ptuse=? 
+				WHERE pastureid=? AND id=?`, fpdweight, pastureid, fpd["id"]).Execute()
+				if err != nil {
+					tx.Rollback()
+					logs.Error(err)
+					return err
+				}
+
+				for _, lppland := range lpplandList {
+					lpplandlweight, _ := strconv.ParseFloat(lppland["lweight"].(string), 64)
+					if weight >= lpplandlweight {
+						weight = weight - lpplandlweight
+						_, err := tx.SQL(` delete from  lpplandtl1  where id = ? `, lppland["id"]).Execute()
+						if err != nil {
+							tx.Rollback()
+							logs.Error(err)
+							return err
+						}
+					} else {
+						lpplandlweight, _ := strconv.ParseFloat(lppland["lweight"].(string), 64)
+						_, err := tx.SQL(` update   lpplandtl1 set lweight = ? where id = ? `, lpplandlweight-weight, lppland["id"]).Execute()
+						if err != nil {
+							tx.Rollback()
+							logs.Error(err)
+							return err
+						}
+						weight = 0
+						break
+					}
+				}
+			}
+		}
+	}
+
+	for _, list := range dataList {
+		ftmap := make(map[string]interface{})
+		ftmap["old"] = list.Old
+		ftmap["new"] = list.New
+		ftmap["times"] = list.Times
+		ftmap["ptid"] = strconv.FormatInt(list.Ptid, 10)
+		ftmap["ptsid"] = ""
+		// fmt.Println(ftmap)
+		// select * from (SELECT TRIM(id) id,times,tratio,ifnull(ROUND(ptsrate*weight,2)-ptsuse,"") weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,
+		// (select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,concat(0) AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
+		// WHERE fpdetail.pastureid = ?   and barname = ? and  times = ?
+		// UNION
+		fpdDataList, err := tx.SQL(`
+			SELECT TRIM(id) id,times,tratio,ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,"") weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM(ptid) ptid,TRIM(ptsid ) ptsid ,
+			(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,concat(1) AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
+			WHERE fpdetail.pastureid = ?  and barname = ? and  times = ? `, pastureid, barname, ftmap["times"]).Query().List()
+		// fmt.Println(pastureid, id, ftmap["times"], pastureid, id, ftmap["times"])
+		if err != nil {
+			tx.Rollback()
+			logs.Error(err)
+		}
+		for _, fpd := range fpdDataList {
+			if fpd["times"].(int64) == ftmap["times"].(int64) && (fpd["ptid"].(string) == ftmap["ptid"].(string) || fpd["ptsid"].(string) == ftmap["ptsid"].(string)) {
+				// fttype := -1
+				// if fpd["fttype"].(string) == "1" {
+				fttype := 1
+				// }
+
+				var fweight float64
+				var lweight float64
+				lpplandtl1List := make([]*lpplandtlInfo, 0)
+				err = tx.SQL(`select lppland.*,t.maxstirfeed  maxweight from lpplan lpp
+					join lpplandtl1 lppland on lpp.id = lppland.lppid  
+					join tmr t on t.id = lpp.tmrid
+					where lppland.fpdid =?
+					and lppland.fttype = ? and lpp.pastureid = ?  and lpp.times  = ? order by lpp.sort desc `,
+					fpd["id"], fttype, pastureid, ftmap["times"]).Find(&lpplandtl1List)
+				if err != nil {
+					tx.Rollback()
+					logs.Error(err)
+				}
+				// [map[barid:4719430583171155825 barname:泌乳1-5西 ccountradio:131 cowcount:30 fttype:0 id:4828050527277810688 isfill:1 pastureid:1705635208 ptid:83
+				//  ptsid:-1 times:1 tratio:48.000 weight:0.00] map[barid:4719430583171155825
+				//  barname:泌乳1-5西 ccountradio:131 cowcount:30 fttype:1 id:4828050527277810688 isfill:0 pastureid:1705635208 ptid:83 ptsid:-1 times:1 tratio:48.000 weight:32.0
+				weight, _ := strconv.ParseFloat(fpd["weight"].(string), 64)
+
+				var w float64
+				var status int
+
+				if ftmap["new"].(float64) < ftmap["old"].(float64) && weight <= 0 {
+					if weight >= 0 {
+						continue
+					}
+					w = weight
+					status = 0
+				} else {
+					// if weight-(ftmap["new"].(float64)-ftmap["old"].(float64)) > 0 {
+					// 	continue
+					// }
+					w = weight
+					status = 1
+				}
+
+				// for _, lppland := range lpplandtl1List {
+				// 	lweight += lppland.Lweight
+				// }
+
+				for _, lppland := range lpplandtl1List {
+					lpplandInfo := new(lpplandtlInfo)
+					err := tx.SQL(` select ifnull(sum(lweight),0) lweight from lpplandtl1  where lppid = ? `, lppland.Lppid).GetFirst(lpplandInfo).Error
+					lweight = lpplandInfo.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
+						}
+
+					}
+
+					if 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
+						}
+					} else {
+						_, err = tx.SQL(`delete from  lpplandtl1    where id = ? and pastureid = ?`, lppland.Id, pastureid).Execute()
+						if err != nil {
+							tx.Rollback()
+							logs.Error(err)
+							return err
+						}
+					}
+					if w == 0 {
+						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, fpd["id"]).Execute()
+				if err != nil {
+					tx.Rollback()
+					logs.Error(err)
+				}
+				if w == 0 {
+					break
+				}
+			}
+
+		}
+	}
+
+	err = tx.Commit()
+	if err != nil {
+		logs.Error(err)
+		tx.Rollback()
+		return err
+	}
+
+	now := time.Now()
+	newLpplandtl1List, err := tx.SQL(` select  lppland.* from lpplandtl1  lppland   where lppland.barname = ?  and pastureid = ? `, barname, pastureid).Query().List()
+	if err != nil {
+		logs.Error(err)
+		return nil
+	}
+
+	newFpdDataList, err := tx.SQL(` select *  from fpdetail where barname = ?  and pastureid = ?  `, barname, pastureid).Query().List()
+	if err != nil {
+		logs.Error(err)
+		return nil
+	}
+
+	newFeedpList, err := tx.SQL(` select *  from feedp    where barname = ?  and pastureid = ?  `, barname, pastureid).Query().List()
+	if err != nil {
+		logs.Error(err)
+		return nil
+	}
+
+	for _, newLpplandtl1 := range newLpplandtl1List {
+		_, err := tx.SQL(` insert into lpplandtl1history(pastureid,lppid,barid,barname,fpdid,fttype,lweight,sort,tmrid,tmrname,
+						background,cowcount,ccountradio,lweighthis,createdate)
+					values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
+			newLpplandtl1["pastureid"], newLpplandtl1["lppid"], newLpplandtl1["barid"],
+			newLpplandtl1["barname"], newLpplandtl1["fpdid"], newLpplandtl1["fttype"],
+			newLpplandtl1["lweight"], newLpplandtl1["sort"], newLpplandtl1["tmrid"],
+			newLpplandtl1["tmrname"], newLpplandtl1["background"], newLpplandtl1["cowcount"],
+			newLpplandtl1["ccountradio"], newLpplandtl1["lweighthis"], now).Execute()
+		if err != nil {
+			logs.Error(err)
+			// appG.Response(http.StatusOK, e.ERROR, false)
+			return err
+		}
+	}
+
+	for _, newFpd := range newFpdDataList {
+		_, err := tx.SQL(` insert into fpdetailhistory(pastureid,barid,barname,times,tratio,weight,ptsrate,cowcount,ccountradio,ptid,ptsid,ptuse,ptsuse,supplement,createdate)
+					 values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, newFpd["pastureid"], newFpd["barid"], newFpd["barname"], newFpd["times"],
+			newFpd["tratio"], newFpd["weight"], newFpd["ptsrate"], newFpd["cowcount"], newFpd["ccountradio"],
+			newFpd["ptid"], newFpd["ptsid"], newFpd["ptuse"], newFpd["ptsuse"], newFpd["supplement"], now).Execute()
+		if err != nil {
+			logs.Error(err)
+			// appG.Response(http.StatusOK, e.ERROR, false)
+			return err
+		}
+	}
+	for _, newFeedp := range newFeedpList {
+		_, err := tx.SQL(` insert into feedphistory(pastureid,barname,barid,softccount,ccount,ratio,ccountratio,ftid,
+					ftname,ptsfid,ptsfname,feedweight,ftweight,supplyweight,owner,createdate)
+				values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
+			newFeedp["pastureid"], newFeedp["barname"], newFeedp["barid"],
+			newFeedp["softccount"], newFeedp["ccount"], newFeedp["ratio"],
+			newFeedp["ccountratio"], newFeedp["ftid"], newFeedp["ftname"],
+			newFeedp["ptsfid"], newFeedp["ptsfname"], newFeedp["feedweight"],
+			newFeedp["ftweight"], newFeedp["supplyweight"], newFeedp["owner"], now).Execute()
+		if err != nil {
+			logs.Error(err)
+			// appG.Response(http.StatusOK, e.ERROR, false)
+			return err
+		}
+	}
+
+	return nil
+}

+ 6 - 0
http/routers/app_api.go

@@ -45,6 +45,7 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 
 		s.GET("/getData", api.GetWxCode)
 		s.GET("/getData/yq", api.GetYqWxCode)
+		s.POST("/language/edit", api.EditLanguage)
 
 		s.POST("/userwxopenid/binding", api.UserWXOpenIDBinding)
 
@@ -243,6 +244,11 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 			apiV1.POST("/surplus/del", api.DelSurplus)
 			apiV1.GET("/surplus/list", api.GetelSurplus)
 
+			// 云养牛搅拌上传
+			apiV1.POST("/stir/yyn/upload", api.LabourStirPush)
+			// 云养牛撒料上传
+			apiV1.POST("/dusting/yyn/upload", api.LabourDustingPush)
+
 		}
 
 		//不需要登录验证的接口

+ 11 - 1
update.sql

@@ -362,4 +362,14 @@ ALTER TABLE `downloadplandtl1_exec`
 ADD COLUMN `surplus` decimal(10, 2) NULL COMMENT '剩料重量' AFTER `xxwFeedCode`;
 
 
-INSERT INTO `dictlist` ( `pid`, `pastureId`, `label`, `value`, `orderby`, `enable`) VALUES ( 19, NULL, '剩料', '5', NULL, 1);
+INSERT INTO `dictlist` ( `pid`, `pastureId`, `label`, `value`, `orderby`, `enable`) VALUES ( 19, NULL, '剩料', '5', NULL, 1);
+
+
+
+INSERT INTO sysopt (`id`, `pastureid`, `inforname`, `inforvalue`)
+ VALUES (3029240269385600831,(select column_default  as pastureid from    information_schema.COLUMNS
+	WHERE table_name = 'recweight' AND table_schema = 'tmrwatch2' AND column_name = 'pastureid'), 'language', '0');
+
+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');

BIN
uploads/file/导入导出模板/配方计划/Spreading.xlsx


BIN
uploads/file/导入导出模板/配方计划/配方模板导入模板.xlsx


+ 1 - 0
yapi-mock.config.json

@@ -0,0 +1 @@
+{"baseUrl":"https://yapi.example.com","apiMap":[{"projectId":1,"apiPrefix":"/example1","token":"example1TokenString"},{"projectId":2,"apiPrefix":["/example2","/example3"],"token":"example2TokenString"}],"proxy":{"targets":[{"name":"开发环境","target":"https://dev.example.com"},{"name":"测试环境","target":"https://test.example.com"},{"name":"生产环境","target":"https://prod.example.com"}],"port":10240}}

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác