api.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  6. "gitee.com/xuyiping_admin/pkg/apierr"
  7. "gitee.com/xuyiping_admin/pkg/ginutil"
  8. "gitee.com/xuyiping_admin/pkg/valid"
  9. "gitee.com/xuyiping_admin/pkg/xerr"
  10. "github.com/gin-gonic/gin"
  11. "github.com/jmoiron/sqlx"
  12. "github.com/pkg/errors"
  13. "kpt.xdmy/apiserver/model"
  14. modelHttp "kpt.xdmy/apiserver/model/http"
  15. "kpt.xdmy/apiserver/service"
  16. "kpt.xdmy/pkg/app"
  17. "kpt.xdmy/pkg/e"
  18. "kpt.xdmy/pkg/log"
  19. "net/http"
  20. modernPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/xdmy"
  21. )
  22. var svc *service.Service
  23. func Init(s *service.Service) {
  24. svc = s
  25. }
  26. type nextServiceInfo struct {
  27. laidType int64
  28. useType int64
  29. }
  30. func NextService(p []map[string]interface{}, tx *sqlx.Tx, vendor int64) error {
  31. isTransfer := false
  32. for _, v := range p {
  33. if v["name"] == nil || v["parammaps"] == nil {
  34. continue
  35. }
  36. sqlname := v["name"].(string)
  37. if sqlname == "updateBigPartTransfer" {
  38. isTransfer = true
  39. } else if sqlname == "insertBigPartUse" {
  40. pf := v["parammaps"].(map[string]interface{})
  41. if pf["useType"].(float64) < 5 {
  42. if _, ok := pf["oddCode"]; !ok {
  43. return errors.New("oddCode 不能为空 !!!")
  44. }
  45. }
  46. }
  47. }
  48. if isTransfer {
  49. var bigPartTransferid float64
  50. insertBigPartlaid := false
  51. for _, v := range p {
  52. if v["name"] == nil || v["parammaps"] == nil {
  53. continue
  54. }
  55. pf := v["parammaps"].(map[string]interface{})
  56. sqlname := v["name"].(string)
  57. if sqlname == "updateBigPartTransfer" {
  58. bigPartTransferid = pf["id"].(float64)
  59. } else if sqlname == "insertBigPartlaid" {
  60. insertBigPartlaid = true
  61. }
  62. }
  63. if bigPartTransferid > 0 && insertBigPartlaid {
  64. //if laidType == 2 {
  65. partTransfer := make([]*model.PartTransferStr, 0)
  66. partsByte, err := service.GetDataList(tx, `select * from parttransfer where bigid = ? `, []interface{}{bigPartTransferid})
  67. if err != nil {
  68. return errors.New("无调拨信息!!!")
  69. }
  70. if partsByte != nil {
  71. err := json.Unmarshal(partsByte, &partTransfer)
  72. if err != nil {
  73. return errors.New("调拨信息转码出错!!!")
  74. }
  75. }
  76. for _, part := range partTransfer {
  77. prByte, err := service.MapStr(tx, `select * from part_repertory where id = ? and reportery >= ? `, part.PartRepID, part.Amount)
  78. if err != nil {
  79. return errors.New("库存信息出错!!!")
  80. }
  81. if prByte != nil {
  82. data := make(map[string]interface{})
  83. err := json.Unmarshal(prByte, &data)
  84. if err != nil {
  85. return errors.New("库存信息出错!!!")
  86. }
  87. if _, ok := data["id"]; !ok {
  88. return errors.New("库存信息出错!!!")
  89. }
  90. } else {
  91. return errors.New("库存信息出错!!!")
  92. }
  93. _, err = tx.Exec(` update part_repertory set reportery = reportery - ? where id = ? `, part.Amount, part.PartRepID)
  94. if err != nil {
  95. return errors.New("库存调整出错!!!")
  96. }
  97. }
  98. if vendor == 1 {
  99. err = service.ManualTransfer(bigPartTransferid, tx)
  100. if err != nil {
  101. return err
  102. }
  103. }
  104. }
  105. } else if vendor == 1 {
  106. for _, v := range p {
  107. if v["name"] == nil || v["parammaps"] == nil {
  108. continue
  109. }
  110. pf := v["parammaps"].(map[string]interface{})
  111. sqlname := v["name"].(string)
  112. fmt.Println(sqlname)
  113. switch sqlname {
  114. case "insertBigPartlaid":
  115. laidType := pf["laidType"].(float64)
  116. log.Info(v)
  117. //b, _ := json.Marshal(p)
  118. //pnext := new(nextServiceInfo)
  119. //json.Unmarshal(b, &pnext)
  120. //switch pnext.laidType {
  121. //手动出库没有采购单号,所以不能传SAP
  122. //case 0:
  123. // 入库-申购、采购(申购、线上、寄售)
  124. if laidType != 2 {
  125. pr := new(modelHttp.ProofPartReq)
  126. pr.LaidCode = pf["laidCode"].(string)
  127. pr.StorageTime = pf["storageTime"].(string)
  128. err := svc.LaidProof(pr, tx)
  129. if err != nil {
  130. return err
  131. }
  132. }
  133. case "insertBigPartUse":
  134. //b, _ := json.Marshal(p)
  135. //pnext := new(nextServiceInfo)
  136. //json.Unmarshal(b, &pnext)
  137. log.Info(v)
  138. pr := new(modelHttp.ProofPartReq)
  139. pr.UseForm = pf["useForm"].(string)
  140. pr.StorageTime = pf["receiveTime"].(string)
  141. err := svc.UseProof(pf, tx)
  142. if err != nil {
  143. return err
  144. }
  145. //}
  146. case "updatePartRepertoryTHS":
  147. log.Info(v)
  148. // 退货
  149. err := svc.RefundProof(pf, tx)
  150. if err != nil {
  151. return err
  152. }
  153. case "insertBigPartquit":
  154. log.Info(v)
  155. // 退库
  156. err := svc.QuitProof(pf, tx)
  157. if err != nil {
  158. return err
  159. }
  160. }
  161. }
  162. }
  163. return nil
  164. }
  165. // SparePartsRequisitions 备件申购-特殊申购
  166. func SparePartsRequisitions(c *gin.Context) {
  167. var req modernPb.SparePartsRequisitionsRequest
  168. if err := ginutil.BindProto(c, &req); err != nil {
  169. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  170. return
  171. }
  172. if err := valid.ValidateStruct(&req,
  173. valid.Field(&req.OrderNumber, valid.Required, valid.Length(1, 100)),
  174. valid.Field(&req.PastureId, valid.Required),
  175. valid.Field(&req.DepartmentId, valid.Required),
  176. valid.Field(&req.EmployeId, valid.Required),
  177. valid.Field(&req.CreateTime, valid.Required),
  178. valid.Field(&req.PurchaseType, valid.Required),
  179. //valid.Field(&req.ProviderName, valid.Required, valid.Length(1, 100)),
  180. ); err != nil {
  181. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  182. return
  183. }
  184. if req.PurchaseType != modernPb.PurchaseType_Advance_Payment {
  185. if err := valid.ValidateStruct(&req,
  186. valid.Field(&req.ProviderId, valid.Required),
  187. ); err != nil {
  188. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  189. return
  190. }
  191. }
  192. if len(req.SpotList) <= 0 {
  193. apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Custom("备件列表不能为空"))
  194. return
  195. }
  196. if err := service.CreateSpecialtyPurchase(c, &req); err != nil {
  197. //apierr.ClassifiedAbort(c, err)
  198. appG := app.Gin{C: c}
  199. appG.Response(200, e.ERROR, err.Error())
  200. return
  201. }
  202. ginutil.JSONResp(c, &operationPb.CommonOK{
  203. Code: http.StatusOK,
  204. Msg: "ok",
  205. Data: &operationPb.Success{Success: true},
  206. })
  207. }
  208. func GetDieselTypeList(c *gin.Context) {
  209. res := &modernPb.DieselTypeListResponse{
  210. Code: http.StatusOK,
  211. Msg: "ok",
  212. Data: &modernPb.DieselTypeList{
  213. DieselType: make([]*modernPb.DieselTypeEnum, 0),
  214. },
  215. }
  216. res.Data.DieselType = append(res.Data.DieselType, &modernPb.DieselTypeEnum{
  217. Value: modernPb.DieselType_Zero,
  218. Label: "0号",
  219. }, &modernPb.DieselTypeEnum{
  220. Value: modernPb.DieselType_Ten,
  221. Label: "10号",
  222. }, &modernPb.DieselTypeEnum{
  223. Value: modernPb.DieselType_Twenty,
  224. Label: "20号",
  225. }, &modernPb.DieselTypeEnum{
  226. Value: modernPb.DieselType_Thirty,
  227. Label: "30号",
  228. }, &modernPb.DieselTypeEnum{
  229. Value: modernPb.DieselType_Thirty_Five,
  230. Label: "35号",
  231. })
  232. ginutil.JSONResp(c, res)
  233. }