neckringlisting.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package controller
  2. import (
  3. v1 "demo/api/v1"
  4. "demo/internal/app"
  5. "demo/internal/model"
  6. "strconv"
  7. "sync"
  8. "github.com/gogf/gf/v2/net/ghttp"
  9. "github.com/pkg/errors"
  10. "github.com/siddontang/go/log"
  11. )
  12. // GetNeckRingListing
  13. // @Summary 脖环清单查看
  14. // @Description add by json account
  15. // @Tags 脖环清单
  16. // @Accept json
  17. // @Produce json
  18. // @Param index path int true "int "
  19. // @Param pagesize path int true "int "
  20. // @Param code path string true "string 脖环编码"
  21. // @Param status path string true "string 脖环状态"
  22. // @Param cattle path int true "int 牛号"
  23. // @Param barname path string true "string 栏舍名称"
  24. // @Param purchasestart path string true "string 购入开始日期"
  25. // @Param purchaseend path string true "string 购入结束日期"
  26. // @Param manufacturestart path string true "string 生产开始日期"
  27. // @Param manufactureend path string true "string 生产结束日期"
  28. // @Param factoryid path string true "string 出厂数量"
  29. // @Param recallid path string true "string 召回"
  30. // @Success 200 {object} v1.GetNeckRingListingRes
  31. // @Router /ring/listing [get]
  32. func GetNeckRingListing(r *ghttp.Request) {
  33. var req *v1.GetNeckRingListingReq
  34. appG := app.Ghttp{C: r}
  35. err := appG.C.Parse(&req)
  36. if err != nil {
  37. err = errors.Wrap(err, "GetNeckRingListing-error")
  38. log.Error(err)
  39. appG.Response(app.StatusInternalServerError, app.ERROR, err)
  40. return
  41. }
  42. var wg sync.WaitGroup
  43. //wg.Add(1)
  44. housenameList := make([]map[string]string, 0)
  45. //go func() {
  46. // defer wg.Done()
  47. //
  48. //}()
  49. userList, count, err := srv.GetNeckRingListing(req.Index, req.PageSize, req.Code, req.BarName,
  50. req.PurchaseStart, req.PurchaseEnd, req.ManufactureStart, req.ManufactureEnd, req.Status, req.Cattle, req.RecallID, req.FactoryID)
  51. if err != nil {
  52. err = errors.Wrap(err, "GetNeckRingListing-error")
  53. appG.Response(app.StatusInternalServerError, app.ERROR, err)
  54. return
  55. }
  56. //wg.Wait()
  57. var codeList []string
  58. for _, item := range userList {
  59. code := strconv.FormatInt(item.Code, 10)
  60. codeList = append(codeList, code)
  61. }
  62. housenameList, err = srv.GetHOUSENAME(codeList)
  63. if err != nil {
  64. err = errors.Wrap(err, "GetNeckRingListing-error")
  65. appG.Response(app.StatusInternalServerError, app.ERROR, err)
  66. return
  67. }
  68. for _, item := range userList {
  69. wg.Add(1)
  70. go func(item *model.NeckRingListingList) {
  71. defer wg.Done()
  72. for _, housename := range housenameList {
  73. code := strconv.FormatInt(item.Code, 10)
  74. if housename["REGIST_NUM_2"] == code && housename["FARM_UUID"] == item.Pastureid {
  75. item.BarName = housename["HOUSE_NAME"]
  76. item.Cattle = housename["COW_NUM"]
  77. }
  78. }
  79. }(item)
  80. }
  81. wg.Wait()
  82. resp := v1.GetNeckRingListingRes{}
  83. dataList := make([]*v1.NeckRingListing, 0)
  84. for _, item := range userList {
  85. var data v1.NeckRingListing
  86. data.Id = item.Id
  87. //data.Name = item.Name
  88. data.Code = item.Code
  89. data.Status = item.Status
  90. data.Cattle = item.Cattle
  91. data.Batch = item.Batch
  92. data.BarName = item.BarName
  93. if !item.PurchaseDate.IsZero() {
  94. data.PurchaseDate = item.PurchaseDate.Format("2006-01-02")
  95. }
  96. if !item.ManufactureDate.IsZero() {
  97. data.ManufactureDate = item.ManufactureDate.Format("2006-01-02 15:04:05")
  98. }
  99. dataList = append(dataList, &data)
  100. }
  101. resp.Neckring = dataList
  102. resp.Total = count
  103. appG.Response(app.StatusOK, app.SUCCESS, resp)
  104. }
  105. // AddNeckRingListing
  106. // @Summary 添加脖环
  107. // @Description add by json account
  108. // @Tags 脖环清单
  109. // @Accept json
  110. // @Produce json
  111. // @Param account body v1.AddNeckRingListingReq true "Add account"
  112. // @Router /ring/listing [post]
  113. //func AddNeckRingListing(r *ghttp.Request) {
  114. // var req *v1.AddNeckRingListingReq
  115. // appG := app.Ghttp{C: r}
  116. // err := appG.C.Parse(&req)
  117. // if err != nil {
  118. // err = errors.Wrap(err, "GetNeckRingListing-error")
  119. // log.Error(err)
  120. // appG.Response(app.StatusInternalServerError, app.ERROR, err)
  121. // return
  122. // }
  123. //
  124. // err = srv.AddNeckRingListing(model.NeckRingListing{
  125. // Name: req.Name,
  126. // Code: req.Code,
  127. // Status: req.Status,
  128. // Cattle: req.Cattle,
  129. // BarId: req.BarId,
  130. // BarName: req.BarName,
  131. // PurchaseDate: req.PurchaseDate,
  132. // ManufactureDate: req.ManufactureDate,
  133. // })
  134. // if err != nil {
  135. // return
  136. // }
  137. // appG.Response(app.StatusOK, app.SUCCESS, true)
  138. //}