report.go 34 KB

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