|
@@ -3576,21 +3576,25 @@ func UpdateFpdetailBar(c *gin.Context) {
|
|
|
ftmap["ptsid"] = list.Get("ptsid").ValueStr()
|
|
|
// fmt.Println(ftmap)
|
|
|
|
|
|
- _, err = tx.SQL(` update lpplandtl1 set lweight = 0 where pastureid = ? and lppid in(select id from lpplan where pastureid = ? and times = ? )
|
|
|
- and find_in_set(barid,(select barid from feedp where id = ? )) `, pastureid, pastureid, ftmap["times"], id).Execute()
|
|
|
- if err != nil {
|
|
|
- tx.Rollback()
|
|
|
- logs.Error(err)
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
- return
|
|
|
- }
|
|
|
- _, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
|
|
|
- WHERE pastureid=? and find_in_set(barid,(select barid from feedp where id = ? ) ) and times = ? `, pastureid, id, ftmap["times"]).Execute()
|
|
|
- if err != nil {
|
|
|
- tx.Rollback()
|
|
|
- logs.Error(err)
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
- return
|
|
|
+ count, err := tx.SQL(` select count(1) from lpplandtl1 where pastureid = ? and lppid in(select id from lpplan where pastureid = ? and times = ? )
|
|
|
+ and find_in_set(barid,(select barid from feedp where id = ? )) and lweight > 0 `, pastureid, pastureid, ftmap["times"], id).Count()
|
|
|
+ if count == 1 {
|
|
|
+ _, err = tx.SQL(` update lpplandtl1 set lweight = 0 where pastureid = ? and lppid in(select id from lpplan where pastureid = ? and times = ? )
|
|
|
+ and find_in_set(barid,(select barid from feedp where id = ? )) `, pastureid, pastureid, ftmap["times"], id).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
|
|
|
+ WHERE pastureid=? and find_in_set(barid,(select barid from feedp where id = ? ) ) and times = ? `, pastureid, id, ftmap["times"]).Execute()
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
fpdDataList, err := tx.SQL(`
|
|
@@ -4712,21 +4716,26 @@ func FpdImportExcel(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
for barname, v := range dataList {
|
|
|
- _, err = tx.SQL(` update lpplandtl1 set lweight = 0 where pastureid = ? and lppid in(select id from lpplan where pastureid = ? )
|
|
|
- and find_in_set(barid,(select barid from feedp where barname = ? )) `, pastureid, pastureid, barname).Execute()
|
|
|
- if err != nil {
|
|
|
- logs.Error(err, "11111")
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
- return
|
|
|
- }
|
|
|
- _, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
|
|
|
- WHERE pastureid=? and find_in_set(barid,(select barid from feedp where barname = ? ) ) `, pastureid, barname).Execute()
|
|
|
- if err != nil {
|
|
|
- logs.Error(err, "22222")
|
|
|
- appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
- return
|
|
|
+ for _, v1 := range v {
|
|
|
+ count, err := tx.SQL(` select count(1) from lpplandtl1 where pastureid = ? and lppid in(select id from lpplan where pastureid = ? and times = ? )
|
|
|
+ and find_in_set(barid,(select barid from feedp where barname = ? )) and lweight > 0 `, pastureid, pastureid, v1.Times, barname).Count()
|
|
|
+ if count == 1 {
|
|
|
+ _, err = tx.SQL(` update lpplandtl1 set lweight = 0 where pastureid = ? and lppid in(select id from lpplan where pastureid = ? and times = ? )
|
|
|
+ and find_in_set(barid,(select barid from feedp where barname = ? )) `, pastureid, pastureid, v1.Times, barname).Execute()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, err = tx.SQL(` UPDATE fpdetail SET ptuse=0,ptsuse=0
|
|
|
+ WHERE pastureid=? and find_in_set(barid,(select barid from feedp where barname = ? ) ) and times= ? `, pastureid, barname, v1.Times).Execute()
|
|
|
+ if err != nil {
|
|
|
+ logs.Error(err)
|
|
|
+ appG.Response(http.StatusInternalServerError, e.ERROR, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
updateFpdetailByBar(pastureid, barname, v)
|
|
|
}
|
|
|
} else {
|