123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- using Azure;
- using Azure.Data.Tables;
- using HTEX.Complex.Models;
- using HTEX.Complex.Service;
- using HTEX.Complex.Service.AzureRedis;
- using HTEX.Complex.Service.AzureStorage;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Azure.Cosmos;
- using System.Text.Json;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI.AzureCosmos3;
- using TableEntity = Azure.Data.Tables.TableEntity;
- namespace HTEX.Complex.Controllers
- {
- [Route("official")]
- [ApiController]
- public class OfficialController : ControllerBase
- {
- private readonly DingDing _dingDing;
- // private readonly SnowflakeId _snowflakeId;
- // private readonly ServerSentEventsService _sse;
- private readonly AzureCosmos3Factory _azureCosmos3Factory;
- private readonly System.Net.Http.IHttpClientFactory _httpClientFactory;
- //private readonly Models.Option _option;
- // private readonly MailFactory _mailFactory;
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IWebHostEnvironment _environment;
- private readonly IConfiguration _configuration;
- // private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly IPSearcher _searcher;
- public OfficialController(IWebHostEnvironment environment, IConfiguration configuration,
- AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, System.Net.Http.IHttpClientFactory httpClientFactory, AzureCosmos3Factory azureCosmos3Factory,
- // IOptionsSnapshot<Option> option,
- DingDing dingDing, IPSearcher searcher)
- {
- _dingDing = dingDing;
- _azureCosmos3Factory = azureCosmos3Factory;
- _httpClientFactory = httpClientFactory;
- _azureRedis = azureRedis;
- _azureStorage = azureStorage;
- _environment = environment;
- _configuration = configuration;
- _searcher = searcher;
- }
-
- [ProducesDefaultResponseType]
- [RequestSizeLimit(102_400_000_00)] //最大10000m左右
- [HttpPost("video-ls")]
- public async Task<IActionResult> VideoUpload()
- {
- List<string> students = new List<string>();
- //var result= await _azureCosmos3Factory.GetCosmosClient().GetContainer("winteachos", Constant.Teacher)
- // .GetList<Teacher>( "select value c from c", "Base");
- await foreach (var item in _azureCosmos3Factory.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student)
- .GetItemQueryIteratorList<string>(queryText: "select value c.id from c", requestOptions: new QueryRequestOptions {MaxItemCount=5, PartitionKey = new PartitionKey("Base-hbcn") }))
- {
- students.AddRange(item.list);
- }
- return Ok(students);
- }
-
- [ProducesDefaultResponseType]
- [HttpPost("video-list")]
- public async Task<IActionResult> VideoList(JsonElement json)
- {
- List<OfficialVideo> videos = new List<OfficialVideo>();
- var table = _azureStorage.TableServiceClient().GetTableClient("ShortUrl");
-
- if (json.TryGetProperty("rowKey", out JsonElement _rowKey) && !string.IsNullOrWhiteSpace($"{_rowKey}"))
- {
- videos = table.Query<OfficialVideo>($"{Constant.PartitionKey} {Constant.Equal} 'OfficialVideo' and {Constant.RowKey} {Constant.Equal} '{_rowKey}'").ToList();
-
-
- }
- else
- {
- videos = table.Query<OfficialVideo>(filter: $"{Constant.PartitionKey} eq 'OfficialVideo'").ToList();
- }
- return Ok(new { videos });
- }
-
- [ProducesDefaultResponseType]
- [RequestSizeLimit(102_400_000_00)] //最大10000m左右
- [HttpPost("video-upload")]
- public async Task<IActionResult> VideoUpload( [FromForm] string name, [FromForm] string type, [FromForm] string? rowKey=null, [FromForm] IFormFile? videoFile = null)
- {
- OfficialVideo video = null;
- string url = string.Empty;
- var table = _azureStorage.TableServiceClient().GetTableClient("ShortUrl");
- if (videoFile == null )
- {
- if (!string.IsNullOrWhiteSpace(rowKey))
- {
- try
- {
- video=await table.GetEntityAsync<OfficialVideo>("OfficialVideo", rowKey);
- }
- catch { return BadRequest(); }
- }
- else {
- return BadRequest();
- }
- }
- else {
- if (!string.IsNullOrWhiteSpace(rowKey))
- {
- try
- {
- video=await table.GetEntityAsync<OfficialVideo>("OfficialVideo", rowKey);
- }
- catch { }
- }
- if (video== null)
- {
- video= new OfficialVideo { RowKey=$"{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}", PartitionKey="OfficialVideo" };
- }
- string fileExt = FileType.GetExtention(videoFile.FileName).ToLower();
- if (fileExt.Equals("mp4", StringComparison.OrdinalIgnoreCase))
- {
- var url_blob = await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(videoFile.OpenReadStream(), "official", $"{video.RowKey}.{fileExt}", false);
- url=url_blob.url;
- }
- }
- video.name= name;
- video.type= type;
- video.url=string.IsNullOrWhiteSpace(url)?video.url:url;
- table.UpsertEntity<OfficialVideo>(video);
- return Ok(new { video });
- }
- }
- //[TableName(Name = "ShortUrl")]
- public class OfficialVideo : HTableEntity
- {
- ///// <summary>
- ///// OfficialVideo
- ///// </summary>
- //public string PartitionKey { get; set; }
- ///// <summary>
- ///// 视频id
- ///// </summary>
- //public string RowKey { get; set; }
- /// <summary>
- /// 名称
- /// </summary>
- public string? name { get; set; }
- /// <summary>
- /// 类型
- /// </summary>
- public string?type { get; set; }
- /// <summary>
- /// 地址
- /// </summary>
- public string? url { get; set; }
- }
- public class Student : CosmosEntity
- {
- public string mail { get; set; }
- public string mobile { get; set; }
- public string country { get; set; }
- public string name { get; set; }
- public string picture { get; set; }
- public string schoolId { get; set; }
- public string pw { get; set; }
- public string salt { get; set; }
- public int year { get; set; }
- //座位号
- public string no { get; set; } //座位号
- public string irs { get; set; }
- //绑定班级Id
- public string classId { get; set; }
- //分组信息
- public string groupId { get; set; }
- public string groupName { get; set; }
- public string periodId { get; set; }
- /// <summary>
- /// 性别 M( male,男) F (female 女) N(secret 保密)
- /// </summary>
- public string gender { get; set; }
- //补充留级信息
- //0在校,1毕业
- public int graduate { get; set; } = 0;
-
- /// <summary>
- /// 创建时间 十位 时间戳
- /// </summary>
- public long createTime { get; set; }
-
- /// <summary>
- /// 学生的专业id
- /// </summary>
- public string majorId { get; set; }
- /// <summary>
- /// 學生的OpenID (TW教育雲綁定ID)
- /// </summary>
- public string openId { get; set; }
- }
- /// <summary>
- /// 教师
- /// </summary>
- public class Teacher : CosmosEntity
- {
- public Teacher()
- {
- pk = "Teacher";
- }
-
- /// <summary>
- /// 系统权限信息
- /// </summary>
- public HashSet<string> permissions { get; set; } = new HashSet<string>();
- /// <summary>
- /// 组织信息
- /// </summary>
-
- //常用设备信息,及IP登录信息。
- }
- }
|