1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249 |
- package api
- import (
- "encoding/json"
- "fmt"
- "sort"
- "strconv"
- "strings"
- "time"
- "tmr-watch/http/handle/restful"
- "github.com/Anderson-Lu/gofasion/gofasion"
- "github.com/xormplus/xorm"
- )
- //包含报表模块前端需要的各种数据格式转换
- func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session, checked string, offset, count, typea int) (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()
- //############
- sql2, p2 := restful.GetSqlByNameDBT("getFeednameSort", tx)
- s_params2 := make([]interface{}, 0)
- if sql2 != "" {
- paramslist2 := strings.Split(p2, ",")
- if len(paramslist2) > 0 && p != "" {
- for _, value := range paramslist2 {
- s_params2 = append(s_params2, parammaps.Get(strings.Trim(value, " ")).ValueStr())
- }
- }
- }
- queryList2, err := tx.SQL(sql2, s_params2...).Query().List()
- var feednamesort []string
- if len(queryList2) > 0 {
- for i := 0; i < len(queryList2); i++ {
- feednamesort = append(feednamesort, queryList2[i]["fname"].(string))
- }
- }
- // #########
- sql3, p3 := restful.GetSqlByNameDBT("getFeednameSort2", tx)
- s_params3 := make([]interface{}, 0)
- if sql3 != "" {
- paramslist3 := strings.Split(p3, ",")
- if len(paramslist3) > 0 && p != "" {
- for _, value := range paramslist3 {
- s_params3 = append(s_params3, parammaps.Get(strings.Trim(value, " ")).ValueStr())
- }
- }
- }
- // var queryList3 []map[string]interface{}
- // queryList3 = make([]map[string]interface{}, 0)
- var feednamesort3 []string
- if sql3 != "" {
- queryList3, err := tx.SQL(sql3, s_params3...).Query().List()
- // fmt.Println()
- if err != nil {
- return nil, err
- }
- if len(queryList3) > 0 {
- for z := 0; z < len(queryList3); z++ {
- feednamesort3 = append(feednamesort3, queryList3[z]["feedname"].(string))
- }
- }
- }
- if err != nil {
- return nil, err
- }
- // if len(queryList) == 0 {
- // return nil, nil
- // }
- temstr := ""
- //除特殊接口外,去接口名称的前10位做同一类型的转换
- 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)
- // 统计分析 过程分析
- if sqlnamestr == "getprocessAnalysisTB" {
- quertDataList := queryData["list"]
- query := quertDataList.(map[string]interface{})
- querys, _ := GetprocessAnalysisTB(parammaps, tx, quertDataList, queryList)
- if len(querys) != 0 {
- query["data1"] = querys["WTime"]
- query["data2"] = querys["data2"]
- query["data3"] = querys["realWandT"]
- query["data5"] = querys["data5"]
- }
- }
- case "getHomepro":
- queryData, err = getAccuracyV3(queryList)
- case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa":
- queryData, err = getAccuracyV2(queryList) //固定维度 日期
- case "getMateria":
- sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr+("sum"), tx)
- s_params1 := make([]interface{}, 0)
- if sql1 != "" {
- paramslist1 := strings.Split(p1, ",")
- if len(paramslist1) > 0 && p != "" {
- for _, value := range paramslist1 {
- s_params1 = append(s_params1, parammaps.Get(strings.Trim(value, " ")).ValueStr())
- }
- }
- }
- queryListSum, _ := tx.SQL(sql1, s_params1...).Query().List()
- queryData, err = getAccuracyV4(queryList, queryListSum, checked, feednamesort3, typea)
- 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":
- var sql2, p2 string
- s_params2 := make([]interface{}, 0)
- if sqlnamestr == "downloadPlanSFJD" {
- sql2, p2 = restful.GetSqlByNameDBT("countfl", tx)
- //s_params1 := make([]interface{}, 0)
- if sql2 != "" {
- paramslist1 := strings.Split(p2, ",")
- if len(paramslist1) > 0 && p != "" {
- for _, value := range paramslist1 {
- s_params2 = append(s_params2, parammaps.Get(strings.Trim(value, " ")).ValueStr())
- }
- }
- }
- }
- queryList2, _ := tx.SQL(sql2, s_params2...).Query().List()
- var flleight string
- if len(queryList2) > 0 {
- flleight, _ = queryList2[0]["flcount"].(string)
- // fmt.Println(flleight)
- }
- flleightint, _ := strconv.Atoi(flleight)
- if sqlnamestr == "downloadPlanTSLJD" {
- queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort3)
- } else {
- queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort) //投料简打、累加
- }
- default:
- queryData, err = nil, nil
- }
- return
- }
- func getAccuracyV9(queryList []map[string]interface{}, sqlnamestr string, flleightint int, feednamesort []string) (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{})
- //if sqlnamestr == "downloadPlanSFJD":
- //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, feedNames []string
- for _, feed := range feednamesort {
- feed = strings.ReplaceAll(feed, " ", "")
- mtem[feed] = struct{}{}
- // fmt.Println(feed)
- stem = append(stem, feed)
- }
- 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{}{}
- feedNames = append(feedNames, queryList[i]["fname"].(string))
- }
- sort.Strings(feedNames)
- for _, feed := range feedNames {
- if _, ok := mtem[feed]; ok {
- continue
- }
- // fmt.Println(feed)
- stem = append(stem, feed)
- mtem[feed] = struct{}{}
- }
- stemEnd := []string{}
- if sqlnamestr == "downloadPlanSFJD" {
- bb := stem[len(stem)-flleightint : len(stem) : len(stem)]
- //aa := stem[0 : len(stem)-flleightint : len(stem)]
- stemEnd = append(stemEnd, bb...)
- stemEnd = append(stemEnd, feednamesort...)
- //fmt.Println(stemEnd)
- } else {
- stemEnd = stem
- }
- //logging.Info("导出数据 ",stemEnd )
- for _, va := range stemEnd {
- mapc3["label"] = va
- mapc3["prop"] = va
- data1 = append(data1, mapc3)
- mapc3 = make(map[string]interface{})
- }
- if queryList[0]["sumlweight"] != nil {
- 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]
- if mapc2["sumlweight"] != nil {
- var sumlweight float64
- sumlweight, _ = strconv.ParseFloat(mapc2["sumlweight"].(string), 64)
- mapc2["sumlweight"] = sumlweight
- }
- for key := range mtem {
- mapc2[xorm.String(key)] = 0
- }
- // var lweight float64
- if queryList[i]["lweight"] != nil {
- // var error errors.Error
- lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
- if err == nil {
- mapc2[xorm.String(queryList[i]["fname"])] = lweight
- } else {
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }
- } else {
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }
- }
- if tem == queryList[i]["projname"] {
- // var lweight float64
- if queryList[i]["lweight"] != nil {
- lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
- if err == nil {
- mapc2[xorm.String(queryList[i]["fname"])] = lweight
- } else {
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }
- } else {
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }
- } else {
- data2 = append(data2, mapc2)
- tem = queryList[i]["projname"]
- mapc2 = queryList[i]
- if mapc2["sumlweight"] != nil {
- var sumlweight float64
- sumlweight, _ = strconv.ParseFloat(mapc2["sumlweight"].(string), 64)
- mapc2["sumlweight"] = sumlweight
- }
- for key := range mtem {
- mapc2[xorm.String(key)] = 0
- }
- if queryList[i]["lweight"] != nil {
- lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
- if err == nil {
- mapc2[xorm.String(queryList[i]["fname"])] = lweight
- } else {
- mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
- }
- } else {
- 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{}, queryListSum []map[string]interface{}, checked string, feednamesort3 []string, typea int) (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
- //ss := 0
- var dtem interface{}
- count2 := 0
- var tem interface{}
- var temstr interface{}
- var typestr interface{}
- //var sort interface{}
- for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
- if i == 0 {
- temstr = queryList[i]["fname"]
- typestr = queryList[i]["typestr"]
- //sort = queryList[i]["sort"]
- }
- if temstr == queryList[i]["fname"] {
- temsmap[queryList[i]["feedname"]] = 1
- }
- //if i == len(queryList)-1{
- // temstr = "合计"
- // typestr = queryList[i]["typestr"]
- //}
- 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) + "/饲料参数"
- 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"]
- if typea == 0 || typea == 1 {
- datamap2child["label"] = "理论"
- datamap2child["prop"] = "a" + strconv.Itoa(a)
- data3 = append(data3, datamap2child)
- datamap2child = make(map[string]interface{})
- }
- if typea == 0 || typea == 2 {
- datamap2child["label"] = "实际"
- datamap2child["prop"] = "a" + strconv.Itoa(a+1)
- data3 = append(data3, datamap2child)
- datamap2child = make(map[string]interface{})
- }
- if checked == "1" {
- 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)
- datamap2child = make(map[string]interface{})
- }
- // datamap2 = make(map[string]interface{})
- if i != len(queryList)-1 {
- datamap2["children"] = data3
- data2 = append(data2, datamap2)
- datamap2 = make(map[string]interface{})
- data3 = []interface{}{}
- }
- }
- datamap1["A"] = queryList[i]["fname"]
- if queryList[i]["lweight"] != nil {
- var lweight float64
- lweight, _ = strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
- datamap1["a"+strconv.Itoa(a)] = lweight
- } else {
- datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
- }
- if queryList[i]["actualweightminus"] != nil {
- var actualweightminus float64
- actualweightminus, _ = strconv.ParseFloat(queryList[i]["actualweightminus"].(string), 64)
- datamap1["a"+strconv.Itoa(a+1)] = actualweightminus
- } else {
- datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
- }
- if checked == "1" {
- datamap1["a"+strconv.Itoa(a+2)] = queryList[i]["diff"]
- datamap1["a"+strconv.Itoa(a+3)] = queryList[i]["diffrate"]
- }
- datamap2["label"] = queryList[i]["饲料名称"]
- for z := 0; z < len(queryListSum); z++ {
- if queryListSum[z]["fname"] == queryList[i]["fname"] {
- if queryListSum[z]["lweight"] != nil {
- var lweight float64
- lweight, _ = strconv.ParseFloat(queryListSum[z]["lweight"].(string), 64)
- datamap1["B"] = lweight
- } else {
- datamap1["B"] = queryListSum[z]["lweight"]
- }
- if queryListSum[z]["actualweightminus"] != nil {
- var actualweightminus float64
- actualweightminus, _ = strconv.ParseFloat(queryListSum[z]["actualweightminus"].(string), 64)
- datamap1["C"] = actualweightminus
- } else {
- datamap1["B"] = queryListSum[z]["actualweightminus"]
- }
- }
- }
- if i == len(queryList)-1 {
- datamap2["label"] = "合计"
- if typea == 0 || typea == 1 {
- datamap2child = make(map[string]interface{})
- datamap2child["label"] = "理论"
- datamap2child["prop"] = "B"
- data3 = append(data3, datamap2child)
- }
- if typea == 0 || typea == 2 {
- datamap2child = make(map[string]interface{})
- datamap2child["label"] = "实际"
- datamap2child["prop"] = "C"
- data3 = append(data3, datamap2child)
- }
- // ###########################
- datamap2["children"] = data3
- data2 = append(data2, datamap2)
- datamap2 = make(map[string]interface{})
- data3 = []interface{}{}
- }
- }
- //var sortSum []string
- //for z := 0; z < len(data2); z++ {
- // ss := data2[z].(map[string]interface{})
- // bb := ss["label"].(string)
- // if bb != "合计" {
- // sortSum = append(sortSum, bb)
- // }
- //}
- //sort.Strings(sortSum)
- //fmt.Println(sortSum)
- theEndSort := []interface{}{}
- for ii := 0; ii < len(data2); ii++ {
- ss := data2[ii].(map[string]interface{})
- bb := ss["label"].(string)
- if "饲料名称" == bb {
- theEndSort = append(theEndSort, data2[ii])
- }
- }
- for _, v := range feednamesort3 {
- for ii := 0; ii < len(data2); ii++ {
- ss := data2[ii].(map[string]interface{})
- bb := ss["label"].(string)
- // fmt.Println(bb)
- if v == bb && "饲料名称" != bb {
- theEndSort = append(theEndSort, data2[ii])
- }
- }
- }
- for ii := 0; ii < len(data2); ii++ {
- ss := data2[ii].(map[string]interface{})
- bb := ss["label"].(string)
- if "合计" == bb {
- theEndSort = append(theEndSort, data2[ii])
- }
- }
- data1 = append(data1, datamap1)
- chartData["data1"] = data1
- chartData["data2"] = theEndSort
- 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{}{}
- //
- 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 := []interface{}{}
- datatem = append(datatem, queryList[i]["startstime"], queryList[i]["lastactualweight"])
- data3 = append(data3, datatem)
- datatem2 := []interface{}{}
- datatem2 = append(datatem2, queryList[i]["intime"], queryList[i]["actualweight"])
- data4 = append(data4, datatem2)
- //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 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
- }
- //统计分析过程分析data值拆分
- func GetprocessAnalysisTB(parammaps *gofasion.Fasion, tx *xorm.Session, quertDataList interface{}, queryList []map[string]interface{}) (query map[string]interface{}, err error) {
- sql1, p1 := restful.GetSqlByNameDBT("getweightjson", tx)
- query1 := make(map[string]interface{}, 0)
- s_params1 := make([]interface{}, 0)
- if sql1 != "" {
- paramslist := strings.Split(p1, ",")
- if len(paramslist) > 0 && p1 != "" {
- for _, value := range paramslist {
- s_params1 = append(s_params1, parammaps.Get(strings.Trim(value, " ")).ValueStr())
- }
- }
- }
- queryList2, err := tx.SQL(sql1, s_params1...).Query().List()
- if len(queryList2) == 0 {
- return query1, nil
- }
- if err != nil {
- fmt.Println("查询配料出错")
- return nil, err
- }
- //fmt.Printf("%T\n",queryList2[0]["weightjson"])
- b, _ := json.Marshal(&quertDataList)
- var m map[string]interface{}
- _ = json.Unmarshal(b, &m)
- msg := queryList2[0]["weightjson"].(string)
- weightjson := make([]map[string]string, 0)
- json.Unmarshal([]byte(msg), &weightjson)
- //fmt.Println(len(weightjson))
- realWandT := make([]interface{}, 0)
- for i := 0; i < len(weightjson); i++ {
- oneSlice := make([]interface{}, 0)
- oneSlice = append(oneSlice, weightjson[i]["mt"])
- oneSlice = append(oneSlice, weightjson[i]["w"])
- realWandT = append(realWandT, oneSlice)
- }
- WTime := make([]interface{}, 0)
- for z := 0; z < len(weightjson); z++ {
- WTime = append(WTime, weightjson[z]["mt"])
- }
- data2 := make([]interface{}, 0)
- for i := 0; i < len(queryList); i++ {
- querySlice := make([]interface{}, 0)
- querySlice = append(querySlice, queryList[i]["timedate"], queryList[i]["lweight"])
- data2 = append(data2, querySlice)
- }
- data5 := make([]interface{}, 0)
- for i := 0; i < len(queryList); i++ {
- querySlice := make([]interface{}, 0)
- querySlice = append(querySlice, queryList[i]["intime"], queryList[i]["actualweight"], queryList[i]["allname"], queryList[i]["fname"])
- data5 = append(data5, querySlice)
- }
- query1["WTime"] = WTime
- query1["data2"] = data2
- query1["data5"] = data5
- query1["realWandT"] = realWandT
- return query1, nil
- }
|