report.go 30 KB

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