report.go 37 KB

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