批量接口、跑批文件、跨域设置

pull/1/head
潘建东 9 months ago
parent 3e18879140
commit e060777868

@ -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);
}
}
}
}

@ -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())

@ -133,5 +133,12 @@ namespace ZKLT.Hadoop.Interface
/// <param name="command">命令</param>
/// <returns>结果</returns>
public HDP_Page<T> Page<T>(HDP_Command command);
/// <summary>
/// 批量执行任务
/// </summary>
/// <param name="command">指令</param>
/// <returns></returns>
public object?[] PatchCommand(HDP_Command[] command);
}
}

@ -19,6 +19,8 @@ namespace ZKLT.Hadoop.Model
private int? _PageSize;
private string? _Type;
private Dictionary<string, string>? _Where;
private Dictionary<string, object>? _Data;
@ -59,5 +61,10 @@ namespace ZKLT.Hadoop.Model
/// 排序
/// </summary>
public Dictionary<string, string>? Order { get => _Order; set => _Order = value; }
/// <summary>
/// 命令类型
/// </summary>
public string? Type { get => _Type; set => _Type = value; }
}
}

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZKLT.Hadoop.Model
{
/// <summary>
/// 命令类型
/// </summary>
public class HDP_CommandType
{
/// <summary>
/// 插入
/// </summary>
public const string INSERT = "INSERT";
/// <summary>
/// 更新
/// </summary>
public const string UPDATE = "UPDATE";
/// <summary>
/// 删除
/// </summary>
public const string DELETE = "DELETE";
/// <summary>
/// 查询单条
/// </summary>
public const string QUERYSINGLE = "QUERYSINGLE";
/// <summary>
/// 查询
/// </summary>
public const string QUERY = "QUERY";
/// <summary>
/// 分页
/// </summary>
public const string PAGE = "PAGE";
}
}

@ -585,5 +585,104 @@ namespace ZKLT.Hadoop
var _source = GetSource(_table.SourceId!);
return _TableService.QueryPage<T>(_source!, _table, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!);
}
/// <summary>
/// 批量执行任务
/// </summary>
/// <param name="command">指令</param>
/// <returns></returns>
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<dynamic>(command[i]);
_result[i] = _temp;
}
else if (command[i].Type == HDP_CommandType.QUERY)
{
var _temp = Query<dynamic>(command[i]);
_result[i] = _temp;
}
else if (command[i].Type == HDP_CommandType.PAGE)
{
var _temp = Page<dynamic>(command[i]);
_result[i] = _temp;
}
else
{
_result[i] = "不支持该命令";
}
}
catch (Exception ex)
{
_result[i] = ex.Message;
}
}
return _result.ToArray();
}
}
}

@ -0,0 +1 @@
docker build -f Hadoop\ZKLT.Hadoop.API\Dockerfile -t hadoop:latest .
Loading…
Cancel
Save