35b8dc2f9e143c01066611ebb02a628724dfb653.svn-base 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. package api
  2. import (
  3. "../../routers/restful"
  4. "fmt"
  5. "github.com/Anderson-Lu/gofasion/gofasion"
  6. "github.com/xormplus/xorm"
  7. "sort"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. //包含报表模块前端需要的各种数据格式转换
  13. func praseReportform(sqlnamestr string, parammaps *gofasion.Fasion, tx *xorm.Session) (queryData map[string]interface{}, err error) {
  14. sql, p := restful.GetSqlByNameDBT(sqlnamestr, tx)
  15. s_params := make([]interface{}, 0)
  16. if sql != "" {
  17. paramslist := strings.Split(p, ",")
  18. if len(paramslist) > 0 && p != "" {
  19. for _, value := range paramslist {
  20. s_params = append(s_params, parammaps.Get(strings.Trim(value, " ")).ValueStr())
  21. }
  22. }
  23. }
  24. queryList, err := tx.SQL(sql, s_params...).Query().List()
  25. if err != nil{
  26. return nil,err
  27. }
  28. if len(queryList) == 0{
  29. return nil,nil
  30. }
  31. temstr := ""
  32. //除特殊接口外,去接口名称的前10位做同一类型的转换
  33. switch sqlnamestr {
  34. case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa", "judgenurFTReportDetail":
  35. temstr = sqlnamestr
  36. default:
  37. temstr = sqlnamestr[:10]
  38. }
  39. // 根据名称选择不通类型的转换-(可自动扩展,不需要使用之前的)
  40. switch temstr {
  41. case "getAccurac", "getFeedEff":
  42. queryData, err = getAccuracy(queryList) // 不定参数
  43. case "getprocess":
  44. //queryData, err = getAccuracyV3v1(queryList)
  45. queryData, err = getAccuracyV3(queryList)
  46. case "getHomepro":
  47. queryData, err = getAccuracyV3(queryList)
  48. case "getAccuracyAllHL", "getAccuracyAllQX", "getAccuracyAllJH", "getFeedEffMR", "getFeedEffHL", "getHomepageCB", "getAccuraa":
  49. queryData, err = getAccuracyV2(queryList) //固定维度 日期
  50. case "getMateria":
  51. queryData, err = getAccuracyV4(queryList)
  52. case "getPriceAn":
  53. queryData, err = getAccuracyV5(queryList)
  54. case "getJT1Accu":
  55. queryData, err = getAccuracyV6(queryList) //固定维度 牧场
  56. case "judgenurFT":
  57. queryData, err = getAccuracyV7(queryList)
  58. case "judgenurFTReportDetail":
  59. queryData, err = getAccuracyV8(queryList)
  60. case "downloadPl":
  61. queryData, err = getAccuracyV9(queryList) //投料简打、累加
  62. default:
  63. queryData, err = nil, nil
  64. }
  65. return
  66. }
  67. func getAccuracyV9(queryList []map[string]interface{}) (map[string]interface{}, error) {
  68. queryData := make(map[string]interface{})
  69. chartData := make(map[string]interface{})
  70. mapc3 := make(map[string]interface{})
  71. data2 := []interface{}{}
  72. data1 := []interface{}{}
  73. mapc3["label"] = "车次"
  74. mapc3["prop"] = "projname"
  75. data1 = append(data1, mapc3)
  76. mapc3 = make(map[string]interface{})
  77. mapc3["label"] = "TMR"
  78. mapc3["prop"] = "tmrtname"
  79. data1 = append(data1, mapc3)
  80. mapc3 = make(map[string]interface{})
  81. mapc3["label"] = "时间"
  82. mapc3["prop"] = "plantime"
  83. data1 = append(data1, mapc3)
  84. mapc3 = make(map[string]interface{})
  85. mapc3["label"] = "班组"
  86. mapc3["prop"] = "times"
  87. data1 = append(data1, mapc3)
  88. mapc3 = make(map[string]interface{})
  89. mapc3["label"] = "驾驶员"
  90. mapc3["prop"] = "driver"
  91. data1 = append(data1, mapc3)
  92. mapc3 = make(map[string]interface{})
  93. mapc3["label"] = "日系数比例"
  94. mapc3["prop"] = "rate"
  95. data1 = append(data1, mapc3)
  96. mapc3 = make(map[string]interface{})
  97. mapc3["label"] = "牛头数"
  98. mapc3["prop"] = "feedpcount"
  99. data1 = append(data1, mapc3)
  100. mapc3 = make(map[string]interface{})
  101. mapc3["label"] = "配方模板"
  102. mapc3["prop"] = "templetname"
  103. data1 = append(data1, mapc3)
  104. mapc3 = make(map[string]interface{})
  105. mtem := make(map[interface{}]interface{})
  106. var stem []string
  107. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  108. if _,ok :=mtem[queryList[i]["fname"]];ok {
  109. continue
  110. }
  111. stem = append(stem,queryList[i]["fname"].(string))
  112. mtem[queryList[i]["fname"]] = struct {}{}
  113. }
  114. sort.Strings(stem)
  115. for _, va := range stem {
  116. mapc3["label"] = va
  117. mapc3["prop"] = va
  118. data1 = append(data1, mapc3)
  119. mapc3 = make(map[string]interface{})
  120. }
  121. if queryList[0]["sumlweight"] != nil{
  122. mapc3["label"] = "合计"
  123. mapc3["prop"] = "sumlweight"
  124. }
  125. data1 = append(data1, mapc3)
  126. mapc3 = make(map[string]interface{})
  127. var tem interface{}
  128. mapc2 := make(map[string]interface{})
  129. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  130. if i == 0{
  131. tem = queryList[i]["projname"]
  132. mapc2 = queryList[i]
  133. //for key:= range mtem {
  134. // mapc2[xorm.String(key)] = ""
  135. //}
  136. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  137. }
  138. if tem == queryList[i]["projname"]{
  139. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  140. }else{
  141. data2 = append(data2, mapc2)
  142. tem = queryList[i]["projname"]
  143. mapc2 = queryList[i]
  144. //for key := range mtem {
  145. // mapc2[xorm.String(key)] = ""
  146. //}
  147. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  148. }
  149. }
  150. data2 = append(data2, mapc2)
  151. chartData["data1"] = data1
  152. chartData["data2"] = data2
  153. queryData["list"] = chartData
  154. queryData["code"] = 0
  155. queryData["message"] = "ok"
  156. queryData["data"] = queryList
  157. return queryData, nil
  158. }
  159. func getAccuracyV8(queryList []map[string]interface{}) (map[string]interface{}, error) {
  160. queryData := make(map[string]interface{})
  161. chartData := make(map[string]interface{})
  162. //list := make(map[string]interface{})
  163. data := []interface{}{}
  164. for i := 0; i < len(queryList); i++ {
  165. dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  166. Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
  167. Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
  168. trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
  169. jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
  170. uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
  171. kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  172. adf, _ := strconv.ParseFloat(queryList[i]["adf"].(string), 64)
  173. ca, _ := strconv.ParseFloat(queryList[i]["ca"].(string), 64)
  174. cdry, _ := strconv.ParseFloat(queryList[i]["cdry"].(string), 64)
  175. cad, _ := strconv.ParseFloat(queryList[i]["cad"].(string), 64)
  176. cndf, _ := strconv.ParseFloat(queryList[i]["cndf"].(string), 64)
  177. cp, _ := strconv.ParseFloat(queryList[i]["cp"].(string), 64)
  178. cpd, _ := strconv.ParseFloat(queryList[i]["cpd"].(string), 64)
  179. fat, _ := strconv.ParseFloat(queryList[i]["fat"].(string), 64)
  180. ndf, _ := strconv.ParseFloat(queryList[i]["ndf"].(string), 64)
  181. nm, _ := strconv.ParseFloat(queryList[i]["nm"].(string), 64)
  182. nmd, _ := strconv.ParseFloat(queryList[i]["nmd"].(string), 64)
  183. nuint, _ := strconv.ParseFloat(queryList[i]["nuint"].(string), 64)
  184. p, _ := strconv.ParseFloat(queryList[i]["p"].(string), 64)
  185. pd, _ := strconv.ParseFloat(queryList[i]["pd"].(string), 64)
  186. starch, _ := strconv.ParseFloat(queryList[i]["starch"].(string), 64)
  187. trans4f, _ := strconv.ParseFloat(queryList[i]["trans4f"].(string), 64)
  188. list := make(map[string]interface{})
  189. list["ft"] = dry
  190. list["index"] = "干物质(kg)"
  191. list["tmr"] = TransFloat(dry * Hrate)
  192. list["cyl"] = TransFloat(dry * Srate)
  193. data = append(data, list)
  194. list = make(map[string]interface{})
  195. list["ft"] = jcrate
  196. list["index"] = "粗精比(%)"
  197. list["tmr"] = TransFloat(jcrate * Hrate)
  198. list["cyl"] = TransFloat(jcrate * Srate)
  199. data = append(data, list)
  200. list = make(map[string]interface{})
  201. list["ft"] = uprice
  202. list["index"] = "日粮成本(元)"
  203. list["tmr"] = TransFloat(uprice * Hrate)
  204. list["cyl"] = TransFloat(uprice * Srate)
  205. data = append(data, list)
  206. list = make(map[string]interface{})
  207. list["ft"] = kprice
  208. list["index"] = "公斤奶成本"
  209. list["tmr"] = TransFloat(kprice * Hrate)
  210. list["cyl"] = TransFloat(kprice * Srate)
  211. data = append(data, list)
  212. list = make(map[string]interface{})
  213. list["ft"] = cdry
  214. list["index"] = "粗料中的干物质"
  215. list["tmr"] = TransFloat(cdry * Hrate)
  216. list["cyl"] = TransFloat(cdry * Srate)
  217. data = append(data, list)
  218. list = make(map[string]interface{})
  219. list["ft"] = nm
  220. list["index"] = " 产奶净能(MJ)"
  221. list["tmr"] = TransFloat(nm * Hrate)
  222. list["cyl"] = TransFloat(nm * Srate)
  223. data = append(data, list)
  224. list = make(map[string]interface{})
  225. list["ft"] = nuint
  226. list["index"] = "奶牛能量单位(NND)"
  227. list["tmr"] = TransFloat(nuint * Hrate)
  228. list["cyl"] = TransFloat(nuint * Srate)
  229. data = append(data, list)
  230. list = make(map[string]interface{})
  231. list["ft"] = cp
  232. list["index"] = "粗蛋白(g)"
  233. list["tmr"] = TransFloat(cp * Hrate)
  234. list["cyl"] = TransFloat(cp * Srate)
  235. data = append(data, list)
  236. list = make(map[string]interface{})
  237. list["ft"] = cpd
  238. list["index"] = "粗蛋白(%DM)"
  239. list["tmr"] = TransFloat(cpd * Hrate)
  240. list["cyl"] = TransFloat(cpd * Srate)
  241. data = append(data, list)
  242. list = make(map[string]interface{})
  243. list["ft"] = ca
  244. list["index"] = "钙(g)"
  245. list["tmr"] = TransFloat(ca * Hrate)
  246. list["cyl"] = TransFloat(ca * Srate)
  247. data = append(data, list)
  248. list = make(map[string]interface{})
  249. list["ft"] = p
  250. list["index"] = "磷(g)"
  251. list["tmr"] = TransFloat(p * Hrate)
  252. list["cyl"] = TransFloat(p * Srate)
  253. data = append(data, list)
  254. list = make(map[string]interface{})
  255. list["ft"] = nmd
  256. list["index"] = "产奶净能(Mcal/DM)"
  257. list["tmr"] = TransFloat(nmd * Hrate)
  258. list["cyl"] = TransFloat(nmd * Srate)
  259. data = append(data, list)
  260. list = make(map[string]interface{})
  261. list["ft"] = fat
  262. list["index"] = "脂肪"
  263. list["tmr"] = TransFloat(fat * Hrate)
  264. list["cyl"] = TransFloat(fat * Srate)
  265. data = append(data, list)
  266. list = make(map[string]interface{})
  267. list["ft"] = starch
  268. list["index"] = "淀粉"
  269. list["tmr"] = TransFloat(starch * Hrate)
  270. list["cyl"] = TransFloat(starch * Srate)
  271. data = append(data, list)
  272. list = make(map[string]interface{})
  273. list["ft"] = ndf
  274. list["index"] = "NDF(%DM)"
  275. list["tmr"] = TransFloat(ndf * Hrate)
  276. list["cyl"] = TransFloat(ndf * Srate)
  277. data = append(data, list)
  278. list = make(map[string]interface{})
  279. list["ft"] = cndf
  280. list["index"] = "粗料中的NDF(%DM)"
  281. list["tmr"] = TransFloat(cndf * Hrate)
  282. list["cyl"] = TransFloat(cndf * Srate)
  283. data = append(data, list)
  284. list = make(map[string]interface{})
  285. list["ft"] = adf
  286. list["index"] = " ADF(%DM)"
  287. list["tmr"] = TransFloat(adf * Hrate)
  288. list["cyl"] = TransFloat(adf * Srate)
  289. data = append(data, list)
  290. list = make(map[string]interface{})
  291. list["ft"] = cad
  292. list["index"] = "钙(%DM)"
  293. list["tmr"] = TransFloat(cad * Hrate)
  294. list["cyl"] = TransFloat(cad * Srate)
  295. data = append(data, list)
  296. list = make(map[string]interface{})
  297. list["ft"] = pd
  298. list["index"] = " 磷(%DM)"
  299. list["tmr"] = TransFloat(pd * Hrate)
  300. list["cyl"] = TransFloat(pd * Srate)
  301. data = append(data, list)
  302. list = make(map[string]interface{})
  303. list["ft"] = trans35f
  304. list["index"] = "(3.5)FCR(kg/DM)"
  305. list["tmr"] = TransFloat(trans35f * Hrate)
  306. list["cyl"] = TransFloat(trans35f * Srate)
  307. data = append(data, list)
  308. list = make(map[string]interface{})
  309. list["ft"] = trans4f
  310. list["index"] = "(4.0)FCR(kg/DM)"
  311. list["tmr"] = TransFloat(trans4f * Hrate)
  312. list["cyl"] = TransFloat(trans4f * Srate)
  313. data = append(data, list)
  314. }
  315. chartData["data"] = data
  316. queryData["list"] = chartData
  317. queryData["code"] = 0
  318. queryData["message"] = "ok"
  319. queryData["data"] = queryList
  320. return queryData, nil
  321. }
  322. func TransFloat(flo float64)(float64){
  323. hf,_ :=strconv.ParseFloat(fmt.Sprintf("%.3f", float64(flo)), 64)
  324. return hf
  325. }
  326. func getAccuracyV7(queryList []map[string]interface{}) (map[string]interface{}, error) {
  327. queryData := make(map[string]interface{})
  328. chartData := make(map[string]interface{})
  329. //list := make(map[string]interface{})
  330. data := []interface{}{}
  331. for i := 0; i < len(queryList); i++ {
  332. dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  333. Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
  334. Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
  335. trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
  336. jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
  337. uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
  338. kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  339. list := make(map[string]interface{})
  340. list["tname"] = queryList[i]["tname"]
  341. list["ftid"] = queryList[i]["ftid"]
  342. list["ft"] = dry
  343. list["index"] = "干物质(kg)"
  344. list["tmr"] = TransFloat(dry * Hrate)
  345. list["cyl"] = TransFloat(dry * Srate)
  346. data = append(data, list)
  347. list = make(map[string]interface{})
  348. list["tname"] = queryList[i]["tname"]
  349. list["ftid"] = queryList[i]["ftid"]
  350. list["ft"] = trans35f
  351. list["index"] = "(3.5)FCR(kg/DM)"
  352. list["tmr"] = TransFloat(trans35f * Hrate)
  353. list["cyl"] = TransFloat(trans35f * Srate)
  354. data = append(data, list)
  355. list = make(map[string]interface{})
  356. list["tname"] = queryList[i]["tname"]
  357. list["ftid"] = queryList[i]["ftid"]
  358. list["ft"] = jcrate
  359. list["index"] = "粗精比(%)"
  360. list["tmr"] = TransFloat(jcrate * Hrate)
  361. list["cyl"] = TransFloat(jcrate * Srate)
  362. data = append(data, list)
  363. list = make(map[string]interface{})
  364. list["tname"] = queryList[i]["tname"]
  365. list["ftid"] = queryList[i]["ftid"]
  366. list["ft"] = uprice
  367. list["index"] = "日粮成本(元)"
  368. list["tmr"] = TransFloat(uprice * Hrate)
  369. list["cyl"] = TransFloat(uprice * Srate)
  370. data = append(data, list)
  371. list = make(map[string]interface{})
  372. list["tname"] = queryList[i]["tname"]
  373. list["ftid"] = queryList[i]["ftid"]
  374. list["ft"] = kprice
  375. list["index"] = "公斤奶成本"
  376. list["tmr"] = TransFloat(kprice * Hrate)
  377. list["cyl"] = TransFloat(kprice * Srate)
  378. data = append(data, list)
  379. }
  380. chartData["data"] = data
  381. queryData["list"] = chartData
  382. queryData["code"] = 0
  383. queryData["message"] = "ok"
  384. queryData["data"] = queryList
  385. return queryData, nil
  386. }
  387. func getAccuracyV6(queryList []map[string]interface{}) (map[string]interface{}, error) {
  388. queryData := make(map[string]interface{})
  389. chartData := make(map[string]interface{})
  390. data := []interface{}{}
  391. data1 := []interface{}{}
  392. data2 := []interface{}{}
  393. data3 := []interface{}{}
  394. data4 := []interface{}{}
  395. for i := 0; i < len(queryList); i++ {
  396. data = append(data, queryList[i]["牧场"])
  397. data1 = append(data1, queryList[i]["field1"])
  398. data2 = append(data2, queryList[i]["field2"])
  399. data3 = append(data3, queryList[i]["field3"])
  400. data4 = append(data4, queryList[i]["field4"])
  401. }
  402. chartData["data1"] = data
  403. chartData["data2"] = data1
  404. chartData["data3"] = data2
  405. chartData["data4"] = data3
  406. chartData["data5"] = data4
  407. queryData["list"] = chartData
  408. queryData["code"] = 0
  409. queryData["message"] = "ok"
  410. queryData["data"] = queryList
  411. return queryData, nil
  412. }
  413. func getAccuracyV5(queryList []map[string]interface{}) (map[string]interface{}, error) {
  414. queryData := make(map[string]interface{})
  415. chartData := make(map[string]interface{})
  416. datamap1 := make(map[string]interface{})
  417. datamap2 := make(map[string]interface{})
  418. temsmap := make(map[interface{}]interface{})
  419. mapc2 := make(map[interface{}]interface{})
  420. data3 := []interface{}{}
  421. datamap2child := make(map[string]interface{})
  422. data2 := []interface{}{}
  423. data1 := []interface{}{}
  424. var dtem interface{}
  425. var temstr interface{}
  426. var typestr interface{}
  427. count2 := 0
  428. a := 0
  429. for i := 0; i < len(queryList); i++ {
  430. if i == 0 {
  431. temstr = queryList[i]["fname"]
  432. typestr = queryList[i]["typestr"]
  433. }
  434. if temstr == queryList[i]["fname"] {
  435. temsmap[queryList[i]["feedname"]] = 1
  436. }
  437. if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
  438. mapc2[queryList[i]["feedname"]] = count2
  439. mapc2[count2] = queryList[i]["feedname"]
  440. count2++
  441. }
  442. }
  443. //for i := 0; i<count2 ; i++ {
  444. // reslist := make([]map[string]interface{},1)
  445. // res := make(map[string]interface{})
  446. // res["fname"] = "分界线"
  447. // res["feedname"] = mapc2[i]
  448. // res["饲料名称"] = mapc2[i]
  449. // reslist[0] = res
  450. // queryList = append(reslist,queryList...)
  451. //}
  452. for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
  453. if _, ok := temsmap[mapc2[i]]; !ok {
  454. reslist := make([]map[string]interface{}, 1)
  455. res := make(map[string]interface{})
  456. res["fname"] = temstr
  457. res["feedname"] = mapc2[i]
  458. res["饲料名称"] = mapc2[i]
  459. res["typestr"] = typestr
  460. reslist[0] = res
  461. queryList = append(reslist, queryList...)
  462. }
  463. }
  464. for i := 0; i < len(queryList); i++ {
  465. a = mapc2[queryList[i]["feedname"]].(int) * 2
  466. if i == 0 {
  467. datamap2["label"] = "饲料名称"
  468. switch queryList[i]["typestr"].(type) {
  469. case string:
  470. datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
  471. default:
  472. datamap2child["label"] = "/饲料参数"
  473. }
  474. datamap2child["prop"] = "A"
  475. data3 = append(data3, datamap2child)
  476. datamap2["children"] = data3
  477. data2 = append(data2, datamap2)
  478. data3 = []interface{}{}
  479. datamap2child = make(map[string]interface{})
  480. datamap2 = make(map[string]interface{})
  481. dtem = queryList[i]["fname"]
  482. }
  483. if dtem != queryList[i]["fname"] && i != 0 {
  484. data1 = append(data1, datamap1)
  485. dtem = queryList[i]["fname"]
  486. datamap1 = make(map[string]interface{})
  487. }
  488. if queryList[i]["fname"] == temstr {
  489. datamap2["label"] = queryList[i]["feedname"]
  490. datamap2child["label"] = "理论"
  491. datamap2child["prop"] = "a" + strconv.Itoa(a)
  492. data3 = append(data3, datamap2child)
  493. datamap2child = make(map[string]interface{})
  494. datamap2child["label"] = "实际"
  495. datamap2child["prop"] = "a" + strconv.Itoa(a+1)
  496. data3 = append(data3, datamap2child)
  497. datamap2child = make(map[string]interface{})
  498. datamap2["children"] = data3
  499. data2 = append(data2, datamap2)
  500. data3 = []interface{}{}
  501. datamap2 = make(map[string]interface{})
  502. datamap2child = make(map[string]interface{})
  503. }
  504. datamap1["A"] = queryList[i]["fname"]
  505. datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
  506. datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
  507. datamap2["label"] = queryList[i]["饲料名称"]
  508. a = a + 2
  509. }
  510. data1 = append(data1, datamap1)
  511. chartData["data1"] = data1
  512. chartData["data2"] = data2
  513. queryData["list"] = chartData
  514. queryData["code"] = 0
  515. queryData["message"] = "ok"
  516. queryData["data"] = queryList
  517. return queryData, nil
  518. }
  519. func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{}, error) {
  520. queryData := make(map[string]interface{})
  521. chartData := make(map[string]interface{})
  522. datamap1 := make(map[string]interface{})
  523. datamap2 := make(map[string]interface{})
  524. temsmap := make(map[interface{}]interface{})
  525. mapc2 := make(map[interface{}]interface{})
  526. mapc3 := make(map[interface{}]interface{})
  527. data3 := []interface{}{}
  528. datamap2child := make(map[string]interface{})
  529. data2 := []interface{}{}
  530. data1 := []interface{}{}
  531. a := 0
  532. var dtem interface{}
  533. count2 := 0
  534. var tem interface{}
  535. var temstr interface{}
  536. var typestr interface{}
  537. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  538. if i == 0 {
  539. temstr = queryList[i]["fname"]
  540. typestr = queryList[i]["typestr"]
  541. }
  542. if temstr == queryList[i]["fname"] {
  543. temsmap[queryList[i]["feedname"]] = 1
  544. }
  545. if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
  546. mapc2[queryList[i]["feedname"]] = count2 // 编号
  547. mapc2[count2] = queryList[i]["feedname"]
  548. count2++
  549. }
  550. }
  551. for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
  552. if _, ok := temsmap[mapc2[i]]; !ok {
  553. reslist := make([]map[string]interface{}, 1)
  554. res := make(map[string]interface{})
  555. res["fname"] = temstr
  556. res["feedname"] = mapc2[i]
  557. res["饲料名称"] = mapc2[i]
  558. res["typestr"] = typestr
  559. reslist[0] = res
  560. queryList = append(reslist, queryList...)
  561. }
  562. }
  563. //for i := 0; i<count2 ; i++ {
  564. // reslist := make([]map[string]interface{},1)
  565. // res := make(map[string]interface{})
  566. // res["fname"] = "分界线"
  567. // res["feedname"] = mapc2[i]
  568. // res["饲料名称"] = mapc2[i]
  569. // res["typestr"] =typestr
  570. // reslist[0] = res
  571. // queryList = append(reslist,queryList...)
  572. //}
  573. for i := 0; i < len(queryList); i++ {
  574. if i == 0 {
  575. tem = queryList[i]["fname"]
  576. }
  577. if queryList[i]["fname"] == tem {
  578. mapc3[queryList[i]["feedname"]] = i
  579. }
  580. }
  581. for i := 0; i < len(queryList); i++ {
  582. a = mapc2[queryList[i]["feedname"]].(int) * 4
  583. if i == 0 {
  584. datamap2["label"] = "饲料名称"
  585. switch queryList[i]["typestr"].(type) {
  586. case string:
  587. datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
  588. default:
  589. datamap2child["label"] = "/饲料参数"
  590. }
  591. datamap2child["prop"] = "A"
  592. data3 = append(data3, datamap2child)
  593. datamap2["children"] = data3
  594. data2 = append(data2, datamap2)
  595. data3 = []interface{}{}
  596. datamap2child = make(map[string]interface{})
  597. datamap2 = make(map[string]interface{})
  598. dtem = queryList[i]["fname"]
  599. }
  600. if dtem != queryList[i]["fname"] && i != 0 {
  601. data1 = append(data1, datamap1)
  602. dtem = queryList[i]["fname"]
  603. datamap1 = make(map[string]interface{})
  604. }
  605. if queryList[i]["fname"] == temstr {
  606. datamap2["label"] = queryList[i]["feedname"]
  607. datamap2child["label"] = "理论"
  608. datamap2child["prop"] = "a" + strconv.Itoa(a)
  609. data3 = append(data3, datamap2child)
  610. datamap2child = make(map[string]interface{})
  611. datamap2child["label"] = "实际"
  612. datamap2child["prop"] = "a" + strconv.Itoa(a+1)
  613. data3 = append(data3, datamap2child)
  614. datamap2child = make(map[string]interface{})
  615. datamap2child["label"] = "误差值"
  616. datamap2child["prop"] = "a" + strconv.Itoa(a+2)
  617. data3 = append(data3, datamap2child)
  618. datamap2child = make(map[string]interface{})
  619. datamap2child["label"] = "误差率"
  620. datamap2child["prop"] = "a" + strconv.Itoa(a+3)
  621. data3 = append(data3, datamap2child)
  622. datamap2["children"] = data3
  623. data2 = append(data2, datamap2)
  624. data3 = []interface{}{}
  625. datamap2 = make(map[string]interface{})
  626. datamap2child = make(map[string]interface{})
  627. }
  628. datamap1["A"] = queryList[i]["fname"]
  629. datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
  630. datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
  631. datamap1["a"+strconv.Itoa(a+2)] = queryList[i]["diff"]
  632. datamap1["a"+strconv.Itoa(a+3)] = queryList[i]["diffrate"]
  633. datamap2["label"] = queryList[i]["饲料名称"]
  634. }
  635. data1 = append(data1, datamap1)
  636. chartData["data1"] = data1
  637. chartData["data2"] = data2
  638. queryData["list"] = chartData
  639. queryData["code"] = 0
  640. queryData["message"] = "ok"
  641. queryData["data"] = queryList
  642. return queryData, nil
  643. }
  644. func getAccuracyV3(queryList []map[string]interface{}) (map[string]interface{}, error) {
  645. queryData := make(map[string]interface{})
  646. chartData := make(map[string]interface{})
  647. data := []interface{}{}
  648. data1 := []interface{}{}
  649. data2 := []interface{}{}
  650. data3 := []interface{}{}
  651. data4 := []interface{}{}
  652. datatem := []interface{}{}
  653. t1 := make(map[interface{}]string, 0)
  654. for i := 0; i < len(queryList); i++ {
  655. data = append(data, queryList[i]["mtime"])
  656. data1 = append(data1, queryList[i]["lweight"])
  657. data2 = append(data2, queryList[i]["weight"])
  658. //data3 = append(data3, queryList[i]["field3"])
  659. //data4 = append(data4, queryList[i]["field4"])
  660. if _, ok := t1[queryList[i]["id"]]; !ok {
  661. datatem = append(datatem, queryList[i]["startstime"], queryList[i]["lastactualweight"])
  662. data3 = append(data3, datatem)
  663. datatem = []interface{}{}
  664. datatem = append(datatem, queryList[i]["intime"], queryList[i]["actualweight"])
  665. data3 = append(data3, datatem)
  666. datatem = []interface{}{}
  667. }
  668. t1[queryList[i]["id"]] = "1"
  669. }
  670. chartData["data1"] = data
  671. chartData["data2"] = data1
  672. chartData["data3"] = data2
  673. chartData["data4"] = data3
  674. chartData["data5"] = data4
  675. queryData["list"] = chartData
  676. queryData["code"] = 0
  677. queryData["message"] = "ok"
  678. queryData["data"] = queryList
  679. return queryData, nil
  680. }
  681. func getAccuracyV2(queryList []map[string]interface{}) (map[string]interface{}, error) {
  682. queryData := make(map[string]interface{})
  683. chartData := make(map[string]interface{})
  684. data := []interface{}{}
  685. data1 := []interface{}{}
  686. data2 := []interface{}{}
  687. data3 := []interface{}{}
  688. data4 := []interface{}{}
  689. for i := 0; i < len(queryList); i++ {
  690. data = append(data, queryList[i]["日期"])
  691. data1 = append(data1, queryList[i]["field1"])
  692. data2 = append(data2, queryList[i]["field2"])
  693. data3 = append(data3, queryList[i]["field3"])
  694. data4 = append(data4, queryList[i]["field4"])
  695. }
  696. chartData["data1"] = data
  697. chartData["data2"] = data1
  698. chartData["data3"] = data2
  699. chartData["data4"] = data3
  700. chartData["data5"] = data4
  701. queryData["list"] = chartData
  702. queryData["code"] = 0
  703. queryData["message"] = "ok"
  704. queryData["data"] = queryList
  705. return queryData, nil
  706. }
  707. func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, error) {
  708. queryData := make(map[string]interface{})
  709. chartData := make(map[string]interface{})
  710. t1 := make(map[interface{}]interface{}, 0)
  711. t2 := make(map[interface{}]interface{}, 0)
  712. data := make(map[string][]interface{}, 0)
  713. t := make([]map[string][]interface{}, 0)
  714. e1 := []interface{}{}
  715. e2 := []string{}
  716. for _, value := range queryList {
  717. if _, ok := t1[value["名称"]]; !ok {
  718. e1 = append(e1, value["名称"])
  719. }
  720. if _, ok := t2[value["日期"]]; !ok {
  721. switch value["日期"].(type) {
  722. case string:
  723. e2 = append(e2, value["日期"].(string))
  724. }
  725. }
  726. t1[value["名称"]] = value["名称"]
  727. t2[value["日期"]] = value["日期"]
  728. }
  729. sort.Strings(e2)
  730. var b interface{}
  731. a := 0
  732. for i := 0; i < len(queryList); i++ {
  733. if i == 0 {
  734. b = queryList[i]["名称"]
  735. }
  736. if b != queryList[i]["名称"] {
  737. if a < len(e2)-1 {
  738. for k := 0; k < len(e2)-a; k++ {
  739. data["data"] = append(data["data"], "")
  740. }
  741. }
  742. t = append(t, data)
  743. data = make(map[string][]interface{}, 0)
  744. b = queryList[i]["名称"]
  745. a = 0
  746. }
  747. switch queryList[i]["日期"].(type) {
  748. case string:
  749. dates, _ := time.Parse("2006-01-02", queryList[i]["日期"].(string))
  750. dates1 := ""
  751. if a < len(e2) -1{
  752. dates1 = e2[a]
  753. }else {
  754. dates1 = e2[len(e2)-1]
  755. }
  756. if a < len(e2)-1 {
  757. if e2[a] != queryList[i]["日期"].(string) {
  758. if e2[a] < queryList[i]["日期"].(string) {
  759. dates1 = queryList[i]["日期"].(string)
  760. dates, _ = time.Parse("2006-01-02", e2[a])
  761. for ; a < len(e2)-1; a++ {
  762. if e2[a] >= queryList[i]["日期"].(string) {
  763. break
  764. }
  765. }
  766. }
  767. for ; dates.Format("2006-01-02") < dates1; dates = dates.Add(24 * time.Hour) {
  768. data["data"] = append(data["data"], "")
  769. }
  770. }
  771. }
  772. }
  773. data["data"] = append(data["data"], queryList[i]["准确率"])
  774. a++
  775. }
  776. if a < len(e2)-1 {
  777. for k := 0; k < len(e2)-a; k++ {
  778. data["data"] = append(data["data"], "")
  779. }
  780. }
  781. t = append(t, data)
  782. chartData["data1"] = e1
  783. chartData["data2"] = e2
  784. chartData["data3"] = t
  785. queryData["list"] = chartData
  786. queryData["code"] = 0
  787. queryData["message"] = "ok"
  788. queryData["data"] = queryList
  789. return queryData, nil
  790. }