package controller import ( v1 "demo/api/v1" "demo/internal/app" "demo/internal/model" "strconv" "sync" "github.com/gogf/gf/v2/net/ghttp" "github.com/pkg/errors" "github.com/siddontang/go/log" ) // GetNeckRingListing // @Summary 脖环清单查看 // @Description add by json account // @Tags 脖环清单 // @Accept json // @Produce json // @Param index path int true "int " // @Param pagesize path int true "int " // @Param code path string true "string 脖环编码" // @Param status path string true "string 脖环状态" // @Param cattle path int true "int 牛号" // @Param barname path string true "string 栏舍名称" // @Param purchasestart path string true "string 购入开始日期" // @Param purchaseend path string true "string 购入结束日期" // @Param manufacturestart path string true "string 生产开始日期" // @Param manufactureend path string true "string 生产结束日期" // @Param factoryid path string true "string 出厂数量" // @Param recallid path string true "string 召回" // @Success 200 {object} v1.GetNeckRingListingRes // @Router /ring/listing [get] func GetNeckRingListing(r *ghttp.Request) { var req *v1.GetNeckRingListingReq appG := app.Ghttp{C: r} err := appG.C.Parse(&req) if err != nil { err = errors.Wrap(err, "GetNeckRingListing-error") log.Error(err) appG.Response(app.StatusInternalServerError, app.ERROR, err) return } var wg sync.WaitGroup //wg.Add(1) housenameList := make([]map[string]string, 0) //go func() { // defer wg.Done() // //}() userList, count, err := srv.GetNeckRingListing(req.Index, req.PageSize, req.Code, req.BarName, req.PurchaseStart, req.PurchaseEnd, req.ManufactureStart, req.ManufactureEnd, req.Status, req.Cattle, req.RecallID, req.FactoryID) if err != nil { err = errors.Wrap(err, "GetNeckRingListing-error") appG.Response(app.StatusInternalServerError, app.ERROR, err) return } //wg.Wait() var codeList []string for _, item := range userList { code := strconv.FormatInt(item.Code, 10) codeList = append(codeList, code) } housenameList, err = srv.GetHOUSENAME(codeList) if err != nil { err = errors.Wrap(err, "GetNeckRingListing-error") appG.Response(app.StatusInternalServerError, app.ERROR, err) return } for _, item := range userList { wg.Add(1) go func(item *model.NeckRingListingList) { defer wg.Done() for _, housename := range housenameList { code := strconv.FormatInt(item.Code, 10) if housename["REGIST_NUM_2"] == code && housename["FARM_UUID"] == item.Pastureid { item.BarName = housename["HOUSE_NAME"] item.Cattle = housename["COW_NUM"] } } }(item) } wg.Wait() resp := v1.GetNeckRingListingRes{} dataList := make([]*v1.NeckRingListing, 0) for _, item := range userList { var data v1.NeckRingListing data.Id = item.Id //data.Name = item.Name data.Code = item.Code data.Status = item.Status data.Cattle = item.Cattle data.Batch = item.Batch data.BarName = item.BarName if !item.PurchaseDate.IsZero() { data.PurchaseDate = item.PurchaseDate.Format("2006-01-02") } if !item.ManufactureDate.IsZero() { data.ManufactureDate = item.ManufactureDate.Format("2006-01-02 15:04:05") } dataList = append(dataList, &data) } resp.Neckring = dataList resp.Total = count appG.Response(app.StatusOK, app.SUCCESS, resp) } // AddNeckRingListing // @Summary 添加脖环 // @Description add by json account // @Tags 脖环清单 // @Accept json // @Produce json // @Param account body v1.AddNeckRingListingReq true "Add account" // @Router /ring/listing [post] //func AddNeckRingListing(r *ghttp.Request) { // var req *v1.AddNeckRingListingReq // appG := app.Ghttp{C: r} // err := appG.C.Parse(&req) // if err != nil { // err = errors.Wrap(err, "GetNeckRingListing-error") // log.Error(err) // appG.Response(app.StatusInternalServerError, app.ERROR, err) // return // } // // err = srv.AddNeckRingListing(model.NeckRingListing{ // Name: req.Name, // Code: req.Code, // Status: req.Status, // Cattle: req.Cattle, // BarId: req.BarId, // BarName: req.BarName, // PurchaseDate: req.PurchaseDate, // ManufactureDate: req.ManufactureDate, // }) // if err != nil { // return // } // appG.Response(app.StatusOK, app.SUCCESS, true) //}