|
@@ -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
|
|
|
+}
|