Sfoglia il codice sorgente

记录老师的绑定信息

CrazyIter_Bin 3 anni fa
parent
commit
ee8b1a629d

+ 1 - 1
TEAMModelOS.SDK/Models/Service/ActivityService.cs

@@ -66,7 +66,7 @@ namespace TEAMModelOS.SDK
                 foreach (MQActivity activity in datas)
                 {
                     //已经完结的不再允许加入,还未开始的。
-                    if (activity.progress.Equals("finish") || activity.progress.Equals("pending"))
+                    if (string.IsNullOrEmpty(activity.progress)|| activity.progress.Equals("finish") || activity.progress.Equals("pending"))
                     {
                         continue;
                     }

+ 30 - 17
TEAMModelOS/Controllers/School/StudentController.cs

@@ -245,20 +245,26 @@ namespace TEAMModelOS.Controllers
                             request.TryGetProperty("oldpwd", out JsonElement _oldpwd) && 
                             request.TryGetProperty("studentId", out JsonElement _studentId)) {
                             if ($"{_studentId}".Equals(stuid) && school.Equals($"{schoolId}")) {
-                                Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
-                                .ReadItemAsync<Student>($"{_studentId}", new PartitionKey($"Base-{schoolId}"));
-                                var HashedPW = Utils.HashedPassword($"{_oldpwd}", student.salt);
-                                if (HashedPW.Equals(student.pw))
-                                {
-                                    student.pw = Utils.HashedPassword($"{_newpwd}", student.salt);
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
-                                  .ReplaceItemAsync<Student>(student, student.id, new PartitionKey($"Base-{schoolId}"));
-                                    return Ok(new { status = true });
-                                }
-                                else
-                                {
-                                    return Ok(new { error = false, status = false, msg = "密码不一致" });
+                                try {
+                                    Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                                   .ReadItemAsync<Student>($"{_studentId}", new PartitionKey($"Base-{schoolId}"));
+                                    var HashedPW = Utils.HashedPassword($"{_oldpwd}", student.salt);
+                                    if (HashedPW.Equals(student.pw))
+                                    {
+                                        student.pw = Utils.HashedPassword($"{_newpwd}", student.salt);
+                                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                                      .ReplaceItemAsync<Student>(student, student.id, new PartitionKey($"Base-{schoolId}"));
+                                        return Ok(new { status = true });
+                                    }
+                                    else
+                                    {
+                                        return Ok(new { error = false, status = false, msg = "密码不一致" });
+                                    }
+                                } catch (Exception ex) {
+                                    await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/StudentManage()\n{ex.Message}{ex.StackTrace}\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                                    return Ok(new { error = false, status = false, msg = "账号不存在" });
                                 }
+
                             }
                             else
                             {
@@ -272,9 +278,16 @@ namespace TEAMModelOS.Controllers
                     case "read-self-info":
                         if (request.TryGetProperty("studentId", out JsonElement __studentId))
                         {
-                            Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
-                                .ReadItemAsync<Student>($"{__studentId}", new PartitionKey($"Base-{schoolId}"));
-                            return Ok(new { student.mail, student.mobile, student.name, student.picture, student.gender, student.id, student.schoolId, student.year, student.no, student.classId, student.periodId,irs=student.irs });
+                            try {
+                                Student student = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student")
+                                    .ReadItemAsync<Student>($"{__studentId}", new PartitionKey($"Base-{schoolId}"));
+                                return Ok(new { student.mail, student.mobile, student.name, student.picture, student.gender, student.id, student.schoolId, student.year, student.no, student.classId, student.periodId, irs = student.irs });
+
+                            }
+                            catch (Exception ex) {
+                                await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/StudentManage()\n{ex.Message}{ex.StackTrace}\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                            }
+                            return Ok();
                         }
                         else
                         {
@@ -286,7 +299,7 @@ namespace TEAMModelOS.Controllers
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/StudentManage()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                await _dingDing.SendBotMsg($"IES5,{_option.Location},StudentController/StudentManage()\n{ex.Message}{ex.StackTrace}\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
             }
             return BadRequest();
         }

+ 7 - 6
TEAMModelOS/Controllers/Third/ScController.cs

@@ -123,7 +123,7 @@ namespace TEAMModelOS.Controllers.Third
                     teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
                     //先检查绑定的平台是否已经被绑定
                     //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
-                    string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where  A1.webid='{scsso.Webid}' and A1.tid='{scsso.tid}'";
+                    string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where   A1.tid='{scsso.tid}'";
                     await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
                         requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
                     {
@@ -159,7 +159,7 @@ namespace TEAMModelOS.Controllers.Third
                                     bind.data.Add(bindData.ToJsonString());
                                 }
                                 await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
-
+                                await _azureStorage.UploadFileByContainer("teammodelos", bindData.ToJsonString(), $"yxpt/{scsso.path}/scbind", $"{teacher.id}.json");
                             }
                         }
                         else
@@ -194,6 +194,7 @@ namespace TEAMModelOS.Controllers.Third
                     var container = _azureStorage.GetBlobContainerClient(id);
                     await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
                     teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
+                    await _azureStorage.UploadFileByContainer("teammodelos", scsso.data.ToJsonString(), $"yxpt/{scsso.path}/scbind", $"{teacher.id}.json");
                 }
                 catch (Exception ex) {
                     await _dingDing.SendBotMsg($"OS,{_option.Location}\n绑定失败:\n{sso.ToJsonString()},{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
@@ -271,7 +272,6 @@ namespace TEAMModelOS.Controllers.Third
                 {
                     return Redirect(rurl.Append($"?status=1").ToString());
                 }
-                //string accessConfig = "{\"homeworkType\":[\"pdf\"],\"submitType\":[\"pdf\",\"mp4\"],\"path\":\"scpjx\",\"config\":\"scsyxpt\",\"passKey\":\"VgEQfEjwzfvFn8my\",\"trainComID\":\"2065\",\"privateKey\":\"4DB15444DEEDBB28B718ACB09217B5FC\",\"url\":\"http://testscts.scedu.com.cn/webservice/EduService.asmx/RequestService\"}";
                 string accessConfig = setting.accessConfig;
                 Dictionary<string, object> dict = new Dictionary<string, object> { { "accessConfig", accessConfig }, { "pxid", scsso.Pxid }, { "tid", scsso.tid } };
                 string SchoolName="",SchoolID = "", ProjectID = "", ProjectItemID ="" ; 
@@ -298,8 +298,8 @@ namespace TEAMModelOS.Controllers.Third
                     pxid = scsso.Pxid
                 };
                 var data = bindData.ToJsonString();
-                ScSSOData sso = new ScSSOData { 
-                    Webid = scsso.Webid,
+                ScSSOData sso = new ScSSOData {
+                    path = path,
                     Pxid = scsso.Pxid,
                     Encrypt = scsso.Encrypt,
                     tid = scsso.tid,
@@ -377,6 +377,7 @@ namespace TEAMModelOS.Controllers.Third
                             //    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
                             //}
                         }
+                        await _azureStorage.UploadFileByContainer("teammodelos", bindData.ToJsonString(), $"yxpt/{sso.path}/scbind", $"{teacher.id}.json");
                         return Redirect(rurl.Append($"?status=200&id_token={implicit_token.id_token}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}").ToString());
                     }
                     else
@@ -962,7 +963,7 @@ namespace TEAMModelOS.Controllers.Third
         }
         public record ScSSOData
         {
-            public string Webid { get; set; }
+            public string path { get; set; }
             public string Pxid { get; set; }
             public string tid { get; set; }
             public string time { get; set; }

+ 403 - 97
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -6,6 +6,8 @@ using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Configuration;
+using Microsoft.International.Converters.PinYinConverter;
+using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
 using Newtonsoft.Json;
 using StackExchange.Redis;
 using System;
@@ -17,6 +19,7 @@ using System.Net.Http;
 using System.Net.Http.Json;
 using System.Text;
 using System.Text.Json;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
@@ -29,7 +32,7 @@ namespace TEAMModelOS.Controllers
 {
     [Route("test")]
     [ApiController]
-    public class TestController :ControllerBase
+    public class TestController : ControllerBase
     {
         public IWebHostEnvironment _environment { get; set; }
         private readonly AzureStorageFactory _azureStorage;
@@ -38,34 +41,54 @@ namespace TEAMModelOS.Controllers
         private readonly DingDing _dingDing;
         private readonly AzureServiceBusFactory _serviceBus;
         public IConfiguration _configuration { get; set; }
-        public TestController(IWebHostEnvironment environment,AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, IConfiguration configuration, AzureServiceBusFactory serviceBus, DingDing dingDing) {
+        public TestController(IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, IConfiguration configuration, AzureServiceBusFactory serviceBus, DingDing dingDing)
+        {
             _azureCosmos = azureCosmos;
             _azureRedis = azureRedis;
             _azureStorage = azureStorage;
-            _dingDing = dingDing; 
+            _dingDing = dingDing;
             _serviceBus = serviceBus; _configuration = configuration;
             _environment = environment;
         }
         public static List<string> comeRemoveStr = new List<string>() { "省", "市", "区", "州", "县", "旗", "盟", "自治" };
         public static List<string> prvcRemoveStr = new List<string>() { "回族", "维吾尔", "壮族", };
-        public static List<string> cityRemoveStr = new List<string>() { "蒙古族",  "地区", "壮族",  "朝鲜族", "直辖" };
+        public static List<string> cityRemoveStr = new List<string>() { "蒙古族", "地区", "壮族", "朝鲜族", "直辖" };
         public static List<string> nationRemoveStr = new List<string> {
-            "维吾尔","回族", "自治", "满族", "蒙古", "壮族", "苗族" , "侗族", "瑶族",
-            "达斡尔","鄂温克","朝鲜","畲族","土家","各族","仫佬","毛南","羌族","彝族","仡佬","布依","水族",
-            "傣族","纳西","哈尼","拉祜","佤族","傈僳","独龙","怒族","白族","普米","固族","哈萨克","土族","撒拉","景颇","族"
+            "维吾尔","回族", "自治", "满族", "蒙古", "壮族", "苗族" , "侗族", "瑶族",
+            "达斡尔","鄂温克","朝鲜","畲族","土家","各族","仫佬","毛南","羌族","彝族","仡佬","布依","水族",
+            "傣族","纳西","哈尼","拉祜","佤族","傈僳","独龙","怒族","白族","普米","固族","哈萨克","土族","撒拉","景颇","族"
         };
         public static List<string> schooRemoveStr = new List<string>() {"(",")", "(",")","省", "市", "校区", "区", "州", "县", "旗", "盟", "自治",
-            "第","学校","校园","镇","村","乡","街","路","部"
+            "第","学校","校园","镇","村","乡","街","路","部","楼","与","站","馆","街道","办事处","义务"
         };
         public static List<KeyValuePair<string, string>> areaRemoveStr = new List<KeyValuePair<string, string>>{
+             new KeyValuePair<string, string>("国际", "际") ,
+            new KeyValuePair<string, string>("中国", ""),
+            new KeyValuePair<string, string>("国家", ""),
             new KeyValuePair<string, string>("新区", ""),
             new KeyValuePair<string, string>("高新", "高"),
             new KeyValuePair<string, string>("园区", ""),
             new KeyValuePair<string, string>("产业", "产"),
             new KeyValuePair<string, string>("经济", "经"),
             new KeyValuePair<string, string>("开发", "开"),
+            new KeyValuePair<string, string>("中心", "") ,
+            new KeyValuePair<string, string>("集团", "") ,
+            new KeyValuePair<string, string>("公司", "") ,
+            new KeyValuePair<string, string>("有限", "") ,
+            new KeyValuePair<string, string>("股份", "") ,
+            new KeyValuePair<string, string>("服务", "") ,
+            new KeyValuePair<string, string>("基地", "") ,
+            new KeyValuePair<string, string>("社区", "社") ,
+            new KeyValuePair<string, string>("职工", "") ,
+            new KeyValuePair<string, string>("专修", "")
+            ,
         };
         public static List<KeyValuePair<string, string>> schooReplaceStr = new List<KeyValuePair<string, string>> {
+            new KeyValuePair<string, string>("职业技术学院", "职技") ,
+            new KeyValuePair<string, string>("创新创业", "创") ,
+            new KeyValuePair<string, string>("就业创业", "就") ,
+            new KeyValuePair<string, string>("应用核技术", "核") ,
+            new KeyValuePair<string, string>("职业学院", "职") ,
             new KeyValuePair<string, string>("幼儿园", "幼") ,
             new KeyValuePair<string, string>("幼儿", "幼") ,
             new KeyValuePair<string, string>("小学", "小") ,
@@ -83,10 +106,113 @@ namespace TEAMModelOS.Controllers
             new KeyValuePair<string, string>("外国语", "外") ,
             new KeyValuePair<string, string>("实验", "验") ,
             new KeyValuePair<string, string>("年制", "制") ,
-            new KeyValuePair<string, string>("高等", "") ,
+            new KeyValuePair<string, string>("高等", "") ,
             new KeyValuePair<string, string>("分校", "分") ,
             new KeyValuePair<string, string>("分园", "分") ,
-            new KeyValuePair<string, string>("附属", "附") ,
+            new KeyValuePair<string, string>("分院", "分") ,
+            new KeyValuePair<string, string>("院校", "院") ,
+            new KeyValuePair<string, string>("初等", "小") ,
+            new KeyValuePair<string, string>("附属", "附"),
+            new KeyValuePair<string, string>("五年", "五") ,
+            new KeyValuePair<string, string>("卫生", "卫") ,
+            new KeyValuePair<string, string>("九年", "九") ,
+            new KeyValuePair<string, string>("创业", "创") ,
+            new KeyValuePair<string, string>("继续", "继") ,
+            new KeyValuePair<string, string>("开放", "开") ,
+            new KeyValuePair<string, string>("技师", "技") ,
+            new KeyValuePair<string, string>("成人", "成") ,
+            new KeyValuePair<string, string>("教育", "教") ,
+            new KeyValuePair<string, string>("科技", "科") ,
+            new KeyValuePair<string, string>("行政", "政") ,
+            new KeyValuePair<string, string>("生物", "生") ,
+            new KeyValuePair<string, string>("美术", "美") ,
+            new KeyValuePair<string, string>("设计", "设") ,
+            new KeyValuePair<string, string>("传播", "传") ,
+            new KeyValuePair<string, string>("计算机", "算") ,
+            new KeyValuePair<string, string>("土木", "土") ,
+            new KeyValuePair<string, string>("石油", "油") ,
+            new KeyValuePair<string, string>("科普", "普") ,
+            new KeyValuePair<string, string>("电信", "信") ,
+            new KeyValuePair<string, string>("联合", "联") ,
+            new KeyValuePair<string, string>("电商", "商") ,
+            new KeyValuePair<string, string>("纺织", "织") ,
+            new KeyValuePair<string, string>("服装", "服") ,
+            new KeyValuePair<string, string>("新闻", "新") ,
+            new KeyValuePair<string, string>("网络", "网") ,
+            new KeyValuePair<string, string>("应用", "应") ,
+            new KeyValuePair<string, string>("畜牧", "畜") ,
+            new KeyValuePair<string, string>("兽医", "兽") ,
+            new KeyValuePair<string, string>("师范", "师") ,
+            new KeyValuePair<string, string>("人文", "文") ,
+            new KeyValuePair<string, string>("创新", "创") ,
+            new KeyValuePair<string, string>("法官", "法") ,
+            new KeyValuePair<string, string>("邮电", "邮") ,
+            new KeyValuePair<string, string>("文化", "文") ,
+            new KeyValuePair<string, string>("函授", "函") ,
+            new KeyValuePair<string, string>("科学", "科") ,
+            new KeyValuePair<string, string>("信息", "息") ,
+            new KeyValuePair<string, string>("水利", "利") ,
+            new KeyValuePair<string, string>("水电", "电") ,
+            new KeyValuePair<string, string>("电力", "力") ,
+            new KeyValuePair<string, string>("环境", "环") ,
+            new KeyValuePair<string, string>("建材", "材") ,
+            new KeyValuePair<string, string>("机电", "机") ,
+            new KeyValuePair<string, string>("航空", "空") ,
+            new KeyValuePair<string, string>("航天", "天") ,
+            new KeyValuePair<string, string>("警察", "警") ,
+            new KeyValuePair<string, string>("警官", "警") ,
+            new KeyValuePair<string, string>("财贸", "财") ,
+            new KeyValuePair<string, string>("电子", "电") ,
+            new KeyValuePair<string, string>("建筑", "筑") ,
+            new KeyValuePair<string, string>("艺术", "艺") ,
+            new KeyValuePair<string, string>("体育", "体") ,
+            new KeyValuePair<string, string>("城市", "城") ,
+            new KeyValuePair<string, string>("地质", "地") ,
+            new KeyValuePair<string, string>("医药", "药") ,
+            new KeyValuePair<string, string>("政法", "法") ,
+            new KeyValuePair<string, string>("铁路", "铁") ,
+            new KeyValuePair<string, string>("铁道", "道") ,
+            new KeyValuePair<string, string>("轨道", "轨") ,
+            new KeyValuePair<string, string>("交通", "通") ,
+            new KeyValuePair<string, string>("医学院", "医") ,
+            new KeyValuePair<string, string>("医学", "医") ,
+            new KeyValuePair<string, string>("传媒", "媒") ,
+            new KeyValuePair<string, string>("工程", "程") ,
+            new KeyValuePair<string, string>("临床", "临") ,
+            new KeyValuePair<string, string>("化工", "化") ,
+            new KeyValuePair<string, string>("林业", "林") ,
+            new KeyValuePair<string, string>("老年", "老") ,
+            new KeyValuePair<string, string>("旅游", "游") ,
+            new KeyValuePair<string, string>("护理", "护") ,
+            new KeyValuePair<string, string>("贸易", "贸") ,
+            new KeyValuePair<string, string>("中医药", "中医") ,
+            new KeyValuePair<string, string>("资源", "源") ,
+            new KeyValuePair<string, string>("冶金", "冶") ,
+            new KeyValuePair<string, string>("能源", "能") ,
+            new KeyValuePair<string, string>("汽车", "车") ,
+            new KeyValuePair<string, string>("医科", "医") ,
+            new KeyValuePair<string, string>("机械", "械") ,
+            new KeyValuePair<string, string>("应用", "应") ,
+            new KeyValuePair<string, string>("电气", "电") ,
+            new KeyValuePair<string, string>("材料", "材") ,
+            new KeyValuePair<string, string>("劳动", "劳") ,
+            new KeyValuePair<string, string>("轻工", "轻") ,
+            new KeyValuePair<string, string>("农业", "农") ,
+            new KeyValuePair<string, string>("委员会", "委") ,
+            
+            new KeyValuePair<string, string>("广播", "广"),
+            new KeyValuePair<string, string>("电视", "电") ,
+            new KeyValuePair<string, string>("工商", "商") ,
+      
+            new KeyValuePair<string, string>("工业", "工") ,
+            new KeyValuePair<string, string>("管理", "管") ,
+            
+            new KeyValuePair<string, string>("社会主义", "社") ,
+            new KeyValuePair<string, string>("社会", "社") ,
+            new KeyValuePair<string, string>("自动化", "自") ,
+
+                    
+
         };
         public static List<KeyValuePair<string, string>> proReplaceStr = new List<KeyValuePair<string, string>> {
             new KeyValuePair<string, string>("北京","京") ,
@@ -126,15 +252,24 @@ namespace TEAMModelOS.Controllers
         };
         // new List<string>() {"省", "市", "校区", "区", "州", "县", "旗", "盟", "自治","小学","第","学校","中学","大学","初中","高中", "学院", "职业","技术","幼儿园","(",")", "(",")","分校","分园","附属","校园","镇","村","乡","街","路","部"
 
+        public class SchoolData{
+            public string province { get; set; }
+            public string id { get; set; }
+            public string name { get; set; }
+            public string city { get; set; }
+            public string address { get; set; }
+        }
         /// <summary>
         /// 测试blob多线程写入同一个文件
         /// </summary>
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("generate-school-code")]
-        public async Task<IActionResult> Servicebus(JsonElement  json) {
+        public async Task<IActionResult> Servicebus(JsonElement json)
+        {
             string path = $"{_environment.ContentRootPath}/JsonFile/Core/region.json";
-            var schools = json.GetProperty("schools").ToObject<List<School>>();
+            var schools = json.GetProperty("schools").ToObject<List<SchoolData>>();
+            schools= schools.Where((x, i) => schools.FindIndex(n => n.name.Equals(x.name)) == i).ToList();
             StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
             StringBuilder stringBuilder = new StringBuilder();
             string text;
@@ -146,50 +281,210 @@ namespace TEAMModelOS.Controllers
             streamReader.Close();
             string input = stringBuilder.ToString();
             List<Region> region = input.ToObject<List<Region>>(); ;
-            schools.ForEach(x => {
-                comeRemoveStr.ForEach(c => { x.province= x.province.Replace(c, ""); });
-                prvcRemoveStr.ForEach(c => { x.province= x.province.Replace(c, ""); });
-                var province =  region.Find(r => r.name.Contains(x.province));
-                if (province != null) {
-                    x.province = province.name;
-                    var city= province.children.Find(r => r.name.Contains(x.city));
-                    if (city == null) {
+            try
+            {
+                schools.ForEach(x =>
+                {
+                    x.province=  ChineseConverter.Convert(x.province, ChineseConversionDirection.TraditionalToSimplified);
+                    x.city = ChineseConverter.Convert(x.city, ChineseConversionDirection.TraditionalToSimplified);
+                    x.name = ChineseConverter.Convert(x.name, ChineseConversionDirection.TraditionalToSimplified);
+                    if (!string.IsNullOrEmpty(x.address)) {
+                        x.address = ChineseConverter.Convert(x.address, ChineseConversionDirection.TraditionalToSimplified);
+                    }
+                 
+                    comeRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
+                    prvcRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
+                    var province = region.Find(r => r.name.Contains(x.province));
+                    string tmpprovince = x.province;
+                    string tmpcity = x.city;
+                    if (province != null)
+                    {
+                        x.province = province.name;
                         comeRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
                         cityRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
-                        city= province.children.Find(r => r.name.Contains(x.city));
+                        nationRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
+                        tmpcity = x.city;
+                        var city = province.children.Find(r => r.name.Contains(x.city));
+
+                        if (city == null)
+                        {
+                            city = province.children.Find(r => r.name.Contains(x.city));
+                            if (city == null)
+                            {
+                                city = province.children.SelectMany(x => x.children).ToList().Find(r => r.name.Contains(x.city));
+                            }
+                        }
+                        if (city != null)
+                        {
+                            x.city = city.name;
+                        }
+                    }
+
+                    string name = x.name;
+                    string[] names = name.Split("(");
+                    if (names.Length > 1)
+                    {
+                        name = $"{names[0]}{names[1].Substring(0, 1)}";
                     }
-                    if (city != null) {
-                        x.city = city.name;
-                        if (x.name.Length > 6) {
-                            //新区,高新,产业等非新政单位
-                            foreach (var str in areaRemoveStr)
+                    names = name.Split("(");
+                    if (names.Length > 1)
+                    {
+                        name = $"{names[0]}{names[1].Substring(0, 1)}";
+                    }
+                    name = Regex.Replace(name, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", "");
+                    name = Regex.Replace(name, @"\s", "");
+                    name = name.Replace("\\", "");
+                    if (name.Length > 6)
+                    {
+                        //新区,高新,产业等非新政单位
+                        areaRemoveStr.ForEach(str =>
+                        {
+                            name = name.Replace(str.Key, str.Value);
+                        });
+                        //去除冗余的学校信息,只保留地名和校名关键信息
+                        schooRemoveStr.ForEach(str =>
+                        {
+                            name = name.Replace(str, "");
+                        });
+                       
+                        //替换民族信息词
+                        if (name.Length > 6)
+                        {
+                            nationRemoveStr.ForEach(str =>
                             {
-                                x.name = x.name.Replace(str.Key, str.Value);
-                                //if (x.name.Length <= 6) {
-                                //    break;
-                                //}
+                                name = name.Replace(str, "");
+                            });
+                        }
+                        //替换学校信息的副词
+                        if (name.Length > 6)
+                        {
+                            foreach (var str in schooReplaceStr) {
+                                if (name.Length <= 6)
+                                {
+                                    break;
+                                }
+                                name = name.Replace(str.Key, str.Value);
+                                
                             }
-                            //去除冗余的学校信息,只保留地名和校名关键信息
-                            foreach (var str in schooRemoveStr) {
-                                 x.name = x.name.Replace(str, "");
-                                //if (x.name.Length <= 6) {
-                                //    break;
-                                //}
+                        }
+                        //替换省简称信息词
+                        string tmpname = name;
+                        if (name.Length > 6)
+                        {
+                            proReplaceStr.ForEach(str =>
+                            {
+                                name = name.Replace(str.Key, str.Value);
+                            });
+                            //如果替换后仍然大于6位,则取消,直接替换省份完整的词
+                            if (name.Length > 6)
+                            {
+                                name = tmpname.Replace(tmpprovince, "");
                             }
-                            //替换学校信息的副词
-                            if (x.name.Length > 6) {
-                                foreach (var str in schooReplaceStr) {
-                                    x.name = x.name.Replace(str.Key, str.Value);
+                        }
+                        //替换城市信息词
+                        if (name.Length > 6)
+                        {
+                            name = name.Replace(tmpcity, "");
+                        }
+
+                    }
+                    int len = name.Length;
+                    if (len >= 6)
+                    {
+                        name = $"{name.Substring(0, 1)}{name.Substring(len-5, 3)}{name.Substring(len - 2, 2)}";
+                    }
+                    //if (len <= 7 && len > 6)
+                    //{
+                    //    name = name.Substring(len - 6);
+                    //}
+                    if (len <= 4)
+                    {
+                        name = $"{x.city.Substring(0, 2)}{name}";
+                    }
+                    if (len == 5)
+                    {
+                        name = $"{x.city.Substring(0, 1)}{name}";
+                    }
+                    string code = ToPinYin(name);
+                    x.address = name;
+                    x.id = code;
+                    
+                });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+            }
+            string a_z = "abcdefghijklmnopqrstuvwxyz";
+            var data= schools.GroupBy(x=>x.id).Select(x=>new {key= x.Key,more=x.ToList().Count>2, count = x.ToList().Count, list= x.ToList()}).ToList();
+            data.ForEach(x =>
+            {
+                if (x.count > 1)
+                {
+                    var first = x.list.First();
+                    var same = x.list.Skip(1).Take(x.count - 1).ToList();
+                    var fs = first.name.Select(x => x).ToArray();
+                    same.ForEach(z =>
+                    {
+                        var sp = z.name.Select(x => x).ToArray();
+                        int len = sp.Length;
+                        if (sp.Length >= fs.Length)
+                        {
+                            len = fs.Count();
+                        }
+                        for (int index = 0; index < len; index++)
+                        {
+                            if (!$"{sp[index]}".Equals($"{fs[index]}"))
+                            {
+                                short st = ChineseChar.GetStrokeNumber(sp[index]);
+                                if (st > 0)
+                                {
+                                    var ins = st % 27;
+                                    var insch = a_z[ins];
+                                    if (z.name.EndsWith($"{insch}"))
+                                    {
+                                        ins = (st + 1) % 27;
+                                        insch = a_z[ins];
+                                    }
+                                    z.id = $"{z.id.Substring(0, z.id.Length - 1)}{insch}";
+                                    break;
                                 }
                             }
                         }
+                    });
+                }
+            });
+            return Ok(data);
+        }
+        public static string ToPinYin(string val)
+        {
+            val = Regex.Replace(val, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!??::•`·、。,;,.;\"‘’“”-]", "");
+            val = Regex.Replace(val, @"\s", "");
+            val = val.Replace("\\", "");
+            StringBuilder sb = new StringBuilder();
+            val.ToCharArray().ToList().ForEach(x =>
+            {
+                if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
+                {
+                    sb.Append(x);
+                }
+                else
+                {
+                    try
+                    {
+                        ChineseChar cc = new ChineseChar(x);
+                        if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
+                        {
+                            sb.Append(cc.Pinyins[0][0]);
+                        }
+                    }
+                    catch (Exception ex)
+                    {
                     }
                 }
-                
             });
-            return Ok();
+            return sb.ToString().ToLower();
         }
-
         /// <summary>
         /// 测试blob多线程写入同一个文件
         /// </summary>
@@ -209,7 +504,8 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("blobroot")]
-        public async Task<IActionResult> MultipleBlob(JsonElement jsonMsg) {
+        public async Task<IActionResult> MultipleBlob(JsonElement jsonMsg)
+        {
             if (jsonMsg.TryGetProperty("name", out JsonElement name) && name.ValueKind == JsonValueKind.String
                     && jsonMsg.TryGetProperty("root", out JsonElement root) && root.ValueKind == JsonValueKind.String)
             {
@@ -235,19 +531,20 @@ namespace TEAMModelOS.Controllers
                     GroupNames.成都开发測試群組);
                 return Ok(list);
             }
-            else {
+            else
+            {
                 return Ok();
             }
-            
+
         }
 
-        private async Task<int> SendNotification( )
+        private async Task<int> SendNotification()
         {
 
 
             HttpClient _httpClient = new HttpClient();
             //  _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
-            var pa = new { grant_type = "device", client_id= "9794e418-c4ef-4fd5-a42d-accaa2d96d6e" , client_secret = "ruL?I79h0w1AZaZXtBaZeZuQLQXLa=:-" };
+            var pa = new { grant_type = "device", client_id = "9794e418-c4ef-4fd5-a42d-accaa2d96d6e", client_secret = "ruL?I79h0w1AZaZXtBaZeZuQLQXLa=:-" };
             HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync("https://api2-rc.teammodel.net/oauth2/token", pa);
             if (responseMessage.StatusCode == HttpStatusCode.OK)
             {
@@ -270,20 +567,26 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpGet("test-delete-read")]
-        public async Task<IActionResult> TestDelete() {
+        public async Task<IActionResult> TestDelete()
+        {
 
-            foreach (var cnt in _azureStorage.GetBlobServiceClient().GetBlobContainers()) {
-               Console.WriteLine(cnt.Name);
+            foreach (var cnt in _azureStorage.GetBlobServiceClient().GetBlobContainers())
+            {
+                Console.WriteLine(cnt.Name);
             }
 
-            await  SendNotification();
+            await SendNotification();
             var client = _azureCosmos.GetCosmosClient();
             string aaa = "0";
-            try { 
+            try
+            {
                 ItemResponse<Student> a = await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
                 Ok(a.GetRawResponse().Status);
-            } catch (CosmosException ex) {
-                if (ex.Response.Status == 404) {
+            }
+            catch (CosmosException ex)
+            {
+                if (ex.Response.Status == 404)
+                {
                     aaa = "404";
                 }
             }
@@ -297,7 +600,7 @@ namespace TEAMModelOS.Controllers
             {
                 if (ex.Response.Status == 404)
                 {
-                    aaa = aaa+ " 404";
+                    aaa = aaa + " 404";
                 }
             }
             try
@@ -334,8 +637,9 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpGet("test-redis")]
-        public async Task<IActionResult> TestRedis( ) {
-            
+        public async Task<IActionResult> TestRedis()
+        {
+
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
@@ -347,9 +651,11 @@ namespace TEAMModelOS.Controllers
                     items.Add(item);
                 }
                 List<ItemCond> itemConds = new List<ItemCond>();
-                items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z => {
+                items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z =>
+                {
                     ItemCond cond = new ItemCond() { id = z.key, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = z.list.Count, grades = new List<GradeCount>(), subjects = new List<SubjectCount>() };
-                    z.list.ForEach(y => {
+                    z.list.ForEach(y =>
+                    {
                         ItemService.CountItemCond(y, null, cond);
                     });
 
@@ -359,11 +665,11 @@ namespace TEAMModelOS.Controllers
                 {
                     await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
                 });
-                return   Ok(new { itemConds });
+                return Ok(new { itemConds });
             }
             catch (Exception ex) { await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-itemcond()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組); }
-            return  Ok(new { });
-            
+            return Ok(new { });
+
         }
 
         /// <summary>
@@ -380,35 +686,35 @@ namespace TEAMModelOS.Controllers
             {
                 if (!request.TryGetProperty("name", out JsonElement name)) return BadRequest();
                 if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
-                
-                
-                    var client = _azureCosmos.GetCosmosClient();
-                    List<string> prefixs = new List<string>() { "audio", "doc", "image", "other", "res", "video", "thum" };
-                    var ContainerClient = _azureStorage.GetBlobContainerClient($"{name}");
-                    string scope = "private";
-                     
-                     
-                        scope = $"{_scope}";
-                   
-                    var tb = "Teacher";
-                    if (scope != "private")
-                    {
-                        tb = "School";
-                    }
-                    long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                    
-                    foreach (var prefix in prefixs)
+
+
+                var client = _azureCosmos.GetCosmosClient();
+                List<string> prefixs = new List<string>() { "audio", "doc", "image", "other", "res", "video", "thum" };
+                var ContainerClient = _azureStorage.GetBlobContainerClient($"{name}");
+                string scope = "private";
+
+
+                scope = $"{_scope}";
+
+                var tb = "Teacher";
+                if (scope != "private")
+                {
+                    tb = "School";
+                }
+                long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+
+                foreach (var prefix in prefixs)
+                {
+                    List<string> items = await ContainerClient.List(prefix);
+                    foreach (var item in items)
                     {
-                        List<string> items = await ContainerClient.List(prefix);
-                        foreach (var item in items)
-                        {
-                            var urlsSize = await ContainerClient.GetBlobsSize(item);
-                            Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
-                           await client.GetContainer(Constant.TEAMModelOS, tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code)) ;
-                        }
+                        var urlsSize = await ContainerClient.GetBlobsSize(item);
+                        Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
+                        await client.GetContainer(Constant.TEAMModelOS, tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
                     }
-                     
-               
+                }
+
+
                 return new OkObjectResult(new { });
 
             }
@@ -419,11 +725,11 @@ namespace TEAMModelOS.Controllers
             }
         }
 
-       /// <summary>
-         /// 删除
-         /// </summary>
-         /// <param name="request"></param>
-         /// <returns></returns>
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher")]
         [HttpPost("get-data")]
@@ -432,7 +738,7 @@ namespace TEAMModelOS.Controllers
             try
             {
                 var client = _azureCosmos.GetCosmosClient();
-                 
+
                 return Ok(new { code = 1 });
             }
             catch (Exception e)
@@ -441,5 +747,5 @@ namespace TEAMModelOS.Controllers
             }
         }
     }
-   
+
 }

+ 3 - 1
TEAMModelOS/TEAMModelOS.csproj

@@ -15,8 +15,10 @@
     <PackageReference Include="CSRedisCore" Version="3.6.5" />
     <PackageReference Include="DotNetZip" Version="1.15.0" />
     <PackageReference Include="HTEXLib" Version="5.2111.41" />
-   
+    <PackageReference Include="jieba.NET" Version="0.42.2" />
+    <PackageReference Include="CHTCHSConv" Version="1.0.0" />
     <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
+    <PackageReference Include="PinYinConverterCore" Version="1.0.2" />
     <PackageReference Include="VueCliMiddleware" Version="5.0.0" />
   </ItemGroup>
   <ItemGroup>