Browse Source

切换羊场分支

baishaojie 8 months ago
parent
commit
5bc1450e9a
8 changed files with 144 additions and 11 deletions
  1. BIN
      KPTAdmin64.exe
  2. BIN
      TMRWatchComm
  3. BIN
      TMRWatchComm.zip
  4. 1 1
      conf/app.ini
  5. 2 2
      http/handle/api/grfdApi.go
  6. 5 5
      http/handle/api/scheduled.go
  7. 134 3
      http/handle/sap/sap.go
  8. 2 0
      http/routers/app_api.go

BIN
KPTAdmin64.exe


BIN
TMRWatchComm


BIN
TMRWatchComm.zip


+ 1 - 1
conf/app.ini

@@ -75,7 +75,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = grfd
+Name = tmrwatch5
 TablePrefix =
 
 ShowXormlog = false

+ 2 - 2
http/handle/api/grfdApi.go

@@ -574,7 +574,7 @@ func AddOtherDevice() {
 		 AND d.pastureid =(SELECT column_default  FROM information_schema.COLUMNS WHERE table_name = 'recweight' AND table_schema = 'tmrwatch2' AND column_name = 'pastureid') 
 		 AND (SELECT COUNT(*) FROM downloadplandtl1 d1 WHERE  d.id=d1.PID AND d.pastureid=d1.pastureid  AND  d1.type = 0)>0
 		 AND (SELECT COUNT(*) FROM downloadedplan WHERE pastureid = d.pastureid AND downloadedplan.lpplantype=1 and mydate = d.mydate AND pid = d.pid AND iscompleted = 0) = 0
-		  group by d.pid,de.Fname`).Query().List()
+		  group by d.pid,de.Fname,d.mydate`).Query().List()
 
 	if err1 == nil && err2 == nil {
 		for i := 0; i < len(queryIdList); i++ {
@@ -765,7 +765,7 @@ func CronGRFD() {
 	}()
 	log.Println("Starting CronWXwork...")
 	c := cron.New()
-	err := c.AddFunc("0/55 * * * *", PostTmrData) //* * * * *, 从分钟开始 每55分钟执行一次
+	err := c.AddFunc("0/30 * * * *", PostTmrData) //* * * * *, 从分钟开始 每30分钟执行一次
 	if err != nil {
 		println("cron4 err", err.Error())
 	}

+ 5 - 5
http/handle/api/scheduled.go

@@ -135,11 +135,11 @@ func CronScheduled(ctx context.Context) {
 	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// xdmy := cron.New()
 	// err = xdmy.AddFunc("0 30 4 * * *", func() {
-	// 	// 	// 	//现代牧业sap同步
-	// 	sap.SyncMaterialOutbound()
-	// 	// 	// 	// 光明ud同步
-	// 	// 	// 	fmt.Println(time.Now())
-	// 	// 	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
+	// 	// 	//现代牧业sap同步
+	// sap.SyncMaterialOutbound()
+	// 	// 	// 光明ud同步
+	// 	// 	fmt.Println(time.Now())
+	// 	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
 	// })
 	// xdmy.Start()
 	// InitMqttClient()

+ 134 - 3
http/handle/sap/sap.go

@@ -31,6 +31,7 @@ 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
 }
 
@@ -113,6 +114,17 @@ func MaterialOutbound(c *gin.Context) {
 	appG.Response(http.StatusOK, e.SUCCESS, true)
 }
 
+func SurplusOutbound(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	pastureId := fsion.Get("pastureid").ValueStr()
+	date := fsion.Get("date").ValueStr()
+
+	surplusOutbound(pastureId, date)
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+}
+
 func materialOutbound(pastureId, date string) error {
 
 	tx := restful.Engine.NewSession()
@@ -129,7 +141,7 @@ func materialOutbound(pastureId, date string) error {
 	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,if( LOCATE("_剩料","日粮_剩料") = 0 , tem.sapcode,(select  inforvalue from sysopt  where inforname="excess" and pastureid =? ) ) CHSNO,tem.cattle FCWTS,tem.MATNR,tem.sapGoods LGORT
+	,tem.bname CHSTX,tem.sapcode CHSNO,tem.cattle FCWTS,tem.MATNR,tem.sapGoods LGORT
 
 	 FROM (
 	(SELECT 
@@ -207,7 +219,7 @@ left join feed f on f.id = ftd.fid
 	
 	) 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, date, pastureId, date).Query().List()
 	if err != nil {
 		logs.Error(err)
 		return err
@@ -232,7 +244,6 @@ left join feed f on f.id = ftd.fid
 	url := "http://192.168.61.117/SAPP0/Feed/MM016/StockOut"
 	postPush(url, data, 0, tx, pastureId)
 	return nil
-	// appG.Response(http.StatusOK, e.SUCCESS, true)
 }
 
 func postPush(url, data string, msgtype int, tx *xorm.Session, pastureId string) (interface{}, bool) {
@@ -338,3 +349,123 @@ func SyncSapFeed(c *gin.Context) {
 
 	// return
 }
+
+func surplusOutbound(pastureId, date string) error {
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	pastureinfo := new(udPastureInfo)
+	err := tx.SQL(`select * from pasture where pastureid = ?`, pastureId).GetFirst(pastureinfo).Error
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+
+	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
+
+	 FROM (
+	(SELECT 
+	d2.type,
+	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
+	SUM(
+	  d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
+	  d1.lweight*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid and ftd2.date= ftp.date  ))
+	 )lweight,
+	d1.sort sort,
+		  SUM(
+		 if ( (SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date) > 0 ,
+	  d2.actualweightminus/(SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
+	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid and ftd2.date= ftp.date )),
+		
+		 d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
+	  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid ))
+		)
+	 )actualweightminus,b.sort as d2sort,b.bname,b.sapcode, b.cattlecode ,f.sapGoods ,(select cattle from feedtemplet where id = d.tempid) cattle
+	 
+	 FROM 
+	downloadedplan d
+	
+	JOIN downloadplandtl2 d2
+	ON d.pastureid = d2.pastureid AND d2.pid = d.id   and d2.type = 0
+	JOIN downloadplandtl1 d1
+	ON d.pastureid = d1.pastureid AND d1.flpid = d2.flpid AND d1.type = 0 AND d2.date = d1.date
+	LEFT JOIN ftdetaildate ftd ON  ftd.pastureid =d1.pastureid AND ftd.ftid = d1.fid AND d1.feedcode = '-1' AND ftd.date = d.mydate AND ftd.version = d.tversion
+	left join bar b  on b.pastureid =d1.pastureid and b.id = d2.fbarid 
+	left join feed f on f.id = d1.fid
+	left join feedtempletdate ftp  on ftp.id = d.tempid  AND ftp.date = ftd.date
+	
+
+	WHERE d.pastureid = ? AND  d.mydate = ? and d1.feedcode  != -1   and  b.sapCode is not null   and  d1.fname like concat('%','_剩料','%')
+	GROUP BY d2.fbarid,IFNULL(ftd.fname,d1.fname )
+	HAVING d2.type = 0  order by b.sort,d2.fbarid)
+	
+	UNION
+	
+		(SELECT 
+	d2.type,
+	 d2.fname,IFNULL(ftd.fname,d1.fname ) feedname,
+	SUM(
+	  d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
+	  d1.lweight*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid and ftd2.date= ftd1.date ))
+	 )lweight,
+	d1.sort sort,
+		  SUM(
+ if ( (SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)  > 0 ,
+  d2.actualweightminus/(SELECT SUM(actualweightminus) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
+  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetail ftd2 WHERE ftd2.pastureid =d1.pastureid AND ftd2.ftid = d1.fid )),
+	
+	 d2.lweight/(SELECT SUM(lweight) FROM downloadplandtl2  d2t WHERE d2t.pastureid = d2.pastureid AND d2t.flpid = d2.flpid AND d2t.type = 0 AND d2t.date = d2.date)*
+  d1.actualweightminus*IF(ftd.id IS NULL,1,ftd.fweight/(SELECT SUM(ftd2.fweight) FROM ftdetaildate ftd2 WHERE  ftd2.date = d1.date AND ftd2.version = ftd1.version and ftd1.id = ftd2.ftid  ))
+	)
+ )actualweightminus,b.sort as d2sort,b.bname,b.sapcode, b.cattlecode ,f.sapGoods ,(select cattle from feedtemplet where id = d.tempid) cattle
+	 
+	 FROM 
+	downloadedplan d
+
+	JOIN downloadplandtl2 d2
+	ON d.pastureid = d2.pastureid AND d2.pid = d.id   and d2.type = 0
+	JOIN downloadplandtl1 d1
+	ON d.pastureid = d1.pastureid AND d1.flpid = d2.flpid AND d1.type = 0 AND d2.date = d1.date
+	left join bar b  on b.pastureid =d1.pastureid and b.id = d2.fbarid 
+	
+	left join feedtempletdate  ftd1 on   d1.feedcode = '-1'  and ftd1.date = d1.date and ftd1.id = d1.fid 
+LEFT JOIN ftdetaildate ftd ON  ftd.pastureid =d1.pastureid AND ftd.ftid = ftd1.id AND d1.feedcode = '-1' AND ftd.date =d1.date AND ftd.version = ftd1.version
+
+
+left join feed f on f.id = ftd.fid
+	WHERE d.pastureid = ? AND  d.mydate = ? and d1.feedcode  = -1   and  b.sapCode is not null    and d1.fname like concat('%','_剩料','%')
+	GROUP BY d2.fbarid,IFNULL(ftd.fname,d1.fname )
+	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()
+	if err != nil {
+		logs.Error(err)
+		return err
+	}
+
+	data := `{
+		"DEST": {
+		  "DEST_ID": "DFEED",
+		  "BUSS_TP": "MM016"
+		},
+		"DATA": {
+		  "BUDAT": "%s",
+		  "WERKS": "%s",
+		  "ITEMS": %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)
+	return nil
+}

+ 2 - 0
http/routers/app_api.go

@@ -193,6 +193,8 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 			apiV1.POST("/biginventory", api.AddBigInventory)
 			//sap原料上传
 			apiV1.POST("/material/sap/upload", sap.MaterialOutbound)
+			//sap剩料上传
+			apiV1.POST("/surplus/sap/upload", sap.SurplusOutbound)
 
 			apiV1.POST("/downloadplandtl1/image/upload", api.UploadFile1)