jct-body-copy.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package controllers_join
  2. import (
  3. "encoding/json"
  4. controllers_func "kkscrap-go/controllers/func"
  5. "kkscrap-go/locals"
  6. models_join "kkscrap-go/models/join"
  7. "net/http"
  8. "github.com/dabory/abango-rest"
  9. "github.com/labstack/echo"
  10. )
  11. type BodyCopyPageReq struct {
  12. QueryVars locals.QueryVars
  13. BodyCopyPageVars locals.BodyCopyPageVars
  14. PageVars locals.PageVars
  15. }
  16. func BodyCopyPage(c echo.Context) error {
  17. v := c.Get("receiver").(BodyCopyPageReq)
  18. y := c.Get("abango").(abango.Controller)
  19. vRet := &struct {
  20. models_join.BodyCopyPageRet
  21. }{}
  22. vRet.QueryVars = v.QueryVars
  23. vRet.BodyCopyPageVars = v.BodyCopyPageVars
  24. vRet.PageVars = v.PageVars
  25. if err := vRet.GetBodyCopyPage(&y); err != nil {
  26. return c.String(607, err.Error())
  27. }
  28. ret, _ := json.Marshal(vRet)
  29. return c.JSONBlob(http.StatusOK, ret)
  30. }
  31. type BodyCopyMactReq struct {
  32. QueryVars locals.QueryVars
  33. LastSeqNoVars controllers_func.LastSeqNoGetReq
  34. Page []locals.BodyCopyBase
  35. }
  36. func BodyCopyMact(c echo.Context) error {
  37. v := c.Get("receiver").(BodyCopyMactReq)
  38. y := c.Get("abango").(abango.Controller)
  39. vRet := &struct {
  40. models_join.BodyCopyMactRet
  41. }{}
  42. // var msg string
  43. // var accErr error
  44. q := &v.QueryVars
  45. sn := &v.LastSeqNoVars
  46. // if if v.q{
  47. // return c.String(608, "Transaction Commit Failed")
  48. // }
  49. vIdRet := &locals.IdBase{}
  50. sess := y.Db.NewSession()
  51. defer sess.Close()
  52. if err := sess.Begin(); err == nil {
  53. for _, row := range v.Page {
  54. seqNo := 0
  55. if serial, err := controllers_func.LastSerial(&y, sn.TableName+sn.SlipNo); err == nil {
  56. seqNo = serial
  57. } else {
  58. return c.String(605, err.Error())
  59. }
  60. if addId, err := models_join.BodyCopyAdd(&y, q.QueryName, sn.TableName, sn.SlipNo, seqNo, row.BdId, row.Qty); err == nil {
  61. vIdRet.Id = addId
  62. vRet.Page = append(vRet.Page, *vIdRet)
  63. } else {
  64. sess.Rollback()
  65. return c.String(603, err.Error())
  66. }
  67. // if addId, err := models_join.BodyCopyAdd(&y, q.QueryName, v.SlipId, seqNo, row.BdId, row.Qty); err == nil {
  68. // vIdRet.Id = addId
  69. // vRet.Page = append(vRet.Page, *vIdRet)
  70. // } else {
  71. // sess.Rollback()
  72. // return c.String(603, err.Error())
  73. // }
  74. }
  75. } else {
  76. return c.String(608, "Transaction Action Failed")
  77. }
  78. if err := sess.Commit(); err != nil {
  79. return c.String(608, "Transaction Commit Failed")
  80. }
  81. ret, _ := json.Marshal(vRet)
  82. return c.JSONBlob(http.StatusOK, ret)
  83. }