From 5e7147c3b0fe90c1c0900a1ba5797d329eb94991 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4672LME\\Xu Tengfei" Date: Wed, 26 Jan 2022 16:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/pj/ProjectDocumentLst.model.go | 1 + .../ProjectDocumentLst.service.impl.go | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/models/pj/ProjectDocumentLst.model.go b/models/pj/ProjectDocumentLst.model.go index 7b66fcc..b8befb7 100644 --- a/models/pj/ProjectDocumentLst.model.go +++ b/models/pj/ProjectDocumentLst.model.go @@ -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"` } /****************************************************************************** diff --git a/services/pj/implments/ProjectDocumentLst.service.impl.go b/services/pj/implments/ProjectDocumentLst.service.impl.go index daf3517..20bd0d5 100644 --- a/services/pj/implments/ProjectDocumentLst.service.impl.go +++ b/services/pj/implments/ProjectDocumentLst.service.impl.go @@ -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 } \ No newline at end of file -- 2.30.1.windows.1