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.

257 lines
6.6 KiB
C#

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)
{
_HadoopService = hadoop;
}
private IHadoopService _HadoopService;
[HttpGet("getid")]
public ActionResult GetId([FromQuery] string? prefix) {
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(1000).ToString().PadLeft(4,'0')}";
return Ok(_result);
}
[HttpGet("getsource")]
public ActionResult GetSource([FromQuery] string sourceid)
{
try
{
return Ok(_HadoopService.GetSource(sourceid));
}
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
{
return Ok(_HadoopService.GetTable(tableid));
}
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)
{
try
{
return Ok(_HadoopService.DeleteTable(tableId));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("querytable")]
public ActionResult QueryTable(HDP_Command command)
{
try
{
return Ok(_HadoopService.QueryTable(command));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
[HttpPost("insert")]
public ActionResult Insert(HDP_Command command)
{
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)
{
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);
}
}
}
}