diff --git a/model/gmodel/fs_product_template_basemap_logic.go b/model/gmodel/fs_product_template_basemap_logic.go index e68225aa..ae70c090 100644 --- a/model/gmodel/fs_product_template_basemap_logic.go +++ b/model/gmodel/fs_product_template_basemap_logic.go @@ -1,2 +1,14 @@ package gmodel -// TODO: 使用model的属性做你想做的 \ No newline at end of file + +import "context" + +// TODO: 使用model的属性做你想做的 + +func (bm *FsProductTemplateBasemapModel) GetAllEnabledList(ctx context.Context, fields ...string) (resp []FsProductTemplateBasemap, err error) { + db := bm.db.WithContext(ctx).Model(&FsProductTemplateBasemap{}).Where("`status` = ? ", 1) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Find(&resp).Error + return resp, err +} diff --git a/server/product-templatev2/internal/handler/getbasemaplisthandler.go b/server/product-templatev2/internal/handler/getbasemaplisthandler.go new file mode 100644 index 00000000..1e23d005 --- /dev/null +++ b/server/product-templatev2/internal/handler/getbasemaplisthandler.go @@ -0,0 +1,27 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/server/product-templatev2/internal/logic" + "fusenapi/server/product-templatev2/internal/svc" +) + +func GetBaseMapListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + l := logic.NewGetBaseMapListLogic(r.Context(), svcCtx) + resp := l.GetBaseMapList(r) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/product-templatev2/internal/handler/routes.go b/server/product-templatev2/internal/handler/routes.go index d2b5fa8a..d2bae9c4 100644 --- a/server/product-templatev2/internal/handler/routes.go +++ b/server/product-templatev2/internal/handler/routes.go @@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/product-template/detail", Handler: GetTemplatevDetailHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/product-template/base-map-list", + Handler: GetBaseMapListHandler(serverCtx), + }, }, ) } diff --git a/server/product-templatev2/internal/logic/getbasemaplistlogic.go b/server/product-templatev2/internal/logic/getbasemaplistlogic.go new file mode 100644 index 00000000..d1da6ba9 --- /dev/null +++ b/server/product-templatev2/internal/logic/getbasemaplistlogic.go @@ -0,0 +1,59 @@ +package logic + +import ( + "errors" + "fusenapi/model/gmodel" + "fusenapi/server/product-templatev2/internal/types" + "fusenapi/utils/basic" + "gorm.io/gorm" + "net/http" + "time" + + "context" + + "fusenapi/server/product-templatev2/internal/svc" + "github.com/zeromicro/go-zero/core/logx" +) + +type GetBaseMapListLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetBaseMapListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBaseMapListLogic { + return &GetBaseMapListLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetBaseMapListLogic) GetBaseMapList(r *http.Request) (resp *basic.Response) { + authKey := r.Header.Get("Auth-Key") + genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn) + _, err := genentModel.Find(l.ctx, authKey) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info") + } + baseMapFields := "id,name,url,ctime" + baseMapList, err := l.svcCtx.AllModels.FsProductTemplateBasemap.GetAllEnabledList(l.ctx, baseMapFields) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product base map list") + } + list := make([]types.GetBaseMapListRsp, 0, len(baseMapList)) + for _, v := range baseMapList { + list = append(list, types.GetBaseMapListRsp{ + Id: v.Id, + Name: *v.Name, + Url: *v.Url, + Ctime: time.Unix(*v.Ctime, 0).Format("2006-01-02 15:04:05"), + }) + } + return resp.SetStatusWithMessage(basic.CodeOK, "success", list) +} diff --git a/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go b/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go index 17bd3cf3..3beb2e37 100644 --- a/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go +++ b/server/product-templatev2/internal/logic/gettemplatevdetaillogic.go @@ -35,15 +35,6 @@ func NewGetTemplatevDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, r *http.Request) (resp *basic.Response) { authKey := r.Header.Get("Auth-Key") - if authKey == "" { - return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first") - } - if req.TemplateId <= 0 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param template_id") - } - if req.ModelId <= 0 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param model_id") - } genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn) _, err := genentModel.Find(l.ctx, authKey) if err != nil { @@ -53,6 +44,12 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta logx.Error(err) return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info") } + if req.TemplateId <= 0 { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param template_id") + } + if req.ModelId <= 0 { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param model_id") + } //获取模型信息 productModel3dModel := gmodel.NewFsProductModel3dModel(l.svcCtx.MysqlConn) model3dInfo, err := productModel3dModel.FindOne(l.ctx, req.ModelId) diff --git a/server/product-templatev2/internal/types/types.go b/server/product-templatev2/internal/types/types.go index 240f9151..21a68f20 100644 --- a/server/product-templatev2/internal/types/types.go +++ b/server/product-templatev2/internal/types/types.go @@ -28,6 +28,13 @@ type Light struct { Info interface{} `json:"info"` } +type GetBaseMapListRsp struct { + Id int64 `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Ctime string `json:"ctime"` +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server_api/product-templatev2.api b/server_api/product-templatev2.api index a074bb9b..64c72fdd 100644 --- a/server_api/product-templatev2.api +++ b/server_api/product-templatev2.api @@ -11,6 +11,9 @@ service product-templatev2 { //获取产品模板详情 @handler GetTemplatevDetailHandler get /product-template/detail(GetTemplatevDetailReq) returns (response); + //获取底图列表 + @handler GetBaseMapListHandler + get /product-template/base-map-list( ) returns (response); } //获取产品模板详情 @@ -34,4 +37,11 @@ type Tag { type Light { Id int64 `json:"id"` Info interface{} `json:"info"` +} +//获取底图列表 +type GetBaseMapListRsp { + Id int64 `json:"id"` + Name string `json:"name"` + Url string `json:"url"` + Ctime string `json:"ctime"` } \ No newline at end of file