annex_api.go 1.3 KB

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