Browse Source

Merge branch 'develop5.0-tmd' of http://106.12.23.251:10080/TEAMMODEL/TEAMModelOS into develop5.0-tmd

liqk 4 years ago
parent
commit
de01ba9259

+ 16 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Class.cs

@@ -10,6 +10,9 @@ using TEAMModelOS.SDK.DI;
 
 namespace TEAMModelOS.SDK.Models
 {    
+    /// <summary>
+    /// 班级
+    /// </summary>
     public class Class : CosmosEntity
     {
         public Class()
@@ -19,15 +22,27 @@ namespace TEAMModelOS.SDK.Models
             //students = new List<StudentSimple>();
         }
         /// <summary>
-        /// 教室编号
+        /// 班级编号
         /// </summary>
         public string no { get; set; }
 
        // public float? x { get; set; }
        // public float? y { get; set; }
+       /// <summary>
+       /// 班级名称
+       /// </summary>
         public string name { get; set; }
+        /// <summary>
+        /// 教师
+        /// </summary>
         public Teachers teacher { get; set; }
+        /// <summary>
+        /// 学段
+        /// </summary>
         public string periodId { get; set; }
+        /// <summary>
+        /// 年级
+        /// </summary>
         public string gradeId { get; set; }
         //public string sn { get; set; }
         /// <summary>

+ 17 - 2
TEAMModelOS.SDK/Models/Cosmos/School/Room.cs

@@ -5,11 +5,18 @@ using System.Text;
 namespace TEAMModelOS.SDK.Models.Cosmos.School
 {
     /// <summary>
-    /// 教室
+    /// 教室,只存在于学校。
     /// </summary>
     public class Room : CosmosEntity
     {
+        public Room(){
+            pk = "Room";
+        }
         public string name { get; set; }
+        /// <summary>
+        /// 教室编号
+        /// </summary>
+        public string no { get; set; }
         public float? x { get; set; }
         public float? y { get; set; }
         public string sn { get; set; }
@@ -17,6 +24,14 @@ namespace TEAMModelOS.SDK.Models.Cosmos.School
         /// 教室属性,普通 /专设的教室
         /// </summary>
         public string openType { get; set; }
-        public string scope { get; set; }
+       // public string scope { get; set; }
+        /// <summary>
+        /// TBL IRS 类型区分
+        /// </summary>
+        public string style { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string area { get; set; }
     }
 }

+ 2 - 2
TEAMModelOS/Controllers/School/ClassRoomController.cs

@@ -23,12 +23,12 @@ namespace TEAMModelOS.Controllers
     //[Authorize(Roles = "IES5")]
     [Route("school/classroom")]
     [ApiController]
-    public class ClassroomController : ControllerBase
+    public class ClassController : ControllerBase
     {
         public readonly AzureCosmosFactory _azureCosmos;
         private readonly Option _option;
         private readonly DingDing _dingDing;
-        public ClassroomController(AzureCosmosFactory azureCosmos, DingDing dingDing,
+        public ClassController(AzureCosmosFactory azureCosmos, DingDing dingDing,
             IOptionsSnapshot<Option> option)
         {
             _azureCosmos = azureCosmos;

+ 168 - 0
TEAMModelOS/Controllers/School/RoomController.cs

@@ -0,0 +1,168 @@
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models.Cosmos.School;
+
+namespace TEAMModelOS.Controllers.School
+{
+    [Route("school/room")]
+    [ApiController]
+    public class RoomController : ControllerBase
+    {
+        public readonly AzureCosmosFactory _azureCosmos;
+        private readonly Option _option;
+        private readonly DingDing _dingDing;
+        public RoomController(AzureCosmosFactory azureCosmos, DingDing dingDing,
+            IOptionsSnapshot<Option> option)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _option = option?.Value;
+        }
+        /// <summary>
+        /// {
+        ///     "id":"教室id,新增时为空","code":"学校编码hbcn","name":"教室名称","no":"编号","x":坐标x,"y":坐标y,
+        ///     "sn":"序列号","openType":"1  教室属性,普通 /专设的教室","style":"TBL IRS 类型区分","area":"教学区,第一教学楼...."
+        /// }
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "Teacher")]
+        [HttpPost("upsert")]
+        public async ValueTask<IActionResult> Upsert(Room request) {
+
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                request.pk = "Room";
+                request.code = request.pk + "-" + request.code;
+                request.ttl = -1;
+                if (string.IsNullOrEmpty(request.id))
+                {
+
+                    request.id = Guid.NewGuid().ToString();
+                    request = await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
+                }
+                else {
+                    var response = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
+                    if (response.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                        var info = json.ToObject<Room>();
+                        request = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(request, info.id, new PartitionKey($"{info.code}"));
+                    }
+                    else
+                    {
+                        request = await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
+                    }
+                }
+                return Ok(new { romm= request });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/save()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+        /// <summary>
+        /// {"code":"hbcn学校编码"} 
+        /// </summary>
+        /// <param name="requert"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "Teacher")]
+        [HttpPost("find")]
+        public async Task<IActionResult> Find(JsonElement request)
+        {
+            try
+            {
+                if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
+                var client = _azureCosmos.GetCosmosClient();
+                var item = client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Room>(queryText: $"select value(c) from c ",
+                requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Room-{code}") });
+                return Ok(new { rooms= item });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},school/room/find()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+        /// <summary>
+        /// {"id":"教室id","code":"hbcn学校编码"} 
+        /// </summary>
+        /// <param name="requert"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("find-id")]
+        public async Task<IActionResult> FindById(JsonElement requert)
+        {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                //id
+                if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                //
+                if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                Room room = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Room>(id.GetString(), new PartitionKey($"Room-{code}"));
+                if (room != null)
+                {
+
+                    return Ok(new { room });
+                }
+                else
+                {
+                    return BadRequest("id,code不存在!");
+                }
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},school/room/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+        /// <summary>
+        /// {"id":"教室id","code":"hbcn学校编码"} 
+        /// </summary>
+        /// <param name="requert"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("delete")]
+        public async Task<IActionResult> Delete(JsonElement requert)
+        {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                //id
+                if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                //
+                if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                Room room = await client.GetContainer("TEAMModelOS", "School").DeleteItemAsync<Room>(id.GetString(), new PartitionKey($"Room-{code}"));
+                if (room != null)
+                {
+
+                    return Ok(new { room });
+                }
+                else
+                {
+                    return BadRequest("id,code不存在!");
+                }
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},school/room/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+    }
+}

+ 34 - 0
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -36,6 +36,40 @@ namespace TEAMModelOS.Controllers
             _dingDing = dingDing;
             _option = option?.Value; ;
         }
+
+        /// <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();
+            }
+        }
+
         /// <summary>
         /// 查找册别
         /// </summary>