Browse Source

圣牧优化更新

baishaojie 1 year ago
parent
commit
ffe724c489

BIN
TMRWatchComm.zip


BIN
TMRWatchComm → __debug_bin.exe


+ 1 - 5
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 = tmrwatch30
+Name = sfmc1
 TablePrefix =
 
 ShowXormlog = false
@@ -109,7 +109,3 @@ MinimumReadSize = 0
 
 
 
-
-
-
-

BIN
dist/favicon.ico


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


File diff suppressed because it is too large
+ 0 - 0
dist/static/css/app.ab9c28b7.css


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


File diff suppressed because it is too large
+ 0 - 0
dist/static/css/chunk-libs.1664ae71.css


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


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


BIN
dist/static/img/404.a57b6f31.png


BIN
dist/static/img/404_cloud.0f4bc32b.png


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


BIN
dist/static/img/logo.afed751a.png


BIN
dist/static/img/logo1.0121925c.png


BIN
dist/static/img/logo_u3.3c77f543.png


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


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


BIN
dist/static/img/topBg.69ecd1e1.png


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/app.efd6406b.js


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


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


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


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


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


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-libs.c399c5fe.js


+ 214 - 86
http/handle/api/chart.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"sort"
 	"strconv"
 	"time"
 
@@ -26,55 +27,33 @@ func GetFeedEffMR(c *gin.Context) {
 	startDate := parammaps.Get("startTime").ValueStr()
 	endDate := parammaps.Get("stopTime").ValueStr()
 	pastureId := parammaps.Get("pastureid").ValueStr()
+	bigcowclass := parammaps.Get("bigcowclass").ValueStr()
 
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	var sqlStr = `SELECT ROUND(IFNULL(SUM(d2.actualweightminus
-		* (SELECT AVG(actweight) FROM ftdry fd WHERE fd.pastureid = d2.pastureid AND fd.barid = d2.fbarid
-		AND fd.operatetime = (SELECT MAX(operatetime) FROM ftdry fd1 WHERE fd1.pastureid =  d2.pastureid
-		AND fd1.barid = d2.fbarid AND fd1.operatetime <=d2.date ))
-		),0),2) field1,
-		ROUND(IFNULL(
-		(SELECT SUM(bm.product*bm.cowsum) FROM
-		(SELECT DISTINCT d21.fbarid,d21.date,d21.pastureid,d21.fname,IFNULL(d21.cowclassid,-1)cowclassid FROM
-		downloadedplan d1
-		JOIN downloadplandtl2 d21
-		ON d21.pastureid = d1.pastureid AND d21.pid = d1.id
-		WHERE   d1.mydate between ? and ? AND d1.pastureid =? AND d1.lpplantype IN (0,1,2,5) AND d21.type = 0
-		) ww
-		LEFT JOIN barmilk bm
-		ON bm.pastureid =ww.pastureid AND bm.barid = ww.fbarid AND bm.productdate
-		=
-		(
-		SELECT MAX(productdate) FROM barmilk
-		WHERE barmilk.productdate <= ww.date
-		AND barmilk.pastureid = ww.pastureid
-		AND barmilk.barid = ww.fbarid
-		)
-		WHERE  ww.date = d.mydate and bm.bigcowclass = '泌乳牛'
-		)
-		,0),2) field2, -- 产奶量
-		%s 日期
-		FROM
-		 downloadedplan d
-		LEFT JOIN downloadplandtl2 d2
-		ON d2.pastureid = d.pastureid AND d2.pid = d.id
-	
-		LEFT JOIN barmilk bm
-		ON bm.pastureid =d.pastureid AND bm.barid = d2.fbarid AND bm.productdate =
-		(SELECT MAX(productdate) FROM barmilk WHERE barmilk.productdate <=d.mydate 
-		AND barmilk.pastureid = d.pastureid AND  barmilk.barid = d2.fbarid)
-	
-		WHERE d.pastureid = ? AND d.mydate BETWEEN ? AND ? AND d.lpplantype IN (0,1,2,5) AND d2.type = 0
-		AND bm.bigcowclass = '泌乳牛'`
+	var sqlStr = `SELECT 		ROUND(IFNULL(SUM((select sum(actualweightminus) from downloadplandtl2  where fbarid = d.barid  and date = d.date)
+	* (SELECT AVG(actweight) FROM ftdry fd WHERE fd.pastureid = d.pastureid AND fd.barid = d.barid
+	AND fd.operatetime = (SELECT MAX(operatetime) FROM ftdry fd1 WHERE fd1.pastureid =  d.pastureid
+	AND fd1.barid = d.barid AND fd1.operatetime <=d.date ))
+	),0),2) field1,
+round( sum(ifnull(bm.product*bm.cowsum,0)),2) field2, -- 产奶量
+%s 日期,(select tname from feedtempletdate  where date = d.date and id = d.ftid) 名称
+	FROM
+	 feedpdate d
+	join feedtempletdate  ftd on d.ftid = ftd.id and ftd.date = d.date
+	LEFT JOIN barmilk bm
+	ON bm.pastureid =d.pastureid AND bm.barid = d.barid AND bm.productdate = d.date
+	join cowclass cc on cc.id = bm.cowclassid 
+	WHERE  d.date BETWEEN ? AND ?  and d.pastureid = ?
+and (cc.classname = ? or ? = '' )  `
 
 	var data []map[string]interface{}
 	var err error
 	if status == "0" {
-		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.mydate, '%Y-%m-%d') ")
-		sqlStr += " GROUP BY DATE_FORMAT(d.mydate, '%Y-%m-%d')  ORDER BY  d.mydate "
-		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, pastureId, startDate, endDate).Query().List()
+		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.date, '%Y-%m-%d') ")
+		sqlStr += " GROUP BY  d.ftid,DATE_FORMAT(d.date, '%Y-%m-%d')  ORDER BY   d.date ,d.ftid"
+		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, bigcowclass, bigcowclass).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -90,19 +69,19 @@ func GetFeedEffMR(c *gin.Context) {
 			week = int(start.Weekday()) - 1
 		}
 
-		sqlStr = fmt.Sprintf(sqlStr, "FLOOR( (( DATEDIFF(mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
-		sqlStr += " GROUP BY 日期  ORDER BY  d.mydate "
-		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, pastureId, startDate, endDate).Query().List()
+		sqlStr = fmt.Sprintf(sqlStr, "FLOOR( (( DATEDIFF(d.date,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
+		sqlStr += " GROUP BY  d.ftid,日期  ORDER BY  d.ftid, d.date "
+		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, bigcowclass, bigcowclass).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
 		}
 
 	} else {
-		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.mydate, '%Y-%m') ")
-		sqlStr += " GROUP BY MONTH(d.mydate)  ORDER BY  d.mydate "
+		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.date, '%Y-%m') ")
+		sqlStr += " GROUP BY  d.ftid,MONTH(d.date)  ORDER BY   d.ftid,d.date "
 
-		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, pastureId, startDate, endDate).Query().List()
+		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, bigcowclass, bigcowclass).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
 			appG.Response(http.StatusInternalServerError, e.ERROR, err)
@@ -110,7 +89,93 @@ func GetFeedEffMR(c *gin.Context) {
 
 	}
 
-	queryData, err := getAccuracyV2(data)
+	queryData := make(map[string]interface{}, 0)
+
+	// if status == "0" {
+	// dateMap := make(map[string]bool)
+	// ftMap := make(map[string]bool)
+	var ftname []string
+	var dates []string
+	for _, item := range data {
+		// dateMap[item["日期"].(string)] = true
+		// ftMap[item["名称"].(string)] = true
+		if len(ftname) == 0 {
+			ftname = append(ftname, item["名称"].(string))
+		}
+		if len(dates) == 0 {
+			dates = append(dates, item["日期"].(string))
+		}
+
+		dateExist := false
+		ftExist := false
+		for _, date := range dates {
+			if date == item["日期"].(string) {
+				dateExist = true
+				break
+			}
+		}
+		if !dateExist {
+			dates = append(dates, item["日期"].(string))
+		}
+
+		for _, tname := range ftname {
+			if tname == item["名称"].(string) {
+				ftExist = true
+				break
+			}
+		}
+		if !ftExist {
+			ftname = append(ftname, item["名称"].(string))
+		}
+
+	}
+
+	var dataArr1 []interface{}
+	var dataArr2 []interface{}
+	sort.Strings(dates)
+	for _, tname := range ftname {
+		var field1 []interface{}
+		var field2 []interface{}
+
+		for _, date := range dates {
+			exist := false
+			for _, item := range data {
+				if item["日期"].(string) == date && item["名称"].(string) == tname {
+					exist = true
+					field1 = append(field1, item["field1"])
+					field2 = append(field2, item["field2"])
+					break
+				}
+			}
+			if !exist {
+				field1 = append(field1, "0")
+				field2 = append(field2, 0)
+			}
+		}
+		dataArr1 = append(dataArr1, field1)
+		dataArr2 = append(dataArr2, field2)
+	}
+
+	for _, item := range data {
+		if _, ok := item["field1"]; ok {
+			item["采食量"] = item["field1"]
+		} else {
+			item["采食量"] = "0"
+		}
+		if _, ok := item["field2"]; ok {
+			item["产奶量"] = item["field2"]
+		} else {
+			item["产奶量"] = 0
+		}
+	}
+	queryData["dataArr1"] = dataArr1
+	queryData["dataArr2"] = dataArr2
+	queryData["date"] = dates
+	queryData["ftname"] = ftname
+	queryData["data"] = data
+	// }
+
+	// queryData, err := getAccuracyV2(data)
 	appG.Response(http.StatusOK, e.SUCCESS, queryData)
 }
 
@@ -211,25 +276,27 @@ func GetFeedEffSL(c *gin.Context) {
 	ft.tname  名称,
 	IFNULL(SUM(d2.actualweightminus),0) 撒料量,
 	IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = ft.pastureid AND bf.barid = fp.barid AND bf.remaindate = fp.date),0) 剩料量,
-	ifnull(ROUND(IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = fp.pastureid AND bf.barid = fp.barid AND bf.remaindate = fp.date),0)/SUM(d2.actualweightminus),2) ,0)准确率,
+	ifnull(ROUND(IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = fp.pastureid AND bf.barid = fp.barid AND bf.remaindate = fp.date),0)/SUM(d2.actualweightminus),2)*100 ,0)准确率,
 	%s 日期
 	
 	FROM 
 	downloadedplan d
 	JOIN downloadplandtl2 d2
 	ON d2.pastureid = d.pastureid AND d2.pid = d.id
-	join feedtempletdate  ft on ft.id = d.tempid AND d.mydate = ft.date
-	
+
 	LEFT JOIN feedpdate fp
 on fp.barid  =  d2.fbarid and d.pastureid = fp.pastureid  AND d.mydate = fp.date 
-	WHERE  d.mydate BETWEEN  ? AND ?  AND  ft.pastureid = ? AND d.lpplantype IN (0,1,2,5) AND d2.type = 0     `
+	join feedtempletdate  ft on ft.id = fp.ftid AND d.mydate = ft.date
+
+	WHERE  d.mydate BETWEEN  ? AND ? and d.pastureid = ? AND d.lpplantype IN (0,1,2,5) AND d2.type = 0 
+	   `
 
 	var data []map[string]interface{}
 	var err error
 	if status == "0" {
 		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(ft.date, '%Y-%m-%d') ")
 
-		sqlStr += "  GROUP BY d.tempid, DATE_FORMAT(ft.date, '%Y-%m-%d')  ORDER BY  ft.tname ,ft.date "
+		sqlStr += "   GROUP BY fp.ftid, DATE_FORMAT(ft.date, '%Y-%m-%d')  ORDER BY  ft.tname ,ft.date "
 		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
@@ -250,7 +317,7 @@ on fp.barid  =  d2.fbarid and d.pastureid = fp.pastureid  AND d.mydate = fp.date
 
 		sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(ft.date,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
 
-		sqlStr += "  GROUP BY d.tempid , 日期 ORDER BY  ft.tname ,ft.date "
+		sqlStr += "  GROUP BY fp.ftid , 日期 ORDER BY  ft.tname ,ft.date "
 		fmt.Println(sqlStr)
 		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
 		if err != nil {
@@ -262,7 +329,7 @@ on fp.barid  =  d2.fbarid and d.pastureid = fp.pastureid  AND d.mydate = fp.date
 	} else {
 
 		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(ft.date, '%Y-%m') ")
-		sqlStr += "  GROUP BY d.tempid , DATE_FORMAT(ft.date, '%Y-%m') ORDER BY  ft.tname ,ft.date "
+		sqlStr += "  GROUP BY fp.ftid , DATE_FORMAT(ft.date, '%Y-%m') ORDER BY  ft.tname ,ft.date "
 
 		// timeTemplate := "2006-01-02"
 		// end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
@@ -276,8 +343,13 @@ on fp.barid  =  d2.fbarid and d.pastureid = fp.pastureid  AND d.mydate = fp.date
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 func GetFeedEffSLJT(c *gin.Context) {
@@ -363,8 +435,13 @@ func GetFeedEffSLJT(c *gin.Context) {
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 func GetFeedEffHL(c *gin.Context) {
@@ -382,19 +459,25 @@ func GetFeedEffHL(c *gin.Context) {
 	defer tx.Close()
 
 	var sqlStr = `SELECT 
- %s 日期,
-ifnull(ROUND(SUM(UNIX_TIMESTAMP((SELECT MAX(intime) FROM downloadplandtl1_exec d2 
-WHERE  d.mydate=d2.date AND d.pastureid = d2.pastureid AND d2.pid=d.id))-UNIX_TIMESTAMP(d.intime))/60,2),0) field1 -- 混料时间
- FROM 
-downloadedplan d
-WHERE  d.mydate  BETWEEN ? AND ?  AND  d.pastureid = ? AND d.lpplantype IN (0,1)  `
+	ft.tname 名称,
+
+   ifnull(ROUND(SUM(UNIX_TIMESTAMP((SELECT MAX(intime) FROM downloadplandtl1_exec d2 
+   WHERE  d.mydate=d2.date AND d.pastureid = d2.pastureid AND d2.pid=d.id))-UNIX_TIMESTAMP(d.intime))/60,2),0) 准确率 ,
+   %s 日期,
+   ifnull(ROUND(SUM(UNIX_TIMESTAMP((SELECT MAX(intime) FROM downloadplandtl1_exec d2 
+   WHERE  d.mydate=d2.date AND d.pastureid = d2.pastureid AND d2.pid=d.id))-UNIX_TIMESTAMP(d.intime))/60,2),0) 混料时间(分钟) 
+ 
+	FROM 
+   downloadedplan d
+   join feedtempletdate  ft on ft.id = d.tempid  and ft.date = d.mydate
+   WHERE  d.mydate  BETWEEN ? AND ?  AND  d.pastureid = ? AND d.lpplantype IN (0,1)    `
 
 	var data []map[string]interface{}
 	var err error
 	if status == "0" {
 		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.mydate, '%Y-%m-%d') ")
 
-		sqlStr += "  GROUP BY DATE_FORMAT(d.mydate, '%Y-%m-%d') ORDER BY  d.mydate "
+		sqlStr += "  GROUP BY ft.id,DATE_FORMAT(d.mydate, '%Y-%m-%d') ORDER BY  ft.id,d.mydate "
 		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
 		if err != nil {
 			logs.Error(sqlName, " : ", err)
@@ -415,7 +498,7 @@ WHERE  d.mydate  BETWEEN ? AND ?  AND  d.pastureid = ? AND d.lpplantype IN (0,1)
 
 		sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
 
-		sqlStr += "  GROUP BY 日期 ORDER BY 日期 "
+		sqlStr += "  GROUP BY ft.id,日期 ORDER BY  ft.id,d.mydate "
 		fmt.Println(sqlStr)
 		data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
 		if err != nil {
@@ -427,7 +510,7 @@ WHERE  d.mydate  BETWEEN ? AND ?  AND  d.pastureid = ? AND d.lpplantype IN (0,1)
 	} else {
 
 		sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.mydate, '%Y-%m') ")
-		sqlStr += "  GROUP BY DATE_FORMAT(d.mydate, '%Y-%m') ORDER BY  d.mydate "
+		sqlStr += "  GROUP BY ft.id,DATE_FORMAT(d.mydate, '%Y-%m') ORDER BY  ft.id,d.mydate"
 
 		// timeTemplate := "2006-01-02"
 		// end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
@@ -441,8 +524,13 @@ WHERE  d.mydate  BETWEEN ? AND ?  AND  d.pastureid = ? AND d.lpplantype IN (0,1)
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracyV2(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 
 }
 
@@ -639,8 +727,13 @@ WHERE d.mydate  BETWEEN ? AND ?  AND   d.pastureid = ?  AND d.lpplantype IN (0,1
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 func GetFeedEffZHJT(c *gin.Context) {
@@ -730,8 +823,13 @@ func GetFeedEffZHJT(c *gin.Context) {
 		}
 
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 func GetFeedEffCBFT(c *gin.Context) {
@@ -860,8 +958,13 @@ WHERE fp.date BETWEEN ? AND ? AND fp.pastureid = ?   AND d.lpplantype IN (0,1,2,
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 //成本分析-集团
@@ -952,8 +1055,13 @@ func GetFeedEffCBAllJT(c *gin.Context) {
 		}
 
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 // getAccuracyAllFT
@@ -1034,8 +1142,13 @@ WHERE  d.mydate  BETWEEN ? AND ?  AND d.pastureid=?   AND d.lpplantype  IN (0,1,
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 // getAccuracyAllJH
@@ -1214,8 +1327,13 @@ func GetAccuracyAllNQ(c *gin.Context) {
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 // getAccuracyAllCC
@@ -1293,8 +1411,13 @@ func GetAccuracyAllCC(c *gin.Context) {
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 // getAccuracyAllHL
@@ -1466,8 +1589,13 @@ func GetAccuracyAllLS(c *gin.Context) {
 
 		// appG.Response(http.StatusOK, e.SUCCESS, data)
 	}
-	queryData, err := getAccuracy(data)
-	appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	if status == "1" {
+		queryData, _ := getAccuracy(data, "2006-01-02")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	} else {
+		queryData, _ := getAccuracy(data, "2006-01")
+		appG.Response(http.StatusOK, e.SUCCESS, queryData)
+	}
 }
 
 //getAccuracyAllQX

+ 282 - 103
http/handle/api/ops.go

@@ -1512,6 +1512,9 @@ func ExecDataByConfig(c *gin.Context) {
 					logging.Error("ExecDataParam error:", err)
 					break
 				}
+				if paramvalue["name"].(string) == "createdownloadedplan" {
+					checkPlan(tx, paramvalue, tempCommon, tempval, 0)
+				}
 			}
 			if err == nil {
 				if tempCommon["returnmap"] != nil && tempCommon["returnmap"] != "" {
@@ -3409,9 +3412,6 @@ func UpdateFTdetail(c *gin.Context) {
 			appG.Response(http.StatusOK, e.ERROR, false)
 			return
 		}
-		// }()
-		// }
-		// }
 	}
 
 	appG.Response(http.StatusOK, e.SUCCESS, true)
@@ -3525,14 +3525,10 @@ func UpdateFpdetailBar(c *gin.Context) {
 		ftmap["ptsid"] = list.Get("ptsid").ValueStr()
 		// fmt.Println(ftmap)
 
-		fpdDataList, err := tx.SQL(`select * from (SELECT TRIM(id) id,times,tratio,ifnull(ROUND(ptsrate*weight,2)-ptsuse,"") weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(-1 ) ptsid ,
-			(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
-			WHERE fpdetail.pastureid = ?   and barid =(select barid from feedp where id = ? )  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((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(ifnull(ptsid,-1) ) ptsid ,
-			(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
-			WHERE fpdetail.pastureid = ?  and barid = (select barid from feedp where id = ? )  and  times = ? ) t
-			order by t.barname,t.times`, pastureid, id, ftmap["times"], pastureid, id, ftmap["times"]).Query().List()
+			(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 barid = (select barid from feedp where id = ? )  and  times = ? `, pastureid, id, ftmap["times"]).Query().List()
 		// fmt.Println(pastureid, id, ftmap["times"], pastureid, id, ftmap["times"])
 		if err != nil {
 			tx.Rollback()
@@ -3542,7 +3538,7 @@ func UpdateFpdetailBar(c *gin.Context) {
 		for _, fpd := range fpdDataList {
 			if fpd["times"].(int64) == ftmap["times"].(int64) && (fpd["ptid"].(string) == ftmap["ptid"].(string)) {
 				fttype := -1
-				if ftmap["ptid"].(string) != "-1" {
+				if fpd["fttype"].(string) == "1" {
 					fttype = 1
 				}
 
@@ -3565,7 +3561,7 @@ func UpdateFpdetailBar(c *gin.Context) {
 				var w float64
 				var status int
 				fmt.Println(ftmap["new"].(float64), ftmap["old"].(float64))
-				if ftmap["new"].(float64) < ftmap["old"].(float64) {
+				if ftmap["new"].(float64) < ftmap["old"].(float64) && weight <= 0 {
 					if weight >= 0 {
 						continue
 					}
@@ -3580,11 +3576,14 @@ func UpdateFpdetailBar(c *gin.Context) {
 					status = 1
 				}
 
-				for _, lppland := range lpplandtl1List {
-					lweight += lppland.Lweight
-				}
+				// 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 {
@@ -3623,13 +3622,26 @@ func UpdateFpdetailBar(c *gin.Context) {
 
 					}
 
-					_, 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
+					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
+						}
+					} else {
+						_, err = tx.SQL(`delete from  lpplandtl1    where id = ? and pastureid = ?`, lppland.Id, pastureid).Execute()
+						if err != nil {
+							tx.Rollback()
+							logs.Error(err)
+							return
+						}
 					}
-					break
+					if w == 0 {
+						break
+					}
+					// 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)
@@ -4125,6 +4137,7 @@ func FpdImportExcel(c *gin.Context) {
 		rows = rows[:10000]
 	}
 
+	dataList := make(map[string][]*upFpdetail, 0)
 	for i, row := range rows {
 		if i > 0 {
 
@@ -4282,6 +4295,7 @@ func FpdImportExcel(c *gin.Context) {
 					}
 				}
 			}
+
 			if !errExist {
 
 				dataexcel := make(map[string]interface{}, 0)
@@ -4316,7 +4330,7 @@ func FpdImportExcel(c *gin.Context) {
 				}
 
 				if _, ok := outentry["第五班比例(%)"]; ok {
-					dataexcel["5"] = outentry["第班比例(%)"]
+					dataexcel["5"] = outentry["第班比例(%)"]
 				}
 
 				if _, ok := outentry["第六班比例(%)"]; ok {
@@ -4333,6 +4347,28 @@ func FpdImportExcel(c *gin.Context) {
 					continue
 				}
 
+				_, err = tx.SQL(` update feedp fp set barname =  (select bname from  bar where bname = ?  and pastureid = ? )   where barid = (select id from  bar where bname = ?  and pastureid = ? )`, dataexcel["barname"], pastureid, dataexcel["barname"], pastureid).Execute()
+				if err != nil {
+					appG.Response(http.StatusInternalServerError, e.ERROR, err)
+					return
+				}
+
+				_, err = tx.SQL(` update fpdetail fp set barname =  (select bname from  bar where bname = ?  and pastureid = ? )   where barid = (select id from  bar where bname = ?  and pastureid = ? )`, dataexcel["barname"], pastureid, dataexcel["barname"], pastureid).Execute()
+				if err != nil {
+					appG.Response(http.StatusInternalServerError, e.ERROR, err)
+					return
+				}
+
+				existft, err := tx.SQL(` select id from  feedtemplet where tname = ?  and pastureid = ?  `, dataexcel["ftname"], pastureid).Exist()
+				if err != nil {
+					logs.Error(err)
+					appG.Response(http.StatusInternalServerError, e.ERROR, "配方不存在!")
+					return
+				}
+				if !existft {
+					continue
+				}
+
 				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)
@@ -4507,7 +4543,7 @@ func FpdImportExcel(c *gin.Context) {
 					dataexcel["ftname"], pastureid, dataexcel["barname"], pastureid, 1)
 				_, err = tx.SQL(upFpdSql, fpdargs1...).Execute()
 				if err != nil {
-					appG.Response(http.StatusInternalServerError, e.ERROR, false)
+					appG.Response(http.StatusInternalServerError, e.ERROR, err)
 					return
 				}
 
@@ -4591,17 +4627,20 @@ func FpdImportExcel(c *gin.Context) {
 						}
 					}
 				}
-
-				updateFpdetailByBar(pastureid, dataexcel["barname"].(string), upFpdetailList)
-
+				// fmt.Println(dataexcel["barname"])
+				dataList[dataexcel["barname"].(string)] = upFpdetailList
+				// updateFpdetailByBar(pastureid, dataexcel["barname"].(string), upFpdetailList)
 			}
-
 		}
 		if !isdone {
 			ok++
 			isdone = true
 		}
 	}
+	for barname, v := range dataList {
+		updateFpdetailByBar(pastureid, barname, v)
+	}
+
 	data := make(map[string]interface{})
 	data["result"] = queryData
 	data["success"] = ok
@@ -4703,27 +4742,25 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 		ftmap["ptid"] = strconv.FormatInt(list.Ptid, 10)
 		ftmap["ptsid"] = ""
 		// fmt.Println(ftmap)
-
-		fpdDataList, err := tx.SQL(`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,0 AS fttype,cowcount,ccountradio,1 isfill  FROM fpdetail
-			WHERE fpdetail.pastureid = ?   and barname = ? and  times = ?
-			UNION
+		// 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,1 AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
-			WHERE fpdetail.pastureid = ?  and barname = ? and  times = ? ) t
-			order by t.barname,t.times`, pastureid, barname, ftmap["times"], pastureid, barname, ftmap["times"]).Query().List()
+			(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 ftmap["ptid"].(string) != "-1" {
-					fttype = 1
-				}
+				// fttype := -1
+				// if fpd["fttype"].(string) == "1" {
+				fttype := 1
+				// }
 
 				var fweight float64
 				var lweight float64
@@ -4738,32 +4775,36 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 					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)
-				// ptuse, _ := strconv.ParseFloat(fpd["ptuse"].(string), 64)
 
 				var w float64
 				var status int
 
-				if ftmap["new"].(float64) < ftmap["old"].(float64) {
+				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
-					}
+					// 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 {
+				// 	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 {
@@ -4776,7 +4817,6 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 							fweight += w
 							w = 0
 						} else {
-
 							w = w - (lppland.Maxweight - lweight)
 							n := (lppland.Maxweight - lweight)
 							lppland.Lweight = lppland.Lweight + n
@@ -4802,13 +4842,25 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 
 					}
 
-					_, 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
+					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
 					}
-					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)
@@ -4968,7 +5020,7 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 		if err != nil {
 			logs.Error(err)
 			// appG.Response(http.StatusOK, e.ERROR, false)
-			return nil
+			return err
 		}
 	}
 
@@ -4980,7 +5032,7 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 		if err != nil {
 			logs.Error(err)
 			// appG.Response(http.StatusOK, e.ERROR, false)
-			return nil
+			return err
 		}
 	}
 	for _, newFeedp := range newFeedpList {
@@ -4995,7 +5047,7 @@ where lppland.pastureid = ?  and lppland.fpdid = ? and lpp.times = ?  order by l
 		if err != nil {
 			logs.Error(err)
 			// appG.Response(http.StatusOK, e.ERROR, false)
-			return nil
+			return err
 		}
 	}
 
@@ -7008,7 +7060,7 @@ func GetFormulaStatistics(c *gin.Context) {
 	}
 
 	downloadedplanList, err := tx.SQL(`select  count(1) total,ft.tname,date_format(d.mydate ,'%Y-%m-%d')  mydate  from downloadedplan d  
-	join  feedtemplet ft on ft.id = d.tempid  where d.mydate between ?  and ? and  d.lpplantype in(0,1) and d.iscompleted = 1  and d.pastureId= ? 
+	join  feedtempletdate ft on ft.id = d.tempid and ft.date = d.mydate  where d.mydate between ?  and ? and  d.lpplantype in(0,1) and d.iscompleted = 1  and d.pastureId= ? 
 	group by d.tempid,d.mydate `, startTime, endTime, pastureId).Query().List()
 	if err != nil {
 		logs.Error("GetFormulaStatistics-error-2:", err)
@@ -7177,32 +7229,32 @@ func PostPlanData(c *gin.Context) {
 			tx.Close()
 		}
 	}()
-	sql, p := restful.GetSqlByNameDBT("updatedownloadedplanYJ", tx)
-	sql1, p1 := restful.GetSqlByNameDBT("updated1YJ", tx)
-	sql2, p2 := restful.GetSqlByNameDBT("updated1execYJ", tx)
-	sql3, p3 := restful.GetSqlByNameDBT("updated2YJ", tx)
+	// sql, p := restful.GetSqlByNameDBT("updatedownloadedplanYJ", tx)
+	sql1, p1 := restful.GetSqlByNameDBT("updated1YJXY", tx)
+	sql2, p2 := restful.GetSqlByNameDBT("updated1execYJXY", tx)
+	sql3, p3 := restful.GetSqlByNameDBT("updated2YJXY", tx)
 	if !fsion.HasKey("parammaps") {
 		appG.Response(http.StatusOK, e.ERROR, "参数解析失败")
 		return
 	}
 	parammaps := fsion.Get("parammaps")
 
-	paramslist := strings.Split(p, ",")
-	if len(paramslist) > 0 && p != "" {
-		for _, value := range paramslist {
-			s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
-		}
-	}
-	_, err = tx.SQL(sql, s_params...).Execute()
-	if err != nil {
-		logging.Error("PostRJSBData  err: ", err)
-		msg := geterrmsg(err.Error())
-		appG.Response(http.StatusOK, e.ERROR, msg)
-		return
-	}
+	// paramslist := strings.Split(p, ",")
+	// if len(paramslist) > 0 && p != "" {
+	// 	for _, value := range paramslist {
+	// 		s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
+	// 	}
+	// }
+	// _, err = tx.SQL(sql, s_params...).Execute()
+	// if err != nil {
+	// 	logging.Error("PostRJSBData  err: ", err)
+	// 	msg := geterrmsg(err.Error())
+	// 	appG.Response(http.StatusOK, e.ERROR, msg)
+	// 	return
+	// }
 
 	s_params = make([]interface{}, 0)
-	paramslist = strings.Split(p1, ",")
+	paramslist := strings.Split(p1, ",")
 	if len(paramslist) > 0 && p1 != "" {
 		for _, value := range paramslist {
 			// if value == "ID" {
@@ -7796,39 +7848,44 @@ func PostPlanDatas(c *gin.Context) {
 	// sql2, p2 := restful.GetSqlByNameDBT("updated1execYJ", tx)
 	// sql3, p3 := restful.GetSqlByNameDBT("updated2YJ", tx)
 
-	sql, p := restful.GetSqlByNameDBT("updatedownloadedplanYJ", tx)
-	sql1, p1 := restful.GetSqlByNameDBT("updated1YJ", tx)
-	sql2, p2 := restful.GetSqlByNameDBT("updated1execYJ", tx)
-	sql3, p3 := restful.GetSqlByNameDBT("updated2YJ", tx)
+	// sql, p := restful.GetSqlByNameDBT("updatedownloadedplanYJ", tx)
+	sql1, p1 := restful.GetSqlByNameDBT("updated1YJXY", tx)
+	sql2, p2 := restful.GetSqlByNameDBT("updated1execYJXY", tx)
+	sql3, p3 := restful.GetSqlByNameDBT("updated2YJXY", tx)
 
 	for _, parammaps := range fsions.Get("arrList").Array() {
+		fmt.Println(parammaps.Json())
+		if parammaps.Json() == "null" {
+			continue
+		}
 		// if !fsion.HasKey("arrList") {
-		// 	appG.Response(http.StatusOK, e.ERROR, "参数解析失败")
-		// 	return
+		// appG.Response(http.StatusOK, e.ERROR, "参数解析失败")
+		// return
+		// 	continue
 		// }
 		// parammaps := fsion.Get("arrList")
 		s_params := make([]interface{}, 0)
-		paramslist := strings.Split(p, ",")
-		if len(paramslist) > 0 && p != "" {
-			for _, value := range paramslist {
-				if value == "pastureid" {
-					s_params = append(s_params, pastureId)
-				} else {
-					s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
-				}
-			}
-		}
-		_, err = tx.SQL(sql, s_params...).Execute()
+		// paramslist := strings.Split(p, ",")
+		// if len(paramslist) > 0 && p != "" {
+		// 	for _, value := range paramslist {
+		// 		if value == "pastureid" {
+		// 			s_params = append(s_params, pastureId)
+		// 		} else {
+		// 			s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
+		// 		}
+		// 	}
+		// }
+		// _, err = tx.SQL(sql, s_params...).Execute()
 
-		if err != nil {
-			logging.Error("PostRJSBData  err: ", err)
-			msg := geterrmsg(err.Error())
-			appG.Response(http.StatusOK, e.ERROR, msg)
-			return
-		}
+		// if err != nil {
+		// 	logging.Error("PostRJSBData  err: ", err)
+		// 	msg := geterrmsg(err.Error())
+		// 	appG.Response(http.StatusOK, e.ERROR, msg)
+		// 	return
+		// }
 
 		s_params = make([]interface{}, 0)
-		paramslist = strings.Split(p1, ",")
+		paramslist := strings.Split(p1, ",")
 		if len(paramslist) > 0 && p1 != "" {
 			for _, value := range paramslist {
 				// if value == "ID" {
@@ -8272,6 +8329,7 @@ func UdFeedtempletPush(c *gin.Context) {
 	dataByte, _ := ioutil.ReadAll(c.Request.Body)
 	fsions := gofasion.NewFasion(string(dataByte))
 	pastureid := fsions.Get("pastureId").ValueStr()
+	date := fsions.Get("date").ValueStr()
 
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
@@ -8283,7 +8341,7 @@ func UdFeedtempletPush(c *gin.Context) {
 		return
 	}
 
-	gm.UdFeedtempletPush(pastureid, pastureinfo.Werks)
+	gm.UdFeedtempletPush(pastureid, pastureinfo.Werks, date)
 
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
@@ -8352,3 +8410,124 @@ func UdMaterialIssuePush(c *gin.Context) {
 
 	appG.Response(http.StatusOK, e.SUCCESS, "ok")
 }
+
+func DelFeedTemplet(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsions := gofasion.NewFasion(string(dataByte))
+	ftId := fsions.Get("ftId").ValueStr()
+	userId := fsions.Get("userId").ValueStr()
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	_, err := tx.Exec(` update feedtemplet set enable = 1 and isdelete = 1  where id = ? `, ftId)
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, errors.New("删除失败!!!"))
+		return
+	}
+
+	barIdList, err := tx.SQL(`select barid from feedp where ftid = ? `, ftId).QueryString()
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, errors.New("删除失败!!!"))
+		return
+	}
+
+	_, err = tx.Exec(` update feedp set ftid = 0 and ftname = '',feedweight = 0,ftweight = 0,  where ftid = ? `, ftId)
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, errors.New("删除栏舍配方失败"))
+		return
+	}
+
+	_, err = tx.Exec(` update fpdetail set weight = ? ,ptid =  0,ptuse= 0   where ftid = ? `, ftId)
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, errors.New("删除栏舍配方失败"))
+		return
+	}
+
+	count, _ := tx.SQL(`select count(1)  from lpplan  where ftid = ? `, ftId).Count()
+	if count > 0 {
+		_, err = tx.Exec(` delete from  lpplandtl1   where lppid in(select id from lpplan  where ftid = ?  ) `, ftId)
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, errors.New("删除子计划失败"))
+			return
+		}
+	}
+	_, err = tx.Exec(` delete from  lpplan    where ftid = ? `, ftId)
+	if err != nil {
+		logs.Error(err)
+		appG.Response(http.StatusOK, e.ERROR, errors.New("删除计划失败"))
+		return
+	}
+
+	var barIdStr []string
+	for _, bar := range barIdList {
+		barIdStr = append(barIdStr, bar["barid"])
+	}
+
+	if len(barIdStr) > 0 {
+
+		newFpdDataList, err := tx.Table("fpdetail").In(`barid`, barIdStr).Query().List()
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, errors.New("删除失败!!!"))
+			return
+		}
+
+		newFeedpList, err := tx.Table("feedp").In(`barid`, barIdStr).Query().List()
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusOK, e.ERROR, errors.New("删除失败!!!"))
+			return
+		}
+
+		now := time.Now()
+		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,userId)
+					 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, userId).Execute()
+			if err != nil {
+				logs.Error(err)
+				appG.Response(http.StatusOK, e.ERROR, false)
+				return
+			}
+		}
+
+		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,userId)
+				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, userId).Execute()
+			if err != nil {
+				logs.Error(err)
+				appG.Response(http.StatusOK, e.ERROR, false)
+				return
+			}
+		}
+	}
+	appG.Response(http.StatusOK, e.SUCCESS, "ok")
+}
+
+func checkPlan(tx *xorm.Session, fasion map[string]interface{}, CommonParamMap map[string]interface{}, ParamMap []map[string]interface{}, number int) {
+	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 `,
+		data["startTime"]).Count()
+	fmt.Println(err)
+	if plancount != plancount1 && number < 10 {
+		number++
+		ExecDataParam(fasion, CommonParamMap, ParamMap, nil, nil, tx)
+		checkPlan(tx, fasion, CommonParamMap, ParamMap, number)
+	}
+}

+ 14 - 6
http/handle/api/report.go

@@ -93,7 +93,7 @@ func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Ses
 	// 根据名称选择不通类型的转换-(可自动扩展,不需要使用之前的)
 	switch temstr {
 	case "getAccurac", "getFeedEff":
-		queryData, err = getAccuracy(queryList) // 不定参数
+		queryData, err = getAccuracy(queryList, "2006-01-02") // 不定参数
 	case "getprocess":
 		//queryData, err = getAccuracyV3v1(queryList)
 		queryData, err = getAccuracyV3(queryList)
@@ -1094,7 +1094,7 @@ func getAccuracyV2(queryList []map[string]interface{}) (map[string]interface{},
 	queryData["data"] = queryList
 	return queryData, nil
 }
-func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, error) {
+func getAccuracy(queryList []map[string]interface{}, layout string) (map[string]interface{}, error) {
 
 	queryData := make(map[string]interface{})
 	chartData := make(map[string]interface{})
@@ -1131,6 +1131,8 @@ func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, er
 		}
 		if b != queryList[i]["名称"] {
 			if a < len(e2)-1 {
+				eee := len(e2) - a
+				fmt.Println(eee)
 				for k := 0; k < len(e2)-a; k++ {
 					data["data"] = append(data["data"], "")
 				}
@@ -1142,7 +1144,7 @@ func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, er
 		}
 		switch queryList[i]["日期"].(type) {
 		case string:
-			dates, _ := time.Parse("2006-01-02", queryList[i]["日期"].(string))
+			dates, _ := time.Parse(layout, queryList[i]["日期"].(string))
 			dates1 := ""
 			if a < len(e2)-1 {
 				dates1 = e2[a]
@@ -1153,15 +1155,21 @@ func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, er
 				if e2[a] != queryList[i]["日期"].(string) {
 					if e2[a] < queryList[i]["日期"].(string) {
 						dates1 = queryList[i]["日期"].(string)
-						dates, _ = time.Parse("2006-01-02", e2[a])
+						dates, _ = time.Parse(layout, e2[a])
 						for ; a < len(e2)-1; a++ {
 							if e2[a] >= queryList[i]["日期"].(string) {
 								break
 							}
 						}
 					}
-					for ; dates.Format("2006-01-02") < dates1; dates = dates.Add(24 * time.Hour) {
-						data["data"] = append(data["data"], "")
+					if layout == "2006-01-02" {
+						for ; dates.Format(layout) < dates1; dates = dates.Add(24 * time.Hour) {
+							data["data"] = append(data["data"], "")
+						}
+					} else if layout == "2006-01" {
+						for ; dates.Format(layout) < dates1; dates = dates.AddDate(0, 1, 0) {
+							data["data"] = append(data["data"], "")
+						}
 					}
 				}
 			}

+ 0 - 1
http/handle/api/scheduled.go

@@ -134,7 +134,6 @@ func CronScheduled(ctx context.Context) {
 	//
 	// //圣牧自动同步前天有进行中的任务
 	manualUdData(pastureinfo)
-	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
 
 	// xdmy := cron.New()
 	// err = xdmy.AddFunc("0 10 4 * * *", func() {

+ 0 - 1
http/handle/api/spillage.go

@@ -1221,7 +1221,6 @@ func UpdateLpplan(c *gin.Context) {
 		for _, data := range dataList {
 			updateStatus := true
 			for _, old := range oldList {
-				fmt.Println(old.Get("lweight").ValueStr(), data["lweight"], old.Get("barid").ValueInt64(), data["barid"], "aaaaaaaaaaa")
 				if (old.Get("lweight").ValueStr() == data["lweight"].(string)) && old.Get("barid").ValueInt64() == data["barid"].(int64) {
 					updateStatus = false
 					break

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

@@ -758,6 +758,10 @@ func GetBarfeedremainExcel(c *gin.Context) {
 	cell.SetStyle(style)
 	cell = row.AddCell()
 
+	cell.SetValue("干物质")
+	cell.SetStyle(style)
+	cell = row.AddCell()
+
 	cell.SetValue("班次(第一班/第二班/第三班)")
 	cell.SetStyle(style)
 	cell = row.AddCell()

+ 51 - 33
http/handle/gm/udservice.go

@@ -23,7 +23,7 @@ func GmUdSync(pastureId, farmId string) {
 	UdBarSync(pastureId, farmId)
 	UdFeedSync(pastureId, farmId)
 
-	UdFeedtempletPush(pastureId, farmId)
+	UdFeedtempletPush(pastureId, farmId, "")
 	UdUtirPush(pastureId, farmId, "")
 	UdBarFeedRemainPush(pastureId, farmId, "")
 	UdMaterialIssuePush(pastureId, farmId, "")
@@ -46,13 +46,13 @@ func UdBarSync(pastureId, farmId string) {
 		}
 		for _, item := range barMap["msg"].([]interface{}) {
 			bar := item.(map[string]interface{})
-			barname := bar["barname"].(string) + "_ud"
+			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)values(?,(select id from bar where bcode=  ? and pastureId = ? ),?,?,?)
-		 ON DUPLICATE KEY UPDATE  softccount = ? `,
-				pastureId, bar["barcode"], pastureId, barname, bar["cowcount"], bar["cowcount"], bar["cowcount"])
+			_, _ = 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)
 			if !barExist {
 				tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
@@ -70,7 +70,6 @@ func UdBarSync(pastureId, farmId string) {
 			}
 		}
 	}
-
 }
 
 func UdFeedSync(pastureId, farmId string) {
@@ -84,6 +83,7 @@ func UdFeedSync(pastureId, farmId string) {
 
 	feedMap := make(map[string]interface{})
 	json.Unmarshal(feedByte, &feedMap)
+	fmt.Println(string(feedByte))
 	if len(feedMap) > 0 {
 		if feedMap["status"].(string) != "ok" {
 			return
@@ -91,7 +91,7 @@ func UdFeedSync(pastureId, farmId string) {
 		for _, item := range feedMap["msg"].([]interface{}) {
 			fmt.Println(item)
 			feed := item.(map[string]interface{})
-			feedname := feed["feedname"].(string) + "_ud"
+			feedname := feed["feedname"].(string)
 			feedClassExist, err := tx.Table("feedclass").Where("fccode = ? ", feed["feedclass"]).Where(" pastureId = ? ", pastureId).Exist()
 			fmt.Println(err)
 			if !feedClassExist {
@@ -101,8 +101,8 @@ func UdFeedSync(pastureId, farmId string) {
 					ids = time.Now().UnixNano()
 					logging.Info("create SnowIds err", err)
 				}
-				_, err = tx.Exec(`insert into feedclass(id,pastureId,fcname,fccode,bigfeedclassname,sort,bigfeedclassid) values(?,?,?,?,?,?)`, ids,
-					pastureId, feed["feedclass"], feed["feedclass"], feed["feedclass"], count+1, ids)
+				_, err = tx.Exec(`insert into feedclass(id,pastureId,fcname,fccode,bigfeedclassname,sort,bigfeedclassid) values(?,?,?,?,?,?,?)`,
+					ids, pastureId, feed["feedclass"], feed["feedclass"], feed["feedclass"], count+1, ids)
 				fmt.Println(err)
 			}
 
@@ -115,6 +115,7 @@ func UdFeedSync(pastureId, farmId string) {
 			_, err = tx.Exec(`insert into feed(id,pastureId,feedcode,udname,fclassid,fclass,fname) values(?,?,?,?,(select id from feedclass where fccode = ? and pastureId = ? ),?,if(char_length(?) > 7, left(?,7),?) )
 		ON DUPLICATE KEY UPDATE udname = ? ,fclassid = (select id from feedclass where fccode = ? and pastureId = ? ) ,fclass = ?`,
 				ids, pastureId, feed["feedcode"], feedname, feed["feedclass"], pastureId, feed["feedclass"], feedname, feedname, feedname, feedname, feed["feedclass"], pastureId, feed["feedclass"])
+			fmt.Println(err)
 		}
 	}
 
@@ -163,9 +164,9 @@ 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.id recipeId,ft.ccname recipeName,ifnull(ifnull(f.id,ftd.fid),0) ingId,d1.fname ingName,
+	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,
 	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 ,d1.lweight expWeight,d1.actualweightminus actualWeight,
+	ifnull(f.dry * d1.actualweightminus,0)  dmPct,d1.sort mixNo,ifnull(d1.feedallowratio,0) allowableError ,ifnull(d1.lweight,'') expWeight,ifnull(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 
@@ -180,7 +181,7 @@ WHERE  d1.date=d2.mydate AND d1.pastureid = d2.pastureid AND d2.id=d1.pid)
 	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 = ?`, now).Query().List()
+	where d1.date = ?  and d.havebutton = 1`, now).Query().List()
 	if err != nil {
 		logging.Error(err)
 		return err
@@ -220,34 +221,44 @@ func UdMaterialIssuePush(pastureId, farmId, date string) error {
 		now = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
 	}
 
-	dataList, err := tx.SQL(`SELECT  dd.sort feedSort, ifnull((select id from feed where feedcode = dd.feedcode ),"") feedId,dd.fname feedName,
-	d.id,IFNULL(ft.id,d2.feedtempletid ) recipeId,IFNULL(ft.id,d2.feedtempletid ) feedtempletId,ft.tname feedtempletName ,
+	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 ,
 	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,b.id as penId,d2.Fname as penName,fp.CCOUNT as cowCount, d2.SORT as feedingNo,
-ifnull(ROUND(d2.lweight * (dd.actualweightminus/ (select sum(actualweightminus) from downloadplandtl1 where pid = dd.pid and type = 0) ),2) ,0)as expWeight,
+	d.Times as dropShift,ifnull(b.bcode,b.id) as penId,b.bname as penName,fp.CCOUNT as cowCount, d2.SORT as feedingNo,
+ifnull(ROUND(d2.lweight * (d1.actualweightminus/ (select sum(actualweightminus) from downloadplandtl1 where pid = d1.pid and type = 0) ),2) ,0)as expWeight,
 	ifnull(d2.ActualWeightMinus,0) as actualWeight, ifnull(date_format(timestamp(d2.InTime,CONCAT('-',d2.processTime)),'%Y-%m-%d %H:%i:%s'),d.mydate) as startTime,
 	ifnull(date_format(d2.InTime,'%Y-%m-%d %H:%i:%s'),d.mydate) as endTime,ifnull((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),"") as tmrName ,d.tmrtname equipmentId ,
-dd.fname,
-  ifnull(TRIM(if(( select sum(dd2.actualweightminus) from downloadplandtl2 dd2 where dd2.pid = d2.pid) >0 ,   ROUND( d2.actualweightminus/( select sum(dd2.actualweightminus) from downloadplandtl2 dd2 where dd2.pid = d2.pid) * (dd.actualweightminus ),2), ROUND( d2.lweight/( select sum(dd2.lweight) from downloadplandtl2 dd2 where dd2.pid = d2.pid) * (dd.actualweightminus ),2))),0) feedWeight
+d1.fname,
+  ifnull(TRIM(if(( select sum(dd2.actualweightminus) from downloadplandtl2 dd2 where dd2.pid = d2.pid) >0 ,   ROUND( d2.actualweightminus/( select sum(dd2.actualweightminus) from downloadplandtl2 dd2 where dd2.pid = d2.pid) * (d1.actualweightminus ),2), ROUND( d2.lweight/( select sum(dd2.lweight) from downloadplandtl2 dd2 where dd2.pid = d2.pid) * (d1.actualweightminus ),2))),0) feedWeight
 
 	,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 =  dd.date and ftid = dd.fid ) *  dd.actualweightminus,"") premixFeedWeight
-
+	 ifnull((select feedcode from feed where id = ftd.fid),"") premixFeedId,ifnull(ftd.fname,"")  premixFeedName,
+	 
+ 
+ 	ifnull(if(d1.feedcode = '-1', if ( (SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date) > 0 ,
+  d2.actualweightminus/(SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
+  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid )),
+	
+	 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 = ft.version and ft.id = ftd2.ftid  ))
+	),''),'')
+  premixFeedWeight
+	
 	from  downloadedplan d
 	LEFT JOIN downloadplandtl2 d2 on d.id=d2.PID
 	LEFT JOIN (select dd.pid as lppid,dd1.* from downloadedplan dd join downloadplandtl1  dd1 on dd1.pid = dd.id and dd1.type = 0
-		where dd.mydate= date_format(?,'%Y-%m-%d')  and dd.lpplanType in (0,1) ) dd on dd.lppid = d.pid
+		where dd.mydate= date_format(?,'%Y-%m-%d')  and dd.lpplanType in (0,1) ) d1 on d1.lppid = d.pid
 
 	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 feedtemplet ft on d.tempid=ft.id
-		left join ftdetaildate  ftd  on  ftd.date =  dd.date and ftd.ftid = dd.fid
+	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
 
-	where d.mydate= date_format(?,'%Y-%m-%d')  and d.lpplanType!=1 and d.pastureid = ?   and dd.fname is not null  order by tmrno `, now, now, pastureId).Query().List()
+	where d.mydate= date_format(?,'%Y-%m-%d')  and d.lpplanType!=1 and d.havebutton = 1 and d.pastureid = ?  and d1.fname is not null  order by tmrno   `, now, now, pastureId).Query().List()
 	if err != nil {
 		logging.Error(err)
 		return err
@@ -291,7 +302,7 @@ func UdBarFeedRemainPush(pastureId, farmId, date string) error {
 	'' startTime,
 	'' endTime,
 	br.RemainDate AS overplusDate,
-	 b.id AS penId,
+	ifnull(b.bcode,b.id) AS penId,
 	b.BNAME AS penName,
 	br.Remain AS actualWeight
 FROM
@@ -334,15 +345,22 @@ WHERE
 // 撒料数据 uploaddiliverdata
 // 剩料 uploadoverplusdata
 
-func UdFeedtempletPush(pastureId, farmId string) error {
+func UdFeedtempletPush(pastureId, farmId, date string) error {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
+	var now string
+	if date != "" {
+		now = date
+	} else {
+		now = time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	}
+
 	dataList, err := tx.SQL(`SELECT
-	ft.ID AS recipeId,
+	ft.tcode AS recipeId,
 	ft.TNAME AS recipeName,
-	f.id  AS ingId,
-	f.FNAME AS ingName,
+	f.feedcode   AS ingId,
+	ifnull(f.udname,f.fname) AS ingName,
 	round( f.dry * ftd.FWEIGHT, 2 ) AS dmQty,
 	ftd.FWEIGHT AS afQty,
 	ftd.SORT AS mixNo,
@@ -350,13 +368,13 @@ func UdFeedtempletPush(pastureId, farmId string) error {
 	fc.fcname AS ingType,
 	f.AllowRatio AS allowableError ,fc.fcname ingType
 FROM
-	feedtemplet ft
-	 JOIN ftdetail ftd ON ft.id = ftd.FTID
+	feedtempletdate ft 
+	 JOIN ftdetaildate ftd ON ft.id = ftd.FTID  and ft.date = ftd.date
 	 JOIN feed f ON ftd.FID = f.id
 	 JOIN feedclass fc ON f.fclassid = fc.id 
 WHERE
 	ft.ENABLE = 1 
-	AND ft.isDelete != 1 `).Query().List()
+	AND ft.isDelete != 1  and ft.date = ?  `, now).Query().List()
 	if err != nil {
 		logging.Error(err)
 		return err

+ 3 - 0
win32.bat

@@ -0,0 +1,3 @@
+set GOARCH=386
+set GOOS=windows
+go build -o KPTAdmin32.exe

+ 4 - 0
win64.bat

@@ -0,0 +1,4 @@
+set GOARCH=amd64
+set GOOS=windows
+go clean
+go build -o KPTAdmin64.exe

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