|
@@ -1,664 +0,0 @@
|
|
|
-using Microsoft.AspNetCore.Mvc;
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using TEAMModelOS.SDK.Context.Exception;
|
|
|
-using TEAMModelOS.SDK;
|
|
|
-
|
|
|
-using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
-using TEAMModelOS.SDK.Helper.Security.ShaHash;
|
|
|
-using TEAMModelOS.SDK.DI;
|
|
|
-using TEAMModelOS.Models;
|
|
|
-using System.Text.Json;
|
|
|
-using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
|
-using TEAMModelOS.SDK.Models;
|
|
|
-using Microsoft.AspNetCore.Http;
|
|
|
-using System.IdentityModel.Tokens.Jwt;
|
|
|
-using Azure.Cosmos;
|
|
|
-using System.IO;
|
|
|
-using TEAMModelOS.SDK.Extension;
|
|
|
-using Microsoft.Extensions.Options;
|
|
|
-
|
|
|
-namespace TEAMModelOS.Controllers
|
|
|
-{
|
|
|
- [ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
- //[Authorize(Roles = "IES5")]
|
|
|
- [Route("common/volume")]
|
|
|
- [ApiController]
|
|
|
- public class VolumeController : ControllerBase
|
|
|
- {
|
|
|
- private readonly AzureCosmosFactory _azureCosmos;
|
|
|
- private readonly SnowflakeId _snowflakeId;
|
|
|
- private readonly DingDing _dingDing;
|
|
|
- private readonly Option _option;
|
|
|
-
|
|
|
- public VolumeController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing,IOptionsSnapshot<Option> option)
|
|
|
- {
|
|
|
- _azureCosmos = azureCosmos;
|
|
|
- _snowflakeId = snowflakeId;
|
|
|
- _dingDing = dingDing;
|
|
|
- _option = option?.Value; ;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 新增册别
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "Teacher")]
|
|
|
- [HttpPost("upsert")]
|
|
|
- public async Task<IActionResult> Upsert(Volume request)
|
|
|
- {
|
|
|
-
|
|
|
- /*try
|
|
|
- {
|
|
|
-
|
|
|
- //if (!requert.TryGetProperty("id_token", out JsonElement id_token)) return BadRequest();
|
|
|
- if (!requert.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- *//* var jwt = new JwtSecurityToken(id_token.GetString());
|
|
|
- if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
|
|
|
- var id = jwt.Payload.Sub;*//*
|
|
|
-
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- var response = await client.GetContainer("TEAMModelOSTemp", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Volume-{school_code}"));
|
|
|
-
|
|
|
- if (response.Status == 200)
|
|
|
- {
|
|
|
- //using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- return Ok(new { V = "该册别已经存在!" });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //如果沒有,Course信息存储
|
|
|
- requert.TryGetProperty("periodCode", out JsonElement periodCode);
|
|
|
- requert.TryGetProperty("subjectCode", out JsonElement subjectCode);
|
|
|
- requert.TryGetProperty("gradeCode", out JsonElement gradeCode);
|
|
|
- requert.TryGetProperty("semesterCode", out JsonElement semesterCode);
|
|
|
- requert.TryGetProperty("volumeName", out JsonElement volumeName);
|
|
|
- requert.TryGetProperty("volumeCode", out JsonElement volumeCode);
|
|
|
- requert.TryGetProperty("type", out JsonElement type);
|
|
|
- //jwt.Payload.TryGetValue("picture", out object picture);
|
|
|
- using var stream = new MemoryStream();
|
|
|
- using var writer = new Utf8JsonWriter(stream); //new JsonWriterOptions() { Indented = true }
|
|
|
- writer.WriteStartObject();
|
|
|
- if (type.ToJsonString().Equals("1"))
|
|
|
- {
|
|
|
- writer.WriteString("code", $"Volume-{id}");
|
|
|
- }
|
|
|
- else {
|
|
|
- writer.WriteString("code", $"Volume-{school_code}");
|
|
|
- }
|
|
|
- writer.WriteString("id", id.ToString());
|
|
|
- writer.WriteString("periodCode", periodCode.ToString());
|
|
|
- writer.WriteString("subjectCode", subjectCode.ToString());
|
|
|
- writer.WriteString("gradeCode", gradeCode.ToString());
|
|
|
- writer.WriteString("semesterCode", semesterCode.ToString());
|
|
|
- writer.WriteString("volumeName", volumeName.ToString());
|
|
|
- writer.WriteString("volumeCode", volumeCode.ToString());
|
|
|
- writer.WriteString("type", type.ToString());
|
|
|
- writer.WriteEndObject();
|
|
|
- writer.Flush();
|
|
|
- response = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOSTemp", "Common").CreateItemStreamAsync(stream, new PartitionKey($"Common-{school_code}"));
|
|
|
- if (response.Status == 200)
|
|
|
- {
|
|
|
- return Ok("保存成功!");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return Ok("保存失败!");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- await _dingDing.SendBotMsg($"CoreAPI2,{_option.Location},course/upsert()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
- return BadRequest();
|
|
|
- }*/
|
|
|
- Volume volume = new Volume();
|
|
|
- if (request.editors != null && request.editors.Count > 5)
|
|
|
- {
|
|
|
- return BadRequest("共编人数大于5人!");
|
|
|
- // throw new BizException("共编人数大于5人!");
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(request.id))
|
|
|
- {
|
|
|
- request.pk = typeof(Volume).Name;
|
|
|
- //request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
- if (request.type == 0)
|
|
|
- {
|
|
|
- /* List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName},
|
|
|
- { "status",1} ,{ "type",0} });*/
|
|
|
- List<Volume> volumesFind = new List<Volume>();
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = 1 and c.periodId = '{request.periodId}' and " +
|
|
|
- $"c.subjectId = '{request.subjectId}' and c.gradeId = '{request.gradeId}' and c.volumeName = '{request.volumeName}' " +
|
|
|
- $"and c.semesterId = '{request.semesterId}' and c.type = 0", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{request.code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- volumesFind.Add(obj.ToObject<Volume>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
- {
|
|
|
- //return BadRequest("已存在!"); //throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- return Ok(new { V = "已存在!", error = ResponseCode.DATA_EXIST });
|
|
|
- }
|
|
|
-
|
|
|
- //校本课纲
|
|
|
- string key = request.code + _snowflakeId.NextId();
|
|
|
- request.id = key;
|
|
|
- request.volumeCode = key;
|
|
|
- string code = request.code;
|
|
|
- //TODO 優化
|
|
|
- request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
- volume = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey($"Volume-{code}"));
|
|
|
- }
|
|
|
- else if (request.type == 1)
|
|
|
- {
|
|
|
- /*List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName},
|
|
|
- { "TEAMModelId",request.TEAMModelId}, { "status",1} ,{ "type",1} });*/
|
|
|
- List<Volume> volumesFind = new List<Volume>();
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = 1 and c.periodId = '{request.periodId}' and " +
|
|
|
- $"c.subjectId = '{request.subjectId}' and c.gradeId = '{request.gradeId}' and c.volumeName = '{request.volumeName}' " +
|
|
|
- $"and c.semesterId = '{request.semesterId}' and c.type = 1", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{request.code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- volumesFind.Add(obj.ToObject<Volume>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
- {
|
|
|
- //return BadRequest("已存在!"); //throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- return Ok(new { V = "已存在!", error = ResponseCode.DATA_EXIST });
|
|
|
- }
|
|
|
- //个人课纲
|
|
|
- string key = "dynamic" + request.TEAMModelId.Replace("#", "") + _snowflakeId.NextId();
|
|
|
- request.id = key;
|
|
|
- request.volumeCode = key;
|
|
|
- string code = request.code;
|
|
|
- request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
- volume = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(request, new PartitionKey($"Volume-{code}"));
|
|
|
- }
|
|
|
- else if (request.type == 2)
|
|
|
- {
|
|
|
- //系统课纲
|
|
|
- string key = "system" + _snowflakeId.NextId();
|
|
|
- request.code = "system";
|
|
|
- request.id = key;
|
|
|
- request.volumeCode = key;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (request.type == 0)
|
|
|
- {
|
|
|
- /* List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "code",request.code},{ "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName} ,
|
|
|
- { "status",1} ,{ "type",0} });*/
|
|
|
-
|
|
|
- List<Volume> volumesFind = new List<Volume>();
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = 1 and c.periodId = '{request.periodId}' and " +
|
|
|
- $"c.subjectId = '{request.subjectId}' and c.gradeId = '{request.gradeId}' and c.volumeName = '{request.volumeName}' " +
|
|
|
- $"and c.semesterId = '{request.semesterId}' and c.type = 0", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{request.code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- volumesFind.Add(obj.ToObject<Volume>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
-
|
|
|
- {
|
|
|
- if (!volumesFind[0].id.Equals(request.id))
|
|
|
- {
|
|
|
- //return BadRequest("已存在!"); //throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- return Ok(new { V = "已存在!", error = ResponseCode.DATA_EXIST });
|
|
|
- }
|
|
|
- }
|
|
|
- volume = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
- }
|
|
|
- else if (request.type == 1)
|
|
|
- {
|
|
|
- /* List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "code",request.code},{ "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName},
|
|
|
- { "TEAMModelId",request.TEAMModelId}, { "status",1} ,{ "type",1} });*/
|
|
|
- List<Volume> volumesFind = new List<Volume>();
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = 1 and c.periodId = '{request.periodId}' and " +
|
|
|
- $"c.subjectId = '{request.subjectId}' and c.gradeId = '{request.gradeId}' and c.volumeName = '{request.volumeName}' " +
|
|
|
- $"and c.semesterId = '{request.semesterId}' and c.type = 1", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{request.code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- volumesFind.Add(obj.ToObject<Volume>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
- {
|
|
|
- if (!volumesFind[0].id.Equals(request.id))
|
|
|
- {
|
|
|
- //return BadRequest("已存在!"); //throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- return Ok(new { V = "已存在!", error = ResponseCode.DATA_EXIST });
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else if (request.type == 2)
|
|
|
- {
|
|
|
- }
|
|
|
- volume = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
-
|
|
|
- }
|
|
|
- //request = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
- }
|
|
|
- /* List<Volume> volumes = new List<Volume>
|
|
|
- {
|
|
|
- request
|
|
|
- };
|
|
|
-
|
|
|
- List<Volume> volume = await _azureCosmos.SaveOrUpdateAll<Volume>(volumes);*/
|
|
|
- return Ok(new { volume });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 删除册别
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "Teacher")]
|
|
|
- [HttpPost("delete")]
|
|
|
- public async Task<IActionResult> Delete(JsonElement request)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
- if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (scope.ToString().Equals("school"))
|
|
|
- {
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Volume-{code}"));
|
|
|
- return Ok(new { code = response.Status });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Volume-{code}"));
|
|
|
- return Ok(new { code = response.Status });
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- return BadRequest();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /*ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
- bool flag = false;
|
|
|
- Volume volume = new Volume();
|
|
|
- if (!string.IsNullOrEmpty(request.id))
|
|
|
- {
|
|
|
- //if (request.@params.type == 0)
|
|
|
- //{
|
|
|
- request.status = 0;
|
|
|
-*//* List<Volume> volumes = new List<Volume>
|
|
|
- {
|
|
|
- request
|
|
|
- };*//*
|
|
|
- volume = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
- //await _azureCosmos.SaveOrUpdateAll<Volume>(volumes);
|
|
|
- flag = true;
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // await azureCosmosDBRepository.DeleteAsync<Volume>(request.@params.id, request.@params.schoolCode);
|
|
|
- // await azureCosmosDBRepository.DeleteAll<SyllabusNode>(new Dictionary<string, object>() { { "volumeCode", request.@params.id } });
|
|
|
- // flag = true;
|
|
|
- //}
|
|
|
- }
|
|
|
- return Ok(flag);*/
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 查找册别
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "Teacher")]
|
|
|
- [HttpPost("find")]
|
|
|
- public async Task<IActionResult> Find(JsonElement request)
|
|
|
- {
|
|
|
- /*ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
- List<Volume> volumes ;*/
|
|
|
- List<Syllabus> syllabuses = new List<Syllabus>();
|
|
|
- List<Volume> volumes = new List<Volume>();
|
|
|
- request.TryGetProperty("periodId", out JsonElement periodCode);
|
|
|
- request.TryGetProperty("subjectId", out JsonElement subjectCode);
|
|
|
- request.TryGetProperty("status", out JsonElement status);
|
|
|
- if (request.TryGetProperty("code", out JsonElement code))
|
|
|
- {
|
|
|
-
|
|
|
- request.TryGetProperty("type", out JsonElement type);
|
|
|
- if (type.GetInt32() == 1)
|
|
|
- {
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- syllabuses.Add(obj.ToObject<Syllabus>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = {status}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- volumes.Add(obj.ToObject<Volume>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- syllabuses.Add(obj.ToObject<Syllabus>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = {status} and c.periodId = '{periodCode}' and c.subjectId = '{subjectCode}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- volumes.Add(obj.ToObject<Volume>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //List<Syllabus> syllabuses = await _azureCosmos.FindByDict<Syllabus>(new Dictionary<string, object> { { "code", "Syllabus-"+code.ToString() } });
|
|
|
- //课纲
|
|
|
- //volumes = await _azureCosmos.FindByDict<Volume>(request);
|
|
|
- //处理单个册别下面的资源和题目
|
|
|
- volumes.ForEach(v => {
|
|
|
-
|
|
|
- HashSet<string> rCount = new HashSet<string>();
|
|
|
- HashSet<string> iCount = new HashSet<string>();
|
|
|
-
|
|
|
- syllabuses.ForEach(s => {
|
|
|
- if (v.volumeCode.Equals(s.id)) {
|
|
|
- s.children.ForEach(c => {
|
|
|
- if (c.resources.IsNotEmpty())
|
|
|
- {
|
|
|
- c.resources.ForEach(r => {
|
|
|
- rCount.Add(r);
|
|
|
- });
|
|
|
- }
|
|
|
- if (c.items.IsNotEmpty())
|
|
|
- {
|
|
|
- c.items.ForEach(i => {
|
|
|
- iCount.Add(i);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- v.resourceCount = rCount.Count;
|
|
|
- v.itemCount = iCount.Count;
|
|
|
- });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return BadRequest();
|
|
|
-
|
|
|
- }
|
|
|
- return Ok(new { volumes });
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 查找册别数量
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "Teacher")]
|
|
|
- [HttpPost("count")]
|
|
|
- public async Task<IActionResult> count(JsonElement request)
|
|
|
- {
|
|
|
- //List<List<List<List<int>>>> allCount = new List<List<List<List<int>>>>();
|
|
|
- ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
-
|
|
|
- List<List<List<int>>> sCount = new List<List<List<int>>>();
|
|
|
- if (StringHelper.getKeyCount(request) > 0) {
|
|
|
- request.TryGetProperty("code", out JsonElement code);
|
|
|
- //List<School> sc = await _azureCosmos.FindByDict<School>(request);
|
|
|
- List<School> sc = new List<School>();
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- //List<object> schools = new List<object>();
|
|
|
- var query = $"select c.id,c.pk,c.code, c.name,c.region,c.province,c.city,c.timeZone,c.picture,c.size,c.period,c.campuses from c where c.id ='{code}'";
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
-
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- sc.Add(obj.ToObject<School>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //查询校本所有册别数据
|
|
|
-/* Dictionary<string, object> scMap = new Dictionary<string, object>
|
|
|
- {
|
|
|
- { "status", 1}
|
|
|
- };*/
|
|
|
- //List<Volume> volumeo = await _azureCosmos.FindByDict<Volume>(scMap);
|
|
|
- List<Volume> volumeo = new List<Volume>();
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.status = 1 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{code}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- volumeo.Add(obj.ToObject<Volume>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (int i = 0; i < sc.Count; i++)
|
|
|
- {
|
|
|
- for (int j = 0; j < sc[i].period.Count; j++)
|
|
|
- {
|
|
|
- List<List<int>> pCount = new List<List<int>>();
|
|
|
- for (int k = 0; k < sc[i].period[j].subjects.Count; k++)
|
|
|
- {
|
|
|
- List<int> listCount = new List<int>() { 0, 0 };
|
|
|
- //查询校本册别
|
|
|
- //计数校本数量
|
|
|
- int n = 0;
|
|
|
- int s = 0;
|
|
|
- for (int m = 0; m < volumeo.Count; m++)
|
|
|
- {
|
|
|
- if (volumeo[m].type == 0 &&
|
|
|
- sc[i].period[j].id.Equals(volumeo[m].periodId) &&
|
|
|
- sc[i].period[j].subjects[k].id.Equals(volumeo[m].subjectId))
|
|
|
- {
|
|
|
- n++;
|
|
|
- }
|
|
|
- if (volumeo[m].type == 1 &&
|
|
|
- sc[i].period[j].id.Equals(volumeo[m].periodId) &&
|
|
|
- sc[i].period[j].subjects[k].id.Equals(volumeo[m].subjectId) && volumeo[m].TEAMModelId.Equals("habook#0001"))
|
|
|
- {
|
|
|
- s++;
|
|
|
- }
|
|
|
- }
|
|
|
- //册别数量
|
|
|
- listCount[0] = n;
|
|
|
- listCount[1] = s;
|
|
|
- pCount.Add(listCount);
|
|
|
- }
|
|
|
- sCount.Add(pCount);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return Ok(sCount);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- #region private
|
|
|
- /*
|
|
|
- public async Task<List<Volume>> SaveOrUpdateVolume(Volume request)
|
|
|
- {
|
|
|
- if (request.editors != null && request.editors.Count > 5)
|
|
|
- {
|
|
|
- throw new BizException("共编人数大于5人!");
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(request.id))
|
|
|
- {
|
|
|
- request.code = typeof(Volume).Name + "-" + request.code;
|
|
|
- if (request.type == 0)
|
|
|
- {
|
|
|
- List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName},
|
|
|
- { "status",1} ,{ "type",0} });
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
- {
|
|
|
- throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- }
|
|
|
- //校本课纲
|
|
|
- string key = request.code + _snowflakeId.NextId();
|
|
|
- request.id = key;
|
|
|
- request.volumeCode = key;
|
|
|
- }
|
|
|
- else if (request.type == 1)
|
|
|
- {
|
|
|
- List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName},
|
|
|
- { "TEAMModelId",request.TEAMModelId}, { "status",1} ,{ "type",1} });
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
- {
|
|
|
- throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- }
|
|
|
- //个人课纲
|
|
|
- string key = "dynamic" + request.TEAMModelId.Replace("#", "") + _snowflakeId.NextId();
|
|
|
- request.id = key;
|
|
|
- request.volumeCode = key;
|
|
|
- }
|
|
|
- else if (request.type == 2)
|
|
|
- {
|
|
|
- //系统课纲
|
|
|
- string key = "system" + _snowflakeId.NextId();
|
|
|
- request.code = "system";
|
|
|
- request.id = key;
|
|
|
- request.volumeCode = key;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (request.type == 0)
|
|
|
- {
|
|
|
- List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "code",request.code},{ "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName} ,
|
|
|
- { "status",1} ,{ "type",0} });
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
- {
|
|
|
- if (!volumesFind[0].id.Equals(request.id))
|
|
|
- {
|
|
|
- throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else if (request.type == 1)
|
|
|
- {
|
|
|
- List<Volume> volumesFind = await _azureCosmos.FindByDict<Volume>(new Dictionary<string, object>() {
|
|
|
- { "code",request.code},{ "periodCode", request.periodCode},
|
|
|
- { "subjectCode", request.subjectCode},{ "gradeCode", request.gradeCode},
|
|
|
- { "semesterCode",request.semesterCode},{ "volumeName",request.volumeName},
|
|
|
- { "TEAMModelId",request.TEAMModelId}, { "status",1} ,{ "type",1} });
|
|
|
- if (volumesFind.IsNotEmpty())
|
|
|
- {
|
|
|
- if (!volumesFind[0].id.Equals(request.id))
|
|
|
- {
|
|
|
- throw new BizException("已存在!", ResponseCode.DATA_EXIST);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else if (request.type == 2)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- List<Volume> volumes = new List<Volume>
|
|
|
- {
|
|
|
- request
|
|
|
- };
|
|
|
- List<Volume> volume = await _azureCosmos.SaveOrUpdateAll<Volume>(volumes);
|
|
|
- return volume;
|
|
|
- }
|
|
|
-
|
|
|
- */
|
|
|
- #endregion
|
|
|
- }
|
|
|
-}
|