package module import ( "tmr-watch/http/handle/restful" "tmr-watch/models" ) // MixedFodderData 混料准确率和撒料准确率 func MixedFodderData(req *models.AnalysisAccuracyRequest) ([]*models.MixedFodderDataList, error) { res := make([]*models.MixedFodderDataList, 0) newSql := restful.Engine.NewSession().Table("downloadedplan").Alias("dp"). Select("dp.oweight,dp.lweight,dp.iweight,dp.mydate"). Join("LEFT", []string{"feedtemplet", "ft"}, "dp.tempid = ft.id"). Where("dp.pastureid = ?", req.PastureId) if len(req.StartDate) > 0 && len(req.EndDate) > 0 { newSql.And("dp.mydate >= ? and dp.mydate <= ?", req.StartDate, req.EndDate) } if req.CattleParentCategoryId > 0 { newSql.And("ft.ccid = ?", req.CattleParentCategoryId) } if req.FeedFormulaId > 0 { newSql.And("dp.tempid = ?", req.FeedFormulaId) } if err := newSql.GroupBy("dp.mydate").OrderBy("dp.mydate").Find(&res); err != nil { return nil, err } return res, nil } // 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 "混料正确数" //FROM downloadplandtl1 de LEFT JOIN feedtemplet ft ON ft.id = de.fid //WHERE de.pastureid = 1653271339 //AND ft.id =20 AND ft.ccid = ? //GROUP BY de.date ORDER BY de.date 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"`). Join("LEFT", []string{"feedtemplet", "ft"}, "ft.id = de.fid"). Where("de.pastureid = ?", req.PastureId) if len(req.StartDate) > 0 && len(req.EndDate) > 0 { newSql.And("de.date >= ? and de.date <= ?", req.StartDate, req.EndDate) } if req.CattleParentCategoryId > 0 { newSql.And("ft.ccid = ?", req.CattleParentCategoryId) } if req.FeedFormulaId > 0 { newSql.And("de.tempid = ?", req.FeedFormulaId) } if err := newSql.GroupBy("de.date").OrderBy("de.date").Find(&res); err != nil { return nil, err } return res, nil } 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"`). Join("LEFT", []string{"feedtemplet", "ft"}, "ft.id = de.feedtempletid"). Where("de.pastureid = ?", req.PastureId) if len(req.StartDate) > 0 && len(req.EndDate) > 0 { newSql.And("de.date >= ? and de.date <= ?", req.StartDate, req.EndDate) } if req.CattleParentCategoryId > 0 { newSql.And("ft.ccid = ?", req.CattleParentCategoryId) } if req.FeedFormulaId > 0 { newSql.And("de.tempid = ?", req.FeedFormulaId) } if err := newSql.GroupBy("de.date").OrderBy("de.date").Find(&res); err != nil { return nil, err } return res, nil } func ProcessAnalysisData(req *models.AnalysisAccuracyRequest) ([]*models.ProcessData, error) { res := make([]*models.ProcessData, 0) newSql := restful.Engine.Table("downloadplandtl1_exec").Alias("e"). Select("e.id,e.begintime as exec_begin_time,e.intime as exec_end_time,e.processtime as exec_process_time,e.stirdelay as exec_stir_delay ,l2.begintime as l2_begin_time,l2.intime as l2_end_time,l2.processtime as l2_process_time"). Join("LEFT", []string{"downloadplandtl2", "l2"}, "e.pastureid = l2.pastureid and e.pid = l2.pid"). Where("e.pastureid = ?", req.PastureId) if len(req.StartDate) > 0 && len(req.EndDate) > 0 { newSql.And("e.date >= ? and e.date <= ?", req.StartDate, req.EndDate) } if req.CattleParentCategoryId > 0 { newSql.And("l2.cowclassid = ?", req.CattleParentCategoryId) } if req.FeedFormulaId > 0 { newSql.And("l2.feedtempletid = ?", req.FeedFormulaId) } if err := newSql.GroupBy("e.date").OrderBy("e.date").Find(&res); err != nil { return nil, err } return res, nil } func SprinkleStatistics(req *models.SprinkleStatisticsRequest) ([]*models.SprinkleStatisticsDataList, error) { res := make([]*models.SprinkleStatisticsDataList, 0) newSql := restful.Engine.Table("downloadplandtl2").Alias("a").Select("a.fbarid,a.fname,a.intime,a.processtime,b.times"). Join("LEFT", []string{"downloadedplan", "b"}, "a.pastureid = b.pastureid AND b.pid = a.pid"). Where("a.pastureid = ?", req.PastureId).And("b.times > 0 ").And("a.fbarid > 0") if len(req.StartDate) > 0 && len(req.EndDate) > 0 { newSql.And("a.date >= ? and a.date <= ?", req.StartDate, req.EndDate) } if req.FeedFormulaId > 0 { newSql.And("a.feedtempletid = ?", req.FeedFormulaId) } if err := newSql.GroupBy("a.fbarid ,b.intime").Find(&res); err != nil { return nil, err } return res, nil }