Parcourir la source

修改学校接入

黄贺彬 il y a 6 ans
Parent
commit
4beebd32e9

+ 15 - 0
TEAMModelOS.Model/Common/Dtos/SchoolCode.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.Model.Common.Dtos
+{
+   public class SchoolCode
+    {
+        public string CountryId { get; set; }//国家
+
+        public string ProvinceId { get; set; }//省份
+
+        public string CityId { get; set; }//城市
+    }
+}

+ 15 - 0
TEAMModelOS.Model/Common/Models/Product.cs

@@ -0,0 +1,15 @@
+using Microsoft.WindowsAzure.Storage.Table;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using TEAMModelOS.SDK.Context.Attributes.Table;
+
+namespace TEAMModelOS.Model.Common.Models
+{
+
+    [TableSpace(Name = "Common")]
+    public class Product : TableEntity
+    {
+        public string Name { get; set; }
+    }
+}

+ 0 - 1
TEAMModelOS.Model/Common/Models/Region.cs

@@ -12,7 +12,6 @@ namespace TEAMModelOS.Model.Common.Models
     [MessagePackObject(keyAsPropertyName: true)]
     [MessagePackObject(keyAsPropertyName: true)]
     public class Region :TableEntity
     public class Region :TableEntity
     {
     {
-        [JsonProperty(PropertyName = "sysAddID")]
         public int SysAddID { get; set; }
         public int SysAddID { get; set; }
         public string CountryId { get; set; }
         public string CountryId { get; set; }
         public string CountryName { get; set; }
         public string CountryName { get; set; }

+ 2 - 0
TEAMModelOS.Model/Common/Models/RoleUser.cs

@@ -12,5 +12,7 @@ namespace TEAMModelOS.Model.Common.Models
     {
     {
         public string Name { get; set; }
         public string Name { get; set; }
         public string Phone { get; set; }
         public string Phone { get; set; }
+        public string RoleCode { get; set; }
+        public string RoleName { get; set; }
     }
     }
 }
 }

+ 20 - 1
TEAMModelOS.Model/Common/Models/School.cs

@@ -1,4 +1,5 @@
-using Microsoft.WindowsAzure.Storage.Table;
+using MessagePack;
+using Microsoft.WindowsAzure.Storage.Table;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
@@ -7,24 +8,42 @@ using TEAMModelOS.SDK.Context.Attributes.Table;
 namespace TEAMModelOS.Model.Common.Models
 namespace TEAMModelOS.Model.Common.Models
 {
 {
     [TableSpace(Name = "Common")]
     [TableSpace(Name = "Common")]
+    [MessagePackObject(keyAsPropertyName: true)]
     public class School :TableEntity
     public class School :TableEntity
     {
     {
+        [Key("code")]
         public string Code { get; set; }
         public string Code { get; set; }
+        [Key("name")]
         public string Name { get; set; }
         public string Name { get; set; }
+        [Key("countryId")]
         public string CountryId { get; set; }
         public string CountryId { get; set; }
+        [Key("countryName")]
         public string CountryName { get; set; }
         public string CountryName { get; set; }
+        [Key("provinceId")]
         public string ProvinceId { get; set; }
         public string ProvinceId { get; set; }
+        [Key("provinceName")]
         public string ProvinceName { get; set; }
         public string ProvinceName { get; set; }
+        [Key("cityId")]
         public string CityId { get; set; }
         public string CityId { get; set; }
+        [Key("cityName")]
         public string CityName { get; set; }
         public string CityName { get; set; }
+        [Key("address")]
         public string Address { get; set; }
         public string Address { get; set; }
+        [Key("typeId")]
         public string TypeId { get; set; }
         public string TypeId { get; set; }
+        [Key("typeName")]
         public string TypeName { get; set; }
         public string TypeName { get; set; }
+        [Key("source")]
         public string Source { get; set; }
         public string Source { get; set; }
+        [Key("distId")]
         public string DistId { get; set; }
         public string DistId { get; set; }
+        [Key("distName")]
         public string DistName { get; set; }
         public string DistName { get; set; }
+        [Key("schoolDist")]
         public string SchoolDist { get; set; }
         public string SchoolDist { get; set; }
+        [Key("aliasName")]
         public string AliasName { get; set; }
         public string AliasName { get; set; }
+        [Key("shortCode")]
         public string ShortCode { get; set; }
         public string ShortCode { get; set; }
     }
     }
 }
 }

+ 1 - 0
TEAMModelOS.SDK/Extension/HttpClient/HttpClientExtension.cs

@@ -11,6 +11,7 @@ namespace TEAMModelOS.SDK.Extension.HttpClient
             //services.AddSingleton<HttpClientService>();
             //services.AddSingleton<HttpClientService>();
             services.AddHttpClient<HttpClientSendCloud>();
             services.AddHttpClient<HttpClientSendCloud>();
             services.AddHttpClient<HttpClientUserInfo>();
             services.AddHttpClient<HttpClientUserInfo>();
+            services.AddHttpClient<HttpClientSchool>();
         }
         }
     }
     }
 }
 }

+ 177 - 0
TEAMModelOS.SDK/Extension/HttpClient/Implements/HttpClientSchool.cs

@@ -0,0 +1,177 @@
+using System;
+using System.Collections.Generic;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.Context.Configuration;
+using TEAMModelOS.SDK.Context.Constant.Common;
+using HttpClientSpace = System.Net.Http;
+
+namespace TEAMModelOS.SDK.Extension.HttpClient.Implements
+{
+    /// <summary>
+    /// 需要调整的  https://blog.yowko.com/httpclientfactory-dotnet-core-dotnet-framework/
+    /// </summary>
+    public class HttpClientSchool
+    {
+        HttpClientSpace.HttpClient client { get; }
+        public HttpClientSchool(HttpClientSpace.HttpClient _client)
+        {
+            // _client.BaseAddress =new Uri(BaseConfigModel.Configuration["HaBookAuth:AccountUrl"]);
+            _client.Timeout = new TimeSpan(0, 0, 1000);
+            _client.DefaultRequestHeaders.Add(Constants.AUTHORIZATION, BaseConfigModel.Configuration["HaBookAuth:SchoolCodeKey"]);
+            client = _client;
+        }
+
+        /// <summary>
+        /// 同步GET请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="headers"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <returns></returns>
+        public string HttpGet(string url)
+        {
+
+            //if (headers != null)
+            //{
+            //    foreach (KeyValuePair<string, string> header in headers)
+            //    {
+            //        client.DefaultRequestHeaders.Add(header.Key, header.Value);
+            //    }
+            //}
+            //if (timeout > 0)
+            //{
+            //    client.Timeout = new TimeSpan(0, 0, timeout);
+            //}
+            byte[] resultBytes = client.GetByteArrayAsync(url).Result;
+            return Encoding.UTF8.GetString(resultBytes);
+        }
+
+        /// <summary>
+        /// 异步GET请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="headers"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <returns></returns>
+        public async Task<string> HttpGetAsync(string url)
+        {
+            //if (headers != null)
+            //{
+            //    foreach (KeyValuePair<string, string> header in headers)
+            //    {
+            //        client.DefaultRequestHeaders.Add(header.Key, header.Value);
+            //    }
+            //}
+            //if (timeout > 0)
+            //{
+            //    client.Timeout = new TimeSpan(0, 0, timeout);
+            //}
+            byte[] resultBytes = await client.GetByteArrayAsync(url);
+            return Encoding.Default.GetString(resultBytes);
+        }
+
+
+        /// <summary>
+        /// 同步POST请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <param name="headers"></param>
+        /// <param name="contentType"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <param name="encoding">默认UTF8</param>
+        /// <returns></returns>
+        public string HttpPost(string url, string postData,  string contentType = null, Encoding encoding = null)
+        {
+            //if (headers != null)
+            //{
+            //    foreach (KeyValuePair<string, string> header in headers)
+            //    {
+            //        client.DefaultRequestHeaders.Add(header.Key, header.Value);
+            //    }
+            //}
+            //if (timeout > 0)
+            //{
+            //    client.Timeout = new TimeSpan(0, 0, timeout);
+            //}
+            HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8);
+
+            if (contentType != null)
+            {
+                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+            }
+            HttpResponseMessage responseMessage = client.PostAsync(url, content).Result;
+            byte[] resultBytes = responseMessage.Content.ReadAsByteArrayAsync().Result;
+            return Encoding.UTF8.GetString(resultBytes);
+        }
+
+        /// <summary>
+        /// 异步POST请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <param name="headers"></param>
+        /// <param name="contentType"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <param name="encoding">默认UTF8</param>
+        /// <returns></returns>
+        public async Task<string> HttpPostAsync(string url, string postData, string contentType = null, Encoding encoding = null)
+        {
+            //if (headers != null)
+            //{
+            //    foreach (KeyValuePair<string, string> header in headers)
+            //    {
+            //        client.DefaultRequestHeaders.Add(header.Key, header.Value);
+            //    }
+            //}
+            //if (timeout > 0)
+            //{
+            //    client.Timeout = new TimeSpan(0, 0, timeout);
+            //}
+            HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8);
+
+            if (contentType != null)
+            {
+                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+            }
+            HttpResponseMessage responseMessage = await client.PostAsync(url, content);
+            byte[] resultBytes = await responseMessage.Content.ReadAsByteArrayAsync();
+            return Encoding.UTF8.GetString(resultBytes);
+        }
+
+        /// <summary>
+        /// 异步POST请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="postData"></param>
+        /// <param name="headers"></param>
+        /// <param name="contentType"></param>
+        /// <param name="timeout">请求响应超时时间,单位/s(默认100秒)</param>
+        /// <param name="encoding">默认UTF8</param>
+        /// <returns></returns>
+        public async Task<string> HttpPostAsync(string url, List<KeyValuePair<string, string>> postData,  string contentType = null, Encoding encoding = null)
+        {
+            //if (headers != null)
+            //{
+            //    foreach (KeyValuePair<string, string> header in headers)
+            //    {
+            //        client.DefaultRequestHeaders.Add(header.Key, header.Value);
+            //    }
+            //}
+            //if (timeout > 0)
+            //{
+            //    client.Timeout = new TimeSpan(0, 0, timeout);
+            //}
+            HttpContent content = new FormUrlEncodedContent(postData);
+            if (contentType != null)
+            {
+                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+            }
+            HttpResponseMessage responseMessage = await client.PostAsync(url, content);
+            byte[] resultBytes = await responseMessage.Content.ReadAsByteArrayAsync();
+            return Encoding.UTF8.GetString(resultBytes);
+        }
+    }
+}

+ 52 - 0
TEAMModelOS.Service/Common/Implements/SchoolService.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.Model.Common.Dtos;
+using TEAMModelOS.Model.Common.Models;
+using TEAMModelOS.SDK.Context.Configuration;
+using TEAMModelOS.SDK.Context.Constant.Common;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.SDK.Extension.HttpClient.Implements;
+using TEAMModelOS.SDK.Helper.Common.JsonHelper;
+using TEAMModelOS.Service.Common.Interfaces;
+
+namespace TEAMModelOS.Service.Common.Implements
+{
+    public class SchoolService : ISchoolService
+    {
+
+        private HttpClientSchool _httpClientSchool;
+        public SchoolService(HttpClientSchool httpClientSchool) {
+            _httpClientSchool = httpClientSchool;
+        }
+
+        /// <summary>
+        /// 查看各个地区城市学校信息
+        /// </summary>
+        /// <param name="getSchool"></param>
+        /// <returns></returns>
+        public Task<List<School>> GetSchool(SchoolCode schoolCode) {
+            Dictionary<string, object> datas = new Dictionary<string, object>
+            {
+                { "countryId", schoolCode.CountryId },
+                { "provinceId", schoolCode.ProvinceId },
+                { "cityId", schoolCode.CityId }
+            };
+            Dictionary<string, object> data = new Dictionary<string, object>
+            {
+                { "data", datas }
+            };
+            JosnRPCRequest<Dictionary<string, object>> request = new JosnRPCRequest<Dictionary<string, object>>
+            {
+                @params = data,
+                method = "SchoolCode"
+            };
+            string postData = MessagePackHelper.ObjectToJson(request);
+            string dataSchool= _httpClientSchool.HttpPost(BaseConfigModel.Configuration["HaBookAuth:ServiceUrl"], postData, Constants.CONTENT_TYPE_JSON, Encoding.UTF8);
+            JosnRPCResponse<List<School>> response = MessagePackHelper.JsonToObject<JosnRPCResponse<List<School>>>(dataSchool);
+            return Task.FromResult(response.result); 
+        }
+    }
+}

+ 19 - 0
TEAMModelOS.Service/Common/Interfaces/ISchoolService.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using TEAMModelOS.Model.Common.Dtos;
+using TEAMModelOS.Model.Common.Models;
+
+namespace TEAMModelOS.Service.Common.Interfaces
+{
+   public interface ISchoolService
+    {
+        /// <summary>
+        /// 查看各个地区城市学校信息
+        /// </summary>
+        /// <param name="getSchool"></param>
+        /// <returns></returns>
+       Task<List<School>> GetSchool(SchoolCode schoolCode);
+    }
+}

+ 45 - 0
TEAMModelOS/Controllers/Common/SchoolController.cs

@@ -0,0 +1,45 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.Model.Common.Dtos;
+using TEAMModelOS.Model.Common.Models;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
+using TEAMModelOS.SDK.Helper.Common.ValidateHelper;
+using TEAMModelOS.Service.Common.Interfaces;
+
+namespace TEAMModelOS.Controllers.Common
+{
+    /// <summary>
+    /// 获得学校信息
+    /// </summary>
+    [Route("api/[controller]")]
+    [ApiController]
+    public class SchoolController : Controller
+    {
+        private ISchoolService _schoolInfoService;
+
+        public SchoolController(ISchoolService schoolInfoService)
+        {
+            _schoolInfoService = schoolInfoService;
+        }
+
+        // GET api/<controller>/5
+        [HttpPost("getSchool")]
+        public async Task<BaseJosnRPCResponse> GetSchoolAsync(JosnRPCRequest<SchoolCode> request)
+        {
+            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
+            List<School> schools =await _schoolInfoService.GetSchool(request.@params);
+            if (schools.IsNotEmpty())
+            {
+                builder.Data(schools);
+            }
+            else builder.Data(null);
+            return builder.build();
+
+        }
+    }
+}

+ 2 - 2
TEAMModelOS/Views/Shared/_Layout.cshtml

@@ -6,9 +6,9 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <title>@ViewData["Title"]TEAMModelOS</title>
     <title>@ViewData["Title"]TEAMModelOS</title>
 
 
-    <link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />
+    @*<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />*@
     <environment names="Staging,Production">
     <environment names="Staging,Production">
-        <link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />
+        @*<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />*@
     </environment>
     </environment>
 </head>
 </head>