mqtt.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. package api
  2. import (
  3. "bytes"
  4. "crypto/hmac"
  5. "crypto/sha1"
  6. "crypto/tls"
  7. "crypto/x509"
  8. "encoding/json"
  9. "fmt"
  10. "io/ioutil"
  11. "os"
  12. "strconv"
  13. "time"
  14. "tmr-watch/conf/setting"
  15. "tmr-watch/http/handle/restful"
  16. "tmr-watch/pkg/logging"
  17. "github.com/astaxie/beego/logs"
  18. MQTT "github.com/eclipse/paho.mqtt.golang"
  19. mqtt "github.com/eclipse/paho.mqtt.golang"
  20. "github.com/robfig/cron"
  21. )
  22. func InitMqttClient() {
  23. if setting.YynserverSetting.FarmId != "" {
  24. c, pubTopic := MqttClient()
  25. deviceHeartbeat(c, pubTopic)
  26. // i := 19
  27. // for {
  28. // i--
  29. // if i == 0 {
  30. // break
  31. // }
  32. // // now := time.Now().AddDate(0, 0, -i).Format("2006-01-02")
  33. // now := "2024-05-23"
  34. // fmt.Println(now, time.Now())
  35. // stirPush(c, pubTopic, now)
  36. // dustingPush(c, pubTopic, now)
  37. // equipmentAccuracyPush(c, pubTopic, now)
  38. // finishedWeightPush(c, pubTopic, now)
  39. // feedtempletPush(c, pubTopic)
  40. // CompletedTrainNumberPush(c, pubTopic, now)
  41. // // }
  42. // now := "2024-05-01"
  43. // stirPush(c, pubTopic, now)
  44. // dustingPush(c, pubTopic, now)
  45. // equipmentAccuracyPush(c, pubTopic, now)
  46. // finishedWeightPush(c, pubTopic, now)
  47. // feedtempletPush(c, pubTopic)
  48. // CompletedTrainNumberPush(c, pubTopic, now)
  49. mqttCron := cron.New()
  50. mqttCron.AddFunc("10 07 * * *", func() {
  51. now := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  52. stirPush(c, pubTopic, now)
  53. dustingPush(c, pubTopic, now)
  54. equipmentAccuracyPush(c, pubTopic, now)
  55. finishedWeightPush(c, pubTopic, now)
  56. feedtempletPush(c, pubTopic)
  57. CompletedTrainNumberPush(c, pubTopic, now)
  58. })
  59. mqttCron.Start()
  60. }
  61. }
  62. func MqttClient() (MQTT.Client, string) {
  63. // set the device info, include product key, device name, and device secret
  64. // var productKey string = "a1NmXfrjL8M"
  65. // var deviceName string = "4776_p_breed"
  66. // var deviceSecret string = "c2591b89adff22e1c9f0fc03363f56a4"
  67. // ProductKey
  68. // DeviceName
  69. // DeviceSecret
  70. var productKey string = setting.YynserverSetting.ProductKey
  71. var deviceName string = setting.YynserverSetting.DeviceName
  72. var deviceSecret string = setting.YynserverSetting.DeviceSecret
  73. // product_key =k03txxLKFae
  74. // device_name =4623_p_breed
  75. // device_secret =d06ababb2b10ba25bca3041e35ac604d
  76. // host = iot-010a5xth.mqtt.iothub.aliyuncs.com
  77. // farmId=1830004623
  78. // heartBeat=18300046234623_p_breed
  79. // TopicName=/k03txxLKFae/4623_p_breed/user/heatwatch/tmrBreed/post
  80. var timeStamp string = strconv.FormatInt(time.Now().UnixNano(), 10)
  81. var clientId string = "go" + setting.YynserverSetting.FarmId
  82. var subTopic string = "/" + productKey + "/" + deviceName + "/user/heatwatch/tmrBreed/get"
  83. var pubTopic string = "/" + productKey + "/" + deviceName + "/user/heatwatch/tmrBreed/post"
  84. // set the login broker url
  85. var raw_broker bytes.Buffer
  86. raw_broker.WriteString("tcp://")
  87. raw_broker.WriteString("iot-010a5xth.mqtt.iothub.aliyuncs.com:1883")
  88. opts := MQTT.NewClientOptions().AddBroker(raw_broker.String())
  89. // calculate the login auth info, and set it into the connection options
  90. auth := calculate_sign(clientId, productKey, deviceName, deviceSecret, timeStamp)
  91. opts.SetClientID(auth.mqttClientId)
  92. opts.SetUsername(auth.username)
  93. opts.SetPassword(auth.password)
  94. opts.SetMaxReconnectInterval(1 * time.Second)
  95. opts.AutoReconnect = true
  96. // opts.SetKeepAlive(60 * 2 * time.Second)
  97. opts.OnConnect = func(c MQTT.Client) {
  98. if token := c.Subscribe(subTopic, 0, feedHeatwatch); token.Wait() && token.Error() != nil {
  99. logging.Error("mqtt Subscribe err: ", token.Error())
  100. os.Exit(1)
  101. }
  102. }
  103. c := mqtt.NewClient(opts)
  104. if token := c.Connect(); token.Wait() && token.Error() != nil {
  105. fmt.Println(token.Error())
  106. os.Exit(1)
  107. }
  108. fmt.Print("Connect aliyun IoT Cloud Sucess\n")
  109. return c, pubTopic
  110. }
  111. func NewTLSConfig() *tls.Config {
  112. // Import trusted certificates from CAfile.pem.
  113. // Alternatively, manually add CA certificates to default openssl CA bundle.
  114. certpool := x509.NewCertPool()
  115. pemCerts, err := ioutil.ReadFile("./x509/root.pem")
  116. if err != nil {
  117. fmt.Println("0. read file error, game over!!")
  118. }
  119. certpool.AppendCertsFromPEM(pemCerts)
  120. // Create tls.Config with desired tls properties
  121. return &tls.Config{
  122. // RootCAs = certs used to verify server cert.
  123. RootCAs: certpool,
  124. // ClientAuth = whether to request cert from server.
  125. // Since the server is set up for SSL, this happens
  126. // anyways.
  127. ClientAuth: tls.NoClientCert,
  128. // ClientCAs = certs used to validate client cert.
  129. ClientCAs: nil,
  130. // InsecureSkipVerify = verify that cert contents
  131. // match server. IP matches what is in cert etc.
  132. InsecureSkipVerify: false,
  133. // Certificates = list of certs client sends to server.
  134. // Certificates: []tls.Certificate{cert},
  135. }
  136. }
  137. // define a function for the default message handler
  138. var f MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Message) {
  139. fmt.Printf("TOPIC: %s\n", msg.Topic())
  140. fmt.Printf("MSG: %s\n", msg.Payload())
  141. }
  142. type AuthInfo struct {
  143. password, username, mqttClientId string
  144. }
  145. func calculate_sign(clientId, productKey, deviceName, deviceSecret, timeStamp string) AuthInfo {
  146. var raw_passwd bytes.Buffer
  147. raw_passwd.WriteString("clientId" + clientId)
  148. raw_passwd.WriteString("deviceName")
  149. raw_passwd.WriteString(deviceName)
  150. raw_passwd.WriteString("productKey")
  151. raw_passwd.WriteString(productKey)
  152. raw_passwd.WriteString("timestamp")
  153. raw_passwd.WriteString(timeStamp)
  154. fmt.Println(raw_passwd.String())
  155. // hmac, use sha1
  156. mac := hmac.New(sha1.New, []byte(deviceSecret))
  157. mac.Write([]byte(raw_passwd.String()))
  158. password := fmt.Sprintf("%02x", mac.Sum(nil))
  159. fmt.Println(password)
  160. username := deviceName + "&" + productKey
  161. var MQTTClientId bytes.Buffer
  162. MQTTClientId.WriteString(clientId)
  163. // hmac, use sha1; securemode=2 means TLS connection
  164. MQTTClientId.WriteString("|securemode=2,_v=paho-go-1.0.0,signmethod=hmacsha1,timestamp=")
  165. MQTTClientId.WriteString(timeStamp)
  166. MQTTClientId.WriteString("|")
  167. auth := AuthInfo{password: password, username: username, mqttClientId: MQTTClientId.String()}
  168. return auth
  169. }
  170. func feedtempletPush(c MQTT.Client, pubTopic string) {
  171. tx := restful.Engine.NewSession()
  172. defer tx.Close()
  173. dataList, err := tx.SQL(`SELECT
  174. f.id AS recipeId,
  175. f.tname recipeName,
  176. ft.id ingId,
  177. ifnull(fd.fname,fdy.fname) ingName,
  178. if(fd.fname is not null, ft.fweight,fty.fweight) afQty,
  179. ft.sort mixNo,
  180. ifnull(fd.allowratio,fdy.allowratio) allowableError,
  181. ifnull(fd.fclass,fdy.fclass) ingType,
  182. if(fd.fname is not null,ft.fweight * ( fd.dry / 100 ), fty.fweight * ( fdy.dry / 100 )) dmQty,
  183. '' recipeCost
  184. FROM
  185. feedtemplet f
  186. JOIN ftdetail ft ON ft.ftid = f.id
  187. left JOIN feed fd ON fd.id = ft.fid
  188. left join feedtemplet fy on fy.id = ft.preftid
  189. left join ftdetail fty on fty.ftid = fy.id
  190. left JOIN feed fdy ON fdy.id = fty.fid
  191. `).QueryString()
  192. if err != nil {
  193. logs.Error("feedtempletPush-error-1:", err)
  194. return
  195. }
  196. pushStr := `{
  197. "apiId": "getKPTData",
  198. "param": {
  199. "farmId": "%s",
  200. "method":"getfeedtempletinfo",
  201. "rowCount": "1",
  202. "resultData":%s
  203. }
  204. }`
  205. if len(dataList) > 0 {
  206. b, _ := json.Marshal(dataList)
  207. pushStr = fmt.Sprintf(pushStr, setting.YynserverSetting.FarmId, string(b))
  208. // c.Publish(pubTopic, 2, false, pushStr)
  209. token := c.Publish(pubTopic, 2, false, pushStr)
  210. fmt.Println("publish msg: ", pushStr, token.Error())
  211. token.Wait()
  212. // time.Sleep(2 * time.Second)
  213. }
  214. }
  215. func stirPush(c MQTT.Client, pubTopic, date string) {
  216. tx := restful.Engine.NewSession()
  217. defer tx.Close()
  218. dataList, err := tx.SQL(`SELECT
  219. DATE_FORMAT(d.mydate,'%Y-%m-%d') loadDate,
  220. d.sort tmrNo,
  221. d.times loadShift,
  222. d.tempid recipeId,
  223. d.templetname recipeName,
  224. f.feedcode ingId,
  225. d1.fname ingName,
  226. 12 ingType,
  227. f.dry dmPct,
  228. d1.sort mixNo,
  229. d1.feedallowratio allowable_error,
  230. d1.lweight expWeight,
  231. d1.actualweightminus actualWeight,
  232. if((select count(1) from downloadplandtl1 where pid = d.id and sort < d1.sort order by sort desc) >0 ,(select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadplandtl1 where pid = d.id and sort < d1.sort order by sort desc limit 1),DATE_FORMAT(d.intime,'%Y-%m-%d %H:%i:%s') ) startTime,
  233. DATE_FORMAT(d1.intime,'%Y-%m-%d %H:%i:%s') endTime , ifnull(if(d.driverId !=0 ,(select drivername from driver where id = d.driverId),(SELECT dr.driver FROM dutyrecord dr
  234. WHERE dr.pastureid = d.pastureid AND dr.eqid = d.tmrid and dr.times= d.times AND dr.operatetime <=d.mydate
  235. ORDER BY dr.operatetime DESC LIMIT 1)),'')tmrName
  236. FROM
  237. downloadedplan d
  238. JOIN downloadplandtl1 d1 ON d1.pid = d.id
  239. JOIN feed f ON f.feedcode = d1.feedcode
  240. AND f.pastureid = d.pastureid
  241. WHERE
  242. DATE_FORMAT( d.mydate ,'%Y-%m-%d' ) = ? `, date).QueryString()
  243. if err != nil {
  244. logs.Error("feedtempletPush-error-1:", err)
  245. return
  246. }
  247. pushStr := `{
  248. "apiId": "getKPTData",
  249. "param": {
  250. "farmId": "%s",
  251. "method":"uploadadddata",
  252. "rowCount": "%d",
  253. "resultData":%s
  254. }
  255. }`
  256. if len(dataList) > 0 {
  257. b, _ := json.Marshal(dataList)
  258. pushStr = fmt.Sprintf(pushStr, setting.YynserverSetting.FarmId, len(dataList), string(b))
  259. token := c.Publish(pubTopic, 2, false, pushStr)
  260. fmt.Println("publish msg: ", pushStr, token.Error())
  261. // token.Wait()
  262. // time.Sleep(2 * time.Second)
  263. }
  264. }
  265. // 撒料信息
  266. func dustingPush(c MQTT.Client, pubTopic, date string) {
  267. tx := restful.Engine.NewSession()
  268. defer tx.Close()
  269. dataList, err := tx.SQL(`SELECT
  270. ifnull(if(d.driverId !=0 ,(select drivername from driver where id = d.driverId),(SELECT dr.driver FROM dutyrecord dr
  271. WHERE dr.pastureid = d.pastureid AND dr.eqid = d.tmrid and dr.times= d.times AND dr.operatetime <=d.mydate
  272. ORDER BY dr.operatetime DESC LIMIT 1)),'')tmrName ,
  273. DATE_FORMAT(d.mydate,'%Y-%m-%d') dropDate,
  274. d.sort tmrNo,
  275. d.times dropShift,
  276. d2.fbarid penId,
  277. b.bname penName,
  278. fp.ccount cowCount,
  279. d2.sort feedingNo,
  280. d2.lweight expWeight,
  281. d2.actualweightminus actualWeight,
  282. if((select count(1) from downloadplandtl2 where pid = d.id and sort < d2.sort order by sort desc) >0 ,(select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadplandtl2 where pid = d.id and sort < d2.sort order by sort desc limit 1), (select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadplandtl1 where pid = d.id order by sort desc limit 1) ) startTime,
  283. DATE_FORMAT(d2.intime,'%Y-%m-%d %H:%i:%s') endTime
  284. FROM
  285. downloadedplan d
  286. JOIN downloadplandtl2 d2 ON d2.pid = d.id
  287. JOIN bar b ON b.id = d2.fbarid
  288. join feedp fp on fp.barid = b.id
  289. join tmr t on t.id = d.tmrid
  290. left join driver on driver.drivercode = t.eqcode
  291. WHERE
  292. DATE_FORMAT( d.mydate ,'%Y-%m-%d' ) = ? `, date).QueryString()
  293. if err != nil {
  294. logs.Error("feedtempletPush-error-1:", err)
  295. return
  296. }
  297. pushStr := `{
  298. "apiId": "getKPTData",
  299. "param": {
  300. "farmId": "%s",
  301. "method":"uploaddiliverdata",
  302. "rowCount": "%d",
  303. "resultData":%s
  304. }
  305. }`
  306. if len(dataList) > 0 {
  307. b, _ := json.Marshal(dataList)
  308. pushStr = fmt.Sprintf(pushStr, setting.YynserverSetting.FarmId, len(dataList), string(b))
  309. token := c.Publish(pubTopic, 2, false, pushStr)
  310. fmt.Println("publish msg: ", pushStr, token.Error())
  311. // token.Wait()
  312. // time.Sleep(2 * time.Second)
  313. }
  314. }
  315. //设备心跳
  316. func deviceHeartbeat(c MQTT.Client, pubTopic string) {
  317. pushStr := fmt.Sprintf(`{"data_collect_number":%s,"status":true,"model_type":"heartbeat"}`, setting.YynserverSetting.HeartBeat)
  318. token := c.Publish(pubTopic, 2, false, pushStr)
  319. fmt.Println("publish msg: ", pushStr, token.Error())
  320. // token.Wait()
  321. // go func() {
  322. duetimecst2, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
  323. duetimecst3, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
  324. spec1 := fmt.Sprintf("@every %v", duetimecst2.Sub(duetimecst3))
  325. // for {
  326. device := cron.New()
  327. device.AddFunc(spec1, func() {
  328. token := c.Publish(pubTopic, 2, false, pushStr)
  329. fmt.Println("publish msg: ", pushStr, token.Error(), time.Now())
  330. token.Wait()
  331. })
  332. // }
  333. device.Start()
  334. // }()
  335. }
  336. // 准确率
  337. func equipmentAccuracyPush(c MQTT.Client, pubTopic, date string) {
  338. tx := restful.Engine.NewSession()
  339. defer tx.Close()
  340. dataList, err := tx.SQL(`SELECT
  341. t.tname Name,
  342. 1-abs (
  343. sum( d1.actualweightminus )- sum( d1.lweight ))/ sum( d1.lweight ) Rate,
  344. d.mydate RateDate , DATE_FORMAT(d.intime,'%Y-%m-%d %H:%i:%s') startTime,
  345. (select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadplandtl2 where pid = d.id order by sort desc limit 1) endTime
  346. FROM
  347. downloadedplan d
  348. JOIN downloadplandtl1 d1 ON d1.pid = d.id
  349. JOIN tmr t ON t.datacaptureno = d.datacaptureno
  350. WHERE
  351. DATE_FORMAT( d.mydate, '%Y-%m-%d' ) = ? and d.lpplantype in(0,1)
  352. GROUP BY
  353. d.datacaptureno`, date).QueryString()
  354. if err != nil {
  355. logs.Error("feedtempletPush-error-1:", err)
  356. return
  357. }
  358. pushStr := `{
  359. "apiId": "getKPTData",
  360. "param": {
  361. "resultData": %s,
  362. "farmId": "%s",
  363. "method": "uploadrate",
  364. "rowCount": %d
  365. }
  366. }`
  367. if len(dataList) > 0 {
  368. b, _ := json.Marshal(dataList)
  369. pushStr = fmt.Sprintf(pushStr, string(b), setting.YynserverSetting.FarmId, len(dataList))
  370. token := c.Publish(pubTopic, 2, false, pushStr)
  371. fmt.Println("publish msg: ", pushStr, token.Error())
  372. token.Wait()
  373. // time.Sleep(2 * time.Second)
  374. }
  375. }
  376. // 完成重量
  377. func finishedWeightPush(c MQTT.Client, pubTopic, date string) {
  378. tx := restful.Engine.NewSession()
  379. defer tx.Close()
  380. dataList, err := tx.SQL(`SELECT
  381. sum( d1.actualweightminus ) completeWeight,
  382. sum( d1.lweight ) planWeight,
  383. d.mydate weightDate , DATE_FORMAT(d.intime,'%Y-%m-%d %H:%i:%s') startTime,
  384. (select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadedplan where mydate = d.mydate and intime is not null order by sort desc limit 1) endTime
  385. FROM
  386. downloadedplan d
  387. JOIN downloadplandtl1 d1 ON d1.pid = d.id
  388. JOIN tmr t ON t.datacaptureno = d.datacaptureno
  389. WHERE
  390. DATE_FORMAT( d.mydate, '%Y-%m-%d' ) = ? and lpplantype in(0,1)`, date).QueryString()
  391. if err != nil {
  392. logs.Error("feedtempletPush-error-1:", err)
  393. return
  394. }
  395. pushStr := `{
  396. "apiId": "getKPTData",
  397. "param": {
  398. "resultData": %s,
  399. "farmId": "%s",
  400. "method": "uploadweight",
  401. "rowCount": "1"
  402. }
  403. }`
  404. if len(dataList) > 0 {
  405. b, _ := json.Marshal(dataList)
  406. pushStr = fmt.Sprintf(pushStr, string(b), setting.YynserverSetting.FarmId)
  407. token := c.Publish(pubTopic, 2, false, pushStr)
  408. fmt.Println("publish msg: ", pushStr, token.Error())
  409. token.Wait()
  410. // time.Sleep(2 * time.Second)
  411. }
  412. }
  413. // 完成车次
  414. func CompletedTrainNumberPush(c MQTT.Client, pubTopic, date string) {
  415. tx := restful.Engine.NewSession()
  416. defer tx.Close()
  417. dataList, err := tx.SQL(` select (select count(1) from downloadedplan where DATE_FORMAT(mydate ,'%Y-%m-%d' ) = ? and lpplantype in(0,1) ) planCar,
  418. (select count(1) from downloadedplan where DATE_FORMAT(mydate ,'%Y-%m-%d' ) = ? and iscompleted = 1 and lpplantype in(0,1)) CompleteCar ,
  419. ? carDate,
  420. (select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadedplan where DATE_FORMAT(mydate ,'%Y-%m-%d' ) = ? and iscompleted = 1 and lpplantype in(0,1) order by intime asc limit 1 ) startTime,
  421. (select DATE_FORMAT(intime,'%Y-%m-%d %H:%i:%s') from downloadedplan where DATE_FORMAT(mydate ,'%Y-%m-%d' ) = ? and iscompleted = 1 and lpplantype in(0,1) and intime is not null order by intime desc limit 1 ) endTime
  422. `, date, date, date, date, date).QueryString()
  423. if err != nil {
  424. logs.Error("feedtempletPush-error-1:", err)
  425. return
  426. }
  427. pushStr := `{
  428. "apiId": "getKPTData",
  429. "param": {
  430. "resultData": %s,
  431. "farmId": "%s",
  432. "method": "uploadcarnumber",
  433. "rowCount": "1"
  434. }
  435. }`
  436. if len(dataList) > 0 {
  437. b, _ := json.Marshal(dataList)
  438. pushStr = fmt.Sprintf(pushStr, string(b), setting.YynserverSetting.FarmId)
  439. token := c.Publish(pubTopic, 2, false, pushStr)
  440. fmt.Println("publish msg: ", pushStr, token.Error())
  441. token.Wait()
  442. // time.Sleep(2 * time.Second)
  443. }
  444. }
  445. func feedHeatwatch(client MQTT.Client, msg MQTT.Message) {
  446. tx := restful.Engine.NewSession()
  447. defer tx.Close()
  448. data := make(map[string]interface{})
  449. json.Unmarshal(msg.Payload(), &data)
  450. if _, ok := data["feedData"]; ok {
  451. for _, item := range data["feedData"].([]map[string]interface{}) {
  452. tx.SQL(` insert into feed(pastureid,feedcode,fname)values((SELECT column_default INTO pastureidTem FROM information_schema.COLUMNS
  453. WHERE table_name = 'recweight' AND table_schema = 'tmrwatch3' AND column_name = 'pastureid'),?,?)
  454. ON DUPLICATE KEY UPDATE feedcode = ?,fname = ? `, item["feedCode"], item["feedName"], item["feedCode"], item["feedName"]).Execute()
  455. }
  456. } else if _, ok := data["barData"]; ok {
  457. for _, item := range data["barData"].([]map[string]interface{}) {
  458. tx.SQL(` insert into bar(pastureid,bcode,bname)values((SELECT column_default INTO pastureidTem FROM information_schema.COLUMNS
  459. WHERE table_name = 'recweight' AND table_schema = 'tmrwatch3' AND column_name = 'pastureid'),?,?)
  460. ON DUPLICATE KEY UPDATE bcode = ?,bname = ? `, item["barCode"], item["barName"], item["barCode"], item["barName"]).Execute()
  461. }
  462. }
  463. }