Browse Source

usage: edit

Yi 1 year ago
parent
commit
563f7dc075
3 changed files with 73 additions and 69 deletions
  1. 2 0
      http/handle/group/feed_formula.go
  2. 11 11
      models/group_data.go
  3. 60 58
      module/group.go

+ 2 - 0
http/handle/group/feed_formula.go

@@ -246,10 +246,12 @@ func FeedUsage(c *gin.Context) {
 		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
 		return
 	}
+
 	if res, err := group.FeedUsageService(&req); err != nil {
 		appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
 			"error": err,
 		})
+		return
 	} else {
 		appG.Response(http.StatusOK, e.SUCCESS, res)
 	}

+ 11 - 11
models/group_data.go

@@ -210,19 +210,19 @@ type MixedDetail struct {
 	RealityWeight            float64 `json:"reality_weight"`              // 实际重量
 	PlanMixedOpts            int32   `json:"plan_mixed_opts"`             // 计划混料操作数
 	RealityMixedOpts         int32   `json:"reality_mixed_opts"`          // 已混料操作数
-	MixedOpsRatio            string  `json:"mixed_ops_ratio"`             // 混料操作率
+	MixedOpsRatio            float64 `json:"mixed_ops_ratio"`             // 混料操作率
 	MixedAutoJumpNumber      int32   `json:"mixed_auto_jump_number"`      // 混料自动跳转次数
 	MixedManualJumpNumber    int32   `json:"mixed_manual_jump_number"`    // 混料手动跳转次数
-	MixErrorNumber           int32   `json:"mix_error_number"`            // 混料误差值
-	MixedFodderAccurateRatio string  `json:"mixed_fodder_accurate_ratio"` // 混料准确率
+	MixErrorNumber           float64 `json:"mix_error_number"`            // 混料误差值
+	MixedFodderAccurateRatio float64 `json:"mixed_fodder_accurate_ratio"` // 混料准确率
 	Hlzq                     float64 `json:"hlzq"`
 	CancelNumber             int32   `json:"cancel_number"`               // 取消次数
 	VarianceRatio            float64 `json:"variance_ratio"`              // 方差
 	MixedFodderCorrectNumber string  `json:"mixed_fodder_correct_number"` // 混料正确数
-	MixedFodderCorrectRatio  string  `json:"mixed_fodder_correct_ratio"`  // 混料正确率
+	MixedFodderCorrectRatio  float64 `json:"mixed_fodder_correct_ratio"`  // 混料正确率
 	Hlzql                    float64 `json:"hlzql"`
 	Pid                      int32   `json:"pid"`
-	RemoveCancelCorrectRatio string  `json:"remove_cancel_correct_ratio"` // 去除取消正确率
+	RemoveCancelCorrectRatio float64 `json:"remove_cancel_correct_ratio"` // 去除取消正确率
 }
 
 type SprinkleDetail struct {
@@ -236,17 +236,17 @@ type SprinkleDetail struct {
 	RealityWeight               float64 `json:"reality_weight"`                 // 实际重量
 	PlanSprinkleOpts            int32   `json:"plan_sprinkle_opts"`             // 计划撒料操作数
 	RealitySprinkleOpts         int32   `json:"reality_sprinkle_opts"`          // 已撒料操作数
-	SprinkleOpsRatio            string  `json:"sprinkle_ops_ratio"`             // 撒料操作率
+	SprinkleOpsRatio            float64 `json:"sprinkle_ops_ratio"`             // 撒料操作率
 	SprinkleAutoJumpNumber      int32   `json:"sprinkle_auto_jump_number"`      // 撒料自动跳转次数
 	SprinkleManualJumpNumber    int32   `json:"sprinkle_manual_jump_number"`    // 撒料手动跳转次数
-	SprinkleErrorNumber         int32   `json:"sprinkle_error_number"`          // 撒料误差值
-	SprinkleFodderAccurateRatio string  `json:"sprinkle_fodder_accurate_ratio"` // 撒料准确率
+	SprinkleErrorNumber         float64 `json:"sprinkle_error_number"`          // 撒料误差值
+	SprinkleFodderAccurateRatio float64 `json:"sprinkle_fodder_accurate_ratio"` // 撒料准确率
 	Slzq                        float64 `json:"slzq"`
 	CancelNumber                int32   `json:"cancel_number"`                  // 取消次数
 	VarianceRatio               float64 `json:"variance_ratio"`                 // 方差
-	SprinkleFodderCorrectNumber string  `json:"sprinkle_fodder_correct_number"` // 撒料正确数
-	SprinkleFodderCorrectRatio  string  `json:"sprinkle_fodder_correct_ratio"`  // 撒料正确率
+	SprinkleFodderCorrectNumber int32   `json:"sprinkle_fodder_correct_number"` // 撒料正确数
+	SprinkleFodderCorrectRatio  float64 `json:"sprinkle_fodder_correct_ratio"`  // 撒料正确率
 	Slzql                       float64 `json:"slzql"`
 	Pid                         int32   `json:"pid"`
-	RemoveCancelCorrectRatio    string  `json:"remove_cancel_correct_ratio"` // 去除取消正确率
+	RemoveCancelCorrectRatio    float64 `json:"remove_cancel_correct_ratio"` // 去除取消正确率
 }

+ 60 - 58
module/group.go

@@ -3,9 +3,9 @@ package module
 import (
 	"errors"
 	"fmt"
+	"strconv"
 	"tmr-watch/http/handle/restful"
 	"tmr-watch/models"
-	"tmr-watch/pkg/logging"
 )
 
 const (
@@ -85,8 +85,8 @@ func SprinkleFodderData(req *models.AnalysisAccuracyRequest) ([]*models.MixedFod
 
 // MixedFodderCorrectData 混料正确率
 // SELECT
-//SUM(de.`havebuttom`) AS "已混料操作数",de.date,
-//IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`feedallowratio` AND de.`actualweightminus`<>0,1,0)),0) AS "混料正确数"
+//SUM(de.havebuttom) AS "已混料操作数",de.date,
+//IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio AND de.actualweightminus<>0,1,0)),0) AS "混料正确数"
 //FROM downloadplandtl1 de LEFT JOIN feedtemplet ft ON ft.id = de.fid
 //WHERE de.pastureid = 1653271339
 //AND ft.id =20 AND ft.ccid = ?
@@ -94,7 +94,7 @@ func SprinkleFodderData(req *models.AnalysisAccuracyRequest) ([]*models.MixedFod
 func MixedFodderCorrectData(req *models.AnalysisAccuracyRequest) ([]*models.MixedFodderCorrectDataList, error) {
 	res := make([]*models.MixedFodderCorrectDataList, 0)
 	newSql := restful.Engine.NewSession().Table("downloadplandtl1").Alias("de").
-		Select(`SUM(de.havebuttom) AS "use_mixed_fodder_option_number",de.date,IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio AND de.actualweightminus<>0,1,0)),0) AS "mixed_correct_number"`).
+		Select("SUM(de.havebuttom) AS use_mixed_fodder_option_number,de.date,IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio AND de.actualweightminus<>0,1,0)),0) AS mixed_correct_number").
 		Join("LEFT", []string{"feedtemplet", "ft"}, "ft.id = de.fid").
 		Where("de.pastureid = ?", req.PastureId)
 
@@ -118,7 +118,7 @@ func MixedFodderCorrectData(req *models.AnalysisAccuracyRequest) ([]*models.Mixe
 func SprinkleFodderCorrectData(req *models.AnalysisAccuracyRequest) ([]*models.SprinkleFodderCorrectDataList, error) {
 	res := make([]*models.SprinkleFodderCorrectDataList, 0)
 	newSql := restful.Engine.NewSession().Table("downloadplandtl2").Alias("de").
-		Select(`SUM(de.havebuttom) AS "use_sprinkle_option_number",de.date,IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio AND de.actualweightminus<>0,1,0)),0) AS "sprinkle_correct_number"`).
+		Select("SUM(de.havebuttom) AS use_sprinkle_option_number,de.date,IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio AND de.actualweightminus<>0,1,0)),0) AS sprinkle_correct_number").
 		Join("LEFT", []string{"feedtemplet", "ft"}, "ft.id = de.feedtempletid").
 		Where("de.pastureid = ?", req.PastureId)
 
@@ -368,10 +368,10 @@ func FeedTemplateUsageDetail(req *models.FeedFormulaUsageRequest) (*models.FeedF
 	}
 
 	response := &models.FeedFormulaUsageResponse{
-		MixedFodderAccurateRatio:    mixedDetail.MixedFodderAccurateRatio,
-		MixedFodderCorrectRatio:     mixedDetail.MixedFodderCorrectNumber,
-		SprinkleFodderAccurateRatio: sprinkleDetail.SprinkleFodderAccurateRatio,
-		SprinkleFodderCorrectRatio:  sprinkleDetail.SprinkleFodderCorrectRatio,
+		MixedFodderAccurateRatio:    strconv.FormatFloat(mixedDetail.MixedFodderAccurateRatio, 'f', 2, 64) + "%",
+		MixedFodderCorrectRatio:     strconv.FormatFloat(mixedDetail.MixedFodderCorrectRatio, 'f', 3, 64) + "%",
+		SprinkleFodderAccurateRatio: strconv.FormatFloat(sprinkleDetail.SprinkleFodderAccurateRatio, 'f', 3, 64) + "%",
+		SprinkleFodderCorrectRatio:  strconv.FormatFloat(sprinkleDetail.SprinkleFodderCorrectRatio, 'f', 3, 64) + "%",
 		AddFeedTime:                 "",
 		SprinkleTime:                "",
 		StirTime:                    "",
@@ -381,64 +381,66 @@ func FeedTemplateUsageDetail(req *models.FeedFormulaUsageRequest) (*models.FeedF
 }
 
 func getMixedDetail(pastureId, feedFormulaId int32, startTime, endTime string) (*models.MixedDetail, error) {
-	sql := fmt.Sprintf("SELECT * FROM ( SELECT DATE(de.`date`) as plan_time,IFNULL((SELECT d.`templetname` "+
-		"FROM `downloadedplan` d WHERE d.pastureid = de.pastureid AND d.id = de.pid),de.`fname`) as feed_formula_name,"+
-		"ROUND(SUM(de.`lweight`),2) as l_weight,ROUND(SUM(de.`actualweightminus`),2) as reality_weight,"+
-		"SUM(1) as plan_mixed_opts,SUM(de.`havebuttom`) as reality_mixed_opts, CONCAT(ROUND(SUM(de.`havebuttom`)/SUM(1)*100,2),'%')  as mixed_ops_ratio,"+
-		"SUM(IF(de.`buttontype` =1,1,0)) as mixed_auto_jump_number , SUM(IF(de.`buttontype`>1,1,0)) as mixed_manual_jump_number , "+
-		"ROUND(ABS(SUM(de.`lweight`)-SUM(de.`actualweightminus`)),2) as mix_error_number,"+
-		" CONCAT( IF (SUM(de.`actualweightminus`)>SUM(de.`lweight`),ROUND((SUM(de.`lweight`)/SUM(de.`actualweightminus`)*100),2) ,"+
-		"ROUND((SUM(de.`actualweightminus`)/SUM(de.`lweight`)*100) ,2)),'%') as mixed_fodder_accurate_ratio,"+
-		"IF (SUM(de.`actualweightminus`)>SUM(de.`lweight`),ROUND((SUM(de.`lweight`)/SUM(de.`actualweightminus`)*100),2) ,"+
-		"ROUND((SUM(de.`actualweightminus`)/SUM(de.`lweight`)*100) ,2)) hlzq,"+
-		"SUM(CASE WHEN (ABS(de.`actualweightminus`-de.`lweight`)/de.`lweight`)>3 AND  de.`lweight` >30 AND de.`actualweightminus` >30 THEN 1 ELSE 0 END) as cancel_number,"+
-		"ROUND(STD(ABS(de.`actualweightminus`-de.`lweight`)) ,2) as variance_ratio,"+
-		"IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`feedallowratio` AND de.`actualweightminus`<>0,1,0)),0) as mixed_fodder_correct_number,"+
-		"CONCAT(ROUND(IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`feedallowratio` AND de.`actualweightminus`<>0,1,0))/SUM(1),0)*100,2),'%') as mixed_fodder_correct_ratio,"+
-		"ROUND(IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`feedallowratio` AND de.`actualweightminus`<>0,1,0))/SUM(1),0)*100,2) hlzql,"+
-		"TRIM(de.pid) pid,"+
-		"CONCAT(ROUND(IFNULL(SUM(IF(((ABS(de.`actualweightminus`-de.`lweight`)/de.`lweight`)<=3 OR (de.`lweight` <30 AND de.`actualweightminus` <30 )),"+
-		"IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`feedallowratio` AND de.`actualweightminus`<>0,1,0),0))/SUM(IF(((ABS(de.`actualweightminus`-de.`lweight`)/de.`lweight`)<=3 OR (de.`lweight` <30 AND de.`actualweightminus` <30 )),1,0 )),0)*100,2),'%') as remove_cancel_correct_ratio "+
-		"FROM `downloadplandtl1` de WHERE  de.pastureid= ? and de.intime is not null AND (SELECT d.`lpplantype` FROM `downloadedplan` d WHERE d.pastureid = de.pastureid AND d.id = de.pid) IN (0,1,4) and de.`date` >= ? AND de.`date` <= ? "+
-		"GROUP BY de.dateORDER BY mixed_fodder_accurate_ratio DESC,feed_formula_name) tmr HAVING  feed_formula_id = ?", pastureId, startTime, endTime, feedFormulaId)
-	logging.Debug("getMixedDetail-sql", sql)
+	sql := fmt.Sprintf(`SELECT * FROM ( 
+		SELECT DATE(de.date) AS plan_time,
+		IFNULL((SELECT d.templetname FROM downloadedplan d WHERE d.pastureid = de.pastureid AND d.id = de.pid),de.fname) AS feed_formula_name,
+		IFNULL((SELECT d.tempid FROM downloadedplan d WHERE d.pastureid = de.pastureid AND d.id = de.pid),0) AS feed_formula_id,  
+		ROUND(SUM(de.lweight),2) AS l_weight,ROUND(SUM(de.actualweightminus),2) AS reality_weight,
+		SUM(1) AS plan_mixed_opts,SUM(de.havebuttom) AS reality_mixed_opts,
+		ROUND(SUM(de.havebuttom)/SUM(1)*100,2)  AS mixed_ops_ratio,
+		SUM(IF(de.buttontype =1,1,0)) AS mixed_auto_jump_number , SUM(IF(de.buttontype>1,1,0)) AS mixed_manual_jump_number ,
+		ROUND(ABS(SUM(de.lweight)-SUM(de.actualweightminus)),2) AS mix_error_number,
+		CONCAT( IF (SUM(de.actualweightminus)>SUM(de.lweight),ROUND((SUM(de.lweight)/SUM(de.actualweightminus)*100),2) ,
+		SUM(de.actualweightminus)/SUM(de.lweight)*100) ,2) AS mixed_fodder_accurate_ratio,
+		IF (SUM(de.actualweightminus)>SUM(de.lweight),
+		ROUND((SUM(de.lweight)/SUM(de.actualweightminus)*100),2) ,
+		ROUND((SUM(de.actualweightminus)/SUM(de.lweight)*100) ,2)) AS hlzq,
+		SUM(CASE WHEN (ABS(de.actualweightminus-de.lweight)/de.lweight)>3 AND  de.lweight >30 AND de.actualweightminus >30 THEN 1 ELSE 0 END) AS cancel_number,
+		ROUND(STD(ABS(de.actualweightminus-de.lweight)) ,2) AS variance_ratio,
+		IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio AND de.actualweightminus<>0,1,0)),0) AS mixed_fodder_correct_number,
+		ROUND(IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio AND de.actualweightminus<>0,1,0))/SUM(1),0)*100,2) AS mixed_fodder_correct_ratio,
+		ROUND(IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio AND de.actualweightminus<>0,1,0))/SUM(1),0)*100,2) hlzql,
+		TRIM(de.pid) pid,
+		ROUND(IFNULL(SUM(IF(((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 )),
+		IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio AND de.actualweightminus<>0,1,0),0))/SUM(IF(((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 )),1,0 )),0)*100,2) AS remove_cancel_correct_ratio
+		FROM downloadplandtl1 de WHERE  de.pastureid= %d AND de.intime IS NOT NULL AND (SELECT d.lpplantype FROM downloadedplan d WHERE d.pastureid = de.pastureid AND d.id = de.pid) IN (0,1,4) AND de.date >= '%s' AND de.date <= '%s'
+		GROUP BY de.date ) tmp HAVING tmp.feed_formula_id = %d`, pastureId, startTime, endTime, feedFormulaId)
 	dataList := &models.MixedDetail{}
-	if err := restful.Engine.NewSession().SQL(sql).Find(dataList); err != nil {
+	if _, err := restful.Engine.NewSession().SQL(sql).Get(dataList); err != nil {
 		return nil, err
 	}
 	return dataList, nil
 }
 
 func getSprinkleDetail(pastureId, feedFormulaId int32, startTime, endTime string) (*models.SprinkleDetail, error) {
-	sql := fmt.Sprintf("SELECT * FROM (SELECT DATE(d.`mydate`) AS plan_time,IFNULL((SELECT d.`templetname` FROM `downloadedplan` d "+
-		"WHERE d.pastureid = de.pastureid AND d.id = de.pid),de.`fname`) AS feed_formula_name,"+
-		"IFNULL((SELECT d.`tempid` FROM `downloadedplan` d WHERE d.pastureid = de.pastureid AND d.id = de.pid),0) AS feed_formula_id,"+
-		"d.tmrtname AS tmr_name,"+
-		"IFNULL(TIMEDIFF ((SELECT MAX(intime) FROM downloadplandtl2 d2 WHERE  d2.`pid`=de.`pid` AND d2.pastureid = de.pastureid ),(SELECT MAX(intime) FROM downloadplandtl1_exec d2 WHERE  d2.`pid`=de.`pid` AND d2.pastureid = de.pastureid )),'00:00:00')  AS mixed_time,"+
-		"IFNULL(TIMEDIFF ((SELECT MIN(intime) FROM downloadplandtl2 d2 WHERE  d2.`pid`=de.`pid` AND d2.pastureid = de.pastureid ),(SELECT MAX(intime) FROM downloadplandtl1_exec d2 WHERE  d2.`pid`=de.`pid` AND d2.pastureid = de.pastureid )),'00:00:00')  AS wait_time,"+
-		"SUM(de.`lweight`) AS l_weight,ROUND(SUM(de.`actualweightminus`)) AS reality_weight,"+
-		"SUM(1) AS plan_sprinkle_opts,"+
-		"SUM(de.`havebuttom`) AS reality_sprinkle_opts, "+
-		"CONCAT(ROUND(SUM(de.`havebuttom`)/SUM(1)*100,2),'%')  AS sprinkle_ops_ratio, "+
-		"SUM(IF(de.`buttontype` =1,1,0)) AS sprinkle_auto_jump_number ,  "+
-		"SUM(IF(de.`buttontype`>1,1,0)) AS sprinkle_manual_jump_number ,"+
-		"ABS(SUM(de.`actualweightminus`)-SUM(de.`lweight`)) AS sprinkle_error_number,"+
-		" CONCAT( IF (SUM(de.`actualweightminus`)>SUM(de.`lweight`),ROUND((SUM(de.`lweight`)/SUM(de.`actualweightminus`)*100),2) ,"+
-		"ROUND((SUM(de.`actualweightminus`)/SUM(de.`lweight`)*100) ,2)),'%') AS sprinkle_fodder_accurate_ratio,"+
-		"IF (SUM(de.`actualweightminus`)>SUM(de.`lweight`),ROUND((SUM(de.`lweight`)/SUM(de.`actualweightminus`)*100),2) ,"+
-		"ROUND((SUM(de.`actualweightminus`)/SUM(de.`lweight`)*100) ,2)) slzq,"+
-		"SUM(CASE WHEN (ABS(de.`actualweightminus`-de.`lweight`)/de.`lweight`)>3 AND  de.`lweight` >30 AND de.`actualweightminus` >30 THEN 1 ELSE 0 END) AS cancel_number,"+
-		"IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`allowratio` AND de.`actualweightminus`<>0,1,0)),0) AS sprinkle_fodder_correct_number,"+
-		"CONCAT(ROUND(IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`allowratio` AND de.`actualweightminus`<>0,1,0))/SUM(1),0)*100,2),'%') AS sprinkle_fodder_correct_ratio,"+
-		"ROUND(IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`allowratio` AND de.`actualweightminus`<>0,1,0))/SUM(1),0)*100,2) as slzql,"+
-		"TRIM(de.pid) pid,"+
-		"CONCAT(ROUND(IFNULL(SUM(IF(((ABS(de.`actualweightminus`-de.`lweight`)/de.`lweight`)<=3 OR (de.`lweight` <30 AND de.`actualweightminus` <30 )),"+
-		"IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`allowratio` AND de.`actualweightminus`<>0,1,0),0))/SUM(IF(((ABS(de.`actualweightminus`-de.`lweight`)/de.`lweight`)<=3 OR (de.`lweight` <30 AND de.`actualweightminus` <30 )),1,0 )),0)*100,2),'%') AS remove_cancel_correct_ratio "+
-		"FROM `downloadplandtl2` de JOIN `downloadedplan` d ON d.`id`=de.`pid` AND d.pastureid = de.pastureid WHERE  d.pastureid = ? AND DATE(d.`mydate`)  BETWEEN ? AND '?   AND d.lpplantype IN (0,2)) tmr HAVING  feed_formula_id = ? ",
+	sql := fmt.Sprintf(`SELECT * FROM (SELECT DATE(d.mydate) AS plan_time,
+        IFNULL((SELECT d.templetname FROM downloadedplan d WHERE d.pastureid = de.pastureid AND d.id = de.pid),de.fname) AS feed_formula_name,
+		IFNULL((SELECT d.tempid FROM downloadedplan d WHERE d.pastureid = de.pastureid AND d.id = de.pid),0) AS feed_formula_id,
+		d.tmrtname AS tmr_name,
+		IFNULL(TIMEDIFF ((SELECT MAX(intime) FROM downloadplandtl2 d2 WHERE  d2.pid=de.pid AND d2.pastureid = de.pastureid ),(SELECT MAX(intime) FROM downloadplandtl1_exec d2 WHERE  d2.pid=de.pid AND d2.pastureid = de.pastureid )),'00:00:00')  AS mixed_time,
+		IFNULL(TIMEDIFF ((SELECT MIN(intime) FROM downloadplandtl2 d2 WHERE  d2.pid=de.pid AND d2.pastureid = de.pastureid ),(SELECT MAX(intime) FROM downloadplandtl1_exec d2 WHERE  d2.pid=de.pid AND d2.pastureid = de.pastureid )),'00:00:00')  AS wait_time,
+		SUM(de.lweight) AS l_weight,ROUND(SUM(de.actualweightminus)) AS reality_weight,
+		SUM(1) AS plan_sprinkle_opts,
+		SUM(de.havebuttom) AS reality_sprinkle_opts, 
+		ROUND(SUM(de.havebuttom)/SUM(1)*100,2) AS sprinkle_ops_ratio, 
+		SUM(IF(de.buttontype =1,1,0)) AS sprinkle_auto_jump_number ,  
+		SUM(IF(de.buttontype>1,1,0)) AS sprinkle_manual_jump_number ,
+		ABS(SUM(de.actualweightminus)-SUM(de.lweight)) AS sprinkle_error_number,
+		CONCAT( IF (SUM(de.actualweightminus)>SUM(de.lweight),ROUND((SUM(de.lweight)/SUM(de.actualweightminus)*100),2) ,
+		SUM(de.actualweightminus)/SUM(de.lweight)*100) ,2) AS sprinkle_fodder_accurate_ratio,
+		IF (SUM(de.actualweightminus)>SUM(de.lweight),ROUND((SUM(de.lweight)/SUM(de.actualweightminus)*100),2) ,
+		ROUND((SUM(de.actualweightminus)/SUM(de.lweight)*100) ,2)) slzq,
+		SUM(CASE WHEN (ABS(de.actualweightminus-de.lweight)/de.lweight)>3 AND  de.lweight >30 AND de.actualweightminus >30 THEN 1 ELSE 0 END) AS cancel_number,
+		IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio AND de.actualweightminus<>0,1,0)),0) AS sprinkle_fodder_correct_number,
+		ROUND(IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio AND de.actualweightminus<>0,1,0))/SUM(1),0)*100,2) AS sprinkle_fodder_correct_ratio,
+		ROUND(IFNULL(SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio AND de.actualweightminus<>0,1,0))/SUM(1),0)*100,2) as slzql,
+		TRIM(de.pid) pid,
+		ROUND(IFNULL(SUM(IF(((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 )),
+		IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio AND de.actualweightminus<>0,1,0),0))/SUM(IF(((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 )),1,0 )),0)*100,2) AS remove_cancel_correct_ratio 
+		FROM downloadplandtl2 de JOIN downloadedplan d ON d.id=de.pid AND d.pastureid = de.pastureid WHERE  d.pastureid = %d AND DATE(d.mydate)  BETWEEN '%s' AND '%s'   AND d.lpplantype IN (0,2)) tmr HAVING  feed_formula_id = %d`,
 		pastureId, startTime, endTime, feedFormulaId)
-	logging.Debug("getSprinkleDetail-sql", sql)
 	dataList := &models.SprinkleDetail{}
-	if err := restful.Engine.NewSession().SQL(sql).Find(dataList); err != nil {
+	if _, err := restful.Engine.NewSession().SQL(sql).Get(dataList); err != nil {
 		return nil, err
 	}
 	return dataList, nil