annex_api.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * @description: 附件相关的接口api
  3. * @Author: LanJianRong
  4. * @Date: 2020-12-07 10:26:49
  5. * @FilePath: \construction_management\web\api\annex_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "strconv"
  11. "github.com/kataras/iris/v12"
  12. "go.mod/services"
  13. "go.mod/web/utils"
  14. )
  15. type AnnexApi struct {
  16. //框架-web应用上下文环境
  17. Ctx iris.Context
  18. // 需要用的service
  19. ServiceAnnex services.AnnexService
  20. }
  21. // @Summary 获取附件列表
  22. // @Tags 附件
  23. // @Description 获得附件列表
  24. // @Accept json
  25. // @Produce json
  26. // @Security ApiKeyAuth
  27. // @Param dataType path int true "附件类型"
  28. // @Param dataId path string true "源数据id"
  29. // @Success 200 {object} viewmodels.AnnexList "{code:0成功,data:viewmodels.AnnexList,msg:}"
  30. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  31. // @Router /api/file [get]
  32. func (c *AnnexApi) Get() {
  33. // 1.规则验证
  34. annexData, err := c.ServiceAnnex.ValidRule(c.Ctx)
  35. if err != nil {
  36. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  37. return
  38. }
  39. dataId, err := utils.GetDecryptId(annexData.DataId)
  40. dataType, err := strconv.Atoi(annexData.DataType)
  41. data = c.ServiceAnnex.Get(dataType, dataId)
  42. c.Ctx.JSON(iris.Map{
  43. "code": 0,
  44. "msg": "请求成功",
  45. "data": data,
  46. })
  47. }