|
@@ -962,6 +962,64 @@ func (this *ReportController) SaveReportContent() {
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
+// @Title 图片上传
|
|
|
+// @Description 图片上传接口
|
|
|
+// @Param File query file true "文件"
|
|
|
+// @Success 200 上传成功
|
|
|
+// @router /uploadImg [post]
|
|
|
+func (this *ReportUploadCommonController) UploadImg() {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("文件上传失败:", err.Error())
|
|
|
+ go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), 3)
|
|
|
+ //go utils.SendEmail(utils.APPNAME+"失败提醒", "URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ f, h, err := this.GetFile("file")
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ext := path.Ext(h.Filename)
|
|
|
+ dateDir := time.Now().Format("20060102")
|
|
|
+ uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
|
|
|
+ err = os.MkdirAll(uploadDir, 777)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ randStr := utils.GetRandStringNoSpecialChar(28)
|
|
|
+ fileName := randStr + ext
|
|
|
+ fpath := uploadDir + "/" + fileName
|
|
|
+ defer f.Close() //关闭上传文件
|
|
|
+ err = this.SaveToFile("file", fpath)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //上传到阿里云
|
|
|
+ resourceUrl, err := services.UploadAliyun(fileName, fpath)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ os.Remove(fpath)
|
|
|
+ }()
|
|
|
+
|
|
|
+ item := new(models.Resource)
|
|
|
+ item.ResourceUrl = resourceUrl
|
|
|
+ item.ResourceType = 1
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ newId, err := models.AddResource(item)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(models.ResourceResp)
|
|
|
+ resp.Id = newId
|
|
|
+ resp.ResourceUrl = resourceUrl
|
|
|
+ this.Data["json"] = map[string]string{"link": resourceUrl}
|
|
|
+ this.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
// @Title 新增晨报周报
|
|
|
// @Description 新增晨报周报
|
|
|
// @Param request body models.SaveDayWeekReportReq true "type json string"
|