package controller import ( v1 "demo/api/v1" "demo/internal/app" "demo/internal/model" "github.com/gogf/gf/v2/net/ghttp" "github.com/pkg/errors" "github.com/siddontang/go/log" "time" ) // AddFactory // @Summary 脖环出厂登记添加 // @Description add by json account // @Tags 脖环出厂登记 // @Accept json // @Produce json // @Param account body v1.AddFactoryReq true "Add account" // @Router /factory/add [post] func AddFactory(r *ghttp.Request) { var req *v1.AddFactoryReq username := r.Context().Value("jwt_username") appG := app.Ghttp{C: r} err := appG.C.Parse(&req) if err != nil { err = errors.Wrap(err, "AddFactory-error") log.Error(err) appG.Response(app.StatusInternalServerError, app.ERROR, err) return } go func() { err = srv.AddFactory(model.Factory{ Pastureid: req.Pastureid, Count: req.Count, Genre: req.Genre, Recall: int64(len(req.RecallID)), CreateName: username.(string), CreateTime: time.Now(), }, req.RecallID) if err != nil { return } }() appG.Response(app.StatusOK, app.SUCCESS, true) } // GetFactory // @Summary 脖环出厂登记查看 // @Description add by json account // @Tags 脖环出厂登记 // @Accept json // @Produce json // @Param index path int true "int " // @Param pagesize path int true "int " // @Param batch path string true "string 批次" // @Param genre path int true "string 0 购买,1 置换 -1 全部" // @Param startcount path string true "string 数量" // @Param endcount path string true "string 数量" // @Param createname path string true "string 登记人" // @Param startdate path string true "string 登记时间" // @Param enddate path string true "string 登记时间" // @Param recallid path int true "string 查看关联出厂批次" // @Success 200 {object} v1.GetFactoryRes // @Router /factory/list [get] func GetFactory(r *ghttp.Request) { var req *v1.GetFactoryReq 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 } 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) if err != nil { return } resp := v1.GetFactoryRes{} dataList := make([]*v1.Factory, 0) for _, item := range respList { var data v1.Factory data.Id = item.Id data.PastureId = item.Pastureid data.Count = item.Count data.Batch = item.Batch data.Genre = item.Genre data.Recall = item.Recall data.CreateName = item.CreateName data.PastureName = item.PastureName if !item.CreateTime.IsZero() { data.CreateTime = item.CreateTime.Format("2006-01-02") } dataList = append(dataList, &data) } resp.List = dataList resp.Total = count appG.Response(app.StatusOK, app.SUCCESS, resp) }