|
|
@@ -20,6 +20,7 @@ import (
|
|
|
"tmr-watch/conf/setting"
|
|
|
"tmr-watch/http/handle/jpud"
|
|
|
"tmr-watch/http/handle/restful"
|
|
|
+ "tmr-watch/http/handle/ymy"
|
|
|
"tmr-watch/models"
|
|
|
"tmr-watch/module"
|
|
|
"tmr-watch/pkg/app"
|
|
|
@@ -1096,7 +1097,7 @@ func GetRJSBData(c *gin.Context) {
|
|
|
returntype := fsion.Get("returntype").ValueDefaultStr("map")
|
|
|
month := fsion.Get("month").ValueDefaultStr("map")
|
|
|
logging.Info("GetUpkeepPlan ", c.Keys, sqlnamestr, month)
|
|
|
- pagecount = 1
|
|
|
+ // pagecount = 1
|
|
|
tx := restful.Engine.NewSession()
|
|
|
err := tx.Begin()
|
|
|
defer func() {
|
|
|
@@ -6261,6 +6262,19 @@ func GetTMRListEnableTypeAll(c *gin.Context) {
|
|
|
data["enable"] = 1
|
|
|
data["id"] = fmt.Sprintf("%d", id)
|
|
|
data["pastureid"] = pastureid
|
|
|
+
|
|
|
+ // data := make(map[string]interface{}, 0)
|
|
|
+ // data["eqcode"] = fmt.Sprintf("AnyCar%d", n)
|
|
|
+ // data["tname"] = fmt.Sprintf("AnyCar%d", n)
|
|
|
+ // data["datacaptureno"] = -2
|
|
|
+ // data["tclassid"] = -2
|
|
|
+ // data["tmrmix"] = fmt.Sprintf("AnyCar%d", n)
|
|
|
+ // data["tclassname"] = fmt.Sprintf("AnyCar%d", n)
|
|
|
+ // data["maxstirfeed"] = 100000
|
|
|
+ // data["remark"] = fmt.Sprintf("AnyCar%d", n)
|
|
|
+ // data["enable"] = 1
|
|
|
+ // data["id"] = fmt.Sprintf("%d", id)
|
|
|
+ // data["pastureid"] = pastureid
|
|
|
dataList = append(dataList, data)
|
|
|
}
|
|
|
// UNION ALL
|
|
|
@@ -9314,7 +9328,7 @@ func UdFeedSync(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
// gm.UdFeedSync(pastureid, pastureinfo.Werks)
|
|
|
- jpud.UdBarSync(pastureid, pastureinfo.Werks)
|
|
|
+ jpud.UdFeedSync(pastureid, pastureinfo.Werks)
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
}
|
|
|
|
|
|
@@ -9405,6 +9419,103 @@ func UdMaterialIssuePush(c *gin.Context) {
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
}
|
|
|
|
|
|
+//搅拌
|
|
|
+func YmyUtirPush(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ 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()
|
|
|
+
|
|
|
+ pastureinfo := new(udPastureInfo)
|
|
|
+ err := tx.SQL(`select werks from pasture where pastureid = ?`, pastureid).GetFirst(pastureinfo).Error
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ymy.YmyUtirPush(pastureid, pastureinfo.Werks, date)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
+}
|
|
|
+
|
|
|
+//撒料
|
|
|
+func YmyMaterialIssuePush(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ 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()
|
|
|
+
|
|
|
+ pastureinfo := new(udPastureInfo)
|
|
|
+ err := tx.SQL(`select werks from pasture where pastureid = ?`, pastureid).GetFirst(pastureinfo).Error
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ymy.YmyMaterialIssuePush(pastureid, pastureinfo.Werks, date)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
+}
|
|
|
+
|
|
|
+func YmyFeedtempletPush(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ 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()
|
|
|
+
|
|
|
+ pastureinfo := new(udPastureInfo)
|
|
|
+ err := tx.SQL(`select werks from pasture where pastureid = ?`, pastureid).GetFirst(pastureinfo).Error
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ymy.YmyFeedtempletPush(pastureid, pastureinfo.Werks, date)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
+}
|
|
|
+
|
|
|
+//饲料
|
|
|
+func YmySyncFeed(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ 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()
|
|
|
+
|
|
|
+ ymy.YmySyncFeed(pastureid)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
+}
|
|
|
+
|
|
|
+// 栏舍
|
|
|
+func YmySyncBar(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ 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()
|
|
|
+
|
|
|
+ pastureinfo := new(udPastureInfo)
|
|
|
+ err := tx.SQL(`select werks from pasture where pastureid = ?`, pastureid).GetFirst(pastureinfo).Error
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ymy.YmySyncBar(pastureinfo.Werks, pastureid)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, "ok")
|
|
|
+}
|
|
|
+
|
|
|
func DelFeedTemplet(c *gin.Context) {
|
|
|
appG := app.Gin{C: c}
|
|
|
dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
@@ -9725,7 +9836,7 @@ func EditDownloadedplanArtificial(c *gin.Context) {
|
|
|
planIdList := strings.Split(planIdStr, ",")
|
|
|
|
|
|
for _, planId := range planIdList {
|
|
|
- _, err := tx.Exec(` update downloadedplan set artificial = 1 ,havebutton = 1,iscompleted = 1 where id = ? and havebutton != 1`, planId)
|
|
|
+ _, err := tx.Exec(` update downloadedplan set artificial = 1 ,havebutton = 1,iscompleted = 1 where id = ? `, planId)
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusOK, e.ERROR, "修改计划状态失败!"+err.Error())
|
|
|
@@ -11693,3 +11804,326 @@ select pastureid,(select id from feedtemplet where tcode = ? ),fid,fname,lweight
|
|
|
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
}
|
|
|
+
|
|
|
+func Test(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, string(dataByte))
|
|
|
+}
|
|
|
+
|
|
|
+func GetPlanDry(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+ dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
|
+ fsion := gofasion.NewFasion(string(dataByte))
|
|
|
+ date := fsion.Get("date").ValueStr()
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ dataList, err := tx.SQL(`SELECT
|
|
|
+t.feedtempletName,
|
|
|
+ifnull(t.feedtempletPrice,0)feedtempletPrice,
|
|
|
+ifnull(t.feedtempletWeight,0)feedtempletWeight,
|
|
|
+ifnull(t.feedtempletDryWeight,0)feedtempletDryWeight,
|
|
|
+ t.tmrno,
|
|
|
+ t.bname,
|
|
|
+ t.barid,
|
|
|
+ t.dry,
|
|
|
+ t.actualweightminus,
|
|
|
+ t.mydate,
|
|
|
+ t.pasturename,
|
|
|
+ t.endDate,
|
|
|
+ t.startDate,
|
|
|
+ t.times,
|
|
|
+ -- 计算startDate和endDate的中间时间
|
|
|
+ ifnull(DATE_FORMAT(
|
|
|
+ DATE_ADD(
|
|
|
+ t.startDate,
|
|
|
+ INTERVAL TIMESTAMPDIFF(SECOND, t.startDate, t.endDate)/2 SECOND
|
|
|
+ ),
|
|
|
+ '%Y-%m-%d %H:%i:%s'
|
|
|
+ ),'') AS midTime
|
|
|
+FROM (
|
|
|
+ SELECT
|
|
|
+ (SELECT sort FROM downloadedplan WHERE pid = d.pid AND mydate = d.mydate AND lpplantype IN (0,1)) tmrno,
|
|
|
+ b.bname,
|
|
|
+ b.id barid,
|
|
|
+ ROUND(IF(IFNULL(d2.actualweightminus,0) < 0, d2.lweight/(select sum(lweight) from downloadplandtl2 where pid = d2.pid )*(select sum(dd1.actualweightminus) from downloadplandtl1 dd1 join downloadedplan dd on dd1.pid = dd.id where dd.pid = d.pid and dd.mydate = d.mydate and dd.lpplantype in(0,1) ) , d2.actualweightminus/(select sum(lweight) from downloadplandtl2 where pid = d2.pid )*(select sum(dd1.actualweightminus) from downloadplandtl1 dd1 join downloadedplan dd on dd1.pid = dd.id where dd.pid = d.pid and dd.mydate = d.mydate and dd.lpplantype in(0,1) ) )*((SELECT IFNULL(AVG(dry),0) FROM downloadedplan dd
|
|
|
+ JOIN downloadplandtl1 dd1 ON dd.id = dd1.pid
|
|
|
+ JOIN feednur fn ON fn.fid = dd1.fid
|
|
|
+ WHERE dd.pid = d.pid AND dd.mydate = d.mydate AND lpplantype IN (0,1,4))/100),2) dry,
|
|
|
+ IF(IFNULL(d2.actualweightminus,0) < 0, d2.lweight/(select sum(lweight) from downloadplandtl2 where pid = d2.pid )*(select sum(dd1.actualweightminus) from downloadplandtl1 dd1 join downloadedplan dd on dd1.pid = dd.id where dd.pid = d.pid and dd.mydate = d.mydate and dd.lpplantype in(0,1) ) , d2.actualweightminus/(select sum(actualweightminus) from downloadplandtl2 where pid = d2.pid )*(select sum(dd1.actualweightminus) from downloadplandtl1 dd1 join downloadedplan dd on dd1.pid = dd.id where dd.pid = d.pid and dd.mydate = d.mydate and dd.lpplantype in(0,1) ) ) actualweightminus,
|
|
|
+ DATE_FORMAT(d.mydate,'%Y-%m-%d') mydate,
|
|
|
+ p.pasture_name pastureName,
|
|
|
+ DATE_FORMAT(d2.intime,'%Y-%m-%d %H:%i:%s') endDate,
|
|
|
+ DATE_FORMAT(IFNULL(
|
|
|
+ (SELECT MAX(intime) FROM downloadplandtl2 d1
|
|
|
+ WHERE d1.pid=d2.pid AND d1.pastureid = d2.pastureid AND d1.intime<d2.intime),
|
|
|
+ (SELECT MAX(intime) FROM downloadplandtl1_exec de
|
|
|
+ WHERE de.date=d2.date AND de.pastureid = d2.pastureid AND de.pid=d2.pid)
|
|
|
+ ), '%Y-%m-%d %H:%i:%s') startDate,
|
|
|
+ d.times ,
|
|
|
+ ( SELECT
|
|
|
+
|
|
|
+round(SUM(
|
|
|
+IF(ftd.preftid<>0,
|
|
|
+ ftd.fweight*IFNULL((SELECT SUM(ftd1.fweight*f1.dry/100)/SUM(ftd1.fweight) FROM ftdetaildate ftd1
|
|
|
+JOIN feednur f1 ON f1.fid= ftd1.fid AND f1.pastureid = ftd1.pastureid
|
|
|
+WHERE ftd1.pastureid = ftd.pastureid AND ftd1.ftid = ftd.preftid and ftd1.date = d2.date ),0),
|
|
|
+ftd.fweight*f.dry/100)) ,2)
|
|
|
+dryweight
|
|
|
+ FROM ftdetaildate ftd
|
|
|
+LEFT JOIN feednur f ON f.fid= ftd.fid AND f.pastureid = ftd.pastureid
|
|
|
+WHERE ftd.ftid = d.tempid and ftd.date = d2.date ) feedtempletDryWeight,(
|
|
|
+select
|
|
|
+sum(ftd.fweight)
|
|
|
+FROM ftdetaildate ftd
|
|
|
+WHERE ftd.ftid = d.tempid and ftd.date = d2.date ) feedtempletWeight,
|
|
|
+( SELECT
|
|
|
+
|
|
|
+round(SUM(
|
|
|
+IF(ftd.preftid<>0,
|
|
|
+IFNULL((SELECT SUM(ftd1.fweight*f1.uprice) FROM ftdetaildate ftd1
|
|
|
+JOIN feed f1 ON f1.id= ftd1.fid AND f1.pastureid = ftd1.pastureid
|
|
|
+WHERE ftd1.pastureid = ftd.pastureid AND ftd1.ftid = ftd.preftid and ftd1.date = d2.date ),0),
|
|
|
+ftd.fweight*f.uprice)) ,2)
|
|
|
+dryweight
|
|
|
+ FROM ftdetaildate ftd
|
|
|
+LEFT JOIN feed f ON f.id= ftd.fid AND f.pastureid = ftd.pastureid
|
|
|
+WHERE ftd.ftid = d.tempid and ftd.date = d2.date )
|
|
|
+ feedtempletPrice,d.templetname feedtempletName
|
|
|
+
|
|
|
+
|
|
|
+ FROM downloadedplan d
|
|
|
+ JOIN downloadplandtl2 d2 ON d.id=d2.PID
|
|
|
+ JOIN bar b ON b.id = d2.fbarid
|
|
|
+ JOIN pasture p ON p.pastureid = d.pastureid
|
|
|
+ WHERE d.mydate = DATE_FORMAT(?,'%Y-%m-%d')
|
|
|
+ AND d2.type = 0
|
|
|
+ AND d.havebutton = 1
|
|
|
+) t
|
|
|
+WHERE 1=1 `, date).QueryString()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, "查询失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, dataList)
|
|
|
+}
|
|
|
+
|
|
|
+func GetBar(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ pastureinfo := new(udPastureInfo)
|
|
|
+ err := tx.SQL(`select column_default as pastureid,(select werks from pasture where pastureid = column_default) werks from information_schema.COLUMNS
|
|
|
+ WHERE table_name = 'recweight' AND table_schema = ? AND column_name = 'pastureid'`, setting.DatabaseSetting.Name).GetFirst(pastureinfo).Error
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ dataList, err := tx.SQL(` select id,bname from bar where pastureid = ?`, pastureinfo.Pastureid).QueryString()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, "查询失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, dataList)
|
|
|
+}
|
|
|
+
|
|
|
+func GetHomepage(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+ dataList, err := tx.SQL(` SELECT
|
|
|
+ ifnull((SELECT CONCAT(ROUND(if(SUM(lweight) <= SUM(iweight),SUM(lweight)/SUM(iweight),SUM(iweight)/SUM(lweight))*100,2),'%') yesRateHL
|
|
|
+ FROM downloadedplan dt WHERE dt.pastureid = d.pastureid
|
|
|
+ AND dt.mydate=DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 1 DAY),'%Y-%m-%d') and dt.lpplantype in(0,1) ),'0.00%')yesRateHL, -- 昨日混料准确率
|
|
|
+ (SELECT CONCAT(ROUND(SUM(iweight)/SUM(lweight)*100,2),'%') yesRateHL
|
|
|
+ FROM downloadedplan dt WHERE dt.pastureid = d.pastureid
|
|
|
+ AND dt.mydate BETWEEN DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 31 DAY),'%Y-%m-%d') AND DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 1 DAY),'%Y-%m-%d') and dt.lpplantype in(0,1) )monRateHL , -- 近30日混料准确率
|
|
|
+
|
|
|
+ ifnull((SELECT CONCAT(ROUND(SUM(oweight)/SUM(lweight)*100,2),'%') yesRateSL
|
|
|
+ FROM downloadedplan dt WHERE dt.pastureid = d.pastureid
|
|
|
+ AND dt.mydate=DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 1 DAY),'%Y-%m-%d') and dt.lpplantype in(0,2) ),'0.00%')yesRateSL, -- 昨日撒料准确率
|
|
|
+
|
|
|
+ (SELECT CONCAT(ROUND(SUM(oweight)/SUM(lweight)*100,2),'%') yesRateSL
|
|
|
+ FROM downloadedplan dt WHERE dt.pastureid = d.pastureid
|
|
|
+ AND dt.mydate BETWEEN DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 31 DAY),'%Y-%m-%d') AND DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 1 DAY),'%Y-%m-%d') and dt.lpplantype in(0,2) )monRateSL, -- 进30日撒料准确率
|
|
|
+
|
|
|
+ ifnull((SELECT CONCAT(ROUND(IF(COUNT(de.id)>0,SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio,1,0))/COUNT(de.id),0)*100,2),'%') -- 正确率
|
|
|
+ FROM downloadedplan dt JOIN downloadplandtl2 de ON dt.id=de.pid AND dt.pastureid = de.pastureid
|
|
|
+ WHERE dt.pastureid = d.pastureid AND dt.mydate=DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 1 DAY),'%Y-%m-%d')),'0.00%') yesRateSLR, -- 昨日正确率
|
|
|
+
|
|
|
+ (SELECT CONCAT(ROUND(IF(COUNT(de.id)>0,SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.allowratio,1,0))/COUNT(de.id),0)*100,2),'%') -- 正确率
|
|
|
+ FROM downloadedplan dt JOIN downloadplandtl2 de ON dt.id=de.pid AND dt.pastureid = de.pastureid
|
|
|
+ WHERE dt.pastureid = d.pastureid
|
|
|
+ AND dt.mydate BETWEEN DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 31 DAY),'%Y-%m-%d') AND DATE_FORMAT(DATE_SUB(d.mydate,INTERVAL 1 DAY),'%Y-%m-%d')) monRateSLR, -- 近30日正确率
|
|
|
+
|
|
|
+ (SELECT COUNT(*)FROM downloadedplan dt WHERE dt.pastureid= d.pastureid AND dt.mydate = d.mydate and dt.iscompleted=1 and if ( 0 = 0 ,1=1, if(0 = 1 ,dt.lpplantype in(0,1), dt.lpplantype in(0,2) ) )) doneTimes,
|
|
|
+ (SELECT COUNT(*)FROM downloadedplan dt WHERE dt.pastureid= d.pastureid AND dt.mydate = d.mydate and if ( 0 = 0 ,1=1, if(0 = 1 ,dt.lpplantype in(0,1), dt.lpplantype in(0,2) ) ) ) planTimes,
|
|
|
+ ifnull((SELECT SUM(dc.actualweightminus) FROM downloadplandtl1_exec dc join downloadedplan dt on dt.id = dc.pid WHERE dc.pastureid = 0 AND dc.date = d.mydate and if ( 0 = 0 ,1=1, if(0 = 1 ,dt.lpplantype in(0,1), dt.lpplantype in(0,2) ) ) ),0) doneWeight,
|
|
|
+ ifnull((SELECT SUM(dc.lweight ) FROM downloadplandtl1_exec dc join downloadedplan dt on dt.id = dc.pid WHERE dc.pastureid = 0 AND dc.date = d.mydate and if ( 0 = 0 ,1=1, if(0 = 1 ,dt.lpplantype in(0,1), dt.lpplantype in(0,2) ) ) ),0) planWeight,
|
|
|
+ ifnull(round(getSLtimeDiffSINGEL(d.pastureid,d.mydate),2),0.00) temtime,
|
|
|
+ ifnull(round(getSLtimeDiffMonth(d.pastureid) ,2),0.00) montime
|
|
|
+ FROM
|
|
|
+ (SELECT (select column_default as pastureid from information_schema.COLUMNS
|
|
|
+ WHERE table_name = 'recweight' AND table_schema = ? AND column_name = 'pastureid') as pastureid,date_format(now(),'%Y-%m-%d') mydate) d `, setting.DatabaseSetting.Name).QueryString()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, "查询失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ dataList1, err := tx.SQL(`select
|
|
|
+ ifnull(round(sum(if(d1.feedcode = '-1', d1.actualweightminus * (ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.ftid = d1.fid ))* f.uprice,f.uprice * d1.actualweightminus )) / (select sum(ccount) from downloadplandtl2 d2 join bar b on b.id = d2.fbarid join feedp fp on fp.barid = b.id where date = d1.date),2),0) cost , ifnull(round(sum(if(d1.feedcode = '-1', d1.actualweightminus * (ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.ftid = d1.fid ))* f.uprice,f.uprice * d1.actualweightminus )),2),0) totalCost from downloadplandtl1 d1
|
|
|
+ LEFT JOIN ftdetail ftd ON ftd.pastureid =d1.pastureid AND ftd.ftid = d1.fid AND d1.feedcode = '-1'
|
|
|
+ join feed f on f.id = ifnull(ftd.fid,d1.fid) where d1.date = date_format(now(),'%Y-%m-%d') `).QueryString()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, "查询失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, data := range dataList {
|
|
|
+ for _, data1 := range dataList1 {
|
|
|
+ data["totalCost"] = data1["totalCost"]
|
|
|
+ data["cost"] = data1["cost"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, dataList)
|
|
|
+}
|
|
|
+
|
|
|
+func GetFeedingManagement(c *gin.Context) {
|
|
|
+ appG := app.Gin{C: c}
|
|
|
+
|
|
|
+ typea := c.Query("typea") // 0 栏舍 1 日期
|
|
|
+ startDate := c.Query("startdate")
|
|
|
+ endDate := c.Query("enddate")
|
|
|
+ tx := restful.Engine.NewSession()
|
|
|
+ defer tx.Close()
|
|
|
+
|
|
|
+ if typea == "0" {
|
|
|
+ dataList, err := tx.SQL(`select t.bname typea ,round(t.actualweightminus,2) actualweightminus ,round(t.dryweight,2) dryweight ,round(t.priceweight,2) totalcost ,round(t.priceweight / t.ccount,2) cost,t.ccount from (SELECT
|
|
|
+ SUM(
|
|
|
+ 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 ftdetaildate ftd2 WHERE ftd2.date = d1.date AND ftd2.version = ftd1.version and 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 = ftd1.version and ftd1.id = ftd2.ftid ))
|
|
|
+ )
|
|
|
+ )actualweightminus ,
|
|
|
+ SUM(
|
|
|
+ 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 ftdetaildate ftd2 WHERE ftd2.date = d1.date AND ftd2.version = ftd1.version and 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 = ftd1.version and ftd1.id = ftd2.ftid ))
|
|
|
+ ) * ifnull(fn.dry,0)
|
|
|
+ ) dryweight , SUM(
|
|
|
+ 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 ftdetaildate ftd2 WHERE ftd2.date = d1.date AND ftd2.version = ftd1.version and 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 = ftd1.version and ftd1.id = ftd2.ftid ))
|
|
|
+ ) * ifnull(f.uprice,0)
|
|
|
+ ) priceweight
|
|
|
+ ,(select ccount from feedpdate where date = d1.date and barid = d2.fbarid) ccount,b.bname
|
|
|
+
|
|
|
+ FROM
|
|
|
+downloadedplan d
|
|
|
+
|
|
|
+JOIN downloadplandtl2 d2
|
|
|
+ON d.pastureid = d2.pastureid AND d2.pid = d.id and d2.type = 0
|
|
|
+JOIN downloadplandtl1 d1
|
|
|
+ON d.pastureid = d1.pastureid AND d1.flpid = d2.flpid AND d1.type = 0 AND d2.date = d1.date
|
|
|
+left join feedtempletdate ftd1 on d1.feedcode = '-1' and ftd1.date = d1.date and ftd1.id = d1.fid
|
|
|
+LEFT JOIN ftdetaildate ftd ON ftd.pastureid =d1.pastureid AND ftd.ftid = ftd1.id AND d1.feedcode = '-1' AND ftd.date =d1.date AND ftd.version = ftd1.version
|
|
|
+left join bar b on b.pastureid =d1.pastureid and b.id = d2.fbarid
|
|
|
+join feed f on f.id = if(d1.feedcode = '-1' , ftd.fid,d1.fid)
|
|
|
+left join feednur fn on fn.fid = f.id
|
|
|
+
|
|
|
+WHERE d.mydate BETWEEN ? AND ? GROUP BY d2.fbarid ) t `, startDate, endDate).QueryString()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, "查询失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, dataList)
|
|
|
+ } else {
|
|
|
+ dataList, err := tx.SQL(`select date_format(t.date ,'%Y-%m-%d') typea ,round(t.actualweightminus,2) actualweightminus ,round(t.dryweight,2) dryweight ,round(t.priceweight,2) totalcost ,round(t.priceweight / (select sum(ccount) from feedpdate fp where fp.date = t.date and fp.barid in(select fbarid from downloadplandtl2 where date = t.date and type = 0) ) ,2) cost,(select sum(ccount) from feedpdate fp where fp.date = t.date and fp.barid in(select fbarid from downloadplandtl2 where date = t.date and type = 0) ) ccount from (SELECT
|
|
|
+ SUM(
|
|
|
+ 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 ftdetaildate ftd2 WHERE ftd2.date = d1.date AND ftd2.version = ftd1.version and 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 = ftd1.version and ftd1.id = ftd2.ftid ))
|
|
|
+ )
|
|
|
+ )actualweightminus ,
|
|
|
+ SUM(
|
|
|
+ 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 ftdetaildate ftd2 WHERE ftd2.date = d1.date AND ftd2.version = ftd1.version and 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 = ftd1.version and ftd1.id = ftd2.ftid ))
|
|
|
+ ) * ifnull(fn.dry,0)
|
|
|
+ ) dryweight , SUM(
|
|
|
+ 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 ftdetaildate ftd2 WHERE ftd2.date = d1.date AND ftd2.version = ftd1.version and 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 = ftd1.version and ftd1.id = ftd2.ftid ))
|
|
|
+ ) * ifnull(f.uprice,0)
|
|
|
+ ) priceweight
|
|
|
+ ,(select sum(ccount) from feedpdate fp join downloadplandtl2 dd2 on dd2.fbarid = fp.barid where fp.date = d2.date and dd2.date = d2.date ) ccount,d2.date
|
|
|
+
|
|
|
+ FROM
|
|
|
+downloadedplan d
|
|
|
+
|
|
|
+JOIN downloadplandtl2 d2
|
|
|
+ON d.pastureid = d2.pastureid AND d2.pid = d.id and d2.type = 0
|
|
|
+JOIN downloadplandtl1 d1
|
|
|
+ON d.pastureid = d1.pastureid AND d1.flpid = d2.flpid AND d1.type = 0 AND d2.date = d1.date
|
|
|
+left join feedtempletdate ftd1 on d1.feedcode = '-1' and ftd1.date = d1.date and ftd1.id = d1.fid
|
|
|
+LEFT JOIN ftdetaildate ftd ON ftd.pastureid =d1.pastureid AND ftd.ftid = ftd1.id AND d1.feedcode = '-1' AND ftd.date =d1.date AND ftd.version = ftd1.version
|
|
|
+left join bar b on b.pastureid =d1.pastureid and b.id = d2.fbarid
|
|
|
+join feed f on f.id = if(d1.feedcode = '-1' , ftd.fid,d1.fid)
|
|
|
+left join feednur fn on fn.fid = f.id
|
|
|
+WHERE d.mydate BETWEEN ? AND ?
|
|
|
+GROUP BY d.mydate) t `, startDate, endDate).QueryString()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusOK, e.ERROR, "查询失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ appG.Response(http.StatusOK, e.SUCCESS, dataList)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// doneTimes 完成计划
|
|
|
+// doneWeight 完成重量
|
|
|
+// monRateHL 近三十天混料准确率
|
|
|
+// monRateSL 近三十天撒料准确率
|
|
|
+// monRateSLR 近30天撒料正确率
|
|
|
+// montime 近30天撒料偏差
|
|
|
+// planTimes 计划车次
|
|
|
+// planWeight 计划重量
|
|
|
+// temtime 撒料偏差
|
|
|
+// yesRateHL 混料准确率
|
|
|
+// yesRateSL 撒料准确率
|
|
|
+// yesRateSLR 撒料正确率
|