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) { _HadoopService = hadoop; } private IHadoopService _HadoopService; [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("insertfile")] //public ActionResult InsertFile(IFormFile file, [FromQuery] string id = "") //{ // if (file == null) // { // return BadRequest("文件不存在"); // } // try // { // var _file = new HDP_File(); // if (!string.IsNullOrEmpty(id)) // { // _file.Id = id; // } // else { // _file.Id = Guid.NewGuid().ToString(); // } // _file.FileName = file.FileName; // _file.ContentType = file.ContentType; // _file.Data = new byte[file.Length]; // file.OpenReadStream().Read(_file.Data, 0, (int)file.Length); // _file.FileSize = (int)file.Length; // if (_HadoopService.Insert(new HDP_Command // { // TableId = "HDP_File", // Data = HDP_Table.Class2Dictionary(_file) // })) // { // return Ok(_file.Id); // } // else { // return Ok(false); // } // } // catch (Exception e) // { // return BadRequest(e.Message); // } //} //[HttpGet("deletefile")] //public ActionResult DeleteFile([FromQuery] string fileId) //{ // try // { // return Ok(_HadoopService.Delete(new HDP_Command // { // TableId = "HDP_File", // Where = new Dictionary { // { "Id","="} // }, // Data = new Dictionary { // {"Id",fileId } // } // })); // } // catch (Exception e) // { // return BadRequest(e.Message); // } //} //[HttpGet("getfile")] //public ActionResult GetFile([FromQuery] string fileId) //{ // try // { // var _file = _HadoopService.QuerySingle(new HDP_Command // { // TableId = "HDP_File", // Where = new Dictionary // { // {"Id","=" } // }, // Data = new Dictionary // { // {"Id",fileId } // } // }); // if (_file != null) // { // return File(_file.Data!, _file.ContentType!); // } // else { // return NoContent(); // } // } // catch (Exception e) // { // return BadRequest(e.Message); // } //} //[HttpPost("queryfile")] //public ActionResult QueryFile(HDP_Command command) //{ // try // { // var _files = _HadoopService.Query(command); // for (var i = 0; i < _files.Length; i++) { // _files[i].Data = null; // } // return Ok(_files); // } // catch (Exception e) // { // return BadRequest(e.Message); // } //} //[HttpPost("pagefile")] //public ActionResult PageFile(HDP_Command command) //{ // try // { // var _filesPage = _HadoopService.Page(command); // for (var i = 0; i < _filesPage.Data!.Length; i++) // { // _filesPage.Data[i]!.Data = null; // } // return Ok(_filesPage); // } // 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); } } } }