123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- /*
- * @description: 附件相关的接口api
- * @Author: LanJianRong
- * @Date: 2020-12-07 10:26:49
- * @FilePath: \construction_management\web\api\annex_api.go
- */
- package api
- import (
- "fmt"
- "strconv"
- "github.com/kataras/iris/v12"
- "go.mod/services"
- "go.mod/web/utils"
- )
- type AnnexApi struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // 需要用的service
- ServiceAnnex services.AnnexService
- }
- // @Summary 获取附件列表
- // @Tags 附件
- // @Description 获得附件列表
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param dataType path int true "附件类型"
- // @Param dataId path string true "源数据id"
- // @Param pageNo path int true "页码" eg:1
- // @Param pageSize path int true "页数" eg:15
- // @Success 200 {object} viewmodels.AnnexList "{code:0成功,data:viewmodels.AnnexList,msg:}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/file [get]
- func (c *AnnexApi) Get() {
- // 1.规则验证
- annexData, err := c.ServiceAnnex.ValidRule(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- dataId, err := utils.GetDecryptId(annexData.DataId)
- dataType, err := strconv.Atoi(annexData.DataType)
- // data = c.ServiceAnnex.Get(dataType, dataId)
- // dataType, err := strconv.Atoi(annexData.DataType)
- data, total := c.ServiceAnnex.Get(dataType, dataId, annexData.PageNo, annexData.PageSize)
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- "data": data,
- "total": total,
- })
- }
- // @Summary 提交文件记录
- // @Tags 附件
- // @Description 提交文件记录
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param fileList body array true "附件数组"
- // @Param dataType body int true "类型" eg:"1"
- // @Param dataId body string true "数据id"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/file [post]
- func (c *AnnexApi) Post() {
- // 1.规则验证
- annexData, err := c.ServiceAnnex.ValidCreate(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- dataId, err := utils.GetDecryptId(annexData.DataId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- uid, err := utils.GetProjectAccountId(c.Ctx)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "未登录或账号失效,请重新登录"})
- return
- }
- err = c.ServiceAnnex.Create(uid, annexData.DataType, dataId, annexData.FileList)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- })
- }
- // @Summary 删除附件
- // @Tags 附件
- // @Description 删除附件
- // @Accept json
- // @Produce json
- // @Security ApiKeyAuth
- // @Param id body string true "数据id"
- // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
- // @Router /api/file [delete]
- func (c *AnnexApi) Delete() {
- // 1.规则验证
- queryId := c.Ctx.URLParam("id")
- if queryId == "" {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": "id不能为空"})
- return
- }
- id, err := utils.GetDecryptId(queryId)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- err = c.ServiceAnnex.Delete(id)
- if err != nil {
- c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
- return
- }
- c.Ctx.JSON(iris.Map{
- "code": 0,
- "msg": "请求成功",
- })
- }
|