|
@@ -0,0 +1,190 @@
|
|
|
+using Azure.Cosmos;
|
|
|
+using DocumentFormat.OpenXml.Drawing.Charts;
|
|
|
+using HTEXLib.COMM.Helpers;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using OpenXmlPowerTools;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Reflection;
|
|
|
+using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using TEAMModelOS.SDK.Services;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers
|
|
|
+{
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 学生五育画像接口
|
|
|
+ /// </summary>
|
|
|
+ [Route("overall-education")]
|
|
|
+ [ApiController]
|
|
|
+ public class OverallEducationController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly SnowflakeId _snowflakeId;
|
|
|
+
|
|
|
+ public OverallEducationController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, DingDing dingDing, CoreAPIHttpService coreAPIHttpService, IOptionsSnapshot<Option> option, IConfiguration configuration, SnowflakeId snowflakeId)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _configuration = configuration;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _snowflakeId = snowflakeId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取看板的基本条件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("overview-cond")]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ public async Task<IActionResult> OverviewCond(JsonElement json)
|
|
|
+ {
|
|
|
+ json.TryGetProperty("schoolId", out JsonElement schoolId);
|
|
|
+ json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ StringBuilder classsql = new StringBuilder($"SELECT count(1) FROM c where ( c.graduate = 0 or IS_DEFINED(c.graduate) = false )");
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ {
|
|
|
+ classsql.Append($" and c.periodId='{periodId}' ");
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: classsql.ToString(),
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+ [HttpPost("overview")]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ public async Task<IActionResult> Overview(JsonElement json)
|
|
|
+ {
|
|
|
+ json.TryGetProperty("schoolId", out JsonElement schoolId);
|
|
|
+ json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ StringBuilder classsql = new StringBuilder($"SELECT count(1) FROM c where ( c.graduate = 0 or IS_DEFINED(c.graduate) = false )");
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ {
|
|
|
+ classsql.Append($" and c.periodId='{periodId}' ");
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: classsql.ToString(),
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+
|
|
|
+{
|
|
|
+ "grades": [
|
|
|
+ 0,1
|
|
|
+ ],
|
|
|
+ "periodId": "463db08d-cbe7-48a0-a81a-fc39b3c1fep1",
|
|
|
+ "school": "hbcn",
|
|
|
+ "classIds": [
|
|
|
+ "e1729a0c-0e7c-4968-bec9-21254b70325b",
|
|
|
+ "b44694b7-4cb2-46b8-8986-106696c4a282"
|
|
|
+ ]
|
|
|
+}
|
|
|
+
|
|
|
+ */
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// school
|
|
|
+ /// periodId
|
|
|
+ /// classIds
|
|
|
+ /// grades
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("overview-base")]
|
|
|
+#if !DEBUG
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+#endif
|
|
|
+ public async Task<IActionResult> OverviewBase(JsonElement json) {
|
|
|
+ json.TryGetProperty("grades", out JsonElement _grades);
|
|
|
+ json.TryGetProperty("school", out JsonElement _school);
|
|
|
+ json.TryGetProperty("periodId", out JsonElement _periodId);
|
|
|
+ json.TryGetProperty("semesterId", out JsonElement _semesterId);
|
|
|
+ json.TryGetProperty("year", out JsonElement _year);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_school}", new PartitionKey("Base"));
|
|
|
+ Dictionary<string, object> dict = OverallEducationService.GetQueryCond(json);
|
|
|
+#region 此处代码用于处理 根据年级 学段获取 相关的班级。
|
|
|
+ List<int > years = null ;
|
|
|
+ if (_grades.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
+ var yearsdata = SchoolService.GetYears(school, $"{_periodId}", _grades.ToObject<List<int>>());
|
|
|
+ years= yearsdata.years.ToList();
|
|
|
+ }
|
|
|
+ if (!years.IsNotEmpty()) {
|
|
|
+ var period = school.period.Find(z => z.id.Equals($"{_periodId}"));
|
|
|
+ if (period != null && period.grades.IsNotEmpty())
|
|
|
+ {
|
|
|
+ List<int> grades = new List<int>();
|
|
|
+ period.grades.Select((z, index) => index).ToList().ForEach(t => { grades.Add(t); });
|
|
|
+ var yearsdata = SchoolService.GetYears(school, $"{_periodId}", grades);
|
|
|
+ years = yearsdata.years.ToList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Class> classes = new List<Class>();
|
|
|
+ if (years.IsNotEmpty()) {
|
|
|
+ List<string> classIds = null;
|
|
|
+ if (json.TryGetProperty("classIds", out JsonElement _classIds)) {
|
|
|
+ classIds = _classIds.ToObject<List<string>>();
|
|
|
+ }
|
|
|
+ StringBuilder sql =new StringBuilder($"select value c from c where c.year in ({string.Join(",", years)}) and c.periodId='{_periodId}' ");
|
|
|
+ if (classIds.IsNotEmpty()) {
|
|
|
+ sql.Append($" and c.id in ({string.Join(",",classIds.Select(z=>$"'{z}'"))})");
|
|
|
+ }
|
|
|
+
|
|
|
+ var result= await client.GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Class>(sql.ToString(),$"Class-{_school}");
|
|
|
+ classes= result.list;
|
|
|
+ }
|
|
|
+#endregion
|
|
|
+ StringBuilder studentCountSQL =new StringBuilder("select value count(1) from c ");
|
|
|
+ AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, studentCountSQL);
|
|
|
+ //获取未毕业的学生。
|
|
|
+ cosmosDbQuery.QueryText.Replace("where", "where ( c.graduate = 0 or IS_DEFINED(c.graduate) = false)");
|
|
|
+ if (classes.IsNotEmpty()) {
|
|
|
+ //处理班级信息
|
|
|
+ cosmosDbQuery.QueryText= cosmosDbQuery.QueryText.Replace("where", $"where c.classId in ({string.Join(",", classes.Select(z => $"'{z.id}'"))}) and ");
|
|
|
+ }
|
|
|
+ var data = await client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<int>(cosmosDbQuery.CosmosQueryDefinition, $"Base-{_school}");
|
|
|
+ int studentCount = data.list.First();
|
|
|
+
|
|
|
+ string oesql = $"select value c from c where c.semesterId='{_semesterId}' and c.year={_year} and c.periodId='{_periodId}' " +
|
|
|
+ $"and c.classId in {string.Join(",",classes.Select(z=>$"'{z}'"))} ";
|
|
|
+ return Ok(new { studentCount ,classCount=classes.Count, grade=years.Count });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|