Kaynağa Gözat

答题卡数据保存

CrazyIter_Bin 3 yıl önce
ebeveyn
işleme
b507a12e4f

+ 62 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/SheetConfig.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.Common
+{
+    public class SheetConfig :CosmosEntity
+    {
+        public string school { get; set; }
+        public string creatorId { get; set; }
+        public string scope { get; set; }
+
+        /// <summary>
+        ///  //列数
+        /// </summary>
+        public int columns { get; set; }
+        /// <summary>
+        /// 页面大小(回字组成的)
+        /// </summary>
+        public int pageWidth { get; set; }
+        /// <summary>
+        /// 页面大小(回字组成的)
+        /// </summary>
+        public int pageHeight { get; set; }
+        /// <summary>
+        /// 页码块数量
+        /// </summary>
+        public int pageNumBlockCount { get; set; }
+        /// <summary>
+        /// 页码起始值, 起始是3个空格方块开始,写1; 2个空格1个实心,写0
+        /// </summary>
+        public int pageNumStartValue { get; set; }
+        /// <summary>
+        /// 二值化区间(pc)-->不同扫描仪的结果图像数据有差距, 按需调整
+        /// </summary>
+        public List<int> threshValue { get; set; } = new List<int> { 190, 220, 10 };
+        /// <summary>
+        /// 二值化区间(手机)
+        /// </summary>
+        public List<int> threshValuePhone { get; set; } = new List<int> { 190, 220, 10 };
+        /// <summary>
+        /// 单个整体回字大小
+        /// </summary>
+        public int huiSize { get; set; } = 70;
+        /// <summary>
+        /// 最小回字的大小比列, 以回字最中间的方块为最小
+        /// </summary>
+        public double minHuiSize { get; set; } = 0.005;
+        /// <summary>
+        /// 最大回字的大小比列, 以回字最外层的方块为最大
+        /// </summary>
+        public double maxHuiSize { get; set; } = 0.1;
+        /// <summary>
+        /// 不检测回字区域(pc版辅助效果20%, 手机版50%)
+        /// </summary>
+        public List<double> notHuisRect { get; set; } = new List<double> { 0.3, 0.3, 0.4, 0.4 };
+        /// <summary>
+        /// 内容块 vblockCount为该模块竖向的方块数 hblockCount为该模块横向方块数
+        /// </summary>
+        public List<ConfigContent> contents { get; set; }
+    }
+}

+ 4 - 54
TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

@@ -72,7 +72,7 @@ namespace TEAMModelOS.SDK.Models
         public PeriodSimple period { get; set; }
         public List<Grade> grades { get; set; }
         public List<ExamSubject> subjects { get; set; }
-        //public long sequenceNumber { get; set; }
+        public List<string>   sheet { get; set; }        //public long sequenceNumber { get; set; }
         //public Condition conditions { get; set; }
         //public List<string> blobUrl { get; set; }
         public string progress { get; set; }
@@ -106,7 +106,7 @@ namespace TEAMModelOS.SDK.Models
         public string id { get; set; }
         public string name { get; set; }
         public int classCount { get; set; }
-
+       
 
     }
     public class PaperSimple { 
@@ -125,60 +125,10 @@ namespace TEAMModelOS.SDK.Models
         public List<int> field { get; set; } = new List<int>();
 
         //public List<Dictionary<string, int>> record { get; set; } = new List<Dictionary<string, int>>();
-        public SheetConfig sheet { get; set; } 
+      
     }
 
-    public class SheetConfig
-    {
-        /// <summary>
-        ///  //列数
-        /// </summary>
-        public int columns { get; set; }
-        /// <summary>
-        /// 页面大小(回字组成的)
-        /// </summary>
-        public int pageWidth { get; set; }
-        /// <summary>
-        /// 页面大小(回字组成的)
-        /// </summary>
-        public int pageHeight { get; set; }
-        /// <summary>
-        /// 页码块数量
-        /// </summary>
-        public int pageNumBlockCount { get; set; }
-        /// <summary>
-        /// 页码起始值, 起始是3个空格方块开始,写1; 2个空格1个实心,写0
-        /// </summary>
-        public int pageNumStartValue { get; set; }
-        /// <summary>
-        /// 二值化区间(pc)-->不同扫描仪的结果图像数据有差距, 按需调整
-        /// </summary>
-        public List<int> threshValue { get; set; } = new List<int> { 190,220,10};
-        /// <summary>
-        /// 二值化区间(手机)
-        /// </summary>
-        public List<int> threshValuePhone { get; set; }=new List<int> { 190,220,10};
-        /// <summary>
-        /// 单个整体回字大小
-        /// </summary>
-        public int huiSize { get; set; } = 70;
-        /// <summary>
-        /// 最小回字的大小比列, 以回字最中间的方块为最小
-        /// </summary>
-        public double minHuiSize { get; set; } = 0.005;
-        /// <summary>
-        /// 最大回字的大小比列, 以回字最外层的方块为最大
-        /// </summary>
-        public double maxHuiSize { get; set; } = 0.1;
-        /// <summary>
-        /// 不检测回字区域(pc版辅助效果20%, 手机版50%)
-        /// </summary>
-        public List<double> notHuisRect { get; set; } = new List<double> { 0.3, 0.3, 0.4, 0.4 };
-        /// <summary>
-        /// 内容块 vblockCount为该模块竖向的方块数 hblockCount为该模块横向方块数
-        /// </summary>
-        public List<ConfigContent> contents { get; set; }
-    }
+   
 
     public class ConfigContent {
         public int type { get; set; }

+ 198 - 0
TEAMModelOS/Controllers/Common/SheetConfigController.cs

@@ -0,0 +1,198 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.IdentityModel.Tokens.Jwt;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Models.Dto;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.Context.Constant.Common;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Helper.Common.StringHelper;
+using TEAMModelOS.Models;
+using Microsoft.Extensions.Options;
+using TEAMModelOS.SDK.Models.Cosmos;
+using Microsoft.AspNetCore.Authorization;
+using TEAMModelOS.Filter;
+using StackExchange.Redis;
+using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
+using TEAMModelOS.Services.Common;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+using Azure;
+
+namespace TEAMModelOS.Controllers.Common
+{
+    [ProducesResponseType(StatusCodes.Status200OK)]
+    [ProducesResponseType(StatusCodes.Status400BadRequest)]
+    //[Authorize(Roles = "IES5")]
+    [Route("common/sheet-config")]
+    [ApiController]
+    public class SheetConfigController : ControllerBase
+    {
+        private readonly AzureRedisFactory _azureRedis;
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly SnowflakeId _snowflakeId;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureStorageFactory _azureStorage;
+        public SheetConfigController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option,
+            AzureRedisFactory azureRedis, AzureStorageFactory azureStorage)
+        {
+            _azureCosmos = azureCosmos;
+            _serviceBus = serviceBus;
+            _snowflakeId = snowflakeId;
+            _dingDing = dingDing;
+            _option = option?.Value;
+            _azureRedis = azureRedis;
+            _azureStorage = azureStorage;
+        }
+
+        /// <summary>
+        ///查询答题卡
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("find")]
+        public async Task<IActionResult> Find(JsonElement request) {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                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();
+                if ($"{scope}" == "school")
+                {
+                    SheetConfig config = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<SheetConfig>($"{id}", new PartitionKey($"SheetConfig-{code}"));
+                    return Ok(new { config = config, status = 200 });
+                }
+                else
+                {
+                    SheetConfig config = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<SheetConfig>($"{id}", new PartitionKey($"SheetConfig-{code}"));
+                    return Ok(new { config = config,status=200 });
+                }
+            }
+            catch (CosmosException e)
+            {
+                return Ok(new { status = e.Response.Status });
+            }
+            catch (Exception ex) {
+
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/SheetConfig/upsert()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest(e.StackTrace);
+            }
+        }
+        /// <summary>
+        /// 新增 或 修改答题卡
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("upsert")]
+        public async Task<IActionResult> Upsert(SheetConfig request)
+        {
+            try
+            {
+                
+                var client = _azureCosmos.GetCosmosClient();
+                request.pk = $"SheetConfig";
+                request.code = $"SheetConfig-{request.code}";
+                request.ttl = -1;
+                if (string.IsNullOrEmpty(request.id))
+                {
+                    int id=  Utils.CreatSaltInt(9999999);
+                    for (int i = 0; i < 10; i++)
+                    {
+                        Response response = null;
+                        if (request.scope == "school")
+                        {
+                              response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{id}", new PartitionKey($"{request.code}"));
+                        }
+                        else {
+                              response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey($"{request.code}"));
+                        }
+                        if (response.Status == 404)
+                        {
+                            break;
+                        }
+                        else {
+                            if (i == 9)
+                            {
+                                await _dingDing.SendBotMsg($"OS,{_option.Location},common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次", GroupNames.醍摩豆服務運維群組);
+                                return BadRequest();
+                            }
+                            else {
+                                id = Utils.CreatSaltInt(9999999);
+                            }
+                        }
+                         
+                    }
+                    request.id = $"{id}";
+                    if (request.scope == "school")
+                    {
+                        request = await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
+                    }
+                    else {
+                        request = await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(request, new PartitionKey($"{request.code}"));
+                    }
+                }
+                else
+                {
+                    if (request.scope == "school")
+                    {
+                        request = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
+                    }
+                    else
+                    {
+                        request = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
+                    }
+                 }
+                return Ok(new { config = request });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/SheetConfig/upsert()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest(e.StackTrace);
+            }
+        }
+        /// <summary>
+        ///删除答题卡
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("delete")]
+        public async Task<IActionResult> Delete(JsonElement request)
+        {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                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();
+                if ($"{scope}" == "school")
+                {
+                    await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync( $"{id}", new PartitionKey($"{code}"));
+                }
+                else {
+                    await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync($"{id}", new PartitionKey($"{code}"));
+                }
+                return Ok(new { status=200  });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/SheetConfig/delete()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest(e.StackTrace);
+            }
+        }
+    }
+}

+ 8 - 4
TEAMModelOS/Controllers/School/StudentController.cs

@@ -108,8 +108,9 @@ namespace TEAMModelOS.Controllers
                         return this.Ok(new { code = $"Base-{schoolId.GetString()}", ids = sucDelIds });
                     case "remove":
                         //將學生基本資料內的classId、no、groupId及groupName寫入null
-                        var retRemove = removeStudentClassInfo(schoolId.GetString(), request.GetProperty("students").EnumerateArray());
-                        return this.Ok(new { code = $"Base-{schoolId.GetString()}", ids = retRemove.Result.studs, retRemove.Result.nonexistentIds, retRemove.Result.errorIds });
+                       ( List<string> studs, List< string > nonexistentIds, List<string> errorIds) retRemove = await removeStudentClassInfo(schoolId.GetString(), request.GetProperty("students").EnumerateArray());
+                       
+                        return  Ok(new { code = $"Base-{schoolId.GetString()}", ids = retRemove.studs, retRemove.nonexistentIds, retRemove.errorIds });
                     default:
                         return BadRequest();
                 }
@@ -1099,6 +1100,7 @@ namespace TEAMModelOS.Controllers
                         writer.WriteStartObject();
                         foreach (var element in doc.EnumerateObject())
                         {
+                            Console.WriteLine(element.ToJsonString());
                             //將教室相關欄位清空
                             switch (true)
                             {
@@ -1124,6 +1126,7 @@ namespace TEAMModelOS.Controllers
                         writer.WriteEndObject();
                         writer.Flush();
 
+                        Console.WriteLine(1111);
                         var ret = await _azureCosmos
                                   .GetCosmosClient()
                                   .GetContainer("TEAMModelOS", "Student")
@@ -1141,14 +1144,15 @@ namespace TEAMModelOS.Controllers
                                 $"IES5,{_option.Location},StudentController/removeStudentClassInfo(),CosmosDB response:{ret.Status}\nBase-{schoolId},id:{id}",
                                 GroupNames.醍摩豆服務運維群組);
                         }
+                        Console.WriteLine(2222);
                     }
                 }
             }
-
+            Console.WriteLine(333);
             //將impStuds內的資料移除sucStuds及errorIds,所得的結果就是不存在於資料庫的id。
             sucStuds.ForEach(o => impStuds.Remove(o));
             errorIds.ForEach(o => impStuds.Remove(o));
-
+            Console.WriteLine(444);
             return (sucStuds, impStuds, errorIds);
         }