|
@@ -1,6 +1,7 @@
|
|
|
package api
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
"strconv"
|
|
@@ -107,7 +108,9 @@ func GetSubPlan(c *gin.Context) {
|
|
|
tx := restful.Engine.NewSession()
|
|
|
defer tx.Close()
|
|
|
|
|
|
- downloadplandtl1List, err := tx.SQL(` select DATE_FORMAT(d1.begintime, '%Y-%m-%d %H:%i:%S') as begintime, DATE_FORMAT(d1.intime, '%Y-%m-%d %H:%i:%S') as intime ,f.id as feedid,d1.fname,d1.feedcode,f.autosecond,f.autozone,d1.lweight,d1.sort,d1.buttontype,d1.actualweightminus from downloadplandtl1 d1
|
|
|
+ downloadplandtl1List, err := tx.SQL(` select DATE_FORMAT(d1.begintime, '%Y-%m-%d %H:%i:%S') as begintime,
|
|
|
+ DATE_FORMAT(d1.intime, '%Y-%m-%d %H:%i:%S') as intime ,f.id as feedid,d1.fname,d1.feedcode,f.autosecond,
|
|
|
+ f.autozone,d1.lweight,d1.sort,d1.buttontype,d1.actualweightminus,f.confirmstart,f.jmp from downloadplandtl1 d1
|
|
|
left join feed f
|
|
|
on f.feedcode = d1.feedcode and f.pastureid = d1.pastureid where d1.pid = ? and d1.pastureid = ? `, pid, pastureid).Query().List()
|
|
|
if err != nil {
|
|
@@ -115,7 +118,11 @@ func GetSubPlan(c *gin.Context) {
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
return
|
|
|
}
|
|
|
- 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 ,d2.id,d2.pid,d2.fbarid,d2.fname as fbarname,d2.lweight,d.lpplantype,d2.actualweightminus from downloadplandtl2 d2 join downloadedplan d on d.id = d2.pid where d2.pid = ? and d2.pastureid = ? `, pid, pastureid).Query().List()
|
|
|
+ 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
|
|
|
+ ,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
|
|
|
+ from downloadplandtl2 d2
|
|
|
+ join downloadedplan d on d.id = d2.pid
|
|
|
+ left join bar b on d2.fbarid = b.id where d2.pid = ? and d2.pastureid = ? `, pid, pastureid).Query().List()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -134,8 +141,11 @@ func GetSubPlan(c *gin.Context) {
|
|
|
data["actualweightminus"] = d2item["actualweightminus"]
|
|
|
data["intime"] = d2item["intime"]
|
|
|
data["begintime"] = d2item["begintime"]
|
|
|
- // flweight, _ := strconv.ParseFloat(d2item["lweight"].(string), 64)
|
|
|
data["sort"] = d2item["sort"]
|
|
|
+ data["autozone"] = d2item["autozone"]
|
|
|
+ data["autosecond"] = d2item["autosecond"]
|
|
|
+ data["isstart"] = d2item["isstart"]
|
|
|
+ data["jmp"] = d2item["jmp"]
|
|
|
d2List = append(d2List, data)
|
|
|
}
|
|
|
|
|
@@ -153,6 +163,8 @@ func GetSubPlan(c *gin.Context) {
|
|
|
d1["intime"] = d1item["intime"]
|
|
|
d1["begintime"] = d1item["begintime"]
|
|
|
d1["actualweightminus"] = d1item["actualweightminus"]
|
|
|
+ d1["confirmstart"] = d1item["confirmstart"]
|
|
|
+ d1["jmp"] = d1item["jmp"]
|
|
|
d1List = append(d1List, d1)
|
|
|
}
|
|
|
|
|
@@ -172,7 +184,8 @@ func CompletePlan(c *gin.Context) {
|
|
|
feedid := parammaps.Get("feedid").ValueStr()
|
|
|
lastactualweight := parammaps.Get("lastactualweight").ValueDefaultFloat64(0)
|
|
|
actualweightminus := parammaps.Get("actualweightminus").ValueDefaultFloat64(0)
|
|
|
- tmrid := parammaps.Get("tmrid").ValueStr()
|
|
|
+ actualweight := parammaps.Get("actualweight").ValueDefaultFloat64(0)
|
|
|
+ datacaptureno := parammaps.Get("datacaptureno").ValueStr()
|
|
|
begintime := parammaps.Get("begintime").ValueStr()
|
|
|
intime := parammaps.Get("intime").ValueStr()
|
|
|
sort := parammaps.Get("sort").ValueStr()
|
|
@@ -182,17 +195,23 @@ func CompletePlan(c *gin.Context) {
|
|
|
pastureid := parammaps.Get("pastureid").ValueStr()
|
|
|
tx := restful.Engine.NewSession()
|
|
|
defer tx.Close()
|
|
|
- // begintime := ""
|
|
|
- // if begintimestr != "" {
|
|
|
- // begintime = strings.ReplaceAll("2022-08-11T13:43:34+08:00", "T", " ")[:len("2006-01-02 15:04:05")]
|
|
|
- // }
|
|
|
+
|
|
|
+ _, err := tx.SQL(` update downloadedplan set tmrid = ( select id from tmr where datacaptureno = ? and pastureid = ?) ,
|
|
|
+ tmrtname = ( select eqcode from tmr where datacaptureno = ? and pastureid = ?) where id = ? and tmrid != ( select id from tmr where datacaptureno = ? and pastureid = ?)`,
|
|
|
+ datacaptureno, pastureid, datacaptureno, pastureid, pid, datacaptureno, pastureid).Execute()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
if lpplantype == 0 {
|
|
|
|
|
|
_, err := tx.SQL(` update downloadplandtl1 set begintime = ? , actualweightminus = ifnull(actualweightminus,0) +? ,
|
|
|
- intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ? where pid = ?
|
|
|
- and sort = ? and feedcode = (select feedcode from feed where id = ? )`,
|
|
|
- begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, pid, sort, feedid).Execute()
|
|
|
+ intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,
|
|
|
+ havebuttom = 1,lastactualweight = ? where pid = ?
|
|
|
+ and sort = ? and feedcode = (select feedcode from feed where id = ? ) and (intime is null )`,
|
|
|
+ begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, pid, sort, feedid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -200,16 +219,9 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
_, err = tx.SQL(` update downloadplandtl1_exec set begintime = ? ,actualweightminus = ifnull(actualweightminus,0)+ ? ,
|
|
|
- intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ? where pid = ?
|
|
|
- and sort = ? `,
|
|
|
- begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, pid, sort).Execute()
|
|
|
- if err != nil {
|
|
|
- logs.Error(err)
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- execExist, err := tx.SQL(` select id from downloadplandtl1_exec where pid = ? and intime is null `, pid).Exist()
|
|
|
+ intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ? where pid = ?
|
|
|
+ and sort = ? and (intime is null ) `,
|
|
|
+ begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, pid, sort).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -237,7 +249,7 @@ func CompletePlan(c *gin.Context) {
|
|
|
actualweight := lweight / sumlweight * actualweightminus
|
|
|
last := lweight / sumlweight * lastactualweight
|
|
|
_, err := tx.SQL(` update downloadplandtl2 set actualweightminus = ifnull(actualweightminus,0)+?, actualweight = ?,
|
|
|
- lastactualweight = ? , intime = ?,begintime = ? ,havebuttom = 1,buttontype = ? where id = ? `, actualweight,
|
|
|
+ lastactualweight = ? , intime = ?,begintime = ? ,havebuttom = 1,buttontype = ? where id = ? and (intime is null ) `, actualweight,
|
|
|
actualweight, last, intime, begintime, buttontype, d2["id"]).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
@@ -246,8 +258,15 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ execExist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and (intime is null ) `, pid).Exist()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if !execExist {
|
|
|
- _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
|
|
|
+ _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -255,8 +274,9 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl1 where pid = ? and intime is null order by sort limit 0,1 ) where id = ? and pastureid = ? `,
|
|
|
- pid, intime, pid, tmrid, pastureid).Execute()
|
|
|
+ _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort =
|
|
|
+ (select sort from downloadplandtl1 where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
|
|
|
+ pid, intime, pid, datacaptureno, pastureid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -266,8 +286,8 @@ func CompletePlan(c *gin.Context) {
|
|
|
} else if lpplantype == 1 {
|
|
|
|
|
|
_, err := tx.SQL(` update downloadplandtl2 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
|
|
|
- lastactualweight = ? , intime = ? ,begintime = ?,havebuttom = 1,buttontype = ? where id = ? `,
|
|
|
- actualweightminus, actualweightminus, lastactualweight, intime, begintime, buttontype, d2id).Execute()
|
|
|
+ lastactualweight = ? , intime = ? ,begintime = ?,havebuttom = 1,buttontype = ? where id = ? and (intime is null ) `,
|
|
|
+ actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, d2id).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -275,8 +295,8 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
_, err = tx.SQL(` update downloadplandtl1_exec set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
|
|
|
- lastactualweight = ? , intime = ?,begintime= ? ,havebuttom = 1,buttontype= ? where pid = ? `,
|
|
|
- actualweightminus, actualweightminus, lastactualweight, intime, begintime, buttontype, pid).Execute()
|
|
|
+ lastactualweight = ? , intime = ?,begintime= ? ,havebuttom = 1,buttontype= ? where pid = ? and (intime is null ) `,
|
|
|
+ actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, pid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -284,15 +304,15 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
_, err = tx.SQL(` update downloadplandtl1 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
|
|
|
- lastactualweight = ? , intime = ?,begintime=? ,havebuttom = 1,buttontype = ? where pid = ? `,
|
|
|
- actualweightminus, actualweightminus, lastactualweight, intime, begintime, buttontype, pid).Execute()
|
|
|
+ lastactualweight = ? , intime = ?,begintime=? ,havebuttom = 1,buttontype = ? where pid = ? and (intime is null ) `,
|
|
|
+ actualweightminus, actualweight, lastactualweight, intime, begintime, buttontype, pid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null `, pid).Exist()
|
|
|
+ exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null `, pid).Exist()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -300,7 +320,7 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
if !exist {
|
|
|
- _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
|
|
|
+ _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -308,8 +328,9 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl2 where pid = ? and intime is null order by sort limit 0,1 ) where id = ? and pastureid = ? `,
|
|
|
- pid, intime, pid, tmrid, pastureid).Execute()
|
|
|
+ _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl2
|
|
|
+ where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
|
|
|
+ pid, intime, pid, datacaptureno, pastureid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -318,9 +339,9 @@ func CompletePlan(c *gin.Context) {
|
|
|
|
|
|
} else if lpplantype == 2 {
|
|
|
_, err := tx.SQL(` update downloadplandtl1 set begintime = ? , actualweightminus =ifnull(actualweightminus,0)+ ? ,
|
|
|
- intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ? where pid = ?
|
|
|
- and sort = ? and feedcode = (select feedcode from feed where id = ? )`,
|
|
|
- begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, begintime, pid, sort, feedid).Execute()
|
|
|
+ intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ? where pid = ?
|
|
|
+ and sort = ? and feedcode = (select feedcode from feed where id = ? ) and (intime is null )`,
|
|
|
+ begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, begintime, pid, sort, feedid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -328,17 +349,18 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
_, err = tx.SQL(` update downloadplandtl1_exec set begintime = ? ,actualweightminus =ifnull(actualweightminus,0)+ ? ,
|
|
|
- intime = ? ,actualweight = ? ,optdevice = ?,buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ? where pid = ?
|
|
|
- and sort = ? `,
|
|
|
- begintime, actualweightminus, intime, actualweightminus, tmrid, buttontype, lastactualweight, begintime, pid, sort).Execute()
|
|
|
+ intime = ? ,actualweight = ? ,optdevice = ( select id from tmr where datacaptureno = ? and pastureid = ?),buttontype = ?,havebuttom = 1,lastactualweight = ?,begintime = ? where pid = ?
|
|
|
+ and sort = ? and (intime is null ) `,
|
|
|
+ begintime, actualweightminus, intime, actualweight, datacaptureno, pastureid, buttontype, lastactualweight, begintime, pid, sort).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl1 where pid = ? and intime is null order by sort limit 0,1 ) where id = ? and pastureid = ? `,
|
|
|
- pid, intime, pid, tmrid, pastureid).Execute()
|
|
|
+ _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort =
|
|
|
+ (select sort from downloadplandtl1 where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
|
|
|
+ pid, intime, pid, datacaptureno, pastureid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -347,15 +369,15 @@ func CompletePlan(c *gin.Context) {
|
|
|
|
|
|
} else {
|
|
|
_, err := tx.SQL(` update downloadplandtl2 set actualweightminus =ifnull(actualweightminus,0)+?, actualweight = ?,
|
|
|
- lastactualweight = ? , intime = ? ,havebuttom = 1,buttontype = ?,begintime = ? where id = ? `,
|
|
|
- actualweightminus, actualweightminus, lastactualweight, intime, buttontype, begintime, d2id).Execute()
|
|
|
+ lastactualweight = ? , intime = ? ,havebuttom = 1,buttontype = ?,begintime = ? where id = ? and (intime is null ) `,
|
|
|
+ actualweightminus, actualweight, lastactualweight, intime, buttontype, begintime, d2id).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null `, pid).Exist()
|
|
|
+ exist, err := tx.SQL(` select id from downloadplandtl2 where pid = ? and intime is null`, pid).Exist()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -363,15 +385,16 @@ func CompletePlan(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
if !exist {
|
|
|
- _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
|
|
|
+ _, err := tx.SQL(` update downloadedplan set iscompleted = 1, completedtime = ? where id = ? `, intime, pid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort = (select sort from downloadplandtl2 where pid = ? and intime is null order by sort limit 0,1 ) where id = ? and pastureid = ? `,
|
|
|
- pid, intime, pid, tmrid, pastureid).Execute()
|
|
|
+ _, err = tx.SQL(` update tmr set projid = ? ,lastbuttontime =? , nextsort =
|
|
|
+ (select sort from downloadplandtl2 where pid = ? and intime is null order by sort limit 0,1 ) where datacaptureno = ? and pastureid = ? `,
|
|
|
+ pid, intime, pid, datacaptureno, pastureid).Execute()
|
|
|
if err != nil {
|
|
|
logs.Error(err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
@@ -390,21 +413,60 @@ func AddRealTimeWeight(c *gin.Context) {
|
|
|
pastureid := fsion.Get("pastureid").ValueStr()
|
|
|
weightjson := fsion.Get("weightjson").ValueStr()
|
|
|
|
|
|
+ // weightjson
|
|
|
+
|
|
|
tx := restful.Engine.NewSession()
|
|
|
defer tx.Close()
|
|
|
|
|
|
- _, err := tx.SQL(`REPLACE INTO recweightmuster (pid, pastureid, weightjson)values (?,?,?)`, pid, pastureid, weightjson).Execute()
|
|
|
+ dataList, err := tx.SQL(` select weightjson from recweightmuster where pid = ? and pastureid = ? `, pid, pastureid).QueryString()
|
|
|
if err != nil {
|
|
|
logs.Error("AddRealTimeWeight-error1: ", err)
|
|
|
appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ weightList := make([]map[string]interface{}, 0)
|
|
|
+ if len(dataList) > 0 {
|
|
|
+ weight := ""
|
|
|
+ for _, item := range dataList {
|
|
|
+ weight = item["weightjson"]
|
|
|
+ }
|
|
|
+ list := make([]map[string]interface{}, 0)
|
|
|
+ err = json.Unmarshal([]byte(weight), &weightList)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("AddRealTimeWeight-error2: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = json.Unmarshal([]byte(weightjson), &list)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("AddRealTimeWeight-error3: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ weightList = append(weightList, list...)
|
|
|
+ } else {
|
|
|
+ json.Unmarshal([]byte(weightjson), &weightList)
|
|
|
+ }
|
|
|
+
|
|
|
+ weightbyte, err := json.Marshal(weightList)
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("AddRealTimeWeight-error4: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = tx.SQL(`REPLACE INTO recweightmuster (pid, pastureid, weightjson)values (?,?,?)`, pid, pastureid, string(weightbyte)).Execute()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error("AddRealTimeWeight-error5: ", err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
appG.Response(http.StatusOK, e.SUCCESS, true)
|
|
|
}
|
|
|
|
|
|
func GetDownloadedplanMaterialList(c *gin.Context) {
|
|
|
- // var reqInfo ReqGetDownloadedplanMaterial
|
|
|
|
|
|
appG := app.Gin{C: c}
|
|
|
dataByte, _ := ioutil.ReadAll(c.Request.Body)
|
|
@@ -430,7 +492,7 @@ func GetDownloadedplanMaterialList(c *gin.Context) {
|
|
|
|
|
|
downloadedplanInfo := make([]*downloadedplan, 0)
|
|
|
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
|
|
|
- where d.mydate = ? and d.pastureid = ? and (d.datacaptureno is null or d.datacaptureno = ?) and d.iscompleted = 0
|
|
|
+ where d.mydate = ? and d.pastureid = ? and (d.datacaptureno is null or d.datacaptureno = ?)
|
|
|
and ( (? IN(1,2) AND d.lpplanType IN (0,1)) OR (? IN (1,3) AND d.lpplanType IN (0,2)))
|
|
|
and if(d.lpplantype = 2,if((select count(1) from downloadplandtl1 d1
|
|
|
where d1.pid = (select id from downloadedplan dd where dd.mydate = d.mydate
|