api.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/jmoiron/sqlx"
  6. "github.com/pkg/errors"
  7. "kpt.xdmy/apiserver/model"
  8. "kpt.xdmy/apiserver/model/http"
  9. "kpt.xdmy/apiserver/service"
  10. "kpt.xdmy/pkg/log"
  11. )
  12. var svc *service.Service
  13. func Init(s *service.Service) {
  14. svc = s
  15. }
  16. type nextServiceInfo struct {
  17. laidType int64
  18. useType int64
  19. }
  20. func NextService(p []map[string]interface{}, tx *sqlx.Tx, vendor int64) error {
  21. isTransfer := false
  22. for _, v := range p {
  23. if v["name"] == nil || v["parammaps"] == nil {
  24. continue
  25. }
  26. sqlname := v["name"].(string)
  27. if sqlname == "updateBigPartTransfer" {
  28. isTransfer = true
  29. } else if sqlname == "insertBigPartUse" {
  30. pf := v["parammaps"].(map[string]interface{})
  31. if pf["useType"].(float64) != 5 {
  32. if _, ok := pf["oddCode"]; !ok {
  33. return errors.New("oddCode 不能为空 !!!")
  34. }
  35. }
  36. }
  37. }
  38. if isTransfer {
  39. var bigPartTransferid float64
  40. insertBigPartlaid := false
  41. for _, v := range p {
  42. if v["name"] == nil || v["parammaps"] == nil {
  43. continue
  44. }
  45. pf := v["parammaps"].(map[string]interface{})
  46. sqlname := v["name"].(string)
  47. if sqlname == "updateBigPartTransfer" {
  48. bigPartTransferid = pf["id"].(float64)
  49. } else if sqlname == "insertBigPartlaid" {
  50. insertBigPartlaid = true
  51. }
  52. }
  53. if bigPartTransferid > 0 && insertBigPartlaid {
  54. //if laidType == 2 {
  55. partTransfer := make([]*model.PartTransferStr, 0)
  56. partsByte, err := service.GetDataList(tx, `select * from parttransfer where bigid = ? `, []interface{}{bigPartTransferid})
  57. if err != nil {
  58. return errors.New("无调拨信息!!!")
  59. }
  60. if partsByte != nil {
  61. err := json.Unmarshal(partsByte, &partTransfer)
  62. if err != nil {
  63. return errors.New("调拨信息转码出错!!!")
  64. }
  65. }
  66. for _, part := range partTransfer {
  67. prByte, err := service.MapStr(tx, `select * from part_repertory where id = ? and reportery >= ? `, part.PartRepID, part.Amount)
  68. if err != nil {
  69. return errors.New("库存信息出错!!!")
  70. }
  71. if prByte != nil {
  72. data := make(map[string]interface{})
  73. err := json.Unmarshal(prByte, &data)
  74. if err != nil {
  75. return errors.New("库存信息出错!!!")
  76. }
  77. if _, ok := data["id"]; !ok {
  78. return errors.New("库存信息出错!!!")
  79. }
  80. } else {
  81. return errors.New("库存信息出错!!!")
  82. }
  83. _, err = tx.Exec(` update part_repertory set reportery = reportery - ? where id = ? `, part.Amount, part.PartRepID)
  84. if err != nil {
  85. return errors.New("库存调整出错!!!")
  86. }
  87. }
  88. if vendor == 1 {
  89. err = service.ManualTransfer(bigPartTransferid, tx)
  90. if err != nil {
  91. return err
  92. }
  93. }
  94. }
  95. } else if vendor == 1 {
  96. for _, v := range p {
  97. if v["name"] == nil || v["parammaps"] == nil {
  98. continue
  99. }
  100. pf := v["parammaps"].(map[string]interface{})
  101. sqlname := v["name"].(string)
  102. fmt.Println(sqlname)
  103. switch sqlname {
  104. case "insertBigPartlaid":
  105. laidType := pf["laidType"].(float64)
  106. log.Info(v)
  107. //b, _ := json.Marshal(p)
  108. //pnext := new(nextServiceInfo)
  109. //json.Unmarshal(b, &pnext)
  110. //switch pnext.laidType {
  111. //手动出库没有采购单号,所以不能传SAP
  112. //case 0:
  113. // 入库-申购、采购(申购、线上、寄售)
  114. if laidType != 2 {
  115. pr := new(http.ProofPartReq)
  116. pr.LaidCode = pf["laidCode"].(string)
  117. pr.StorageTime = pf["storageTime"].(string)
  118. err := svc.LaidProof(pr, tx)
  119. if err != nil {
  120. return err
  121. }
  122. }
  123. case "insertBigPartUse":
  124. //b, _ := json.Marshal(p)
  125. //pnext := new(nextServiceInfo)
  126. //json.Unmarshal(b, &pnext)
  127. log.Info(v)
  128. pr := new(http.ProofPartReq)
  129. pr.UseForm = pf["useForm"].(string)
  130. pr.StorageTime = pf["receiveTime"].(string)
  131. err := svc.UseProof(pf, tx)
  132. if err != nil {
  133. return err
  134. }
  135. //}
  136. case "updatePartRepertoryTHS":
  137. log.Info(v)
  138. // 退货
  139. err := svc.RefundProof(pf, tx)
  140. if err != nil {
  141. return err
  142. }
  143. case "insertBigPartquit":
  144. log.Info(v)
  145. // 退库
  146. err := svc.QuitProof(pf, tx)
  147. if err != nil {
  148. return err
  149. }
  150. }
  151. }
  152. }
  153. return nil
  154. }