临时保存

pull/1/head
潘建东 9 months ago
parent c7a66ded83
commit 2c03cb5ce0

@ -149,6 +149,22 @@ namespace ZKLT.Hadoop.API.Controllers
}
}
[HttpPost("insertfile")]
public ActionResult InsertFile(IFormFile file)
{
if(file == null) {
return BadRequest("文件不存在");
}
var _file = new HDP_File();
_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;
return Ok(_file);
}
[HttpPost("insert")]
public ActionResult Insert(HDP_Command command) {
try

@ -40,25 +40,25 @@ namespace ZKLT.Hadoop.API
app.UseCors("all");
#endregion
//app.UseHadoop((c) =>
//{
// c.Host = "127.0.0.1";
// c.Account = "root";
// c.PassWord = "root";
// c.Key = "devdb";
// c.Port = 3306;
//});
app.UseHadoop((c) =>
{
c.Host = "172.17.0.1";
c.Host = "127.0.0.1";
c.Account = "root";
c.PassWord = "root";
c.Key = "testdb";
c.Port = 4000;
c.Key = "devdb";
c.Port = 3306;
});
//app.UseHadoop((c) =>
//{
// c.Host = "172.17.0.1";
// c.Account = "root";
// c.PassWord = "root";
// c.Key = "testdb";
// c.Port = 4000;
//});
//app.UseHadoop((c) =>
//{
// c.Host = "118.195.165.218";

@ -45,5 +45,10 @@ namespace ZKLT.Hadoop.Model
/// 大文本
/// </summary>
public const string LONGTEXT = "LONGTEXT";
/// <summary>
/// 大文件
/// </summary>
public const string LONGBLOB = "LONGBLOB";
}
}

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZKLT.Hadoop.Model
{
/// <summary>
/// 文件
/// </summary>
[HDP_Table(Key = "HDP_File", Description = "文件")]
public class HDP_File
{
private string? _Id;
private string? _FileName;
private string? _ContentType;
private int? _FileSize;
private byte[]? _Data;
private DateTime? createDate;
/// <summary>
/// 编号
/// </summary>
[HDP_Column(Key = "Id", Description = "编号",Length = 100,DataType = HDP_ColumnDataType.VARCHAR,IsPrimary = true,InsertDefault = "UUID()")]
public string? Id { get => _Id; set => _Id = value; }
/// <summary>
/// 文件名
/// </summary>
[HDP_Column(Key = "FileName",Description = "文件名",Length = 100, DataType = HDP_ColumnDataType.VARCHAR)]
public string? FileName { get => _FileName; set => _FileName = value; }
/// <summary>
/// 文件类型
/// </summary>
[HDP_Column(Key = "ContentType",Description = "文件类型",Length = 100,DataType = HDP_ColumnDataType.VARCHAR)]
public string? ContentType { get => _ContentType; set => _ContentType = value; }
/// <summary>
/// 文件数据
/// </summary>
[HDP_Column(Key = "Data",Description = "文件数据",DataType = HDP_ColumnDataType.LONGBLOB)]
public byte[]? Data { get => _Data; set => _Data = value; }
/// <summary>
/// 创建日期
/// </summary>
[HDP_Column(Key = "CreateDate", Description = "创建日期",DataType = HDP_ColumnDataType.DATETIME)]
public DateTime? CreateDate { get => createDate; set => createDate = value; }
/// <summary>
/// 文件大小
/// </summary>
[HDP_Column(Key = "FileSize",Description = "文件大小",DataType = HDP_ColumnDataType.INT)]
public int? FileSize { get => _FileSize; set => _FileSize = value; }
}
}

@ -127,6 +127,13 @@ namespace ZKLT.Hadoop
{
throw new Exception("初始化数据列失败");
}
var _file = HDP_Table.Class2Table<HDP_File>();
_Tables.Add(_file);
if (!_TableService.InitStruct(_Source, _file))
{
throw new Exception("初始化文件失败");
}
}
/// <summary>
@ -455,6 +462,48 @@ namespace ZKLT.Hadoop
return _TableService.Query<HDP_Table>(_Source, GetTable("HDP_Table")!, command.Where!, command.Data!, command.Order!);
}
/// <summary>
/// 插入文件
/// </summary>
/// <param name="file">文件</param>
/// <returns>是否成功</returns>
public bool InsertFile(HDP_File file)
{
if (!string.IsNullOrEmpty(file.Id) && _TableService.QuerySingle<HDP_File>(_Source, GetTable("HDP_File")!, new Dictionary<string, string> {
{ "Id","=" }
}, new Dictionary<string, object> {
{"Id",file.Id }
}) != null)
{
throw new ArgumentException("文件编号已存在");
}
return _TableService.Insert(_Source, GetTable("HDP_File")!, HDP_Table.Class2Dictionary(file));
}
/// <summary>
/// 删除文件
/// </summary>
/// <param name="fileId">文件编号</param>
/// <returns>是否成功</returns>
public bool DeleteFile(string fileId)
{
if (string.IsNullOrEmpty(fileId) || _TableService.QuerySingle<HDP_File>(_Source, GetTable("HDP_File")!, new Dictionary<string, string> {
{ "Id","=" }
}, new Dictionary<string, object> {
{"Id",fileId }
}) == null)
{
throw new ArgumentException("文件编号不存在");
}
return _TableService.Delete(_Source, GetTable("HDP_File")!, new Dictionary<string, string> {
{"Id","=" }
}, new Dictionary<string, object> {
{"Id",fileId }
});
}
/// <summary>
/// 插入数据
/// </summary>

Loading…
Cancel
Save