730265d8864698e68b59f4f582dce857c3b81bb6.svn-base 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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. if queryList[0]["sumlweight"] != nil{
  230. mapc3["label"] = "合计"
  231. mapc3["prop"] = "sumlweight"
  232. }
  233. data1 = append(data1, mapc3)
  234. mapc3 = make(map[string]interface{})
  235. var tem interface{}
  236. mapc2 := make(map[string]interface{})
  237. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  238. if i == 0{
  239. tem = queryList[i]["projname"]
  240. mapc2 = queryList[i]
  241. //for key:= range mtem {
  242. // mapc2[xorm.String(key)] = ""
  243. //}
  244. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  245. }
  246. if tem == queryList[i]["projname"]{
  247. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  248. }else{
  249. data2 = append(data2, mapc2)
  250. tem = queryList[i]["projname"]
  251. mapc2 = queryList[i]
  252. //for key := range mtem {
  253. // mapc2[xorm.String(key)] = ""
  254. //}
  255. mapc2[xorm.String(queryList[i]["fname"])] = queryList[i]["lweight"]
  256. }
  257. }
  258. data2 = append(data2, mapc2)
  259. chartData["data1"] = data1
  260. chartData["data2"] = data2
  261. queryData["list"] = chartData
  262. queryData["code"] = 0
  263. queryData["message"] = "ok"
  264. queryData["data"] = queryList
  265. return queryData, nil
  266. }
  267. func getAccuracyV8(queryList []map[string]interface{}) (map[string]interface{}, error) {
  268. queryData := make(map[string]interface{})
  269. chartData := make(map[string]interface{})
  270. //list := make(map[string]interface{})
  271. data := []interface{}{}
  272. for i := 0; i < len(queryList); i++ {
  273. dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  274. Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
  275. Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
  276. trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
  277. jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
  278. uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
  279. kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  280. adf, _ := strconv.ParseFloat(queryList[i]["adf"].(string), 64)
  281. ca, _ := strconv.ParseFloat(queryList[i]["ca"].(string), 64)
  282. cdry, _ := strconv.ParseFloat(queryList[i]["cdry"].(string), 64)
  283. cad, _ := strconv.ParseFloat(queryList[i]["cad"].(string), 64)
  284. cndf, _ := strconv.ParseFloat(queryList[i]["cndf"].(string), 64)
  285. cp, _ := strconv.ParseFloat(queryList[i]["cp"].(string), 64)
  286. cpd, _ := strconv.ParseFloat(queryList[i]["cpd"].(string), 64)
  287. fat, _ := strconv.ParseFloat(queryList[i]["fat"].(string), 64)
  288. ndf, _ := strconv.ParseFloat(queryList[i]["ndf"].(string), 64)
  289. nm, _ := strconv.ParseFloat(queryList[i]["nm"].(string), 64)
  290. nmd, _ := strconv.ParseFloat(queryList[i]["nmd"].(string), 64)
  291. nuint, _ := strconv.ParseFloat(queryList[i]["nuint"].(string), 64)
  292. p, _ := strconv.ParseFloat(queryList[i]["p"].(string), 64)
  293. pd, _ := strconv.ParseFloat(queryList[i]["pd"].(string), 64)
  294. starch, _ := strconv.ParseFloat(queryList[i]["starch"].(string), 64)
  295. trans4f, _ := strconv.ParseFloat(queryList[i]["trans4f"].(string), 64)
  296. list := make(map[string]interface{})
  297. list["ft"] = dry
  298. list["index"] = "干物质(kg)"
  299. list["tmr"] = TransFloat(dry * Hrate)
  300. list["cyl"] = TransFloat(dry * Srate)
  301. data = append(data, list)
  302. list = make(map[string]interface{})
  303. list["ft"] = jcrate
  304. list["index"] = "粗精比(%)"
  305. list["tmr"] = TransFloat(jcrate * Hrate)
  306. list["cyl"] = TransFloat(jcrate * Srate)
  307. data = append(data, list)
  308. list = make(map[string]interface{})
  309. list["ft"] = uprice
  310. list["index"] = "日粮成本(元)"
  311. list["tmr"] = TransFloat(uprice * Hrate)
  312. list["cyl"] = TransFloat(uprice * Srate)
  313. data = append(data, list)
  314. list = make(map[string]interface{})
  315. list["ft"] = kprice
  316. list["index"] = "公斤奶成本"
  317. list["tmr"] = TransFloat(kprice * Hrate)
  318. list["cyl"] = TransFloat(kprice * Srate)
  319. data = append(data, list)
  320. list = make(map[string]interface{})
  321. list["ft"] = cdry
  322. list["index"] = "粗料中的干物质"
  323. list["tmr"] = TransFloat(cdry * Hrate)
  324. list["cyl"] = TransFloat(cdry * Srate)
  325. data = append(data, list)
  326. list = make(map[string]interface{})
  327. list["ft"] = nm
  328. list["index"] = " 产奶净能(MJ)"
  329. list["tmr"] = TransFloat(nm * Hrate)
  330. list["cyl"] = TransFloat(nm * Srate)
  331. data = append(data, list)
  332. list = make(map[string]interface{})
  333. list["ft"] = nuint
  334. list["index"] = "奶牛能量单位(NND)"
  335. list["tmr"] = TransFloat(nuint * Hrate)
  336. list["cyl"] = TransFloat(nuint * Srate)
  337. data = append(data, list)
  338. list = make(map[string]interface{})
  339. list["ft"] = cp
  340. list["index"] = "粗蛋白(g)"
  341. list["tmr"] = TransFloat(cp * Hrate)
  342. list["cyl"] = TransFloat(cp * Srate)
  343. data = append(data, list)
  344. list = make(map[string]interface{})
  345. list["ft"] = cpd
  346. list["index"] = "粗蛋白(%DM)"
  347. list["tmr"] = TransFloat(cpd * Hrate)
  348. list["cyl"] = TransFloat(cpd * Srate)
  349. data = append(data, list)
  350. list = make(map[string]interface{})
  351. list["ft"] = ca
  352. list["index"] = "钙(g)"
  353. list["tmr"] = TransFloat(ca * Hrate)
  354. list["cyl"] = TransFloat(ca * Srate)
  355. data = append(data, list)
  356. list = make(map[string]interface{})
  357. list["ft"] = p
  358. list["index"] = "磷(g)"
  359. list["tmr"] = TransFloat(p * Hrate)
  360. list["cyl"] = TransFloat(p * Srate)
  361. data = append(data, list)
  362. list = make(map[string]interface{})
  363. list["ft"] = nmd
  364. list["index"] = "产奶净能(Mcal/DM)"
  365. list["tmr"] = TransFloat(nmd * Hrate)
  366. list["cyl"] = TransFloat(nmd * Srate)
  367. data = append(data, list)
  368. list = make(map[string]interface{})
  369. list["ft"] = fat
  370. list["index"] = "脂肪"
  371. list["tmr"] = TransFloat(fat * Hrate)
  372. list["cyl"] = TransFloat(fat * Srate)
  373. data = append(data, list)
  374. list = make(map[string]interface{})
  375. list["ft"] = starch
  376. list["index"] = "淀粉"
  377. list["tmr"] = TransFloat(starch * Hrate)
  378. list["cyl"] = TransFloat(starch * Srate)
  379. data = append(data, list)
  380. list = make(map[string]interface{})
  381. list["ft"] = ndf
  382. list["index"] = "NDF(%DM)"
  383. list["tmr"] = TransFloat(ndf * Hrate)
  384. list["cyl"] = TransFloat(ndf * Srate)
  385. data = append(data, list)
  386. list = make(map[string]interface{})
  387. list["ft"] = cndf
  388. list["index"] = "粗料中的NDF(%DM)"
  389. list["tmr"] = TransFloat(cndf * Hrate)
  390. list["cyl"] = TransFloat(cndf * Srate)
  391. data = append(data, list)
  392. list = make(map[string]interface{})
  393. list["ft"] = adf
  394. list["index"] = " ADF(%DM)"
  395. list["tmr"] = TransFloat(adf * Hrate)
  396. list["cyl"] = TransFloat(adf * Srate)
  397. data = append(data, list)
  398. list = make(map[string]interface{})
  399. list["ft"] = cad
  400. list["index"] = "钙(%DM)"
  401. list["tmr"] = TransFloat(cad * Hrate)
  402. list["cyl"] = TransFloat(cad * Srate)
  403. data = append(data, list)
  404. list = make(map[string]interface{})
  405. list["ft"] = pd
  406. list["index"] = " 磷(%DM)"
  407. list["tmr"] = TransFloat(pd * Hrate)
  408. list["cyl"] = TransFloat(pd * Srate)
  409. data = append(data, list)
  410. list = make(map[string]interface{})
  411. list["ft"] = trans35f
  412. list["index"] = "(3.5)FCR(kg/DM)"
  413. list["tmr"] = TransFloat(trans35f * Hrate)
  414. list["cyl"] = TransFloat(trans35f * Srate)
  415. data = append(data, list)
  416. list = make(map[string]interface{})
  417. list["ft"] = trans4f
  418. list["index"] = "(4.0)FCR(kg/DM)"
  419. list["tmr"] = TransFloat(trans4f * Hrate)
  420. list["cyl"] = TransFloat(trans4f * Srate)
  421. data = append(data, list)
  422. }
  423. chartData["data"] = data
  424. queryData["list"] = chartData
  425. queryData["code"] = 0
  426. queryData["message"] = "ok"
  427. queryData["data"] = queryList
  428. return queryData, nil
  429. }
  430. func TransFloat(flo float64)(float64){
  431. hf,_ :=strconv.ParseFloat(fmt.Sprintf("%.3f", float64(flo)), 64)
  432. return hf
  433. }
  434. func getAccuracyV7(queryList []map[string]interface{}) (map[string]interface{}, error) {
  435. queryData := make(map[string]interface{})
  436. chartData := make(map[string]interface{})
  437. //list := make(map[string]interface{})
  438. data := []interface{}{}
  439. for i := 0; i < len(queryList); i++ {
  440. dry, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  441. Hrate, _ := strconv.ParseFloat(queryList[i]["Hrate"].(string), 64)
  442. Srate, _ := strconv.ParseFloat(queryList[i]["Srate"].(string), 64)
  443. trans35f, _ := strconv.ParseFloat(queryList[i]["trans35f"].(string), 64)
  444. jcrate, _ := strconv.ParseFloat(queryList[i]["jcrate"].(string), 64)
  445. uprice, _ := strconv.ParseFloat(queryList[i]["uprice"].(string), 64)
  446. kprice, _ := strconv.ParseFloat(queryList[i]["dry"].(string), 64)
  447. list := make(map[string]interface{})
  448. list["tname"] = queryList[i]["tname"]
  449. list["ftid"] = queryList[i]["ftid"]
  450. list["ft"] = dry
  451. list["index"] = "干物质(kg)"
  452. list["tmr"] = TransFloat(dry * Hrate)
  453. list["cyl"] = TransFloat(dry * Srate)
  454. data = append(data, list)
  455. list = make(map[string]interface{})
  456. list["tname"] = queryList[i]["tname"]
  457. list["ftid"] = queryList[i]["ftid"]
  458. list["ft"] = trans35f
  459. list["index"] = "(3.5)FCR(kg/DM)"
  460. list["tmr"] = TransFloat(trans35f * Hrate)
  461. list["cyl"] = TransFloat(trans35f * Srate)
  462. data = append(data, list)
  463. list = make(map[string]interface{})
  464. list["tname"] = queryList[i]["tname"]
  465. list["ftid"] = queryList[i]["ftid"]
  466. list["ft"] = jcrate
  467. list["index"] = "粗精比(%)"
  468. list["tmr"] = TransFloat(jcrate * Hrate)
  469. list["cyl"] = TransFloat(jcrate * Srate)
  470. data = append(data, list)
  471. list = make(map[string]interface{})
  472. list["tname"] = queryList[i]["tname"]
  473. list["ftid"] = queryList[i]["ftid"]
  474. list["ft"] = uprice
  475. list["index"] = "日粮成本(元)"
  476. list["tmr"] = TransFloat(uprice * Hrate)
  477. list["cyl"] = TransFloat(uprice * Srate)
  478. data = append(data, list)
  479. list = make(map[string]interface{})
  480. list["tname"] = queryList[i]["tname"]
  481. list["ftid"] = queryList[i]["ftid"]
  482. list["ft"] = kprice
  483. list["index"] = "公斤奶成本"
  484. list["tmr"] = TransFloat(kprice * Hrate)
  485. list["cyl"] = TransFloat(kprice * Srate)
  486. data = append(data, list)
  487. }
  488. chartData["data"] = data
  489. queryData["list"] = chartData
  490. queryData["code"] = 0
  491. queryData["message"] = "ok"
  492. queryData["data"] = queryList
  493. return queryData, nil
  494. }
  495. func getAccuracyV6(queryList []map[string]interface{}) (map[string]interface{}, error) {
  496. queryData := make(map[string]interface{})
  497. chartData := make(map[string]interface{})
  498. data := []interface{}{}
  499. data1 := []interface{}{}
  500. data2 := []interface{}{}
  501. data3 := []interface{}{}
  502. data4 := []interface{}{}
  503. for i := 0; i < len(queryList); i++ {
  504. data = append(data, queryList[i]["牧场"])
  505. data1 = append(data1, queryList[i]["field1"])
  506. data2 = append(data2, queryList[i]["field2"])
  507. data3 = append(data3, queryList[i]["field3"])
  508. data4 = append(data4, queryList[i]["field4"])
  509. }
  510. chartData["data1"] = data
  511. chartData["data2"] = data1
  512. chartData["data3"] = data2
  513. chartData["data4"] = data3
  514. chartData["data5"] = data4
  515. queryData["list"] = chartData
  516. queryData["code"] = 0
  517. queryData["message"] = "ok"
  518. queryData["data"] = queryList
  519. return queryData, nil
  520. }
  521. func getAccuracyV5(queryList []map[string]interface{}) (map[string]interface{}, error) {
  522. queryData := make(map[string]interface{})
  523. chartData := make(map[string]interface{})
  524. datamap1 := make(map[string]interface{})
  525. datamap2 := make(map[string]interface{})
  526. temsmap := make(map[interface{}]interface{})
  527. mapc2 := make(map[interface{}]interface{})
  528. data3 := []interface{}{}
  529. datamap2child := make(map[string]interface{})
  530. data2 := []interface{}{}
  531. data1 := []interface{}{}
  532. var dtem interface{}
  533. var temstr interface{}
  534. var typestr interface{}
  535. count2 := 0
  536. a := 0
  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. // reslist := make([]map[string]interface{},1)
  553. // res := make(map[string]interface{})
  554. // res["fname"] = "分界线"
  555. // res["feedname"] = mapc2[i]
  556. // res["饲料名称"] = mapc2[i]
  557. // reslist[0] = res
  558. // queryList = append(reslist,queryList...)
  559. //}
  560. for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
  561. if _, ok := temsmap[mapc2[i]]; !ok {
  562. reslist := make([]map[string]interface{}, 1)
  563. res := make(map[string]interface{})
  564. res["fname"] = temstr
  565. res["feedname"] = mapc2[i]
  566. res["饲料名称"] = mapc2[i]
  567. res["typestr"] = typestr
  568. reslist[0] = res
  569. queryList = append(reslist, queryList...)
  570. }
  571. }
  572. for i := 0; i < len(queryList); i++ {
  573. a = mapc2[queryList[i]["feedname"]].(int) * 2
  574. if i == 0 {
  575. datamap2["label"] = "饲料名称"
  576. switch queryList[i]["typestr"].(type) {
  577. case string:
  578. datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
  579. default:
  580. datamap2child["label"] = "/饲料参数"
  581. }
  582. datamap2child["prop"] = "A"
  583. data3 = append(data3, datamap2child)
  584. datamap2["children"] = data3
  585. data2 = append(data2, datamap2)
  586. data3 = []interface{}{}
  587. datamap2child = make(map[string]interface{})
  588. datamap2 = make(map[string]interface{})
  589. dtem = queryList[i]["fname"]
  590. }
  591. if dtem != queryList[i]["fname"] && i != 0 {
  592. data1 = append(data1, datamap1)
  593. dtem = queryList[i]["fname"]
  594. datamap1 = make(map[string]interface{})
  595. }
  596. if queryList[i]["fname"] == temstr {
  597. datamap2["label"] = queryList[i]["feedname"]
  598. datamap2child["label"] = "理论"
  599. datamap2child["prop"] = "a" + strconv.Itoa(a)
  600. data3 = append(data3, datamap2child)
  601. datamap2child = make(map[string]interface{})
  602. datamap2child["label"] = "实际"
  603. datamap2child["prop"] = "a" + strconv.Itoa(a+1)
  604. data3 = append(data3, datamap2child)
  605. datamap2child = make(map[string]interface{})
  606. datamap2["children"] = data3
  607. data2 = append(data2, datamap2)
  608. data3 = []interface{}{}
  609. datamap2 = make(map[string]interface{})
  610. datamap2child = make(map[string]interface{})
  611. }
  612. datamap1["A"] = queryList[i]["fname"]
  613. datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
  614. datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
  615. datamap2["label"] = queryList[i]["饲料名称"]
  616. a = a + 2
  617. }
  618. data1 = append(data1, datamap1)
  619. chartData["data1"] = data1
  620. chartData["data2"] = data2
  621. queryData["list"] = chartData
  622. queryData["code"] = 0
  623. queryData["message"] = "ok"
  624. queryData["data"] = queryList
  625. return queryData, nil
  626. }
  627. func getAccuracyV4(queryList []map[string]interface{}) (map[string]interface{}, error) {
  628. queryData := make(map[string]interface{})
  629. chartData := make(map[string]interface{})
  630. datamap1 := make(map[string]interface{})
  631. datamap2 := make(map[string]interface{})
  632. temsmap := make(map[interface{}]interface{})
  633. mapc2 := make(map[interface{}]interface{})
  634. mapc3 := make(map[interface{}]interface{})
  635. data3 := []interface{}{}
  636. datamap2child := make(map[string]interface{})
  637. data2 := []interface{}{}
  638. data1 := []interface{}{}
  639. a := 0
  640. var dtem interface{}
  641. count2 := 0
  642. var tem interface{}
  643. var temstr interface{}
  644. var typestr interface{}
  645. for i := 0; i < len(queryList); i++ { // 获取所有饲料种类
  646. if i == 0 {
  647. temstr = queryList[i]["fname"]
  648. typestr = queryList[i]["typestr"]
  649. }
  650. if temstr == queryList[i]["fname"] {
  651. temsmap[queryList[i]["feedname"]] = 1
  652. }
  653. if _, ok := mapc2[queryList[i]["feedname"]]; !ok {
  654. mapc2[queryList[i]["feedname"]] = count2 // 编号
  655. mapc2[count2] = queryList[i]["feedname"]
  656. count2++
  657. }
  658. }
  659. for i := 0; i < count2; i++ { // 将所有饲料种类新增为第一行 测试
  660. if _, ok := temsmap[mapc2[i]]; !ok {
  661. reslist := make([]map[string]interface{}, 1)
  662. res := make(map[string]interface{})
  663. res["fname"] = temstr
  664. res["feedname"] = mapc2[i]
  665. res["饲料名称"] = mapc2[i]
  666. res["typestr"] = typestr
  667. reslist[0] = res
  668. queryList = append(reslist, queryList...)
  669. }
  670. }
  671. //for i := 0; i<count2 ; i++ {
  672. // reslist := make([]map[string]interface{},1)
  673. // res := make(map[string]interface{})
  674. // res["fname"] = "分界线"
  675. // res["feedname"] = mapc2[i]
  676. // res["饲料名称"] = mapc2[i]
  677. // res["typestr"] =typestr
  678. // reslist[0] = res
  679. // queryList = append(reslist,queryList...)
  680. //}
  681. for i := 0; i < len(queryList); i++ {
  682. if i == 0 {
  683. tem = queryList[i]["fname"]
  684. }
  685. if queryList[i]["fname"] == tem {
  686. mapc3[queryList[i]["feedname"]] = i
  687. }
  688. }
  689. for i := 0; i < len(queryList); i++ {
  690. a = mapc2[queryList[i]["feedname"]].(int) * 4
  691. if i == 0 {
  692. datamap2["label"] = "饲料名称"
  693. switch queryList[i]["typestr"].(type) {
  694. case string:
  695. datamap2child["label"] = queryList[i]["typestr"].(string) + "/饲料参数"
  696. default:
  697. datamap2child["label"] = "/饲料参数"
  698. }
  699. datamap2child["prop"] = "A"
  700. data3 = append(data3, datamap2child)
  701. datamap2["children"] = data3
  702. data2 = append(data2, datamap2)
  703. data3 = []interface{}{}
  704. datamap2child = make(map[string]interface{})
  705. datamap2 = make(map[string]interface{})
  706. dtem = queryList[i]["fname"]
  707. }
  708. if dtem != queryList[i]["fname"] && i != 0 {
  709. data1 = append(data1, datamap1)
  710. dtem = queryList[i]["fname"]
  711. datamap1 = make(map[string]interface{})
  712. }
  713. if queryList[i]["fname"] == temstr {
  714. datamap2["label"] = queryList[i]["feedname"]
  715. datamap2child["label"] = "理论"
  716. datamap2child["prop"] = "a" + strconv.Itoa(a)
  717. data3 = append(data3, datamap2child)
  718. datamap2child = make(map[string]interface{})
  719. datamap2child["label"] = "实际"
  720. datamap2child["prop"] = "a" + strconv.Itoa(a+1)
  721. data3 = append(data3, datamap2child)
  722. datamap2child = make(map[string]interface{})
  723. datamap2child["label"] = "误差值"
  724. datamap2child["prop"] = "a" + strconv.Itoa(a+2)
  725. data3 = append(data3, datamap2child)
  726. datamap2child = make(map[string]interface{})
  727. datamap2child["label"] = "误差率"
  728. datamap2child["prop"] = "a" + strconv.Itoa(a+3)
  729. data3 = append(data3, datamap2child)
  730. datamap2["children"] = data3
  731. data2 = append(data2, datamap2)
  732. data3 = []interface{}{}
  733. datamap2 = make(map[string]interface{})
  734. datamap2child = make(map[string]interface{})
  735. }
  736. datamap1["A"] = queryList[i]["fname"]
  737. datamap1["a"+strconv.Itoa(a)] = queryList[i]["lweight"]
  738. datamap1["a"+strconv.Itoa(a+1)] = queryList[i]["actualweightminus"]
  739. datamap1["a"+strconv.Itoa(a+2)] = queryList[i]["diff"]
  740. datamap1["a"+strconv.Itoa(a+3)] = queryList[i]["diffrate"]
  741. datamap2["label"] = queryList[i]["饲料名称"]
  742. }
  743. data1 = append(data1, datamap1)
  744. chartData["data1"] = data1
  745. chartData["data2"] = data2
  746. queryData["list"] = chartData
  747. queryData["code"] = 0
  748. queryData["message"] = "ok"
  749. queryData["data"] = queryList
  750. return queryData, nil
  751. }
  752. func getAccuracyV3(queryList []map[string]interface{}) (map[string]interface{}, error) {
  753. queryData := make(map[string]interface{})
  754. chartData := make(map[string]interface{})
  755. data := []interface{}{}
  756. data1 := []interface{}{}
  757. data2 := []interface{}{}
  758. data3 := []interface{}{}
  759. data4 := []interface{}{}
  760. datatem := []interface{}{}
  761. t1 := make(map[interface{}]string, 0)
  762. for i := 0; i < len(queryList); i++ {
  763. data = append(data, queryList[i]["mtime"])
  764. data1 = append(data1, queryList[i]["lweight"])
  765. data2 = append(data2, queryList[i]["weight"])
  766. //data3 = append(data3, queryList[i]["field3"])
  767. //data4 = append(data4, queryList[i]["field4"])
  768. if _, ok := t1[queryList[i]["id"]]; !ok {
  769. datatem = append(datatem, queryList[i]["startstime"], queryList[i]["lastactualweight"])
  770. data3 = append(data3, datatem)
  771. datatem = []interface{}{}
  772. datatem = append(datatem, queryList[i]["intime"], queryList[i]["actualweight"])
  773. data3 = append(data3, datatem)
  774. datatem = []interface{}{}
  775. }
  776. t1[queryList[i]["id"]] = "1"
  777. }
  778. chartData["data1"] = data
  779. chartData["data2"] = data1
  780. chartData["data3"] = data2
  781. chartData["data4"] = data3
  782. chartData["data5"] = data4
  783. queryData["list"] = chartData
  784. queryData["code"] = 0
  785. queryData["message"] = "ok"
  786. queryData["data"] = queryList
  787. return queryData, nil
  788. }
  789. func getAccuracyV3v1(queryList []map[string]interface{}) (map[string]interface{}, error) {
  790. queryData := make(map[string]interface{})
  791. chartData := make(map[string]interface{})
  792. data := []interface{}{}
  793. data1 := []interface{}{}
  794. data2 := []interface{}{}
  795. data3 := []interface{}{}
  796. data4 := []interface{}{}
  797. datatem := []interface{}{}
  798. //t1 := make(map[interface{}]string, 0)
  799. jsonstr := ""
  800. jsonmap := make([]map[string]interface{},0)
  801. if len(queryList)>0{
  802. queryjsonList, _ := restful.Engine.SQL("select weightjson from recweightmuster where pid = ? and pastureid = ?" ,queryList[0]["pid"],queryList[0]["pastureid"]).Query().List()
  803. if len(queryjsonList)>0{
  804. jsonstr = queryjsonList[0]["weightjson"].(string)
  805. }
  806. }
  807. err := json.Unmarshal([]byte(jsonstr),&jsonmap)
  808. if err != nil{
  809. return nil ,err
  810. }
  811. for i := 0; i < len(queryList); i++ {
  812. datatem = append(datatem, queryList[i]["startstime"], queryList[i]["lastactualweight"])
  813. data3 = append(data3, datatem)
  814. datatem = []interface{}{}
  815. datatem = append(datatem, queryList[i]["intime"], queryList[i]["actualweight"])
  816. data3 = append(data3, datatem)
  817. datatem = []interface{}{}
  818. }
  819. j := 0
  820. for i := 0; i < len(jsonmap); i++ {
  821. if jsonmap[i]["mt"].(string)>queryList[j]["intime"].(string){
  822. if j < len(queryList)-1{
  823. j++
  824. }
  825. }
  826. data1 = append(data1, queryList[j]["lweight"])
  827. data = append(data, jsonmap[i]["mt"])
  828. data2 = append(data2, jsonmap[i]["w"])
  829. }
  830. chartData["data1"] = data
  831. chartData["data2"] = data1
  832. chartData["data3"] = data2
  833. chartData["data4"] = data3
  834. chartData["data5"] = data4
  835. queryData["list"] = chartData
  836. queryData["code"] = 0
  837. queryData["message"] = "ok"
  838. queryData["data"] = queryList
  839. return queryData, nil
  840. }
  841. func getAccuracyV2(queryList []map[string]interface{}) (map[string]interface{}, error) {
  842. queryData := make(map[string]interface{})
  843. chartData := make(map[string]interface{})
  844. data := []interface{}{}
  845. data1 := []interface{}{}
  846. data2 := []interface{}{}
  847. data3 := []interface{}{}
  848. data4 := []interface{}{}
  849. for i := 0; i < len(queryList); i++ {
  850. data = append(data, queryList[i]["日期"])
  851. data1 = append(data1, queryList[i]["field1"])
  852. data2 = append(data2, queryList[i]["field2"])
  853. data3 = append(data3, queryList[i]["field3"])
  854. data4 = append(data4, queryList[i]["field4"])
  855. }
  856. chartData["data1"] = data
  857. chartData["data2"] = data1
  858. chartData["data3"] = data2
  859. chartData["data4"] = data3
  860. chartData["data5"] = data4
  861. queryData["list"] = chartData
  862. queryData["code"] = 0
  863. queryData["message"] = "ok"
  864. queryData["data"] = queryList
  865. return queryData, nil
  866. }
  867. func getAccuracy(queryList []map[string]interface{}) (map[string]interface{}, error) {
  868. queryData := make(map[string]interface{})
  869. chartData := make(map[string]interface{})
  870. t1 := make(map[interface{}]interface{}, 0)
  871. t2 := make(map[interface{}]interface{}, 0)
  872. data := make(map[string][]interface{}, 0)
  873. t := make([]map[string][]interface{}, 0)
  874. e1 := []interface{}{}
  875. e2 := []string{}
  876. for _, value := range queryList {
  877. if _, ok := t1[value["名称"]]; !ok {
  878. e1 = append(e1, value["名称"])
  879. }
  880. if _, ok := t2[value["日期"]]; !ok {
  881. switch value["日期"].(type) {
  882. case string:
  883. e2 = append(e2, value["日期"].(string))
  884. }
  885. }
  886. t1[value["名称"]] = value["名称"]
  887. t2[value["日期"]] = value["日期"]
  888. }
  889. sort.Strings(e2)
  890. var b interface{}
  891. a := 0
  892. for i := 0; i < len(queryList); i++ {
  893. if i == 0 {
  894. b = queryList[i]["名称"]
  895. }
  896. if b != queryList[i]["名称"] {
  897. if a < len(e2)-1 {
  898. for k := 0; k < len(e2)-a; k++ {
  899. data["data"] = append(data["data"], "")
  900. }
  901. }
  902. t = append(t, data)
  903. data = make(map[string][]interface{}, 0)
  904. b = queryList[i]["名称"]
  905. a = 0
  906. }
  907. switch queryList[i]["日期"].(type) {
  908. case string:
  909. dates, _ := time.Parse("2006-01-02", queryList[i]["日期"].(string))
  910. dates1 := ""
  911. if a < len(e2) -1{
  912. dates1 = e2[a]
  913. }else {
  914. dates1 = e2[len(e2)-1]
  915. }
  916. if a < len(e2)-1 {
  917. if e2[a] != queryList[i]["日期"].(string) {
  918. if e2[a] < queryList[i]["日期"].(string) {
  919. dates1 = queryList[i]["日期"].(string)
  920. dates, _ = time.Parse("2006-01-02", e2[a])
  921. for ; a < len(e2)-1; a++ {
  922. if e2[a] >= queryList[i]["日期"].(string) {
  923. break
  924. }
  925. }
  926. }
  927. for ; dates.Format("2006-01-02") < dates1; dates = dates.Add(24 * time.Hour) {
  928. data["data"] = append(data["data"], "")
  929. }
  930. }
  931. }
  932. }
  933. data["data"] = append(data["data"], queryList[i]["准确率"])
  934. a++
  935. }
  936. if a < len(e2)-1 {
  937. for k := 0; k < len(e2)-a; k++ {
  938. data["data"] = append(data["data"], "")
  939. }
  940. }
  941. t = append(t, data)
  942. chartData["data1"] = e1
  943. chartData["data2"] = e2
  944. chartData["data3"] = t
  945. queryData["list"] = chartData
  946. queryData["code"] = 0
  947. queryData["message"] = "ok"
  948. queryData["data"] = queryList
  949. return queryData, nil
  950. }