Browse Source

Merge branch 'TPE/develop' into TPE/feat/classroomManage

osbert 4 years ago
parent
commit
15e7953040

+ 185 - 0
TEAMModelOS/Controllers/School/SchoolController.cs

@@ -16,6 +16,11 @@ using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.Options;
 using System.IO;
 using System.Dynamic;
+using TEAMModelOS.SDK.Context.Configuration;
+using System.Net.Http;
+using System.Net;
+using Newtonsoft.Json;
+using System.Linq;
 
 namespace TEAMModelOS.Controllers
 {
@@ -223,5 +228,185 @@ namespace TEAMModelOS.Controllers
             }
             return Ok(new { periods, grades, classes });
         }
+
+        /// <summary>
+        /// 取得某學校產品資料 
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-school-product")]
+        public async Task<IActionResult> GetSchoolProductInfo(JsonElement request)
+        {
+            if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
+
+            var client = _azureCosmos.GetCosmosClient();
+            List<SerialInfo> serial = new List<SerialInfo>();
+            List<object> service = new List<object>();
+            List<object> hard = new List<object>();
+            List<object> uuidList = new List<object>(); //要向CoreService詢問deviceID及硬體資訊的UUID列表
+            var response = await client.GetContainer("TEAMModelOSTemp", "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Product"));
+            if (response.Status == 200)
+            {
+                var json = await JsonDocument.ParseAsync(response.ContentStream);
+                if (json.RootElement.TryGetProperty("serial", out JsonElement serialJobj))
+                {
+                    foreach (var serialInfo in serialJobj.EnumerateArray())
+                    {
+                        serial.Add(serialInfo.ToObject<SerialInfo>());
+                        serialInfo.TryGetProperty("deviceBound", out JsonElement deviceBoundJobj);
+                        foreach (var deviceBoundRow in deviceBoundJobj.EnumerateArray())
+                        {
+                            dynamic uuidExtobj = new ExpandoObject();
+                            uuidExtobj.serial = serialInfo.GetProperty("serial");
+                            uuidExtobj.uuid = deviceBoundRow.GetProperty("uuid");
+                            uuidExtobj.uuid2 = deviceBoundRow.GetProperty("uuid2");
+                            uuidExtobj.deviceId = deviceBoundRow.GetProperty("deviceId");
+                            uuidList.Add(uuidExtobj);
+                        }
+                    }
+                }
+
+                if (json.RootElement.TryGetProperty("service", out JsonElement serviceJobj))
+                {
+                    service.Add(serviceJobj.ToObject<object>());
+                }
+
+                if (json.RootElement.TryGetProperty("hard", out JsonElement hardJobj))
+                {
+                    hard.Add(hardJobj.ToObject<object>());
+                }
+
+                //取得DeviceInfo From Core [先做假的,之後再對接]
+                List<object> serialResult = new List<object>();
+                List<CoreUuid> coreUuidList = (List<CoreUuid>)GetDeviceFromCore(uuidList);
+                foreach (SerialInfo serialRow in serial)
+                {
+                    var deviceBoundArray = new List<deviceBoundExt>();
+                    List<CoreUuid> coreUuid = coreUuidList
+                           .Where((CoreUuid x) => x.serial == serialRow.serial)
+                           .ToList();
+                    foreach (CoreUuid deviceRow in coreUuid)
+                    {
+                        deviceBoundExt deviceBoundRow = new deviceBoundExt();
+                        deviceBoundRow.uuid = deviceRow.uuid;
+                        deviceBoundRow.uuid2 = deviceRow.uuid2;
+                        deviceBoundRow.os = deviceRow.os;
+                        deviceBoundRow.deviceId = deviceRow.deviceId;
+                        deviceBoundRow.ip = deviceRow.ip;
+                        deviceBoundRow.cpu = deviceRow.cpu;
+                        deviceBoundRow.pcname = deviceRow.pcname;
+                        deviceBoundRow.ram = deviceRow.ram;
+                        deviceBoundArray.Add(deviceBoundRow);
+                    }
+                    serialRow.deviceBound = deviceBoundArray;
+                }
+
+
+            }
+
+
+
+            return Ok(new { serial, service, hard });
+        }
+
+        /// <summary>
+        /// 取得CoreDevice資訊
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        private List<CoreUuid> GetDeviceFromCore(List<object> uuidList)
+        {
+            List<CoreUuid> list = new List<CoreUuid>();
+            try
+            {
+                //string url = BaseConfigModel.Configuration["HaBookAuth:CoreId:userinfo"];
+                //HttpClient client = new HttpClient();
+                //var content = new StringContent(JsonConvert.SerializeObject(uuidList), Encoding.UTF8, "application/json");
+                //HttpResponseMessage responseMessage = await client.PostAsync(url, content);
+                //if (responseMessage.StatusCode == HttpStatusCode.OK)
+                //{
+                //    string responseBody = responseMessage.Content.ReadAsStringAsync().Result;
+                //    return Ok(responseBody);
+                //}
+                //else
+                //{
+                //    return BadRequest();
+                //}
+
+                CoreUuid CoreUuid1 = new CoreUuid();
+                CoreUuid1.serial = "3222IAVN-H4RS-VF5L-YSCJ-ZXYW";
+                CoreUuid1.uuid = "3C970E5CD649";
+                CoreUuid1.uuid2 = "E006E6CE1D28";
+                CoreUuid1.deviceId = "2d776529-ac7b-4197-b981-3ae3370fe686";
+                CoreUuid1.ip = "171.216.152.131";
+                CoreUuid1.pcname = "ONLY-PC";
+                CoreUuid1.os = "Microsoft Windows NT 6.1.7601 Service Pack 1";
+                CoreUuid1.cpu = "Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz";
+                CoreUuid1.ram = 3287;
+                list.Add(CoreUuid1);
+                CoreUuid CoreUuid2 = new CoreUuid();
+                CoreUuid2.serial = "3222IAVN-8MKL-9N6F-C14T-QK39";
+                CoreUuid2.uuid = "000C2909298F";
+                CoreUuid2.uuid2 = null;
+                CoreUuid2.deviceId = "a5b21a8d-b204-40f4-b28b-c7df34cda0a9";
+                CoreUuid2.ip = "182.148.142.235";
+                CoreUuid2.pcname = null;
+                CoreUuid2.os = "Microsoft Windows NT 6.1.7601 Service Pack 1";
+                CoreUuid2.cpu = "Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz";
+                CoreUuid2.ram = 6143;
+                list.Add(CoreUuid2);
+                CoreUuid CoreUuid3 = new CoreUuid();
+                CoreUuid3.serial = "12DLT43F-BTXK-W65T-9P6J-DVAR";
+                CoreUuid3.uuid = null;
+                CoreUuid3.uuid2 = "A483E742B0FF";
+                CoreUuid3.deviceId = "efb9adc2-0713-401a-8f17-46129cf3b849";
+                CoreUuid3.ip = "110.185.29.13";
+                CoreUuid3.pcname = "DESKTOP-D4OMD85";
+                CoreUuid3.os = "Microsoft Windows NT 10.0.18362.0";
+                CoreUuid3.cpu = "Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz";
+                CoreUuid3.ram = 8036;
+                list.Add(CoreUuid3);
+                CoreUuid CoreUuid4 = new CoreUuid();
+                CoreUuid4.serial = "12DLT43F-TOGN-OGVR-MYVR-6PSA";
+                CoreUuid4.uuid = "94C691231A5F";
+                CoreUuid4.uuid2 = null;
+                CoreUuid4.deviceId = "a4c0bf19-db01-4f3c-8d1e-f3074476349f";
+                CoreUuid4.ip = "118.114.15.247";
+                CoreUuid4.pcname = "PC-201909100955";
+                CoreUuid4.os = "Microsoft Windows NT 10.0.14393.0";
+                CoreUuid4.cpu = "Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz";
+                CoreUuid4.ram = 16291;
+                list.Add(CoreUuid4);
+                CoreUuid CoreUuid5 = new CoreUuid();
+                CoreUuid5.serial = "12DLT43F-TOGN-OGVR-MYVR-6PSA";
+                CoreUuid5.uuid = "D8CB8A780144";
+                CoreUuid5.uuid2 = null;
+                CoreUuid5.deviceId = "699c8847-f9cd-4f8d-9799-2f5555e46e34";
+                CoreUuid5.ip = "183.220.92.210";
+                CoreUuid5.pcname = "USER-20180716GZ";
+                CoreUuid5.os = "Microsoft Windows NT 10.0.17134.0";
+                CoreUuid5.cpu = "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz";
+                CoreUuid5.ram = 16287;
+                list.Add(CoreUuid5);
+                CoreUuid CoreUuid6 = new CoreUuid();
+                CoreUuid6.serial = "12DLT43F-TOGN-OGVR-MYVR-6PSA";
+                CoreUuid6.uuid = null;
+                CoreUuid6.uuid2 = "C49DED0BB2A9";
+                CoreUuid6.deviceId = "44af0c54-7927-4a26-8503-9dcb62272e95";
+                CoreUuid6.ip = "118.114.15.247";
+                CoreUuid6.pcname = "DESKTOP-S4JOQCB";
+                CoreUuid6.os = "Microsoft Windows NT 10.0.18362.0";
+                CoreUuid6.cpu = "Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz";
+                CoreUuid6.ram = 4021;
+                list.Add(CoreUuid6);
+
+                return list;
+            }
+            catch (Exception ex)
+            {
+                return list;
+            }
+        }
     }
 }

+ 120 - 0
TEAMModelOS/Models/SchoolInfo/SchoolProduct.cs

@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Context.Attributes.Azure;
+
+namespace TEAMModelOS.Models.SchoolInfo
+{
+    [CosmosDB(Database = "TEAMModelOS", Name = "School")]
+    public class SchoolProduct
+    {
+        public string id { get; set; }
+        [PartitionKey]
+        public string code { get; set; }
+        public List<SerialInfo> serial { get; set; }
+        public ProductService service { get; set; }
+        public ProductHard hard { get; set; }
+        public List<string> aclassoneUserIds { get; set; }
+        
+
+    }
+
+    public class SerialInfo
+    {
+        public string id { get; set; }
+        public string serial { get; set; }
+        public string prodGroup { get; set; }
+        public string prodName { get; set; }
+        public int clientQty { get; set; }
+        public long regDate { get; set; }
+        public long startDate { get; set; }
+        public long endDate { get; set; }
+        public bool active { get; set; }
+        public int deviceMax { get; set; }
+        public List<deviceBoundExt> deviceBound { get; set; }
+        public object aprule { get; set; }
+        public string expireStatus { get; set; }
+        public int status { get; set; }
+    }
+
+    public class deviceBound
+    {
+        public string uuid { get; set; }
+        public string uuid2 { get; set; }
+        public string deviceId { get; set; }
+        public string classId { get; set; }
+    }
+    public class deviceBoundExt: deviceBound
+    {
+        public string ip { get; set; }
+        public string pcname { get; set; }
+        public string os { get; set; }
+        public string cpu { get; set; }
+        public int ram { get; set; }
+    }
+
+    public class ProductService
+    {
+        public List<ServiceMainPeriod> mainperiod { get; set; }
+        public List<ServicePeriod> period { get; set; }
+        public List<ServiceProduct> product { get; set; }
+    }
+    public class ServiceMainPeriod
+    {
+        public string mainPeriodId { get; set; }
+        public string mainPeriodtype { get; set; }
+        public long startDate { get; set; }
+        public long endDate { get; set; }
+        public bool active { get; set; }
+    }
+    public class ServicePeriod
+    {
+        public string mainPeriodId { get; set; }
+        public string periodId { get; set; }
+        public long startDate { get; set; }
+        public long endDate { get; set; }
+        public bool active { get; set; }
+    }
+
+    public class ServiceProduct
+    {
+        public string prodCode { get; set; }
+        public string prodGroup { get; set; }
+        public string prodName { get; set; }
+        public bool noperiod { get; set; }
+        public string serviceType { get; set; }
+        public List<ServiceProductAuth> auth { get; set; }
+        public int avaliable { get; set; }
+    }
+    public class ServiceProductAuth
+    {
+        public string orderId { get; set; }
+        public string periodId { get; set; }
+        public int number { get; set; }
+        public string unit { get; set; }
+    }
+
+    public class ProductHard
+    {
+        public string prodCode { get; set; }
+        public string prodGroup { get; set; }
+        public string prodName { get; set; }
+        public string model { get; set; }
+        public string serial { get; set; }
+    }
+
+    public class CoreUuid
+    {
+        public string serial { get; set; }
+        public string os { get; set; }
+        public string ip { get; set; }
+        public string uuid { get; set; }
+        public string uuid2 { get; set; }
+        public string deviceId { get; set; }
+        public string pcname { get; set; }
+        public string cpu { get; set; }
+        public int ram { get; set; }
+    }
+}
+