material.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. package api
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "net/http"
  6. "strconv"
  7. "../../pkg/app"
  8. "../../pkg/e"
  9. "../../routers/restful"
  10. "github.com/Anderson-Lu/gofasion/gofasion"
  11. "github.com/astaxie/beego/logs"
  12. "github.com/gin-gonic/gin"
  13. )
  14. type downloadedplan struct {
  15. Id int64 `json:"id"`
  16. Mydate string `json:"mydate"`
  17. Projname string `json:"projname"`
  18. Datacaptureno string `json:"datacaptureno"`
  19. Lweight string `json:"lweight"`
  20. Havebutton string `json:"havebutton"`
  21. Feedpname string `json:"feedpname"`
  22. Iscompleted string `json:"iscompleted"`
  23. Tmrtname string `json:"tmrtname"`
  24. Remark string `json:"remark"`
  25. Lpplantype string `json:"lpplantype"`
  26. Sort string `json:"sort"`
  27. Shifts string `json:"shifts"`
  28. }
  29. type ReqGetDownloadedplanMaterial struct {
  30. Pastureid int64 `json:"pastureid"`
  31. Datacaptureno int64 `json:"datacaptureno"`
  32. Date string `json:"date"`
  33. }
  34. func GetDownloadedplanMaterial1(c *gin.Context) {
  35. // var reqInfo ReqGetDownloadedplanMaterial
  36. // err := c.Bind(&reqInfo)
  37. appG := app.Gin{C: c}
  38. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  39. fsion := gofasion.NewFasion(string(dataByte))
  40. date := fsion.Get("date").ValueStr()
  41. pastureid := fsion.Get("pastureid").ValueStr()
  42. datacaptureno := fsion.Get("datacaptureno").ValueStr()
  43. id := fsion.Get("id").ValueStr()
  44. tx := restful.Engine.NewSession()
  45. defer tx.Close()
  46. tclassid := ""
  47. tmrList, err := tx.SQL(` select tclassid from tmr where datacaptureno = ? `, datacaptureno).QueryString()
  48. if err != nil {
  49. logs.Error(err)
  50. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  51. return
  52. }
  53. for _, tmr := range tmrList {
  54. tclassid = tmr["tclassid"]
  55. }
  56. downloadedplanInfo := new(downloadedplan)
  57. err = tx.SQL(` select d.id,date_format(d.mydate ,'%Y-%m-%d') as mydate ,d.projname,d.datacaptureno,d.lweight,d.havebutton,d.feedpname,d.iscompleted,d.remark,d.tmrtname from downloadedplan d
  58. where d.mydate = ? and d.pastureid = ? and (d.datacaptureno is null or d.datacaptureno = ?) and d.iscompleted = 0
  59. and ( (? IN(1,2) AND d.lpplanType IN (0,1)) OR (? IN (1,3) AND d.lpplanType IN (0,2)))
  60. and if(d.lpplantype = 2,if((select count(1) from downloadplandtl1 d1
  61. where d1.pid = (select id from downloadedplan dd where dd.mydate = d.mydate
  62. and dd.pastureId = d.pastureid and dd.lpplanType IN (0,1) and dd.pid = d.pid and dd.times = d.times )
  63. and d1.type = 0 and d1.havebuttom = 0 ) >0 ,1,0 ),0) = 0 and (?= '' or d.id = ? )
  64. order by d.sort `,
  65. date, pastureid, datacaptureno, tclassid, tclassid, id, id).GetFirst(downloadedplanInfo).Error
  66. if err != nil {
  67. logs.Error(err)
  68. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  69. return
  70. }
  71. if downloadedplanInfo.Id == 0 {
  72. appG.Response(http.StatusOK, e.THROUGHOUt_THE_DAY_TO_END, nil)
  73. return
  74. }
  75. _, err = tx.SQL(` update downloadedplan set havebutton = 1 ,intime = now() where id = ? and havebutton != 1 `, downloadedplanInfo.Id).Execute()
  76. if err != nil {
  77. logs.Error(err)
  78. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  79. return
  80. }
  81. _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = ifnull((select sort from downloadplandtl1 where pid = ? and intime is null order by sort limit 0,1),0 ) where datacaptureno = ? and pastureid = ? `,
  82. downloadedplanInfo.Id, date, downloadedplanInfo.Id, datacaptureno, pastureid).Execute()
  83. if err != nil {
  84. logs.Error(err)
  85. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  86. return
  87. }
  88. appG.Response(http.StatusOK, e.SUCCESS, downloadedplanInfo)
  89. }
  90. func GetSubPlan(c *gin.Context) {
  91. appG := app.Gin{C: c}
  92. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  93. parammaps := gofasion.NewFasion(string(dataByte))
  94. pid := parammaps.Get("pid").ValueStr()
  95. pastureid := parammaps.Get("pastureid").ValueStr()
  96. tx := restful.Engine.NewSession()
  97. defer tx.Close()
  98. downloadplandtl1List, err := tx.SQL(` select DATE_FORMAT(d1.begintime, '%Y-%m-%d %H:%i:%S') as begintime,
  99. DATE_FORMAT(d1.intime, '%Y-%m-%d %H:%i:%S') as intime ,f.id as feedid,d1.fname,d1.feedcode,f.autosecond,
  100. f.autozone,d1.lweight,d1.sort,d1.buttontype,d1.actualweightminus,f.confirmstart,f.jmp from downloadplandtl1 d1
  101. left join feed f
  102. on f.feedcode = d1.feedcode and f.pastureid = d1.pastureid where d1.pid = ? and d1.pastureid = ? `, pid, pastureid).Query().List()
  103. if err != nil {
  104. logs.Error(err)
  105. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  106. return
  107. }
  108. downloadplandtl2List, err := tx.SQL(` select d2.sort,DATE_FORMAT(d2.begintime, '%Y-%m-%d %H:%i:%S') as begintime ,DATE_FORMAT(d2.intime, '%Y-%m-%d %H:%i:%S') as intime
  109. ,d2.id,d2.pid,d2.fbarid,d2.fname as fbarname,d2.lweight,d.lpplantype,d2.actualweightminus ,ifnull(b.autozone,0) as autozone,ifnull(b.autosecond,"") as autosecond,ifnull(b.isstart,1) as isstart ,ifnull(b.jmp,0) as jmp
  110. from downloadplandtl2 d2
  111. join downloadedplan d on d.id = d2.pid
  112. left join bar b on d2.fbarid = b.id where d2.pid = ? and d2.pastureid = ? `, pid, pastureid).Query().List()
  113. if err != nil {
  114. logs.Error(err)
  115. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  116. return
  117. }
  118. d1List := make([]map[string]interface{}, 0)
  119. d2List := make([]map[string]interface{}, 0)
  120. for _, d2item := range downloadplandtl2List {
  121. data := make(map[string]interface{}, 0)
  122. data["fbarid"] = d2item["fbarid"]
  123. data["fbarname"] = d2item["fbarname"]
  124. data["lweight"] = d2item["lweight"]
  125. data["lpplantype"] = d2item["lpplantype"]
  126. data["id"] = d2item["id"]
  127. data["actualweightminus"] = d2item["actualweightminus"]
  128. data["intime"] = d2item["intime"]
  129. data["begintime"] = d2item["begintime"]
  130. data["sort"] = d2item["sort"]
  131. data["autozone"] = d2item["autozone"]
  132. data["autosecond"] = d2item["autosecond"]
  133. data["isstart"] = d2item["isstart"]
  134. data["jmp"] = d2item["jmp"]
  135. d2List = append(d2List, data)
  136. }
  137. for _, d1item := range downloadplandtl1List {
  138. d1 := make(map[string]interface{}, 0)
  139. // lweight, _ := strconv.ParseFloat(d1item["lweight"].(string), 64)
  140. d1["fname"] = d1item["fname"]
  141. d1["feedcode"] = d1item["feedcode"]
  142. d1["autosecond"] = d1item["autosecond"]
  143. d1["autozone"] = d1item["autozone"]
  144. d1["sort"] = d1item["sort"]
  145. d1["buttontype"] = d1item["buttontype"]
  146. d1["feedid"] = d1item["feedid"]
  147. d1["lweight"] = d1item["lweight"]
  148. d1["intime"] = d1item["intime"]
  149. d1["begintime"] = d1item["begintime"]
  150. d1["actualweightminus"] = d1item["actualweightminus"]
  151. d1["confirmstart"] = d1item["confirmstart"]
  152. d1["jmp"] = d1item["jmp"]
  153. d1List = append(d1List, d1)
  154. }
  155. resData := make(map[string]interface{}, 0)
  156. resData["mixing"] = d1List
  157. resData["spillage"] = d2List
  158. // data["plan"] = d1List
  159. // dataList = append(dataList, data)
  160. appG.Response(http.StatusOK, e.SUCCESS, resData)
  161. }
  162. func CompletePlan(c *gin.Context) {
  163. appG := app.Gin{C: c}
  164. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  165. parammaps := gofasion.NewFasion(string(dataByte))
  166. pid := parammaps.Get("pid").ValueStr()
  167. feedid := parammaps.Get("feedid").ValueStr()
  168. lastactualweight := parammaps.Get("lastactualweight").ValueDefaultFloat64(0)
  169. actualweightminus := parammaps.Get("actualweightminus").ValueDefaultFloat64(0)
  170. actualweight := parammaps.Get("actualweight").ValueDefaultFloat64(0)
  171. datacaptureno := parammaps.Get("datacaptureno").ValueStr()
  172. begintime := parammaps.Get("begintime").ValueStr()
  173. intime := parammaps.Get("intime").ValueStr()
  174. sort := parammaps.Get("sort").ValueStr()
  175. buttontype := parammaps.Get("buttontype").ValueStr()
  176. lpplantype := parammaps.Get("lpplantype").ValueDefaultInt64(0)
  177. d2id := parammaps.Get("d2id").ValueStr()
  178. pastureid := parammaps.Get("pastureid").ValueStr()
  179. tx := restful.Engine.NewSession()
  180. defer tx.Close()
  181. _, err := tx.SQL(` update downloadedplan set tmrid = ( select id from tmr where datacaptureno = ? and pastureid = ?) ,
  182. tmrtname = ( select eqcode from tmr where datacaptureno = ? and pastureid = ?) where id = ? and tmrid != ( select id from tmr where datacaptureno = ? and pastureid = ?)`,
  183. datacaptureno, pastureid, datacaptureno, pastureid, pid, datacaptureno, pastureid).Execute()
  184. if err != nil {
  185. logs.Error(err)
  186. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  187. return
  188. }
  189. if lpplantype == 0 {
  190. _, err := tx.SQL(` update downloadplandtl1 set begintime = ? , actualweightminus = ifnull(actualweightminus,0) +? ,
  191. intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,
  192. havebuttom = 1,lastactualweight = ? where pid = ?
  193. and sort = ? and feedcode = (select feedcode from feed where id = ? ) and (intime is null )`,
  194. begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, pid, sort, feedid).Execute()
  195. if err != nil {
  196. logs.Error(err)
  197. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  198. return
  199. }
  200. _, err = tx.SQL(` update downloadplandtl1_exec set begintime = ? ,actualweightminus = ifnull(actualweightminus,0)+ ? ,
  201. intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ? where pid = ?
  202. and sort = ? and (intime is null ) `,
  203. begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, pid, sort).Execute()
  204. if err != nil {
  205. logs.Error(err)
  206. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  207. return
  208. }
  209. d2List, err := tx.SQL(` select * from downloadplandtl2 where pid = ? order by sort `, pid).Query().List()
  210. if err != nil {
  211. logs.Error(err)
  212. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  213. return
  214. }
  215. var sumlweight float64
  216. for _, d2 := range d2List {
  217. lweight, _ := strconv.ParseFloat(d2["lweight"].(string), 64)
  218. sumlweight += lweight
  219. }
  220. for _, d2 := range d2List {
  221. if actualweightminus <= 0 {
  222. break
  223. }
  224. lweight, _ := strconv.ParseFloat(d2["lweight"].(string), 64)
  225. actualweight := lweight / sumlweight * actualweightminus
  226. last := lweight / sumlweight * lastactualweight
  227. _, err := tx.SQL(` update downloadplandtl2 set actualweightminus = ifnull(actualweightminus,0)+?, actualweight = ?,
  228. lastactualweight = ? , intime = ?,begintime = ? ,havebuttom = 1,buttontype = ? where id = ? and (intime is null ) `, actualweight,
  229. actualweight, last, intime, begintime, buttontype, d2["id"]).Execute()
  230. if err != nil {
  231. logs.Error(err)
  232. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  233. return
  234. }
  235. }
  236. execExist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and (intime is null ) `, pid).Exist()
  237. if err != nil {
  238. logs.Error(err)
  239. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  240. return
  241. }
  242. if !execExist {
  243. _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
  244. if err != nil {
  245. logs.Error(err)
  246. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  247. return
  248. }
  249. }
  250. _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort =
  251. (select sort from downloadplandtl1 where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
  252. pid, intime, pid, datacaptureno, pastureid).Execute()
  253. if err != nil {
  254. logs.Error(err)
  255. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  256. return
  257. }
  258. } else if lpplantype == 1 {
  259. _, err := tx.SQL(` update downloadplandtl2 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
  260. lastactualweight = ? , intime = ? ,begintime = ?,havebuttom = 1,buttontype = ? where id = ? and (intime is null ) `,
  261. actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, d2id).Execute()
  262. if err != nil {
  263. logs.Error(err)
  264. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  265. return
  266. }
  267. _, err = tx.SQL(` update downloadplandtl1_exec set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
  268. lastactualweight = ? , intime = ?,begintime= ? ,havebuttom = 1,buttontype= ? where pid = ? and (intime is null ) `,
  269. actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, pid).Execute()
  270. if err != nil {
  271. logs.Error(err)
  272. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  273. return
  274. }
  275. _, err = tx.SQL(` update downloadplandtl1 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
  276. lastactualweight = ? , intime = ?,begintime=? ,havebuttom = 1,buttontype = ? where pid = ? and (intime is null ) `,
  277. actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, pid).Execute()
  278. if err != nil {
  279. logs.Error(err)
  280. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  281. return
  282. }
  283. exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null `, pid).Exist()
  284. if err != nil {
  285. logs.Error(err)
  286. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  287. return
  288. }
  289. if !exist {
  290. _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
  291. if err != nil {
  292. logs.Error(err)
  293. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  294. return
  295. }
  296. }
  297. _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl2
  298. where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
  299. pid, intime, pid, datacaptureno, pastureid).Execute()
  300. if err != nil {
  301. logs.Error(err)
  302. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  303. return
  304. }
  305. } else if lpplantype == 2 {
  306. _, err := tx.SQL(` update downloadplandtl1 set begintime = ? , actualweightminus =ifnull(actualweightminus,0)+ ? ,
  307. intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ? where pid = ?
  308. and sort = ? and feedcode = (select feedcode from feed where id = ? ) and (intime is null )`,
  309. begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, begintime, pid, sort, feedid).Execute()
  310. if err != nil {
  311. logs.Error(err)
  312. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  313. return
  314. }
  315. _, err = tx.SQL(` update downloadplandtl1_exec set begintime = ? ,actualweightminus =ifnull(actualweightminus,0)+ ? ,
  316. intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ? where pid = ?
  317. and sort = ? and (intime is null ) `,
  318. begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, begintime, pid, sort).Execute()
  319. if err != nil {
  320. logs.Error(err)
  321. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  322. return
  323. }
  324. _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort =
  325. (select sort from downloadplandtl1 where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
  326. pid, intime, pid, datacaptureno, pastureid).Execute()
  327. if err != nil {
  328. logs.Error(err)
  329. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  330. return
  331. }
  332. } else {
  333. _, err := tx.SQL(` update downloadplandtl2 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
  334. lastactualweight = ? , intime = ? ,havebuttom = 1,buttontype = ?,begintime = ? where id = ? and (intime is null ) `,
  335. actualweightminus, actualweight, lastactualweight, intime, buttontype, begintime, d2id).Execute()
  336. if err != nil {
  337. logs.Error(err)
  338. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  339. return
  340. }
  341. exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null`, pid).Exist()
  342. if err != nil {
  343. logs.Error(err)
  344. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  345. return
  346. }
  347. if !exist {
  348. _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
  349. if err != nil {
  350. logs.Error(err)
  351. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  352. return
  353. }
  354. }
  355. _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort =
  356. (select sort from downloadplandtl2 where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
  357. pid, intime, pid, datacaptureno, pastureid).Execute()
  358. if err != nil {
  359. logs.Error(err)
  360. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  361. return
  362. }
  363. }
  364. appG.Response(http.StatusOK, e.SUCCESS, true)
  365. }
  366. func AddRealTimeWeight(c *gin.Context) {
  367. appG := app.Gin{C: c}
  368. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  369. fsion := gofasion.NewFasion(string(dataByte))
  370. pid := fsion.Get("pid").ValueStr()
  371. pastureid := fsion.Get("pastureid").ValueStr()
  372. weightjson := fsion.Get("weightjson").ValueStr()
  373. // weightjson
  374. tx := restful.Engine.NewSession()
  375. defer tx.Close()
  376. dataList, err := tx.SQL(` select weightjson from recweightmuster where pid = ? and pastureid = ? `, pid, pastureid).QueryString()
  377. if err != nil {
  378. logs.Error("AddRealTimeWeight-error1: ", err)
  379. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  380. return
  381. }
  382. weightList := make([]map[string]interface{}, 0)
  383. if len(dataList) > 0 {
  384. weight := ""
  385. for _, item := range dataList {
  386. weight = item["weightjson"]
  387. }
  388. list := make([]map[string]interface{}, 0)
  389. err = json.Unmarshal([]byte(weight), &weightList)
  390. if err != nil {
  391. logs.Error("AddRealTimeWeight-error2: ", err)
  392. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  393. return
  394. }
  395. err = json.Unmarshal([]byte(weightjson), &list)
  396. if err != nil {
  397. logs.Error("AddRealTimeWeight-error3: ", err)
  398. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  399. return
  400. }
  401. weightList = append(weightList, list...)
  402. } else {
  403. json.Unmarshal([]byte(weightjson), &weightList)
  404. }
  405. weightbyte, err := json.Marshal(weightList)
  406. if err != nil {
  407. logs.Error("AddRealTimeWeight-error4: ", err)
  408. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  409. return
  410. }
  411. _, err = tx.SQL(`REPLACE INTO recweightmuster (pid, pastureid, weightjson)values (?,?,?)`, pid, pastureid, string(weightbyte)).Execute()
  412. if err != nil {
  413. logs.Error("AddRealTimeWeight-error5: ", err)
  414. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  415. return
  416. }
  417. appG.Response(http.StatusOK, e.SUCCESS, true)
  418. }
  419. func GetDownloadedplanMaterialList(c *gin.Context) {
  420. appG := app.Gin{C: c}
  421. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  422. fsion := gofasion.NewFasion(string(dataByte))
  423. pastureid := fsion.Get("pastureid").ValueStr()
  424. date := fsion.Get("date").ValueStr()
  425. datacaptureno := fsion.Get("datacaptureno").ValueStr()
  426. // date := reqInfo.Date
  427. // datacaptureno := reqInfo.Datacaptureno
  428. tx := restful.Engine.NewSession()
  429. defer tx.Close()
  430. tclassid := ""
  431. tmrList, err := tx.SQL(` select tclassid from tmr where datacaptureno = ? `, datacaptureno).QueryString()
  432. if err != nil {
  433. logs.Error(err)
  434. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  435. return
  436. }
  437. for _, tmr := range tmrList {
  438. tclassid = tmr["tclassid"]
  439. }
  440. downloadedplanInfo := make([]*downloadedplan, 0)
  441. err = tx.SQL(` select d.lpplantype,d.times,d.sort,d.times shifts,d.id,date_format(d.mydate ,'%Y-%m-%d') as mydate ,d.projname,d.datacaptureno,d.lweight,d.havebutton,d.feedpname,d.iscompleted,d.remark,d.tmrtname from downloadedplan d
  442. where d.mydate = ? and d.pastureid = ? and (d.datacaptureno is null or d.datacaptureno = ?)
  443. and ( (? IN(1,2) AND d.lpplanType IN (0,1)) OR (? IN (1,3) AND d.lpplanType IN (0,2)))
  444. and if(d.lpplantype = 2,if((select count(1) from downloadplandtl1 d1
  445. where d1.pid = (select id from downloadedplan dd where dd.mydate = d.mydate
  446. and dd.pastureId = d.pastureid and dd.lpplanType IN (0,1) and dd.pid = d.pid and dd.times = d.times )
  447. and d1.type = 0 and d1.havebuttom = 0 ) >0 ,1,0 ),0) = 0
  448. order by d.sort `,
  449. date, pastureid, datacaptureno, tclassid, tclassid).Find(&downloadedplanInfo)
  450. if err != nil {
  451. logs.Error(err)
  452. appG.Response(http.StatusInternalServerError, e.ERROR, err)
  453. return
  454. }
  455. appG.Response(http.StatusOK, e.SUCCESS, downloadedplanInfo)
  456. }