| | |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/pkg/httpx" |
| | | "aps_crm/service" |
| | | "github.com/flipped-aurora/gin-vue-admin/server/utils/upload" |
| | | "aps_crm/utils/upload" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "os" |
| | | "path/filepath" |
| | | "strconv" |
| | | ) |
| | | |
| | | type FileApi struct{} |
| | |
| | | // @Tags 附件管理 |
| | | // @Summary 添加附件 |
| | | // @Produce application/json |
| | | // @Param object body request.AddFile true "查询参数" |
| | | // @Param object formData request.AddFile true "查询参数" |
| | | // @Param file formData file true "上传文件" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/file/add [post] |
| | | func (s *FileApi) Add(c *gin.Context) { |
| | |
| | | return |
| | | } |
| | | |
| | | _, filename := filepath.Split(filePath) |
| | | _, filename := filepath.Split(header.Filename) |
| | | |
| | | fileRecord := &model.File{ |
| | | Name: filename, |
| | |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | |
| | | idx := c.Param("id") |
| | | id := cast.ToUint(idx) |
| | | file, err := model.NewFileSearch().SetId(id).First() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "查找文件失败") |
| | | return |
| | | } |
| | | |
| | | err = os.Remove(file.FilePath) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "删除文件失败") |
| | | return |
| | | } |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // @Tags 附件管理 |
| | | // @Summary 更新附件 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateFile true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/file/update [put] |
| | | func (s *FileApi) Update(c *gin.Context) { |
| | | var params request.UpdateFile |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | if params.Id == 0 { |
| | | ctx.Fail(ecode.ParamsErr) |
| | | } |
| | | params.File.Id = params.Id |
| | | |
| | | errCode := service.NewFileService().UpdateFile(¶ms.File) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | err = os.Remove(file.FilePath) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "删除文件失败") |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | //// Update |
| | | //// @Tags 附件管理 |
| | | //// @Summary 更新附件 |
| | | //// @Produce application/json |
| | | //// @Param object body request.UpdateFile true "查询参数" |
| | | //// @Success 200 {object} contextx.Response{} |
| | | //// @Router /api/file/update [put] |
| | | //func (s *FileApi) Update(c *gin.Context) { |
| | | // var params request.UpdateFile |
| | | // ctx, ok := contextx.NewContext(c, ¶ms) |
| | | // if !ok { |
| | | // return |
| | | // } |
| | | // if params.Id == 0 { |
| | | // ctx.Fail(ecode.ParamsErr) |
| | | // } |
| | | // params.File.ID = params.Id |
| | | // |
| | | // errCode := service.NewFileService().UpdateFile(¶ms.File) |
| | | // if errCode != ecode.OK { |
| | | // ctx.Fail(errCode) |
| | | // return |
| | | // } |
| | | // |
| | | // ctx.Ok() |
| | | //} |
| | | |
| | | // List |
| | | // @Tags 附件管理 |
| | | // @Summary 获取附件列表 |