瀏覽代碼

app2.0附件接口

新疆体育高职分支
ndbs 1 年之前
父節點
當前提交
abcc52aae1
共有 1 個文件被更改,包括 147 次插入95 次删除
  1. +147
    -95
      Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs

+ 147
- 95
Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/AnnexesApiWx.cs 查看文件

@@ -18,22 +18,22 @@ namespace Learun.Application.WebApi.Modules
Post["/wxupload"] = WxUpload;
Post["/wxbase64"] = WxUploadbase64;
Post["/wxdelete"] = WxDeleteFile;
//Post["/wxuploadinsingle"] = WxUploadInSingle;
Post["/wxuploadinsingle"] = WxUploadInSingle;
}
private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();

/// <summary>
/// 获取附件列表
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxGetList(dynamic _)
{
var keyValue = this.GetReqData();
var list = annexesFileIBLL.GetList(keyValue);
/// <summary>
/// 获取附件列表
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxGetList(dynamic _)
{
var keyValue = this.GetReqData();
var list = annexesFileIBLL.GetList(keyValue);

return Success(list);
}
return Success(list);
}

public Response WxUploadbase64(dynamic _)
{
@@ -82,95 +82,147 @@ namespace Learun.Application.WebApi.Modules
string fileType = fileEextension.Replace(".", "");
string fileGuid = Guid.NewGuid().ToString();

string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, fileEextension);
//创建文件夹
string path = Path.GetDirectoryName(virtualPath);
Directory.CreateDirectory(path);
AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
if (!System.IO.File.Exists(virtualPath))
{
byte[] bytes = new byte[files[0].Value.Length];
files[0].Value.Read(bytes, 0, bytes.Length);
FileInfo file = new FileInfo(virtualPath);
FileStream fs = file.Create();
fs.Write(bytes, 0, bytes.Length);
fs.Close();
//文件信息写入数据库
fileAnnexesEntity.F_Id = fileGuid;
fileAnnexesEntity.F_FileName = files[0].Name;
fileAnnexesEntity.F_FilePath = virtualPath;
fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString();
fileAnnexesEntity.F_FileExtensions = fileEextension;
fileAnnexesEntity.F_FileType = fileType;
fileAnnexesEntity.F_CreateUserId = userInfo.userId;
fileAnnexesEntity.F_CreateUserName = userInfo.realName;
annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
}
return SuccessString(fileGuid);
}
string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, fileEextension);
//创建文件夹
string path = Path.GetDirectoryName(virtualPath);
Directory.CreateDirectory(path);
AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
if (!System.IO.File.Exists(virtualPath))
{
byte[] bytes = new byte[files[0].Value.Length];
files[0].Value.Read(bytes, 0, bytes.Length);
FileInfo file = new FileInfo(virtualPath);
FileStream fs = file.Create();
fs.Write(bytes, 0, bytes.Length);
fs.Close();
//文件信息写入数据库
fileAnnexesEntity.F_Id = fileGuid;
fileAnnexesEntity.F_FileName = files[0].Name;
fileAnnexesEntity.F_FilePath = virtualPath;
fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString();
fileAnnexesEntity.F_FileExtensions = fileEextension;
fileAnnexesEntity.F_FileType = fileType;
fileAnnexesEntity.F_CreateUserId = userInfo.userId;
fileAnnexesEntity.F_CreateUserName = userInfo.realName;
annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
}
return SuccessString(fileGuid);
}

/// <summary>
/// 获取文件信息
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxFileInfo(dynamic _)
{
var fileId = this.GetReqData();
var fileEntity = annexesFileIBLL.GetEntity(fileId);
/// <summary>
/// 获取文件信息
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxFileInfo(dynamic _)
{
var fileId = this.GetReqData();
var fileEntity = annexesFileIBLL.GetEntity(fileId);

return Success(fileEntity);
}
return Success(fileEntity);
}

/// <summary>
/// 删除文件
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxDeleteFile(dynamic _)
{
var fileId = this.GetReqData();
AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId);
annexesFileIBLL.DeleteEntity(fileId);
//删除文件
if (System.IO.File.Exists(fileInfoEntity.F_FilePath))
{
System.IO.File.Delete(fileInfoEntity.F_FilePath);
}
return Success("删除成功");
}
/// <summary>
/// 删除文件
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxDeleteFile(dynamic _)
{
var fileId = this.GetReqData();
AnnexesFileEntity fileInfoEntity = annexesFileIBLL.GetEntity(fileId);
annexesFileIBLL.DeleteEntity(fileId);
//删除文件
if (System.IO.File.Exists(fileInfoEntity.F_FilePath))
{
System.IO.File.Delete(fileInfoEntity.F_FilePath);
}
return Success("删除成功");
}

/// <summary>
/// 下载文件,微信小程序用
///
/// 微信小程序可以预览图片、文档
/// 支持的图片格式:.jpg .png .webp .gif
/// 支持的文档格式:.doc(x) .xls(x) .ppt(x) .pdf
///
/// 对于其他格式的文件,微信小程序官方未提供打开或预览的 API,文件对用户来说不可访问
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxDownload(dynamic _)
{
string name = this.GetReqData();
string fileId = name.Split('.')[0];
var fileEntity = annexesFileIBLL.GetEntity(fileId);
string filepath = fileEntity.F_FilePath;
/// <summary>
/// 下载文件,微信小程序用
///
/// 微信小程序可以预览图片、文档
/// 支持的图片格式:.jpg .png .webp .gif
/// 支持的文档格式:.doc(x) .xls(x) .ppt(x) .pdf
///
/// 对于其他格式的文件,微信小程序官方未提供打开或预览的 API,文件对用户来说不可访问
/// </summary>
/// <param name="_"></param>
/// <returns></returns>
public Response WxDownload(dynamic _)
{
string name = this.GetReqData();
string fileId = name.Split('.')[0];
var fileEntity = annexesFileIBLL.GetEntity(fileId);
string filepath = fileEntity.F_FilePath;

if (!FileDownHelper.FileExists(filepath))
{
return 404;
}

if (!FileDownHelper.FileExists(filepath))
{
return 404;
}
FileDownHelper.DownLoadWx(filepath, fileEntity.F_FileType);

FileDownHelper.DownLoadWx(filepath, fileEntity.F_FileType);
return Success("");
}

return Success("");
/// <summary>
/// 上传附件图片文件【移动端app2.0,单独页面中的附件图片上传使用方法】
/// <summary>
/// <returns></returns>
public Response WxUploadInSingle(dynamic _)
{
var files = (List<HttpFile>)this.Context.Request.Files;
var folderId = this.GetReq<FileModel>().folderId;
var name = this.GetReq<FileModel>().name;

string filePath = Config.GetValue("AnnexesFile");
string uploadDate = DateTime.Now.ToString("yyyyMMdd");
string FileEextension = Path.GetExtension(name);
string fileGuid = Guid.NewGuid().ToString();

string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, FileEextension);

//创建文件夹
string path = Path.GetDirectoryName(virtualPath);
Directory.CreateDirectory(path);
AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
if (!System.IO.File.Exists(virtualPath))
{
byte[] bytes = new byte[files[0].Value.Length];
files[0].Value.Read(bytes, 0, bytes.Length);
FileInfo file = new FileInfo(virtualPath);
FileStream fs = file.Create();
fs.Write(bytes, 0, bytes.Length);
fs.Close();

//文件信息写入数据库
fileAnnexesEntity.F_Id = fileGuid;
fileAnnexesEntity.F_FolderId = folderId;
fileAnnexesEntity.F_FileName = name;
fileAnnexesEntity.F_FilePath = virtualPath;
fileAnnexesEntity.F_FileSize = files[0].Value.Length.ToString();
fileAnnexesEntity.F_FileExtensions = FileEextension;
fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
fileAnnexesEntity.F_CreateUserId = userInfo.userId;
fileAnnexesEntity.F_CreateUserName = userInfo.realName;

annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
}
return SuccessString(folderId);
}
}
public class FileModel
{
public string folderId { get; set; }
public string name { get; set; }
public string id { get; set; }
}
}
}

Loading…
取消
儲存