You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
8.6 KiB
C#

9 months ago
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MySqlX.XDevAPI.Relational;
using Newtonsoft.Json.Linq;
using ZKLT.Hadoop.Interface;
using ZKLT.Hadoop.Model;
namespace ZKLT.Hadoop.API.Controllers
{
/// <summary>
/// 云计算接口
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class HadoopController : ControllerBase
{
public HadoopController(IHadoopService hadoop,ITableService table, ITaskService task)
9 months ago
{
_HadoopService = hadoop;
4 months ago
_TableService = table;
_TaskService = task;
9 months ago
}
private IHadoopService _HadoopService;
4 months ago
private ITableService _TableService;
private ITaskService _TaskService;
9 months ago
[HttpGet("getid")]
public ActionResult GetId([FromQuery] string? prefix, [FromQuery] int? count) {
if (count != null && count > 0)
{
List<string> _result = new List<string>();
for (int i = 0; i < count; i++) {
string _temp = "";
if (!string.IsNullOrEmpty(prefix))
{
_temp += prefix;
}
var _date = DateTime.Now;
_temp += $@"{_date.Year.ToString().PadLeft(4, '0')}{_date.Month.ToString().PadLeft(2, '0')}{_date.Day.ToString().PadLeft(2, '0')}{_date.Hour.ToString().PadLeft(2, '0')}{_date.Minute.ToString().PadLeft(2, '0')}{_date.Second.ToString().PadLeft(2, '0')}{_date.Millisecond.ToString().PadLeft(3, '0')}{new Random().Next(9999).ToString().PadLeft(4, '0')}";
if (_result.Any(v => v == _temp))
{
i--;
}
else {
_result.Add(_temp);
}
}
return Ok(_result);
}
else {
string _result = "";
if (!string.IsNullOrEmpty(prefix))
{
_result += prefix;
}
var _date = DateTime.Now;
_result += $@"{_date.Year.ToString().PadLeft(4, '0')}{_date.Month.ToString().PadLeft(2, '0')}{_date.Day.ToString().PadLeft(2, '0')}{_date.Hour.ToString().PadLeft(2, '0')}{_date.Minute.ToString().PadLeft(2, '0')}{_date.Second.ToString().PadLeft(2, '0')}{_date.Millisecond.ToString().PadLeft(3, '0')}{new Random().Next(9999).ToString().PadLeft(4, '0')}";
return Ok(_result);
9 months ago
}
}
9 months ago
[HttpGet("getsource")]
public ActionResult GetSource([FromQuery] string sourceid)
{
try
{
4 months ago
return Ok(_TableService.GetSource(sourceid));
9 months ago
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("insertsource")]
public ActionResult InsertSource(HDP_Source source)
{
try
{
return Ok(_HadoopService.InsertSource(source));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("updatesource")]
public ActionResult UpdateSource(HDP_Source source)
{
try
{
return Ok(_HadoopService.UpdateSource(source));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpGet("deletesource")]
public ActionResult DeleteSource([FromQuery] string sourceid)
{
try
{
return Ok(_HadoopService.DeleteSource(sourceid));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("querysource")]
public ActionResult QuerySource(HDP_Command command)
{
try
{
return Ok(_HadoopService.QuerySource(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpGet("gettable")]
public ActionResult GetTable([FromQuery] string tableid)
{
try
{
4 months ago
return Ok(_TableService.GetTable(tableid));
9 months ago
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("inserttable")]
public ActionResult InsertTable(HDP_Table table)
{
try
{
return Ok(_HadoopService.InsertTable(table));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("updatetable")]
public ActionResult UpdateTable(HDP_Table table)
{
try
{
return Ok(_HadoopService.UpdateTable(table));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpGet("deletetable")]
public ActionResult DeleteTable([FromQuery] string tableId)
{
9 months ago
try
{
return Ok(_HadoopService.DeleteTable(tableId));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("querytable")]
public ActionResult QueryTable(HDP_Command command)
{
9 months ago
try
{
return Ok(_HadoopService.QueryTable(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("insert")]
[RequestSizeLimit(int.MaxValue)]
public ActionResult Insert(HDP_Command command)
{
9 months ago
try
{
return Ok(_HadoopService.Insert(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("update")]
public ActionResult Update(HDP_Command command)
{
try
{
return Ok(_HadoopService.Update(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("delete")]
public ActionResult Delete(HDP_Command command)
{
try
{
return Ok(_HadoopService.Delete(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("querysingle")]
public ActionResult QuerySingle(HDP_Command command)
{
try
{
return Ok(_HadoopService.QuerySingle<dynamic>(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("query")]
public ActionResult Query(HDP_Command command)
{
try
{
return Ok(_HadoopService.Query<dynamic>(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("page")]
public ActionResult Page(HDP_Command command)
{
9 months ago
try
{
return Ok(_HadoopService.Page<dynamic>(command));
}
catch (Exception e)
{
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);
}
}
[HttpPost("createTask")]
public ActionResult CreateTask(HDP_Task taskParams)
{
try
{
return Ok(_TaskService.Start(taskParams));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("closeTask")]
public ActionResult CloseTask(HDP_Task taskParams)
{
try
{
return Ok(_TaskService.Close(taskParams));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
9 months ago
}
}