岗位合并清理、班前会数据同步、
This commit is contained in:
@@ -1,17 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
public static class FileInsertService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 保存其他单位附件同步处理
|
||||
/// </summary>
|
||||
/// <param name="domain">单位域名地址</param>
|
||||
/// <param name="attachFileId">附件id</param>
|
||||
/// <param name="tokeyId">附件keyid</param>
|
||||
/// <param name="attachSource">附件json信息</param>
|
||||
/// <param name="attachUrl">附件地址</param>
|
||||
public static void SaveAttachFileRecords(string domain, string attachFileId, string tokeyId, string attachSource, string attachUrl)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(attachFileId) && !string.IsNullOrEmpty(attachSource) && !string.IsNullOrEmpty(attachUrl))
|
||||
{
|
||||
List<byte[]> FileContext = new List<byte[]>();
|
||||
if (!string.IsNullOrWhiteSpace(domain) && !string.IsNullOrWhiteSpace(attachUrl))
|
||||
{
|
||||
FileContext = FilePathTransStream(domain, attachUrl);
|
||||
}
|
||||
InsertAttachFilesRecord(attachFileId, tokeyId, attachSource, attachUrl, FileContext);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器图片转byte
|
||||
/// </summary>
|
||||
@@ -22,35 +45,43 @@ namespace BLL
|
||||
{
|
||||
List<byte[]> bytes = new List<byte[]>();
|
||||
var strs = attachUrl.Trim().Split(',');
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var fileUrl in strs)
|
||||
{
|
||||
string filepath = $"{fileHost}{fileUrl}";
|
||||
// 创建WebClient实例
|
||||
using (WebClient webClient = new WebClient())
|
||||
string path = ConfigurationManager.AppSettings["localRoot"] + fileUrl;
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
// 下载图片并保存到内存流
|
||||
using (MemoryStream ms = new MemoryStream(webClient.DownloadData(filepath)))
|
||||
//BLL.ErrLogInfo.WriteLog($"不存在则新增,附件地址:{path}");
|
||||
string filepath = $"{fileHost}{fileUrl}";
|
||||
//BLL.ErrLogInfo.WriteLog($"不存在则新增,责任单位附件地址:{filepath}");
|
||||
// 创建WebClient实例
|
||||
using (WebClient webClient = new WebClient())
|
||||
{
|
||||
// 将MemoryStream转换为byte数组
|
||||
byte[] imageBytes = ms.ToArray();
|
||||
bytes.Add(imageBytes);
|
||||
//// 使用byte数组(例如,保存到文件或进行其他处理)
|
||||
//File.WriteAllBytes("localImage.jpg", imageBytes);
|
||||
// 下载图片并保存到内存流
|
||||
using (MemoryStream ms = new MemoryStream(webClient.DownloadData(filepath)))
|
||||
{
|
||||
// 将MemoryStream转换为byte数组
|
||||
byte[] imageBytes = ms.ToArray();
|
||||
bytes.Add(imageBytes);
|
||||
//// 使用byte数组(例如,保存到文件或进行其他处理)
|
||||
//File.WriteAllBytes("localImage.jpg", imageBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// BLL.ErrLogInfo.WriteLog($"已存在附件地址:{path}");
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error: " + ex.Message);
|
||||
BLL.ErrLogInfo.WriteLog($"服务器图片转换异常:{fileHost};图片地址:{attachUrl}", ex.Message);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取附件数据流类
|
||||
/// </summary>
|
||||
@@ -187,6 +218,46 @@ namespace BLL
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据和附件插入到多附件表
|
||||
/// </summary>
|
||||
public static void InsertAttachFilesRecord(string attachFileId, string dataId, string attachSource, string attachUrl, List<byte[]> fileContext)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(attachFileId))
|
||||
{
|
||||
//多附件
|
||||
var attachFile = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == dataId);
|
||||
if (attachFile == null)
|
||||
{
|
||||
////插入附件文件
|
||||
BLL.FileInsertService.FileMoreInsert(fileContext, attachUrl);
|
||||
|
||||
Model.AttachFile newAttachFile = new Model.AttachFile
|
||||
{
|
||||
AttachFileId = attachFileId,
|
||||
ToKeyId = dataId,
|
||||
AttachSource = attachSource,
|
||||
AttachUrl = attachUrl
|
||||
};
|
||||
Funs.DB.AttachFile.InsertOnSubmit(newAttachFile);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (attachFile.AttachUrl != attachUrl)
|
||||
{
|
||||
/////删除附件文件
|
||||
//BLL.UploadAttachmentService.DeleteFile(ConfigurationManager.AppSettings["localRoot"], attachFile.AttachUrl);
|
||||
////插入附件文件
|
||||
BLL.FileInsertService.FileMoreInsert(fileContext, attachUrl);
|
||||
attachFile.AttachSource = attachSource;
|
||||
attachFile.AttachUrl = attachUrl;
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据和附件插入到多附件表【不存实际文件,只存地址】
|
||||
|
||||
Reference in New Issue
Block a user