Browse Source

圣牧 手动上传云养牛更新

baishaojie 8 months ago
parent
commit
1149fa645e
2 changed files with 41 additions and 32 deletions
  1. 3 3
      conf/app.ini
  2. 38 29
      http/handle/api/ops.go

+ 3 - 3
conf/app.ini

@@ -50,8 +50,8 @@ Type = mysql
 User = root
 Password = root
 #Host = 8.130.17.8:3306
-Host = 192.168.1.93:3326
-#Host = 127.0.0.1:3316
+#Host = 192.168.1.93:3326
+Host = 127.0.0.1:3316
 #Name = haiyuan
 #Password = root
 #Password = root
@@ -75,7 +75,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = tmrwatch5
+Name = tmrwatch2
 TablePrefix =
 
 ShowXormlog = false

+ 38 - 29
http/handle/api/ops.go

@@ -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 {