report.go 32 KB

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