Browse Source

Merge branch 'master' into develop

Yi 1 year ago
parent
commit
e837fe91df

BIN
TMRWatchComm


BIN
TMRWatchComm.zip


+ 28 - 3
conf/app.ini

@@ -45,9 +45,34 @@ GRFDURL = http://120.48.30.31:88
 [database]
 Type = mysql
 User = root
-Host = 127.0.0.1:3306
-Password = 123456
-Name = tmrwatch2
+Password = root
+#Host = 8.130.17.8:3306
+Host = 192.168.1.93:3326
+#Host = 127.0.0.1:3316
+#Name = haiyuan
+#Password = root
+#Password = root
+#Password = kptzhu@163.com
+#Host = 192.168.1.50:3326
+#Password = root123456
+#Password = keep
+
+#Password = kptzhu@163.com
+#Password = kpt123456*
+#Password = kepaiteng!QAZ
+#Host = 47.92.52.73:3306
+#Host = 127.0.0.1:3306
+#Host = 210.16.186.252:3326
+
+#Host = 210.16.186.252:3326
+#Host = 127.0.0.1:3309
+#Name = equipment
+#Name = eqdev
+#Name = eq0422
+#Name = tmrgo
+#Password = kepaiteng!QAZ
+#Host = 222.73.129.15:31306
+Name = tmrwatch5
 TablePrefix =
 
 ShowXormlog = false

BIN
dist.zip


BIN
dist/favicon.ico


File diff suppressed because it is too large
+ 0 - 0
dist/index.html


File diff suppressed because it is too large
+ 0 - 0
dist/static/css/app.0efec87a.css


File diff suppressed because it is too large
+ 0 - 0
dist/static/css/chunk-elementUI.c1c3b808.css


File diff suppressed because it is too large
+ 0 - 0
dist/static/css/chunk-libs.1664ae71.css


BIN
dist/static/fonts/element-icons.535877f5.woff


BIN
dist/static/fonts/element-icons.732389de.ttf


BIN
dist/static/img/404.a57b6f31.png


BIN
dist/static/img/404_cloud.0f4bc32b.png


File diff suppressed because it is too large
+ 28 - 0
dist/static/img/iconfont.7d9f8392.svg


BIN
dist/static/img/logo.afed751a.png


BIN
dist/static/img/logo1.0121925c.png


BIN
dist/static/img/logo_u3.3c77f543.png


BIN
dist/static/img/nlogin-bg1.77301f56.jpg


BIN
dist/static/img/row-bg3.b3be7548.png


BIN
dist/static/img/topBg.69ecd1e1.png


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/app.1c90c226.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-218b9b2f.443d0c85.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-52ecc0ac.ba542cb9.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-5c4dc4a9.9bfbd7f4.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-b702d234.fadfa57f.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-elementUI.c961dc79.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-libs.d1627c47.js


+ 2 - 65
go.mod

@@ -1,6 +1,6 @@
 module tmr-watch
 
-go 1.17
+go 1.16
 
 require (
 	gitee.com/xuyiping_admin/go_proto v0.0.0-20231020024751-e01ca61df346
@@ -30,7 +30,6 @@ require (
 	github.com/pkg/errors v0.9.1
 	github.com/recoilme/slowpoke v2.0.1+incompatible
 	github.com/robfig/cron v1.2.0
-	github.com/sirupsen/logrus v1.9.3
 	github.com/swaggo/gin-swagger v1.2.0
 	github.com/swaggo/swag v1.16.1
 	github.com/tealeg/xlsx v1.0.5
@@ -40,75 +39,13 @@ require (
 
 require (
 	github.com/Chronokeeper/anyxml v0.0.0-20160530174208-54457d8e98c6 // indirect
-	github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
 	github.com/CloudyKit/jet v2.1.2+incompatible // indirect
-	github.com/KyleBanks/depth v1.2.1 // indirect
-	github.com/PuerkitoBio/purell v1.1.1 // indirect
-	github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
 	github.com/agrison/go-tablib v0.0.0-20160310143025-4930582c22ee // indirect
 	github.com/agrison/mxj v0.0.0-20160310142625-1269f8afb3b4 // indirect
-	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/bndr/gotabulate v1.1.2 // indirect
-	github.com/bytedance/sonic v1.9.1 // indirect
-	github.com/cespare/xxhash/v2 v2.2.0 // indirect
-	github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
 	github.com/clbanning/mxj v1.8.4 // indirect
-	github.com/faabiosr/cachego v0.15.0 // indirect
-	github.com/fatih/structs v1.1.0 // indirect
-	github.com/fsnotify/fsnotify v1.4.9 // indirect
-	github.com/gabriel-vasile/mimetype v1.4.2 // indirect
-	github.com/getsentry/sentry-go v0.23.0 // indirect
-	github.com/gin-contrib/sse v0.1.0 // indirect
-	github.com/go-openapi/jsonpointer v0.19.5 // indirect
-	github.com/go-openapi/jsonreference v0.19.6 // indirect
-	github.com/go-openapi/spec v0.20.4 // indirect
-	github.com/go-openapi/swag v0.19.15 // indirect
-	github.com/go-playground/locales v0.14.1 // indirect
-	github.com/go-playground/universal-translator v0.18.1 // indirect
-	github.com/go-playground/validator/v10 v10.14.0 // indirect
-	github.com/goccy/go-json v0.10.2 // indirect
-	github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
-	github.com/golang-sql/sqlexp v0.1.0 // indirect
-	github.com/golang/protobuf v1.5.3 // indirect
-	github.com/golang/snappy v0.0.4 // indirect
-	github.com/gorilla/websocket v1.4.2 // indirect
-	github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
-	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
-	github.com/huandu/xstrings v1.4.0 // indirect
-	github.com/josharian/intern v1.0.0 // indirect
-	github.com/klauspost/cpuid/v2 v2.2.4 // indirect
-	github.com/leodido/go-urn v1.2.4 // indirect
-	github.com/lestrrat-go/strftime v1.0.6 // indirect
-	github.com/mailru/easyjson v0.7.7 // indirect
-	github.com/mattn/go-isatty v0.0.19 // indirect
-	github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
-	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
-	github.com/modern-go/reflect2 v1.0.2 // indirect
-	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
-	github.com/pelletier/go-toml/v2 v2.0.8 // indirect
-	github.com/prometheus/client_golang v1.16.0 // indirect
-	github.com/prometheus/client_model v0.3.0 // indirect
-	github.com/prometheus/common v0.42.0 // indirect
-	github.com/prometheus/procfs v0.10.1 // indirect
 	github.com/recoilme/pudge v1.0.3 // indirect
-	github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
-	github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c // indirect
-	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
-	github.com/ugorji/go/codec v1.2.11 // indirect
 	github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be // indirect
-	go.uber.org/atomic v1.7.0 // indirect
-	go.uber.org/multierr v1.6.0 // indirect
-	golang.org/x/arch v0.3.0 // indirect
-	golang.org/x/crypto v0.9.0 // indirect
-	golang.org/x/net v0.10.0 // indirect
-	golang.org/x/sync v0.2.0 // indirect
-	golang.org/x/sys v0.8.0 // indirect
-	golang.org/x/text v0.9.0 // indirect
-	golang.org/x/tools v0.7.0 // indirect
-	google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect
-	google.golang.org/grpc v1.57.0 // indirect
-	google.golang.org/protobuf v1.31.0 // indirect
 	gopkg.in/flosch/pongo2.v3 v3.0.0-20141028000813-5e81b817a0c4 // indirect
-	gopkg.in/yaml.v2 v2.4.0 // indirect
-	gopkg.in/yaml.v3 v3.0.1 // indirect
+	xorm.io/xorm v1.3.4 // indirect
 )

File diff suppressed because it is too large
+ 1018 - 12
go.sum


+ 3 - 3
http/handle/api/ops.go

@@ -3196,9 +3196,9 @@ func UpdateFTdetail(c *gin.Context) {
 
 						weight, _ := strconv.ParseFloat(fpd["weight"].(string), 64)
 						oldweight, _ := strconv.ParseFloat(old["weight"].(string), 64)
-						if weight > oldweight {
-							return
-						}
+						// if weight > oldweight {
+						// 	return
+						// }
 
 						var w float64
 						var status int

+ 29 - 14
http/handle/api/scheduled.go

@@ -20,6 +20,9 @@ import (
 	"tmr-watch/pkg/e"
 	"tmr-watch/pkg/logging"
 
+	// "../../routers/api/gm"
+	// "../../routers/api/sap"
+	// "../../routers/restful"
 	"github.com/Anderson-Lu/gofasion/gofasion"
 	"github.com/astaxie/beego/logs"
 	"github.com/gin-gonic/gin"
@@ -132,12 +135,18 @@ func CronScheduled(ctx context.Context) {
 	// //圣牧自动同步前天有进行中的任务
 	manualUdData(pastureinfo)
 
+	//现代牧业sap同步
 	// xdmy := cron.New()
 	// dayCron.AddFunc("50 04 * * *", func() {
 	// 	sap.SyncMaterialOutbound()
 	// })
 	// xdmy.Start()
 
+	//光明ud同步
+	// gm.UdFeedSync(pastureinfo.Pastureid)
+
+	// gm.GmUdSync(pastureinfo.Pastureid, pastureinfo.Werks)
+
 }
 
 type ScheduledInfo struct {
@@ -745,8 +754,8 @@ func (h *ScheduledDown) SyncFeedp(pastureid string, feedpList []interface{}) err
 		// insertSql := `insert into feedp(pastureid,barname,barid,softccount)VALUES(?,?,?,?)
 		// ON DUPLICATE KEY UPDATE softccount = ?  `
 		// _, err = tx.SQL(insertSql, pastureid, barName, barId, cowCount, cowCount).Execute()
-		fmt.Println(barName)
-		_, err = tx.SQL(`update feedp fp set fp.softccount = ? where  (select bcode from bar where id = fp.id ) = ? `, cowCount, barCode).Execute()
+		fmt.Println(barCode)
+		_, err = tx.SQL(`update feedp fp set fp.softccount = ? where  (select bcode from bar where id = fp.id ) = ? `, cowCount, barName).Execute()
 		if err != nil {
 			tx.Rollback()
 			logs.Error("syncFeedp-error-7:", err)
@@ -1767,16 +1776,22 @@ func udFeedpSync(pastureinfo *udPastureInfo) error {
 	return nil
 }
 
-// func UdFeedpSync(c *gin.Context) {
-// 	appG := app.Gin{C: c}
-// 	dataByte, _ := ioutil.ReadAll(c.Request.Body)
-// 	fsion := gofasion.NewFasion(string(dataByte))
-// 	pastureId := fsion.Get("pastureId").ValueStr()
-
-// 	pastureinfo := new(udPastureInfo)
-// 	pastureinfo.Pastureid = pastureId
-// 	udFeedpSync(pastureinfo)
+func UdFeedpSync(c *gin.Context) {
+	appG := app.Gin{C: c}
+	dataByte, _ := ioutil.ReadAll(c.Request.Body)
+	fsion := gofasion.NewFasion(string(dataByte))
+	pastureId := fsion.Get("pastureId").ValueStr()
 
-// 	appG.Response(http.StatusOK, e.SUCCESS, true)
-// 	return
-// }
+	// 	pastureinfo := new(udPastureInfo)
+	// 	pastureinfo.Pastureid = pastureId
+	// 	udFeedpSync(pastureinfo)
+	pastureinfo := new(udPastureInfo)
+	pastureinfo.Pastureid = pastureId
+	err := udFeedpSync(pastureinfo)
+	if err != nil {
+		appG.Response(http.StatusOK, e.ERROR, err.Error())
+		return
+	}
+	appG.Response(http.StatusOK, e.SUCCESS, true)
+	// return
+}

+ 2 - 1
http/handle/api/udsync.go

@@ -24,7 +24,7 @@ func UDSync() {
 	defer tx.Close()
 
 	pastureinfo := new(udPastureInfo)
-	err := tx.SQL(`select token,pastureid  from pasture  p join ( select column_default   from    information_schema.COLUMNS 
+	err := tx.SQL(`select token,pastureid,werks  from pasture  p join ( select column_default   from    information_schema.COLUMNS 
 		WHERE table_name = 'recweight' AND table_schema = 'tmrwatch2' AND column_name = 'pastureid') pas  
 		where p.pastureid = pas.column_default`).GetFirst(pastureinfo).Error
 	if err != nil {
@@ -362,6 +362,7 @@ func syncFeedtemplet(pastureid string, feedtempletList []map[string]interface{})
 type udPastureInfo struct {
 	Token     string `xorm:"token"`
 	Pastureid string `xorm:"pastureid"`
+	Werks     string `xorm:"werks"`
 }
 
 func httpGet(farmId, method string) []interface{} {

+ 362 - 0
http/handle/gm/udservice.go

@@ -0,0 +1,362 @@
+package gm
+
+import (
+	"bytes"
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"time"
+	"tmr-watch/conf/setting"
+	"tmr-watch/http/handle/restful"
+	"tmr-watch/pkg/logging"
+
+	"github.com/astaxie/beego/logs"
+	"github.com/xormplus/xorm"
+)
+
+// "../../../pkg/setting"
+// "../../../routers/restful"
+
+func GmUdSync(pastureId, farmId string) {
+	fmt.Println(111)
+}
+
+func UdBarSync(pastureId, farmId string) {
+	url := fmt.Sprintf("http://172.16.86.95:8080/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=%s&method=downloadpen", farmId)
+	barByte := getPull(url)
+
+	barMap := make(map[string]interface{})
+	json.Unmarshal(barByte, &barMap)
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
+	values(?,?,?,?,?,now(),?,now(),?)`, pastureId, "", string(barByte), "", "", 3, url)
+
+	for _, item := range barMap["msg"].([]interface{}) {
+		bar := item.(map[string]interface{})
+		barname := bar["barname"].(string) + "_ud"
+		barExist, _ := tx.SQL(` select count(1) from bar where bcode = ? `, bar["barcode"]).Exist()
+		tx.Exec(`insert into bar(pastureid,bcode,bname)values(?,?,?)   ON DUPLICATE KEY UPDATE  bname = ? `, pastureId, bar["barcode"], barname, barname)
+		_, _ = tx.Exec(`insert into feedp(pastureid,barid,barname,softccount,ccount)values(?,(select id from bar where bcode=  ? and pastureId = ? ),?,?,?)
+		 ON DUPLICATE KEY UPDATE  softccount = ? `,
+			pastureId, bar["barcode"], pastureId, barname, bar["cowcount"], bar["cowcount"], bar["cowcount"])
+		// fmt.Println(err)
+		if !barExist {
+			tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
+				pastureId, bar["barcode"], 1, barname)
+			tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
+				pastureId, bar["barcode"], 2, barname)
+			tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
+				pastureId, bar["barcode"], 3, barname)
+			tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
+				pastureId, bar["barcode"], 4, barname)
+			tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
+				pastureId, bar["barcode"], 5, barname)
+			tx.Exec(`insert into fpdetail(pastureId,barid,weight,ptsrate,times,barname) values(?,(select id from bar where bcode=  ? and pastureId = ? ),0,0,?,?)`,
+				pastureId, bar["barcode"], 6, barname)
+		}
+	}
+
+}
+
+func UdFeedSync(pastureId, farmId string) {
+	url := fmt.Sprintf("http://172.16.86.95:8080/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=%s&method=downloadmaterial", farmId)
+	feedByte := getPull(url)
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
+	values(?,?,?,?,?,now(),?,now(),?)`, pastureId, "", string(feedByte), "", "", 3, url)
+
+	feedMap := make(map[string]interface{})
+	json.Unmarshal(feedByte, &feedMap)
+
+	for _, item := range feedMap["msg"].([]interface{}) {
+		fmt.Println(item)
+		feed := item.(map[string]interface{})
+		feedname := feed["feedname"].(string) + "_ud"
+		feedClassExist, _ := tx.SQL(` select count(1) from feedclass where fccode = ? and pastureId = ? `, feed["feedclass"], pastureId).Exist()
+
+		if !feedClassExist {
+			tx.Exec(`insert into feedclass(pastureId,fcname,fccode,bigfeedclassname,sort) values(?,?,?,?,(select max(sort) +1 from feedclass where pastureId = ? and fccode = ? ))`,
+				pastureId, feed["feedclass"], feed["feedclass"], feed["feedclass"], pastureId, feed["feedclass"])
+		}
+
+		ids, err := setting.SnowIds.NextId()
+		if err != nil {
+			ids = time.Now().UnixNano()
+			logging.Info("create SnowIds err", err)
+		}
+
+		_, err = tx.Exec(`insert into feed(id,pastureId,feedcode,fname,fclassid,fclass) values(?,?,?,?,(select id from feedclass where fccode = ? and pastureId = ? ),?)
+		ON DUPLICATE KEY UPDATE fname = ? `,
+			ids, pastureId, feed["feedcode"], feedname, feed["feedclass"], pastureId, feed["feedclass"], feedname)
+	}
+
+}
+
+func getPull(url string) []byte {
+	// 创建一个HTTP客户端
+	client := &http.Client{}
+
+	// 创建一个GET请求
+	req, err := http.NewRequest("GET", url, nil)
+	if err != nil {
+		fmt.Println("创建请求时发生错误:", err)
+		return nil
+	}
+
+	// 发送请求
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Println("发送请求时发生错误:", err)
+		return nil
+	}
+	defer resp.Body.Close()
+
+	// 读取响应内容
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		fmt.Println("读取响应时发生错误:", err)
+		return nil
+	}
+
+	// 打印响应内容
+	// fmt.Println(string(body))
+
+	return body
+}
+
+//搅拌
+func UdUtirPush(pastureId, farmId string) error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	dataList, err := tx.SQL(`select d1.date loadDate,d.times loadShift,d.datacaptureno  tmrNo,ft.id recipeId,ft.ccname,d1.feedcode,d1.fname,f.fclass,
+	f.dry * d1.actualweightminus  dmPct,d1.sort mixNo,d1.feedallowratio allowableError ,d1.lweight expWeight,d1.actualweightminus actualWeight,d1.begintime startTime,
+	d1.intime endTime, d.tmrtname tmrName , d.pid id ,ftd.sort premixFeedSort ,
+	 (select feedcode from feed where id = ftd.fid) premixFeedId,ftd.fname  premixFeedName,
+	ftd.fweight / (select sum(fweight)  from ftdetaildate  where  date =  d1.date and ftid = d1.fid ) *  d1.actualweightminus premixFeedWeight
+
+	from downloadplandtl1  d1 join  downloadedplan d on d.id = d1.pid
+	left join feedtempletdate ft  on ft.id = d.tempid  and ft.date = d1.date
+	left join feed f on f.feedcode  = d1.feedcode
+	left join ftdetaildate  ftd  on  ftd.date =  d1.date and ftd.ftid = d1.fid
+	where d1.date = ?`, now).Query().List()
+	if err != nil {
+		logging.Error(err)
+		return err
+	}
+
+	dataByte, _ := json.Marshal(&dataList)
+
+	reqJson := `{
+    "reqMethod": "PARTY",
+    "param": {
+        "code": "1",
+        "method": "uploadadddata",
+        "resultData": %s,
+        "farmId": %s,
+        "rowCount": %d,
+        "errMessage": ""
+    },
+    "regCode": "cpt180511",
+    "command": "3d6e4752",
+    "apiId": "getCptData"
+}`
+
+	reqJson = fmt.Sprintf(reqJson, string(dataByte), farmId, len(dataList))
+	postPush(reqJson, 0, tx, pastureId)
+	fmt.Println(reqJson)
+	return nil
+}
+
+func UdMaterialIssuePush(pastureId, farmId string) error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	dataList, err := tx.SQL(`SELECT  dd.feedsort feedSort, dd.feedcode feedId,dd.fname feedName,
+	d.id,IFNULL(ft.id,d2.feedtempletid ) recipeId,
+	IFNULL(d.templetName,d2.feedtempletName ) recipeName,
+	date_format(d.mydate,'%Y-%m-%d') as dropDate,ifnull((select sort from downloadedplan where pid=d.pid and lpplanType !=d.lpplanType and mydate=d.mydate),d.sort) as tmrNo,
+	d.Times as dropShift,b.bcode as penId,d2.Fname as penName,fp.CCOUNT as cowCount, d2.SORT as feedingNo,
+ifnull(ROUND(d2.lweight * (dd.actualweightminus/ (select sum(actualweightminus) from downloadplandtl1 where pid = dd.pid and type = 0) ),2) ,0)as expWeight,
+	ifnull(d2.ActualWeightMinus,0) as actualWeight, ifnull(date_format(timestamp(d2.InTime,CONCAT('-',d2.processTime)),'%Y-%m-%d %H:%i:%s'),d.mydate) as startTime,
+	ifnull(date_format(d2.InTime,'%Y-%m-%d %H:%i:%s'),d.mydate) as endTime,ifnull((SELECT dr.driver FROM dutyrecord dr
+WHERE dr.pastureid = d.pastureid AND dr.eqid = d.tmrid AND dr.times= d.times  AND dr.operatetime <=d.mydate
+ORDER BY dr.operatetime DESC LIMIT 1),"") as tmrName ,d.tmrtname equipmentId ,
+dd.fname,
+  ifnull(TRIM(if(( select sum(dd2.actualweightminus) from downloadplandtl2 dd2 where dd2.pid = d2.pid) >0 ,   ROUND( d2.actualweightminus/( select sum(dd2.actualweightminus) from downloadplandtl2 dd2 where dd2.pid = d2.pid) * (dd.actualweightminus ),2), ROUND( d2.lweight/( select sum(dd2.lweight) from downloadplandtl2 dd2 where dd2.pid = d2.pid) * (dd.actualweightminus ),2))),0) feedWeight
+
+	,ftd.sort premixFeedSort ,
+	 (select feedcode from feed where id = ftd.fid) premixFeedId,ftd.fname  premixFeedName,
+	ftd.fweight / (select sum(fweight)  from ftdetaildate  where  date =  dd.date and ftid = dd.fid ) *  dd.actualweightminus premixFeedWeight
+
+	from  downloadedplan d
+	LEFT JOIN downloadplandtl2 d2 on d.id=d2.PID
+	LEFT JOIN (select dd.pid as lppid,dd1.* from downloadedplan dd join downloadplandtl1  dd1 on dd1.pid = dd.id and dd1.type = 0
+		where dd.mydate= date_format(?,'%Y-%m-%d')  and dd.lpplanType in (0,1) ) dd on dd.lppid = d.pid
+
+	LEFT JOIN feedp fp on d2.FBarID=fp.barid
+	left join bar b on fp.barid = b.id and d.pastureid = b.pastureid
+	left JOIN feedtemplet ft on d.tempid=ft.id
+		left join ftdetaildate  ftd  on  ftd.date =  dd.date and ftd.ftid = dd.fid
+
+	where d.mydate= date_format(?,'%Y-%m-%d')  and d.lpplanType!=1 and d.pastureid = ?   and dd.fname is not null  order by tmrno `, now, now, pastureId).Query().List()
+	if err != nil {
+		logging.Error(err)
+		return err
+	}
+
+	dataByte, _ := json.Marshal(&dataList)
+
+	reqJson := `{
+    "reqMethod": "PARTY",
+    "param": {
+        "code": "1",
+        "method": "uploaddiliverdata",
+        "resultData": %s,
+        "farmId": %s,
+        "rowCount": %d,
+        "errMessage": ""
+    },
+    "regCode": "cpt180511",
+    "command": "3d6e4752",
+    "apiId": "getCptData"
+}`
+	reqJson = fmt.Sprintf(reqJson, string(dataByte), farmId, len(dataList))
+	//  '0饲喂  1剩料  2原料  3栏舍  4配方 5栏舍牛头数 6库存',
+	postPush(reqJson, 0, tx, pastureId)
+	return nil
+}
+
+func UdBarFeedRemainPush(pastureId, farmId string) error {
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	now := time.Now().AddDate(0, 0, 0).Format("2006-01-02")
+	dataList, err := tx.SQL(`SELECT
+	'' startTime,
+	'' endTime,
+	br.RemainDate AS overplusDate,
+	 b.bcode AS penId,
+	b.BNAME AS penName,
+	br.Remain AS actualWeight
+FROM
+	barfeedremain br
+	LEFT JOIN feedp fp ON br.barid = fp.id
+	left join bar b on b.id = fp.barid
+WHERE
+	date_format( RemainDate, '%Y-%m-%d' ) =? `, now).Query().List()
+	if err != nil {
+		logging.Error(err)
+		return err
+	}
+
+	dataByte, _ := json.Marshal(&dataList)
+
+	reqJson := `{
+    "reqMethod": "PARTY",
+    "param": {
+        "code": "1",
+        "method": "uploadoverplusdata",
+        "resultData": %s,
+        "farmId": %s,
+        "rowCount": %d,
+        "errMessage": ""
+    },
+    "regCode": "cpt180511",
+    "command": "3d6e4752",
+    "apiId": "getCptData"
+}`
+	reqJson = fmt.Sprintf(reqJson, string(dataByte), farmId, len(dataList))
+	//  '0饲喂  1剩料  2原料  3栏舍  4配方 5栏舍牛头数 6库存',
+	postPush(reqJson, 1, tx, pastureId)
+	return nil
+}
+
+// method:
+// 配方 getfeedtempletinfo
+// 搅拌数据 uploadadddata
+// 撒料数据 uploaddiliverdata
+// 剩料 uploadoverplusdata
+
+func UdFeedtempletPush(pastureId, farmId string) error {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	dataList, err := tx.SQL(`SELECT
+	ft.ID AS recipeId,
+	ft.TNAME AS recipeName,
+	ifnull( f.feedcode, f.id ) AS ingId,
+	f.FNAME AS ingName,
+	round( f.dry * ftd.FWEIGHT, 2 ) AS dmQty,
+	ftd.FWEIGHT AS afQty,
+	ftd.SORT AS mixNo,
+	round( f.Uprice * ftd.FWEIGHT, 2 ) AS recipeCost,
+	fc.FCNAME AS ingType,
+	f.AllowRatio AS allowableError 
+FROM
+	feedtemplet ft
+	LEFT JOIN ftdetail ftd ON ft.id = ftd.FTID
+	LEFT JOIN feed f ON ftd.FID = f.id
+	LEFT JOIN feedclass fc ON f.FCLASS = fc.id 
+WHERE
+	ft.ENABLE = 1 
+	AND ft.isDelete != 1 `).Query().List()
+	if err != nil {
+		logging.Error(err)
+		return err
+	}
+
+	dataByte, _ := json.Marshal(&dataList)
+
+	reqJson := `{
+    "reqMethod": "PARTY",
+    "param": {
+        "code": "1",
+        "method": "getfeedtempletinfo",
+        "resultData": %s,
+        "farmId": %s,
+        "rowCount": %d,
+        "errMessage": ""
+    },
+    "regCode": "cpt180511",
+    "command": "3d6e4752",
+    "apiId": "getCptData"
+}`
+	reqJson = fmt.Sprintf(reqJson, string(dataByte), farmId, len(dataList))
+
+	postPush(reqJson, 4, tx, pastureId)
+	return nil
+}
+
+func postPush(data string, msgtype int, tx *xorm.Session, pastureId string) {
+	url := "http://dev.unidairy.cn:8011/copartner_uploads/"
+	var jsonStr = []byte(data)
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
+	if err != nil {
+		logs.Error(err)
+		// return nil
+	}
+
+	// req.SetBasicAuth("zinf_TMR", "zinf_TMR@1234")  测试线密码
+	// req.SetBasicAuth("zinf_TMR", "$C2Cj$\\Uv#")
+	req.Header.Set("Content-Type", "application/json")
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		logs.Error(err)
+		return
+	}
+
+	defer resp.Body.Close()
+	body, _ := ioutil.ReadAll(resp.Body)
+	fmt.Println(string(body))
+	fmt.Println("11111111111111", time.Now())
+	tx.Exec(` insert into saplog(pastureId,request,response,status,msgtext,createTime,msgtype,dataDate,url)
+	values(?,?,?,?,?,now(),?,now(),?)`, pastureId, data, string(body), "", "", msgtype, url)
+
+}

+ 1 - 1
http/handle/sap/sap.go

@@ -192,7 +192,7 @@ func materialOutbound(pastureId, date string) error {
 	 
 	 FROM 
 	downloadedplan d
-	
+
 	JOIN downloadplandtl2 d2
 	ON d.pastureid = d2.pastureid AND d2.pid = d.id   and d2.type = 0
 	JOIN downloadplandtl1 d1

+ 10 - 0
http/routers/app_api.go

@@ -200,6 +200,16 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 			apiV1.POST("/dailydata/edit", api.UpdateDailyData)
 			apiV1.POST("/formulastatistics", api.GetFormulaStatistics)
 
+			apiV1.POST("/sap/feed", sap.SyncSapFeed)
+
+			apiV1.POST("/sap/bar", sap.SyncSapBar)
+
+			apiV1.POST("/sap/material", sap.MaterialOutbound)
+
+			apiV1.POST("/feedbackup/check", api.CheckFeedTrgaddress)
+
+			apiV1.POST("/ud/feedp/sync", api.UdFeedpSync)
+
 		}
 
 		//不需要登录验证的接口

+ 3 - 0
linux64.bat

@@ -0,0 +1,3 @@
+set GOARCH=amd64
+set GOOS=linux
+go build -o tmrgo

+ 0 - 204
pkg/logger/logrus/log.go

@@ -1,204 +0,0 @@
-package logrus
-
-import (
-	"fmt"
-	"kpt-tmr-group/pkg/tool"
-	"path"
-	"runtime"
-	"time"
-
-	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
-	"github.com/sirupsen/logrus"
-)
-
-var (
-	logPath     = "./logger"
-	logFileName = fmt.Sprintf("/logrus-%s.log", time.Now().Format(tool.DateTime))
-)
-
-func init() {
-	// Log as JSON instead of the default ASCII formatter.
-	logrus.SetFormatter(&logrus.JSONFormatter{
-		CallerPrettyfier: func(f *runtime.Frame) (string, string) {
-			filename := path.Base(f.File)
-			return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
-		},
-	})
-
-	// Output to stdout instead of the default stderr
-	// Can be any io.Writer, see below for File example
-	writer, _ := rotatelogs.New(
-		fmt.Sprintf("%s%s", logPath, logFileName),
-		// rotatelogs.WithLinkName(logPath),
-		rotatelogs.WithMaxAge(time.Duration(7*24)*time.Hour),     // 备份7天的日志
-		rotatelogs.WithRotationTime(time.Duration(24)*time.Hour), // 24小时切割一次日志
-	)
-	logrus.SetOutput(writer) // logrus 设置日志的输出方式
-	// Only log the warning severity or above.
-	logrus.SetLevel(DebugLevel)
-}
-
-// These are the different logging levels. You can set the logging level to log
-// on your instance of logger, obtained with `logrus.New()`.
-const (
-	// PanicLevel level, highest level of severity. Logs and then calls panic with the
-	// message passed to Debug, Info, ...
-	PanicLevel Level = iota
-	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
-	// logging level is set to Panic.
-	FatalLevel
-	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
-	// Commonly used for hooks to send errors to an error tracking service.
-	ErrorLevel
-	// WarnLevel level. Non-critical entries that deserve eyes.
-	WarnLevel
-	// InfoLevel level. General operational entries about what's going on inside the
-	// application.
-	InfoLevel
-	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
-	DebugLevel
-	// TraceLevel level. Designates finer-grained informational events than the Debug.
-	TraceLevel
-)
-
-// Entry is the final or intermediate Logrus logging entry. It contains all
-// the fields passed with WithField{,s}. It's finally logged when Debug, Info,
-// Warn, Error, Fatal or Panic is called on it. These objects can be reused and
-// passed around as much as you wish to avoid field duplication.
-type Entry = logrus.Entry
-
-// Fields type, used to pass to `WithFields`.
-type Fields = logrus.Fields
-
-// FieldMap allows customization of the key names for default fields.
-type FieldMap = logrus.FieldMap
-
-// Level type
-type Level = logrus.Level
-
-// Logger type
-type Logger = logrus.Logger
-
-// JSONFormatter formats logs into parsable json
-type JSONFormatter struct {
-	logrus.JSONFormatter
-}
-
-// TextFormatter formats logs into text
-type TextFormatter struct {
-	logrus.TextFormatter
-}
-
-// Formatter
-// The Formatter interface is used to implement a custom Formatter. It takes an
-// `Entry`. It exposes all the fields, including the default ones:
-//
-// * `entry.Data["msg"]`. The message passed from Info, Warn, Error ..
-// * `entry.Data["time"]`. The timestamp.
-// * `entry.Data["level"]. The level the entry was logged at.
-//
-// Any additional fields added with `WithField` or `WithFields` are also in
-// `entry.Data`. Format is expected to return an array of bytes which are then
-// logged to `logger.Out`.
-
-// SetLevel ...
-func SetLevel(level Level) {
-	logrus.SetLevel(level)
-}
-
-// NewWithFields returns a logrus Entry with fields
-func NewWithFields(fields Fields) *Entry {
-	return logrus.WithFields(fields)
-}
-
-// NewEntry return an entry is the final or intermediate Logrus logging entry
-func NewEntry(logger *Logger) *Entry {
-	return logrus.NewEntry(logger)
-}
-
-// Exported from logrus
-var (
-	// Creates a new logger. Configuration should be set by changing `Formatter`,
-	// `Out` and `Hooks` directly on the default logger instance. You can also just
-	// instantiate your own:
-	//
-	//    var log = &Logger{
-	//      Out: os.Stderr,
-	//      Formatter: new(JSONFormatter),
-	//      Level: logrus.DebugLevel,
-	//    }
-	//
-	// It's recommended to make this a global instance called `log`.
-	New = logrus.New
-	// StandardLogger default logger
-	StandardLogger = logrus.StandardLogger
-	// SetOutput sets the standard logger output.
-	SetOutput = logrus.SetOutput
-	// SetFormatter sets the standard logger formatter.
-	SetFormatter = logrus.SetFormatter
-	// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
-	WithError = logrus.WithError
-	// WithField creates an entry from the standard logger and adds a field to
-	// it. If you want multiple fields, use `WithFields`.
-	//
-	// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
-	// or Panic on the Entry it returns.
-	WithField = logrus.WithField
-	// WithFields creates an entry from the standard logger and adds multiple
-	// fields to it. This is simply a helper for `WithField`, invoking it
-	// once for each field.
-	//
-	// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
-	// or Panic on the Entry it returns.
-	WithFields = logrus.WithFields
-
-	// Debug logs a message at level Debug on the standard logger.
-	Debug = logrus.Debug
-	// Print logs a message at level Info on the standard logger.
-	Print = logrus.Print
-	// Info logs a message at level Info on the standard logger.
-	Info = logrus.Info
-	// Warn logs a message at level Warn on the standard logger.
-	Warn = logrus.Warn
-	// Warning logs a message at level Warn on the standard logger.
-	Warning = logrus.Warning
-	// Error logs a message at level Error on the standard logger.
-	Error = logrus.Error
-	// Panic logs a message at level Panic on the standard logger.
-	Panic = logrus.Panic
-	// Fatal logs a message at level Fatal on the standard logger.
-	Fatal = logrus.Fatal
-
-	// Debugf logs a message at level Debug on the standard logger.
-	Debugf = logrus.Debugf
-	// Printf logs a message at level Info on the standard logger.
-	Printf = logrus.Printf
-	// Infof logs a message at level Info on the standard logger.
-	Infof = logrus.Infof
-	// Warnf logs a message at level Warn on the standard logger.
-	Warnf = logrus.Warnf
-	// Warningf logs a message at level Warn on the standard logger.
-	Warningf = logrus.Warningf
-	// Errorf logs a message at level Error on the standard logger.
-	Errorf = logrus.Errorf
-	// Panicf logs a message at level Panic on the standard logger.
-	Panicf = logrus.Panicf
-	// Fatalf logs a message at level Fatal on the standard logger.
-	Fatalf = logrus.Fatalf
-	// Debugln logs a message at level Debug on the standard logger.
-	Debugln = logrus.Debugln
-	// Println logs a message at level Info on the standard logger.
-	Println = logrus.Println
-	// Infoln logs a message at level Info on the standard logger.
-	Infoln = logrus.Infoln
-	// Warnln logs a message at level Warn on the standard logger.
-	Warnln = logrus.Warnln
-	// Warningln logs a message at level Warn on the standard logger.
-	Warningln = logrus.Warningln
-	// Errorln logs a message at level Error on the standard logger.
-	Errorln = logrus.Errorln
-	// Panicln logs a message at level Panic on the standard logger.
-	Panicln = logrus.Panicln
-	// Fatalln logs a message at level Fatal on the standard logger.
-	Fatalln = logrus.Fatalln
-)

BIN
tmr-watch.exe


Some files were not shown because too many files changed in this diff