report.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "sort"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "tmr-watch/http/handle/restful"
  11. "github.com/Anderson-Lu/gofasion/gofasion"
  12. "github.com/xormplus/xorm"
  13. )
  14. //包含报表模块前端需要的各种数据格式转换
  15. func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session, checked string, offset, count, typea, mode int) (queryData map[string]interface{}, err error) {
  16. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  17. s_params := make([]interface{}, 0)
  18. if sql != "" {
  19. paramslist := strings.Split(p, ",")
  20. if len(paramslist) > 0 && p != "" {
  21. for _, value := range paramslist {
  22. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  23. }
  24. }
  25. }
  26. queryList, err := tx.SQL(sql, s_params...).Query().List()
  27. //############
  28. sql2, p2 := restful.GetSqlByNameDBT("getFeednameSort", tx)
  29. s_params2 := make([]interface{}, 0)
  30. if sql2 != "" {
  31. paramslist2 := strings.Split(p2, ",")
  32. if len(paramslist2) > 0 && p != "" {
  33. for _, value := range paramslist2 {
  34. s_params2 = append(s_params2, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  35. }
  36. }
  37. }
  38. queryList2, err := tx.SQL(sql2, s_params2...).Query().List()
  39. var feednamesort []string
  40. var feedcodelist []string
  41. if len(queryList2) > 0 {
  42. for i := 0; i < len(queryList2); i++ {
  43. feednamesort = append(feednamesort, queryList2[i]["fname"].(string))
  44. }
  45. }
  46. // #########
  47. sql3, p3 := restful.GetSqlByNameDBT("getFeednameSort2", tx)
  48. s_params3 := make([]interface{}, 0)
  49. if sql3 != "" {
  50. paramslist3 := strings.Split(p3, ",")
  51. if len(paramslist3) > 0 && p != "" {
  52. for _, value := range paramslist3 {
  53. s_params3 = append(s_params3, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  54. }
  55. }
  56. }
  57. // var queryList3 []map[string]interface{}
  58. feedDataList := make([]map[string]interface{}, 0)
  59. var feednamesort3 []string
  60. if sql3 != "" {
  61. queryList3, err := tx.SQL(sql3, s_params3...).Query().List()
  62. // fmt.Println()
  63. if err != nil {
  64. return nil, err
  65. }
  66. if len(queryList3) > 0 {
  67. for z := 0; z < len(queryList3); z++ {
  68. feednamesort3 = append(feednamesort3, queryList3[z]["feedname"].(string))
  69. feedcodelist = append(feedcodelist, queryList3[z]["feedcode"].(string))
  70. }
  71. feedDataList = append(feedDataList, queryList3...)
  72. }
  73. }
  74. if err != nil {
  75. return nil, err
  76. }
  77. // if len(queryList) == 0 {
  78. // return nil, nil
  79. // }
  80. temstr := ""
  81. //除特殊接口外,去接口名称的前10位做同一类型的转换
  82. switch sqlnamestr {
  83. case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa", "judgenurFTReportDetail":
  84. temstr = sqlnamestr
  85. default:
  86. temstr = sqlnamestr[:10]
  87. }
  88. // 根据名称选择不通类型的转换-(可自动扩展,不需要使用之前的)
  89. switch temstr {
  90. case "getAccurac", "getFeedEff":
  91. queryData, err = getAccuracy(queryList, "2006-01-02") // 不定参数
  92. case "getprocess":
  93. //queryData, err = getAccuracyV3v1(queryList)
  94. queryData, err = getAccuracyV3(queryList)
  95. // 统计分析 过程分析
  96. if sqlnamestr == "getprocessAnalysisTB" {
  97. quertDataList := queryData["list"]
  98. query := quertDataList.(map[string]interface{})
  99. querys, _ := GetprocessAnalysisTB(parammaps, tx, quertDataList, queryList)
  100. if len(querys) != 0 {
  101. query["data1"] = querys["WTime"]
  102. query["data2"] = querys["data2"]
  103. query["data3"] = querys["realWandT"]
  104. query["data5"] = querys["data5"]
  105. }
  106. }
  107. case "getHomepro":
  108. queryData, err = getAccuracyV3(queryList)
  109. case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa":
  110. queryData, err = getAccuracyV2(queryList) //固定维度 日期
  111. case "getMateria":
  112. sql1, p1 := restful.GetSqlByNameDBT(sqlnamestr+("sum"), tx)
  113. s_params1 := make([]interface{}, 0)
  114. if sql1 != "" {
  115. paramslist1 := strings.Split(p1, ",")
  116. if len(paramslist1) > 0 && p != "" {
  117. for _, value := range paramslist1 {
  118. s_params1 = append(s_params1, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  119. }
  120. }
  121. }
  122. queryListSum, _ := tx.SQL(sql1, s_params1...).Query().List()
  123. if mode == 0 {
  124. queryData, err = getAccuracyV4(queryList, queryListSum, checked, feednamesort3, typea)
  125. } else {
  126. queryData, _ = getAccuracyV41(queryList, queryListSum, checked, feednamesort3, typea, feedDataList)
  127. }
  128. queryData["feedcode"] = feedcodelist
  129. case "getPriceAn":
  130. queryData, err = getAccuracyV5(queryList)
  131. case "getJT1Accu":
  132. queryData, err = getAccuracyV6(queryList) //固定维度 牧场
  133. case "judgenurFT":
  134. queryData, err = getAccuracyV7(queryList)
  135. case "judgenurFTReportDetail":
  136. queryData, err = getAccuracyV8(queryList)
  137. case "downloadPl":
  138. var sql2, p2 string
  139. s_params2 := make([]interface{}, 0)
  140. if sqlnamestr == "downloadPlanSFJD" {
  141. sql2, p2 = restful.GetSqlByNameDBT("countfl", tx)
  142. //s_params1 := make([]interface{}, 0)
  143. if sql2 != "" {
  144. paramslist1 := strings.Split(p2, ",")
  145. if len(paramslist1) > 0 && p != "" {
  146. for _, value := range paramslist1 {
  147. s_params2 = append(s_params2, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  148. }
  149. }
  150. }
  151. }
  152. queryList2, _ := tx.SQL(sql2, s_params2...).Query().List()
  153. var flleight string
  154. if len(queryList2) > 0 {
  155. flleight, _ = queryList2[0]["flcount"].(string)
  156. // fmt.Println(flleight)
  157. }
  158. flleightint, _ := strconv.Atoi(flleight)
  159. if sqlnamestr == "downloadPlanTSLJD" {
  160. queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort3)
  161. } else {
  162. queryData, err = getAccuracyV9(queryList, sqlnamestr, flleightint, feednamesort) //投料简打、累加
  163. }
  164. default:
  165. queryData, err = nil, nil
  166. }
  167. return
  168. }
  169. func getAccuracyV9(queryList []map[string]interface{}, sqlnamestr string, flleightint int, feednamesort []string) (map[string]interface{}, error) {
  170. queryData := make(map[string]interface{})
  171. chartData := make(map[string]interface{})
  172. mapc3 := make(map[string]interface{})
  173. data2 := []interface{}{}
  174. data1 := []interface{}{}
  175. mapc3["label"] = "车次"
  176. mapc3["prop"] = "projname"
  177. data1 = append(data1, mapc3)
  178. mapc3 = make(map[string]interface{})
  179. mapc3["label"] = "TMR"
  180. mapc3["prop"] = "tmrtname"
  181. data1 = append(data1, mapc3)
  182. mapc3 = make(map[string]interface{})
  183. //if sqlnamestr == "downloadPlanSFJD":
  184. //mapc3["label"] = "时间"
  185. //mapc3["prop"] = "plantime"
  186. //data1 = append(data1, mapc3)
  187. //mapc3 = make(map[string]interface{})
  188. //
  189. //mapc3["label"] = "班组"
  190. //mapc3["prop"] = "times"
  191. //data1 = append(data1, mapc3)
  192. //mapc3 = make(map[string]interface{})
  193. //
  194. //mapc3["label"] = "驾驶员"
  195. //mapc3["prop"] = "driver"
  196. //data1 = append(data1, mapc3)
  197. //mapc3 = make(map[string]interface{})
  198. //
  199. //mapc3["label"] = "日系数比例"
  200. //mapc3["prop"] = "rate"
  201. //data1 = append(data1, mapc3)
  202. //mapc3 = make(map[string]interface{})
  203. //
  204. //mapc3["label"] = "牛头数"
  205. //mapc3["prop"] = "feedpcount"
  206. //data1 = append(data1, mapc3)
  207. //mapc3 = make(map[string]interface{})
  208. //
  209. //mapc3["label"] = "配方模板"
  210. //mapc3["prop"] = "templetname"
  211. //data1 = append(data1, mapc3)
  212. //mapc3 = make(map[string]interface{})
  213. //#######################################################################################
  214. mtem := make(map[interface{}]interface{})
  215. var stem, feedNames []string
  216. for _, feed := range feednamesort {
  217. feed = strings.ReplaceAll(feed, " ", "")
  218. mtem[feed] = struct{}{}
  219. // fmt.Println(feed)
  220. stem = append(stem, feed)
  221. }
  222. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  223. // if _, ok := mtem[queryList[i]["fname"]]; ok {
  224. // continue
  225. // }
  226. // stem = append(stem, queryList[i]["fname"].(string))
  227. // mtem[queryList[i]["fname"]] = struct{}{}
  228. feedNames = append(feedNames, queryList[i]["fname"].(string))
  229. }
  230. sort.Strings(feedNames)
  231. for _, feed := range feedNames {
  232. if _, ok := mtem[feed]; ok {
  233. continue
  234. }
  235. // fmt.Println(feed)
  236. stem = append(stem, feed)
  237. mtem[feed] = struct{}{}
  238. }
  239. stemEnd := []string{}
  240. if sqlnamestr == "downloadPlanSFJD" {
  241. bb := stem[len(stem)-flleightint : len(stem) : len(stem)]
  242. //aa := stem[0 : len(stem)-flleightint : len(stem)]
  243. stemEnd = append(stemEnd, bb...)
  244. stemEnd = append(stemEnd, feednamesort...)
  245. //fmt.Println(stemEnd)
  246. } else {
  247. stemEnd = stem
  248. }
  249. //logging.Info("导出数据 ",stemEnd )
  250. for _, va := range stemEnd {
  251. mapc3["label"] = va
  252. mapc3["prop"] = va
  253. data1 = append(data1, mapc3)
  254. mapc3 = make(map[string]interface{})
  255. }
  256. if queryList[0]["sumlweight"] != nil {
  257. mapc3["label"] = "合计"
  258. mapc3["prop"] = "sumlweight"
  259. }
  260. data1 = append(data1, mapc3)
  261. mapc3 = make(map[string]interface{})
  262. var tem interface{}
  263. mapc2 := make(map[string]interface{})
  264. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  265. if i == 0 {
  266. tem = queryList[i]["projname"]
  267. mapc2 = queryList[i]
  268. if mapc2["sumlweight"] != nil {
  269. var sumlweight float64
  270. sumlweight, _ = strconv.ParseFloat(mapc2["sumlweight"].(string), 64)
  271. mapc2["sumlweight"] = sumlweight
  272. }
  273. for key := range mtem {
  274. mapc2[xorm.String(key)] = 0
  275. }
  276. // var lweight float64
  277. if queryList[i]["lweight"] != nil {
  278. // var error errors.Error
  279. lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
  280. if err == nil {
  281. mapc2[xorm.String(queryList[i]["fname"])] = lweight
  282. } else {
  283. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  284. }
  285. } else {
  286. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  287. }
  288. }
  289. if tem == queryList[i]["projname"] {
  290. // var lweight float64
  291. if queryList[i]["lweight"] != nil {
  292. lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
  293. if err == nil {
  294. mapc2[xorm.String(queryList[i]["fname"])] = lweight
  295. } else {
  296. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  297. }
  298. } else {
  299. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  300. }
  301. } else {
  302. data2 = append(data2, mapc2)
  303. tem = queryList[i]["projname"]
  304. mapc2 = queryList[i]
  305. if mapc2["sumlweight"] != nil {
  306. var sumlweight float64
  307. sumlweight, _ = strconv.ParseFloat(mapc2["sumlweight"].(string), 64)
  308. mapc2["sumlweight"] = sumlweight
  309. }
  310. for key := range mtem {
  311. mapc2[xorm.String(key)] = 0
  312. }
  313. if queryList[i]["lweight"] != nil {
  314. lweight, err := strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
  315. if err == nil {
  316. mapc2[xorm.String(queryList[i]["fname"])] = lweight
  317. } else {
  318. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  319. }
  320. } else {
  321. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  322. }
  323. }
  324. }
  325. data2 = append(data2, mapc2)
  326. chartData["data1"] = data1
  327. chartData["data2"] = data2
  328. queryData["list"] = chartData
  329. queryData["code"] = 0
  330. queryData["message"] = "ok"
  331. queryData["data"] = queryList
  332. return queryData, nil
  333. }
  334. func getAccuracyV8(queryList []map[string]interface{}) (map[string]interface{}, error) {
  335. queryData := make(map[string]interface{})
  336. chartData := make(map[string]interface{})
  337. //list := make(map[string]interface{})
  338. data := []interface{}{}
  339. for i := 0; i < len(queryList); i++ {
  340. dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  341. Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
  342. Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
  343. trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
  344. jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
  345. uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
  346. // kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  347. adf, _ := strconv.ParseFloat(queryList[i]["adf"].(string), 64)
  348. ca, _ := strconv.ParseFloat(queryList[i]["ca"].(string), 64)
  349. cdry, _ := strconv.ParseFloat(queryList[i]["cdry"].(string), 64)
  350. cad, _ := strconv.ParseFloat(queryList[i]["cad"].(string), 64)
  351. cndf, _ := strconv.ParseFloat(queryList[i]["cndf"].(string), 64)
  352. cp, _ := strconv.ParseFloat(queryList[i]["cp"].(string), 64)
  353. cpd, _ := strconv.ParseFloat(queryList[i]["cpd"].(string), 64)
  354. fat, _ := strconv.ParseFloat(queryList[i]["fat"].(string), 64)
  355. ndf, _ := strconv.ParseFloat(queryList[i]["ndf"].(string), 64)
  356. // nm, _ := strconv.ParseFloat(queryList[i]["nm"].(string), 64)
  357. // nmd, _ := strconv.ParseFloat(queryList[i]["nmd"].(string), 64)
  358. // nuint, _ := strconv.ParseFloat(queryList[i]["nuint"].(string), 64)
  359. p, _ := strconv.ParseFloat(queryList[i]["p"].(string), 64)
  360. pd, _ := strconv.ParseFloat(queryList[i]["pd"].(string), 64)
  361. starch, _ := strconv.ParseFloat(queryList[i]["starch"].(string), 64)
  362. trans4f, _ := strconv.ParseFloat(queryList[i]["trans4f"].(string), 64)
  363. list := make(map[string]interface{})
  364. list["ft"] = dry
  365. list["index"] = "干物质(kg)"
  366. list["tmr"] = TransFloat(dry * Hrate)
  367. list["cyl"] = TransFloat(dry * Srate)
  368. data = append(data, list)
  369. list = make(map[string]interface{})
  370. list["ft"] = jcrate
  371. list["index"] = "粗精比(%)"
  372. list["tmr"] = TransFloat(jcrate * Hrate)
  373. list["cyl"] = TransFloat(jcrate * Srate)
  374. data = append(data, list)
  375. list = make(map[string]interface{})
  376. list["ft"] = uprice
  377. list["index"] = "日粮成本(元)"
  378. list["tmr"] = TransFloat(uprice * Hrate)
  379. list["cyl"] = TransFloat(uprice * Srate)
  380. data = append(data, list)
  381. // list = make(map[string]interface{})
  382. // list["ft"] = kprice
  383. // list["index"] = "公斤奶成本"
  384. // list["tmr"] = TransFloat(kprice * Hrate)
  385. // list["cyl"] = TransFloat(kprice * Srate)
  386. // data = append(data, list)
  387. list = make(map[string]interface{})
  388. list["ft"] = cdry
  389. list["index"] = "粗料中的干物质"
  390. list["tmr"] = TransFloat(cdry * Hrate)
  391. list["cyl"] = TransFloat(cdry * Srate)
  392. data = append(data, list)
  393. // list = make(map[string]interface{})
  394. // list["ft"] = nm
  395. // list["index"] = " 产奶净能(MJ)"
  396. // list["tmr"] = TransFloat(nm * Hrate)
  397. // list["cyl"] = TransFloat(nm * Srate)
  398. // data = append(data, list)
  399. // list = make(map[string]interface{})
  400. // list["ft"] = nuint
  401. // list["index"] = "奶牛能量单位(NND)"
  402. // list["tmr"] = TransFloat(nuint * Hrate)
  403. // list["cyl"] = TransFloat(nuint * Srate)
  404. // data = append(data, list)
  405. list = make(map[string]interface{})
  406. list["ft"] = cp
  407. list["index"] = "粗蛋白(g)"
  408. list["tmr"] = TransFloat(cp * Hrate)
  409. list["cyl"] = TransFloat(cp * Srate)
  410. data = append(data, list)
  411. list = make(map[string]interface{})
  412. list["ft"] = cpd
  413. list["index"] = "粗蛋白(%DM)"
  414. list["tmr"] = TransFloat(cpd * Hrate)
  415. list["cyl"] = TransFloat(cpd * Srate)
  416. data = append(data, list)
  417. list = make(map[string]interface{})
  418. list["ft"] = ca
  419. list["index"] = "钙(g)"
  420. list["tmr"] = TransFloat(ca * Hrate)
  421. list["cyl"] = TransFloat(ca * Srate)
  422. data = append(data, list)
  423. list = make(map[string]interface{})
  424. list["ft"] = p
  425. list["index"] = "磷(g)"
  426. list["tmr"] = TransFloat(p * Hrate)
  427. list["cyl"] = TransFloat(p * Srate)
  428. data = append(data, list)
  429. // list = make(map[string]interface{})
  430. // list["ft"] = nmd
  431. // list["index"] = "产奶净能(Mcal/DM)"
  432. // list["tmr"] = TransFloat(nmd * Hrate)
  433. // list["cyl"] = TransFloat(nmd * Srate)
  434. // data = append(data, list)
  435. list = make(map[string]interface{})
  436. list["ft"] = fat
  437. list["index"] = "脂肪"
  438. list["tmr"] = TransFloat(fat * Hrate)
  439. list["cyl"] = TransFloat(fat * Srate)
  440. data = append(data, list)
  441. list = make(map[string]interface{})
  442. list["ft"] = starch
  443. list["index"] = "淀粉"
  444. list["tmr"] = TransFloat(starch * Hrate)
  445. list["cyl"] = TransFloat(starch * Srate)
  446. data = append(data, list)
  447. list = make(map[string]interface{})
  448. list["ft"] = ndf
  449. list["index"] = "NDF(%DM)"
  450. list["tmr"] = TransFloat(ndf * Hrate)
  451. list["cyl"] = TransFloat(ndf * Srate)
  452. data = append(data, list)
  453. list = make(map[string]interface{})
  454. list["ft"] = cndf
  455. list["index"] = "粗料中的NDF(%DM)"
  456. list["tmr"] = TransFloat(cndf * Hrate)
  457. list["cyl"] = TransFloat(cndf * Srate)
  458. data = append(data, list)
  459. list = make(map[string]interface{})
  460. list["ft"] = adf
  461. list["index"] = " ADF(%DM)"
  462. list["tmr"] = TransFloat(adf * Hrate)
  463. list["cyl"] = TransFloat(adf * Srate)
  464. data = append(data, list)
  465. list = make(map[string]interface{})
  466. list["ft"] = cad
  467. list["index"] = "钙(%DM)"
  468. list["tmr"] = TransFloat(cad * Hrate)
  469. list["cyl"] = TransFloat(cad * Srate)
  470. data = append(data, list)
  471. list = make(map[string]interface{})
  472. list["ft"] = pd
  473. list["index"] = " 磷(%DM)"
  474. list["tmr"] = TransFloat(pd * Hrate)
  475. list["cyl"] = TransFloat(pd * Srate)
  476. data = append(data, list)
  477. list = make(map[string]interface{})
  478. list["ft"] = trans35f
  479. list["index"] = "(3.5)FCR(kg/DM)"
  480. list["tmr"] = TransFloat(trans35f * Hrate)
  481. list["cyl"] = TransFloat(trans35f * Srate)
  482. data = append(data, list)
  483. list = make(map[string]interface{})
  484. list["ft"] = trans4f
  485. list["index"] = "(4.0)FCR(kg/DM)"
  486. list["tmr"] = TransFloat(trans4f * Hrate)
  487. list["cyl"] = TransFloat(trans4f * Srate)
  488. data = append(data, list)
  489. }
  490. chartData["data"] = data
  491. queryData["list"] = chartData
  492. queryData["code"] = 0
  493. queryData["message"] = "ok"
  494. queryData["data"] = queryList
  495. return queryData, nil
  496. }
  497. func TransFloat(flo float64) float64 {
  498. hf, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(flo)), 64)
  499. return hf
  500. }
  501. func getAccuracyV7(queryList []map[string]interface{}) (map[string]interface{}, error) {
  502. queryData := make(map[string]interface{})
  503. chartData := make(map[string]interface{})
  504. //list := make(map[string]interface{})
  505. data := []interface{}{}
  506. for i := 0; i < len(queryList); i++ {
  507. dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  508. Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
  509. Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
  510. trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
  511. jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
  512. uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
  513. kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  514. list := make(map[string]interface{})
  515. list["tname"] = queryList[i]["tname"]
  516. list["ftid"] = queryList[i]["ftid"]
  517. list["ft"] = dry
  518. list["index"] = "干物质(kg)"
  519. list["tmr"] = TransFloat(dry * Hrate)
  520. list["cyl"] = TransFloat(dry * Srate)
  521. data = append(data, list)
  522. list = make(map[string]interface{})
  523. list["tname"] = queryList[i]["tname"]
  524. list["ftid"] = queryList[i]["ftid"]
  525. list["ft"] = trans35f
  526. list["index"] = "(3.5)FCR(kg/DM)"
  527. list["tmr"] = TransFloat(trans35f * Hrate)
  528. list["cyl"] = TransFloat(trans35f * Srate)
  529. data = append(data, list)
  530. list = make(map[string]interface{})
  531. list["tname"] = queryList[i]["tname"]
  532. list["ftid"] = queryList[i]["ftid"]
  533. list["ft"] = jcrate
  534. list["index"] = "粗精比(%)"
  535. list["tmr"] = TransFloat(jcrate * Hrate)
  536. list["cyl"] = TransFloat(jcrate * Srate)
  537. data = append(data, list)
  538. list = make(map[string]interface{})
  539. list["tname"] = queryList[i]["tname"]
  540. list["ftid"] = queryList[i]["ftid"]
  541. list["ft"] = uprice
  542. list["index"] = "日粮成本(元)"
  543. list["tmr"] = TransFloat(uprice * Hrate)
  544. list["cyl"] = TransFloat(uprice * Srate)
  545. data = append(data, list)
  546. list = make(map[string]interface{})
  547. list["tname"] = queryList[i]["tname"]
  548. list["ftid"] = queryList[i]["ftid"]
  549. list["ft"] = kprice
  550. list["index"] = "公斤奶成本"
  551. list["tmr"] = TransFloat(kprice * Hrate)
  552. list["cyl"] = TransFloat(kprice * Srate)
  553. data = append(data, list)
  554. }
  555. chartData["data"] = data
  556. queryData["list"] = chartData
  557. queryData["code"] = 0
  558. queryData["message"] = "ok"
  559. queryData["data"] = queryList
  560. return queryData, nil
  561. }
  562. func getAccuracyV6(queryList []map[string]interface{}) (map[string]interface{}, error) {
  563. queryData := make(map[string]interface{})
  564. chartData := make(map[string]interface{})
  565. data := []interface{}{}
  566. data1 := []interface{}{}
  567. data2 := []interface{}{}
  568. data3 := []interface{}{}
  569. data4 := []interface{}{}
  570. for i := 0; i < len(queryList); i++ {
  571. data = append(data, queryList[i]["牧场"])
  572. data1 = append(data1, queryList[i]["field1"])
  573. data2 = append(data2, queryList[i]["field2"])
  574. data3 = append(data3, queryList[i]["field3"])
  575. data4 = append(data4, queryList[i]["field4"])
  576. }
  577. chartData["data1"] = data
  578. chartData["data2"] = data1
  579. chartData["data3"] = data2
  580. chartData["data4"] = data3
  581. chartData["data5"] = data4
  582. queryData["list"] = chartData
  583. queryData["code"] = 0
  584. queryData["message"] = "ok"
  585. queryData["data"] = queryList
  586. return queryData, nil
  587. }
  588. func getAccuracyV5(queryList []map[string]interface{}) (map[string]interface{}, error) {
  589. queryData := make(map[string]interface{})
  590. chartData := make(map[string]interface{})
  591. datamap1 := make(map[string]interface{})
  592. datamap2 := make(map[string]interface{})
  593. temsmap := make(map[interface{}]interface{})
  594. mapc2 := make(map[interface{}]interface{})
  595. data3 := []interface{}{}
  596. datamap2child := make(map[string]interface{})
  597. data2 := []interface{}{}
  598. data1 := []interface{}{}
  599. var dtem interface{}
  600. var temstr interface{}
  601. var typestr interface{}
  602. count2 := 0
  603. a := 0
  604. for i := 0; i < len(queryList); i++ {
  605. if i == 0 {
  606. temstr = queryList[i]["fname"]
  607. typestr = queryList[i]["typestr"]
  608. }
  609. if temstr == queryList[i]["fname"] {
  610. temsmap[queryList[i]["feedname"]] = 1
  611. }
  612. if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
  613. mapc2[queryList[i]["feedname"]] = count2
  614. mapc2[count2] = queryList[i]["feedname"]
  615. count2++
  616. }
  617. }
  618. //for i := 0; i<count2 ; i++ {
  619. // reslist := make([]map[string]interface{},1)
  620. // res := make(map[string]interface{})
  621. // res["fname"] = "分界线"
  622. // res["feedname"] = mapc2[i]
  623. // res["饲料名称"] = mapc2[i]
  624. // reslist[0] = res
  625. // queryList = append(reslist,queryList...)
  626. //}
  627. for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
  628. if _, ok := temsmap[mapc2[i]]; !ok {
  629. reslist := make([]map[string]interface{}, 1)
  630. res := make(map[string]interface{})
  631. res["fname"] = temstr
  632. res["feedname"] = mapc2[i]
  633. res["饲料名称"] = mapc2[i]
  634. res["typestr"] = typestr
  635. reslist[0] = res
  636. queryList = append(reslist, queryList...)
  637. }
  638. }
  639. for i := 0; i < len(queryList); i++ {
  640. a = mapc2[queryList[i]["feedname"]].(int) * 2
  641. if i == 0 {
  642. datamap2["label"] = "饲料名称"
  643. switch queryList[i]["typestr"].(type) {
  644. case string:
  645. datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
  646. default:
  647. datamap2child["label"] = "/饲料参数"
  648. }
  649. datamap2child["prop"] = "A"
  650. data3 = append(data3, datamap2child)
  651. datamap2["children"] = data3
  652. data2 = append(data2, datamap2)
  653. data3 = []interface{}{}
  654. datamap2child = make(map[string]interface{})
  655. datamap2 = make(map[string]interface{})
  656. dtem = queryList[i]["fname"]
  657. }
  658. if dtem != queryList[i]["fname"] && i != 0 {
  659. data1 = append(data1, datamap1)
  660. dtem = queryList[i]["fname"]
  661. datamap1 = make(map[string]interface{})
  662. }
  663. if queryList[i]["fname"] == temstr {
  664. datamap2["label"] = queryList[i]["feedname"]
  665. datamap2child["label"] = "理论"
  666. datamap2child["prop"] = "a" + strconv.Itoa(a)
  667. data3 = append(data3, datamap2child)
  668. datamap2child = make(map[string]interface{})
  669. datamap2child["label"] = "实际"
  670. datamap2child["prop"] = "a" + strconv.Itoa(a+1)
  671. data3 = append(data3, datamap2child)
  672. datamap2child = make(map[string]interface{})
  673. datamap2["children"] = data3
  674. data2 = append(data2, datamap2)
  675. data3 = []interface{}{}
  676. datamap2 = make(map[string]interface{})
  677. datamap2child = make(map[string]interface{})
  678. }
  679. datamap1["A"] = queryList[i]["fname"]
  680. datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
  681. datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
  682. datamap2["label"] = queryList[i]["饲料名称"]
  683. a = a + 2
  684. }
  685. data1 = append(data1, datamap1)
  686. chartData["data1"] = data1
  687. chartData["data2"] = data2
  688. queryData["list"] = chartData
  689. queryData["code"] = 0
  690. queryData["message"] = "ok"
  691. queryData["data"] = queryList
  692. return queryData, nil
  693. }
  694. func getAccuracyV4(queryList []map[string]interface{}, queryListSum []map[string]interface{}, checked string, feednamesort3 []string, typea int) (map[string]interface{}, error) {
  695. queryData := make(map[string]interface{})
  696. chartData := make(map[string]interface{})
  697. datamap1 := make(map[string]interface{})
  698. datamap2 := make(map[string]interface{})
  699. temsmap := make(map[interface{}]interface{})
  700. mapc2 := make(map[interface{}]interface{})
  701. mapc3 := make(map[interface{}]interface{})
  702. data3 := []interface{}{}
  703. datamap2child := make(map[string]interface{})
  704. data2 := []interface{}{}
  705. data1 := []interface{}{}
  706. a := 0
  707. //ss := 0
  708. var dtem interface{}
  709. count2 := 0
  710. var tem interface{}
  711. var temstr interface{}
  712. var typestr interface{}
  713. //var sort interface{}
  714. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  715. if i == 0 {
  716. temstr = queryList[i]["fname"]
  717. typestr = queryList[i]["typestr"]
  718. //sort = queryList[i]["sort"]
  719. }
  720. if temstr == queryList[i]["fname"] {
  721. temsmap[queryList[i]["feedname"]] = 1
  722. }
  723. //if i == len(queryList)-1{
  724. // temstr = "合计"
  725. // typestr = queryList[i]["typestr"]
  726. //}
  727. if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
  728. mapc2[queryList[i]["feedname"]] = count2 // 编号
  729. mapc2[count2] = queryList[i]["feedname"]
  730. count2++
  731. }
  732. }
  733. for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
  734. if _, ok := temsmap[mapc2[i]]; !ok {
  735. reslist := make([]map[string]interface{}, 1)
  736. res := make(map[string]interface{})
  737. res["fname"] = temstr
  738. res["feedname"] = mapc2[i]
  739. res["饲料名称"] = mapc2[i]
  740. res["typestr"] = typestr
  741. reslist[0] = res
  742. queryList = append(reslist, queryList...)
  743. }
  744. }
  745. //for i := 0; i<count2 ; i++ {
  746. // reslist := make([]map[string]interface{},1)
  747. // res := make(map[string]interface{})
  748. // res["fname"] = "分界线"
  749. // res["feedname"] = mapc2[i]
  750. // res["饲料名称"] = mapc2[i]
  751. // res["typestr"] =typestr
  752. // reslist[0] = res
  753. // queryList = append(reslist,queryList...)
  754. //}
  755. for i := 0; i < len(queryList); i++ {
  756. if i == 0 {
  757. tem = queryList[i]["fname"]
  758. }
  759. if queryList[i]["fname"] == tem {
  760. mapc3[queryList[i]["feedname"]] = i
  761. }
  762. }
  763. for i := 0; i < len(queryList); i++ {
  764. a = mapc2[queryList[i]["feedname"]].(int) * 4
  765. if i == 0 {
  766. datamap2["label"] = "饲料名称"
  767. switch queryList[i]["typestr"].(type) {
  768. case string:
  769. // datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
  770. datamap2child["label"] = queryList[i]["typestr"].(string)
  771. default:
  772. datamap2child["label"] = "/饲料参数"
  773. }
  774. datamap2child["prop"] = "A"
  775. data3 = append(data3, datamap2child)
  776. datamap2["children"] = data3
  777. data2 = append(data2, datamap2)
  778. data3 = []interface{}{}
  779. datamap2child = make(map[string]interface{})
  780. datamap2 = make(map[string]interface{})
  781. dtem = queryList[i]["fname"]
  782. }
  783. if dtem != queryList[i]["fname"] && i != 0 {
  784. data1 = append(data1, datamap1)
  785. dtem = queryList[i]["fname"]
  786. datamap1 = make(map[string]interface{})
  787. }
  788. if queryList[i]["fname"] == temstr {
  789. datamap2["label"] = queryList[i]["feedname"]
  790. if typea == 0 || typea == 1 {
  791. datamap2child["label"] = "理论"
  792. datamap2child["prop"] = "a" + strconv.Itoa(a)
  793. data3 = append(data3, datamap2child)
  794. datamap2child = make(map[string]interface{})
  795. }
  796. if typea == 0 || typea == 2 {
  797. datamap2child["label"] = "实际"
  798. datamap2child["prop"] = "a" + strconv.Itoa(a+1)
  799. data3 = append(data3, datamap2child)
  800. datamap2child = make(map[string]interface{})
  801. }
  802. if checked == "1" {
  803. datamap2child["label"] = "误差值"
  804. datamap2child["prop"] = "a" + strconv.Itoa(a+2)
  805. data3 = append(data3, datamap2child)
  806. datamap2child = make(map[string]interface{})
  807. datamap2child["label"] = "误差率"
  808. datamap2child["prop"] = "a" + strconv.Itoa(a+3)
  809. data3 = append(data3, datamap2child)
  810. datamap2child = make(map[string]interface{})
  811. }
  812. // datamap2 = make(map[string]interface{})
  813. if i != len(queryList)-1 {
  814. datamap2["children"] = data3
  815. data2 = append(data2, datamap2)
  816. datamap2 = make(map[string]interface{})
  817. data3 = []interface{}{}
  818. }
  819. }
  820. datamap1["A"] = queryList[i]["fname"]
  821. if queryList[i]["lweight"] != nil {
  822. var lweight float64
  823. lweight, _ = strconv.ParseFloat(queryList[i]["lweight"].(string), 64)
  824. datamap1["a"+strconv.Itoa(a)] = lweight
  825. } else {
  826. datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
  827. }
  828. if queryList[i]["actualweightminus"] != nil {
  829. var actualweightminus float64
  830. actualweightminus, _ = strconv.ParseFloat(queryList[i]["actualweightminus"].(string), 64)
  831. datamap1["a"+strconv.Itoa(a+1)] = actualweightminus
  832. } else {
  833. datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
  834. }
  835. if checked == "1" {
  836. datamap1["a"+strconv.Itoa(a+2)] = queryList[i]["diff"]
  837. datamap1["a"+strconv.Itoa(a+3)] = queryList[i]["diffrate"]
  838. }
  839. datamap2["label"] = queryList[i]["饲料名称"]
  840. for z := 0; z < len(queryListSum); z++ {
  841. if queryListSum[z]["fname"] == queryList[i]["fname"] {
  842. if queryListSum[z]["lweight"] != nil {
  843. var lweight float64
  844. lweight, _ = strconv.ParseFloat(queryListSum[z]["lweight"].(string), 64)
  845. datamap1["B"] = lweight
  846. } else {
  847. datamap1["B"] = queryListSum[z]["lweight"]
  848. }
  849. if queryListSum[z]["actualweightminus"] != nil {
  850. var actualweightminus float64
  851. actualweightminus, _ = strconv.ParseFloat(queryListSum[z]["actualweightminus"].(string), 64)
  852. datamap1["C"] = actualweightminus
  853. } else {
  854. datamap1["B"] = queryListSum[z]["actualweightminus"]
  855. }
  856. }
  857. }
  858. if i == len(queryList)-1 {
  859. datamap2["label"] = "合计"
  860. if typea == 0 || typea == 1 {
  861. datamap2child = make(map[string]interface{})
  862. datamap2child["label"] = "理论"
  863. datamap2child["prop"] = "B"
  864. data3 = append(data3, datamap2child)
  865. }
  866. if typea == 0 || typea == 2 {
  867. datamap2child = make(map[string]interface{})
  868. datamap2child["label"] = "实际"
  869. datamap2child["prop"] = "C"
  870. data3 = append(data3, datamap2child)
  871. }
  872. // ###########################
  873. datamap2["children"] = data3
  874. data2 = append(data2, datamap2)
  875. datamap2 = make(map[string]interface{})
  876. data3 = []interface{}{}
  877. }
  878. }
  879. //var sortSum []string
  880. //for z := 0; z < len(data2); z++ {
  881. // ss := data2[z].(map[string]interface{})
  882. // bb := ss["label"].(string)
  883. // if bb != "合计" {
  884. // sortSum = append(sortSum, bb)
  885. // }
  886. //}
  887. //sort.Strings(sortSum)
  888. //fmt.Println(sortSum)
  889. theEndSort := []interface{}{}
  890. for ii := 0; ii < len(data2); ii++ {
  891. ss := data2[ii].(map[string]interface{})
  892. bb := ss["label"].(string)
  893. if "饲料名称" == bb {
  894. theEndSort = append(theEndSort, data2[ii])
  895. }
  896. }
  897. for _, v := range feednamesort3 {
  898. for ii := 0; ii < len(data2); ii++ {
  899. ss := data2[ii].(map[string]interface{})
  900. bb := ss["label"].(string)
  901. // fmt.Println(bb)
  902. if v == bb && "饲料名称" != bb {
  903. theEndSort = append(theEndSort, data2[ii])
  904. }
  905. }
  906. }
  907. for ii := 0; ii < len(data2); ii++ {
  908. ss := data2[ii].(map[string]interface{})
  909. bb := ss["label"].(string)
  910. if "合计" == bb {
  911. theEndSort = append(theEndSort, data2[ii])
  912. }
  913. }
  914. data1 = append(data1, datamap1)
  915. chartData["data1"] = data1
  916. chartData["data2"] = theEndSort
  917. queryData["list"] = chartData
  918. queryData["code"] = 0
  919. queryData["message"] = "ok"
  920. queryData["data"] = queryList
  921. return queryData, nil
  922. }
  923. func getAccuracyV3(queryList []map[string]interface{}) (map[string]interface{}, error) {
  924. queryData := make(map[string]interface{})
  925. chartData := make(map[string]interface{})
  926. data := []interface{}{}
  927. data1 := []interface{}{}
  928. data2 := []interface{}{}
  929. data3 := []interface{}{}
  930. data4 := []interface{}{}
  931. //
  932. t1 := make(map[interface{}]string, 0)
  933. for i := 0; i < len(queryList); i++ {
  934. data = append(data, queryList[i]["mtime"])
  935. data1 = append(data1, queryList[i]["lweight"])
  936. data2 = append(data2, queryList[i]["weight"])
  937. //data3 = append(data3, queryList[i]["field3"])
  938. //data4 = append(data4, queryList[i]["field4"])
  939. if _, ok := t1[queryList[i]["id"]]; !ok {
  940. datatem := []interface{}{}
  941. datatem = append(datatem, queryList[i]["startstime"], queryList[i]["lastactualweight"])
  942. data3 = append(data3, datatem)
  943. datatem2 := []interface{}{}
  944. datatem2 = append(datatem2, queryList[i]["intime"], queryList[i]["actualweight"])
  945. data4 = append(data4, datatem2)
  946. //datatem = []interface{}{}
  947. }
  948. t1[queryList[i]["id"]] = "1"
  949. }
  950. //
  951. chartData["data1"] = data
  952. chartData["data2"] = data1
  953. chartData["data3"] = data2
  954. chartData["data4"] = data3
  955. chartData["data5"] = data4
  956. queryData["list"] = chartData
  957. queryData["code"] = 0
  958. queryData["message"] = "ok"
  959. queryData["data"] = queryList
  960. return queryData, nil
  961. }
  962. func getAccuracyV2(queryList []map[string]interface{}) (map[string]interface{}, error) {
  963. queryData := make(map[string]interface{})
  964. chartData := make(map[string]interface{})
  965. data := []interface{}{}
  966. data1 := []interface{}{}
  967. data2 := []interface{}{}
  968. data3 := []interface{}{}
  969. data4 := []interface{}{}
  970. for i := 0; i < len(queryList); i++ {
  971. data = append(data, queryList[i]["日期"])
  972. data1 = append(data1, queryList[i]["field1"])
  973. data2 = append(data2, queryList[i]["field2"])
  974. data3 = append(data3, queryList[i]["field3"])
  975. data4 = append(data4, queryList[i]["field4"])
  976. }
  977. chartData["data1"] = data
  978. chartData["data2"] = data1
  979. chartData["data3"] = data2
  980. chartData["data4"] = data3
  981. chartData["data5"] = data4
  982. queryData["list"] = chartData
  983. queryData["code"] = 0
  984. queryData["message"] = "ok"
  985. queryData["data"] = queryList
  986. return queryData, nil
  987. }
  988. func getAccuracy(queryList []map[string]interface{}, layout string) (map[string]interface{}, error) {
  989. queryData := make(map[string]interface{})
  990. chartData := make(map[string]interface{})
  991. t1 := make(map[interface{}]interface{}, 0)
  992. t2 := make(map[interface{}]interface{}, 0)
  993. data := make(map[string][]interface{}, 0)
  994. t := make([]map[string][]interface{}, 0)
  995. e1 := []interface{}{}
  996. e2 := []string{}
  997. for _, value := range queryList {
  998. if _, ok := t1[value["名称"]]; !ok {
  999. e1 = append(e1, value["名称"])
  1000. }
  1001. if _, ok := t2[value["日期"]]; !ok {
  1002. switch value["日期"].(type) {
  1003. case string:
  1004. e2 = append(e2, value["日期"].(string))
  1005. }
  1006. }
  1007. t1[value["名称"]] = value["名称"]
  1008. t2[value["日期"]] = value["日期"]
  1009. }
  1010. sort.Strings(e2)
  1011. var b interface{}
  1012. a := 0
  1013. for i := 0; i < len(queryList); i++ {
  1014. if i == 0 {
  1015. b = queryList[i]["名称"]
  1016. }
  1017. if b != queryList[i]["名称"] {
  1018. if a < len(e2)-1 {
  1019. eee := len(e2) - a
  1020. fmt.Println(eee)
  1021. for k := 0; k < len(e2)-a; k++ {
  1022. data["data"] = append(data["data"], "")
  1023. }
  1024. }
  1025. t = append(t, data)
  1026. data = make(map[string][]interface{}, 0)
  1027. b = queryList[i]["名称"]
  1028. a = 0
  1029. }
  1030. switch queryList[i]["日期"].(type) {
  1031. case string:
  1032. dates, _ := time.Parse(layout, queryList[i]["日期"].(string))
  1033. dates1 := ""
  1034. if a < len(e2)-1 {
  1035. dates1 = e2[a]
  1036. } else {
  1037. dates1 = e2[len(e2)-1]
  1038. }
  1039. if a < len(e2)-1 {
  1040. if e2[a] != queryList[i]["日期"].(string) {
  1041. if e2[a] < queryList[i]["日期"].(string) {
  1042. dates1 = queryList[i]["日期"].(string)
  1043. dates, _ = time.Parse(layout, e2[a])
  1044. for ; a < len(e2)-1; a++ {
  1045. if e2[a] >= queryList[i]["日期"].(string) {
  1046. break
  1047. }
  1048. }
  1049. }
  1050. if layout == "2006-01-02" {
  1051. for ; dates.Format(layout) < dates1; dates = dates.Add(24 * time.Hour) {
  1052. data["data"] = append(data["data"], "")
  1053. }
  1054. } else if layout == "2006-01" {
  1055. for ; dates.Format(layout) < dates1; dates = dates.AddDate(0, 1, 0) {
  1056. data["data"] = append(data["data"], "")
  1057. }
  1058. }
  1059. }
  1060. }
  1061. }
  1062. data["data"] = append(data["data"], queryList[i]["准确率"])
  1063. a++
  1064. }
  1065. if a < len(e2)-1 {
  1066. for k := 0; k < len(e2)-a; k++ {
  1067. data["data"] = append(data["data"], "")
  1068. }
  1069. }
  1070. t = append(t, data)
  1071. chartData["data1"] = e1
  1072. chartData["data2"] = e2
  1073. chartData["data3"] = t
  1074. queryData["list"] = chartData
  1075. queryData["code"] = 0
  1076. queryData["message"] = "ok"
  1077. queryData["data"] = queryList
  1078. return queryData, nil
  1079. }
  1080. //统计分析过程分析data值拆分
  1081. func GetprocessAnalysisTB(parammaps *gofasion.Fasion, tx *xorm.Session, quertDataList interface{}, queryList []map[string]interface{}) (query map[string]interface{}, err error) {
  1082. sql1, p1 := restful.GetSqlByNameDBT("getweightjson", tx)
  1083. query1 := make(map[string]interface{}, 0)
  1084. s_params1 := make([]interface{}, 0)
  1085. if sql1 != "" {
  1086. paramslist := strings.Split(p1, ",")
  1087. if len(paramslist) > 0 && p1 != "" {
  1088. for _, value := range paramslist {
  1089. s_params1 = append(s_params1, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  1090. }
  1091. }
  1092. }
  1093. queryList2, err := tx.SQL(sql1, s_params1...).Query().List()
  1094. if len(queryList2) == 0 {
  1095. return query1, nil
  1096. }
  1097. if err != nil {
  1098. fmt.Println("查询配料出错")
  1099. return nil, err
  1100. }
  1101. //fmt.Printf("%T\n",queryList2[0]["weightjson"])
  1102. b, _ := json.Marshal(&quertDataList)
  1103. var m map[string]interface{}
  1104. _ = json.Unmarshal(b, &m)
  1105. msg := queryList2[0]["weightjson"].(string)
  1106. weightjson := make([]map[string]string, 0)
  1107. json.Unmarshal([]byte(msg), &weightjson)
  1108. //fmt.Println(len(weightjson))
  1109. realWandT := make([]interface{}, 0)
  1110. for i := 0; i < len(weightjson); i++ {
  1111. oneSlice := make([]interface{}, 0)
  1112. oneSlice = append(oneSlice, weightjson[i]["mt"])
  1113. oneSlice = append(oneSlice, weightjson[i]["w"])
  1114. realWandT = append(realWandT, oneSlice)
  1115. }
  1116. WTime := make([]interface{}, 0)
  1117. for z := 0; z < len(weightjson); z++ {
  1118. WTime = append(WTime, weightjson[z]["mt"])
  1119. }
  1120. data2 := make([]interface{}, 0)
  1121. for i := 0; i < len(queryList); i++ {
  1122. querySlice := make([]interface{}, 0)
  1123. querySlice = append(querySlice, queryList[i]["timedate"], queryList[i]["lweight"])
  1124. data2 = append(data2, querySlice)
  1125. }
  1126. data5 := make([]interface{}, 0)
  1127. for i := 0; i < len(queryList); i++ {
  1128. querySlice := make([]interface{}, 0)
  1129. querySlice = append(querySlice, queryList[i]["intime"], queryList[i]["actualweight"], queryList[i]["allname"], queryList[i]["fname"])
  1130. data5 = append(data5, querySlice)
  1131. }
  1132. query1["WTime"] = WTime
  1133. query1["data2"] = data2
  1134. query1["data5"] = data5
  1135. query1["realWandT"] = realWandT
  1136. return query1, nil
  1137. }
  1138. type Columns struct {
  1139. Prop string `json:"prop"`
  1140. Label string `json:"label"`
  1141. }
  1142. func getAccuracyV41(queryList []map[string]interface{}, queryListSum []map[string]interface{}, checked string, feednamesort3 []string, typea int, feednameCodes []map[string]interface{}) (map[string]interface{}, error) {
  1143. columns := make([]*Columns, 0)
  1144. columns = append(columns, &Columns{
  1145. Prop: "A",
  1146. Label: "饲料编码",
  1147. })
  1148. columns = append(columns, &Columns{
  1149. Prop: "B",
  1150. Label: "饲料名称",
  1151. })
  1152. label := "类别"
  1153. // column1 := new(Columns)
  1154. columns1 := make([]*Columns, 0)
  1155. dataList := make([]map[string]interface{}, 0)
  1156. for i := 0; i < len(queryList); i++ {
  1157. label = queryList[i]["typestr"].(string)
  1158. exist1 := false
  1159. for _, data := range dataList {
  1160. if data["B"].(string) == queryList[i]["feedname"].(string) {
  1161. exist1 = true
  1162. }
  1163. }
  1164. if !exist1 {
  1165. data1 := make(map[string]interface{}, 0)
  1166. data2 := make(map[string]interface{}, 0)
  1167. for _, v := range feednameCodes {
  1168. if v["feedname"].(string) == queryList[i]["feedname"].(string) {
  1169. data1["A"] = v["feedcode"]
  1170. data2["A"] = v["feedcode"]
  1171. break
  1172. }
  1173. }
  1174. data1["B"] = queryList[i]["feedname"]
  1175. data1["C"] = "理论"
  1176. // data1[queryList[i]["fname"].(string)] = 0
  1177. dataList = append(dataList, data1)
  1178. data2["B"] = queryList[i]["feedname"]
  1179. data2["C"] = "实际"
  1180. // data2[queryList[i]["fname"].(string)] = 0
  1181. dataList = append(dataList, data2)
  1182. }
  1183. column := new(Columns)
  1184. column.Prop = queryList[i]["fname"].(string)
  1185. column.Label = queryList[i]["fname"].(string)
  1186. exist := false
  1187. for _, c := range columns1 {
  1188. if c.Prop == queryList[i]["fname"].(string) {
  1189. exist = true
  1190. }
  1191. }
  1192. if exist {
  1193. continue
  1194. }
  1195. columns1 = append(columns1, column)
  1196. }
  1197. for _, data := range dataList {
  1198. for _, c := range columns1 {
  1199. data[c.Prop] = 0
  1200. }
  1201. }
  1202. data1 := make(map[string]interface{}, 0)
  1203. data2 := make(map[string]interface{}, 0)
  1204. data1["B"] = "合计"
  1205. data1["C"] = "理论"
  1206. data2["B"] = "合计"
  1207. data2["C"] = "实际"
  1208. for _, c := range columns1 {
  1209. if c.Prop != "合计" {
  1210. data1[c.Prop] = 0.0
  1211. data2[c.Prop] = 0.0
  1212. }
  1213. }
  1214. columns = append(columns, &Columns{
  1215. Prop: "C",
  1216. Label: label,
  1217. })
  1218. columns = append(columns, columns1...)
  1219. for _, data := range dataList {
  1220. for i := 0; i < len(queryList); i++ {
  1221. if queryList[i]["feedname"].(string) == data["B"] {
  1222. if data["C"].(string) == "理论" {
  1223. f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", queryList[i]["lweight"]), 64)
  1224. data[queryList[i]["fname"].(string)] = Round(f1, 2)
  1225. } else {
  1226. if queryList[i]["actualweightminus"] == nil {
  1227. data[queryList[i]["fname"].(string)] = 0.0
  1228. } else {
  1229. f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", queryList[i]["actualweightminus"]), 64)
  1230. data[queryList[i]["fname"].(string)] = Round(f1, 2)
  1231. }
  1232. }
  1233. }
  1234. }
  1235. }
  1236. for _, data := range dataList {
  1237. for _, c := range columns1 {
  1238. if c.Prop != "合计" {
  1239. if data["C"].(string) == "理论" {
  1240. f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", data1[c.Prop]), 64)
  1241. f2, _ := strconv.ParseFloat(fmt.Sprintf("%v", data[c.Prop]), 64)
  1242. data1[c.Prop] = Round(f1+f2, 2)
  1243. } else {
  1244. f1, _ := strconv.ParseFloat(fmt.Sprintf("%v", data2[c.Prop]), 64)
  1245. f2, _ := strconv.ParseFloat(fmt.Sprintf("%v", data[c.Prop]), 64)
  1246. data2[c.Prop] = Round(f1+f2, 2)
  1247. }
  1248. }
  1249. }
  1250. }
  1251. dataList = append(dataList, data1)
  1252. dataList = append(dataList, data2)
  1253. respData := make(map[string]interface{})
  1254. respData["data"] = dataList
  1255. respData["columns"] = columns
  1256. return respData, nil
  1257. }
  1258. func Round(number float64, size int) float64 {
  1259. return math.Round(number*100) / 100
  1260. }