factory.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package controller
  2. import (
  3. v1 "demo/api/v1"
  4. "demo/internal/app"
  5. "demo/internal/model"
  6. "github.com/gogf/gf/v2/net/ghttp"
  7. "github.com/pkg/errors"
  8. "github.com/siddontang/go/log"
  9. "time"
  10. )
  11. // AddFactory
  12. // @Summary 脖环出厂登记添加
  13. // @Description add by json account
  14. // @Tags 脖环出厂登记
  15. // @Accept json
  16. // @Produce json
  17. // @Param account body v1.AddFactoryReq true "Add account"
  18. // @Router /factory/add [post]
  19. func AddFactory(r *ghttp.Request) {
  20. var req *v1.AddFactoryReq
  21. username := r.Context().Value("jwt_username")
  22. appG := app.Ghttp{C: r}
  23. err := appG.C.Parse(&req)
  24. if err != nil {
  25. err = errors.Wrap(err, "AddFactory-error")
  26. log.Error(err)
  27. appG.Response(app.StatusInternalServerError, app.ERROR, err)
  28. return
  29. }
  30. go func() {
  31. err = srv.AddFactory(model.Factory{
  32. Pastureid: req.Pastureid,
  33. Count: req.Count,
  34. Genre: req.Genre,
  35. Recall: int64(len(req.RecallID)),
  36. CreateName: username.(string),
  37. CreateTime: time.Now(),
  38. }, req.RecallID)
  39. if err != nil {
  40. return
  41. }
  42. }()
  43. appG.Response(app.StatusOK, app.SUCCESS, true)
  44. }
  45. // GetFactory
  46. // @Summary 脖环出厂登记查看
  47. // @Description add by json account
  48. // @Tags 脖环出厂登记
  49. // @Accept json
  50. // @Produce json
  51. // @Param index path int true "int "
  52. // @Param pagesize path int true "int "
  53. // @Param batch path string true "string 批次"
  54. // @Param genre path int true "string 0 购买,1 置换 -1 全部"
  55. // @Param startcount path string true "string 数量"
  56. // @Param endcount path string true "string 数量"
  57. // @Param createname path string true "string 登记人"
  58. // @Param startdate path string true "string 登记时间"
  59. // @Param enddate path string true "string 登记时间"
  60. // @Param recallid path int true "string 查看关联出厂批次"
  61. // @Success 200 {object} v1.GetFactoryRes
  62. // @Router /factory/list [get]
  63. func GetFactory(r *ghttp.Request) {
  64. var req *v1.GetFactoryReq
  65. appG := app.Ghttp{C: r}
  66. err := appG.C.Parse(&req)
  67. if err != nil {
  68. err = errors.Wrap(err, "GetNeckRingListing-error")
  69. log.Error(err)
  70. appG.Response(app.StatusInternalServerError, app.ERROR, err)
  71. return
  72. }
  73. respList, count, err := srv.GetFactory(req.Index, req.PageSize, req.Pastureid, req.Batch, req.Genre, req.StartCount, req.EndCount, req.CreateName, req.StartDate, req.EndDate, req.RecallID)
  74. if err != nil {
  75. return
  76. }
  77. resp := v1.GetFactoryRes{}
  78. dataList := make([]*v1.Factory, 0)
  79. for _, item := range respList {
  80. var data v1.Factory
  81. data.Id = item.Id
  82. data.PastureId = item.Pastureid
  83. data.Count = item.Count
  84. data.Batch = item.Batch
  85. data.Genre = item.Genre
  86. data.Recall = item.Recall
  87. data.CreateName = item.CreateName
  88. data.PastureName = item.PastureName
  89. if !item.CreateTime.IsZero() {
  90. data.CreateTime = item.CreateTime.Format("2006-01-02")
  91. }
  92. dataList = append(dataList, &data)
  93. }
  94. resp.List = dataList
  95. resp.Total = count
  96. appG.Response(app.StatusOK, app.SUCCESS, resp)
  97. }