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 { /// /// 云计算接口 /// [Route("api/[controller]")] [ApiController] public class HadoopController : ControllerBase { public HadoopController(IHadoopService hadoop,ITableService table, ITaskService task) { _HadoopService = hadoop; _TableService = table; _TaskService = task; } private IHadoopService _HadoopService; private ITableService _TableService; private ITaskService _TaskService; [HttpGet("getid")] public ActionResult GetId([FromQuery] string? prefix, [FromQuery] int? count) { if (count != null && count > 0) { List _result = new List(); 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); } } [HttpGet("getsource")] public ActionResult GetSource([FromQuery] string sourceid) { try { return Ok(_TableService.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(_TableService.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(command)); } catch (Exception e) { return BadRequest(e.Message); } } [HttpPost("query")] public ActionResult Query(HDP_Command command) { try { return Ok(_HadoopService.Query(command)); } catch (Exception e) { return BadRequest(e.Message); } } [HttpPost("page")] public ActionResult Page(HDP_Command command) { try { return Ok(_HadoopService.Page(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("1")); } catch (Exception e) { return BadRequest(e.Message); } } } }