diff --git a/IBKLinker-Minio/Common/MinioBusinessLogic.cs b/IBKLinker-Minio/Common/MinioBusinessLogic.cs new file mode 100644 index 0000000..dd37a46 --- /dev/null +++ b/IBKLinker-Minio/Common/MinioBusinessLogic.cs @@ -0,0 +1,72 @@ +using IBKLinker_Minio.Entity; +using log4net; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Minio; +using System.Net.PeerToPeer; +using System.IO; +using System.Reactive.Linq; +using Minio.DataModel; +using System.Security.AccessControl; +using System.IO.Pipes; +using System.Net.Mime; +using IBKLinker_Minio.Entity.MinioController; +using SOA.Objects; +using SOA.Persistent; +using System.Web.Http.Results; +using System.Runtime.InteropServices.ComTypes; +using System.Xml; +using Swashbuckle.Swagger; +using System.Runtime.ConstrainedExecution; +using System.Net.Http; +using System.Web.UI.WebControls; +using System.Runtime.Remoting.Contexts; +using System.Runtime.InteropServices; +using System.Net; +using NPOI.XSSF.UserModel; +using NPOI.SS.UserModel; +using System.Net.Http.Headers; +using NPOI.SS.Formula.Functions; +using System.Xml.Linq; +using NPOI.HPSF; + +namespace IBKLinker_Minio.Common +{ + /// + /// 作者:孙亮 + /// 编写时间:2023-10-13 + /// 编写内容:minio业务逻辑 + /// + public class MinioBusinessLogic + { + private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public async Task Download(string bucketName, string path) + { + + MemoryStream memoryStream = new MemoryStream(); + try + { + var minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin");//验证连接minio数据库 + bucketName = "dayetegang";//桶名 + await minio.GetObjectAsync(bucketName, path, (stream) => + { + stream.CopyTo(memoryStream);//将文件去除复制到memoryStream + }); + memoryStream.Position = 0;//清除 + string base64String = Convert.ToBase64String(memoryStream.ToArray());//转换base64 + return base64String;//返回值 + } + catch (Exception ex) + { + logger.InfoFormat(ex.ToString()); + throw; + } + } + } +} diff --git a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs index b2ca7a2..266b66f 100644 --- a/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs +++ b/IBKLinker-Minio/Controller/MinioController/MinioApiController.cs @@ -27,6 +27,14 @@ using System.Net.Http; using System.Web.UI.WebControls; using System.Runtime.Remoting.Contexts; using System.Runtime.InteropServices; +using System.Net; +using NPOI.XSSF.UserModel; +using NPOI.SS.UserModel; +using System.Net.Http.Headers; +using NPOI.SS.Formula.Functions; +using System.Xml.Linq; +using NPOI.HPSF; +using IBKLinker_Minio.Common; namespace IBKLinker_Minio.Controller.MinioController { @@ -842,6 +850,7 @@ namespace IBKLinker_Minio.Controller.MinioController foreach (var item in date) { RequstStoragePath model = new RequstStoragePath(); + model.Pk = item.Pk; model.FileName = item.FileName; model.FilePate = item.FilePath; @@ -925,6 +934,7 @@ namespace IBKLinker_Minio.Controller.MinioController [HttpPost, Route("FileDownload")] public RequestEntity FileDownload(List minioStoragePath) { + MinioBusinessLogic bb = new MinioBusinessLogic(); RequestEntity request = new RequestEntity(); MinioStoragePath data = new MinioStoragePath(); using (IDbContext db = ObjectContainer.GetObject("db")) @@ -935,26 +945,19 @@ namespace IBKLinker_Minio.Controller.MinioController { foreach (var item in minioStoragePath) { + var minio = new MinioClient("172.15.88.212:9000", "minioadmin", "minioadmin"); string bucketName = "dayetegang"; - string downloadpath = "D:/linshi"; - if (System.IO.Directory.Exists(@downloadpath) == false)//如果不存在就创建文件夹 + var uploadTask = bb.Download(bucketName, item.FileName);//异步取base64 + uploadTask.Wait();//等待取值 + if (uploadTask.Status == TaskStatus.RanToCompletion && !uploadTask.IsFaulted) //判读是否由数值 { - System.IO.Directory.CreateDirectory(@downloadpath); - } - minio.GetObjectAsync(bucketName, item.FileName, downloadpath +"/"+ item.FileName);//先将minio数据库中的文件存储到本地 - bool fileExist = File.Exists(downloadpath + "/" + item.FileName);//判断是否已经存储到本地文件夹 - if (fileExist)//如果本地存在 - { - data.Bate64 = Base64(downloadpath + "/" + item.FileName); - data.FileName = item.FileName; - if (data.Bate64 != null) + data.Bate64 = uploadTask.Result; + data.FileName = item.FileName; + if (item.OperationType == "0") //操作类型为下载 { - File.Delete(downloadpath + "/" + item.FileName);//删除暂存文件 - } - if (item.OperationType =="0") //操作类型为下载 - { - string sql = "update MINIO_STORAGE_PATH set DOWNLOAD_NUM='" + item.DownloadNum + 1 + "' where pk='" + item.Pk + "'"; + int DownloadNum = item.DownloadNum + 1; + string sql = "update MINIO_STORAGE_PATH set DOWNLOAD_NUM='" + DownloadNum + "' where pk='" + item.Pk + "'"; db.Execute(sql); } request.code = "0"; @@ -987,6 +990,157 @@ namespace IBKLinker_Minio.Controller.MinioController return request; } #endregion + #region 标准清单 + [HttpGet, Route("StandardListGeneration")] + public HttpResponseMessage StandardListGeneration(StandardListGenerationModel args) + { + RequestEntity request = new RequestEntity(); + IList date = new List(); + HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); + using (IDbContext db = ObjectContainer.GetObject("db")) + { + try + { + if (args != null) + { + string ExcelName = "";//定义导出Excel文件名称 + FileStream file = new FileStream("D:/linshi/" + "清单模板.xlsx", FileMode.Open, FileAccess.Read); + XSSFWorkbook hssfworkbook = new XSSFWorkbook(file); + string sql = "select * from MINIO_STORAGE_PATH where 1=1 and FILE_TYPE='1' "; + if (args.InventoryType == "0")//标准类型 + { + if (!string.IsNullOrEmpty(args.BeginTime)) + { + sql += string.Format(" and CREATE_TIME >= to_date('{0}', 'yyyy/mm/dd hh24:mi:ss')", args.BeginTime);//开始时间 + } + if (!string.IsNullOrEmpty(args.EndTime)) + { + sql += string.Format(" and CREATE_TIME <= to_date('{0}', 'yyyy/mm/dd hh24:mi:ss')", args.EndTime);//结束时间 + } + sql += string.Format(" and FILE_PATH like'%{0}%'", args.InventoryName);//直接添加文件加名称 + ExcelName = "标准清单"; + } + else + { + #region 清单判断 + if (args.InventoryName =="HY企业标准清单") + { + sql += "and FILE_PATH like'%HY%'"; + ExcelName = "HY企业标准清单"; + } + if (args.InventoryName == "Q-HY企业标准清单") + { + sql += "and (FILE_PATH like'%Q/HY%'"; + ExcelName = "Q-HY企业标准清单"; + } + if (args.InventoryName == "新产品标准清单") + { + sql += "and (FILE_PATH like'%XYGN%' or FILE_PATH like'%XYGW%')"; + ExcelName = "新产品标准清单"; + } + if (args.InventoryName == "标准目录有效清单") + { + ExcelName = "标准目录有效清单"; + } + if (args.InventoryName == "企业标准明细表") + { + ExcelName = "企业标准明细表"; + } + if (args.InventoryName == "过期标准清单") + { + sql += "and (FILE_PATH like'%过期XYGN%' or FILE_PATH like'%过期XYGW%')"; + ExcelName = "过期标准清单"; + } + if (args.InventoryName == "参考标准清单") + { + sql += "and (FILE_PATH like'%XYGN%' or FILE_PATH like'%XYGW%')"; + ExcelName = "参考标准清单"; + } + if (args.InventoryName == "工艺卡清单") + { + sql += "and (FILE_PATH like'%170钢管厂工艺卡%' or FILE_PATH like'%219钢管厂工艺卡%' or FILE_PATH like'%460钢管厂工艺卡%' or FILE_PATH like'%170热处理工艺卡%' or FILE_PATH like'%连模铸系列工艺卡/转炉厂%' or FILE_PATH like'%连模铸系列工艺卡/特冶厂%' or FILE_PATH like'%连模铸系列工艺卡/电炉厂%' or FILE_PATH like'%电炉厂工艺卡%' or FILE_PATH like'%转炉厂工艺卡%' or FILE_PATH like'%特冶厂工艺卡%' or FILE_PATH like'%大棒厂工艺卡%' or FILE_PATH like'%小棒厂工艺卡%' or FILE_PATH like'%中棒厂工艺卡%'or FILE_PATH like'%锻造厂工艺卡%' or FILE_PATH like'%扁棒厂工艺卡)"; + ExcelName = "工艺卡清单"; + } + if (args.InventoryName == "工艺规程清单") + { + sql += "and FILE_PATH like'%工艺规程%'"; + ExcelName = "工艺规程清单"; + } + if (args.InventoryName == "技术制度清单") + { + sql += "and FILE_PATH like'%技术制度%'"; + ExcelName = "技术制度清单"; + } + if (args.InventoryName == "艺字工艺清单") + { + sql += "and FILE_PATH like'%艺字工艺%'"; + ExcelName = "艺字工艺清单"; + } + if (args.InventoryName == "技字通知清单") + { + sql += "and FILE_PATH like'%技字通知%'"; + ExcelName = "技字通知清单"; + } + #endregion + } + date = db.Query(string.Format("{0} order by UPK ASC, CREATOR_TIME ASC ", sql)); + if (date.Count > 0) + { + request.data = date;//测试查看数据用后去去掉 + var sheet = hssfworkbook.GetSheetAt(0); + for (int i = 0; i < date.Count; i++) + { + if (sheet != null) + { + sheet.CopyRow(2, 3 + i); + } + } + var rowIndex = 3; + for (int i = 0; i < date.Count; i++) + { + var curRow = sheet.GetRow(rowIndex); + var data = date[i]; + if (data.FilePath.IndexOf("XYGN") >= 0 || data.FilePath.IndexOf("XYGW") >= 0)//对国内国外标准进行特殊处理 + { + int Num = data.FileName.IndexOf("-") + 8;//取文件名称技术协议编号位数 + int name = data.FileName.Length - Num;//取文件名称技术协议名称位数 + curRow.GetCell(0).SetCellValue(data.FilePath.Replace(data.FileName, ""));//路径 + curRow.GetCell(1).SetCellValue(data.FileName.Substring(0, Num).Trim());//协议编号 + curRow.GetCell(2).SetCellValue(data.FileName.Substring(Num, name).Trim());//名称 + } + else + { + curRow.GetCell(0).SetCellValue(data.FilePath.Replace(data.FileName, ""));//路径 + curRow.GetCell(2).SetCellValue(data.FileName);//名称 + } + rowIndex = rowIndex + 1; + } + MemoryStream output = new MemoryStream(); + hssfworkbook.Write(output); + output.Seek(0, SeekOrigin.Begin); + result.Content = new StreamContent(output); + result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); + if (ExcelName != null) + { + result.Content.Headers.ContentDisposition.FileName = ExcelName + ".xlsx"; + } + else + { + result.Content.Headers.ContentDisposition.FileName = "标准清单.xlsx"; + } + result.Content.Headers.ContentLength = output.Length; + } + } + } + catch (Exception ex) + { + logger.InfoFormat(ex.ToString()); + } + } + return result; + } + #endregion #region 公用方法 /// /// 矫正pk值 @@ -1050,6 +1204,8 @@ namespace IBKLinker_Minio.Controller.MinioController } } #endregion + #region + #endregion } } diff --git a/IBKLinker-Minio/Entity/MinioController/StandardListGenerationModel.cs b/IBKLinker-Minio/Entity/MinioController/StandardListGenerationModel.cs new file mode 100644 index 0000000..a91b14b --- /dev/null +++ b/IBKLinker-Minio/Entity/MinioController/StandardListGenerationModel.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IBKLinker_Minio.Entity.MinioController +{ + /// + /// 文件上传标准清单model + /// + public class StandardListGenerationModel + { + /// + /// 清单名称 + /// + public string InventoryName { get; set; } + + /// + /// 清单类型 0为标准类型一个单一文件夹的清单,1为特殊模式多个文件夹的清单 + /// + public string InventoryType { get; set; } + + /// + /// 开始时间 + /// + public string BeginTime { set; get; } + + /// + /// 结束时间 + /// + public string EndTime { set; get; } + + + } +} diff --git a/IBKLinker-Minio/packages/NPOI.2.5.6/.signature.p7s b/IBKLinker-Minio/packages/NPOI.2.5.6/.signature.p7s new file mode 100644 index 0000000..30d84d5 Binary files /dev/null and b/IBKLinker-Minio/packages/NPOI.2.5.6/.signature.p7s differ diff --git a/IBKLinker-Minio/packages/NPOI.2.5.6/lib/netstandard2.0/NPOI.OOXML.dll b/IBKLinker-Minio/packages/NPOI.2.5.6/lib/netstandard2.0/NPOI.OOXML.dll new file mode 100644 index 0000000..fc393e7 Binary files /dev/null and b/IBKLinker-Minio/packages/NPOI.2.5.6/lib/netstandard2.0/NPOI.OOXML.dll differ diff --git a/IBKLinker-Minio/packages/NPOI.2.5.6/lib/netstandard2.0/NPOI.OpenXml4Net.dll b/IBKLinker-Minio/packages/NPOI.2.5.6/lib/netstandard2.0/NPOI.OpenXml4Net.dll new file mode 100644 index 0000000..5b33da5 Binary files /dev/null and b/IBKLinker-Minio/packages/NPOI.2.5.6/lib/netstandard2.0/NPOI.OpenXml4Net.dll differ