seq.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. // seqID return id
  8. func seqID(c *bm.Context) {
  9. params := c.Request.Form
  10. bsIDStr := params.Get("businessID")
  11. // check params
  12. bsID, err := strconv.ParseInt(bsIDStr, 10, 64)
  13. if err != nil {
  14. c.JSON(nil, ecode.RequestErr)
  15. return
  16. }
  17. token := params.Get("token")
  18. if token == "" {
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. c.JSON(seqSvc.ID(c, bsID, token))
  23. }
  24. // seqID32 return id32
  25. func seqID32(c *bm.Context) {
  26. params := c.Request.Form
  27. bsIDStr := params.Get("businessID")
  28. // check params
  29. bsID, err := strconv.ParseInt(bsIDStr, 10, 64)
  30. if err != nil {
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. token := params.Get("token")
  35. if token == "" {
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. id, err := seqSvc.ID32(c, bsID, token)
  40. if err != nil {
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. c.JSON(id, nil)
  45. }
  46. // maxSeq update maxseq.
  47. func maxSeq(c *bm.Context) {
  48. params := c.Request.Form
  49. bsIDStr := params.Get("businessID")
  50. maxSeqStr := params.Get("maxseq")
  51. stepStr := params.Get("step")
  52. token := params.Get("token")
  53. // check params
  54. bsID, err := strconv.ParseInt(bsIDStr, 10, 64)
  55. if err != nil {
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. maxSeq, err := strconv.ParseInt(maxSeqStr, 10, 64)
  60. if err != nil {
  61. c.JSON(nil, ecode.RequestErr)
  62. return
  63. }
  64. step, err := strconv.ParseInt(stepStr, 10, 64)
  65. if err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. if token == "" {
  70. c.JSON(nil, ecode.RequestErr)
  71. return
  72. }
  73. if err = seqSvc.UpMaxSeq(c, bsID, maxSeq, step, token); err != nil {
  74. c.JSON(nil, err)
  75. return
  76. }
  77. c.JSON(maxSeq, nil)
  78. }