From e060777868fb97e906ebaa203a79efeac55484c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=BD=98=E5=BB=BA=E4=B8=9C?= <617601767@qq.com>
Date: Sat, 2 Mar 2024 18:26:16 +0800
Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=8E=A5=E5=8F=A3=E3=80=81?=
=?UTF-8?q?=E8=B7=91=E6=89=B9=E6=96=87=E4=BB=B6=E3=80=81=E8=B7=A8=E5=9F=9F?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/HadoopController.cs | 12 +++
Hadoop/ZKLT.Hadoop.API/Program.cs | 21 +++-
.../ZKLT.Hadoop.Interface/IHadoopService.cs | 7 ++
Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs | 7 ++
Hadoop/ZKLT.Hadoop.Model/HDP_CommandType.cs | 44 +++++++++
Hadoop/ZKLT.Hadoop/HadoopService.cs | 99 +++++++++++++++++++
HadoopDocker.bat | 1 +
7 files changed, 188 insertions(+), 3 deletions(-)
create mode 100644 Hadoop/ZKLT.Hadoop.Model/HDP_CommandType.cs
create mode 100644 HadoopDocker.bat
diff --git a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
index e34419a..ef5fa7b 100644
--- a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
+++ b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
@@ -224,5 +224,17 @@ namespace ZKLT.Hadoop.API.Controllers
return BadRequest(e.Message);
}
}
+
+ [HttpPost("patch")]
+ public ActionResult PatchCommand(HDP_Command[] command) {
+ try
+ {
+ return Ok(_HadoopService.PatchCommand(command));
+ }
+ catch (Exception e)
+ {
+ return BadRequest(e.Message);
+ }
+ }
}
}
diff --git a/Hadoop/ZKLT.Hadoop.API/Program.cs b/Hadoop/ZKLT.Hadoop.API/Program.cs
index 1be08e0..abe13e2 100644
--- a/Hadoop/ZKLT.Hadoop.API/Program.cs
+++ b/Hadoop/ZKLT.Hadoop.API/Program.cs
@@ -9,6 +9,18 @@ namespace ZKLT.Hadoop.API
{
var builder = WebApplication.CreateBuilder(args);
+ #region Cors跨域
+ builder.Services.AddCors(options =>
+ {
+ options.AddPolicy("all", builder =>
+ {
+ builder.SetIsOriginAllowed(origin => true) //允许任何来源的主机访问
+ .AllowAnyMethod()
+ .AllowAnyHeader()
+ .AllowCredentials();//指定处理cookie
+ });
+ });
+ #endregion
// Add services to the container.
builder.Services.AddControllers().AddNewtonsoftJson(options =>
@@ -24,12 +36,15 @@ namespace ZKLT.Hadoop.API
builder.Services.AddSwaggerGen();
builder.Services.AddHadoop();
var app = builder.Build();
+ #region Cors跨域
+ app.UseCors("all");
+ #endregion
app.UseHadoop((c) => {
- c.Host = "127.0.0.1";
+ c.Host = "172.17.0.1";
c.Account = "root";
c.PassWord = "root";
- c.Key = "devdb";
- c.Port = 3306;
+ c.Key = "testdb";
+ c.Port = 4000;
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
diff --git a/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs b/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs
index 9c34355..f0813b5 100644
--- a/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs
+++ b/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs
@@ -133,5 +133,12 @@ namespace ZKLT.Hadoop.Interface
/// 鍛戒护
/// 缁撴灉
public HDP_Page Page(HDP_Command command);
+
+ ///
+ /// 鎵归噺鎵ц浠诲姟
+ ///
+ /// 鎸囦护
+ ///
+ public object?[] PatchCommand(HDP_Command[] command);
}
}
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
index b0ab375..4931ac8 100644
--- a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
@@ -19,6 +19,8 @@ namespace ZKLT.Hadoop.Model
private int? _PageSize;
+ private string? _Type;
+
private Dictionary? _Where;
private Dictionary? _Data;
@@ -59,5 +61,10 @@ namespace ZKLT.Hadoop.Model
/// 鎺掑簭
///
public Dictionary? Order { get => _Order; set => _Order = value; }
+
+ ///
+ /// 鍛戒护绫诲瀷
+ ///
+ public string? Type { get => _Type; set => _Type = value; }
}
}
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_CommandType.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_CommandType.cs
new file mode 100644
index 0000000..36dd7dd
--- /dev/null
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_CommandType.cs
@@ -0,0 +1,44 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZKLT.Hadoop.Model
+{
+ ///
+ /// 鍛戒护绫诲瀷
+ ///
+ public class HDP_CommandType
+ {
+ ///
+ /// 鎻掑叆
+ ///
+ public const string INSERT = "INSERT";
+
+ ///
+ /// 鏇存柊
+ ///
+ public const string UPDATE = "UPDATE";
+
+ ///
+ /// 鍒犻櫎
+ ///
+ public const string DELETE = "DELETE";
+
+ ///
+ /// 鏌ヨ鍗曟潯
+ ///
+ public const string QUERYSINGLE = "QUERYSINGLE";
+
+ ///
+ /// 鏌ヨ
+ ///
+ public const string QUERY = "QUERY";
+
+ ///
+ /// 鍒嗛〉
+ ///
+ public const string PAGE = "PAGE";
+ }
+}
diff --git a/Hadoop/ZKLT.Hadoop/HadoopService.cs b/Hadoop/ZKLT.Hadoop/HadoopService.cs
index 74ac972..79b77ba 100644
--- a/Hadoop/ZKLT.Hadoop/HadoopService.cs
+++ b/Hadoop/ZKLT.Hadoop/HadoopService.cs
@@ -585,5 +585,104 @@ namespace ZKLT.Hadoop
var _source = GetSource(_table.SourceId!);
return _TableService.QueryPage(_source!, _table, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!);
}
+
+ ///
+ /// 鎵归噺鎵ц浠诲姟
+ ///
+ /// 鎸囦护
+ ///
+ public object?[] PatchCommand(HDP_Command[] command)
+ {
+ object?[] _result = new object?[command.Length];
+ using (TransactionScope _scope = new TransactionScope())
+ {
+ var _isComplete = true;
+ for (var i = 0; i < command.Length; i++)
+ {
+ try
+ {
+ if (command[i].Type == HDP_CommandType.INSERT)
+ {
+ var _temp = Insert(command[i]);
+ if (!_temp)
+ {
+ _isComplete = false;
+ }
+ _result[i] = _temp;
+ }
+ else if (command[i].Type == HDP_CommandType.UPDATE)
+ {
+ var _temp = Update(command[i]);
+ if (!_temp)
+ {
+ _isComplete = false;
+ }
+ _result[i] = _temp;
+ }
+ else if (command[i].Type == HDP_CommandType.DELETE)
+ {
+ var _temp = Delete(command[i]);
+ if (!_temp)
+ {
+ _isComplete = false;
+ }
+ _result[i] = _temp;
+ }
+ else if (command[i].Type == HDP_CommandType.QUERYSINGLE || command[i].Type == HDP_CommandType.QUERY || command[i].Type == HDP_CommandType.PAGE)
+ {
+ continue;
+ }
+ else
+ {
+ _result[i] = "涓嶆敮鎸佽鍛戒护";
+ _isComplete = false;
+ }
+ }
+ catch (Exception ex)
+ {
+ _result[i] = ex.Message;
+ _isComplete = false;
+ }
+ }
+ if (_isComplete)
+ {
+ _scope.Complete();
+ }
+ }
+ for (var i = 0; i < command.Length; i++)
+ {
+ try
+ {
+ if (command[i].Type == HDP_CommandType.INSERT || command[i].Type == HDP_CommandType.UPDATE || command[i].Type == HDP_CommandType.DELETE)
+ {
+ continue;
+ }
+ else if (command[i].Type == HDP_CommandType.QUERYSINGLE)
+ {
+ var _temp = QuerySingle(command[i]);
+ _result[i] = _temp;
+ }
+ else if (command[i].Type == HDP_CommandType.QUERY)
+ {
+ var _temp = Query(command[i]);
+ _result[i] = _temp;
+ }
+ else if (command[i].Type == HDP_CommandType.PAGE)
+ {
+ var _temp = Page(command[i]);
+ _result[i] = _temp;
+ }
+ else
+ {
+ _result[i] = "涓嶆敮鎸佽鍛戒护";
+ }
+ }
+ catch (Exception ex)
+ {
+ _result[i] = ex.Message;
+ }
+ }
+ return _result.ToArray();
+ }
}
}
diff --git a/HadoopDocker.bat b/HadoopDocker.bat
new file mode 100644
index 0000000..d7e9f50
--- /dev/null
+++ b/HadoopDocker.bat
@@ -0,0 +1 @@
+docker build -f Hadoop\ZKLT.Hadoop.API\Dockerfile -t hadoop:latest .
\ No newline at end of file