Browse Source

製作途中

jeff 4 years ago
parent
commit
da432cff9c

+ 110 - 111
TEAMModelOS/Controllers/School/SchoolController.cs

@@ -246,7 +246,7 @@ namespace TEAMModelOS.Controllers
             List<SerialInfoBaseWithdeviceBoundExt> serial = new List<SerialInfoBaseWithdeviceBoundExt>(); //最後要輸出的序號結果
             List<SerialInfoBaseWithdeviceBoundExt> serial = new List<SerialInfoBaseWithdeviceBoundExt>(); //最後要輸出的序號結果
             List<object> service = new List<object>();
             List<object> service = new List<object>();
             List<object> hard = new List<object>();
             List<object> hard = new List<object>();
-            List<deviceBoundRich> uuidList = new List<deviceBoundRich>(); //要向CoreService詢問deviceID及硬體資訊的UUID列表
+            List<deviceForCoreService> uuidList = new List<deviceForCoreService>(); //要向CoreService詢問deviceID及硬體資訊的UUID列表
             var response = await client.GetContainer("TEAMModelOSTemp", "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Product"));
             var response = await client.GetContainer("TEAMModelOSTemp", "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Product"));
             if (response.Status == 200)
             if (response.Status == 200)
             {
             {
@@ -257,51 +257,53 @@ namespace TEAMModelOS.Controllers
                     foreach (var serialInfo in serialJobj.EnumerateArray())
                     foreach (var serialInfo in serialJobj.EnumerateArray())
                     {
                     {
                         serial.Add(serialInfo.ToObject<SerialInfoBaseWithdeviceBoundExt>());
                         serial.Add(serialInfo.ToObject<SerialInfoBaseWithdeviceBoundExt>());
-                        serialInfo.TryGetProperty("deviceBound", out JsonElement deviceBoundJobj);
-                        foreach (var deviceBoundRow in deviceBoundJobj.EnumerateArray())
+                        if(serialInfo.TryGetProperty("deviceBound", out JsonElement deviceBoundJobj) && !string.IsNullOrWhiteSpace(deviceBoundJobj.ToString()) )
                         {
                         {
-                            deviceBoundRich uuidExtobj = new deviceBoundRich();
-                            uuidExtobj.serial = (!string.IsNullOrWhiteSpace(Convert.ToString(serialInfo.GetProperty("serial")))) ? Convert.ToString(serialInfo.GetProperty("serial")) : null;
-                            uuidExtobj.uuid = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid")) : null;
-                            uuidExtobj.uuid2 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid2")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid2")) : null;
-                            uuidExtobj.deviceId = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("deviceId")))) ? Convert.ToString(deviceBoundRow.GetProperty("deviceId")) : null;
-                            uuidExtobj.classId = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("classId")))) ? Convert.ToString(deviceBoundRow.GetProperty("classId")) : null;
-                            uuidList.Add(uuidExtobj);
+                            foreach (var deviceBoundRow in deviceBoundJobj.EnumerateArray())
+                            {
+                                deviceForCoreService uuidForCore = new deviceForCoreService();
+                                uuidForCore.sn = (!string.IsNullOrWhiteSpace(Convert.ToString(serialInfo.GetProperty("serial")))) ? Convert.ToString(serialInfo.GetProperty("serial")) : null;
+                                uuidForCore.uuid1 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid")) : null;
+                                uuidForCore.uuid2 = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("uuid2")))) ? Convert.ToString(deviceBoundRow.GetProperty("uuid2")) : null;
+                                uuidForCore.device_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("deviceId")))) ? Convert.ToString(deviceBoundRow.GetProperty("deviceId")) : null;
+                                uuidForCore.class_id = (!string.IsNullOrWhiteSpace(Convert.ToString(deviceBoundRow.GetProperty("classId")))) ? Convert.ToString(deviceBoundRow.GetProperty("classId")) : null;
+                                uuidList.Add(uuidForCore);
+                            }
                         }
                         }
                     }
                     }
                 }
                 }
-                //取得DeviceInfo From Core [先做假的,之後再對接]
-                List<object> serialResult = new List<object>();
-                List<CoreUuid> coreUuidList = (List<CoreUuid>)GetDeviceFromCore(uuidList);
+                //取得DeviceInfo From Core
+                List<deviceFromCoreService> coreUuidList = (List<deviceFromCoreService>)GetDeviceFromCoreAsync(uuidList).GetAwaiter().GetResult();
                 foreach (SerialInfoBaseWithdeviceBoundExt serialRow in serial)
                 foreach (SerialInfoBaseWithdeviceBoundExt serialRow in serial)
                 {
                 {
                     var deviceBoundArray = new List<deviceBoundExt>();
                     var deviceBoundArray = new List<deviceBoundExt>();
-                    List<CoreUuid> coreUuid = coreUuidList
-                           .Where((CoreUuid x) => x.serial == serialRow.serial)
+                    List<deviceFromCoreService> coreUuid = coreUuidList
+                           .Where((deviceFromCoreService x) => x.sn == serialRow.serial)
                            .ToList();
                            .ToList();
-                    foreach (CoreUuid deviceRow in coreUuid)
+                    foreach (deviceFromCoreService deviceRow in coreUuid)
                     {
                     {
                         //前端顯示用
                         //前端顯示用
-                        deviceBoundRich deviceBoundRow = uuidList.Where(u => u.serial == deviceRow.serial && u.uuid == deviceRow.uuid && u.uuid2 == deviceRow.uuid2).FirstOrDefault();
+                        deviceForCoreService deviceBoundRow = uuidList.Where(u => u.sn == deviceRow.sn && u.uuid1 == deviceRow.uuid1 && u.uuid2 == deviceRow.uuid2).FirstOrDefault();
                         deviceBoundExt deviceBoundExt = new deviceBoundExt();
                         deviceBoundExt deviceBoundExt = new deviceBoundExt();
-                        deviceBoundExt.uuid = deviceBoundRow.uuid;
+                        deviceBoundExt.uuid = deviceBoundRow.uuid1;
                         deviceBoundExt.uuid2 = deviceBoundRow.uuid2;
                         deviceBoundExt.uuid2 = deviceBoundRow.uuid2;
-                        deviceBoundExt.classId = deviceBoundRow.classId;
-                        deviceBoundExt.deviceId = deviceRow.deviceId;
+                        deviceBoundExt.classId = deviceBoundRow.class_id;
+                        deviceBoundExt.deviceId = deviceRow.device_id;
                         deviceBoundExt.os = deviceRow.os;
                         deviceBoundExt.os = deviceRow.os;
-                        deviceBoundExt.deviceId = deviceRow.deviceId;
-                        deviceBoundExt.ip = deviceRow.ip;
+                        deviceBoundExt.ip = deviceRow.local_ip;
                         deviceBoundExt.cpu = deviceRow.cpu;
                         deviceBoundExt.cpu = deviceRow.cpu;
-                        deviceBoundExt.pcname = deviceRow.pcname;
-                        deviceBoundExt.ram = deviceRow.ram;
+                        deviceBoundExt.pcname = deviceRow.pc_name;
+                        deviceBoundExt.osver = deviceRow.os_ver;
                         deviceBoundArray.Add(deviceBoundExt);
                         deviceBoundArray.Add(deviceBoundExt);
                         //DB更新用
                         //DB更新用
-                        deviceBound serialDeviceBoundRow = serialRow.deviceBound.Where(d => d.uuid == deviceBoundRow.uuid && d.uuid2 == deviceBoundRow.uuid2).FirstOrDefault();
-                        if (serialDeviceBoundRow.deviceId != deviceRow.deviceId)
+                        deviceBound serialDeviceBoundRow = serialRow.deviceBound.Where(d => d.uuid == deviceBoundRow.uuid1 && d.uuid2 == deviceBoundRow.uuid2).FirstOrDefault();
+                        if (serialDeviceBoundRow.deviceId != deviceRow.device_id)
                         {
                         {
                             deviceBoundRich deviceBoundUpdRow = new deviceBoundRich();
                             deviceBoundRich deviceBoundUpdRow = new deviceBoundRich();
-                            deviceBoundUpdRow = deviceBoundRow;
-                            deviceBoundUpdRow.deviceId = deviceRow.deviceId;
+                            deviceBoundUpdRow.uuid = deviceBoundRow.uuid1;
+                            deviceBoundUpdRow.uuid2 = deviceBoundRow.uuid2;
+                            deviceBoundUpdRow.classId = deviceBoundRow.class_id;
+                            deviceBoundUpdRow.deviceId = deviceRow.device_id;
                             serialDeviceUpdList.Add(deviceBoundUpdRow);
                             serialDeviceUpdList.Add(deviceBoundUpdRow);
                         }
                         }
                     }
                     }
@@ -445,97 +447,94 @@ namespace TEAMModelOS.Controllers
         /// </summary>
         /// </summary>
         /// <param name="request"></param>
         /// <param name="request"></param>
         /// <returns></returns>
         /// <returns></returns>
-        private List<CoreUuid> GetDeviceFromCore(List<deviceBoundRich> uuidList)
+        private async Task<List<deviceFromCoreService>> GetDeviceFromCoreAsync(List<deviceForCoreService> uuidList)
         {
         {
-            List<CoreUuid> list = new List<CoreUuid>();
+            List<deviceFromCoreService> result = new List<deviceFromCoreService>();
             try
             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();
-                //}
+                string url = BaseConfigModel.Configuration["HaBookAuth:CoreService:deviceinfo"];
+                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;
+                    result = System.Text.Json.JsonSerializer.Deserialize<List<deviceFromCoreService>>(responseBody.ToString());
+                    
+                }
+                return result;
 
 
-                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 = "8acb91e0-b5c7-4224-8e3e-5e165b80093b";
-                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);
+                //CoreUuid CoreUuid1 = new CoreUuid();
+                //CoreUuid1.serial = "12DLT43F-P871-UQS5-36JY-ADTB";
+                //CoreUuid1.uuid = "ac0541dd5bba";
+                //CoreUuid1.uuid2 = "5e470c0c0599";
+                //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 = "12DLT43F-KKHR-Z9VB-VODR-9WGX";
+                //CoreUuid2.uuid = null;
+                //CoreUuid2.uuid2 = null;
+                //CoreUuid2.deviceId = null;
+                //CoreUuid2.ip = null;
+                //CoreUuid2.pcname = null;
+                //CoreUuid2.os = null;
+                //CoreUuid2.cpu = null;
+                //CoreUuid2.ram = 0;
+                //list.Add(CoreUuid2);
+                //CoreUuid CoreUuid3 = new CoreUuid();
+                //CoreUuid3.serial = "12DLT43F-BTXK-W65T-9P6J-DVAR";
+                //CoreUuid3.uuid = null;
+                //CoreUuid3.uuid2 = "A483E742B0FF";
+                //CoreUuid3.deviceId = "8acb91e0-b5c7-4224-8e3e-5e165b80093b";
+                //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)
             catch (Exception ex)
             {
             {
-                return list;
+                return result;
             }
             }
         }
         }
 
 

+ 22 - 1
TEAMModelOS/Models/SchoolInfo/SchoolProduct.cs

@@ -63,13 +63,34 @@ namespace TEAMModelOS.Models.SchoolInfo
     {
     {
         public string serial { get; set; }
         public string serial { get; set; }
     }
     }
+    public class deviceForCoreService
+    {
+        public string uuid1 { get; set; }
+        public string uuid2 { get; set; }
+        public string device_id { get; set; }
+        public string class_id { get; set; }
+        public string sn { get; set; }
+    }
+    public class deviceFromCoreService
+    {
+        public string uuid1 { get; set; }
+        public string uuid2 { get; set; }
+        public string device_id { get; set; }
+        public string sn { get; set; }
+        public string os { get; set; }
+        public string os_ver { get; set; }
+        public string local_ip { get; set; }
+        public string product_ver { get; set; }
+        public string cpu { get; set; }
+        public string pc_name { get; set; }
+    }
     public class deviceBoundExt: deviceBound
     public class deviceBoundExt: deviceBound
     {
     {
         public string ip { get; set; }
         public string ip { get; set; }
         public string pcname { get; set; }
         public string pcname { get; set; }
         public string os { get; set; }
         public string os { get; set; }
         public string cpu { get; set; }
         public string cpu { get; set; }
-        public int ram { get; set; }
+        public string osver { get; set; }
     }
     }
 
 
     public class ProductService
     public class ProductService

+ 3 - 0
TEAMModelOS/appsettings.Development.json

@@ -66,6 +66,9 @@
     },
     },
     "CoreId": {
     "CoreId": {
       "userinfo": "https://api2.teammodel.cn/Oauth2/GetUserInfos"
       "userinfo": "https://api2.teammodel.cn/Oauth2/GetUserInfos"
+    },
+    "CoreService": {
+      "deviceinfo": "https://api2.teammodel.net/oauth2/getdeviceinfos"
     }
     }
   },
   },
   "SmsSendCloud": {
   "SmsSendCloud": {

+ 3 - 0
TEAMModelOS/appsettings.json

@@ -65,6 +65,9 @@
     },
     },
     "CoreId": {
     "CoreId": {
       "userinfo": "https://api2.teammodel.cn/Oauth2/GetUserInfos"
       "userinfo": "https://api2.teammodel.cn/Oauth2/GetUserInfos"
+    },
+    "CoreService": {
+      "deviceinfo": "https://api2.teammodel.net/oauth2/getdeviceinfos"
     }
     }
     },
     },
   "SmsSendCloud": {
   "SmsSendCloud": {