|
@@ -2,11 +2,13 @@ package service
|
|
|
|
|
|
import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "io/ioutil"
|
|
|
"iot_manager_service/app/file/dao"
|
|
|
"iot_manager_service/app/file/model"
|
|
|
userdao "iot_manager_service/app/user/dao"
|
|
|
"iot_manager_service/util/common"
|
|
|
"iot_manager_service/util/websocket"
|
|
|
+ "net/http"
|
|
|
"path"
|
|
|
"strconv"
|
|
|
"time"
|
|
@@ -44,7 +46,7 @@ func (f *fileService) Distribute(encryptedname, savepath string, requserfile *mo
|
|
|
Operator: uid,
|
|
|
Receiver: u.ID,
|
|
|
FileID: file.ID,
|
|
|
- EffectiveDate: requserfile.EffectiveDate,
|
|
|
+ EffectiveDate: &requserfile.EffectiveDate,
|
|
|
OperationStatus: "上传",
|
|
|
})
|
|
|
}
|
|
@@ -71,3 +73,40 @@ func (f *fileService) GetUserFiles(id string) *common.Errors {
|
|
|
}
|
|
|
return common.SuccessResponse("查询成功", gin.H{"files": files})
|
|
|
}
|
|
|
+
|
|
|
+func (f *fileService) GetFile(id string, c *gin.Context) {
|
|
|
+ filedao := &dao.File{}
|
|
|
+ file, err := filedao.GetFile(id)
|
|
|
+ if err != nil {
|
|
|
+ panic(err.Error())
|
|
|
+ }
|
|
|
+ encryptedData, err := ioutil.ReadFile(file.SavePath)
|
|
|
+ if err != nil {
|
|
|
+ panic(err.Error())
|
|
|
+ }
|
|
|
+ c.Header("Content-Disposition", "attachment;filename="+file.EncryptedName)
|
|
|
+ c.Header("Content-Type", "application/octet-stream")
|
|
|
+ c.Data(http.StatusOK, "application/octet-stream", encryptedData)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (f *fileService) ForwardingFile(uid, fileid int, users []int) *common.Errors {
|
|
|
+ var userfile []dao.UserFile
|
|
|
+ var nilTime *time.Time
|
|
|
+ for _, u := range users {
|
|
|
+ userfile = append(userfile, dao.UserFile{
|
|
|
+ Operator: uid,
|
|
|
+ Receiver: u,
|
|
|
+ FileID: fileid,
|
|
|
+ EffectiveDate: nilTime,
|
|
|
+ OperationStatus: "转发",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ userfiledao := &dao.UserFile{}
|
|
|
+ err := userfiledao.BatchUFRecords(userfile)
|
|
|
+ if err != nil {
|
|
|
+ return common.FailResponse(err.Error(), nil)
|
|
|
+
|
|
|
+ }
|
|
|
+ return common.SuccessResponse("新增记录成功", nil)
|
|
|
+}
|