From 2c03cb5ce02dd02312dd10b7f90670019dfe9a98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=BD=98=E5=BB=BA=E4=B8=9C?= <617601767@qq.com>
Date: Fri, 8 Mar 2024 12:49:47 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E4=BF=9D=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/HadoopController.cs | 16 +++++
Hadoop/ZKLT.Hadoop.API/Program.cs | 26 ++++----
.../ZKLT.Hadoop.Model/HDP_ColumnDataType.cs | 5 ++
Hadoop/ZKLT.Hadoop.Model/HDP_File.cs | 64 +++++++++++++++++++
Hadoop/ZKLT.Hadoop/HadoopService.cs | 49 ++++++++++++++
5 files changed, 147 insertions(+), 13 deletions(-)
create mode 100644 Hadoop/ZKLT.Hadoop.Model/HDP_File.cs
diff --git a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
index ef5fa7b..facde84 100644
--- a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
+++ b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
@@ -149,6 +149,22 @@ namespace ZKLT.Hadoop.API.Controllers
}
}
+ [HttpPost("insertfile")]
+ public ActionResult InsertFile(IFormFile file)
+ {
+ if(file == null) {
+ return BadRequest("文件不存在");
+ }
+
+ var _file = new HDP_File();
+ _file.FileName = file.FileName;
+ _file.ContentType = file.ContentType;
+ _file.Data = new byte[file.Length];
+ file.OpenReadStream().Read(_file.Data, 0, (int)file.Length);
+ _file.FileSize = (int)file.Length;
+ return Ok(_file);
+ }
+
[HttpPost("insert")]
public ActionResult Insert(HDP_Command command) {
try
diff --git a/Hadoop/ZKLT.Hadoop.API/Program.cs b/Hadoop/ZKLT.Hadoop.API/Program.cs
index 4bd3f71..3d373ef 100644
--- a/Hadoop/ZKLT.Hadoop.API/Program.cs
+++ b/Hadoop/ZKLT.Hadoop.API/Program.cs
@@ -40,25 +40,25 @@ namespace ZKLT.Hadoop.API
app.UseCors("all");
#endregion
- //app.UseHadoop((c) =>
- //{
- // c.Host = "127.0.0.1";
- // c.Account = "root";
- // c.PassWord = "root";
- // c.Key = "devdb";
- // c.Port = 3306;
- //});
-
-
app.UseHadoop((c) =>
{
- c.Host = "172.17.0.1";
+ c.Host = "127.0.0.1";
c.Account = "root";
c.PassWord = "root";
- c.Key = "testdb";
- c.Port = 4000;
+ c.Key = "devdb";
+ c.Port = 3306;
});
+
+ //app.UseHadoop((c) =>
+ //{
+ // c.Host = "172.17.0.1";
+ // c.Account = "root";
+ // c.PassWord = "root";
+ // c.Key = "testdb";
+ // c.Port = 4000;
+ //});
+
//app.UseHadoop((c) =>
//{
// c.Host = "118.195.165.218";
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_ColumnDataType.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_ColumnDataType.cs
index caa710f..722dc45 100644
--- a/Hadoop/ZKLT.Hadoop.Model/HDP_ColumnDataType.cs
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_ColumnDataType.cs
@@ -45,5 +45,10 @@ namespace ZKLT.Hadoop.Model
/// 大文本
///
public const string LONGTEXT = "LONGTEXT";
+
+ ///
+ /// 大文件
+ ///
+ public const string LONGBLOB = "LONGBLOB";
}
}
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_File.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_File.cs
new file mode 100644
index 0000000..cf00eff
--- /dev/null
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_File.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZKLT.Hadoop.Model
+{
+ ///
+ /// 文件
+ ///
+ [HDP_Table(Key = "HDP_File", Description = "文件")]
+ public class HDP_File
+ {
+ private string? _Id;
+
+ private string? _FileName;
+
+ private string? _ContentType;
+
+ private int? _FileSize;
+
+ private byte[]? _Data;
+
+ private DateTime? createDate;
+
+ ///
+ /// 编号
+ ///
+ [HDP_Column(Key = "Id", Description = "编号",Length = 100,DataType = HDP_ColumnDataType.VARCHAR,IsPrimary = true,InsertDefault = "UUID()")]
+ public string? Id { get => _Id; set => _Id = value; }
+
+ ///
+ /// 文件名
+ ///
+ [HDP_Column(Key = "FileName",Description = "文件名",Length = 100, DataType = HDP_ColumnDataType.VARCHAR)]
+ public string? FileName { get => _FileName; set => _FileName = value; }
+
+ ///
+ /// 文件类型
+ ///
+ [HDP_Column(Key = "ContentType",Description = "文件类型",Length = 100,DataType = HDP_ColumnDataType.VARCHAR)]
+ public string? ContentType { get => _ContentType; set => _ContentType = value; }
+
+ ///
+ /// 文件数据
+ ///
+ [HDP_Column(Key = "Data",Description = "文件数据",DataType = HDP_ColumnDataType.LONGBLOB)]
+ public byte[]? Data { get => _Data; set => _Data = value; }
+
+ ///
+ /// 创建日期
+ ///
+ [HDP_Column(Key = "CreateDate", Description = "创建日期",DataType = HDP_ColumnDataType.DATETIME)]
+ public DateTime? CreateDate { get => createDate; set => createDate = value; }
+
+ ///
+ /// 文件大小
+ ///
+ [HDP_Column(Key = "FileSize",Description = "文件大小",DataType = HDP_ColumnDataType.INT)]
+ public int? FileSize { get => _FileSize; set => _FileSize = value; }
+ }
+}
diff --git a/Hadoop/ZKLT.Hadoop/HadoopService.cs b/Hadoop/ZKLT.Hadoop/HadoopService.cs
index 79b77ba..c021ac3 100644
--- a/Hadoop/ZKLT.Hadoop/HadoopService.cs
+++ b/Hadoop/ZKLT.Hadoop/HadoopService.cs
@@ -127,6 +127,13 @@ namespace ZKLT.Hadoop
{
throw new Exception("初始化数据列失败");
}
+
+ var _file = HDP_Table.Class2Table();
+ _Tables.Add(_file);
+ if (!_TableService.InitStruct(_Source, _file))
+ {
+ throw new Exception("初始化文件失败");
+ }
}
///
@@ -455,6 +462,48 @@ namespace ZKLT.Hadoop
return _TableService.Query(_Source, GetTable("HDP_Table")!, command.Where!, command.Data!, command.Order!);
}
+ ///
+ /// 插入文件
+ ///
+ /// 文件
+ /// 是否成功
+ public bool InsertFile(HDP_File file)
+ {
+ if (!string.IsNullOrEmpty(file.Id) && _TableService.QuerySingle(_Source, GetTable("HDP_File")!, new Dictionary {
+ { "Id","=" }
+ }, new Dictionary {
+ {"Id",file.Id }
+ }) != null)
+ {
+ throw new ArgumentException("文件编号已存在");
+ }
+
+ return _TableService.Insert(_Source, GetTable("HDP_File")!, HDP_Table.Class2Dictionary(file));
+ }
+
+ ///
+ /// 删除文件
+ ///
+ /// 文件编号
+ /// 是否成功
+ public bool DeleteFile(string fileId)
+ {
+ if (string.IsNullOrEmpty(fileId) || _TableService.QuerySingle(_Source, GetTable("HDP_File")!, new Dictionary {
+ { "Id","=" }
+ }, new Dictionary {
+ {"Id",fileId }
+ }) == null)
+ {
+ throw new ArgumentException("文件编号不存在");
+ }
+
+ return _TableService.Delete(_Source, GetTable("HDP_File")!, new Dictionary {
+ {"Id","=" }
+ }, new Dictionary {
+ {"Id",fileId }
+ });
+ }
+
///
/// 插入数据
///