#6 文件下载

Merged
Ghost merged 1 commits from feature_work into develop 3 years ago
  1. +1
    -0
      models/pj/ProjectDocumentLst.model.go
  2. +55
    -0
      services/pj/implments/ProjectDocumentLst.service.impl.go

+ 1
- 0
models/pj/ProjectDocumentLst.model.go View File

@ -30,6 +30,7 @@ type ProjectDocumentLst struct {
LastModify grmi.DateTime `xorm:"datetime 'LastModify' not null updated" json:"PJ_ProjectDocumentLst-LastModify"`
LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"PJ_ProjectDocumentLst-LastUser"`
CreateTime grmi.DateTime `xorm:"datetime 'CreateTime' not null created" json:"PJ_ProjectDocumentLst-CreateTime"`
Url string `xorm:"-" json:"PJ_ProjectDocumentLst-Url"`
}
/******************************************************************************


+ 55
- 0
services/pj/implments/ProjectDocumentLst.service.impl.go View File

@ -9,6 +9,8 @@ import (
"LEIT_PM/grmi"
meta "LEIT_PM/meta/pj"
model "LEIT_PM/models/pj"
"LEIT_PM/utils"
"strings"
)
/******************************************************************************
@ -268,6 +270,32 @@ func (impl *ProjectDocumentLstServiceImplement) Select(user *global.User, urlPar
if err != nil {
return nil, err
}
for index, data := range result{
record, err := dao.SelectOne(data.ProjectId, data.Pos)
if err != nil {
return nil,err
}
if record == nil {
return nil,grmi.NewBusinessError("找不到文件")
}
dirname, err := utils.GetCurrentPath("web/public")
if err != nil {
return nil, grmi.NewBusinessError("文件夹找不到, 错误:" + err.Error())
}
filepath := dirname + "/" +record.ProjectId + "/"+ record.Document+"."+record.DocumentType
pathLi := strings.Split(filepath, "web\\")
if len(pathLi) != 2 {
return nil, grmi.NewBusinessError("文档损坏")
}
result[index].Url = pathLi[1]
}
return result, nil
}
@ -362,4 +390,31 @@ func (impl *ProjectDocumentLstServiceImplement) Upload(user *global.User, entity
}
return result, err
}
func (impl *ProjectDocumentLstServiceImplement)Download(user *global.User,projectId string,pos int) (result string, err error){
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
dao := dal.NewProjectDocumentLstDAO(session, user.UserId)
record, err := dao.SelectOne(projectId, pos)
if err != nil {
return "",err
}
if record == nil {
return "",grmi.NewBusinessError("找不到文件")
}
dirname, err := utils.GetCurrentPath("web/public/uploadxlsx")
if err != nil {
return "", grmi.NewBusinessError("文件夹找不到, 错误:" + err.Error())
}
filepath := dirname + "/" + record.Document+"."+record.DocumentType
pathLi := strings.Split(filepath, "web\\")
if len(pathLi) != 2 {
return "", grmi.NewBusinessError("文档损坏")
}
return pathLi[1], nil
}

Loading…
Cancel
Save