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 }