/// <summary> /// 发送文件 /// </summary> /// <param name="userInfo">用户</param> /// <param name="fileName">文件名</param> /// <param name="file">文件内容</param> /// <param name="toUserId">发送给谁主键</param> /// <returns>文件主键</returns> public string Send(BaseUserInfo userInfo, string fileName, byte[] file, string toUserId) { string result = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { BaseFolderEntity folderEntity = new BaseFolderEntity(); var folderManager = new BaseFolderManager(dbHelper, userInfo); // 检查相应的系统必备文件夹 folderManager.FolderCheck(); BaseUserEntity userEntity = new BaseUserManager(dbHelper, userInfo).GetObject(toUserId); if (!string.IsNullOrEmpty(userEntity.Id)) { // 04:判断发送者的空间是否存在? // 05:判断已收文件夹是否存在? if (!folderManager.Exists(userEntity.Id)) { folderEntity.FolderName = userEntity.RealName + AppMessage.FileService_File; folderEntity.ParentId = "UserSpace"; folderEntity.Id = userEntity.Id; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddObject(folderEntity); } // 06:判断来自谁的文件夹是否存在? // 07:判断发给谁的文件夹是否存在? if (!folderManager.Exists(toUserId + "_Receive")) { folderEntity.FolderName = AppMessage.FileService_ReceiveFile; folderEntity.ParentId = toUserId; folderEntity.Id = toUserId + "_Receive"; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddObject(folderEntity); } if (!folderManager.Exists(userInfo.Id + "_Send_" + toUserId)) { folderEntity.FolderName = userEntity.RealName + "(" + userEntity.UserName + ")"; folderEntity.ParentId = userInfo.Id + "_Send"; folderEntity.Id = userInfo.Id + "_Send_" + toUserId; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddObject(folderEntity); } if (!folderManager.Exists(toUserId + "_Receive_" + userInfo.Id)) { folderEntity.FolderName = userInfo.RealName + "(" + userInfo.UserName + ")"; folderEntity.ParentId = toUserId + "_Receive"; folderEntity.Id = toUserId + "_Receive_" + userInfo.Id; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddObject(folderEntity); } // 08:已发送文件夹多一个文件。 // 09:已接收文件夹多一个文件。 BaseFileEntity fileEntity = new BaseFileEntity(); fileEntity.FileName = fileName; fileEntity.Contents = file; fileEntity.Enabled = 1; fileEntity.ReadCount = 0; fileEntity.FolderId = userInfo.Id + "_Send_" + toUserId; // 把修改人显示出来 fileEntity.ModifiedBy = userInfo.RealName; fileEntity.ModifiedUserId = userInfo.Id; fileEntity.ModifiedOn = DateTime.Now; var fileManager = new BaseFileManager(dbHelper, userInfo); fileManager.AddObject(fileEntity); fileEntity.FolderId = toUserId + "_Receive_" + userInfo.Id; result = fileManager.AddObject(fileEntity); // string webHostUrl = BaseSystemInfo.WebHost; // if (string.IsNullOrEmpty(webHostUrl)) // { // webHostUrl = "WebHostUrl"; // } // 10:应该还发一个短信提醒一下才对。 BaseMessageEntity messageEntity = new BaseMessageEntity(); //messageEntity.Id = Guid.NewGuid().ToString("N"); messageEntity.CategoryCode = MessageCategory.Send.ToString(); messageEntity.FunctionCode = MessageFunction.Message.ToString(); messageEntity.ObjectId = result; messageEntity.ReceiverId = toUserId; // target=\"_blank\" messageEntity.Contents = AppMessage.FileService_SendFileFrom + " <a href={WebHostUrl}Download.aspx?Id=" + result + ">" + fileName + "</a>" + AppMessage.FileService_CheckReceiveFile; messageEntity.IsNew = (int)MessageStateCode.New; messageEntity.ReadCount = 0; messageEntity.DeletionStateCode = 0; var messageManager = new BaseMessageManager(dbHelper, userInfo); messageManager.Identity = true; result = messageManager.Add(messageEntity); } }); return(result); }