Browse Source

代码合并

baishaojie 1 year ago
parent
commit
d16152cc61

BIN
TMRWatchComm


BIN
TMRWatchComm.zip


BIN
__debug_bin.exe


+ 5 - 5
conf/app.ini

@@ -45,9 +45,9 @@ GRFDURL = http://120.48.30.31:88
 [database]
 Type = mysql
 User = root
-Password = root
-#Host = 8.130.17.8:3306
-Host = 192.168.1.93:3326
+#Password = root
+Host = 8.130.17.8:3306
+#Host = 192.168.1.93:3326
 #Host = 127.0.0.1:3316
 #Name = haiyuan
 #Password = root
@@ -58,7 +58,7 @@ Host = 192.168.1.93:3326
 #Password = keep
 
 #Password = kptzhu@163.com
-#Password = kpt123456*
+Password = kpt123456*
 #Password = kepaiteng!QAZ
 #Host = 47.92.52.73:3306
 #Host = 127.0.0.1:3306
@@ -72,7 +72,7 @@ Host = 192.168.1.93:3326
 #Name = tmrgo
 #Password = kepaiteng!QAZ
 #Host = 222.73.129.15:31306
-Name = tmrwatch5
+Name = tmrwatchrn
 TablePrefix =
 
 ShowXormlog = false

+ 194 - 0
routers/api/gm/udservice.go

@@ -0,0 +1,194 @@
+package gm
+
+import (
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"time"
+
+	"../../../pkg/setting"
+	"../../../routers/restful"
+	"github.com/kptyun/KPTCOMM/pkg/logging"
+)
+
+func UdBarSync(pastureId string) {
+	url := "http://172.16.86.95:8080/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=f9b066e206d44ce6af77aeb06a352651&method=downloadpen"
+	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 string) {
+	url := "http://172.16.86.95:8080/copartner_downloads?equipmentId=48ffa4de-7870-4b18-a052-9f8d3a46089a&farmId=f9b066e206d44ce6af77aeb06a352651&method=downloadmaterial"
+	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 string) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	tx.SQL(`select d1.date loadDate,d.times loadShift,d.datacaptureno  tmrNo,ft.tcode 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()
+
+}
+
+func UdMaterialIssuePush(pastureId string) {
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	tx.SQL(`SELECT  dd.feedsort feedSort, dd.feedcode feedId,dd.fname feedName,
+	d.id,IFNULL(ft.tcode,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()
+
+}
+
+func UdBarFeedRemainPush(pastureId string) {
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
+	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()
+}

+ 1 - 1
routers/api/sap/sap.go

@@ -191,7 +191,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

+ 26 - 15
routers/api/scheduled.go

@@ -19,6 +19,7 @@ import (
 	"../../pkg/logging"
 	"../../pkg/setting"
 
+	// "../../routers/api/gm"
 	// "../../routers/api/sap"
 	"../../routers/restful"
 	"github.com/Anderson-Lu/gofasion/gofasion"
@@ -131,14 +132,18 @@ func CronScheduled(ctx context.Context) {
 
 	//
 	// //圣牧自动同步前天有进行中的任务
-	// manualUdData(pastureinfo)
+	manualUdData(pastureinfo)
 
+	//现代牧业sap同步
 	// xdmy := cron.New()
 	// dayCron.AddFunc("50 04 * * *", func() {
 	// 	sap.SyncMaterialOutbound()
 	// })
 	// xdmy.Start()
 
+	//光明ud同步
+	// gm.UdFeedSync(pastureinfo.Pastureid)
+
 }
 
 type ScheduledInfo struct {
@@ -746,8 +751,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)
@@ -1768,16 +1773,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
+}

+ 1 - 1
routers/router.go

@@ -239,7 +239,7 @@ func InitRouter() *gin.Engine {
 
 		apiV1.POST("/feedbackup/check", api.CheckFeedTrgaddress)
 
-		// apiV1.POST("/ud/feedp/sync", api.UdFeedpSync)
+		apiV1.POST("/ud/feedp/sync", api.UdFeedpSync)
 
 	}
 

+ 1 - 1
service/user_service/user.go

@@ -25,7 +25,7 @@ type User struct {
 }
 
 func (a *User) Check() (bool, error) {
-	return restful.CheckUser(a.Username, util.EncodeMD5(a.Password))
+	return restful.CheckUser(a.Username, a.Password)
 
 }