소스 검색

取消erp用户缓存

icole 4 년 전
부모
커밋
132ea9cfbc
1개의 변경된 파일110개의 추가작업 그리고 3개의 파일을 삭제
  1. 110 3
      internal/logic/system/system_file_upload_logic.go

+ 110 - 3
internal/logic/system/system_file_upload_logic.go

@@ -3,14 +3,13 @@ package system
 import (
 	"context"
 	"fmt"
+	"git.i2edu.net/i2/i2-bill-api/internal/svc"
+	"git.i2edu.net/i2/i2-bill-api/internal/types"
 	"io"
 	"net/http"
 	"os"
 	"path/filepath"
 
-	"git.i2edu.net/i2/i2-bill-api/internal/svc"
-	"git.i2edu.net/i2/i2-bill-api/internal/types"
-
 	"git.i2edu.net/i2/go-zero/core/logx"
 )
 
@@ -57,4 +56,112 @@ func (l *SystemFileUploadLogic) SystemFileUpload(r *http.Request) (*types.Respon
 		return &types.Response{500, err.Error(), nil}, nil
 	}
 	return &types.Response{200, "", fileName}, nil
+
+	//
+	//file, fInfo, err := r.FormFile("file")
+	//if err != nil {
+	//	logx.Error(err.Error())
+	//	return &types.Response{500, err.Error(), nil}, nil
+	//}
+	//defer file.Close()
+	//
+	//var attach *sysmodel.SysAttachment = nil
+	//if _attachementUpDownloader != nil{
+	//	attach, err = _attachementUpDownloader.Upload(file, fInfo)
+	//	if err !=nil{
+	//		return nil, err
+	//	}
+	//}else{
+	//	return nil, errors.New("附件上传下载接口为nil")
+	//}
+	//
+	//userId := c.Ctx.GetString("user_id")
+	//
+	//if attach.Id == ""{
+	//	attach.Id = sysutils.NewUUID()
+	//}
+	//if attach.Size <= 0{
+	//	attach.Size = int32((fInfo.Size))
+	//}
+	//attach.Name = fInfo.Filename
+	//attach.CreateBy = userId
+	//attach.CreateTime = time.Now()
+	//attach.Ext = path.Ext(attach.Name)
+	//
+	//_, err = c.PlatformDbEngine.InsertOne(attach)
+	//if err != nil {
+	//	syslogs.Error("保存附件出错了:", err)
+	//	return nil, err
+	//}
+
+	//return attach, nil
+
 }
+
+/**
+ * @brief: 默认
+ */
+type defaultAttachUpDownloader struct {
+}
+
+/**
+ * @brief: 附件上传接口
+ * @param1 file: post 多媒体file
+ * @param1 header: 文件相头信息
+ * @return1: 附件信息,主要包括id,url, hash和大小。其他字段会自动设置
+ * @return2: 错误信息
+ */
+//func(d *defaultAttachUpDownloader)Upload(file multipart.File, header *multipart.FileHeader)(*sysmodel.SysAttachment, error){
+//	fileDir := fmt.Sprintf("files/")
+//	if err := mkdir(fileDir); err != nil {
+//		syslogs.Info("文件夹创建失败")
+//		return nil, err
+//	}
+//	attachId := sysutils.NewUUID()
+//	filePath := fileDir + attachId
+//	fW, err := os.Create(filePath)
+//	if err != nil {
+//		syslogs.Info("文件创建失败")
+//		return nil, err
+//	}
+//	defer fW.Close()
+//	length, err := io.Copy(fW, file)
+//	if err != nil {
+//		syslogs.Info("文件保存失败")
+//		return nil, err
+//	}
+//
+//	attach := &sysmodel.SysAttachment{}
+//	attach.Id = attachId
+//	attach.Url = "/api/v1/sys_attachment/download?id=" + attach.Id
+//	attach.Hash = ""
+//	attach.Size = int32(length)
+//
+//	return attach, nil
+//}
+//
+///**
+// * @brief: 附件下载
+// * @param1 ctx: 上下文
+// * @param2 id: 附件记录的id
+// */
+//func(d *defaultAttachUpDownloader)Download(c *entitys.CtrlContext, attach *sysmodel.SysAttachment){
+//	filePath := "files/" + attach.Id
+//
+//	c.Ctx.Writer.Header().Add("Content-Disposition", "attachment;filename=\""+sysutils.FormatForBrowse(c.Ctx.Request.UserAgent(), attach.Name)+"\"")
+//	c.Ctx.Writer.Header().Add("Content-Type", mime.TypeByExtension(attach.Ext))
+//	c.Ctx.Writer.Header().Add("Content-Length", strconv.FormatInt(int64(attach.Size), 10))
+//	c.Ctx.Writer.Header().Add("Accept-Ranges", "bytes")
+//
+//	if !sysutils.Exists(filePath) {
+//		c.Ctx.Writer.WriteHeader(400)
+//		return
+//	}
+//	fmt.Println("---->", c.Ctx.Writer.Header().Get("Content-Disposition"))
+//	fmt.Println("---->", c.Ctx.Writer.Header().Get("Content-Type"))
+//	fmt.Println("---->", c.Ctx.Writer.Header().Get("Content-Length"))
+//	fmt.Println("---->", c.Ctx.Writer.Header().Get("Accept-Ranges"))
+//
+//	c.Ctx.File(filePath)
+//}
+//