synceas.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. package util
  2. import (
  3. "../../pkg/logging"
  4. "../../pkg/setting"
  5. "../../routers/restful"
  6. "errors"
  7. "fmt"
  8. "strconv"
  9. )
  10. // @Summary 现代牧业EAS对接 备件,出入库
  11. type BillLaid struct { // 销售出库&其它出库 &采购入库 & 其他入库
  12. BizType BillNumber `json:"bizType"` //业务类型
  13. BizDate string `json:"bizDate"` //业务日期
  14. Description string `json:"description"` //摘要
  15. PaymentType BillNumber `json:"paymentType"` // 付款方式
  16. TransactionType BillNumber `json:"transactionType"` // 事务类型
  17. Number string `json:"number"` // 单据编号
  18. Entry []BillEntry `json:"entry"` //
  19. StorageOrgUnit BillNumber `json:"storageOrgUnit"` //库存组织
  20. Supplier BillNumber `json:"supplier"` //供应商
  21. Currency BillNumber `json:"currency"` // 币别
  22. Creator BillNumber `json:"creator"` //创建者
  23. }
  24. type BillNumber struct {
  25. Number string `json:"number"`
  26. }
  27. type BillEntry struct {
  28. ActualPrice string `json:"actualPrice"` //实际单价
  29. ActualTaxPrice string `json:"actualTaxPrice"` //实际含税单价
  30. UnitActualCost string `json:"unitActualCost"` //单位实际成本
  31. UnitPurchaseCost string `json:"unitPurchaseCost"` //单位采购成本
  32. TaxPrice string `json:"taxPrice"` //含税单价
  33. BalanceSupplier BillNumber `json:"balanceSupplier"` //结算供应商
  34. Price string `json:"price"` //单价
  35. ActualCost string `json:"actualCost"` //实际成本
  36. PurchaseCost string `json:"purchaseCost"` //采购成本
  37. Amount string `json:"amount"` // 金额
  38. TaxAmount string `json:"taxAmount"` // 价税合计
  39. ContractNumber string `json:"contractNumber"` // 合同号
  40. Warehouse BillNumber `json:"warehouse"` // 仓库
  41. Unit BillNumber `json:"unit"` // 单位
  42. Material BillNumber `json:"material"` //物料
  43. Qty string `json:"qty"` //数量
  44. StoreType BillNumber`json:"storeType"`//库存类型
  45. StoreStatus BillNumber`json:"storeStatus"`//库存状态
  46. }
  47. type BillUse struct { //领料出库&生产入库
  48. Head BillUseHead `json:"head"`
  49. Entrys []BillUseEntrys `json:"entrys"`
  50. }
  51. type BillUseHead struct {
  52. BillNumber string `json:"billNumber"` //单据编号
  53. BizDate string `json:"bizDate"` //业务日期
  54. BizTypeNumber string `json:"bizTypeNumber"` //业务类型
  55. TransactionType string `json:"transactionType"` //事务类型
  56. Department string `json:"department"` //部门
  57. SupplyStorageOrg string `json:"supplyStorageOrg"` //供方库存组织
  58. StorageOrg string `json:"storageOrg"` //需方库存组织
  59. CostCenter string `json:"costCenter"` //成本中心
  60. Remark string `json:"remark"` //摘要
  61. Creator string `json:"creator"` //创建者
  62. }
  63. type BillUseEntrys struct {
  64. MaterielNumber string `json:"materielNumber"` // 物料
  65. Lot string `json:"lot"` //批次
  66. Amount string `json:"amount"` //数量
  67. MeteredUnit string `json:"meteredUnit"` //单位
  68. WareHouse string `json:"wareHouse"` //需方仓库
  69. Location string `json:"location"` //需方库位
  70. Picker string `json:"picker"` // 领料员
  71. EntryRemark string `json:"entryRemark"` //备注
  72. MasterDepartment string `json:"masterDepartment"` //主制部门
  73. EntryCostCenter string `json:"entryCostCenter"` //成本中心
  74. }
  75. type Parts struct { // 备件
  76. MaterialNumber string `json:"materialNumber"`
  77. MaterialName string `json:"materialName"`
  78. MaterialGroup string `json:"materialGroup"`
  79. Model string `json:"model"`
  80. BaseUnit string `json:"baseUnit"`
  81. Status int `json:"status"`
  82. KaClass string `json:"kaClass"`
  83. //kaClass int32 `json:"kaClass"`
  84. //planningMode int32 `json:"planningMode"`
  85. }
  86. func EASBillSync(typeIN int, billCode interface{}, statue string) error {
  87. defer func() {
  88. if err := recover(); err != nil {
  89. logging.Error("EASBillSync recover err :", err)
  90. }
  91. }()
  92. fmt.Println("++++++++++++++++", typeIN, billCode)
  93. var err error
  94. schema := ""
  95. id := ""
  96. switch typeIN {
  97. case 1: // 入库
  98. schema = "bigpartlaid"
  99. id,err = BigpartLaid(billCode, "syncEASPpartlaid", "006")
  100. case 2: // 出库
  101. schema = "bigpartUse"
  102. id,err = BigpartUse(billCode, "syncEASPpartuse", "100")
  103. case 3,10: //退库
  104. schema = "bigpartquit"
  105. if typeIN == 3{
  106. s,err := restful.Engine.SQL("select id from bigpartquit where useForm=? and issync = 0 order by id limit 1",billCode).QueryString()
  107. if len(s) > 0 && err == nil{
  108. billCode = s[0]["id"]
  109. }
  110. }
  111. id,err = BigpartUse(billCode, "syncEASPpartquit", "100")
  112. case 4: //退货
  113. schema = "bigpartrefund"
  114. id,err = BigpartLaid(billCode, "syncEASPpartrefund", "006")
  115. case 5: //备件
  116. schema = "parts"
  117. id = billCode.(string)
  118. err = CheckEASWebServiceParts(statue, "syncEASParts",billCode.(string))
  119. case 6: //调拨入库&出库
  120. schema = "bigparttransfer"
  121. id,err = BigpartLaid(billCode, "syncEASPpartlaid", "008")
  122. case 7: //仅调拨出库
  123. schema = "bigpartUse"
  124. id,err = BigpartUseTransfer(billCode, "syncEASPpartuse", "009")
  125. default:
  126. return errors.New("未知处理类型")
  127. }
  128. tx := restful.Engine.NewSession()
  129. err1 := tx.Begin()
  130. if err1 != nil {
  131. logging.Error("tx.Begin 事务启动失败__error:", err1)
  132. }
  133. defer func() {
  134. switch {
  135. case err1 != nil:
  136. if tx != nil {
  137. tx.Rollback()
  138. }
  139. default:
  140. if tx != nil {
  141. err = tx.Commit()
  142. }
  143. }
  144. if tx != nil {
  145. tx.Close()
  146. }
  147. }()
  148. if err != nil {
  149. logging.Info("EASBillSync err", err)
  150. fmt.Println("EASBillSync err", err)
  151. sql := "update "+schema+" set msg = ? where id =?"
  152. _,err1 =tx.Exec(sql, err.Error(),id)
  153. return err
  154. }
  155. if id == ""{
  156. return nil
  157. }
  158. sql := "update "+schema+" set issync = 1 where id =?"
  159. _,err1 =tx.Exec(sql, id)
  160. return err
  161. }
  162. func CheckEASWebServiceParts(statue, sqlname,id string) error {
  163. if statue == "1" {
  164. valuesMap, err := restful.Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? limit 1", sqlname).QueryString()
  165. sqls := ""
  166. if err == nil && len(valuesMap) > 0 {
  167. sqls = valuesMap[0]["sqlstr"]
  168. }
  169. ress, err := restful.Engine.SQL(sqls, id).QueryString()
  170. if len(ress) == 0 {
  171. logging.Error("CheckEASWebServiceParts select len is 0", len(ress))
  172. return errors.New("查询结果为空")
  173. }
  174. if err != nil {
  175. logging.Error("CheckEASWebServiceParts select err", err)
  176. return err
  177. }
  178. //
  179. //ress, err := restful.Engine.SQL(`SELECT partCode materialNumber,NAME materialName,
  180. // (SELECT VALUE FROM dictlist WHERE pid = 44 AND label = parts.unit) baseUnit,
  181. // LEFT(partCode,11) materialGroup,specification model
  182. // FROM parts WHERE id = ?`, id).QueryString()
  183. //if len(ress) == 0 {
  184. // logging.Error("CheckEASWebServiceParts select len is 0", len(ress))
  185. // return errors.New("查询结果为空")
  186. //}
  187. //if err != nil {
  188. // logging.Error("CheckEASWebServiceParts select err", err)
  189. // return err
  190. //}
  191. var parts = Parts{}
  192. parts.BaseUnit = ress[0]["baseUnit"]
  193. parts.MaterialGroup = ress[0]["materialGroup"]
  194. parts.MaterialName = ress[0]["materialName"]
  195. parts.MaterialNumber = ress[0]["materialNumber"]
  196. parts.KaClass = ress[0]["kaClass"]
  197. parts.Model = ress[0]["model"]
  198. parts.Status = 0
  199. //sessionid, err := EASWebServiceLogin()
  200. //if err != nil {
  201. // logging.Error("EASWebServiceLogin", err)
  202. // return err
  203. //}
  204. sessionid := ""
  205. // 先判断备件与单据是否要分两个地址同步(一个正式线一个测试线)
  206. if setting.ServerSetting.EasUrlTem != ""{
  207. sessionid,err = EASWebServiceLogin(setting.ServerSetting.EasUrlTem)
  208. if err != nil || len(sessionid)<7 {
  209. logging.Info("EASWebServiceLogin",err,sessionid,setting.ServerSetting.EasUrlTem)
  210. return errors.New("eas登录失败")
  211. }
  212. }else{
  213. singelChan <- struct{}{}
  214. sessionid = <- sessionidChan
  215. if len(sessionid)<7 || sessionid[:6] == "error:"{
  216. return errors.New("eas登录失败")
  217. }
  218. }
  219. err = EASWebServicInsertParts(sessionid, parts,setting.ServerSetting.EasUrlTem)
  220. if err != nil {
  221. logging.Error("EASWebServicInsertParts", err)
  222. return err
  223. }
  224. //err = EASWebServiceLogout()
  225. //if err != nil {
  226. // logging.Error("EASWebServiceLogout", err)
  227. //}
  228. }
  229. return nil
  230. //}
  231. }
  232. func BigpartUse(billCode interface{}, sqlname, billType string) (string,error) {
  233. valuesMap, err := restful.Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? limit 1", sqlname).QueryString()
  234. sqls := ""
  235. if err == nil && len(valuesMap) > 0 {
  236. sqls = valuesMap[0]["sqlstr"]
  237. }
  238. ress, err := restful.Engine.SQL(sqls, billCode).QueryString()
  239. if len(ress) == 0 {
  240. logging.Error("BigpartUse select len is 0", len(ress))
  241. return "",errors.New("查询结果为空")
  242. }
  243. if err != nil {
  244. logging.Error("BigpartUse select err", err)
  245. return "",err
  246. }
  247. id := ress[0]["id"]
  248. pu := BillUse{}
  249. pu.Head.BillNumber = ress[0]["BillNumber"]
  250. pu.Head.BizDate = ress[0]["BizDate"]
  251. pu.Head.BizTypeNumber = ress[0]["BizTypeNumber"]
  252. pu.Head.TransactionType = ress[0]["TransactionType"]
  253. pu.Head.Department = ress[0]["Department"]
  254. pu.Head.SupplyStorageOrg = ress[0]["SupplyStorageOrg"]
  255. pu.Head.StorageOrg = ress[0]["StorageOrg"]
  256. pu.Head.Creator = ress[0]["Creator"]
  257. pu.Head.Remark = ress[0]["Remark"]
  258. pu.Head.CostCenter = ress[0]["Department"]
  259. //pu.Head.entryCostCenter
  260. isZeroStock := false //是否零库存
  261. en := make([]BillUseEntrys, len(ress))
  262. count := 0
  263. for key, res := range ress {
  264. if res["isZeroStock"] == "1" {
  265. isZeroStock = true
  266. count ++
  267. }
  268. en[key].Amount = res["Amount"]
  269. en[key].EntryRemark = res["EntryRemark"]
  270. en[key].Lot = res["Lot"]
  271. en[key].MaterielNumber = res["MaterielNumber"]
  272. en[key].MeteredUnit = res["MeteredUnit"]
  273. en[key].Picker = res["Picker"]
  274. en[key].WareHouse = res["WareHouse"]
  275. en[key].Location = res["Location"]
  276. en[key].MasterDepartment = ress[0]["Department"]
  277. en[key].EntryCostCenter = ress[0]["Department"]
  278. //en[key].Location="0202001"
  279. //en[key].WareHouse ="0202001"
  280. }
  281. pu.Entrys = en
  282. pujson, _ := json.Marshal(pu)
  283. //sessionid, err := EASWebServiceLogin()
  284. //if err != nil {
  285. // logging.Error("EASWebServiceLogin", err)
  286. // return id,err
  287. //}
  288. singelChan <- struct{}{}
  289. sessionid := <- sessionidChan
  290. if len(sessionid)<7 || sessionid[:6] == "error:"{
  291. return id,errors.New("eas登录失败")
  292. }
  293. //零库存出库,先进行入库,每个供应商一个入库单
  294. if isZeroStock {
  295. pls := make([]BillLaid, 0)
  296. pl := BillLaid{}
  297. pl.Number = ress[0]["BillNumber"] + "-RK"
  298. pl.TransactionType = BillNumber{
  299. Number: "001",
  300. }
  301. pl.BizDate = ress[0]["BizDate1"]
  302. pl.BizType = BillNumber{
  303. Number: "110",
  304. }
  305. pl.Currency = BillNumber{
  306. Number: "BB01",
  307. }
  308. pl.PaymentType = BillNumber{
  309. Number: "004",
  310. }
  311. pl.StorageOrgUnit = BillNumber{
  312. Number: ress[0]["SupplyStorageOrg"],
  313. }
  314. pl.Supplier = BillNumber{
  315. Number: ress[0]["BalanceSupplier"],
  316. }
  317. pl.Creator = BillNumber{
  318. Number: ress[0]["Creator"],
  319. }
  320. en := make([]BillEntry, 0)
  321. count = 0
  322. temp := ""
  323. cou := 1
  324. code := pl.Number
  325. for _, res := range ress {
  326. if res["isZeroStock"] == "0" {
  327. continue
  328. }
  329. if temp == "" {
  330. temp = res["BalanceSupplier"]
  331. }
  332. if temp != res["BalanceSupplier"]{
  333. pl.Entry = en
  334. pls = append(pls, pl)
  335. pl.Number = code +"-"+ strconv.Itoa(cou)
  336. pl.Supplier = BillNumber{
  337. Number: res["BalanceSupplier"],
  338. }
  339. cou ++
  340. temp = res["BalanceSupplier"]
  341. en = make([]BillEntry, 0)
  342. }
  343. pl.Supplier = BillNumber{
  344. Number: res["BalanceSupplier"],
  345. }
  346. ent := BillEntry{}
  347. ent.Amount = res["SumPrice"]
  348. ent.Qty = res["Amount"]
  349. ent.ActualCost = res["SumPrice"]
  350. ent.ActualPrice = res["Price"]
  351. ent.ActualTaxPrice = res["Price"]
  352. ent.BalanceSupplier = BillNumber{
  353. Number: res["BalanceSupplier"],
  354. }
  355. ent.ContractNumber = res["ContractNumber"]
  356. ent.Material = BillNumber{
  357. Number: res["MaterielNumber"],
  358. }
  359. ent.Price = res["Price"]
  360. ent.PurchaseCost = res["SumPrice"]
  361. ent.TaxAmount = res["SumPrice"]
  362. ent.TaxPrice = res["Price"]
  363. ent.Unit = BillNumber{
  364. Number: res["MeteredUnit"],
  365. }
  366. ent.UnitActualCost = res["SumPrice"]
  367. ent.UnitPurchaseCost = res["Price"]
  368. ent.Warehouse = BillNumber{
  369. Number: res["WareHouse"],
  370. }
  371. en = append(en,ent)
  372. }
  373. pl.Entry = en
  374. pls = append(pls, pl)
  375. pljson, _ := json.Marshal(pls)
  376. //println(string(pljson))
  377. err = EASWebServicInsertPartsuselaid(sessionid, string(pljson), "006")
  378. if err != nil {
  379. logging.Error("EASWebServicInsertPartsuselaid", err)
  380. return id,err
  381. }
  382. }
  383. err = EASWebServicInsertPartsuselaid(sessionid, string(pujson), billType)
  384. if err != nil {
  385. logging.Error("EASWebServicInsertPartsuselaid", err)
  386. return id,err
  387. }
  388. //EASWebServiceLogout()
  389. return id,nil
  390. }
  391. //
  392. func BigpartUseTransfer(billCode interface{}, sqlname, billType string)(string,error) {
  393. valuesMap, err := restful.Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? limit 1", sqlname).QueryString()
  394. sqls := ""
  395. if err == nil && len(valuesMap) > 0 {
  396. sqls = valuesMap[0]["sqlstr"]
  397. }
  398. ress, err := restful.Engine.SQL(sqls, billCode).QueryString()
  399. if len(ress) == 0 {
  400. logging.Error("BigpartUse select len is 0", len(ress))
  401. return "",errors.New("查询结果为空")
  402. }
  403. if err != nil {
  404. logging.Error("BigpartUse select err", err)
  405. return "",err
  406. }
  407. id := ress[0]["id"]
  408. pus := make([]BillLaid, 0)
  409. pu := BillLaid{}
  410. pu.Number = ress[0]["BillNumber"]
  411. pu.TransactionType = BillNumber{
  412. Number: ress[0]["TransactionType"],
  413. }
  414. pu.BizDate = ress[0]["BizDate1"]
  415. pu.BizType = BillNumber{
  416. Number: ress[0]["BizTypeNumber"],
  417. }
  418. pu.Currency = BillNumber{
  419. Number: "BB01",
  420. }
  421. pu.PaymentType = BillNumber{
  422. Number: ress[0]["PaymentType"],
  423. }
  424. pu.StorageOrgUnit = BillNumber{
  425. Number: ress[0]["SupplyStorageOrg"],
  426. }
  427. pu.Supplier = BillNumber{
  428. Number: ress[0]["BalanceSupplier"],
  429. }
  430. pu.Description = ress[0]["Description"]
  431. pu.Creator = BillNumber{
  432. Number: ress[0]["Creator"],
  433. }
  434. en := make([]BillEntry, len(ress))
  435. isZeroStock := false
  436. for key, res := range ress {
  437. //if res["isZeroStock"] == "1" {
  438. // continue
  439. //} else {
  440. isZeroStock = true
  441. //}
  442. en[key].Amount = res["SumPrice"]
  443. en[key].Qty = res["Amount"]
  444. en[key].ActualCost = res["SumPrice"]
  445. en[key].ActualPrice = res["Price"]
  446. en[key].ActualTaxPrice = res["Price"]
  447. en[key].BalanceSupplier = BillNumber{
  448. Number: res["BalanceSupplier"],
  449. }
  450. en[key].ContractNumber = res["ContractNumber"]
  451. en[key].Material = BillNumber{
  452. Number: res["MaterielNumber"],
  453. }
  454. en[key].Price = res["Price"]
  455. en[key].PurchaseCost = res["SumPrice"]
  456. en[key].TaxAmount = res["SumPrice"]
  457. en[key].TaxPrice = res["Price"]
  458. en[key].Unit = BillNumber{
  459. Number: res["MeteredUnit"],
  460. }
  461. en[key].UnitActualCost = res["SumPrice"]
  462. en[key].UnitPurchaseCost = res["Price"]
  463. en[key].Warehouse = BillNumber{
  464. Number: res["WareHouse"],
  465. }
  466. en[key].StoreType= BillNumber{
  467. Number: "G",
  468. }
  469. en[key].StoreStatus= BillNumber{
  470. Number: "1",
  471. }
  472. }
  473. if isZeroStock {
  474. pu.Entry = en
  475. pus = append(pus, pu)
  476. pujson, _ := json.Marshal(pus)
  477. //sessionid, err := EASWebServiceLogin()
  478. //if err != nil {
  479. // logging.Error("EASWebServiceLogin", err)
  480. // return err
  481. //}
  482. singelChan <- struct{}{}
  483. sessionid := <- sessionidChan
  484. if len(sessionid)<7 || sessionid[:6] == "error:"{
  485. return id,errors.New("eas登录失败")
  486. }
  487. err = EASWebServicInsertPartsuselaid(sessionid, string(pujson), billType)
  488. if err != nil {
  489. logging.Error("EASWebServicInsertPartsuselaid", err)
  490. return id,err
  491. }
  492. //EASWebServiceLogout()
  493. }
  494. tx := restful.Engine.NewSession()
  495. err = tx.Begin()
  496. if err != nil {
  497. logging.Error("tx.Begin 事务启动失败__error:", err)
  498. }
  499. defer func() {
  500. switch {
  501. case err != nil:
  502. fmt.Println("__error:", err)
  503. if tx != nil {
  504. tx.Rollback()
  505. }
  506. default:
  507. if tx != nil {
  508. err = tx.Commit()
  509. }
  510. }
  511. if tx != nil {
  512. tx.Close()
  513. }
  514. }()
  515. sql := "update bigpartUse set issync = 1 where id =?"
  516. _,err =tx.Exec(sql, id)
  517. return id,err
  518. }
  519. func BigpartLaid(billCode interface{}, sqlname, billtype string) (string,error ) {
  520. valuesMap, err := restful.Engine.SQL("SELECT sqlstr,params FROM apisql WHERE sqlname = ? limit 1", sqlname).QueryString() //"syncEASPpartlaid"
  521. sqls := ""
  522. if err == nil && len(valuesMap) > 0 {
  523. sqls = valuesMap[0]["sqlstr"]
  524. }
  525. ress, err := restful.Engine.SQL(sqls, billCode).QueryString()
  526. if len(ress) == 0 {
  527. logging.Error("BigpartLaid select len is 0", len(ress))
  528. return "",errors.New("查询结果为空")
  529. }
  530. if err != nil {
  531. logging.Error("BigpartLaid select err", err)
  532. return "",err
  533. }
  534. id := ress[0]["id"]
  535. pls := make([]BillLaid, 0)
  536. pl := BillLaid{}
  537. pl.Number = ress[0]["BillNumber"]
  538. pl.TransactionType = BillNumber{
  539. Number: ress[0]["TransactionType"],
  540. }
  541. pl.BizDate = ress[0]["BizDate"]
  542. pl.BizType = BillNumber{
  543. Number: ress[0]["BizType"],
  544. }
  545. pl.Currency = BillNumber{
  546. Number: ress[0]["Currency"],
  547. }
  548. pl.PaymentType = BillNumber{
  549. Number: ress[0]["PaymentType"],
  550. }
  551. pl.StorageOrgUnit = BillNumber{
  552. Number: ress[0]["StorageOrgUnit"],
  553. }
  554. pl.Supplier = BillNumber{
  555. Number: ress[0]["BalanceSupplier"],
  556. }
  557. pl.Description = ress[0]["Description"]
  558. pl.Creator = BillNumber{
  559. Number: ress[0]["Creator"],
  560. }
  561. en := make([]BillEntry, len(ress))
  562. isZeroStock := false
  563. for key, res := range ress { // 零库存入库跳过
  564. if res["isZeroStock"] == "1" {
  565. continue
  566. } else {
  567. isZeroStock = true
  568. }
  569. pl.Supplier = BillNumber{
  570. Number: res["BalanceSupplier"],
  571. }
  572. en[key].Amount = res["Amount"]
  573. en[key].Qty = res["Qty"]
  574. en[key].ActualCost = res["ActualCost"]
  575. en[key].ActualPrice = res["ActualPrice"]
  576. en[key].ActualTaxPrice = res["ActualTaxPrice"]
  577. en[key].BalanceSupplier = BillNumber{
  578. Number: res["BalanceSupplier"],
  579. }
  580. en[key].ContractNumber = res["ContractNumber"]
  581. en[key].Material = BillNumber{
  582. Number: res["Material"],
  583. }
  584. en[key].Price = res["Price"]
  585. en[key].PurchaseCost = res["PurchaseCost"]
  586. en[key].TaxAmount = res["TaxAmount"]
  587. en[key].TaxPrice = res["TaxPrice"]
  588. en[key].Unit = BillNumber{
  589. Number: res["Unit"],
  590. }
  591. en[key].UnitActualCost = res["UnitActualCost"]
  592. en[key].UnitPurchaseCost = res["UnitPurchaseCost"]
  593. en[key].Warehouse = BillNumber{
  594. Number: res["Warehouse"],
  595. }
  596. }
  597. if isZeroStock {
  598. pl.Entry = en
  599. pls = append(pls, pl)
  600. pujson, _ := json.Marshal(pls)
  601. //sessionid, err := EASWebServiceLogin()
  602. //if err != nil {
  603. // logging.Error("EASWebServiceLogin", err)
  604. // return id,err
  605. //}
  606. singelChan <- struct{}{}
  607. sessionid := <- sessionidChan
  608. if len(sessionid)<7 || sessionid[:6] == "error:"{
  609. return id,errors.New("eas登录失败")
  610. }
  611. err = EASWebServicInsertPartsuselaid(sessionid, string(pujson), billtype)
  612. if err != nil {
  613. logging.Error("EASWebServicInsertPartsuselaid", err)
  614. return id,err
  615. }
  616. if billtype == "008" { // 为调拨入库时
  617. _,err = BigpartUseTransfer(ress[0]["useCode"], "syncEASPpartuse", "009")
  618. }
  619. //err = EASWebServiceLogout()
  620. //if err != nil {
  621. // fmt.Println("EASWebServiceLogout",err)
  622. //}
  623. }
  624. return id,nil
  625. }