sap.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. package routers
  2. import (
  3. "github.com/360EntSecGroup-Skylar/excelize"
  4. "github.com/Anderson-Lu/gofasion/gofasion"
  5. "github.com/gin-gonic/gin"
  6. "github.com/pkg/errors"
  7. "io/ioutil"
  8. "kpt.xdmy/apiserver/model"
  9. "kpt.xdmy/apiserver/model/http"
  10. "kpt.xdmy/apiserver/routers/restful"
  11. "kpt.xdmy/apiserver/service"
  12. "kpt.xdmy/pkg/logging"
  13. "strconv"
  14. )
  15. func ProofList(c *gin.Context) {
  16. p := new(model.ProofReq)
  17. //if !Bind(c, p) {
  18. // return
  19. //}
  20. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  21. fsion := gofasion.NewFasion(string(dataByte))
  22. p.OrderNumber = fsion.Get("OrderNumber").ValueStr()
  23. p.NumberType = fsion.Get("NumberType").ValueInt()
  24. rp := service.ProofList(p)
  25. c.JSON(200, &rp)
  26. }
  27. func ProofOff(c *gin.Context) {
  28. p := new(model.ProofReq)
  29. if !Bind(c, p) {
  30. return
  31. }
  32. rp := svc.ProofOff(p)
  33. c.JSON(200, &rp)
  34. }
  35. func ProofOffList(c *gin.Context) {
  36. p := new(model.ProofReq)
  37. if !Bind(c, p) {
  38. return
  39. }
  40. rp := service.ProofList(p)
  41. c.JSON(rp.Code, &rp)
  42. }
  43. func ManualTransfer(c *gin.Context) {
  44. list := make([]*http.ManaulReq, 0)
  45. //p := new(http.ManaulReq)
  46. c.Bind(&list)
  47. tx, err := restful.Dbs.Beginx()
  48. defer func() {
  49. switch {
  50. case err != nil:
  51. logging.Error("tx.Begin 事务启动失败__error:", err)
  52. if tx != nil {
  53. tx.Rollback()
  54. }
  55. default:
  56. if tx != nil {
  57. err = tx.Commit()
  58. }
  59. }
  60. }()
  61. for _, item := range list {
  62. err := service.ManualTransfer(item.Id, tx)
  63. if err == nil {
  64. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"})
  65. return
  66. } else {
  67. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"})
  68. return
  69. }
  70. }
  71. }
  72. func ManaulSapOrder(c *gin.Context) {
  73. ////dataByte, _ := ioutil.ReadAll(c.Request.Body)
  74. ////fsion := gofasion.NewFasion(string(dataByte))
  75. ////for _, code := range fsion.Array() {
  76. //if e := service.ManaulSapOrderJob(""); e != nil {
  77. // c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"})
  78. // return
  79. //}
  80. ////}
  81. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  82. fsion := gofasion.NewFasion(string(dataByte))
  83. for _, code := range fsion.Array() {
  84. if e := service.ManaulSapOrderJob(code.Get("buyeCode").ValueStr()); e != nil {
  85. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"})
  86. return
  87. }
  88. }
  89. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"})
  90. }
  91. func ManaulSrmOrderJob(c *gin.Context) {
  92. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  93. fsion := gofasion.NewFasion(string(dataByte))
  94. //parammaps := fsion.Get("list").Array()
  95. for _, code := range fsion.Array() {
  96. service.ManaulSrmOrderJob(code.Get("buyeCode").ValueStr())
  97. }
  98. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"})
  99. }
  100. //手动入库
  101. func LaidProof(c *gin.Context) {
  102. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  103. fsion := gofasion.NewFasion(string(dataByte))
  104. //parammaps := fsion.Get("list").Array()
  105. var err []error
  106. tx, err1 := restful.Dbs.Beginx()
  107. if err1 != nil {
  108. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  109. return
  110. }
  111. for _, parammap := range fsion.Array() {
  112. p := new(http.ProofPartReq)
  113. p.LaidCode = parammap.Get("laidCode").ValueStr()
  114. p.StorageTime = parammap.Get("creatTime").ValueStr()
  115. err1 := svc.LaidProof(p, tx)
  116. err = append(err, err1)
  117. }
  118. err1 = tx.Commit()
  119. if err1 != nil {
  120. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  121. return
  122. }
  123. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"})
  124. }
  125. //手动出库
  126. func UseProof(c *gin.Context) {
  127. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  128. fsion := gofasion.NewFasion(string(dataByte))
  129. //parammaps := fsion.Get("list").Array()
  130. tx, err1 := restful.Dbs.Beginx()
  131. if err1 != nil {
  132. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  133. return
  134. }
  135. for _, parammap := range fsion.Array() {
  136. p := new(http.ProofPartReq)
  137. p.UseForm = parammap.Get("useForm").ValueStr()
  138. p.ReceiveTime = parammap.Get("creatTime").ValueStr()
  139. svc.UseProof(p, tx)
  140. }
  141. err1 = tx.Commit()
  142. if err1 != nil {
  143. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  144. return
  145. }
  146. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"})
  147. }
  148. //手动退货
  149. func RefundProof(c *gin.Context) {
  150. //p := make([]*http.ProofPartReq, 0)
  151. //c.Bind(&p)
  152. //for _, item := range p {
  153. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  154. fsion := gofasion.NewFasion(string(dataByte))
  155. //parammaps := fsion.Get("list").Array()
  156. tx, err1 := restful.Dbs.Beginx()
  157. if err1 != nil {
  158. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  159. return
  160. }
  161. for _, parammap := range fsion.Array() {
  162. p := new(http.ProofPartReq)
  163. p.ID = parammap.Get("id").ValueInt()
  164. svc.RefundProof(p, tx)
  165. }
  166. err1 = tx.Commit()
  167. if err1 != nil {
  168. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  169. return
  170. }
  171. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 0}, "msg": "ok"})
  172. }
  173. //手动退库
  174. func QuitProof(c *gin.Context) {
  175. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  176. fsion := gofasion.NewFasion(string(dataByte))
  177. //parammaps := fsion.Get("list").Array()
  178. tx, err1 := restful.Dbs.Beginx()
  179. if err1 != nil {
  180. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  181. return
  182. }
  183. for _, parammap := range fsion.Array() {
  184. p := new(http.ProofPartReq)
  185. p.UseForm = parammap.Get("useForm").ValueStr()
  186. p.QuitDate = parammap.Get("quitDate").ValueStr()
  187. svc.QuitProof(p, tx)
  188. }
  189. err1 = tx.Commit()
  190. if err1 != nil {
  191. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": err1})
  192. return
  193. }
  194. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"})
  195. }
  196. func Exec(c *gin.Context) {
  197. file, err := c.FormFile("file")
  198. if err != nil {
  199. err = errors.Wrap(err, "AddManagement-error")
  200. return
  201. }
  202. f, _ := file.Open()
  203. xlsx1, err := excelize.OpenReader(f)
  204. rows := xlsx1.GetRows("人员花名册")
  205. service.Exec(rows)
  206. }
  207. func DepartmentExec(c *gin.Context) {
  208. file, err := c.FormFile("file")
  209. if err != nil {
  210. err = errors.Wrap(err, "AddManagement-error")
  211. return
  212. }
  213. f, _ := file.Open()
  214. xlsx1, err := excelize.OpenReader(f)
  215. rows := xlsx1.GetRows("Sheet1")
  216. service.DepartmentExec(rows)
  217. }
  218. func ProviderExec(c *gin.Context) {
  219. file, err := c.FormFile("file")
  220. if err != nil {
  221. err = errors.Wrap(err, "AddManagement-error")
  222. return
  223. }
  224. f, _ := file.Open()
  225. xlsx1, err := excelize.OpenReader(f)
  226. rows := xlsx1.GetRows("Sheet1")
  227. service.ProviderExec(rows)
  228. }
  229. func EquipmentExec(c *gin.Context) {
  230. file, err := c.FormFile("file")
  231. if err != nil {
  232. err = errors.Wrap(err, "AddManagement-error")
  233. return
  234. }
  235. pastureIdstr := c.PostForm("pastureId")
  236. //dataByte, _ := ioutil.ReadAll(c.Request.Body)
  237. //fsion := gofasion.NewFasion(string(dataByte))
  238. //pastureId := fsion.Get("pastureId").ValueInt()
  239. f, _ := file.Open()
  240. xlsx1, err := excelize.OpenReader(f)
  241. rows := xlsx1.GetRows("设备基础信息")
  242. pastureId, err := strconv.Atoi(pastureIdstr)
  243. if err != nil {
  244. panic(err)
  245. }
  246. err = service.EquipmentExec(rows, pastureId)
  247. if err != nil {
  248. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"})
  249. return
  250. }
  251. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"})
  252. }
  253. func EquipmentExecAdd(c *gin.Context) {
  254. file, err := c.FormFile("file")
  255. if err != nil {
  256. err = errors.Wrap(err, "AddManagement-error")
  257. return
  258. }
  259. f, _ := file.Open()
  260. xlsx1, err := excelize.OpenReader(f)
  261. rows := xlsx1.GetRows("财务资产汇总")
  262. err = service.EquipmentExecAdd(rows)
  263. if err != nil {
  264. c.JSON(500, map[string]interface{}{"code": 500, "data": map[string]interface{}{"code": 0}, "msg": "fail"})
  265. return
  266. }
  267. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"})
  268. }
  269. func ContractExec(c *gin.Context) {
  270. file, err := c.FormFile("file")
  271. if err != nil {
  272. err = errors.Wrap(err, "AddManagement-error")
  273. return
  274. }
  275. f, _ := file.Open()
  276. xlsx1, err := excelize.OpenReader(f)
  277. rows := xlsx1.GetRows("三位小数清单")
  278. service.ContractExec(rows)
  279. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"})
  280. }
  281. func PostPushContractDataToSAP(c *gin.Context) {
  282. req := new(http.PostPushContractDataToSAPReq)
  283. hrp := new(http.Response)
  284. if err := c.ShouldBind(&req); err != nil {
  285. hrp.Code = 200
  286. hrp.Message = err.Error()
  287. hrp.Msg = "fail"
  288. hrp.Data = err.Error()
  289. c.JSON(200, hrp)
  290. return
  291. }
  292. err := svc.PostPushContractDataToSAP(req.PastureId, req.ProviderId, req.ContractIdList)
  293. if err != nil {
  294. hrp.Code = 200
  295. hrp.Message = err.Error()
  296. hrp.Msg = "fail"
  297. hrp.Data = err.Error()
  298. c.JSON(200, hrp)
  299. return
  300. }
  301. c.JSON(200, map[string]interface{}{"code": 200, "data": map[string]interface{}{"code": 200}, "msg": "ok"})
  302. }