123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548 |
- package api
- import (
- "fmt"
- "io/ioutil"
- "net/http"
- "strconv"
- "time"
- "../../pkg/app"
- "../../pkg/e"
- "../../routers/restful"
- "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)
- }
|