1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549 |
- package api
- import (
- "fmt"
- "io/ioutil"
- "net/http"
- "strconv"
- "time"
- "tmr-watch/http/handle/restful"
- "tmr-watch/pkg/app"
- "tmr-watch/pkg/e"
- "github.com/Anderson-Lu/gofasion/gofasion"
- "github.com/astaxie/beego/logs"
- "github.com/gin-gonic/gin"
- )
- func GetFeedEffMR(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").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 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()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else if status == "1" {
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- 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()
- 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 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- }
- queryData, err := getAccuracyV2(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffMRJT(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT IFNULL(SUM(d2.actualweightminus),0) 准确率, -- 采食量
- (SELECT pasture_name FROM pasture WHERE pastureid = d.pastureid) 名称,
- %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 = d.mydate
- JOIN
- (SELECT pastureid FROM groups_pasture WHERE groupsid = ?
- UNION
- SELECT pastureid FROM pasture WHERE groupsid = ?
- ) tem ON tem.pastureid = d.pastureid
-
- WHERE d.mydate BETWEEN ? AND ? AND d.lpplantype IN (0,1,2,5) AND d2.type = 0
- AND IF(bm.idIS NOT NULL,bm.bigcowclass = '泌乳牛',1=1)
- GROUP BY d.pastureid,日期 ORDER BY 名称, 日期 `
- 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, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else if status == "1" {
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- 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, pastureId, pastureId, startDate, endDate).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 "
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- }
- queryData, err := getAccuracyV2(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffSL(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT
- fp.barname 名称,
- IFNULL(SUM(d2.actualweightminus),0) 撒料量,
- IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = fp.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)准确率, -- 剩料率
- %s 日期
- FROM
- downloadedplan d
- JOIN downloadplandtl2 d2
- ON d2.pastureid = d.pastureid AND d2.pid = d.id
- 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 fp.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(fp.date, '%Y-%m-%d') ")
- sqlStr += " GROUP BY fp.barname , DATE_FORMAT(fp.date, '%Y-%m-%d') ORDER BY fp.barname ,fp.date "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(fp.date,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- sqlStr += " GROUP BY fp.barname , 日期 ORDER BY fp.barname ,fp.date "
- fmt.Println(sqlStr)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(fp.date, '%Y-%m') ")
- sqlStr += " GROUP BY fp.barname , DATE_FORMAT(fp.date, '%Y-%m') ORDER BY fp.barname ,fp.date "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffSLJT(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT
- (SELECT pasture_name FROM pasture WHERE pastureid = d.pastureid) 名称,
- IFNULL(SUM(d.oweight),0) 撒料量,
- IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = fp.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(d.oweight),2),0)准确率, -- 剩料率
- %s 日期
-
- FROM
- feedpdate fp
-
- RIGHT JOIN downloadedplan d
- ON d.pastureid = fp.pastureid AND d.mydate = fp.date AND d.templetname = fp.ftname
-
- LEFT JOIN barmilk bm
- ON bm.pastureid =fp.pastureid AND bm.barid = fp.barid AND bm.productdate = fp.date
-
- JOIN
- (SELECT pastureid FROM groups_pasture WHERE groupsid = ?
- UNION
- SELECT pastureid FROM pasture WHERE groupsid = ?
- ) tem
- ON tem.pastureid = d.pastureid
-
-
- WHERE fp.date BETWEEN ? AND ? AND d.lpplantype<3
- GROUP BY d.pastureid ,日期
- ORDER BY 名称 ,日期`
- var data []map[string]interface{}
- var err error
- if status == "0" {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.mydate, '%Y-%m-%d') ")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- fmt.Println(sqlStr)
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).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') ")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffHL(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- 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) `
- 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).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- sqlStr += " GROUP BY 日期 ORDER BY 日期 "
- fmt.Println(sqlStr)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.mydate, '%Y-%m') ")
- sqlStr += " GROUP BY DATE_FORMAT(d.mydate, '%Y-%m') ORDER BY d.mydate "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracyV2(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffHLJT(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT
- (SELECT pasture_name FROM pasture WHERE pastureid = d.pastureid) 名称,
- %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
- (SELECT pastureid FROM groups_pasture WHERE groupsid = ?
- UNION
- SELECT pastureid FROM pasture WHERE groupsid = ?
- ) tem
- ON tem.pastureid = d.pastureid
- WHERE d.mydate BETWEEN ? AND ? AND d.lpplantype<3
- GROUP BY d.pastureid,日期
- ORDER BY 名称,日期`
- 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, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).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 DATE_FORMAT(d.mydate, '%Y-%m') ORDER BY d.mydate "
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- }
- queryData, err := getAccuracyV2(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffZH(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT
- 日期,
- 配方模板 名称,
- IFNULL(ROUND(IFNULL(产奶量/实际牛头数,0)/((撒料量 - 今日剩料量)*TMR干物质/实际牛头数)*100,2),0) 准确率 -- 饲料转化率
- FROM (
- SELECT
- %s 日期,
- d.templetname 配方模板,
- (SELECT SUM(ccount) FROM feedpdate fpt WHERE fpt.pastureid = d.pastureid AND fpt.date = d.mydate AND fpt.ftid = d.tempid)实际牛头数,
- @tid := d.tempid tempid,
- @da := d.mydate,
- (SELECT SUM(bm.product*bm.cowsum) FROM
- (SELECT DISTINCT d21.fbarid,d21.date,d21.pastureid,d1.tempid 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
- GROUP BY d1.tempid,d1.mydate) 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.tempid = @tid AND ww.date = @da
- ) 产奶量,
- SUM(d2.actualweightminus) 撒料量,
- SUM(IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = fp.pastureid AND bf.barid = fp.barid AND bf.remaindate = fp.date),0)) 今日剩料量,
- SUM(IFNULL((SELECT AVG(actweight) FROM ftdry fd WHERE fd.pastureid = fp.pastureid AND fd.barid = fp.barid AND fd.operatetime = (SELECT MAX(operatetime) FROM ftdry fd1 WHERE fd1.pastureid = fp.pastureid AND fd1.barid = fp.barid AND fd1.operatetime <=fp.date )),0)*d2.actualweightminus)/SUM(d2.actualweightminus) TMR干物质
- FROM
- downloadedplan d
- JOIN downloadplandtl2 d2
- ON d2.pastureid = d.pastureid AND d2.pid = d.id
- 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 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(fp.date, '%Y-%m-%d') ")
- sqlStr += " GROUP BY d.tempid,日期 ) tem ORDER BY 名称,日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(fp.date,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- sqlStr += " GROUP BY d.tempid,日期 ) tem ORDER BY 名称,日期 "
- fmt.Println(sqlStr)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(fp.date, '%Y-%m') ")
- sqlStr += " GROUP BY d.tempid,日期 ) tem ORDER BY 名称,日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffZHJT(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `
- SELECT
- 日期,
- (SELECT pasture_name FROM pasture WHERE pastureid = tem.pastureid) 名称,
- IFNULL(ROUND((产奶量)/((撒料量 - 今日剩料量)*TMR干物质)*100,2),'0.00') 准确率 -- 饲料转化率
- FROM (
- SELECT
- d.pastureid,
- %s 日期,
- fp.ftname 配方模板,SUM(bm.product)产奶量,
- SUM(d.oweight) 撒料量,
- IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = fp.pastureid AND bf.barid = fp.barid AND bf.remaindate = fp.date),0) 今日剩料量,
- IFNULL((SELECT AVG(actweight) FROM ftdry fd WHERE fd.pastureid = fp.pastureid AND fd.barid = fp.barid AND fd.operatetime = fp.date),0) TMR干物质
-
- FROM
- feedpdate fp
-
- INNER JOIN downloadedplan d
- ON d.pastureid = fp.pastureid AND d.mydate = fp.date AND d.templetname = fp.ftname
-
- LEFT JOIN barmilk bm
- ON bm.pastureid =fp.pastureid AND bm.barid = fp.barid AND bm.productdate = (SELECT MAX(productdate) FROM barmilk WHERE barmilk.productdate <=fp.date AND barmilk.pastureid = fp.pastureid and barmilk.barid = fp.barid)
-
- JOIN
- (SELECT pastureid FROM groups_pasture WHERE groupsid = ?
- UNION
- SELECT pastureid FROM pasture WHERE groupsid = ?
- ) tem
- ON tem.pastureid = d.pastureid
- WHERE fp.date BETWEEN ? AND ? AND d.lpplantype<3
- GROUP BY d.pastureid,日期 ) tem
- ORDER BY 名称,日期`
- var data []map[string]interface{}
- var err error
- if status == "0" {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(fp.date, '%Y-%m-%d') ")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else if status == "1" {
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(fp.date,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(fp.date, '%Y-%m') ")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- func GetFeedEffCBFT(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT
- 日期,
- 配方 名称,
- IFNULL(ROUND(实际混料量*配方单价/产奶量,2),0) 准确率 -- 公斤奶饲料成本
- FROM (
- SELECT
- %s 日期,
- fp.ftname 配方,
- (SELECT SUM(d1e.actualweightminus) FROM downloadplandtl1_exec d1e
- JOIN downloadedplan dv ON dv.pastureid= d1e.pastureid AND dv.id = d1e.pid
- WHERE d1e.pastureid = d.pastureid AND dv.mydate = d.mydate AND d1e.type = 0 AND dv.tempid= d.tempid)实际混料量,
- @tid := d.tempid tempid,
- @da := d.mydate,
- (SELECT SUM(bm.product*bm.cowsum) FROM
- (SELECT DISTINCT d21.fbarid,d21.date,d21.pastureid,d1.tempid 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
- GROUP BY d1.tempid,d1.mydate) 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.tempid = @tid AND ww.date = @da
- ) 产奶量,
- (SELECT SUM(
- IF(ftd.preftid<>0,
- (SELECT SUM(f1.uprice* ftd1.fweight)/SUM(ftd1.fweight) FROM ftdetaildate ftd1
- LEFT JOIN feed f1
- ON f1.pastureid = ftd1.pastureid AND f1.id = ftd1.fid
- WHERE ftd1.pastureid = ftd.pastureid AND ftd1.date = ftd.date AND ftd1.ftid = ftd.preftid
- AND ftd1.version = (SELECT MAX(VERSION) FROM ftdetaildate ftd2 WHERE ftd2.pastureid = ftd.pastureid AND ftd2.date = ftd.date AND ftd2.ftid = ftd.preftid)),
-
- f.uprice)*ftd.fweight)/SUM(ftd.fweight) FROM ftdetaildate ftd
- LEFT JOIN feed f
- ON f.pastureid = ftd.pastureid AND f.id = ftd.fid
- WHERE ftd.pastureid = fp.pastureid AND ftd.date = fp.date AND ftd.ftid = fp.ftid AND ftd.version = d.tversion
- ) 配方单价
-
- FROM
- downloadedplan d
- JOIN downloadplandtl2 d2
- ON d2.pastureid = d.pastureid AND d2.pid = d.id
- LEFT JOIN feedpdate fp
- ON d.pastureid = fp.pastureid AND d.mydate = fp.date AND fp.barid = d2.fbarid
- WHERE fp.date BETWEEN ? AND ? AND fp.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(fp.date, '%Y-%m-%d') ")
- sqlStr += " GROUP BY d.tempid,日期) tem ORDER BY 名称,日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(fp.date,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- sqlStr += " GROUP BY d.tempid,日期) tem ORDER BY 名称,日期 "
- fmt.Println(sqlStr)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(fp.date, '%Y-%m') ")
- sqlStr += " GROUP BY d.tempid,日期) tem ORDER BY 名称,日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- //成本分析-集团
- func GetFeedEffCBAllJT(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `
- SELECT
- 日期,
- (SELECT pasture_name FROM pasture WHERE pastureid = tem.pastureid) 名称,
- IFNULL(ROUND((产奶量)/((撒料量 - 今日剩料量)*TMR干物质)*100,2),'0.00') 准确率 -- 饲料转化率
- FROM (
- SELECT
- d.pastureid,
- %s 日期,
- fp.ftname 配方模板,SUM(bm.product)产奶量,
- SUM(d.oweight) 撒料量,
- IFNULL((SELECT SUM(remain) FROM barfeedremain bf WHERE bf.pastureid = fp.pastureid AND bf.barid = fp.barid AND bf.remaindate = fp.date),0) 今日剩料量,
- IFNULL((SELECT AVG(actweight) FROM ftdry fd WHERE fd.pastureid = fp.pastureid AND fd.barid = fp.barid AND fd.operatetime = fp.date),0) TMR干物质
-
- FROM
- feedpdate fp
-
- INNER JOIN downloadedplan d
- ON d.pastureid = fp.pastureid AND d.mydate = fp.date AND d.templetname = fp.ftname
-
- LEFT JOIN barmilk bm
- ON bm.pastureid =fp.pastureid AND bm.barid = fp.barid AND bm.productdate = (SELECT MAX(productdate) FROM barmilk WHERE barmilk.productdate <=fp.date AND barmilk.pastureid = fp.pastureid and barmilk.barid = fp.barid)
-
- JOIN
- (SELECT pastureid FROM groups_pasture WHERE groupsid = ?
- UNION
- SELECT pastureid FROM pasture WHERE groupsid = ?
- ) tem
- ON tem.pastureid = d.pastureid
- WHERE fp.date BETWEEN ? AND ? AND d.lpplantype<3
- GROUP BY d.pastureid,日期 ) tem
- ORDER BY 名称,日期`
- var data []map[string]interface{}
- var err error
- if status == "0" {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(fp.date, '%Y-%m-%d') ")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else if status == "1" {
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(fp.date,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(fp.date, '%Y-%m') ")
- data, err = tx.SQL(sqlStr, pastureId, pastureId, startDate, endDate).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- // getAccuracyAllFT
- func GetAccuracyAllFT(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT %s 日期,
- d.templetname 名称,
- SUM(de.lweight) 理论量,
- IFNULL(SUM(de.actualweightminus),0) 实际量,
- ROUND(IF(SUM(de.lweight)>SUM(de.actualweightminus),SUM(de.actualweightminus)/SUM(de.lweight),SUM(de.lweight)/SUM(de.actualweightminus))*100,2) 准确率,
- COUNT(de.id) 添加饲料次数,
- SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio,1,0)) 添加正确数,
- IF(COUNT(de.id)>0,SUM(IF(ABS(de.actualweightminus-de.lweight)<=de.feedallowratio,1,0))/COUNT(de.id),0) 正确率
- FROM downloadedplan d JOIN downloadplandtl1_exec de ON d.pastureid = de.pastureid and d.id=de.pid
- WHERE d.mydate BETWEEN ? AND ? AND d.pastureid=? AND d.lpplantype IN (0,1,2,5) AND de.type = 0
- -- 加上就是不含取消操作
- -- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 ))
- `
- 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 日期,d.templetname ORDER BY d.templetname ,d.Mydate "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- sqlStr += " GROUP BY 日期,d.templetname ORDER BY d.templetname ,d.Mydate "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m') ")
- sqlStr += " GROUP BY 日期,d.templetname ORDER BY d.templetname ,d.Mydate "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- // getAccuracyAllJH
- func GetAccuracyAllJH(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT
- 日期,
- SUM(计划取消重量) 计划取消重量,
- ROUND((SUM(实际量)-SUM(计划取消重量))/SUM(理论量)*100,2) field3, -- 准确率(去除取消重量)
- IFNULL(ROUND(IF(SUM(实际量)>SUM(理论量),SUM(理论量)/SUM(实际量),SUM(实际量)/SUM(理论量))*100,2),0) field1, -- 准确率
- SUM(理论量) 理论量,
- SUM(实际量) 实际量,
- SUM(计划数) 计划数,
- SUM(正确数) 正确数,
- IFNULL(ROUND(SUM(正确数)/SUM(计划数)*100,2),0) field2
- FROM
- (
- SELECT
- IFNULL((SELECT SUM(actualweightminus) FROM downloadplandtl1_exec de1 WHERE de1.pid = d.id AND d.pastureid = de1.pastureid
- AND ((ABS(de1.actualweightminus-de1.lweight)/de1.lweight)>=3 AND (de1.lweight >=30 OR de1.actualweightminus >=30 AND de1.type = 0))
- ),0) 计划取消重量,
-
- %s 日期,
- d.lweight 理论量,
- IFNULL(d.iweight,0) 实际量,
- (SELECT COUNT(*) FROM downloadplandtl1 de1 WHERE de1.pid = d.id AND d.pastureid = de1.pastureid AND de1.type = 0) 计划数, -- 添加饲料次数,
- (SELECT SUM(IF(ABS(de1.actualweightminus-de1.lweight)<=de1.feedallowratio AND de1.actualweightminus<>0,1,0))
- FROM downloadplandtl1 de1 WHERE de1.pid = d.id AND d.pastureid = de1.pastureid AND de1.type = 0) 正确数
-
- FROM downloadedplan d
-
- WHERE d.mydate BETWEEN ? AND ? AND d.pastureid=? AND d.lpplantype in (0,1,2,5)
- -- 加上就是不含取消操作
- -- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 ))
- ) tem `
- 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 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- sqlStr += " GROUP BY 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m') ")
- sqlStr += " GROUP BY 日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracyV2(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- // getAccuracyAllNQ
- func GetAccuracyAllNQ(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT IFNULL((SELECT cowclass FROM barmilk WHERE pastureid = de.pastureid AND barid = de.fbarid AND productdate <= de.date ORDER BY productdate DESC LIMIT 1) ,'无类别')名称 ,
- %s 日期,
- SUM(de.lweight) 理论量,SUM(de.actualweightminus) 实际量,
- ROUND(IF(SUM(de.lweight)>SUM(de.actualweightminus),SUM(de.actualweightminus)/SUM(de.lweight),SUM(de.lweight)/SUM(de.actualweightminus))*100,2) 准确率
- FROM downloadedplan d JOIN downloadplandtl2 de ON d.id=de.pid AND d.pastureid = de.pastureid
- WHERE d.mydate BETWEEN ? AND ? AND d.pastureid=? AND d.lpplantype IN (0,1,2,5) AND de.type = 0
- -- 加上就是不含取消操作
- -- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 ))
- GROUP BY 日期,(SELECT cowclass FROM barmilk WHERE pastureid = de.pastureid AND barid = de.fbarid AND productdate <= de.date ORDER BY productdate DESC LIMIT 1)
- ORDER BY 名称 ,d.Mydate `
- 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 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- // sqlStr += " GROUP BY 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m') ")
- // sqlStr += " GROUP BY 日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- // getAccuracyAllCC
- func GetAccuracyAllCC(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT d.projname 名称,%s 日期,
- SUM(de.lweight) 理论量,SUM(de.actualweightminus) 实际量,
- ROUND(IF(SUM(de.lweight)>SUM(de.actualweightminus),SUM(de.actualweightminus)/SUM(de.lweight),SUM(de.lweight)/SUM(de.actualweightminus))*100,2) 准确率
- FROM downloadedplan d right JOIN downloadplandtl1_exec de ON d.pastureid = de.pastureid and d.id=de.pid
- WHERE d.mydate BETWEEN ? AND ? AND d.pastureid=? AND d.lpplantype IN (0,1,2,5) AND de.type = 0
- -- 加上就是不含取消操作
- -- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 ))
- GROUP BY d.projname,日期
- order by d.projname ,d.Mydate`
- 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 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- // sqlStr += " GROUP BY 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m') ")
- // sqlStr += " GROUP BY 日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- // getAccuracyAllHL
- func GetAccuracyAllHL(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT
- 日期,
- SUM(自动次数) field1, -- 自动次数,
- ifnull( SUM(实际自动),0) 实际自动,
- ifnull(SUM(理论自动),0)理论自动,
- SUM(手动次数) field2, -- 手动次数,
- SUM(实际手动) 实际手动,SUM(理论手动) 理论手动,
- IFNULL(ROUND(IF(SUM(实际自动)>SUM(理论自动),SUM(理论自动)/SUM(实际自动),SUM(实际自动)/SUM(理论自动))*100,2),0) field3, -- 自动准确率,
- IFNULL(ROUND(IF(SUM(实际手动)>SUM(理论手动),SUM(理论手动)/SUM(实际手动),SUM(实际手动)/SUM(理论手动))*100,2),0) field4 -- 手动准确率
- FROM (
- SELECT %s 日期,
- (SELECT SUM(actualweightminus) FROM downloadplandtl1_exec de WHERE d.id=de.pid AND d.pastureid = de.pastureid AND de.buttontype = 1 AND actualweightminus>0 AND de.type = 0) 实际自动,
- (SELECT SUM(lweight) FROM downloadplandtl1_exec de WHERE d.id=de.pid AND d.pastureid = de.pastureid AND de.buttontype = 1 AND de.type = 0) 理论自动,
- (SELECT COUNT(*) FROM downloadplandtl1_exec de WHERE d.id=de.pid AND d.pastureid = de.pastureid AND de.buttontype = 1 AND de.type = 0) 自动次数,
-
- (SELECT SUM(actualweightminus) FROM downloadplandtl1_exec de WHERE d.id=de.pid AND d.pastureid = de.pastureid AND de.buttontype IN (2,3) AND actualweightminus>0 AND de.type = 0) 实际手动,
- (SELECT SUM(lweight) FROM downloadplandtl1_exec de WHERE d.id=de.pid AND d.pastureid = de.pastureid AND de.buttontype IN (2,3) AND de.type = 0) 理论手动,
- (SELECT COUNT(*) FROM downloadplandtl1_exec de WHERE d.id=de.pid AND d.pastureid = de.pastureid AND de.buttontype IN (2,3) AND de.type = 0) 手动次数
- FROM downloadedplan d
- WHERE d.mydate BETWEEN ? AND ? AND d.pastureid=? AND d.lpplantype IN (0,1,2,5)
- -- 加上就是不含取消操作
- -- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)>3 and (de.lweight >=30 or de.actualweightminus >=30 ))
- )d
- GROUP BY 日期
- ORDER BY 日期`
- 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 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- // sqlStr += " GROUP BY 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m') ")
- // sqlStr += " GROUP BY 日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracyV2(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- // getAccuracyAllLS
- func GetAccuracyAllLS(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT concat(de.fname,'-',d.times,'班') 名称,de.fname,%s 日期,
- IFNULL(DATE_FORMAT(de.intime,'%%H.%%i'),'') 准确率 -- 撒料时间
- FROM downloadedplan d right JOIN downloadplandtl2 de ON d.pastureid = de.pastureid and d.id=de.pid
- WHERE d.mydate BETWEEN ? AND ? AND d.pastureid=? AND d.lpplantype IN (0,1,2,5) AND de.type = 0
- -- 加上就是不含取消操作
- -- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)<=3 OR (de.lweight <30 AND de.actualweightminus <30 ))
- GROUP BY d.times,日期,de.fname
- ORDER BY concat(de.fname,d.times) ,日期`
- 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 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- // sqlStr += " GROUP BY 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m') ")
- // sqlStr += " GROUP BY 日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracy(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
- //getAccuracyAllQX
- func GetAccuracyAllQX(c *gin.Context) {
- appG := app.Gin{C: c}
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- sqlName := fsion.Get("name").ValueStr()
- parammaps := fsion.Get("parammaps")
- status := parammaps.Get("status").ValueStr()
- startDate := parammaps.Get("startTime").ValueStr()
- endDate := parammaps.Get("stopTime").ValueStr()
- pastureId := parammaps.Get("pastureid").ValueStr()
- tx := restful.Engine.NewSession()
- defer tx.Close()
- var sqlStr = `SELECT de.fname 名称,%s 日期,
- count(de.id) field1 -- 取消次数
- FROM downloadedplan d LEFT JOIN downloadplandtl1_exec de ON d.id=de.pid AND d.pastureid = de.pastureid
- AND ((ABS(de.actualweightminus-de.lweight)/de.lweight)>3 AND (de.lweight >=30 OR de.actualweightminus >=30 ))
- AND de.type = 0
- WHERE d.mydate BETWEEN ? AND ? AND d.pastureid=? AND d.lpplantype IN (0,1,2,5)
- -- 加上就是不含取消操作
- GROUP BY 日期`
- 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 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else if status == "1" {
- // sqlStr := chartMap[sqlName]
- timeTemplate := "2006-01-02"
- start, _ := time.ParseInLocation(timeTemplate, startDate, time.Local)
- week := 0
- if int(start.Weekday()) == 0 {
- week = 6
- } else {
- week = int(start.Weekday()) - 1
- }
- sqlStr = fmt.Sprintf(sqlStr, "FLOOR( ((DATEDIFF(d.Mydate,'"+startDate+"') +"+strconv.Itoa(week)+")/7)+1)")
- // sqlStr += " GROUP BY 日期 "
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- } else {
- sqlStr = fmt.Sprintf(sqlStr, " DATE_FORMAT(d.Mydate, '%Y-%m') ")
- // sqlStr += " GROUP BY 日期 "
- // timeTemplate := "2006-01-02"
- // end, _ := time.ParseInLocation(timeTemplate, endDate, time.Local)
- // endDate = end.AddDate(0, 1, -1).Format(timeTemplate)
- data, err = tx.SQL(sqlStr, startDate, endDate, pastureId).Query().List()
- if err != nil {
- logs.Error(sqlName, " : ", err)
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
- }
- // appG.Response(http.StatusOK, e.SUCCESS, data)
- }
- queryData, err := getAccuracyV2(data)
- appG.Response(http.StatusOK, e.SUCCESS, queryData)
- }
|