123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/tasker/httptasker"
- "git.getensh.com/common/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "net/http"
- "property-system-gateway/errors"
- param_v1 "property-system-gateway/param/v1"
- "property-system-gateway/pb"
- "property-system-gateway/pb/v1"
- "strconv"
- "strings"
- )
- //
- // @Summary 获取单个素材
- // @Description 获取单个素材
- // @Tags 素材
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param mtype query int true "素材类型"
- // @Success 200 {object} v1.MaterialInfoResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/material/info [get]
- func (c *Controller) MaterialInfo(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.MaterialInfoRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.MaterialInfoQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- //tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.MaterialInfoResponse{}
- rpcReq := &v1.MaterialInfoRequest{
- Mtype: req.Mtype,
- }
- rpcRsp, err := pb.Common.MaterialInfo(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Common.MaterialInfo"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 根据类型获取素材列表
- // @Description 根据类型获取素材列表
- // @Tags 素材
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param mtypes query string true "类型,多个类型以逗号分隔"
- // @Success 200 {object} v1.MaterialListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/material/list [get]
- func (c *Controller) MaterialList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.MaterialListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.MaterialListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.MaterialListResponse{}
- array := strings.Split(req.Mtypes, ",")
- if len(array) == 0 {
- return errors.ParamsError
- }
- mtypes := make([]int32, len(array))
- for i, v := range array {
- tmp, _ := strconv.Atoi(v)
- mtypes[i] = int32(tmp)
- }
- rpcReq := &v1.MaterialListRequest{
- Mtypes: mtypes,
- Page: -1,
- PageSize: -1,
- }
- rpcRsp, err := pb.Common.MaterialList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Common.MaterialList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.MaterialItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|