report.go 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "sort"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "../../routers/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. }