From 137c67c8a8d6a85d58a3b99f400d6b62c6b13394 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com>
Date: Mon, 16 Aug 2021 13:56:40 +0800
Subject: [PATCH] 'commit'
---
dsSzxy/.idea/workspace.xml | 5 +--
.../FileReleateController.go | 40 +++++++++++++++++-
.../FileRelateDao/FileReleateDao.go | 41 +++++++++++++++++--
dsSzxy/main.go | 2 +-
dsSzxy/models/t_zhxy_file.go | 6 +--
5 files changed, 82 insertions(+), 12 deletions(-)
diff --git a/dsSzxy/.idea/workspace.xml b/dsSzxy/.idea/workspace.xml
index ee512112..17dc197d 100644
--- a/dsSzxy/.idea/workspace.xml
+++ b/dsSzxy/.idea/workspace.xml
@@ -7,10 +7,9 @@
-
-
-
+
+
diff --git a/dsSzxy/Business/FileRelate/FileRelateController/FileReleateController.go b/dsSzxy/Business/FileRelate/FileRelateController/FileReleateController.go
index f045b771..c6c91021 100644
--- a/dsSzxy/Business/FileRelate/FileRelateController/FileReleateController.go
+++ b/dsSzxy/Business/FileRelate/FileRelateController/FileReleateController.go
@@ -41,7 +41,7 @@ func Routers(r *gin.RouterGroup) {
// @Param target_person_id formData string true "目标人ID"
// @Success 200 {object} Model.Res
// @Router /dsSzxy/fileRelate/fileUpload [post]
-// @X-IntRangeLimit [{"identity_id":"5"},{"person_id":"1,999999999999"},{"target_group_id":"1,999999999999"},{"target_identity_id":"5"},{"target_person_id":"1,999999999999"},{"system_id":"1,20"}]
+// @X-IntRangeLimit [{"identity_id":"5"},{"person_id":"1,999999999999"},{"target_group_id":"-1,999999999999"},{"target_identity_id":"5"},{"target_person_id":"1,999999999999"},{"system_id":"1,20"}]
// @X-TableName ["t_zhxy_file"]
func fileUpload(c *gin.Context) {
file, err := c.FormFile("file")
@@ -170,3 +170,41 @@ func fileUpdate(c *gin.Context) {
"message": `修改成功!`,
})
}
+
+// @Summary 文件复制,一般用于文件转发
+// @Description 文件复制,一般用于文件转发
+// @Tags 文件系统管理
+// @Accept application/x-www-form-urlencoded
+// @Produce json
+// @Param file_id formData string true "文件ID"
+// @Param source_identity_id formData string true "原文件所有人身份ID"
+// @Param source_person_id formData string true "原文件所有人ID"
+// @Param target_identity_id formData string true "接收文件所有人身份ID"
+// @Param target_person_id formData string true "接收文件所有人ID"
+// @Param target_group_id formData string true "接收文件群组ID"
+// @Success 200 {object} Model.Res
+// @X-EmptyLimit ["file_id"]
+// @Router /dsSzxy/fileRelate/FileCopy [post]
+// @X-IntRangeLimit [{"source_identity_id":"5"},{"source_person_id":"1,999999999999"},{"target_group_id":"-1,999999999999"},{"target_identity_id":"5"},{"target_person_id":"1,999999999999"}]
+// @X-TableName ["t_zhxy_file"]
+func FileCopy(c *gin.Context) {
+ fileId := c.PostForm("file_id")
+ sourceIdentityId := CommonUtil.ConvertStringToInt32(c.PostForm("source_identity_id"))
+ sourcePersonId := CommonUtil.ConvertStringToInt32(c.PostForm("source_person_id"))
+ targetIdentityId := CommonUtil.ConvertStringToInt32(c.PostForm("target_identity_id"))
+ targetPersonId := CommonUtil.ConvertStringToInt32(c.PostForm("target_person_id"))
+ targetGroupId := CommonUtil.ConvertStringToInt32(c.PostForm("target_group_id"))
+ //文件复制
+ success, err := FileRelateDao.FileCopy(fileId, sourceIdentityId, sourcePersonId, targetIdentityId, targetPersonId, targetGroupId)
+ if err != nil {
+ c.JSON(200, gin.H{
+ "success": success,
+ "message": `复制成功!`,
+ })
+ } else {
+ c.JSON(200, gin.H{
+ "success": success,
+ "message": err.Error(),
+ })
+ }
+}
diff --git a/dsSzxy/Business/FileRelate/FileRelateDao/FileReleateDao.go b/dsSzxy/Business/FileRelate/FileRelateDao/FileReleateDao.go
index 87bb1474..853cc18a 100644
--- a/dsSzxy/Business/FileRelate/FileRelateDao/FileReleateDao.go
+++ b/dsSzxy/Business/FileRelate/FileRelateDao/FileReleateDao.go
@@ -5,6 +5,7 @@ import (
"dsSzxy/Utils/ConfigUtil"
"dsSzxy/Utils/DbUtil"
"dsSzxy/models"
+ "errors"
"fmt"
"github.com/xormplus/builder"
"net/url"
@@ -35,9 +36,9 @@ func FileRecord(fileName string, indentityId int32, personId int32, targetGroupI
model.TargetGroupId = targetGroupId
model.TargetIdentityId = tIdentityId
model.TargetPersonId = tPersonId
- model.UploadIndentityId = indentityId
- model.UploadPersonId = personId
- model.UploadTime = time.Now()
+ model.SourceIndentityId = indentityId
+ model.SourcePersonId = personId
+ model.RecordTime = time.Now()
c, err := GetFileTypeByExtName(extName)
if err == nil {
model.TypeId = int32(c)
@@ -56,7 +57,39 @@ func FileUpdate(fileId string, fileName string) {
var myBuilder = builder.Dialect(builder.MYSQL).Update(builder.Eq{"file_name": fileName}).
From(`t_zhxy_file`).Where(builder.Eq{"file_id": fileId})
sql, _ := myBuilder.ToBoundSQL()
- db.SQL(sql).Execute()
+ _, err := db.SQL(sql).Execute()
+ if err != nil {
+ fmt.Println(err.Error())
+ }
+}
+
+//复制文件记录
+func FileCopy(fileId string, sIdentityId int32, sPersonId int32, tIdentityId int32, tPersonId int32, tGroudpId int32) (bool, error) {
+ //1、查询这个文件原来是谁的
+ modelArray := make([]models.TZhxyFile, 0)
+ err := db.Where("file_id = ?", fileId).Limit(1, 1).Find(&modelArray)
+ if err != nil {
+ fmt.Println("在检索时发生错误:", err.Error())
+ return false, err
+ }
+ //2、拷贝一份
+ if len(modelArray) == 0 {
+ return false, errors.New("没有找到指定的file_id")
+ }
+ model := modelArray[0]
+ model.FileId = CommonUtil.GetUUID()
+ model.SourceIndentityId = sIdentityId
+ model.SourcePersonId = sPersonId
+ model.TargetIdentityId = tIdentityId
+ model.TargetPersonId = tPersonId
+ model.TargetGroupId = tGroudpId
+ model.RecordTime = time.Now()
+ _, err = db.Insert(model)
+ if err != nil {
+ fmt.Println(err.Error())
+ return false, errors.New("写入数据库时发生错误")
+ }
+ return true, nil
}
/**
diff --git a/dsSzxy/main.go b/dsSzxy/main.go
index 05e672d7..09ce5645 100644
--- a/dsSzxy/main.go
+++ b/dsSzxy/main.go
@@ -19,7 +19,7 @@ import (
// @title 智慧校园API
// @version 1.0
-// @description 分布式,大并发,高可用
+// @description 物联网,大数据,人工智能
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
diff --git a/dsSzxy/models/t_zhxy_file.go b/dsSzxy/models/t_zhxy_file.go
index 8f97489a..82a1e3bb 100644
--- a/dsSzxy/models/t_zhxy_file.go
+++ b/dsSzxy/models/t_zhxy_file.go
@@ -9,9 +9,9 @@ type TZhxyFile struct {
FileName string `xorm:"not null comment('文件名称') VARCHAR(255)"`
ExtName string `xorm:"not null comment('扩展名') VARCHAR(10)"`
TypeId int32 `xorm:"not null comment('文件、视频、图片') index INT(11)"`
- UploadTime time.Time `xorm:"not null comment('上传时间') DATETIME"`
- UploadIndentityId int32 `xorm:"not null comment('上传人身份') INT(11)"`
- UploadPersonId int32 `xorm:"not null comment('上传人ID') INT(11)"`
+ RecordTime time.Time `xorm:"not null comment('上传时间') DATETIME"`
+ SourceIndentityId int32 `xorm:"not null comment('上传人身份') INT(11)"`
+ SourcePersonId int32 `xorm:"not null comment('上传人ID') INT(11)"`
TargetIdentityId int32 `xorm:"not null comment('接收方身份ID,如果对方是群组,标识-1') INT(11)"`
TargetPersonId int32 `xorm:"not null comment('接收人ID,如果对方是群组,标识-1') INT(11)"`
TargetGroupId int32 `xorm:"not null comment('接收群组ID,如果对方是具体的员,标识-1') INT(11)"`