You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package FileRelateDao
import (
"dsSzxy/Utils/CommonUtil"
"dsSzxy/Utils/ConfigUtil"
"dsSzxy/Utils/DbUtil"
"dsSzxy/models"
"errors"
"net/url"
"time"
)
var db = DbUtil.Engine
/**
功能:生成下载地址带中文名
*/
func GetFileDownLoadUrl(key string, originName string) string {
infix := "?response-content-disposition=attachment%3BfileName%2A%3DUTF-8%27%27"
downloadUrl := ConfigUtil.MinioDownloadPrefix + ConfigUtil.MinioBucket + "/" + key + infix + url.QueryEscape(url.QueryEscape(originName))
return downloadUrl
}
//文件记录
func FileRecord(fileName string, indentityId int32, personId int32, targetGroupId int32, tIdentityId int32, tPersonId int32, systemId int32, fileSize int32, extName string) {
var model models.TZhxyFile
model.FileId = CommonUtil.GetUUID()
model.FileName = fileName
model.FileSize = fileSize
model.BaseId = "-1"
model.BUse = 1
model.ExtName = extName
model.SystemId = systemId
model.TargetGroupId = targetGroupId
model.TargetIdentityId = tIdentityId
model.TargetPersonId = tPersonId
model.UploadIndentityId = indentityId
model.UploadPersonId = personId
model.UploadTime = time.Now()
c, err := GetFileTypeByExtName(extName)
if err == nil {
model.TypeId = c
} else {
model.TypeId = 0
}
db.Insert(model)
}
/**
功能获取文件扩展名对应的类型ID
*/
func GetFileTypeByExtName(extName string) (int32, error) {
sql := "select type_id from t_zhxy_file_type_ext where ext_name=?"
res, err := DbUtil.Engine.SQL(sql, extName).Query().List()
if err != nil {
return -1, errors.New("查询SQL语句失败")
}
if len(res) == 0 {
return 0, nil
}
return res[0]["type_id"].(int32), nil
}