8814e272cf8c2f2c019462555469a98e0c48e063.svn-base 31 KB

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