123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104 |
- package api
- import (
- "../../routers/restful"
- "encoding/json"
- "fmt"
- "github.com/Anderson-Lu/gofasion/gofasion"
- "github.com/xormplus/xorm"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- //包含报表模块需要的各种数据格式转换
- func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session) (queryData map[string]interface{}, err error) {
- sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
- s_params := make([]interface{}, 0)
- if sql != "" {
- paramslist := strings.Split(p, ",")
- if len(paramslist) > 0 && p != "" {
- for _, value := range paramslist {
- s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
- }
- }
- }
- queryList, err := tx.SQL(sql, s_params...).Query().List()
- if err != nil{
- return nil,err
- }
- if len(queryList) == 0{
- return nil,nil
- }
- temstr := ""
- switch sqlnamestr {
- case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa", "judgenurFTReportDetail":
- temstr = sqlnamestr
- default:
- temstr = sqlnamestr[:10]
- }
- switch temstr {
- case "getAccurac", "getFeedEff":
- queryData, err = getAccuracy(queryList) // 不定参数
- case "getprocess":
- //queryData, err = getAccuracyV3v1(queryList)
- queryData, err = getAccuracyV3(queryList)
- case "getHomepro":
- queryData, err = getAccuracyV3(queryList)
- case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa":
- queryData, err = getAccuracyV2(queryList) //固定维度 日期
- case "getMateria":
- queryData, err = getAccuracyV4(queryList)
- case "getPriceAn":
- queryData, err = getAccuracyV5(queryList)
- case "getJT1Accu":
- queryData, err = getAccuracyV6(queryList) //固定维度 牧场
- case "judgenurFT":
- queryData, err = getAccuracyV7(queryList)
- case "judgenurFTReportDetail":
- queryData, err = getAccuracyV8(queryList)
- case "downloadPl":
- queryData, err = getAccuracyV9(queryList) //投料简打、累加
- default:
- queryData, err = nil, nil
- }
- return
- //switch sqlnamestr {
- //case "getAccuracyAllFT", "getAccuracyAllNQ", "getAccuracyAllCC", "getAccuracyAllLS","getFeedEffSL","getFeedEffZH","getFeedEffCB","getFeedEffCBLS","getFeedEffCBFT":
- // queryData, err = getAccuracy(queryList)
- //case "getprocessAnalysisTB","getHomeprocessAnalysis":
- // queryData, err = getAccuracyV3(queryList)
- //case "getAccuracyAllHL", "getAccuracyAllQX","getAccuracyAllJH","getFeedEffMR","getFeedEffHL","getHomepageCB":
- // queryData, err = getAccuracyV2(queryList)
- //default:
- // queryData, err = nil, nil
- //}
- //return
- }
- func getAccuracyV10(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- mapc3 := make(map[string]interface{})
- data2 := []interface{}{}
- data1 := []interface{}{}
- mapc3["label"] = "车次"
- mapc3["prop"] = "projname"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "TMR"
- mapc3["prop"] = "tmrtname"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "时间"
- mapc3["prop"] = "plantime"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "班组"
- mapc3["prop"] = "times"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "驾驶员"
- mapc3["prop"] = "driver"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "日系数比例"
- mapc3["prop"] = "rate"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "牛头数"
- mapc3["prop"] = "feedpcount"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "配方模板"
- mapc3["prop"] = "templetname"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- var stem []string
- var tem1 interface{}
- max,count := 0,0
- for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
- if i == 0{
- tem1 = queryList[i]["projname"]
- }
- if tem1 != queryList[i]["projname"]{
- tem1 = queryList[i]["projname"]
- if max < count {
- max = count
- }
- count = 0
- }else{
- count ++
- }
- }
- sort.Strings(stem)
- for i := 0;i<=max;i++{
- mapc3["label"] = "发料位"+ strconv.Itoa(i+1)
- mapc3["prop"] = "发料位"+ strconv.Itoa(i+1)
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- }
- mapc3["label"] = "合计"
- mapc3["prop"] = "sumlweight"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- var tem interface{}
- mapc2 := make(map[string]interface{})
- count = 1
- for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
- if i == 0{
- tem = queryList[i]["projname"]
- mapc2 = queryList[i]
- mapc2["发料位"+ strconv.Itoa(count)] = queryList[i]["lweight"]
- continue
- }
- if tem == queryList[i]["projname"]{
- count ++
- fmt.Println("===========aa ",queryList[i]["projname"],"发料位"+ strconv.Itoa(count))
- mapc2["发料位"+ strconv.Itoa(count)] = queryList[i]["lweight"]
- }else{
- count = 1
- fmt.Println("===========bb ",queryList[i]["projname"],count)
- data2 = append(data2, mapc2)
- tem = queryList[i]["projname"]
- mapc2 = queryList[i]
- mapc2["发料位"+ strconv.Itoa(count)] = queryList[i]["lweight"]
- }
- }
- data2 = append(data2, mapc2)
- chartData["data1"] = data1
- chartData["data2"] = data2
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV9(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- mapc3 := make(map[string]interface{})
- data2 := []interface{}{}
- data1 := []interface{}{}
- mapc3["label"] = "车次"
- mapc3["prop"] = "projname"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "TMR"
- mapc3["prop"] = "tmrtname"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "时间"
- mapc3["prop"] = "plantime"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "班组"
- mapc3["prop"] = "times"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "驾驶员"
- mapc3["prop"] = "driver"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "日系数比例"
- mapc3["prop"] = "rate"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "牛头数"
- mapc3["prop"] = "feedpcount"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mapc3["label"] = "配方模板"
- mapc3["prop"] = "templetname"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- mtem := make(map[interface{}]interface{})
- var stem []string
- for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
- if _,ok :=mtem[queryList[i]["fname"]];ok {
- continue
- }
- stem = append(stem,queryList[i]["fname"].(string))
- mtem[queryList[i]["fname"]] = struct {}{}
- }
- sort.Strings(stem)
- for _, va := range stem {
- mapc3["label"] = va
- mapc3["prop"] = va
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- }
- mapc3["label"] = "合计"
- mapc3["prop"] = "sumlweight"
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- var tem interface{}
- mapc2 := make(map[string]interface{})
- for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
- if i == 0{
- tem = queryList[i]["projname"]
- mapc2 = queryList[i]
- //for key:= range mtem {
- // mapc2[xorm.String(key)] = ""
- //}
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }
- if tem == queryList[i]["projname"]{
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }else{
- data2 = append(data2, mapc2)
- tem = queryList[i]["projname"]
- mapc2 = queryList[i]
- //for key := range mtem {
- // mapc2[xorm.String(key)] = ""
- //}
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }
- }
- data2 = append(data2, mapc2)
- chartData["data1"] = data1
- chartData["data2"] = data2
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV8(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- //list := make(map[string]interface{})
- data := []interface{}{}
- for i := 0; i < len(queryList); i++ {
- dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
- Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
- Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
- trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
- jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
- uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
- kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
- adf, _ := strconv.ParseFloat(queryList[i]["adf"].(string), 64)
- ca, _ := strconv.ParseFloat(queryList[i]["ca"].(string), 64)
- cdry, _ := strconv.ParseFloat(queryList[i]["cdry"].(string), 64)
- cad, _ := strconv.ParseFloat(queryList[i]["cad"].(string), 64)
- cndf, _ := strconv.ParseFloat(queryList[i]["cndf"].(string), 64)
- cp, _ := strconv.ParseFloat(queryList[i]["cp"].(string), 64)
- cpd, _ := strconv.ParseFloat(queryList[i]["cpd"].(string), 64)
- fat, _ := strconv.ParseFloat(queryList[i]["fat"].(string), 64)
- ndf, _ := strconv.ParseFloat(queryList[i]["ndf"].(string), 64)
- nm, _ := strconv.ParseFloat(queryList[i]["nm"].(string), 64)
- nmd, _ := strconv.ParseFloat(queryList[i]["nmd"].(string), 64)
- nuint, _ := strconv.ParseFloat(queryList[i]["nuint"].(string), 64)
- p, _ := strconv.ParseFloat(queryList[i]["p"].(string), 64)
- pd, _ := strconv.ParseFloat(queryList[i]["pd"].(string), 64)
- starch, _ := strconv.ParseFloat(queryList[i]["starch"].(string), 64)
- trans4f, _ := strconv.ParseFloat(queryList[i]["trans4f"].(string), 64)
- list := make(map[string]interface{})
- list["ft"] = dry
- list["index"] = "干物质(kg)"
- list["tmr"] = TransFloat(dry * Hrate)
- list["cyl"] = TransFloat(dry * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = jcrate
- list["index"] = "粗精比(%)"
- list["tmr"] = TransFloat(jcrate * Hrate)
- list["cyl"] = TransFloat(jcrate * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = uprice
- list["index"] = "日粮成本(元)"
- list["tmr"] = TransFloat(uprice * Hrate)
- list["cyl"] = TransFloat(uprice * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = kprice
- list["index"] = "公斤奶成本"
- list["tmr"] = TransFloat(kprice * Hrate)
- list["cyl"] = TransFloat(kprice * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = cdry
- list["index"] = "粗料中的干物质"
- list["tmr"] = TransFloat(cdry * Hrate)
- list["cyl"] = TransFloat(cdry * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = nm
- list["index"] = " 产奶净能(MJ)"
- list["tmr"] = TransFloat(nm * Hrate)
- list["cyl"] = TransFloat(nm * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = nuint
- list["index"] = "奶牛能量单位(NND)"
- list["tmr"] = TransFloat(nuint * Hrate)
- list["cyl"] = TransFloat(nuint * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = cp
- list["index"] = "粗蛋白(g)"
- list["tmr"] = TransFloat(cp * Hrate)
- list["cyl"] = TransFloat(cp * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = cpd
- list["index"] = "粗蛋白(%DM)"
- list["tmr"] = TransFloat(cpd * Hrate)
- list["cyl"] = TransFloat(cpd * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = ca
- list["index"] = "钙(g)"
- list["tmr"] = TransFloat(ca * Hrate)
- list["cyl"] = TransFloat(ca * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = p
- list["index"] = "磷(g)"
- list["tmr"] = TransFloat(p * Hrate)
- list["cyl"] = TransFloat(p * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = nmd
- list["index"] = "产奶净能(Mcal/DM)"
- list["tmr"] = TransFloat(nmd * Hrate)
- list["cyl"] = TransFloat(nmd * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = fat
- list["index"] = "脂肪"
- list["tmr"] = TransFloat(fat * Hrate)
- list["cyl"] = TransFloat(fat * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = starch
- list["index"] = "淀粉"
- list["tmr"] = TransFloat(starch * Hrate)
- list["cyl"] = TransFloat(starch * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = ndf
- list["index"] = "NDF(%DM)"
- list["tmr"] = TransFloat(ndf * Hrate)
- list["cyl"] = TransFloat(ndf * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = cndf
- list["index"] = "粗料中的NDF(%DM)"
- list["tmr"] = TransFloat(cndf * Hrate)
- list["cyl"] = TransFloat(cndf * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = adf
- list["index"] = " ADF(%DM)"
- list["tmr"] = TransFloat(adf * Hrate)
- list["cyl"] = TransFloat(adf * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = cad
- list["index"] = "钙(%DM)"
- list["tmr"] = TransFloat(cad * Hrate)
- list["cyl"] = TransFloat(cad * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = pd
- list["index"] = " 磷(%DM)"
- list["tmr"] = TransFloat(pd * Hrate)
- list["cyl"] = TransFloat(pd * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = trans35f
- list["index"] = "(3.5)FCR(kg/DM)"
- list["tmr"] = TransFloat(trans35f * Hrate)
- list["cyl"] = TransFloat(trans35f * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["ft"] = trans4f
- list["index"] = "(4.0)FCR(kg/DM)"
- list["tmr"] = TransFloat(trans4f * Hrate)
- list["cyl"] = TransFloat(trans4f * Srate)
- data = append(data, list)
- }
- chartData["data"] = data
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func TransFloat(flo float64)(float64){
- hf,_ :=strconv.ParseFloat(fmt.Sprintf("%.3f", float64(flo)), 64)
- return hf
- }
- func getAccuracyV7(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- //list := make(map[string]interface{})
- data := []interface{}{}
- for i := 0; i < len(queryList); i++ {
- dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
- Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
- Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
- trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
- jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
- uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
- kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
- list := make(map[string]interface{})
- list["tname"] = queryList[i]["tname"]
- list["ftid"] = queryList[i]["ftid"]
- list["ft"] = dry
- list["index"] = "干物质(kg)"
- list["tmr"] = TransFloat(dry * Hrate)
- list["cyl"] = TransFloat(dry * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["tname"] = queryList[i]["tname"]
- list["ftid"] = queryList[i]["ftid"]
- list["ft"] = trans35f
- list["index"] = "(3.5)FCR(kg/DM)"
- list["tmr"] = TransFloat(trans35f * Hrate)
- list["cyl"] = TransFloat(trans35f * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["tname"] = queryList[i]["tname"]
- list["ftid"] = queryList[i]["ftid"]
- list["ft"] = jcrate
- list["index"] = "粗精比(%)"
- list["tmr"] = TransFloat(jcrate * Hrate)
- list["cyl"] = TransFloat(jcrate * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["tname"] = queryList[i]["tname"]
- list["ftid"] = queryList[i]["ftid"]
- list["ft"] = uprice
- list["index"] = "日粮成本(元)"
- list["tmr"] = TransFloat(uprice * Hrate)
- list["cyl"] = TransFloat(uprice * Srate)
- data = append(data, list)
- list = make(map[string]interface{})
- list["tname"] = queryList[i]["tname"]
- list["ftid"] = queryList[i]["ftid"]
- list["ft"] = kprice
- list["index"] = "公斤奶成本"
- list["tmr"] = TransFloat(kprice * Hrate)
- list["cyl"] = TransFloat(kprice * Srate)
- data = append(data, list)
- }
- chartData["data"] = data
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV6(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- data := []interface{}{}
- data1 := []interface{}{}
- data2 := []interface{}{}
- data3 := []interface{}{}
- data4 := []interface{}{}
- for i := 0; i < len(queryList); i++ {
- data = append(data, queryList[i]["牧场"])
- data1 = append(data1, queryList[i]["field1"])
- data2 = append(data2, queryList[i]["field2"])
- data3 = append(data3, queryList[i]["field3"])
- data4 = append(data4, queryList[i]["field4"])
- }
- chartData["data1"] = data
- chartData["data2"] = data1
- chartData["data3"] = data2
- chartData["data4"] = data3
- chartData["data5"] = data4
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV5(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- datamap1 := make(map[string]interface{})
- datamap2 := make(map[string]interface{})
- temsmap := make(map[interface{}]interface{})
- mapc2 := make(map[interface{}]interface{})
- data3 := []interface{}{}
- datamap2child := make(map[string]interface{})
- data2 := []interface{}{}
- data1 := []interface{}{}
- var dtem interface{}
- var temstr interface{}
- var typestr interface{}
- count2 := 0
- a := 0
- for i := 0; i < len(queryList); i++ {
- if i == 0 {
- temstr = queryList[i]["fname"]
- typestr = queryList[i]["typestr"]
- }
- if temstr == queryList[i]["fname"] {
- temsmap[queryList[i]["feedname"]] = 1
- }
- if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
- mapc2[queryList[i]["feedname"]] = count2
- mapc2[count2] = queryList[i]["feedname"]
- count2++
- }
- }
- //for i := 0; i<count2 ; i++ {
- // reslist := make([]map[string]interface{},1)
- // res := make(map[string]interface{})
- // res["fname"] = "分界线"
- // res["feedname"] = mapc2[i]
- // res["饲料名称"] = mapc2[i]
- // reslist[0] = res
- // queryList = append(reslist,queryList...)
- //}
- for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
- if _, ok := temsmap[mapc2[i]]; !ok {
- reslist := make([]map[string]interface{}, 1)
- res := make(map[string]interface{})
- res["fname"] = temstr
- res["feedname"] = mapc2[i]
- res["饲料名称"] = mapc2[i]
- res["typestr"] = typestr
- reslist[0] = res
- queryList = append(reslist, queryList...)
- }
- }
- for i := 0; i < len(queryList); i++ {
- a = mapc2[queryList[i]["feedname"]].(int) * 2
- if i == 0 {
- datamap2["label"] = "饲料名称"
- switch queryList[i]["typestr"].(type) {
- case string:
- datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
- default:
- datamap2child["label"] = "/饲料参数"
- }
- datamap2child["prop"] = "A"
- data3 = append(data3, datamap2child)
- datamap2["children"] = data3
- data2 = append(data2, datamap2)
- data3 = []interface{}{}
- datamap2child = make(map[string]interface{})
- datamap2 = make(map[string]interface{})
- dtem = queryList[i]["fname"]
- }
- if dtem != queryList[i]["fname"] && i != 0 {
- data1 = append(data1, datamap1)
- dtem = queryList[i]["fname"]
- datamap1 = make(map[string]interface{})
- }
- if queryList[i]["fname"] == temstr {
- datamap2["label"] = queryList[i]["feedname"]
- datamap2child["label"] = "理论"
- datamap2child["prop"] = "a" + strconv.Itoa(a)
- data3 = append(data3, datamap2child)
- datamap2child = make(map[string]interface{})
- datamap2child["label"] = "实际"
- datamap2child["prop"] = "a" + strconv.Itoa(a+1)
- data3 = append(data3, datamap2child)
- datamap2child = make(map[string]interface{})
- datamap2["children"] = data3
- data2 = append(data2, datamap2)
- data3 = []interface{}{}
- datamap2 = make(map[string]interface{})
- datamap2child = make(map[string]interface{})
- }
- datamap1["A"] = queryList[i]["fname"]
- datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
- datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
- datamap2["label"] = queryList[i]["饲料名称"]
- a = a + 2
- }
- data1 = append(data1, datamap1)
- chartData["data1"] = data1
- chartData["data2"] = data2
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- datamap1 := make(map[string]interface{})
- datamap2 := make(map[string]interface{})
- temsmap := make(map[interface{}]interface{})
- mapc2 := make(map[interface{}]interface{})
- mapc3 := make(map[interface{}]interface{})
- data3 := []interface{}{}
- datamap2child := make(map[string]interface{})
- data2 := []interface{}{}
- data1 := []interface{}{}
- a := 0
- var dtem interface{}
- count2 := 0
- var tem interface{}
- var temstr interface{}
- var typestr interface{}
- for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
- if i == 0 {
- temstr = queryList[i]["fname"]
- typestr = queryList[i]["typestr"]
- }
- if temstr == queryList[i]["fname"] {
- temsmap[queryList[i]["feedname"]] = 1
- }
- if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
- mapc2[queryList[i]["feedname"]] = count2 // 编号
- mapc2[count2] = queryList[i]["feedname"]
- count2++
- }
- }
- for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
- if _, ok := temsmap[mapc2[i]]; !ok {
- reslist := make([]map[string]interface{}, 1)
- res := make(map[string]interface{})
- res["fname"] = temstr
- res["feedname"] = mapc2[i]
- res["饲料名称"] = mapc2[i]
- res["typestr"] = typestr
- reslist[0] = res
- queryList = append(reslist, queryList...)
- }
- }
- //for i := 0; i<count2 ; i++ {
- // reslist := make([]map[string]interface{},1)
- // res := make(map[string]interface{})
- // res["fname"] = "分界线"
- // res["feedname"] = mapc2[i]
- // res["饲料名称"] = mapc2[i]
- // res["typestr"] =typestr
- // reslist[0] = res
- // queryList = append(reslist,queryList...)
- //}
- for i := 0; i < len(queryList); i++ {
- if i == 0 {
- tem = queryList[i]["fname"]
- }
- if queryList[i]["fname"] == tem {
- mapc3[queryList[i]["feedname"]] = i
- }
- }
- for i := 0; i < len(queryList); i++ {
- a = mapc2[queryList[i]["feedname"]].(int) * 4
- if i == 0 {
- datamap2["label"] = "饲料名称"
- switch queryList[i]["typestr"].(type) {
- case string:
- datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
- default:
- datamap2child["label"] = "/饲料参数"
- }
- datamap2child["prop"] = "A"
- data3 = append(data3, datamap2child)
- datamap2["children"] = data3
- data2 = append(data2, datamap2)
- data3 = []interface{}{}
- datamap2child = make(map[string]interface{})
- datamap2 = make(map[string]interface{})
- dtem = queryList[i]["fname"]
- }
- if dtem != queryList[i]["fname"] && i != 0 {
- data1 = append(data1, datamap1)
- dtem = queryList[i]["fname"]
- datamap1 = make(map[string]interface{})
- }
- if queryList[i]["fname"] == temstr {
- datamap2["label"] = queryList[i]["feedname"]
- datamap2child["label"] = "理论"
- datamap2child["prop"] = "a" + strconv.Itoa(a)
- data3 = append(data3, datamap2child)
- datamap2child = make(map[string]interface{})
- datamap2child["label"] = "实际"
- datamap2child["prop"] = "a" + strconv.Itoa(a+1)
- data3 = append(data3, datamap2child)
- datamap2child = make(map[string]interface{})
- datamap2child["label"] = "误差值"
- datamap2child["prop"] = "a" + strconv.Itoa(a+2)
- data3 = append(data3, datamap2child)
- datamap2child = make(map[string]interface{})
- datamap2child["label"] = "误差率"
- datamap2child["prop"] = "a" + strconv.Itoa(a+3)
- data3 = append(data3, datamap2child)
- datamap2["children"] = data3
- data2 = append(data2, datamap2)
- data3 = []interface{}{}
- datamap2 = make(map[string]interface{})
- datamap2child = make(map[string]interface{})
- }
- datamap1["A"] = queryList[i]["fname"]
- datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
- datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
- datamap1["a"+strconv.Itoa(a+2)] = queryList[i]["diff"]
- datamap1["a"+strconv.Itoa(a+3)] = queryList[i]["diffrate"]
- datamap2["label"] = queryList[i]["饲料名称"]
- }
- data1 = append(data1, datamap1)
- chartData["data1"] = data1
- chartData["data2"] = data2
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV3(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- data := []interface{}{}
- data1 := []interface{}{}
- data2 := []interface{}{}
- data3 := []interface{}{}
- data4 := []interface{}{}
- datatem := []interface{}{}
- t1 := make(map[interface{}]string, 0)
- for i := 0; i < len(queryList); i++ {
- data = append(data, queryList[i]["mtime"])
- data1 = append(data1, queryList[i]["lweight"])
- data2 = append(data2, queryList[i]["weight"])
- //data3 = append(data3, queryList[i]["field3"])
- //data4 = append(data4, queryList[i]["field4"])
- if _, ok := t1[queryList[i]["id"]]; !ok {
- datatem = append(datatem, queryList[i]["startstime"], queryList[i]["lastactualweight"])
- data3 = append(data3, datatem)
- datatem = []interface{}{}
- datatem = append(datatem, queryList[i]["intime"], queryList[i]["actualweight"])
- data3 = append(data3, datatem)
- datatem = []interface{}{}
- }
- t1[queryList[i]["id"]] = "1"
- }
- chartData["data1"] = data
- chartData["data2"] = data1
- chartData["data3"] = data2
- chartData["data4"] = data3
- chartData["data5"] = data4
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV3v1(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- data := []interface{}{}
- data1 := []interface{}{}
- data2 := []interface{}{}
- data3 := []interface{}{}
- data4 := []interface{}{}
- datatem := []interface{}{}
- //t1 := make(map[interface{}]string, 0)
- jsonstr := ""
- jsonmap := make([]map[string]interface{},0)
- if len(queryList)>0{
- queryjsonList, _ := restful.Engine.SQL("select weightjson from recweightmuster where pid = ? and pastureid = ?" ,queryList[0]["pid"],queryList[0]["pastureid"]).Query().List()
- if len(queryjsonList)>0{
- jsonstr = queryjsonList[0]["weightjson"].(string)
- }
- }
- err := json.Unmarshal([]byte(jsonstr),&jsonmap)
- if err != nil{
- return nil ,err
- }
- for i := 0; i < len(queryList); i++ {
- datatem = append(datatem, queryList[i]["startstime"], queryList[i]["lastactualweight"])
- data3 = append(data3, datatem)
- datatem = []interface{}{}
- datatem = append(datatem, queryList[i]["intime"], queryList[i]["actualweight"])
- data3 = append(data3, datatem)
- datatem = []interface{}{}
- }
- j := 0
- for i := 0; i < len(jsonmap); i++ {
- if jsonmap[i]["mt"].(string)>queryList[j]["intime"].(string){
- if j < len(queryList)-1{
- j++
- }
- }
- data1 = append(data1, queryList[j]["lweight"])
- data = append(data, jsonmap[i]["mt"])
- data2 = append(data2, jsonmap[i]["w"])
- }
- chartData["data1"] = data
- chartData["data2"] = data1
- chartData["data3"] = data2
- chartData["data4"] = data3
- chartData["data5"] = data4
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracyV2(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- data := []interface{}{}
- data1 := []interface{}{}
- data2 := []interface{}{}
- data3 := []interface{}{}
- data4 := []interface{}{}
- for i := 0; i < len(queryList); i++ {
- data = append(data, queryList[i]["日期"])
- data1 = append(data1, queryList[i]["field1"])
- data2 = append(data2, queryList[i]["field2"])
- data3 = append(data3, queryList[i]["field3"])
- data4 = append(data4, queryList[i]["field4"])
- }
- chartData["data1"] = data
- chartData["data2"] = data1
- chartData["data3"] = data2
- chartData["data4"] = data3
- chartData["data5"] = data4
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
- func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, error) {
- queryData := make(map[string]interface{})
- chartData := make(map[string]interface{})
- t1 := make(map[interface{}]interface{}, 0)
- t2 := make(map[interface{}]interface{}, 0)
- data := make(map[string][]interface{}, 0)
- t := make([]map[string][]interface{}, 0)
- e1 := []interface{}{}
- e2 := []string{}
- for _, value := range queryList {
- if _, ok := t1[value["名称"]]; !ok {
- e1 = append(e1, value["名称"])
- }
- if _, ok := t2[value["日期"]]; !ok {
- switch value["日期"].(type) {
- case string:
- e2 = append(e2, value["日期"].(string))
- }
- }
- t1[value["名称"]] = value["名称"]
- t2[value["日期"]] = value["日期"]
- }
- sort.Strings(e2)
- var b interface{}
- a := 0
- for i := 0; i < len(queryList); i++ {
- if i == 0 {
- b = queryList[i]["名称"]
- }
- if b != queryList[i]["名称"] {
- if a < len(e2)-1 {
- for k := 0; k < len(e2)-a; k++ {
- data["data"] = append(data["data"], "")
- }
- }
- t = append(t, data)
- data = make(map[string][]interface{}, 0)
- b = queryList[i]["名称"]
- a = 0
- }
- switch queryList[i]["日期"].(type) {
- case string:
- dates, _ := time.Parse("2006-01-02", queryList[i]["日期"].(string))
- dates1 := ""
- if a < len(e2) -1{
- dates1 = e2[a]
- }else {
- dates1 = e2[len(e2)-1]
- }
- if a < len(e2)-1 {
- if e2[a] != queryList[i]["日期"].(string) {
- if e2[a] < queryList[i]["日期"].(string) {
- dates1 = queryList[i]["日期"].(string)
- dates, _ = time.Parse("2006-01-02", e2[a])
- for ; a < len(e2)-1; a++ {
- if e2[a] >= queryList[i]["日期"].(string) {
- break
- }
- }
- }
- for ; dates.Format("2006-01-02") < dates1; dates = dates.Add(24 * time.Hour) {
- data["data"] = append(data["data"], "")
- }
- }
- }
- }
- data["data"] = append(data["data"], queryList[i]["准确率"])
- a++
- }
- if a < len(e2)-1 {
- for k := 0; k < len(e2)-a; k++ {
- data["data"] = append(data["data"], "")
- }
- }
- t = append(t, data)
- chartData["data1"] = e1
- chartData["data2"] = e2
- chartData["data3"] = t
- queryData["list"] = chartData
- queryData["code"] = 0
- queryData["message"] = "ok"
- queryData["data"] = queryList
- return queryData, nil
- }
|