Browse Source

代码提交

baishaojie 9 months ago
parent
commit
927c0f9e95
5 changed files with 91 additions and 10 deletions
  1. BIN
      TMRWatchComm
  2. BIN
      TMRWatchComm.zip
  3. 66 0
      http/handle/api/ops.go
  4. 4 0
      http/handle/api/scheduled.go
  5. 21 10
      http/handle/sap/sap.go

BIN
TMRWatchComm


BIN
TMRWatchComm.zip


+ 66 - 0
http/handle/api/ops.go

@@ -3206,6 +3206,24 @@ func UpdateFTdetail(c *gin.Context) {
 			return
 		}
 
+		for _, lpp := range lpplandtl1AllList {
+			_, err = tx.SQL(` update  lpplandtl1  set lweight = 0 where pastureid = ? and  lppid in(select  id from lpplan where pastureid = ?  ) 
+		and find_in_set(barid,?) `, parammaps["pastureid"], parammaps["pastureid"], lpp.Barid).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,?  )   `, parammaps["pastureid"], lpp.Barid).Execute()
+			if err != nil {
+				logs.Error(err)
+				appG.Response(http.StatusInternalServerError, e.ERROR, err)
+				return
+			}
+
+		}
+
 		var wg sync.WaitGroup
 		for _, old := range fpdOldDataList {
 			for _, fpd := range fpdDataList {
@@ -3559,6 +3577,23 @@ 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
+		}
+
 		fpdDataList, err := tx.SQL(`
 			SELECT TRIM(id) id,times,tratio,ifnull(ROUND((1-ptsrate)*weight,2)-ptuse,"") weight,TRIM(barid) barid,TRIM(pastureid) pastureid,TRIM((select ftid from feedp where barid =fpdetail.barid)) ptid,TRIM(ifnull(ptsid,-1) ) ptsid ,
 			(select bname  from bar where pastureid =fpdetail.pastureid and id = fpdetail.barid ) barname,concat(1) AS fttype,cowcount,ccountradio,0 isfill  FROM fpdetail
@@ -4671,7 +4706,23 @@ func FpdImportExcel(c *gin.Context) {
 			isdone = true
 		}
 	}
+
 	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)
+			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)
+			appG.Response(http.StatusInternalServerError, e.ERROR, err)
+			return
+		}
+
 		updateFpdetailByBar(pastureid, barname, v)
 	}
 
@@ -8058,6 +8109,21 @@ func FpdBatchEdit(c *gin.Context) {
 			continue
 		}
 
+		_, 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, dataexcel["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 = ? )  )   `, pastureid, dataexcel["barname"]).Execute()
+		if err != nil {
+			logs.Error(err)
+			appG.Response(http.StatusInternalServerError, e.ERROR, err)
+			return
+		}
+
 		dataexcel["1"] = barFsions.Get("times1").ValueStr()
 		dataexcel["2"] = barFsions.Get("times2").ValueStr()
 		dataexcel["3"] = barFsions.Get("times3").ValueStr()

+ 4 - 0
http/handle/api/scheduled.go

@@ -141,6 +141,10 @@ func CronScheduled(ctx context.Context) {
 	// 	// 	fmt.Println(time.Now())
 	// 	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// })
+	// err = xdmy.AddFunc("0 10 17 * * *", func() {
+	// 	sap.SyncSurplusOutbound()
+	// })
+
 	// xdmy.Start()
 	// InitMqttClient()
 	// yq.YqCron()

+ 21 - 10
http/handle/sap/sap.go

@@ -31,7 +31,21 @@ func SyncMaterialOutbound() error {
 		return err
 	}
 	materialOutbound(pastureinfo.Pastureid, time.Now().AddDate(0, 0, -1).Format("2006-01-02"))
-	surplusOutbound(pastureinfo.Pastureid, time.Now().AddDate(0, 0, -1).Format("2006-01-02"))
+	return nil
+}
+
+func SyncSurplusOutbound() error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	pastureinfo := new(udPastureInfo)
+	err := tx.SQL(`select column_default  as pastureid   from    information_schema.COLUMNS
+	WHERE table_name = 'recweight' AND table_schema = ? AND column_name = 'pastureid'`, setting.DatabaseSetting.Name).GetFirst(pastureinfo).Error
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+	surplusOutbound(pastureinfo.Pastureid, time.Now().Format("2006-01-02"))
 	return nil
 }
 
@@ -360,13 +374,15 @@ func surplusOutbound(pastureId, date string) error {
 		logs.Error(err)
 		return err
 	}
+	now, _ := time.ParseInLocation("2006-01-02", date, time.Local)
 
 	dataList, err := tx.SQL(`SELECT 
 	tem.sort ZEILE,
 	tem.feedname MAKTX,
 	ifnull(ROUND(if(tem.lweight<0,0,tem.lweight),(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid =? )),0)lweight,
 	ifnull(ROUND(tem.actualweightminus,(select  inforvalue from sysopt  where inforname="decimalPlaces" and pastureid = ?)),0) MENGE
-	,tem.bname CHSTX,tem.sapcode CHSNO,tem.cattle FCWTS,(select  inforvalue from sysopt  where inforname="excess" and pastureid = ?) MATNR,tem.sapGoods LGORT
+	,tem.bname CHSTX,tem.sapcode CHSNO,tem.cattle FCWTS,(select  inforvalue from sysopt  where inforname="excess" and pastureid = ?) MATNR,tem.sapGoods LGORT,
+	? WERKS , ? BUDAT
 
 	 FROM (
 	(SELECT 
@@ -443,7 +459,7 @@ left join feed f on f.id = ftd.fid
 	HAVING d2.type = 0  order by b.sort,d2.fbarid)
 	
 	) tem
-	ORDER BY tem.d2sort,tem.feedname     `, pastureId, pastureId, pastureId, pastureId, date, pastureId, date).Query().List()
+	ORDER BY tem.d2sort,tem.feedname     `, pastureId, pastureId, pastureId, pastureinfo.Werks, now.Format("20060102"), pastureId, date, pastureId, date).Query().List()
 	if err != nil {
 		logs.Error(err)
 		return err
@@ -454,16 +470,11 @@ left join feed f on f.id = ftd.fid
 		  "DEST_ID": "DFEED",
 		  "BUSS_TP": "MM016"
 		},
-		"DATA": {
-		  "BUDAT": "%s",
-		  "WERKS": "%s",
-		  "ITEMS": %s
-		}
+		"DATA":  %s
+		
 	  }`
 	databyte, _ := json.Marshal(dataList)
 
-	now, _ := time.ParseInLocation("2006-01-02", date, time.Local)
-
 	data = fmt.Sprintf(data, now.Format("20060102"), pastureinfo.Werks, string(databyte))
 	url := "https://app.modernfarming.cn:7443/sap/QAS/Feed/MM032/LeftoverEntry"
 	postPush(url, data, 0, tx, pastureId)