material.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. package service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "kpt.xdmy/apiserver/config"
  6. "regexp"
  7. "strconv"
  8. "time"
  9. "github.com/pkg/errors"
  10. log "github.com/sirupsen/logrus"
  11. _ "github.com/go-sql-driver/mysql"
  12. "kpt.xdmy/apiserver/model"
  13. "kpt.xdmy/apiserver/model/http"
  14. // "kpt.xdmy/pkg/log"
  15. )
  16. var partChan chan error
  17. // 定时从sap拉取物料(备件等)数据
  18. // 预留参数时间、备件编码,给手动调用接口
  19. func (s *Service) SapMaterial(t time.Time, code string) {
  20. partChan = make(chan error, 10)
  21. r := new(http.MaterialReq)
  22. rp := new(http.MaterialResp)
  23. var e error
  24. r.Dest.DestID = "EQMAN"
  25. r.Dest.BussTp = "MM002"
  26. //r.Dest.Url = "http://192.168.61.117/SAPP0/Common/MM002/QueryMaterial/"
  27. r.Dest.Url = fmt.Sprintf("%s/Common/MM002/QueryMaterial/", config.Conf.Http.Routing)
  28. if t.IsZero() {
  29. t = time.Now()
  30. }
  31. r.Data.BudatB = t.Format("20060102")
  32. r.Data.BudatE = t.Format("20060102")
  33. //r.Data.BudatB = "20221104"
  34. //r.Data.BudatE = "20221028"
  35. r.Data.Type = http.MTART{MTART: "XD08"}
  36. // r.Data.Group = []http.MATKL{{MATKL: "14010101"}}
  37. // r.Data.Group = []http.MATKL{{MATKL: "14"}}
  38. if code != "" {
  39. // r.Data.Codes = []http.MATNR{{Code: "14.01.06.02.000216"}}
  40. }
  41. rbyte, _ := json.Marshal(r)
  42. fmt.Println(string(rbyte))
  43. if e = s.SyncSap(r, rp, rbyte); e == nil {
  44. if rp.Dest.Status == "S" {
  45. log.Infof("sap material success:len=%d", len(rp.Data.Master))
  46. } else {
  47. e = errors.Errorf("sap material fail", rp.Dest.MessText)
  48. }
  49. } else {
  50. e = errors.Wrapf(e, "sap material error")
  51. }
  52. var update error
  53. var count int
  54. for _, v := range rp.Data.Master {
  55. update = nil
  56. s.UpdatePart(&v)
  57. update = <-partChan
  58. if update != nil {
  59. log.Error(update)
  60. count++
  61. l := model.SapDetailLog{Name: "part", Code: v.Code, ErrorText: update.Error()}
  62. if e := s.d.DB.Create(&l); e != nil {
  63. log.Errorf("add sapdetail log: %v", e)
  64. }
  65. }
  66. }
  67. if e != nil {
  68. log.Error(e)
  69. } else if update != nil {
  70. e = errors.Errorf("material update fail sum:%d", count)
  71. } else {
  72. log.Infof("material update success sum:%d", len(rp.Data.Master)-count)
  73. }
  74. s.AddSapLog(r, e)
  75. return
  76. }
  77. // 物料数据更新
  78. func (s *Service) UpdatePart(p *http.MaterialDetail) {
  79. part := new(model.Parts)
  80. if len(p.ModifyTime) >= 8 {
  81. p.ModifyTime = p.ModifyTime[:4] + "-" + p.ModifyTime[4:6] + "-" + p.ModifyTime[6:8]
  82. } else {
  83. partChan <- errors.New("ModifyTime is invalid:" + p.ModifyTime)
  84. }
  85. if t, e := time.ParseInLocation("2006-01-02", p.ModifyTime, time.Local); e != nil {
  86. partChan <- errors.Wrapf(e, "time:%s", p.ModifyTime)
  87. } else {
  88. part.ModifyTime = t
  89. }
  90. if p.Dflag == "" {
  91. part.Enable = 1
  92. part.Statue = 1
  93. }
  94. part.PartCode = p.Code
  95. part.Note = p.Description
  96. part.Category = p.Type
  97. part.Unit = p.Unit
  98. part.Name = p.Name
  99. part.Specification = p.Model
  100. if e := s.d.DB.Where(model.Parts{PartCode: p.Code}).Assign(*part).FirstOrCreate(part).Error; e != nil {
  101. partChan <- errors.Wrapf(e, "code:%s", p.Code)
  102. } else {
  103. log.Infof("sap part update success:%s", p.Code)
  104. partChan <- nil
  105. }
  106. }
  107. func Exec(rows [][]string) {
  108. for i, v := range rows {
  109. fmt.Println(i)
  110. if i == 0 {
  111. continue
  112. }
  113. fmt.Println(v[1], v[2], v[10])
  114. s.d.DB.Exec(` update emp set tel = ? where empCode = ? `, v[10], v[1])
  115. }
  116. //precontractId := model.PartRepertory{}
  117. //err := s.d.DB.Raw(`select precontractId from part_repertory where precontractId is not null order by precontractId `).First(&precontractId).Error
  118. //if err != nil {
  119. // log.Error(err)
  120. // //continue
  121. //}
  122. //contractId := model.PartRepertory{}
  123. //err = s.d.DB.Raw(`select (contractId) contractId from part_repertory order by contractId `).First(&contractId).Error
  124. //if err != nil {
  125. // log.Error(err)
  126. // //continue
  127. //}
  128. //for i, v := range rows {
  129. // fmt.Println(i)
  130. // if i == 0 {
  131. // continue
  132. // }
  133. // /*
  134. // pasture := model.Pasture{}
  135. // err := s.d.DB.Where(&model.Pasture{Name: v[1]}).First(&pasture).Error
  136. // if err != nil {
  137. // fmt.Println(err)
  138. // return
  139. // }
  140. // now := time.Now().Format("2006-01-02")
  141. // contractId, partCode := v[13], v[4]
  142. // partLaid := model.PartLaid{}
  143. // err = s.d.DB.Raw(` select p.id from bigpartlaid bp join partlaid p on p.bigid = bp.id
  144. // where bp.pastureid = ? and p.contractId = ? and p.partCode = ? and DATE_FORMAT(bp.creatDate,'%Y-%m-%d') = ?`, pasture.ID, contractId, partCode, now).First(&partLaid).Error
  145. // if err != nil {
  146. // fmt.Println(err)
  147. // //return
  148. // }
  149. // partuse := model.PartUse{}
  150. // err = s.d.DB.Raw(` select p.id from bigpartuse bp join partuse p on p.bigid = bp.id
  151. // where bp.pastureid = ? and p.contractId = ? and p.partCode = ? and DATE_FORMAT(bp.creatDate,'%Y-%m-%d') = ?`, pasture.ID, contractId, partCode, now).First(&partuse).Error
  152. // if err != nil {
  153. // fmt.Println(err)
  154. // //return
  155. // }
  156. // if partuse.ID > 0 || partLaid.ID > 0 {
  157. // continue
  158. // }
  159. //
  160. // err = s.d.DB.Exec(` update part_repertory ps set reportery = ? where id = ? `, v[15], v[0]).Error
  161. // if err != nil {
  162. // fmt.Println(err)
  163. // return
  164. // }
  165. // */
  166. //
  167. // //if v[14] == "新增" {
  168. // //
  169. // // //1983
  170. //
  171. // //
  172. // //if v[1] == "M017" || v[1] == "N302" || i <= 47 {
  173. // // continue
  174. // //}
  175. // id := v[0]
  176. // ///*
  177. // if id == "" && v[11] == "无合同" && v[14] == "M017" {
  178. //
  179. // parts := model.Parts{}
  180. // err := s.d.DB.Where(&model.Parts{PartCode: v[3]}).First(&parts).Error
  181. // if err != nil {
  182. // log.Error(err)
  183. // continue
  184. // }
  185. //
  186. // pasture := model.Pasture{}
  187. // err = s.d.DB.Where(&model.Pasture{FactoryCode: "M005"}).First(&pasture).Error
  188. // if err != nil {
  189. // fmt.Println(err)
  190. // continue
  191. // }
  192. //
  193. // w := model.Warehouse{}
  194. // err = s.d.DB.Where(&model.Warehouse{PastureID: pasture.ID, Status: 1}).First(&w).Error
  195. // if err != nil {
  196. // fmt.Println(err)
  197. // continue
  198. // }
  199. //
  200. // reportery := v[16]
  201. // price := 1
  202. // //reportery := v[2]
  203. // providerid := "1975"
  204. // providerName := "北京京东"
  205. // contractId := fmt.Sprintf("-%d%s%d", pasture.ID, providerid, parts.ID)
  206. // //
  207. // //// PrecontractID, err := strconv.ParseInt(precontractId.PrecontractID, 10, 64)
  208. // err = s.d.DB.Exec(` insert into part_repertory(specification,pastureId,partId,partName,partCode,location,locationId,reportery,
  209. // contractId,brandId,unit,price,precontractId,providerNames,providerId)
  210. // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
  211. // parts.Specification, pasture.ID, parts.ID, parts.Name, parts.PartCode, w.WarehoseCode, w.ID, reportery, contractId, 0, parts.Unit,
  212. // price, contractId, providerName, providerid).Error
  213. // }
  214. // //*/
  215. // //if err != nil {
  216. // // fmt.Println(err)
  217. // // return
  218. // //}
  219. //
  220. // //}
  221. // //else {
  222. // //reportery := v[16]
  223. // //id := v[0]
  224. // //if id != "" {
  225. // // err := s.d.DB.Exec(` update part_repertory ps set reportery = ? where id = ?`, reportery, id).Error
  226. // // if err != nil {
  227. // // fmt.Println(err)
  228. // // return
  229. // // }
  230. // //}
  231. // //} else {
  232. // // err := s.d.DB.Exec(` delete from part_repertory where id = ?`, id).Error
  233. // // if err != nil {
  234. // // fmt.Println(err)
  235. // // return
  236. // // }
  237. // //}
  238. // //}
  239. //}
  240. }
  241. func DepartmentExec(rows [][]string) {
  242. for i, v := range rows {
  243. //fmt.Println(i, v)
  244. if i == 0 {
  245. continue
  246. }
  247. id := v[0]
  248. name := v[1]
  249. parentid := v[4]
  250. costCenter_code := v[15]
  251. costCenter_code2 := v[17]
  252. fmt.Println(id, name, parentid, costCenter_code, costCenter_code2)
  253. if id != "新增" {
  254. fmt.Println(id, name, parentid, costCenter_code, costCenter_code2)
  255. if costCenter_code2 != "" {
  256. err := s.d.DB.Exec(` update department ps set costCenter_code = ? where id = ? `, costCenter_code2, id).Error
  257. if err != nil {
  258. fmt.Println(err)
  259. return
  260. }
  261. }
  262. if v[18] == "无此部门" || v[18] == "未上线牧场" || v[18] == "重复" {
  263. err := s.d.DB.Exec(` delete from department where id = ? `, id).Error
  264. if err != nil {
  265. fmt.Println(err)
  266. return
  267. }
  268. }
  269. } else {
  270. fmt.Println(id, name, parentid, costCenter_code, costCenter_code2)
  271. if costCenter_code2 != "" {
  272. err := s.d.DB.Exec(` insert into department(name,pastureId,isPasture,costCenter_code) values(?,?,?,?) `, name, parentid, 0, costCenter_code2).Error
  273. if err != nil {
  274. fmt.Println(err)
  275. return
  276. }
  277. }
  278. }
  279. }
  280. }
  281. func ProviderExec(rows [][]string) {
  282. //for i, v := range rows {
  283. // if i == 0 {
  284. // continue
  285. // }
  286. // id := v[0]
  287. // //sapcode := v[4]
  288. // //providername := v[5]
  289. // status := v[6]
  290. //
  291. // if status == "删除" || v[4] == "" {
  292. // err := s.d.DB.Exec(` delete from provider where id = ? `, id).Error
  293. // if err != nil {
  294. // fmt.Println(err)
  295. // return
  296. // }
  297. // }
  298. //}
  299. //for i, v := range rows {
  300. // if i == 0 {
  301. // continue
  302. // }
  303. // id := v[0]
  304. // sapcode := v[4]
  305. // providername := v[5]
  306. // status := v[6]
  307. //
  308. // if status != "删除" {
  309. // err := s.d.DB.Exec(` update provider set providerIntro = ? , sapcode = ? where id = ? `, providername, sapcode, id).Error
  310. // if err != nil {
  311. // fmt.Println(err)
  312. // return
  313. // }
  314. // }
  315. //}
  316. //for _, v := range rows {
  317. //if i == 0 {
  318. // continue
  319. //}
  320. //id := v[0]
  321. //sapcode := v[4]
  322. //providername := v[1]
  323. //providerIntro := v[5]
  324. //status := v[6]
  325. //
  326. //if status != "删除" {
  327. // err := s.d.DB.Exec(` update provider set providerIntro = ? , sapcode = ? where id = ? `, providername, sapcode, id).Error
  328. // if err != nil {
  329. // fmt.Println(err)
  330. // return
  331. // }
  332. //}
  333. // err := s.d.DB.Exec(` insert into provider(providerName,providerIntro,providerNumber,sapcode) values(?,?,?,?)`,
  334. // providername, providerIntro, sapcode, sapcode).Error
  335. // if err != nil {
  336. // fmt.Println(err)
  337. // return
  338. // }
  339. //}
  340. }
  341. func EquipmentExec(rows [][]string, pastureId int) error {
  342. errList := make([]map[string]interface{}, 0)
  343. for i, v := range rows {
  344. financeCode := v[13]
  345. if financeCode == "" || i == 0 {
  346. continue
  347. }
  348. data := make(map[string]interface{})
  349. fmt.Println(i)
  350. eqCode := v[4]
  351. eqName := v[3]
  352. specification := v[5]
  353. //用途
  354. purpose := v[8]
  355. //purchaseDate, _ := ExcelIntDate(v[10])
  356. //purchaseDate := v[10]
  357. //entranceDate, _ := ExcelIntDate(v[11])
  358. //entranceDate := v[11]
  359. depreciation := v[12]
  360. yuanzhi := v[14]
  361. salvage := v[15]
  362. subtractvalue := v[16]
  363. upkeepgrade := v[17]
  364. if upkeepgrade == "A" {
  365. upkeepgrade = "113"
  366. } else if upkeepgrade == "B" {
  367. upkeepgrade = "114"
  368. } else if upkeepgrade == "C" {
  369. upkeepgrade = "115"
  370. }
  371. yearUpkeepCost := v[18]
  372. yearMaintainCost := v[19]
  373. baseHours := v[20]
  374. employeName := v[22]
  375. inputUser := v[23]
  376. var leaveDate interface{}
  377. if v[24] != "" {
  378. leaveDate = v[24]
  379. //leaveDate, _ = ExcelIntDate(v[24])
  380. }
  381. brand := v[6]
  382. proName := v[7]
  383. maintenance := v[27]
  384. var onepushTime, twopushTime, threepushTime interface{}
  385. if v[29] == "" {
  386. onepushTime = nil
  387. } else {
  388. onepushTime = v[29]
  389. }
  390. if v[31] == "" {
  391. twopushTime = nil
  392. } else {
  393. twopushTime = v[31]
  394. }
  395. if v[33] == "" {
  396. threepushTime = nil
  397. } else {
  398. threepushTime = v[33]
  399. }
  400. levelone := v[28]
  401. leveltwo := v[30]
  402. levelthree := v[32]
  403. brandInfo := model.Brand{}
  404. if brand != "" {
  405. err := s.d.DB.Where(&model.Brand{BrandName: brand}).First(&brandInfo).Error
  406. if err != nil {
  407. fmt.Println(err)
  408. //return err
  409. }
  410. }
  411. provider := model.Provider{}
  412. if proName != "" {
  413. err := s.d.DB.Where(&model.Provider{ProviderName: proName}).First(&provider).Error
  414. if err != nil {
  415. fmt.Println(err)
  416. //return err
  417. }
  418. }
  419. pasture := model.Pasture{}
  420. err := s.d.DB.Where(&model.Pasture{Name: v[0]}).First(&pasture).Error
  421. if err != nil {
  422. data["pasture"] = v[0]
  423. data["eqName"] = eqName
  424. data["eqCode"] = eqCode
  425. data["financeCode"] = financeCode
  426. data["err"] = err.Error()
  427. errList = append(errList, data)
  428. fmt.Println(err)
  429. return err
  430. }
  431. if pastureId != pasture.ID {
  432. continue
  433. }
  434. err = s.d.DB.Exec(` update equipment set eqCode = if(? = '',null,?),specification = ?,purpose = ?
  435. ,depreciation=?,
  436. yuanzhi=?, salvage =?,subtractvalue =?, upkeepgrade= ?,yearUpkeepCost=? ,yearMaintainCost=?,baseHours=?,employeName=(select empname from emp where replace(empname,' ','') = ? and pastureId = ? and enable = 1 ),
  437. employeeId = (select id from emp where replace(empname,' ','') = ? and pastureId = ? and enable = 1 ),inputUser=?,leaveDate=? ,
  438. brand = ?, brandId = ? ,proId= ?,proName= ? ,eqClassName = ?,eqClassId = (select id from eqclass where typeName = ?),eqName = ?,
  439. maintenance= (select GROUP_CONCAT(id) from emp where FIND_IN_SET(replace(empname,' ',''),replace(?,' ','')) and pastureId = ? and enable = 1 ),levelone=(select id from emp where replace(empname,' ','') = replace(?,' ','') and pastureId = ? and enable = 1 ) ,
  440. leveltwo = (select id from emp where replace(empname,' ','') = replace(?,' ','') and pastureId = ? and enable = 1 ),levelthree=(select id from emp where replace(empname,' ','') = replace(?,' ','') and pastureId = ? and enable = 1 )
  441. ,leveloneTime = ? ,leveltwoTime = ?,levelthreeTime= ? where financeCode = ? `,
  442. eqCode, eqCode, specification, purpose, depreciation, yuanzhi,
  443. salvage, subtractvalue, upkeepgrade, yearUpkeepCost, yearMaintainCost, baseHours, employeName, pasture.ID, employeName, pasture.ID, inputUser, leaveDate,
  444. brandInfo.BrandName, brandInfo.ID, provider.ID, provider.ProviderName, eqName, v[1], v[3], maintenance, pasture.ID, levelone, pasture.ID,
  445. leveltwo, pasture.ID, levelthree, pasture.ID, onepushTime, twopushTime, threepushTime, financeCode).Error
  446. if err != nil {
  447. data["pasture"] = v[0]
  448. data["eqName"] = eqName
  449. data["eqCode"] = eqCode
  450. data["financeCode"] = financeCode
  451. data["err"] = err.Error()
  452. errList = append(errList, data)
  453. fmt.Println(err)
  454. //return err
  455. continue
  456. }
  457. eqclass := model.EqClass{}
  458. err = s.d.DB.Table("eqclass").Where("typeName = ?", v[1]).First(&eqclass).Error
  459. if err != nil {
  460. data["pasture"] = v[0]
  461. data["eqName"] = eqName
  462. data["eqCode"] = eqCode
  463. data["financeCode"] = financeCode
  464. data["err"] = err.Error()
  465. errList = append(errList, data)
  466. fmt.Println(err)
  467. //return err
  468. continue
  469. }
  470. if eqclass.ID == 0 {
  471. continue
  472. }
  473. if v[2] == "" {
  474. err = s.d.DB.Exec(` update equipment set assetCode = (select cerateEQNumber((select typeCode from eqclass where typeName = ?),?)) where financeCode = ? `,
  475. v[1], pasture.ID, financeCode).Error
  476. if err != nil {
  477. data["pasture"] = v[0]
  478. data["eqName"] = eqName
  479. data["eqCode"] = eqCode
  480. data["financeCode"] = financeCode
  481. data["err"] = err.Error()
  482. errList = append(errList, data)
  483. fmt.Println(err)
  484. //return err
  485. }
  486. }
  487. }
  488. return nil
  489. }
  490. func ExcelIntDate(dateStr string) (dt time.Time, err error) {
  491. var dateValue float64
  492. matched, err := regexp.MatchString(`^\d+$`, dateStr)
  493. if err != nil {
  494. return
  495. }
  496. if !matched {
  497. err = errors.New("not excel time")
  498. return
  499. }
  500. dateValue, err = strconv.ParseFloat(dateStr, 64)
  501. if err != nil {
  502. return
  503. }
  504. epoch := time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC) // UTC 1899/12/30 00:00:00
  505. dt = epoch.Add(time.Duration(dateValue) * 24 * time.Hour)
  506. return
  507. }
  508. func EquipmentExecAdd(rows [][]string) error {
  509. for i, v := range rows {
  510. financeCode := fmt.Sprintf("%s-%s-%s", v[0], v[1], v[2])
  511. fmt.Println(financeCode, v[11], i)
  512. //financeCode := v[13]
  513. if i == 0 || (v[0] != "1042" && v[0] != "1002") {
  514. continue
  515. }
  516. err := s.d.DB.Exec(` update equipment set pastureid = (SELECT pastureid FROM department WHERE costCenter_code = ? ) where financeCode = ? `, v[11], financeCode).Error
  517. fmt.Println(err)
  518. //var purchaseDate, entranceDate string
  519. //if v[9] != "" {
  520. // date, _ := ExcelIntDate(v[9])
  521. // purchaseDate = date.Format("2006-01-02")
  522. //}
  523. //if v[10] != "" {
  524. // date, _ := ExcelIntDate(v[10])
  525. // entranceDate = date.Format("2006-01-02")
  526. //}
  527. //a1, _ := strconv.Atoi()
  528. //a1, _ := strconv.ParseFloat(v[12][:3], 64)
  529. //n := strings.Index(v[12][3:], "6")
  530. //if n > 0 {
  531. // a1 += 0.5
  532. //}
  533. }
  534. return nil
  535. }
  536. func ContractExec(rows [][]string) {
  537. for i, v := range rows {
  538. if i < 6 {
  539. continue
  540. }
  541. partCode := v[1]
  542. providerSapCode := v[3]
  543. pastureCode := v[6]
  544. price := v[8]
  545. //fmt.Println(partCode, providerSapCode, pastureCode, price)
  546. pasture := model.Pasture{}
  547. err := s.d.DB.Where(model.Pasture{FactoryCode: pastureCode}).First(&pasture).Error
  548. if err != nil {
  549. fmt.Println(err)
  550. //return
  551. continue
  552. }
  553. //fmt.Println(pasture, err)
  554. provider := model.Provider{}
  555. err = s.d.DB.Where(model.Provider{SapCode: providerSapCode}).First(&provider).Error
  556. if err != nil {
  557. fmt.Println(err)
  558. continue
  559. }
  560. contract := model.Contract{}
  561. s.d.DB.Raw(`SELECT
  562. c.id
  563. FROM
  564. contract c
  565. JOIN bigcontract bc ON bc.id = c.bigid
  566. WHERE
  567. c.partCode = ?
  568. AND ? IN (
  569. SELECT
  570. pb.pasture_id
  571. FROM
  572. bigcontract bct
  573. JOIN pasture_bigcontract pb ON pb.bigcontract_id = bct.id
  574. WHERE
  575. bct.contractCode LIKE concat( "%", LEFT ( bc.contractCode, 12 ), "%" )
  576. )
  577. AND bc.providerId = ? `, partCode, pasture.ID, provider.ID).First(&contract)
  578. fmt.Println(pasture.Name, provider.ProviderName, price, pastureCode, i)
  579. if contract.ID > 0 {
  580. s.d.DB.Exec(" update contract set price = ? where id = ? ", price, contract.ID)
  581. }
  582. }
  583. }